khronosfws/openmax_al/src/gst_adaptation/xarecorditfadaptation.c
author hgs
Fri, 25 Jun 2010 17:36:03 -0500
changeset 28 ebf79c79991a
parent 25 6f7ceef7b1d1
child 33 5e8b14bae8c3
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
hgs
parents:
diff changeset
     1
/*
25
hgs
parents: 20
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents: 20
diff changeset
     3
 * All rights reserved.
hgs
parents: 20
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents: 20
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents: 20
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents: 20
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents: 20
diff changeset
     8
 *
hgs
parents: 20
diff changeset
     9
 * Initial Contributors:
hgs
parents: 20
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents: 20
diff changeset
    11
 *
hgs
parents: 20
diff changeset
    12
 * Contributors:
hgs
parents: 20
diff changeset
    13
 *
hgs
parents: 20
diff changeset
    14
 * Description: Record Itf GST adaptation
hgs
parents: 20
diff changeset
    15
 *
hgs
parents: 20
diff changeset
    16
 */
19
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <pthread.h>
20
hgs
parents: 19
diff changeset
    19
#include <gst/gst.h>
19
hgs
parents:
diff changeset
    20
#include "xamediarecorderadaptctx.h"
hgs
parents:
diff changeset
    21
#include "xarecorditfadaptation.h"
hgs
parents:
diff changeset
    22
#include "xaadaptationgst.h"
hgs
parents:
diff changeset
    23
#include "xacameraadaptctx.h"
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
/*forward declaration of position updater callback*/
hgs
parents:
diff changeset
    26
gboolean XARecordItfAdapt_PositionUpdate(gpointer ctx);
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
extern XAboolean cameraRealized;
hgs
parents:
diff changeset
    29
extern XACameraAdaptationCtx_* cameraCtx;
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
/*
hgs
parents:
diff changeset
    32
 * XAresult XARecordItfAdapt_SetRecordState(XAAdaptationGstCtx *ctx, XAuint32 state)
hgs
parents:
diff changeset
    33
 * Sets record state to GStreamer.
hgs
parents:
diff changeset
    34
 * @param XAAdaptationGstCtx *ctx - Adaptation context
hgs
parents:
diff changeset
    35
 * XAuint32 state - Record state to be set
hgs
parents:
diff changeset
    36
 * @return XAresult ret - Success value
hgs
parents:
diff changeset
    37
 */
25
hgs
parents: 20
diff changeset
    38
XAresult XARecordItfAdapt_SetRecordState(XAAdaptationGstCtx *bCtx,
hgs
parents: 20
diff changeset
    39
        XAuint32 state)
hgs
parents: 20
diff changeset
    40
    {
19
hgs
parents:
diff changeset
    41
    XAresult ret = XA_RESULT_SUCCESS;
hgs
parents:
diff changeset
    42
    XAboolean closeSink = XA_BOOLEAN_FALSE;
hgs
parents:
diff changeset
    43
    XAboolean requestStateChange = XA_BOOLEAN_FALSE;
hgs
parents:
diff changeset
    44
    GstStateChangeReturn gstRet = GST_STATE_CHANGE_SUCCESS;
hgs
parents:
diff changeset
    45
    XAMediaRecorderAdaptationCtx* mCtx = NULL;
hgs
parents:
diff changeset
    46
    XAboolean recording = XA_BOOLEAN_FALSE;
hgs
parents:
diff changeset
    47
    DEBUG_API_A1("->XARecordItfAdapt_SetRecordState %s",RECORDSTATENAME(state));
25
hgs
parents: 20
diff changeset
    48
    if (!bCtx || bCtx->baseObj.ctxId != XAMediaRecorderAdaptation)
hgs
parents: 20
diff changeset
    49
        {
19
hgs
parents:
diff changeset
    50
        DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
hgs
parents:
diff changeset
    51
        DEBUG_API("<-XARecordItfAdapt_SetRecordState");
hgs
parents:
diff changeset
    52
        return XA_RESULT_PARAMETER_INVALID;
25
hgs
parents: 20
diff changeset
    53
        }
19
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
    mCtx = (XAMediaRecorderAdaptationCtx*) bCtx;
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
    mCtx->isRecord = XA_BOOLEAN_TRUE;
hgs
parents:
diff changeset
    58
25
hgs
parents: 20
diff changeset
    59
    switch (state)
hgs
parents: 20
diff changeset
    60
        {
19
hgs
parents:
diff changeset
    61
        case XA_RECORDSTATE_STOPPED:
25
hgs
parents: 20
diff changeset
    62
            {
hgs
parents: 20
diff changeset
    63
            // Audio sourse should be stopped 
hgs
parents: 20
diff changeset
    64
            if (mCtx->audiosource)
19
hgs
parents:
diff changeset
    65
                {
25
hgs
parents: 20
diff changeset
    66
                if (gst_element_send_event(mCtx->audiosource,
hgs
parents: 20
diff changeset
    67
                        gst_event_new_eos()) == TRUE)
hgs
parents: 20
diff changeset
    68
                    {
hgs
parents: 20
diff changeset
    69
                    DEBUG_INFO ("posted eos");
hgs
parents: 20
diff changeset
    70
                    }
hgs
parents: 20
diff changeset
    71
                else
hgs
parents: 20
diff changeset
    72
                    {
hgs
parents: 20
diff changeset
    73
                    DEBUG_ERR("FAIL : post eos");
hgs
parents: 20
diff changeset
    74
                    }
19
hgs
parents:
diff changeset
    75
                }
25
hgs
parents: 20
diff changeset
    76
hgs
parents: 20
diff changeset
    77
            if (cameraCtx && cameraRealized && mCtx->isobjvsrc
hgs
parents: 20
diff changeset
    78
                    && mCtx->videosource)
hgs
parents: 20
diff changeset
    79
                {
hgs
parents: 20
diff changeset
    80
                cameraCtx->recording = XA_BOOLEAN_FALSE;
19
hgs
parents:
diff changeset
    81
25
hgs
parents: 20
diff changeset
    82
                if (!cameraCtx->playing && !cameraCtx->snapshotting)
hgs
parents: 20
diff changeset
    83
                    {
hgs
parents: 20
diff changeset
    84
                    /* Neither view finder or recorder is running -> pause camera */
hgs
parents: 20
diff changeset
    85
                    if (GST_STATE( GST_ELEMENT(mCtx->videosource))
hgs
parents: 20
diff changeset
    86
                            == GST_STATE_PLAYING)
hgs
parents: 20
diff changeset
    87
                        {
hgs
parents: 20
diff changeset
    88
                        GstStateChangeReturn gret;
hgs
parents: 20
diff changeset
    89
                        DEBUG_INFO("Stop camera source");
hgs
parents: 20
diff changeset
    90
                        gret = gst_element_set_state(
hgs
parents: 20
diff changeset
    91
                                GST_ELEMENT(mCtx->videosource),
hgs
parents: 20
diff changeset
    92
                                GST_STATE_PAUSED);
hgs
parents: 20
diff changeset
    93
                        if (gret == GST_STATE_CHANGE_SUCCESS)
hgs
parents: 20
diff changeset
    94
                            gret = gst_element_get_state(
hgs
parents: 20
diff changeset
    95
                                    GST_ELEMENT(mCtx->videosource), NULL,
hgs
parents: 20
diff changeset
    96
                                    NULL, XA_ADAPT_ASYNC_TIMEOUT_SHORT_NSEC);
hgs
parents: 20
diff changeset
    97
                        }
hgs
parents: 20
diff changeset
    98
                    }
hgs
parents: 20
diff changeset
    99
                }
19
hgs
parents:
diff changeset
   100
hgs
parents:
diff changeset
   101
            bCtx->binWantedState = GST_STATE_PAUSED;
hgs
parents:
diff changeset
   102
            closeSink = XA_BOOLEAN_TRUE;
25
hgs
parents: 20
diff changeset
   103
            if (mCtx->runpositiontimer > 0)
hgs
parents: 20
diff changeset
   104
                {
19
hgs
parents:
diff changeset
   105
                g_source_remove(mCtx->runpositiontimer);
25
hgs
parents: 20
diff changeset
   106
                mCtx->runpositiontimer = 0;
hgs
parents: 20
diff changeset
   107
                }
19
hgs
parents:
diff changeset
   108
25
hgs
parents: 20
diff changeset
   109
            if (mCtx->recThrCtx.bufInsufficientSem)
hgs
parents: 20
diff changeset
   110
                {
19
hgs
parents:
diff changeset
   111
                DEBUG_INFO("No buffer-insufficient received, posting record thr semaphore.");
25
hgs
parents: 20
diff changeset
   112
                if (XAImpl_PostSemaphore(mCtx->recThrCtx.bufInsufficientSem)
hgs
parents: 20
diff changeset
   113
                        != XA_RESULT_SUCCESS)
hgs
parents: 20
diff changeset
   114
                    {
19
hgs
parents:
diff changeset
   115
                    DEBUG_ERR("Posting buffer-insufficient semaphore FAILED!");
25
hgs
parents: 20
diff changeset
   116
                    }
19
hgs
parents:
diff changeset
   117
                }
hgs
parents:
diff changeset
   118
hgs
parents:
diff changeset
   119
            break;
25
hgs
parents: 20
diff changeset
   120
            }
19
hgs
parents:
diff changeset
   121
        case XA_RECORDSTATE_PAUSED:
hgs
parents:
diff changeset
   122
            {
25
hgs
parents: 20
diff changeset
   123
            if (cameraCtx && cameraRealized && mCtx->isobjvsrc
hgs
parents: 20
diff changeset
   124
                    && mCtx->videosource)
hgs
parents: 20
diff changeset
   125
                {
hgs
parents: 20
diff changeset
   126
                cameraCtx->recording = XA_BOOLEAN_FALSE;
hgs
parents: 20
diff changeset
   127
                if (!cameraCtx->playing && !cameraCtx->snapshotting)
hgs
parents: 20
diff changeset
   128
                    {
hgs
parents: 20
diff changeset
   129
                    /* Neither view finder or recorder is running -> pause camera */
hgs
parents: 20
diff changeset
   130
                    if (GST_STATE( GST_ELEMENT(mCtx->videosource))
hgs
parents: 20
diff changeset
   131
                            == GST_STATE_PLAYING)
hgs
parents: 20
diff changeset
   132
                        {
hgs
parents: 20
diff changeset
   133
                        GstStateChangeReturn gret;
hgs
parents: 20
diff changeset
   134
                        DEBUG_INFO("Stop camera source");
hgs
parents: 20
diff changeset
   135
                        gret = gst_element_set_state(
hgs
parents: 20
diff changeset
   136
                                GST_ELEMENT(mCtx->videosource),
hgs
parents: 20
diff changeset
   137
                                GST_STATE_PAUSED);
hgs
parents: 20
diff changeset
   138
                        if (gret == GST_STATE_CHANGE_SUCCESS)
hgs
parents: 20
diff changeset
   139
                            gret = gst_element_get_state(
hgs
parents: 20
diff changeset
   140
                                    GST_ELEMENT(mCtx->videosource), NULL,
hgs
parents: 20
diff changeset
   141
                                    NULL, XA_ADAPT_ASYNC_TIMEOUT_SHORT_NSEC);
hgs
parents: 20
diff changeset
   142
                        }
hgs
parents: 20
diff changeset
   143
                    }
hgs
parents: 20
diff changeset
   144
                }
hgs
parents: 20
diff changeset
   145
hgs
parents: 20
diff changeset
   146
            if (mCtx->xaRecordState == XA_RECORDSTATE_STOPPED
hgs
parents: 20
diff changeset
   147
                    && mCtx->encodingchanged)
hgs
parents: 20
diff changeset
   148
                {
28
hgs
parents: 25
diff changeset
   149
                ret = XAMediaRecorderAdapt_ChangeEncoders(mCtx);
25
hgs
parents: 20
diff changeset
   150
                mCtx->encodingchanged = XA_BOOLEAN_FALSE;
28
hgs
parents: 25
diff changeset
   151
                if(ret != XA_RESULT_SUCCESS)
hgs
parents: 25
diff changeset
   152
                    {
hgs
parents: 25
diff changeset
   153
                      return ret;
hgs
parents: 25
diff changeset
   154
                    }
25
hgs
parents: 20
diff changeset
   155
                }
hgs
parents: 20
diff changeset
   156
            bCtx->binWantedState = GST_STATE_PAUSED;
hgs
parents: 20
diff changeset
   157
            if (mCtx->runpositiontimer > 0)
hgs
parents: 20
diff changeset
   158
                {
19
hgs
parents:
diff changeset
   159
                g_source_remove(mCtx->runpositiontimer);
25
hgs
parents: 20
diff changeset
   160
                mCtx->runpositiontimer = 0;
hgs
parents: 20
diff changeset
   161
                }
hgs
parents: 20
diff changeset
   162
            break;
19
hgs
parents:
diff changeset
   163
            }
hgs
parents:
diff changeset
   164
        case XA_RECORDSTATE_RECORDING:
hgs
parents:
diff changeset
   165
            {
25
hgs
parents: 20
diff changeset
   166
            if (cameraCtx && mCtx->isobjvsrc)
hgs
parents: 20
diff changeset
   167
                {
hgs
parents: 20
diff changeset
   168
                cameraCtx->recording = XA_BOOLEAN_TRUE;
hgs
parents: 20
diff changeset
   169
                }
hgs
parents: 20
diff changeset
   170
hgs
parents: 20
diff changeset
   171
            if (mCtx->xaRecordState == XA_RECORDSTATE_STOPPED
hgs
parents: 20
diff changeset
   172
                    && (mCtx->encodingchanged))
hgs
parents: 20
diff changeset
   173
                {
28
hgs
parents: 25
diff changeset
   174
                ret = XAMediaRecorderAdapt_ChangeEncoders(mCtx);
19
hgs
parents:
diff changeset
   175
                mCtx->encodingchanged = XA_BOOLEAN_FALSE;
28
hgs
parents: 25
diff changeset
   176
                if(ret != XA_RESULT_SUCCESS)
hgs
parents: 25
diff changeset
   177
                    {
hgs
parents: 25
diff changeset
   178
                      return ret;
hgs
parents: 25
diff changeset
   179
                    }
25
hgs
parents: 20
diff changeset
   180
                }
19
hgs
parents:
diff changeset
   181
25
hgs
parents: 20
diff changeset
   182
            if (mCtx->recThrCtx.bufInsufficientSem)
hgs
parents: 20
diff changeset
   183
                {
19
hgs
parents:
diff changeset
   184
                /* Recording to address and recording thread semaphora is created */
25
hgs
parents: 20
diff changeset
   185
                if (!XAImpl_StartThread(&(mCtx->recordingEventThr), NULL,
hgs
parents: 20
diff changeset
   186
                        &XAMediaRecorderAdapt_RecordEventThr, (void*) mCtx))
19
hgs
parents:
diff changeset
   187
                    {
25
hgs
parents: 20
diff changeset
   188
                    DEBUG_ERR("Start thread Failed");
hgs
parents: 20
diff changeset
   189
                    return XA_RESULT_INTERNAL_ERROR;
19
hgs
parents:
diff changeset
   190
                    }
25
hgs
parents: 20
diff changeset
   191
                }
19
hgs
parents:
diff changeset
   192
hgs
parents:
diff changeset
   193
            bCtx->binWantedState = GST_STATE_PLAYING;
hgs
parents:
diff changeset
   194
            recording = XA_BOOLEAN_TRUE;
hgs
parents:
diff changeset
   195
            break;
25
hgs
parents: 20
diff changeset
   196
            }
19
hgs
parents:
diff changeset
   197
        default:
25
hgs
parents: 20
diff changeset
   198
            DEBUG_ERR("Unhandled state")
hgs
parents: 20
diff changeset
   199
            ;
19
hgs
parents:
diff changeset
   200
            ret = XA_RESULT_PARAMETER_INVALID;
hgs
parents:
diff changeset
   201
            break;
25
hgs
parents: 20
diff changeset
   202
        }
19
hgs
parents:
diff changeset
   203
25
hgs
parents: 20
diff changeset
   204
    if (ret == XA_RESULT_SUCCESS)
hgs
parents: 20
diff changeset
   205
        {
19
hgs
parents:
diff changeset
   206
        mCtx->xaRecordState = state;
25
hgs
parents: 20
diff changeset
   207
        }
19
hgs
parents:
diff changeset
   208
hgs
parents:
diff changeset
   209
    /* launch Gstreamer state change only if necessary */
25
hgs
parents: 20
diff changeset
   210
    if (GST_STATE_TARGET(bCtx->bin) == bCtx->binWantedState)
hgs
parents: 20
diff changeset
   211
        {
19
hgs
parents:
diff changeset
   212
        DEBUG_INFO("Gst already transitioning to wanted state!!");
hgs
parents:
diff changeset
   213
        requestStateChange = XA_BOOLEAN_FALSE;
25
hgs
parents: 20
diff changeset
   214
        }
19
hgs
parents:
diff changeset
   215
    else
hgs
parents:
diff changeset
   216
        {
25
hgs
parents: 20
diff changeset
   217
        if ((GST_STATE(bCtx->bin) == bCtx->binWantedState)
hgs
parents: 20
diff changeset
   218
                && (GST_STATE_PENDING(bCtx->bin) == GST_STATE_VOID_PENDING))
hgs
parents: 20
diff changeset
   219
            {
19
hgs
parents:
diff changeset
   220
            DEBUG_ERR_A3("WARNING : gststate %d == wanted %d != gsttarget %d and no statechange pending",
25
hgs
parents: 20
diff changeset
   221
                    GST_STATE(bCtx->bin), bCtx->binWantedState, GST_STATE_TARGET(bCtx->bin));
hgs
parents: 20
diff changeset
   222
            }
19
hgs
parents:
diff changeset
   223
        requestStateChange = XA_BOOLEAN_TRUE;
25
hgs
parents: 20
diff changeset
   224
        }
19
hgs
parents:
diff changeset
   225
25
hgs
parents: 20
diff changeset
   226
    if (requestStateChange)
hgs
parents: 20
diff changeset
   227
        {
19
hgs
parents:
diff changeset
   228
        XAAdaptationGst_PrepareAsyncWait(bCtx);
hgs
parents:
diff changeset
   229
        DEBUG_INFO_A1("Sending change state request to state %d", bCtx->binWantedState);
25
hgs
parents: 20
diff changeset
   230
        gstRet = gst_element_set_state(GST_ELEMENT(bCtx->bin),
hgs
parents: 20
diff changeset
   231
                bCtx->binWantedState);
hgs
parents: 20
diff changeset
   232
        switch (gstRet)
hgs
parents: 20
diff changeset
   233
            {
19
hgs
parents:
diff changeset
   234
            case GST_STATE_CHANGE_FAILURE:
25
hgs
parents: 20
diff changeset
   235
                DEBUG_ERR_A1("FAILED to change state (target %d)",bCtx->binWantedState)
hgs
parents: 20
diff changeset
   236
                ;
19
hgs
parents:
diff changeset
   237
                bCtx->binWantedState = GST_STATE(bCtx->bin);
hgs
parents:
diff changeset
   238
                ret = XA_RESULT_INTERNAL_ERROR;
hgs
parents:
diff changeset
   239
                break;
hgs
parents:
diff changeset
   240
            case GST_STATE_CHANGE_ASYNC:
hgs
parents:
diff changeset
   241
                DEBUG_INFO_A1("Change state will happen asyncronously (target %d)",bCtx->binWantedState);
hgs
parents:
diff changeset
   242
                XAAdaptationGst_StartAsyncWait(bCtx);
hgs
parents:
diff changeset
   243
                ret = XA_RESULT_SUCCESS;
hgs
parents:
diff changeset
   244
                break;
hgs
parents:
diff changeset
   245
            case GST_STATE_CHANGE_NO_PREROLL:
25
hgs
parents: 20
diff changeset
   246
                DEBUG_INFO("GST_STATE_CHANGE_NO_PREROLL")
hgs
parents: 20
diff changeset
   247
                ;
19
hgs
parents:
diff changeset
   248
                /* deliberate fall-through */
hgs
parents:
diff changeset
   249
            case GST_STATE_CHANGE_SUCCESS:
25
hgs
parents: 20
diff changeset
   250
                DEBUG_INFO_A1("Successfully changed state (target %d)",bCtx->binWantedState)
hgs
parents: 20
diff changeset
   251
                ;
19
hgs
parents:
diff changeset
   252
                ret = XA_RESULT_SUCCESS;
hgs
parents:
diff changeset
   253
                break;
hgs
parents:
diff changeset
   254
            default:
25
hgs
parents: 20
diff changeset
   255
                DEBUG_ERR_A1("Unhandled error (%d)",gstRet)
hgs
parents: 20
diff changeset
   256
                ;
19
hgs
parents:
diff changeset
   257
                ret = XA_RESULT_UNKNOWN_ERROR;
hgs
parents:
diff changeset
   258
                break;
25
hgs
parents: 20
diff changeset
   259
            }
19
hgs
parents:
diff changeset
   260
        bCtx->waitingasyncop = XA_BOOLEAN_FALSE;
25
hgs
parents: 20
diff changeset
   261
        }
hgs
parents: 20
diff changeset
   262
    if ((GST_STATE(bCtx->bin) > GST_STATE_READY) && closeSink)
hgs
parents: 20
diff changeset
   263
        { /* close the sink*/
hgs
parents: 20
diff changeset
   264
        gst_element_send_event(bCtx->bin, gst_event_new_flush_start());
hgs
parents: 20
diff changeset
   265
        gst_element_send_event(bCtx->bin, gst_event_new_flush_stop());
hgs
parents: 20
diff changeset
   266
        }
19
hgs
parents:
diff changeset
   267
25
hgs
parents: 20
diff changeset
   268
    if (recording && mCtx->isobjvsrc && mCtx->videosource)
hgs
parents: 20
diff changeset
   269
        {
hgs
parents: 20
diff changeset
   270
        GstPad *pad = gst_element_get_static_pad(
hgs
parents: 20
diff changeset
   271
                GST_ELEMENT(mCtx->videosource), "MRObjSrc");
hgs
parents: 20
diff changeset
   272
        if (pad && gst_pad_is_linked(pad))
hgs
parents: 20
diff changeset
   273
            {
hgs
parents: 20
diff changeset
   274
            DEBUG_INFO_A2("unblock element:%s pad:%s",
hgs
parents: 20
diff changeset
   275
                    gst_element_get_name(mCtx->videosource),
hgs
parents: 20
diff changeset
   276
                    gst_pad_get_name(pad));
hgs
parents: 20
diff changeset
   277
            gst_pad_set_blocked_async(pad, FALSE, XAAdaptationGst_PadBlockCb,
hgs
parents: 20
diff changeset
   278
                    NULL);
hgs
parents: 20
diff changeset
   279
            }
19
hgs
parents:
diff changeset
   280
25
hgs
parents: 20
diff changeset
   281
        if (GST_STATE( GST_ELEMENT(mCtx->videosource)) != GST_STATE_PLAYING)
hgs
parents: 20
diff changeset
   282
            {
hgs
parents: 20
diff changeset
   283
            GstStateChangeReturn gret = GST_STATE_CHANGE_SUCCESS;
hgs
parents: 20
diff changeset
   284
            DEBUG_INFO("Start camera source");
hgs
parents: 20
diff changeset
   285
            gret = gst_element_set_state(GST_ELEMENT(mCtx->videosource),
hgs
parents: 20
diff changeset
   286
                    GST_STATE_PLAYING);
hgs
parents: 20
diff changeset
   287
            if (gret == GST_STATE_CHANGE_SUCCESS)
hgs
parents: 20
diff changeset
   288
                gret = gst_element_get_state(GST_ELEMENT(mCtx->videosource),
hgs
parents: 20
diff changeset
   289
                        NULL, NULL, XA_ADAPT_ASYNC_TIMEOUT_SHORT_NSEC);
hgs
parents: 20
diff changeset
   290
            }
hgs
parents: 20
diff changeset
   291
        }DEBUG_API("<-XARecordItfAdapt_SetRecordState");
hgs
parents: 20
diff changeset
   292
    return ret;
19
hgs
parents:
diff changeset
   293
    }
hgs
parents:
diff changeset
   294
hgs
parents:
diff changeset
   295
/*
hgs
parents:
diff changeset
   296
 * XAresult XARecordItfAdapt_GetRecordState(XAAdaptationGstCtx *bCtx, XAuint32 *state)
hgs
parents:
diff changeset
   297
 * Description: Return record state
hgs
parents:
diff changeset
   298
 */
25
hgs
parents: 20
diff changeset
   299
XAresult XARecordItfAdapt_GetRecordState(XAAdaptationGstCtx *bCtx,
hgs
parents: 20
diff changeset
   300
        XAuint32 *state)
hgs
parents: 20
diff changeset
   301
    {
19
hgs
parents:
diff changeset
   302
    XAMediaRecorderAdaptationCtx* mCtx = NULL;
hgs
parents:
diff changeset
   303
    DEBUG_API("->XARecordItfAdapt_GetRecordState");
hgs
parents:
diff changeset
   304
25
hgs
parents: 20
diff changeset
   305
    if (!bCtx || bCtx->baseObj.ctxId != XAMediaRecorderAdaptation)
hgs
parents: 20
diff changeset
   306
        {
19
hgs
parents:
diff changeset
   307
        DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
hgs
parents:
diff changeset
   308
        DEBUG_API("<-XARecordItfAdapt_GetRecordState");
hgs
parents:
diff changeset
   309
        return XA_RESULT_PARAMETER_INVALID;
25
hgs
parents: 20
diff changeset
   310
        }
19
hgs
parents:
diff changeset
   311
hgs
parents:
diff changeset
   312
    mCtx = (XAMediaRecorderAdaptationCtx*) bCtx;
hgs
parents:
diff changeset
   313
hgs
parents:
diff changeset
   314
    *state = mCtx->xaRecordState;
hgs
parents:
diff changeset
   315
hgs
parents:
diff changeset
   316
    DEBUG_API("<-XARecordItfAdapt_GetRecordState");
hgs
parents:
diff changeset
   317
    return XA_RESULT_SUCCESS;
25
hgs
parents: 20
diff changeset
   318
    }
19
hgs
parents:
diff changeset
   319
hgs
parents:
diff changeset
   320
/*
hgs
parents:
diff changeset
   321
 * XAresult XARecordItfAdapt_GetPosition(XAAdaptationGstCtx *ctx, AdaptationContextIDS ctxIDs, XAmillisecond *pMsec)
hgs
parents:
diff changeset
   322
 * @param XAAdaptationGstCtx *ctx - Adaptation context, this will be casted to correct type regarding to contextID value given as 2nd parameter
hgs
parents:
diff changeset
   323
 * XAmillisecond *pMsec - Pointer where to store current position in stream.
hgs
parents:
diff changeset
   324
 * @return XAresult ret - Success value
hgs
parents:
diff changeset
   325
 */
25
hgs
parents: 20
diff changeset
   326
XAresult XARecordItfAdapt_GetPosition(XAAdaptationGstCtx *bCtx,
hgs
parents: 20
diff changeset
   327
        XAmillisecond *pMsec)
hgs
parents: 20
diff changeset
   328
    {
19
hgs
parents:
diff changeset
   329
    XAresult ret = XA_RESULT_SUCCESS;
25
hgs
parents: 20
diff changeset
   330
hgs
parents: 20
diff changeset
   331
    gint64 position = 0;
19
hgs
parents:
diff changeset
   332
    GstFormat format = GST_FORMAT_TIME;
hgs
parents:
diff changeset
   333
    DEBUG_API("->XARecordItfAdapt_GetPosition");
hgs
parents:
diff changeset
   334
25
hgs
parents: 20
diff changeset
   335
    if (!bCtx || bCtx->baseObj.ctxId != XAMediaRecorderAdaptation)
hgs
parents: 20
diff changeset
   336
        {
19
hgs
parents:
diff changeset
   337
        DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
hgs
parents:
diff changeset
   338
        DEBUG_API("<-XARecordItfAdapt_GetPosition");
hgs
parents:
diff changeset
   339
        /* invalid parameter */
hgs
parents:
diff changeset
   340
        return XA_RESULT_PARAMETER_INVALID;
25
hgs
parents: 20
diff changeset
   341
        }
hgs
parents: 20
diff changeset
   342
    if (gst_element_query_position(GST_ELEMENT(bCtx->bin), &format, &position))
hgs
parents: 20
diff changeset
   343
        {
19
hgs
parents:
diff changeset
   344
        ret = XA_RESULT_SUCCESS;
hgs
parents:
diff changeset
   345
        *pMsec = GST_TIME_AS_MSECONDS(position); /*Warning ok due to used API specification*/
hgs
parents:
diff changeset
   346
        DEBUG_INFO_A1("Gst: Position in microseconds : %u", *pMsec );
25
hgs
parents: 20
diff changeset
   347
        }
19
hgs
parents:
diff changeset
   348
    else
25
hgs
parents: 20
diff changeset
   349
        {
19
hgs
parents:
diff changeset
   350
        DEBUG_ERR("WARNING: Gst: could not get position");
hgs
parents:
diff changeset
   351
        /* probably not fully prerolled - safe assumption for position = 0 */
hgs
parents:
diff changeset
   352
        *pMsec = 0;
hgs
parents:
diff changeset
   353
        ret = XA_RESULT_SUCCESS;
25
hgs
parents: 20
diff changeset
   354
        }
19
hgs
parents:
diff changeset
   355
hgs
parents:
diff changeset
   356
    DEBUG_API("<-XARecordItfAdapt_GetPosition");
hgs
parents:
diff changeset
   357
    return ret;
25
hgs
parents: 20
diff changeset
   358
    }
19
hgs
parents:
diff changeset
   359
hgs
parents:
diff changeset
   360
/*
hgs
parents:
diff changeset
   361
 * gboolean XARecordItfAdapt_PositionUpdate(gpointer ctx)
hgs
parents:
diff changeset
   362
 * callback.
hgs
parents:
diff changeset
   363
 * If position tracking enabled, periodic timer calls this method every XA_ADAPT_PU_INTERVAL msecs
hgs
parents:
diff changeset
   364
 * @return false to stop periodic calls
hgs
parents:
diff changeset
   365
 */
hgs
parents:
diff changeset
   366
gboolean XARecordItfAdapt_PositionUpdate(gpointer ctx)
25
hgs
parents: 20
diff changeset
   367
    {
19
hgs
parents:
diff changeset
   368
    XAAdaptationGstCtx *bCtx = (XAAdaptationGstCtx*) ctx;
hgs
parents:
diff changeset
   369
    XAMediaRecorderAdaptationCtx* mCtx = (XAMediaRecorderAdaptationCtx*) ctx;
hgs
parents:
diff changeset
   370
    DEBUG_API("->XARecordItfAdapt_PositionUpdate");
hgs
parents:
diff changeset
   371
25
hgs
parents: 20
diff changeset
   372
    if (mCtx && mCtx->trackpositionenabled)
hgs
parents: 20
diff changeset
   373
        {
19
hgs
parents:
diff changeset
   374
        GstFormat format = GST_FORMAT_TIME;
hgs
parents:
diff changeset
   375
        gint64 position = 0;
25
hgs
parents: 20
diff changeset
   376
        if (gst_element_query_position(GST_ELEMENT(bCtx->bin), &format,
hgs
parents: 20
diff changeset
   377
                &position))
hgs
parents: 20
diff changeset
   378
            {
hgs
parents: 20
diff changeset
   379
            XAuint32 posMsec = GST_TIME_AS_MSECONDS(position);
hgs
parents: 20
diff changeset
   380
            /*Warning ok due to used API specification*/
hgs
parents: 20
diff changeset
   381
            XAAdaptEvent event =
hgs
parents: 20
diff changeset
   382
                {
hgs
parents: 20
diff changeset
   383
                XA_RECORDITFEVENTS, XA_ADAPT_POSITION_UPDATE_EVT, 1, NULL
hgs
parents: 20
diff changeset
   384
                };
19
hgs
parents:
diff changeset
   385
            event.data = &posMsec;
hgs
parents:
diff changeset
   386
            DEBUG_API_A1("XARecordItfAdapt_PositionUpdate: pos %lu ms", posMsec);
hgs
parents:
diff changeset
   387
            /* send needed events */
25
hgs
parents: 20
diff changeset
   388
            XAAdaptationBase_SendAdaptEvents(&bCtx->baseObj, &event);
hgs
parents: 20
diff changeset
   389
            }
19
hgs
parents:
diff changeset
   390
        else
25
hgs
parents: 20
diff changeset
   391
            {
19
hgs
parents:
diff changeset
   392
            DEBUG_ERR("Gst: Failed to get position");
25
hgs
parents: 20
diff changeset
   393
            }
hgs
parents: 20
diff changeset
   394
        DEBUG_API_A1("<-XARecordItfAdapt_PositionUpdate: %d", mCtx->runpositiontimer);
hgs
parents: 20
diff changeset
   395
        /* return false to stop timer */
hgs
parents: 20
diff changeset
   396
        return (mCtx->runpositiontimer);
19
hgs
parents:
diff changeset
   397
        }
25
hgs
parents: 20
diff changeset
   398
    return FALSE;
19
hgs
parents:
diff changeset
   399
    }
hgs
parents:
diff changeset
   400
hgs
parents:
diff changeset
   401
/*
hgs
parents:
diff changeset
   402
 * XAresult XARecordItfAdapt_EnablePositionTracking
hgs
parents:
diff changeset
   403
 * Enable/disable periodic position tracking callbacks
hgs
parents:
diff changeset
   404
 */
25
hgs
parents: 20
diff changeset
   405
XAresult XARecordItfAdapt_EnablePositionTracking(XAAdaptationGstCtx *bCtx,
hgs
parents: 20
diff changeset
   406
        XAboolean enable)
hgs
parents: 20
diff changeset
   407
    {
19
hgs
parents:
diff changeset
   408
    XAMediaRecorderAdaptationCtx* mCtx = (XAMediaRecorderAdaptationCtx*) bCtx;
hgs
parents:
diff changeset
   409
    DEBUG_API_A1("->XARecordItfAdapt_EnablePositionTracking (enable: %lu)", enable);
hgs
parents:
diff changeset
   410
25
hgs
parents: 20
diff changeset
   411
    if (!bCtx || bCtx->baseObj.ctxId != XAMediaRecorderAdaptation)
hgs
parents: 20
diff changeset
   412
        {
19
hgs
parents:
diff changeset
   413
        DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
hgs
parents:
diff changeset
   414
        DEBUG_API("<-XARecordItfAdapt_EnablePositionTracking");
hgs
parents:
diff changeset
   415
        /* invalid parameter */
hgs
parents:
diff changeset
   416
        return XA_RESULT_PARAMETER_INVALID;
25
hgs
parents: 20
diff changeset
   417
        }
19
hgs
parents:
diff changeset
   418
hgs
parents:
diff changeset
   419
    /* create a timer to track position of playback */
25
hgs
parents: 20
diff changeset
   420
    if (enable && !(mCtx->trackpositionenabled))
hgs
parents: 20
diff changeset
   421
        {
19
hgs
parents:
diff changeset
   422
        mCtx->trackpositionenabled = XA_BOOLEAN_TRUE;
hgs
parents:
diff changeset
   423
        mCtx->positionCb = &XARecordItfAdapt_PositionUpdate;
hgs
parents:
diff changeset
   424
        /* if recording is already on, create a timer to track position of recording */
25
hgs
parents: 20
diff changeset
   425
        if (GST_STATE(bCtx->bin) == GST_STATE_PLAYING)
hgs
parents: 20
diff changeset
   426
            {
hgs
parents: 20
diff changeset
   427
            mCtx->runpositiontimer = g_timeout_add(XA_ADAPT_PU_INTERVAL,
hgs
parents: 20
diff changeset
   428
                    mCtx->positionCb, mCtx);
hgs
parents: 20
diff changeset
   429
            }
19
hgs
parents:
diff changeset
   430
        }
hgs
parents:
diff changeset
   431
    else if (!enable && (mCtx->trackpositionenabled))
25
hgs
parents: 20
diff changeset
   432
        {
19
hgs
parents:
diff changeset
   433
        mCtx->trackpositionenabled = XA_BOOLEAN_FALSE;
25
hgs
parents: 20
diff changeset
   434
        if (mCtx->runpositiontimer > 0)
hgs
parents: 20
diff changeset
   435
            {
19
hgs
parents:
diff changeset
   436
            g_source_remove(mCtx->runpositiontimer);
25
hgs
parents: 20
diff changeset
   437
            mCtx->runpositiontimer = 0;
hgs
parents: 20
diff changeset
   438
            }
19
hgs
parents:
diff changeset
   439
        }
hgs
parents:
diff changeset
   440
hgs
parents:
diff changeset
   441
    DEBUG_API("<-XARecordItfAdapt_EnablePositionTracking");
hgs
parents:
diff changeset
   442
    return XA_RESULT_SUCCESS;
25
hgs
parents: 20
diff changeset
   443
    }
19
hgs
parents:
diff changeset
   444