khronosfws/openmax_al/src/gst_adaptation/xaadaptationgst.c
author hgs
Fri, 11 Jun 2010 19:59:23 -0500
changeset 25 6f7ceef7b1d1
parent 21 2ed61feeead6
child 28 ebf79c79991a
permissions -rw-r--r--
201023
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
hgs
parents:
diff changeset
     1
/*
25
hgs
parents: 21
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents: 21
diff changeset
     3
 * All rights reserved.
hgs
parents: 21
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents: 21
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents: 21
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents: 21
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents: 21
diff changeset
     8
 *
hgs
parents: 21
diff changeset
     9
 * Initial Contributors:
hgs
parents: 21
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents: 21
diff changeset
    11
 *
hgs
parents: 21
diff changeset
    12
 * Contributors:
hgs
parents: 21
diff changeset
    13
 *
hgs
parents: 21
diff changeset
    14
 * Description: Base GStreamer Adaptation Source
hgs
parents: 21
diff changeset
    15
 *
hgs
parents: 21
diff changeset
    16
 */
19
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <assert.h>
hgs
parents:
diff changeset
    19
#include <string.h>
25
hgs
parents: 21
diff changeset
    20
#include <gst/gst.h>
hgs
parents: 21
diff changeset
    21
#include <gst/gstbuffer.h>
19
hgs
parents:
diff changeset
    22
#include "xaobjectitf.h"
hgs
parents:
diff changeset
    23
#include "xacameradevice.h"
hgs
parents:
diff changeset
    24
#include "xaradiodevice.h"
hgs
parents:
diff changeset
    25
#include "xaoutputmix.h"
hgs
parents:
diff changeset
    26
#include "xamediaplayeradaptctx.h"
hgs
parents:
diff changeset
    27
#include "xacameraadaptctx.h"
hgs
parents:
diff changeset
    28
#include <stdlib.h>
21
hgs
parents: 19
diff changeset
    29
hgs
parents: 19
diff changeset
    30
#ifdef OMAX_CAMERABIN
19
hgs
parents:
diff changeset
    31
extern XAboolean cameraRealized;
21
hgs
parents: 19
diff changeset
    32
19
hgs
parents:
diff changeset
    33
extern XACameraAdaptationCtx_* cameraCtx;
21
hgs
parents: 19
diff changeset
    34
#else
hgs
parents: 19
diff changeset
    35
XAboolean cameraRealized = XA_BOOLEAN_FALSE;
hgs
parents: 19
diff changeset
    36
XACameraAdaptationCtx_* cameraCtx = NULL;
hgs
parents: 19
diff changeset
    37
#endif
19
hgs
parents:
diff changeset
    38
/*
hgs
parents:
diff changeset
    39
 * XAAdaptationGstCtx* XAAdaptationGst_Create()
hgs
parents:
diff changeset
    40
 * 1st phase initialization function for Adaptation Base context structure.
hgs
parents:
diff changeset
    41
 * Reserves memory for base context and initializes GStreamer FW.
hgs
parents:
diff changeset
    42
 */
25
hgs
parents: 21
diff changeset
    43
XAresult XAAdaptationGst_Init(XAAdaptationGstCtx* pSelf, XAuint32 ctxId)
hgs
parents: 21
diff changeset
    44
    {
19
hgs
parents:
diff changeset
    45
    DEBUG_API("->XAAdaptationGst_Init");
hgs
parents:
diff changeset
    46
25
hgs
parents: 21
diff changeset
    47
    if (pSelf)
hgs
parents: 21
diff changeset
    48
        {
hgs
parents: 21
diff changeset
    49
        if (XAAdaptationBase_Init(&(pSelf->baseObj), ctxId)
hgs
parents: 21
diff changeset
    50
                != XA_RESULT_SUCCESS)
19
hgs
parents:
diff changeset
    51
            {
hgs
parents:
diff changeset
    52
            DEBUG_ERR("Failed to init base context!!!");
hgs
parents:
diff changeset
    53
            free(pSelf);
hgs
parents:
diff changeset
    54
            pSelf = NULL;
hgs
parents:
diff changeset
    55
            }
hgs
parents:
diff changeset
    56
        else
hgs
parents:
diff changeset
    57
            {
hgs
parents:
diff changeset
    58
            GError* gerror = 0;
25
hgs
parents: 21
diff changeset
    59
hgs
parents: 21
diff changeset
    60
            /*         Add default handler for Gst-bus messages */
19
hgs
parents:
diff changeset
    61
            pSelf->busCb = XAAdaptationGst_GstBusCb;
25
hgs
parents: 21
diff changeset
    62
19
hgs
parents:
diff changeset
    63
            // VASU MOD BEGINS
hgs
parents:
diff changeset
    64
            pSelf->cond_mutx_inited = XA_BOOLEAN_FALSE;
hgs
parents:
diff changeset
    65
            // VASU MOD ENDS
25
hgs
parents: 21
diff changeset
    66
hgs
parents: 21
diff changeset
    67
            sem_init(&(pSelf->semAsyncWait), 0, 0);
hgs
parents: 21
diff changeset
    68
hgs
parents: 21
diff changeset
    69
            if (!gst_init_check(NULL, NULL, &gerror))
19
hgs
parents:
diff changeset
    70
                {
25
hgs
parents: 21
diff changeset
    71
                DEBUG_ERR("Gst Initalization failure.");
hgs
parents: 21
diff changeset
    72
                return XA_RESULT_INTERNAL_ERROR;
19
hgs
parents:
diff changeset
    73
                }
25
hgs
parents: 21
diff changeset
    74
19
hgs
parents:
diff changeset
    75
            }
25
hgs
parents: 21
diff changeset
    76
        }
19
hgs
parents:
diff changeset
    77
    else
25
hgs
parents: 21
diff changeset
    78
        {
19
hgs
parents:
diff changeset
    79
        DEBUG_ERR("Invalid Gst Base Context.")
hgs
parents:
diff changeset
    80
        return XA_RESULT_PARAMETER_INVALID;
25
hgs
parents: 21
diff changeset
    81
        }
19
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
    DEBUG_API("<-XAAdaptationGst_Init");
hgs
parents:
diff changeset
    84
    return XA_RESULT_SUCCESS;
25
hgs
parents: 21
diff changeset
    85
    }
19
hgs
parents:
diff changeset
    86
hgs
parents:
diff changeset
    87
/*
hgs
parents:
diff changeset
    88
 * XAresult XAAdaptationGst_PostInit()
hgs
parents:
diff changeset
    89
 * 2nd phase initialization for Adaptation Base.
hgs
parents:
diff changeset
    90
 */
25
hgs
parents: 21
diff changeset
    91
XAresult XAAdaptationGst_PostInit(XAAdaptationGstCtx* ctx)
hgs
parents: 21
diff changeset
    92
    {
19
hgs
parents:
diff changeset
    93
    XAresult ret = XA_RESULT_SUCCESS;
hgs
parents:
diff changeset
    94
    DEBUG_API("->XAAdaptationGst_PostInit");
hgs
parents:
diff changeset
    95
    // VASU MOD BEGINS
hgs
parents:
diff changeset
    96
    XAAdaptationBase_PostInit(&ctx->baseObj);
25
hgs
parents: 21
diff changeset
    97
19
hgs
parents:
diff changeset
    98
    ctx->thread_launched = XA_BOOLEAN_FALSE;
hgs
parents:
diff changeset
    99
    pthread_mutex_init(&(ctx->ds_mutex), NULL);
hgs
parents:
diff changeset
   100
    pthread_cond_init(&(ctx->ds_condition), NULL);
hgs
parents:
diff changeset
   101
    ctx->cond_mutx_inited = XA_BOOLEAN_TRUE;
25
hgs
parents: 21
diff changeset
   102
19
hgs
parents:
diff changeset
   103
    // VASU MOD ENDS
hgs
parents:
diff changeset
   104
    DEBUG_API("<-XAAdaptationGst_PostInit");
hgs
parents:
diff changeset
   105
    return ret;
25
hgs
parents: 21
diff changeset
   106
    }
19
hgs
parents:
diff changeset
   107
hgs
parents:
diff changeset
   108
/*
hgs
parents:
diff changeset
   109
 * void XAAdaptationGst_Free( XAAdaptationGstCtx* ctx )
hgs
parents:
diff changeset
   110
 * Frees all Base context variables .
hgs
parents:
diff changeset
   111
 */
25
hgs
parents: 21
diff changeset
   112
void XAAdaptationGst_Free(XAAdaptationGstCtx* ctx)
hgs
parents: 21
diff changeset
   113
    {
hgs
parents: 21
diff changeset
   114
    GstElement* fakesink = NULL;
19
hgs
parents:
diff changeset
   115
    DEBUG_API("->XAAdaptationGst_Free");
hgs
parents:
diff changeset
   116
25
hgs
parents: 21
diff changeset
   117
    if (ctx->bin)
hgs
parents: 21
diff changeset
   118
        {
hgs
parents: 21
diff changeset
   119
        fakesink = gst_bin_get_by_name(GST_BIN(ctx->bin), "fakesink");
hgs
parents: 21
diff changeset
   120
        if (fakesink)
hgs
parents: 21
diff changeset
   121
            {
hgs
parents: 21
diff changeset
   122
            gst_element_set_state(GST_ELEMENT(fakesink), GST_STATE_NULL);
hgs
parents: 21
diff changeset
   123
            gst_object_unref(fakesink);
hgs
parents: 21
diff changeset
   124
            }
19
hgs
parents:
diff changeset
   125
25
hgs
parents: 21
diff changeset
   126
        if (gst_element_set_state(GST_ELEMENT(ctx->bin), GST_STATE_NULL)
hgs
parents: 21
diff changeset
   127
                != GST_STATE_CHANGE_SUCCESS)
hgs
parents: 21
diff changeset
   128
            { /*not much we can do*/
19
hgs
parents:
diff changeset
   129
            DEBUG_ERR("WARNING: Failed to change to NULL state before deletion!!")
25
hgs
parents: 21
diff changeset
   130
            }
19
hgs
parents:
diff changeset
   131
        }
hgs
parents:
diff changeset
   132
25
hgs
parents: 21
diff changeset
   133
    if (ctx->asynctimer)
hgs
parents: 21
diff changeset
   134
        { /*cancel timer*/
19
hgs
parents:
diff changeset
   135
        g_source_remove(ctx->asynctimer);
25
hgs
parents: 21
diff changeset
   136
        }
19
hgs
parents:
diff changeset
   137
    sem_post(&(ctx->semAsyncWait));
hgs
parents:
diff changeset
   138
    sem_destroy(&(ctx->semAsyncWait));
hgs
parents:
diff changeset
   139
hgs
parents:
diff changeset
   140
    XAAdaptationGst_StopGstListener(ctx);
hgs
parents:
diff changeset
   141
25
hgs
parents: 21
diff changeset
   142
    if (ctx->bin)
hgs
parents: 21
diff changeset
   143
        {
19
hgs
parents:
diff changeset
   144
        gst_object_unref(ctx->bin);
25
hgs
parents: 21
diff changeset
   145
        }
19
hgs
parents:
diff changeset
   146
hgs
parents:
diff changeset
   147
    //g_array_free(ctx->evtHdlrs, TRUE);
hgs
parents:
diff changeset
   148
    // VASU MOD BEGINS
hgs
parents:
diff changeset
   149
    if (ctx->cond_mutx_inited == XA_BOOLEAN_TRUE)
hgs
parents:
diff changeset
   150
        {
hgs
parents:
diff changeset
   151
        ctx->thread_launched = XA_BOOLEAN_FALSE;
hgs
parents:
diff changeset
   152
        pthread_mutex_destroy(&(ctx->ds_mutex));
hgs
parents:
diff changeset
   153
        pthread_cond_destroy(&(ctx->ds_condition));
hgs
parents:
diff changeset
   154
        ctx->cond_mutx_inited = XA_BOOLEAN_FALSE;
hgs
parents:
diff changeset
   155
        }
hgs
parents:
diff changeset
   156
    // VASU MOD ENDS
hgs
parents:
diff changeset
   157
    XAAdaptationBase_Free(&ctx->baseObj);
25
hgs
parents: 21
diff changeset
   158
19
hgs
parents:
diff changeset
   159
    DEBUG_API("<-XAAdaptationGst_Free");
25
hgs
parents: 21
diff changeset
   160
    }
19
hgs
parents:
diff changeset
   161
hgs
parents:
diff changeset
   162
/*
hgs
parents:
diff changeset
   163
 * gboolean XAAdaptationBase_GstBusCb( GstBus *bus, GstMessage *message, gpointer data )
hgs
parents:
diff changeset
   164
 * Default Gst-bus message handler (Callback)
hgs
parents:
diff changeset
   165
 */
25
hgs
parents: 21
diff changeset
   166
gboolean XAAdaptationGst_GstBusCb(GstBus *bus, GstMessage *message,
hgs
parents: 21
diff changeset
   167
        gpointer data)
hgs
parents: 21
diff changeset
   168
    {
19
hgs
parents:
diff changeset
   169
    GError *error;
hgs
parents:
diff changeset
   170
    gchar *debug;
25
hgs
parents: 21
diff changeset
   171
    DEBUG_API("->XAAdaptationGst_GstBusCb");DEBUG_INFO_A2("Received Gst callback \"%s\" from \"%s\"",
hgs
parents: 21
diff changeset
   172
            GST_MESSAGE_TYPE_NAME(message),
hgs
parents: 21
diff changeset
   173
            GST_OBJECT_NAME(GST_MESSAGE_SRC(message)));
19
hgs
parents:
diff changeset
   174
25
hgs
parents: 21
diff changeset
   175
    switch (GST_MESSAGE_TYPE(message))
hgs
parents: 21
diff changeset
   176
        {
19
hgs
parents:
diff changeset
   177
        case GST_MESSAGE_ERROR:
25
hgs
parents: 21
diff changeset
   178
            gst_message_parse_error(message, &error, &debug);
hgs
parents: 21
diff changeset
   179
            DEBUG_INFO_A1("%s", debug)
hgs
parents: 21
diff changeset
   180
            ;
19
hgs
parents:
diff changeset
   181
            break;
hgs
parents:
diff changeset
   182
        case GST_MESSAGE_EOS:
hgs
parents:
diff changeset
   183
            break;
hgs
parents:
diff changeset
   184
        case GST_MESSAGE_UNKNOWN:
hgs
parents:
diff changeset
   185
            break;
hgs
parents:
diff changeset
   186
        case GST_MESSAGE_WARNING:
hgs
parents:
diff changeset
   187
            break;
hgs
parents:
diff changeset
   188
        case GST_MESSAGE_INFO:
hgs
parents:
diff changeset
   189
            break;
hgs
parents:
diff changeset
   190
        case GST_MESSAGE_TAG:
hgs
parents:
diff changeset
   191
            break;
hgs
parents:
diff changeset
   192
        case GST_MESSAGE_BUFFERING:
hgs
parents:
diff changeset
   193
            break;
hgs
parents:
diff changeset
   194
        case GST_MESSAGE_STATE_CHANGED:
hgs
parents:
diff changeset
   195
            break;
hgs
parents:
diff changeset
   196
        case GST_MESSAGE_STATE_DIRTY:
hgs
parents:
diff changeset
   197
            break;
hgs
parents:
diff changeset
   198
        case GST_MESSAGE_STEP_DONE:
hgs
parents:
diff changeset
   199
            break;
hgs
parents:
diff changeset
   200
        case GST_MESSAGE_CLOCK_PROVIDE:
hgs
parents:
diff changeset
   201
            break;
hgs
parents:
diff changeset
   202
        case GST_MESSAGE_CLOCK_LOST:
hgs
parents:
diff changeset
   203
            break;
hgs
parents:
diff changeset
   204
        case GST_MESSAGE_NEW_CLOCK:
hgs
parents:
diff changeset
   205
            break;
hgs
parents:
diff changeset
   206
        case GST_MESSAGE_STRUCTURE_CHANGE:
hgs
parents:
diff changeset
   207
            break;
hgs
parents:
diff changeset
   208
        case GST_MESSAGE_STREAM_STATUS:
hgs
parents:
diff changeset
   209
            break;
hgs
parents:
diff changeset
   210
        case GST_MESSAGE_APPLICATION:
hgs
parents:
diff changeset
   211
            break;
hgs
parents:
diff changeset
   212
        case GST_MESSAGE_ELEMENT:
hgs
parents:
diff changeset
   213
            break;
hgs
parents:
diff changeset
   214
        case GST_MESSAGE_SEGMENT_START:
hgs
parents:
diff changeset
   215
            break;
hgs
parents:
diff changeset
   216
        case GST_MESSAGE_SEGMENT_DONE:
hgs
parents:
diff changeset
   217
            break;
hgs
parents:
diff changeset
   218
        case GST_MESSAGE_DURATION:
hgs
parents:
diff changeset
   219
            break;
hgs
parents:
diff changeset
   220
        case GST_MESSAGE_LATENCY:
hgs
parents:
diff changeset
   221
            break;
hgs
parents:
diff changeset
   222
        case GST_MESSAGE_ASYNC_START:
hgs
parents:
diff changeset
   223
            break;
hgs
parents:
diff changeset
   224
        case GST_MESSAGE_ASYNC_DONE:
hgs
parents:
diff changeset
   225
            break;
hgs
parents:
diff changeset
   226
        case GST_MESSAGE_ANY:
hgs
parents:
diff changeset
   227
            break;
hgs
parents:
diff changeset
   228
        default:
25
hgs
parents: 21
diff changeset
   229
            DEBUG_INFO("Unhandled Gst-Bus message")
hgs
parents: 21
diff changeset
   230
            ;
19
hgs
parents:
diff changeset
   231
            break;
25
hgs
parents: 21
diff changeset
   232
        }DEBUG_API("<-XAAdaptationGst_GstBusCb");
hgs
parents: 21
diff changeset
   233
    return TRUE;
19
hgs
parents:
diff changeset
   234
    }
hgs
parents:
diff changeset
   235
hgs
parents:
diff changeset
   236
XAresult XAAdaptationGst_InitGstListener(XAAdaptationGstCtx* ctx)
25
hgs
parents: 21
diff changeset
   237
    {
19
hgs
parents:
diff changeset
   238
    int ret;
hgs
parents:
diff changeset
   239
    DEBUG_API("->XAAdaptationGst_InitGstListener");
25
hgs
parents: 21
diff changeset
   240
    if (ctx->bin)
hgs
parents: 21
diff changeset
   241
        {
hgs
parents: 21
diff changeset
   242
        ctx->bus = gst_pipeline_get_bus(GST_PIPELINE( ctx->bin ));
hgs
parents: 21
diff changeset
   243
        }
hgs
parents: 21
diff changeset
   244
    if (!ctx->bus)
hgs
parents: 21
diff changeset
   245
        {
19
hgs
parents:
diff changeset
   246
        DEBUG_ERR("could not get gst bus!")
hgs
parents:
diff changeset
   247
        return XA_RESULT_INTERNAL_ERROR;
25
hgs
parents: 21
diff changeset
   248
        }
hgs
parents: 21
diff changeset
   249
    ret = pthread_create(&(ctx->busloopThr), NULL,
hgs
parents: 21
diff changeset
   250
            (XAAdaptationGst_LaunchGstListener), (void*) ctx);
19
hgs
parents:
diff changeset
   251
    // VASU MOD BEGINS
25
hgs
parents: 21
diff changeset
   252
    if (ctx->thread_launched == XA_BOOLEAN_FALSE)
hgs
parents: 21
diff changeset
   253
        {
19
hgs
parents:
diff changeset
   254
        // Wait until the thread is created
hgs
parents:
diff changeset
   255
        pthread_mutex_lock(&(ctx->ds_mutex));
hgs
parents:
diff changeset
   256
        pthread_cond_wait(&(ctx->ds_condition), &(ctx->ds_mutex));
hgs
parents:
diff changeset
   257
        pthread_mutex_unlock(&(ctx->ds_mutex));
hgs
parents:
diff changeset
   258
        // VASU MOD ENDS
25
hgs
parents: 21
diff changeset
   259
        }
hgs
parents: 21
diff changeset
   260
    if (ret)
hgs
parents: 21
diff changeset
   261
        {
19
hgs
parents:
diff changeset
   262
        DEBUG_ERR_A1("could not create thread!! (%d)",ret)
hgs
parents:
diff changeset
   263
        return XA_RESULT_INTERNAL_ERROR;
25
hgs
parents: 21
diff changeset
   264
        }DEBUG_API("<-XAAdaptationGst_InitGstListener");
hgs
parents: 21
diff changeset
   265
    return XA_RESULT_SUCCESS;
19
hgs
parents:
diff changeset
   266
    }
hgs
parents:
diff changeset
   267
hgs
parents:
diff changeset
   268
void * XAAdaptationGst_LaunchGstListener(void* args)
25
hgs
parents: 21
diff changeset
   269
    {
hgs
parents: 21
diff changeset
   270
    XAAdaptationGstCtx* ctx = (XAAdaptationGstCtx*) args;
19
hgs
parents:
diff changeset
   271
    DEBUG_API("->XAAdaptationGst_LaunchGstListener");
hgs
parents:
diff changeset
   272
    // VASU MOD BEGINS
hgs
parents:
diff changeset
   273
    // Signal calling thread that this thread creation is completed
hgs
parents:
diff changeset
   274
    ctx->thread_launched = XA_BOOLEAN_TRUE;
hgs
parents:
diff changeset
   275
    pthread_mutex_lock(&(ctx->ds_mutex));
hgs
parents:
diff changeset
   276
    pthread_cond_signal(&(ctx->ds_condition));
hgs
parents:
diff changeset
   277
    pthread_mutex_unlock(&(ctx->ds_mutex));
hgs
parents:
diff changeset
   278
    // VASU MOD ENDS
hgs
parents:
diff changeset
   279
25
hgs
parents: 21
diff changeset
   280
    ctx->busloop = g_main_loop_new(NULL, FALSE);
hgs
parents: 21
diff changeset
   281
    if (!ctx->busloop)
hgs
parents: 21
diff changeset
   282
        {
hgs
parents: 21
diff changeset
   283
        DEBUG_ERR("Glib main loop failure.");
19
hgs
parents:
diff changeset
   284
        DEBUG_API("<-XAAdaptationGst_LaunchGstListener");
hgs
parents:
diff changeset
   285
        assert(0);
25
hgs
parents: 21
diff changeset
   286
        }
19
hgs
parents:
diff changeset
   287
    else
25
hgs
parents: 21
diff changeset
   288
        {
19
hgs
parents:
diff changeset
   289
        DEBUG_INFO("Start Glib main loop")
hgs
parents:
diff changeset
   290
        g_main_loop_run(ctx->busloop);
25
hgs
parents: 21
diff changeset
   291
        DEBUG_INFO("Glib main loop stopped - exiting thread");
19
hgs
parents:
diff changeset
   292
        DEBUG_API("<-XAAdaptationGst_LaunchGstListener");
hgs
parents:
diff changeset
   293
        pthread_exit(NULL);
25
hgs
parents: 21
diff changeset
   294
        }
hgs
parents: 21
diff changeset
   295
    return NULL;
19
hgs
parents:
diff changeset
   296
    }
hgs
parents:
diff changeset
   297
hgs
parents:
diff changeset
   298
void XAAdaptationGst_StopGstListener(XAAdaptationGstCtx* ctx)
25
hgs
parents: 21
diff changeset
   299
    {
19
hgs
parents:
diff changeset
   300
    DEBUG_API("->XAAdaptationGst_StopGstListener");
25
hgs
parents: 21
diff changeset
   301
    if (ctx->busloop)
hgs
parents: 21
diff changeset
   302
        {
hgs
parents: 21
diff changeset
   303
        g_main_loop_quit(ctx->busloop);
19
hgs
parents:
diff changeset
   304
        g_main_loop_unref(ctx->busloop);
25
hgs
parents: 21
diff changeset
   305
        }
hgs
parents: 21
diff changeset
   306
    if (ctx->bus)
hgs
parents: 21
diff changeset
   307
        {
19
hgs
parents:
diff changeset
   308
        gst_object_unref(ctx->bus);
hgs
parents:
diff changeset
   309
        ctx->bus = NULL;
25
hgs
parents: 21
diff changeset
   310
        }DEBUG_API("<-XAAdaptationGst_StopGstListener");
19
hgs
parents:
diff changeset
   311
    }
hgs
parents:
diff changeset
   312
hgs
parents:
diff changeset
   313
/*
hgs
parents:
diff changeset
   314
 * ASynchronous operation managing
hgs
parents:
diff changeset
   315
 **/
hgs
parents:
diff changeset
   316
hgs
parents:
diff changeset
   317
/* NOTE: This should NOT be called from gst callbacks - danger of deadlock!!
hgs
parents:
diff changeset
   318
 */
hgs
parents:
diff changeset
   319
void XAAdaptationGst_PrepareAsyncWait(XAAdaptationGstCtx* ctx)
25
hgs
parents: 21
diff changeset
   320
    {
19
hgs
parents:
diff changeset
   321
    DEBUG_API("->XAAdaptationGst_PrepareAsyncWait");
hgs
parents:
diff changeset
   322
25
hgs
parents: 21
diff changeset
   323
    if (ctx->waitingasyncop)
hgs
parents: 21
diff changeset
   324
        { /*wait previous async op*/
19
hgs
parents:
diff changeset
   325
        DEBUG_INFO("::WARNING:: previous asynch still ongoing!!!");
hgs
parents:
diff changeset
   326
        DEBUG_INFO(">>>>  WAIT PREVIOUS");
hgs
parents:
diff changeset
   327
        sem_wait(&(ctx->semAsyncWait));
hgs
parents:
diff changeset
   328
        DEBUG_INFO("<<<<  PREVIOUS COMPLETED");
25
hgs
parents: 21
diff changeset
   329
        }
hgs
parents: 21
diff changeset
   330
    sem_init(&(ctx->semAsyncWait), 0, 0);
19
hgs
parents:
diff changeset
   331
hgs
parents:
diff changeset
   332
    ctx->waitingasyncop = XA_BOOLEAN_TRUE;
hgs
parents:
diff changeset
   333
    DEBUG_API("<-XAAdaptationGst_PrepareAsyncWait");
25
hgs
parents: 21
diff changeset
   334
    }
19
hgs
parents:
diff changeset
   335
hgs
parents:
diff changeset
   336
void XAAdaptationGst_StartAsyncWait(XAAdaptationGstCtx* ctx)
25
hgs
parents: 21
diff changeset
   337
    {
19
hgs
parents:
diff changeset
   338
    DEBUG_API("->XAAdaptationGst_StartAsyncWait");
hgs
parents:
diff changeset
   339
hgs
parents:
diff changeset
   340
    /* timeout to try to avoid gst freeze in rollup */
hgs
parents:
diff changeset
   341
    ctx->asynctimer = g_timeout_add(XA_ADAPT_ASYNC_TIMEOUT,
25
hgs
parents: 21
diff changeset
   342
            XAAdaptationGst_CancelAsyncWait, ctx);
19
hgs
parents:
diff changeset
   343
    /* check flag once again if callback already happened before wait */
25
hgs
parents: 21
diff changeset
   344
    if (ctx->waitingasyncop)
hgs
parents: 21
diff changeset
   345
        {
19
hgs
parents:
diff changeset
   346
        DEBUG_INFO(">>>>  ASYNC STARTS");
hgs
parents:
diff changeset
   347
        sem_wait(&(ctx->semAsyncWait));
hgs
parents:
diff changeset
   348
        DEBUG_INFO("<<<<  ASYNC COMPLETED");
25
hgs
parents: 21
diff changeset
   349
        }
19
hgs
parents:
diff changeset
   350
    else
25
hgs
parents: 21
diff changeset
   351
        {
19
hgs
parents:
diff changeset
   352
        DEBUG_INFO("<> async completed already");
25
hgs
parents: 21
diff changeset
   353
        }
19
hgs
parents:
diff changeset
   354
    /*cancel timer*/
25
hgs
parents: 21
diff changeset
   355
    if (ctx->asynctimer)
hgs
parents: 21
diff changeset
   356
        {
19
hgs
parents:
diff changeset
   357
        g_source_remove(ctx->asynctimer);
25
hgs
parents: 21
diff changeset
   358
        }
19
hgs
parents:
diff changeset
   359
    ctx->waitingasyncop = XA_BOOLEAN_FALSE;
hgs
parents:
diff changeset
   360
hgs
parents:
diff changeset
   361
    DEBUG_API("<-XAAdaptationGst_StartAsyncWait");
25
hgs
parents: 21
diff changeset
   362
    }
19
hgs
parents:
diff changeset
   363
hgs
parents:
diff changeset
   364
/* async operation timeout callback*/
hgs
parents:
diff changeset
   365
gboolean XAAdaptationGst_CancelAsyncWait(gpointer ctx)
25
hgs
parents: 21
diff changeset
   366
    {
hgs
parents: 21
diff changeset
   367
    XAAdaptationGstCtx* bCtx = (XAAdaptationGstCtx*) ctx;
19
hgs
parents:
diff changeset
   368
    DEBUG_API("->XAAdaptationGst_CancelAsyncWait");
25
hgs
parents: 21
diff changeset
   369
    if (bCtx->waitingasyncop)
hgs
parents: 21
diff changeset
   370
        {
19
hgs
parents:
diff changeset
   371
        DEBUG_ERR_A3("ASYNC TIMED OUT : current %d, gsttarget %d, wanted %d",
25
hgs
parents: 21
diff changeset
   372
                GST_STATE(bCtx->bin), GST_STATE_TARGET(bCtx->bin), bCtx->binWantedState);
19
hgs
parents:
diff changeset
   373
        bCtx->waitingasyncop = XA_BOOLEAN_FALSE;
hgs
parents:
diff changeset
   374
        sem_post(&(bCtx->semAsyncWait));
25
hgs
parents: 21
diff changeset
   375
        }DEBUG_API("<-XAAdaptationGst_CancelAsyncWait");
19
hgs
parents:
diff changeset
   376
    /* return false to remove timer */
hgs
parents:
diff changeset
   377
    return FALSE;
25
hgs
parents: 21
diff changeset
   378
    }
19
hgs
parents:
diff changeset
   379
hgs
parents:
diff changeset
   380
void XAAdaptationGst_CompleteAsyncWait(XAAdaptationGstCtx* ctx)
25
hgs
parents: 21
diff changeset
   381
    {
19
hgs
parents:
diff changeset
   382
    DEBUG_API("->XAAdaptationGst_CompleteAsyncWait");
25
hgs
parents: 21
diff changeset
   383
    if (ctx->waitingasyncop)
hgs
parents: 21
diff changeset
   384
        {
19
hgs
parents:
diff changeset
   385
        int i;
hgs
parents:
diff changeset
   386
        ctx->waitingasyncop = XA_BOOLEAN_FALSE;
25
hgs
parents: 21
diff changeset
   387
        sem_getvalue(&(ctx->semAsyncWait), &i);
19
hgs
parents:
diff changeset
   388
        DEBUG_INFO_A1("Asynch operation succeeded, sem value %d",i);
25
hgs
parents: 21
diff changeset
   389
        if (i <= 0)
hgs
parents: 21
diff changeset
   390
            { /* only post if locked */
19
hgs
parents:
diff changeset
   391
            sem_post(&(ctx->semAsyncWait));
25
hgs
parents: 21
diff changeset
   392
            }
hgs
parents: 21
diff changeset
   393
        else if (i > 0)
hgs
parents: 21
diff changeset
   394
            { /* should not be, reset semaphore */
hgs
parents: 21
diff changeset
   395
            sem_init(&(ctx->semAsyncWait), 0, 0);
hgs
parents: 21
diff changeset
   396
            }
hgs
parents: 21
diff changeset
   397
        }DEBUG_API("<-XAAdaptationGst_CompleteAsyncWait");
19
hgs
parents:
diff changeset
   398
    }
hgs
parents:
diff changeset
   399
hgs
parents:
diff changeset
   400
/**
hgs
parents:
diff changeset
   401
 * GstElement* XAAdaptationGst_CreateGstSource( XADataSource* xaSrc, const XAchar *name )
hgs
parents:
diff changeset
   402
 * @param XADataSource* xaSnk - XADataSource defining gst source to create
hgs
parents:
diff changeset
   403
 * @param const XAchar *name - string for naming the gst element
hgs
parents:
diff changeset
   404
 * @param XAboolean *isobj - (out param) is source another XA object?
hgs
parents:
diff changeset
   405
 * @return GstElement* - return newly created gst source element
hgs
parents:
diff changeset
   406
 * Description: Create gst source element corresponding to XA source structure
hgs
parents:
diff changeset
   407
 */
25
hgs
parents: 21
diff changeset
   408
GstElement* XAAdaptationGst_CreateGstSource(XADataSource* xaSrc,
hgs
parents: 21
diff changeset
   409
        const char *name, XAboolean *isobj, XAboolean *isPCM,
hgs
parents: 21
diff changeset
   410
        XAboolean *isRawImage)
hgs
parents: 21
diff changeset
   411
    {
19
hgs
parents:
diff changeset
   412
    XAuint32 locType = 0;
hgs
parents:
diff changeset
   413
    GstElement* gstSrc = NULL;
25
hgs
parents: 21
diff changeset
   414
    char* fname = NULL;
19
hgs
parents:
diff changeset
   415
    XADataLocator_URI* uri = NULL;
hgs
parents:
diff changeset
   416
    XADataLocator_IODevice* ioDevice = NULL;
21
hgs
parents: 19
diff changeset
   417
#ifdef OMAX_CAMERABIN
19
hgs
parents:
diff changeset
   418
    XACameraDeviceImpl* cameraDevice = NULL;
21
hgs
parents: 19
diff changeset
   419
    XAObjectItfImpl* pObj = NULL;
hgs
parents: 19
diff changeset
   420
#endif
19
hgs
parents:
diff changeset
   421
    XARadioDeviceImpl* radioDevice = NULL;
hgs
parents:
diff changeset
   422
hgs
parents:
diff changeset
   423
    DEBUG_API("->XAAdaptationGst_CreateGstSource");
25
hgs
parents: 21
diff changeset
   424
    if (!xaSrc || !xaSrc->pLocator || !isobj)
hgs
parents: 21
diff changeset
   425
        {
19
hgs
parents:
diff changeset
   426
        return NULL;
25
hgs
parents: 21
diff changeset
   427
        }
19
hgs
parents:
diff changeset
   428
    *isobj = XA_BOOLEAN_FALSE;
25
hgs
parents: 21
diff changeset
   429
    if (xaSrc && xaSrc->pFormat && *((XAuint32*) (xaSrc->pFormat))
hgs
parents: 21
diff changeset
   430
            ==XA_DATAFORMAT_PCM && isPCM)
hgs
parents: 21
diff changeset
   431
        {
19
hgs
parents:
diff changeset
   432
        *isPCM = XA_BOOLEAN_TRUE;
25
hgs
parents: 21
diff changeset
   433
        }
hgs
parents: 21
diff changeset
   434
    if (xaSrc && xaSrc->pFormat && *((XAuint32*) (xaSrc->pFormat))
hgs
parents: 21
diff changeset
   435
            ==XA_DATAFORMAT_RAWIMAGE && isRawImage)
hgs
parents: 21
diff changeset
   436
        {
19
hgs
parents:
diff changeset
   437
        *isRawImage = XA_BOOLEAN_TRUE;
25
hgs
parents: 21
diff changeset
   438
        }
hgs
parents: 21
diff changeset
   439
    locType = *((XAuint32*) (xaSrc->pLocator));
hgs
parents: 21
diff changeset
   440
    switch (locType)
hgs
parents: 21
diff changeset
   441
        {
19
hgs
parents:
diff changeset
   442
        case XA_DATALOCATOR_URI:
25
hgs
parents: 21
diff changeset
   443
            DEBUG_INFO("XA_DATALOCATOR_URI")
hgs
parents: 21
diff changeset
   444
            ;
hgs
parents: 21
diff changeset
   445
            uri = (XADataLocator_URI*) xaSrc->pLocator;
hgs
parents: 21
diff changeset
   446
            gstSrc = gst_element_factory_make("filesrc", name);
hgs
parents: 21
diff changeset
   447
            if (uri->URI != NULL)
hgs
parents: 21
diff changeset
   448
                {
19
hgs
parents:
diff changeset
   449
                DEBUG_INFO_A1("URI: %s", uri->URI);
25
hgs
parents: 21
diff changeset
   450
                if (strncmp((char *) uri->URI, "file:///", 8) == 0)
19
hgs
parents:
diff changeset
   451
                    {
25
hgs
parents: 21
diff changeset
   452
                    fname = (char *) &((uri->URI)[8]);
19
hgs
parents:
diff changeset
   453
                    }
hgs
parents:
diff changeset
   454
                else
hgs
parents:
diff changeset
   455
                    {
25
hgs
parents: 21
diff changeset
   456
                    fname = (char *) uri->URI;
hgs
parents: 21
diff changeset
   457
                    }DEBUG_INFO_A1("->filesystem path %s", fname);
hgs
parents: 21
diff changeset
   458
                g_object_set(G_OBJECT(gstSrc), "location", fname, NULL);
hgs
parents: 21
diff changeset
   459
                /*check for pcm - decodebin does not know how to handle raw PCM files */
hgs
parents: 21
diff changeset
   460
                if (isPCM && strstr(fname, ".pcm"))
hgs
parents: 21
diff changeset
   461
                    {
hgs
parents: 21
diff changeset
   462
                    DEBUG_INFO("PCM file detected");
hgs
parents: 21
diff changeset
   463
                    *isPCM = XA_BOOLEAN_TRUE;
19
hgs
parents:
diff changeset
   464
                    }
25
hgs
parents: 21
diff changeset
   465
                }
hgs
parents: 21
diff changeset
   466
            else
19
hgs
parents:
diff changeset
   467
                {
hgs
parents:
diff changeset
   468
                DEBUG_ERR("No uri specified.");
hgs
parents:
diff changeset
   469
                return NULL;
25
hgs
parents: 21
diff changeset
   470
                }
19
hgs
parents:
diff changeset
   471
            break; /* XA_DATALOCATOR_URI */
hgs
parents:
diff changeset
   472
hgs
parents:
diff changeset
   473
        case XA_DATALOCATOR_IODEVICE:
25
hgs
parents: 21
diff changeset
   474
            DEBUG_INFO("XA_DATALOCATOR_IODEVICE")
hgs
parents: 21
diff changeset
   475
            ;
hgs
parents: 21
diff changeset
   476
            ioDevice = (XADataLocator_IODevice*) (xaSrc->pLocator);
hgs
parents: 21
diff changeset
   477
            switch (ioDevice->deviceType)
hgs
parents: 21
diff changeset
   478
                {
19
hgs
parents:
diff changeset
   479
                case XA_IODEVICE_AUDIOINPUT:
25
hgs
parents: 21
diff changeset
   480
                    {
19
hgs
parents:
diff changeset
   481
                    DEBUG_INFO("XA_IODEVICE_AUDIOINPUT");
hgs
parents:
diff changeset
   482
                    DEBUG_INFO_A1("ioDevice->deviceID: %x", ioDevice->deviceID);
25
hgs
parents: 21
diff changeset
   483
                    switch (ioDevice->deviceID)
19
hgs
parents:
diff changeset
   484
                        {
25
hgs
parents: 21
diff changeset
   485
                        //case XA_ADAPTID_ALSASRC: //Krishna
hgs
parents: 21
diff changeset
   486
                        case XA_ADAPTID_DEVSOUNDSRC:
hgs
parents: 21
diff changeset
   487
                            //DEBUG_INFO("alsasrc"); //Krishna
hgs
parents: 21
diff changeset
   488
                            DEBUG_INFO("devsoundsrc")
hgs
parents: 21
diff changeset
   489
                            ;
hgs
parents: 21
diff changeset
   490
                            gstSrc = gst_element_factory_make("devsoundsrc",
hgs
parents: 21
diff changeset
   491
                                    name); //Krishna - changed to devsoundsrc
hgs
parents: 21
diff changeset
   492
                            g_object_set(G_OBJECT (gstSrc), "num-buffers",
hgs
parents: 21
diff changeset
   493
                                    80, NULL);
19
hgs
parents:
diff changeset
   494
                            break;
25
hgs
parents: 21
diff changeset
   495
                        case XA_ADAPTID_AUDIOTESTSRC:
hgs
parents: 21
diff changeset
   496
                            /*fall through*/
19
hgs
parents:
diff changeset
   497
                        default:
25
hgs
parents: 21
diff changeset
   498
                            DEBUG_INFO("audiotestsrc")
hgs
parents: 21
diff changeset
   499
                            ;
hgs
parents: 21
diff changeset
   500
                            gstSrc = gst_element_factory_make("audiotestsrc",
hgs
parents: 21
diff changeset
   501
                                    name);
19
hgs
parents:
diff changeset
   502
                            break;
hgs
parents:
diff changeset
   503
                        }
25
hgs
parents: 21
diff changeset
   504
                    break;
19
hgs
parents:
diff changeset
   505
                    }
25
hgs
parents: 21
diff changeset
   506
#ifdef OMAX_CAMERABIN
hgs
parents: 21
diff changeset
   507
hgs
parents: 21
diff changeset
   508
                    case XA_IODEVICE_CAMERA:
hgs
parents: 21
diff changeset
   509
                        {
hgs
parents: 21
diff changeset
   510
                        DEBUG_INFO("XA_IODEVICE_CAMERA");
hgs
parents: 21
diff changeset
   511
                        if ( ioDevice->device )
hgs
parents: 21
diff changeset
   512
                            { /*source is camera object*/
hgs
parents: 21
diff changeset
   513
                            DEBUG_INFO("Use camerabin as source.");
hgs
parents: 21
diff changeset
   514
                            /* Get camerabin from source object */
hgs
parents: 21
diff changeset
   515
                            pObj = (XAObjectItfImpl*)(*ioDevice->device);
hgs
parents: 21
diff changeset
   516
                            cameraDevice = (XACameraDeviceImpl*)(pObj);
hgs
parents: 21
diff changeset
   517
                            /*TODO we had to remove this line below since adaptationCtx
hgs
parents: 21
diff changeset
   518
                             * was  not a member of structure*/
hgs
parents: 21
diff changeset
   519
hgs
parents: 21
diff changeset
   520
                            gstSrc = GST_ELEMENT(((XAAdaptationGstCtx*)(cameraDevice->adaptationCtx))->bin);
hgs
parents: 21
diff changeset
   521
                            /* refcount increase is needed to keep this not being deleted after use */
hgs
parents: 21
diff changeset
   522
                            gst_object_ref(GST_OBJECT(gstSrc));
hgs
parents: 21
diff changeset
   523
                            *isobj = XA_BOOLEAN_TRUE;
hgs
parents: 21
diff changeset
   524
                            }
hgs
parents: 21
diff changeset
   525
                        else
hgs
parents: 21
diff changeset
   526
                            {
hgs
parents: 21
diff changeset
   527
                            DEBUG_INFO_A1("ioDevice->deviceID: %x", ioDevice->deviceID);
hgs
parents: 21
diff changeset
   528
                            switch (ioDevice->deviceID )
hgs
parents: 21
diff changeset
   529
                                {
hgs
parents: 21
diff changeset
   530
                                case XA_ADAPTID_V4L2SRC:
hgs
parents: 21
diff changeset
   531
                                DEBUG_INFO("Camera deviceID: v4l2src ");
hgs
parents: 21
diff changeset
   532
hgs
parents: 21
diff changeset
   533
                                break;
hgs
parents: 21
diff changeset
   534
                                case XA_ADAPTID_VIDEOTESTSRC:
hgs
parents: 21
diff changeset
   535
                                DEBUG_INFO("Camera deviceID: videotestsrc");
hgs
parents: 21
diff changeset
   536
hgs
parents: 21
diff changeset
   537
                                break;
hgs
parents: 21
diff changeset
   538
                                default:
hgs
parents: 21
diff changeset
   539
                                case XA_DEFAULTDEVICEID_CAMERA:
hgs
parents: 21
diff changeset
   540
                                DEBUG_INFO("Camera deviceID:Default");
hgs
parents: 21
diff changeset
   541
hgs
parents: 21
diff changeset
   542
                                break;
hgs
parents: 21
diff changeset
   543
                                }
hgs
parents: 21
diff changeset
   544
                            if ( cameraCtx )
hgs
parents: 21
diff changeset
   545
                                {
hgs
parents: 21
diff changeset
   546
                                gstSrc = GST_ELEMENT(cameraCtx->baseObj.bin);
hgs
parents: 21
diff changeset
   547
                                gst_object_ref(GST_OBJECT(gstSrc));
hgs
parents: 21
diff changeset
   548
                                *isobj = XA_BOOLEAN_TRUE;
hgs
parents: 21
diff changeset
   549
                                }
hgs
parents: 21
diff changeset
   550
                            else
hgs
parents: 21
diff changeset
   551
                                {
hgs
parents: 21
diff changeset
   552
                                DEBUG_ERR("No camera object created!");
hgs
parents: 21
diff changeset
   553
                                return NULL;
hgs
parents: 21
diff changeset
   554
                                }
hgs
parents: 21
diff changeset
   555
                            }
hgs
parents: 21
diff changeset
   556
                        break;
hgs
parents: 21
diff changeset
   557
                        }
21
hgs
parents: 19
diff changeset
   558
#endif                
19
hgs
parents:
diff changeset
   559
                case XA_IODEVICE_RADIO:
25
hgs
parents: 21
diff changeset
   560
                    DEBUG_INFO("XA_IODEVICE_RADIO")
hgs
parents: 21
diff changeset
   561
                    ;
hgs
parents: 21
diff changeset
   562
                    if (ioDevice->device)
hgs
parents: 21
diff changeset
   563
                        {
19
hgs
parents:
diff changeset
   564
                        DEBUG_INFO("Use radio pipeline as source.");
hgs
parents:
diff changeset
   565
                        /* Get radio_pipeline and set it to base context */
25
hgs
parents: 21
diff changeset
   566
                        radioDevice = (XARadioDeviceImpl*) (*ioDevice->device);
19
hgs
parents:
diff changeset
   567
                        /* radio does not have actual bin, only source element*/
hgs
parents:
diff changeset
   568
                        gstSrc = GST_ELEMENT(((XAAdaptationGstCtx*)radioDevice->adaptationCtx)->bin);
hgs
parents:
diff changeset
   569
                        /* refcount increase is needed to keep this not being deleted after use */
hgs
parents:
diff changeset
   570
                        gst_object_ref(GST_OBJECT(gstSrc));
hgs
parents:
diff changeset
   571
                        /**isobj = XA_BOOLEAN_TRUE;*/
25
hgs
parents: 21
diff changeset
   572
                        }
19
hgs
parents:
diff changeset
   573
                    break;
hgs
parents:
diff changeset
   574
                default:
25
hgs
parents: 21
diff changeset
   575
                    {
19
hgs
parents:
diff changeset
   576
                    DEBUG_ERR("Unsupported IODevice.");
hgs
parents:
diff changeset
   577
                    break;
25
hgs
parents: 21
diff changeset
   578
                    }
19
hgs
parents:
diff changeset
   579
                }
hgs
parents:
diff changeset
   580
            break; /* XA_DATALOCATOR_IODEVICE */
hgs
parents:
diff changeset
   581
hgs
parents:
diff changeset
   582
        case XA_DATALOCATOR_ADDRESS:
hgs
parents:
diff changeset
   583
            {
25
hgs
parents: 21
diff changeset
   584
            XADataLocator_Address* address =
hgs
parents: 21
diff changeset
   585
                    (XADataLocator_Address*) (xaSrc->pLocator);
hgs
parents: 21
diff changeset
   586
            gstSrc = gst_element_factory_make("appsrc", name);
hgs
parents: 21
diff changeset
   587
            /* init gst buffer from datalocator */
hgs
parents: 21
diff changeset
   588
            if (gstSrc)
19
hgs
parents:
diff changeset
   589
                {
25
hgs
parents: 21
diff changeset
   590
                /* init GST buffer from XADataLocator*/
hgs
parents: 21
diff changeset
   591
                GstBuffer* userBuf = gst_buffer_new();
hgs
parents: 21
diff changeset
   592
                if (userBuf)
19
hgs
parents:
diff changeset
   593
                    {
25
hgs
parents: 21
diff changeset
   594
                    userBuf->size = address->length;
hgs
parents: 21
diff changeset
   595
                    userBuf->data = address->pAddress;
hgs
parents: 21
diff changeset
   596
                    /* push the whole buffer to appsrc so it is ready for preroll */
hgs
parents: 21
diff changeset
   597
                    DEBUG_INFO("Pushing buffer");
hgs
parents: 21
diff changeset
   598
                    gst_app_src_push_buffer(GST_APP_SRC(gstSrc), userBuf);
hgs
parents: 21
diff changeset
   599
                    DEBUG_INFO_A1("Sent buffer at 0x%x to appsrc", userBuf );
hgs
parents: 21
diff changeset
   600
                    gst_app_src_end_of_stream(GST_APP_SRC(gstSrc));
19
hgs
parents:
diff changeset
   601
                    }
25
hgs
parents: 21
diff changeset
   602
                else
19
hgs
parents:
diff changeset
   603
                    {
25
hgs
parents: 21
diff changeset
   604
                    DEBUG_ERR("Failure allocating buffer!");
19
hgs
parents:
diff changeset
   605
                    }
hgs
parents:
diff changeset
   606
                }
25
hgs
parents: 21
diff changeset
   607
            else
19
hgs
parents:
diff changeset
   608
                {
25
hgs
parents: 21
diff changeset
   609
                DEBUG_ERR("Failure creating appsrc!");
19
hgs
parents:
diff changeset
   610
                }
hgs
parents:
diff changeset
   611
            }
hgs
parents:
diff changeset
   612
            break;
hgs
parents:
diff changeset
   613
hgs
parents:
diff changeset
   614
        default:
hgs
parents:
diff changeset
   615
            DEBUG_ERR("Incorrect data locator for source.")
hgs
parents:
diff changeset
   616
            break;
25
hgs
parents: 21
diff changeset
   617
        }
19
hgs
parents:
diff changeset
   618
25
hgs
parents: 21
diff changeset
   619
    if (gstSrc)
hgs
parents: 21
diff changeset
   620
        {
19
hgs
parents:
diff changeset
   621
        DEBUG_INFO_A1("Created gstreamer source element at %x", gstSrc);
25
hgs
parents: 21
diff changeset
   622
        }
19
hgs
parents:
diff changeset
   623
hgs
parents:
diff changeset
   624
    DEBUG_API("<-XAAdaptationGst_CreateGstSource");
hgs
parents:
diff changeset
   625
    return gstSrc;
25
hgs
parents: 21
diff changeset
   626
    }
19
hgs
parents:
diff changeset
   627
hgs
parents:
diff changeset
   628
/**
hgs
parents:
diff changeset
   629
 * GstElement* XAAdaptationGst_CreateGstSink( XADataSink* xaSnk, const XAchar *name )
hgs
parents:
diff changeset
   630
 * @param XADataSink* xaSnk - XADataSink defining gst sink to create
hgs
parents:
diff changeset
   631
 * @param const XAchar *name - string for naming the gst element
hgs
parents:
diff changeset
   632
 * @return GstElement* - return newly created gst sink element
hgs
parents:
diff changeset
   633
 * Description: Create gst sink element corresponding to XA sink structure
hgs
parents:
diff changeset
   634
 */
25
hgs
parents: 21
diff changeset
   635
GstElement* XAAdaptationGst_CreateGstSink(XADataSink* xaSnk,
hgs
parents: 21
diff changeset
   636
        const char *name, XAboolean *isobj)
hgs
parents: 21
diff changeset
   637
    {
19
hgs
parents:
diff changeset
   638
    XAuint32 locType = 0;
hgs
parents:
diff changeset
   639
    GstElement* gstSnk = NULL;
hgs
parents:
diff changeset
   640
    XADataLocator_URI* uri = NULL;
hgs
parents:
diff changeset
   641
    DEBUG_API("->XAAdaptationGst_CreateGstSink");
25
hgs
parents: 21
diff changeset
   642
    if (!xaSnk || !xaSnk->pLocator)
hgs
parents: 21
diff changeset
   643
        {
19
hgs
parents:
diff changeset
   644
        DEBUG_INFO("Warning! No sink specified, use fakesink");
25
hgs
parents: 21
diff changeset
   645
        gstSnk = gst_element_factory_make("fakesink", name);
hgs
parents: 21
diff changeset
   646
        if (!gstSnk)
hgs
parents: 21
diff changeset
   647
            {
19
hgs
parents:
diff changeset
   648
            DEBUG_ERR("Cannot create sink!");
hgs
parents:
diff changeset
   649
            return NULL;
25
hgs
parents: 21
diff changeset
   650
            }
hgs
parents: 21
diff changeset
   651
        g_object_set(G_OBJECT(gstSnk), "async", FALSE, NULL);
19
hgs
parents:
diff changeset
   652
        }
hgs
parents:
diff changeset
   653
    else
hgs
parents:
diff changeset
   654
        {
25
hgs
parents: 21
diff changeset
   655
        locType = *((XAuint32*) (xaSnk->pLocator));
hgs
parents: 21
diff changeset
   656
        switch (locType)
hgs
parents: 21
diff changeset
   657
            {
19
hgs
parents:
diff changeset
   658
            case XA_DATALOCATOR_URI:
25
hgs
parents: 21
diff changeset
   659
                DEBUG_INFO("XA_DATALOCATOR_URI")
hgs
parents: 21
diff changeset
   660
                ;
hgs
parents: 21
diff changeset
   661
                uri = (XADataLocator_URI*) xaSnk->pLocator;
hgs
parents: 21
diff changeset
   662
                gstSnk = gst_element_factory_make("filesink", name);
hgs
parents: 21
diff changeset
   663
                if (!gstSnk)
hgs
parents: 21
diff changeset
   664
                    {
19
hgs
parents:
diff changeset
   665
                    DEBUG_ERR("Cannot create sink!");
hgs
parents:
diff changeset
   666
                    return NULL;
25
hgs
parents: 21
diff changeset
   667
                    }
hgs
parents: 21
diff changeset
   668
                if (uri->URI != NULL)
hgs
parents: 21
diff changeset
   669
                    {
19
hgs
parents:
diff changeset
   670
                    XAchar *fname;
hgs
parents:
diff changeset
   671
                    DEBUG_INFO_A1("URI: %s", uri->URI);
25
hgs
parents: 21
diff changeset
   672
                    if (strncmp((char *) uri->URI, "file:///", 8) == 0)
hgs
parents: 21
diff changeset
   673
                        {
19
hgs
parents:
diff changeset
   674
                        fname = &((uri->URI)[8]);
25
hgs
parents: 21
diff changeset
   675
                        }
19
hgs
parents:
diff changeset
   676
                    else
25
hgs
parents: 21
diff changeset
   677
                        {
19
hgs
parents:
diff changeset
   678
                        fname = uri->URI;
25
hgs
parents: 21
diff changeset
   679
                        }DEBUG_INFO_A1("->filesystem path %s", fname);
hgs
parents: 21
diff changeset
   680
                    g_object_set(G_OBJECT(gstSnk), "location", fname,
hgs
parents: 21
diff changeset
   681
                            "async", FALSE, "qos", FALSE, "max-lateness",
hgs
parents: 21
diff changeset
   682
                            (gint64) (-1), NULL);
19
hgs
parents:
diff changeset
   683
                    }
hgs
parents:
diff changeset
   684
                else
25
hgs
parents: 21
diff changeset
   685
                    {
19
hgs
parents:
diff changeset
   686
                    DEBUG_ERR("No recording output uri specified.");
hgs
parents:
diff changeset
   687
                    return NULL;
25
hgs
parents: 21
diff changeset
   688
                    }
19
hgs
parents:
diff changeset
   689
                break;
hgs
parents:
diff changeset
   690
            case XA_DATALOCATOR_NATIVEDISPLAY:
25
hgs
parents: 21
diff changeset
   691
                DEBUG_INFO("Sink locator type - XA_DATALOCATOR_NATIVEDISPLAY")
hgs
parents: 21
diff changeset
   692
                ;
19
hgs
parents:
diff changeset
   693
#ifdef USE_NGA_SURFACES
25
hgs
parents: 21
diff changeset
   694
                gstSnk = gst_element_factory_make("devvideosink",
hgs
parents: 21
diff changeset
   695
                        "devvideosink");
19
hgs
parents:
diff changeset
   696
#else
hgs
parents:
diff changeset
   697
                gstSnk = gst_element_factory_make("ximagesink",name);
hgs
parents:
diff changeset
   698
#endif /*USE_NGA_SURFACES*/
25
hgs
parents: 21
diff changeset
   699
                if (!gstSnk)
hgs
parents: 21
diff changeset
   700
                    {
19
hgs
parents:
diff changeset
   701
                    DEBUG_ERR("Cannot create sink!");
hgs
parents:
diff changeset
   702
                    return NULL;
25
hgs
parents: 21
diff changeset
   703
                    }
hgs
parents: 21
diff changeset
   704
                g_object_set(G_OBJECT(gstSnk), "force-aspect-ratio", TRUE,
hgs
parents: 21
diff changeset
   705
                        "async", FALSE, "qos", FALSE, "handle-events", TRUE,
hgs
parents: 21
diff changeset
   706
                        "handle-expose", TRUE, "max-lateness", (gint64) (-1),
hgs
parents: 21
diff changeset
   707
                        NULL);
19
hgs
parents:
diff changeset
   708
                break;
hgs
parents:
diff changeset
   709
            case XA_DATALOCATOR_OUTPUTMIX:
25
hgs
parents: 21
diff changeset
   710
                DEBUG_INFO("Sink locator type - XA_DATALOCATOR_OUTPUTMIX")
hgs
parents: 21
diff changeset
   711
                ;
hgs
parents: 21
diff changeset
   712
                    {
19
hgs
parents:
diff changeset
   713
                    /* Get OutputMix adaptation from data locator */
25
hgs
parents: 21
diff changeset
   714
                    XADataLocator_OutputMix* omix =
hgs
parents: 21
diff changeset
   715
                            (XADataLocator_OutputMix*) (xaSnk->pLocator);
hgs
parents: 21
diff changeset
   716
                    if (omix->outputMix)
hgs
parents: 21
diff changeset
   717
                        {
hgs
parents: 21
diff changeset
   718
                        XAOMixImpl* omixDevice =
hgs
parents: 21
diff changeset
   719
                                (XAOMixImpl*) (*omix->outputMix);
19
hgs
parents:
diff changeset
   720
25
hgs
parents: 21
diff changeset
   721
                        if (omixDevice)
hgs
parents: 21
diff changeset
   722
                            {
19
hgs
parents:
diff changeset
   723
                            /*TODO we had to remove this line below since adaptationCtx
hgs
parents:
diff changeset
   724
                             * was  not a member of structure*/
25
hgs
parents: 21
diff changeset
   725
19
hgs
parents:
diff changeset
   726
                            /*gstSnk = XAOutputMixAdapt_GetSink(omixDevice->adaptationCtx);*/
25
hgs
parents: 21
diff changeset
   727
                            if (!gstSnk)
hgs
parents: 21
diff changeset
   728
                                {
19
hgs
parents:
diff changeset
   729
                                DEBUG_ERR("Cannot create sink!");
hgs
parents:
diff changeset
   730
                                return NULL;
25
hgs
parents: 21
diff changeset
   731
                                }
19
hgs
parents:
diff changeset
   732
                            *isobj = XA_BOOLEAN_TRUE;
25
hgs
parents: 21
diff changeset
   733
                            }
19
hgs
parents:
diff changeset
   734
                        else
25
hgs
parents: 21
diff changeset
   735
                            {
19
hgs
parents:
diff changeset
   736
                            DEBUG_ERR("Warning - NULL outputmix object - default audio output used");
25
hgs
parents: 21
diff changeset
   737
                            gstSnk = gst_element_factory_make("alsasink",
hgs
parents: 21
diff changeset
   738
                                    name);
hgs
parents: 21
diff changeset
   739
                            }
19
hgs
parents:
diff changeset
   740
                        }
hgs
parents:
diff changeset
   741
                    else
25
hgs
parents: 21
diff changeset
   742
                        {
19
hgs
parents:
diff changeset
   743
                        DEBUG_ERR("Warning - NULL outputmix object - default audio output used");
25
hgs
parents: 21
diff changeset
   744
                        gstSnk = gst_element_factory_make("alsasink", name);
hgs
parents: 21
diff changeset
   745
                        }
19
hgs
parents:
diff changeset
   746
25
hgs
parents: 21
diff changeset
   747
                    }
19
hgs
parents:
diff changeset
   748
                break;
25
hgs
parents: 21
diff changeset
   749
19
hgs
parents:
diff changeset
   750
            case XA_DATALOCATOR_ADDRESS:
hgs
parents:
diff changeset
   751
                {
25
hgs
parents: 21
diff changeset
   752
                gstSnk = gst_element_factory_make("appsink", name);
hgs
parents: 21
diff changeset
   753
                /* Not actually object sink, but attribute used to notify recorder
hgs
parents: 21
diff changeset
   754
                 * about appsink (no object sinks applicable in this use case)
hgs
parents: 21
diff changeset
   755
                 **/
hgs
parents: 21
diff changeset
   756
                *isobj = TRUE;
19
hgs
parents:
diff changeset
   757
                }
hgs
parents:
diff changeset
   758
                break;
hgs
parents:
diff changeset
   759
            case XA_DATALOCATOR_IODEVICE:
hgs
parents:
diff changeset
   760
                /* when only valid IOdevice sinks vibra and LED sinks implemented
hgs
parents:
diff changeset
   761
                 * at adaptation level, add handling here (in this implementation,
hgs
parents:
diff changeset
   762
                 * no handling needed as only dummy implementations for those)
hgs
parents:
diff changeset
   763
                 **/
hgs
parents:
diff changeset
   764
            default:
hgs
parents:
diff changeset
   765
                DEBUG_ERR("Incorrect data locator for sink.")
hgs
parents:
diff changeset
   766
                break;
25
hgs
parents: 21
diff changeset
   767
            }
19
hgs
parents:
diff changeset
   768
        }
25
hgs
parents: 21
diff changeset
   769
    if (gstSnk)
hgs
parents: 21
diff changeset
   770
        {
19
hgs
parents:
diff changeset
   771
        DEBUG_INFO_A1("Created gstreamer sink element at %x", gstSnk);
25
hgs
parents: 21
diff changeset
   772
        }DEBUG_API("<-XAAdaptationGst_CreateGstSink");
hgs
parents: 21
diff changeset
   773
    return gstSnk;
19
hgs
parents:
diff changeset
   774
    }
hgs
parents:
diff changeset
   775
hgs
parents:
diff changeset
   776
/**
hgs
parents:
diff changeset
   777
 * GstElement* XAAdaptationGst_CreateVideoPP( )
hgs
parents:
diff changeset
   778
 * @return GstElement* - return newly created gst pipeline element
hgs
parents:
diff changeset
   779
 * Description: Create video processing pipeline
hgs
parents:
diff changeset
   780
 */
25
hgs
parents: 21
diff changeset
   781
GstElement* XAAdaptationGst_CreateVideoPP()
hgs
parents: 21
diff changeset
   782
    {
19
hgs
parents:
diff changeset
   783
    GstElement *vpp;
hgs
parents:
diff changeset
   784
    DEBUG_API("->XAAdaptationGst_CreateVideoPP");
hgs
parents:
diff changeset
   785
    vpp = gst_pipeline_new("videopp");
25
hgs
parents: 21
diff changeset
   786
    if (vpp)
hgs
parents: 21
diff changeset
   787
        {
19
hgs
parents:
diff changeset
   788
        GstPad *ghostsink, *ghostsrc;
25
hgs
parents: 21
diff changeset
   789
        GstElement *col1, *col2, *rotate, *mirror, *box, *crop, *gamma,
hgs
parents: 21
diff changeset
   790
                *balance, *scale, *scale2,
19
hgs
parents:
diff changeset
   791
#ifdef USE_NGA_SURFACES
25
hgs
parents: 21
diff changeset
   792
                *identity,
19
hgs
parents:
diff changeset
   793
#endif /*USE_NGA_SURFACES*/
25
hgs
parents: 21
diff changeset
   794
                *queue;
19
hgs
parents:
diff changeset
   795
hgs
parents:
diff changeset
   796
        /* Crete ffmpegcolorspace to convert stream to correct format */
25
hgs
parents: 21
diff changeset
   797
        col1 = gst_element_factory_make("ffmpegcolorspace", "pp_colsp1");
hgs
parents: 21
diff changeset
   798
        if (col1)
hgs
parents: 21
diff changeset
   799
            {
19
hgs
parents:
diff changeset
   800
            DEBUG_INFO("Created ffmpegcolorspace element");
hgs
parents:
diff changeset
   801
            gst_bin_add(GST_BIN(vpp), col1);
25
hgs
parents: 21
diff changeset
   802
            /* make this bin link point*/
hgs
parents: 21
diff changeset
   803
            ghostsink = gst_element_get_static_pad(col1, "sink");
hgs
parents: 21
diff changeset
   804
            if (ghostsink)
hgs
parents: 21
diff changeset
   805
                {
hgs
parents: 21
diff changeset
   806
                gst_element_add_pad(vpp, gst_ghost_pad_new("videopp_sink",
hgs
parents: 21
diff changeset
   807
                        ghostsink));
19
hgs
parents:
diff changeset
   808
                gst_object_unref(GST_OBJECT(ghostsink));
25
hgs
parents: 21
diff changeset
   809
                }
19
hgs
parents:
diff changeset
   810
            }
hgs
parents:
diff changeset
   811
hgs
parents:
diff changeset
   812
        /* create video crop, this will be sink for videoPP pipeline */
25
hgs
parents: 21
diff changeset
   813
        crop = gst_element_factory_make("videocrop", "pp_crop");
hgs
parents: 21
diff changeset
   814
        if (crop)
hgs
parents: 21
diff changeset
   815
            {
19
hgs
parents:
diff changeset
   816
            DEBUG_INFO("Created crop element");
hgs
parents:
diff changeset
   817
            gst_bin_add(GST_BIN(vpp), crop);
25
hgs
parents: 21
diff changeset
   818
            }
19
hgs
parents:
diff changeset
   819
hgs
parents:
diff changeset
   820
        /* create video rotate */
25
hgs
parents: 21
diff changeset
   821
        rotate = gst_element_factory_make("videoflip", "pp_rotate");
hgs
parents: 21
diff changeset
   822
        if (rotate)
hgs
parents: 21
diff changeset
   823
            {
19
hgs
parents:
diff changeset
   824
            DEBUG_INFO("Created rotate element");
hgs
parents:
diff changeset
   825
            g_object_set(G_OBJECT(rotate), "method", FLIP_NONE, NULL);
hgs
parents:
diff changeset
   826
            gst_bin_add(GST_BIN(vpp), rotate);
25
hgs
parents: 21
diff changeset
   827
            }
19
hgs
parents:
diff changeset
   828
hgs
parents:
diff changeset
   829
        /* create video mirror */
25
hgs
parents: 21
diff changeset
   830
        mirror = gst_element_factory_make("videoflip", "pp_mirror");
hgs
parents: 21
diff changeset
   831
        if (mirror)
hgs
parents: 21
diff changeset
   832
            {
19
hgs
parents:
diff changeset
   833
            DEBUG_INFO("Created mirror element");
hgs
parents:
diff changeset
   834
            g_object_set(G_OBJECT(mirror), "method", FLIP_NONE, NULL);
hgs
parents:
diff changeset
   835
            gst_bin_add(GST_BIN(vpp), mirror);
25
hgs
parents: 21
diff changeset
   836
            }
19
hgs
parents:
diff changeset
   837
hgs
parents:
diff changeset
   838
        /* create video box */
25
hgs
parents: 21
diff changeset
   839
        box = gst_element_factory_make("videobox", "pp_box");
hgs
parents: 21
diff changeset
   840
        if (box)
hgs
parents: 21
diff changeset
   841
            {
19
hgs
parents:
diff changeset
   842
            DEBUG_INFO("Created videobox element");
hgs
parents:
diff changeset
   843
            gst_bin_add(GST_BIN(vpp), box);
25
hgs
parents: 21
diff changeset
   844
            }
19
hgs
parents:
diff changeset
   845
hgs
parents:
diff changeset
   846
        /* create video balance */
25
hgs
parents: 21
diff changeset
   847
        balance = gst_element_factory_make("videobalance", "pp_balance");
hgs
parents: 21
diff changeset
   848
        if (balance)
hgs
parents: 21
diff changeset
   849
            {
19
hgs
parents:
diff changeset
   850
            DEBUG_INFO("Created balance element");
hgs
parents:
diff changeset
   851
            gst_bin_add(GST_BIN(vpp), balance);
25
hgs
parents: 21
diff changeset
   852
            }
19
hgs
parents:
diff changeset
   853
hgs
parents:
diff changeset
   854
        /* create video gamma */
25
hgs
parents: 21
diff changeset
   855
        gamma = gst_element_factory_make("gamma", "pp_gamma");
hgs
parents: 21
diff changeset
   856
        if (gamma)
hgs
parents: 21
diff changeset
   857
            {
19
hgs
parents:
diff changeset
   858
            DEBUG_INFO("Created gamma element");
hgs
parents:
diff changeset
   859
            gst_bin_add(GST_BIN(vpp), gamma);
25
hgs
parents: 21
diff changeset
   860
            }
19
hgs
parents:
diff changeset
   861
hgs
parents:
diff changeset
   862
        /* Create videoscale element to scale postprocessed output to correct size */
hgs
parents:
diff changeset
   863
        scale = gst_element_factory_make("videoscale", "pp_scale");
25
hgs
parents: 21
diff changeset
   864
        if (scale)
hgs
parents: 21
diff changeset
   865
            {
19
hgs
parents:
diff changeset
   866
            DEBUG_INFO("Created videoscale element");
hgs
parents:
diff changeset
   867
            gst_bin_add(GST_BIN(vpp), scale);
25
hgs
parents: 21
diff changeset
   868
            }
19
hgs
parents:
diff changeset
   869
        scale2 = gst_element_factory_make("videoscale", "pp_scale2");
25
hgs
parents: 21
diff changeset
   870
        if (scale2)
hgs
parents: 21
diff changeset
   871
            {
hgs
parents: 21
diff changeset
   872
            GstPad *pad = NULL;
hgs
parents: 21
diff changeset
   873
            GstCaps *caps = NULL;
hgs
parents: 21
diff changeset
   874
            DEBUG_INFO("Created videoscale element");
hgs
parents: 21
diff changeset
   875
            pad = gst_element_get_static_pad(scale2, "src");
hgs
parents: 21
diff changeset
   876
            caps = gst_caps_new_simple("video/x-raw-yuv", "width",
hgs
parents: 21
diff changeset
   877
                    G_TYPE_INT, 0, "height", G_TYPE_INT, 0, NULL);
hgs
parents: 21
diff changeset
   878
            gst_pad_set_caps(pad, caps);
hgs
parents: 21
diff changeset
   879
            gst_bin_add(GST_BIN(vpp), scale2);
hgs
parents: 21
diff changeset
   880
            }
19
hgs
parents:
diff changeset
   881
hgs
parents:
diff changeset
   882
        /* create video queue */
25
hgs
parents: 21
diff changeset
   883
        queue = gst_element_factory_make("queue", "vpp_queue");
hgs
parents: 21
diff changeset
   884
        if (queue)
hgs
parents: 21
diff changeset
   885
            {
19
hgs
parents:
diff changeset
   886
            DEBUG_INFO("Created queue element");
hgs
parents:
diff changeset
   887
            gst_bin_add(GST_BIN(vpp), queue);
hgs
parents:
diff changeset
   888
#ifdef USE_NGA_SURFACES
hgs
parents:
diff changeset
   889
            /* make this bin link point*/
25
hgs
parents: 21
diff changeset
   890
            ghostsink = gst_element_get_static_pad(queue, "sink");
hgs
parents: 21
diff changeset
   891
            if (ghostsink)
hgs
parents: 21
diff changeset
   892
                {
hgs
parents: 21
diff changeset
   893
                gst_element_add_pad(vpp, gst_ghost_pad_new("videopp_src",
hgs
parents: 21
diff changeset
   894
                        ghostsink));
19
hgs
parents:
diff changeset
   895
                gst_object_unref(GST_OBJECT(ghostsink));
25
hgs
parents: 21
diff changeset
   896
                }
19
hgs
parents:
diff changeset
   897
#endif /*USE_NGA_SURFACES*/
25
hgs
parents: 21
diff changeset
   898
            }
19
hgs
parents:
diff changeset
   899
hgs
parents:
diff changeset
   900
        /* Crete ffmpegcolorspace to convert stream to correct format */
25
hgs
parents: 21
diff changeset
   901
        col2 = gst_element_factory_make("ffmpegcolorspace", "pp_colsp2");
hgs
parents: 21
diff changeset
   902
        if (col2)
hgs
parents: 21
diff changeset
   903
            {
19
hgs
parents:
diff changeset
   904
            DEBUG_INFO("Created ffmpegcolorspace element");
hgs
parents:
diff changeset
   905
            gst_bin_add(GST_BIN(vpp), col2);
hgs
parents:
diff changeset
   906
            /* make this bin link point*/
25
hgs
parents: 21
diff changeset
   907
            ghostsrc = gst_element_get_static_pad(col2, "src");
hgs
parents: 21
diff changeset
   908
            if (ghostsrc)
hgs
parents: 21
diff changeset
   909
                {
hgs
parents: 21
diff changeset
   910
                gst_element_add_pad(vpp, gst_ghost_pad_new("videopp_src",
hgs
parents: 21
diff changeset
   911
                        ghostsrc));
19
hgs
parents:
diff changeset
   912
                gst_object_unref(GST_OBJECT(ghostsrc));
25
hgs
parents: 21
diff changeset
   913
                }
19
hgs
parents:
diff changeset
   914
            }
hgs
parents:
diff changeset
   915
hgs
parents:
diff changeset
   916
#ifdef USE_NGA_SURFACES
hgs
parents:
diff changeset
   917
        //shyward
hgs
parents:
diff changeset
   918
        /* create identity element */
25
hgs
parents: 21
diff changeset
   919
        identity = gst_element_factory_make("identity", "identity");
hgs
parents: 21
diff changeset
   920
        if (identity)
hgs
parents: 21
diff changeset
   921
            {
hgs
parents: 21
diff changeset
   922
            DEBUG_INFO("Created identity element");
hgs
parents: 21
diff changeset
   923
            gst_bin_add(GST_BIN(vpp), identity);
hgs
parents: 21
diff changeset
   924
            /* make this bin link point*/
hgs
parents: 21
diff changeset
   925
            ghostsrc = gst_element_get_static_pad(identity, "src");
hgs
parents: 21
diff changeset
   926
            if (ghostsrc)
hgs
parents: 21
diff changeset
   927
                {
hgs
parents: 21
diff changeset
   928
                gst_element_add_pad(vpp, gst_ghost_pad_new("videopp_sink",
hgs
parents: 21
diff changeset
   929
                        ghostsrc));
hgs
parents: 21
diff changeset
   930
                gst_object_unref(GST_OBJECT(ghostsrc));
hgs
parents: 21
diff changeset
   931
                }
hgs
parents: 21
diff changeset
   932
            }
hgs
parents: 21
diff changeset
   933
        if (!(gst_element_link_many(queue, identity, NULL)))
19
hgs
parents:
diff changeset
   934
#else
hgs
parents:
diff changeset
   935
        //shyward - thins code assumes all the elements will have been created, which is not true
hgs
parents:
diff changeset
   936
        if( !(gst_element_link_many(col1,
25
hgs
parents: 21
diff changeset
   937
                                scale,
hgs
parents: 21
diff changeset
   938
                                crop,
hgs
parents: 21
diff changeset
   939
                                rotate,
hgs
parents: 21
diff changeset
   940
                                mirror,
hgs
parents: 21
diff changeset
   941
                                box,
hgs
parents: 21
diff changeset
   942
                                balance,
hgs
parents: 21
diff changeset
   943
                                gamma,
hgs
parents: 21
diff changeset
   944
                                queue,
hgs
parents: 21
diff changeset
   945
                                scale2,
19
hgs
parents:
diff changeset
   946
#ifdef USE_NGA_SURFACES
25
hgs
parents: 21
diff changeset
   947
                                identity,
19
hgs
parents:
diff changeset
   948
#endif /*USE_NGA_SURFACES*/
25
hgs
parents: 21
diff changeset
   949
                                col2,
hgs
parents: 21
diff changeset
   950
                                NULL)
hgs
parents: 21
diff changeset
   951
                ) )
19
hgs
parents:
diff changeset
   952
#endif /*USE_NGA_SURFACES*/
25
hgs
parents: 21
diff changeset
   953
            {
19
hgs
parents:
diff changeset
   954
            DEBUG_ERR("Could not link videopp elements!!");
hgs
parents:
diff changeset
   955
            gst_object_unref(vpp);
hgs
parents:
diff changeset
   956
            vpp = NULL;
25
hgs
parents: 21
diff changeset
   957
            }
hgs
parents: 21
diff changeset
   958
        }DEBUG_API("<-XAAdaptationGst_CreateVideoPP");
hgs
parents: 21
diff changeset
   959
    return vpp;
19
hgs
parents:
diff changeset
   960
    }
hgs
parents:
diff changeset
   961
hgs
parents:
diff changeset
   962
/**
hgs
parents:
diff changeset
   963
 * GstElement* XAAdaptationGst_CreateFixedSizeRecordVideoPP( )
hgs
parents:
diff changeset
   964
 * @return GstElement* - return newly created gst pipeline element
25
hgs
parents: 21
diff changeset
   965
 * Description: Create video processing pipeline with fixed output size
hgs
parents: 21
diff changeset
   966
 *  to TEST_VIDEO_WIDTH x TEST_VIDEO_HEIGHT
19
hgs
parents:
diff changeset
   967
 *              experimental implementation for changing recorder output size
hgs
parents:
diff changeset
   968
 */
25
hgs
parents: 21
diff changeset
   969
GstElement* XAAdaptationGst_CreateFixedSizeVideoPP()
hgs
parents: 21
diff changeset
   970
    {
19
hgs
parents:
diff changeset
   971
    GstElement *vpp;
hgs
parents:
diff changeset
   972
    DEBUG_API("->XAAdaptationGst_CreateFixedSizeVideoPP");
hgs
parents:
diff changeset
   973
    vpp = gst_pipeline_new("videopp");
25
hgs
parents: 21
diff changeset
   974
    if (vpp)
hgs
parents: 21
diff changeset
   975
        {
19
hgs
parents:
diff changeset
   976
        GstPad *ghostsink, *ghostsrc;
25
hgs
parents: 21
diff changeset
   977
        GstElement *col1, *col2, *rotate, *mirror, *box, *crop, *gamma,
hgs
parents: 21
diff changeset
   978
                *balance, *scale, *scale2, *filter, *queue;
19
hgs
parents:
diff changeset
   979
hgs
parents:
diff changeset
   980
        /* Crete ffmpegcolorspace to convert stream to correct format */
25
hgs
parents: 21
diff changeset
   981
        col1 = gst_element_factory_make("ffmpegcolorspace", "pp_colsp1");
hgs
parents: 21
diff changeset
   982
        if (col1)
hgs
parents: 21
diff changeset
   983
            {
19
hgs
parents:
diff changeset
   984
            DEBUG_INFO("Created ffmpegcolorspace element");
hgs
parents:
diff changeset
   985
            gst_bin_add(GST_BIN(vpp), col1);
25
hgs
parents: 21
diff changeset
   986
            /* make this bin link point*/
hgs
parents: 21
diff changeset
   987
            ghostsink = gst_element_get_static_pad(col1, "sink");
hgs
parents: 21
diff changeset
   988
            if (ghostsink)
hgs
parents: 21
diff changeset
   989
                {
hgs
parents: 21
diff changeset
   990
                gst_element_add_pad(vpp, gst_ghost_pad_new("videopp_sink",
hgs
parents: 21
diff changeset
   991
                        ghostsink));
19
hgs
parents:
diff changeset
   992
                gst_object_unref(GST_OBJECT(ghostsink));
25
hgs
parents: 21
diff changeset
   993
                }
19
hgs
parents:
diff changeset
   994
            }
hgs
parents:
diff changeset
   995
hgs
parents:
diff changeset
   996
        /* create video crop, this will be sink for videoPP pipeline */
25
hgs
parents: 21
diff changeset
   997
        crop = gst_element_factory_make("videocrop", "pp_crop");
hgs
parents: 21
diff changeset
   998
        if (crop)
hgs
parents: 21
diff changeset
   999
            {
19
hgs
parents:
diff changeset
  1000
            DEBUG_INFO("Created crop element");
hgs
parents:
diff changeset
  1001
            gst_bin_add(GST_BIN(vpp), crop);
25
hgs
parents: 21
diff changeset
  1002
            }
19
hgs
parents:
diff changeset
  1003
hgs
parents:
diff changeset
  1004
        /* create video rotate */
25
hgs
parents: 21
diff changeset
  1005
        rotate = gst_element_factory_make("videoflip", "pp_rotate");
hgs
parents: 21
diff changeset
  1006
        if (rotate)
hgs
parents: 21
diff changeset
  1007
            {
19
hgs
parents:
diff changeset
  1008
            DEBUG_INFO("Created rotate element");
hgs
parents:
diff changeset
  1009
            g_object_set(G_OBJECT(rotate), "method", FLIP_NONE, NULL);
hgs
parents:
diff changeset
  1010
            gst_bin_add(GST_BIN(vpp), rotate);
25
hgs
parents: 21
diff changeset
  1011
            }
19
hgs
parents:
diff changeset
  1012
hgs
parents:
diff changeset
  1013
        /* create video mirror */
25
hgs
parents: 21
diff changeset
  1014
        mirror = gst_element_factory_make("videoflip", "pp_mirror");
hgs
parents: 21
diff changeset
  1015
        if (mirror)
hgs
parents: 21
diff changeset
  1016
            {
19
hgs
parents:
diff changeset
  1017
            DEBUG_INFO("Created mirror element");
hgs
parents:
diff changeset
  1018
            g_object_set(G_OBJECT(mirror), "method", FLIP_NONE, NULL);
hgs
parents:
diff changeset
  1019
            gst_bin_add(GST_BIN(vpp), mirror);
25
hgs
parents: 21
diff changeset
  1020
            }
19
hgs
parents:
diff changeset
  1021
hgs
parents:
diff changeset
  1022
        /* create video box */
25
hgs
parents: 21
diff changeset
  1023
        box = gst_element_factory_make("videobox", "pp_box");
hgs
parents: 21
diff changeset
  1024
        if (box)
hgs
parents: 21
diff changeset
  1025
            {
19
hgs
parents:
diff changeset
  1026
            DEBUG_INFO("Created videobox element");
hgs
parents:
diff changeset
  1027
            gst_bin_add(GST_BIN(vpp), box);
25
hgs
parents: 21
diff changeset
  1028
            }
19
hgs
parents:
diff changeset
  1029
hgs
parents:
diff changeset
  1030
        /* create video balance */
25
hgs
parents: 21
diff changeset
  1031
        balance = gst_element_factory_make("videobalance", "pp_balance");
hgs
parents: 21
diff changeset
  1032
        if (balance)
hgs
parents: 21
diff changeset
  1033
            {
19
hgs
parents:
diff changeset
  1034
            DEBUG_INFO("Created balance element");
hgs
parents:
diff changeset
  1035
            gst_bin_add(GST_BIN(vpp), balance);
25
hgs
parents: 21
diff changeset
  1036
            }
19
hgs
parents:
diff changeset
  1037
hgs
parents:
diff changeset
  1038
        /* create video gamma */
25
hgs
parents: 21
diff changeset
  1039
        gamma = gst_element_factory_make("gamma", "pp_gamma");
hgs
parents: 21
diff changeset
  1040
        if (gamma)
hgs
parents: 21
diff changeset
  1041
            {
19
hgs
parents:
diff changeset
  1042
            DEBUG_INFO("Created gamma element");
hgs
parents:
diff changeset
  1043
            gst_bin_add(GST_BIN(vpp), gamma);
25
hgs
parents: 21
diff changeset
  1044
            }
19
hgs
parents:
diff changeset
  1045
hgs
parents:
diff changeset
  1046
        /* Create videoscale element to scale postprocessed output to correct size */
hgs
parents:
diff changeset
  1047
        scale = gst_element_factory_make("videoscale", "pp_scale");
25
hgs
parents: 21
diff changeset
  1048
        if (scale)
hgs
parents: 21
diff changeset
  1049
            {
19
hgs
parents:
diff changeset
  1050
            DEBUG_INFO("Created videoscale element");
hgs
parents:
diff changeset
  1051
            gst_bin_add(GST_BIN(vpp), scale);
25
hgs
parents: 21
diff changeset
  1052
            }
19
hgs
parents:
diff changeset
  1053
        scale2 = gst_element_factory_make("videoscale", "pp_scale2");
25
hgs
parents: 21
diff changeset
  1054
        if (scale2)
hgs
parents: 21
diff changeset
  1055
            {
19
hgs
parents:
diff changeset
  1056
            GstPad *pad = NULL;
hgs
parents:
diff changeset
  1057
            GstCaps *caps = NULL;
hgs
parents:
diff changeset
  1058
            DEBUG_INFO("Created videoscale element");
25
hgs
parents: 21
diff changeset
  1059
            pad = gst_element_get_static_pad(scale2, "src");
hgs
parents: 21
diff changeset
  1060
            caps = gst_caps_new_simple("video/x-raw-yuv", "width",
hgs
parents: 21
diff changeset
  1061
                    G_TYPE_INT, 0, "height", G_TYPE_INT, 0, NULL);
19
hgs
parents:
diff changeset
  1062
            gst_pad_set_caps(pad, caps);
hgs
parents:
diff changeset
  1063
            gst_bin_add(GST_BIN(vpp), scale2);
25
hgs
parents: 21
diff changeset
  1064
            }
19
hgs
parents:
diff changeset
  1065
hgs
parents:
diff changeset
  1066
        /* create capsfilter for fixed video size */
hgs
parents:
diff changeset
  1067
        filter = gst_element_factory_make("capsfilter", "pp_filter");
25
hgs
parents: 21
diff changeset
  1068
        if (filter)
hgs
parents: 21
diff changeset
  1069
            {
19
hgs
parents:
diff changeset
  1070
25
hgs
parents: 21
diff changeset
  1071
            g_object_set(G_OBJECT(filter), "caps", gst_caps_new_simple(
hgs
parents: 21
diff changeset
  1072
                    "video/x-raw-yuv", "width", G_TYPE_INT, TEST_VIDEO_WIDTH,
hgs
parents: 21
diff changeset
  1073
                    "height", G_TYPE_INT, TEST_VIDEO_HEIGHT, NULL), NULL);
19
hgs
parents:
diff changeset
  1074
            gst_bin_add(GST_BIN(vpp), filter);
25
hgs
parents: 21
diff changeset
  1075
            }
19
hgs
parents:
diff changeset
  1076
hgs
parents:
diff changeset
  1077
        /* create video queue */
25
hgs
parents: 21
diff changeset
  1078
        queue = gst_element_factory_make("queue", "vpp_queue");
hgs
parents: 21
diff changeset
  1079
        if (queue)
hgs
parents: 21
diff changeset
  1080
            {
19
hgs
parents:
diff changeset
  1081
            gst_bin_add(GST_BIN(vpp), queue);
25
hgs
parents: 21
diff changeset
  1082
            }
19
hgs
parents:
diff changeset
  1083
hgs
parents:
diff changeset
  1084
        /* Crete ffmpegcolorspace to convert stream to correct format */
25
hgs
parents: 21
diff changeset
  1085
        col2 = gst_element_factory_make("ffmpegcolorspace", "pp_colsp2");
hgs
parents: 21
diff changeset
  1086
        if (col2)
hgs
parents: 21
diff changeset
  1087
            {
19
hgs
parents:
diff changeset
  1088
            DEBUG_INFO("Created ffmpegcolorspace element");
hgs
parents:
diff changeset
  1089
            gst_bin_add(GST_BIN(vpp), col2);
hgs
parents:
diff changeset
  1090
            /* make this bin link point*/
25
hgs
parents: 21
diff changeset
  1091
            ghostsrc = gst_element_get_static_pad(col2, "src");
hgs
parents: 21
diff changeset
  1092
            if (ghostsrc)
hgs
parents: 21
diff changeset
  1093
                {
hgs
parents: 21
diff changeset
  1094
                gst_element_add_pad(vpp, gst_ghost_pad_new("videopp_src",
hgs
parents: 21
diff changeset
  1095
                        ghostsrc));
19
hgs
parents:
diff changeset
  1096
                gst_object_unref(GST_OBJECT(ghostsrc));
25
hgs
parents: 21
diff changeset
  1097
                }
19
hgs
parents:
diff changeset
  1098
            }
25
hgs
parents: 21
diff changeset
  1099
        if (!(gst_element_link_many(col1, scale, crop, rotate, mirror, box,
hgs
parents: 21
diff changeset
  1100
                balance, gamma, queue, scale2, filter, col2, NULL)))
hgs
parents: 21
diff changeset
  1101
            {
19
hgs
parents:
diff changeset
  1102
            DEBUG_ERR("Could not link videopp elements!!");
hgs
parents:
diff changeset
  1103
            gst_object_unref(vpp);
hgs
parents:
diff changeset
  1104
            vpp = NULL;
25
hgs
parents: 21
diff changeset
  1105
            }
hgs
parents: 21
diff changeset
  1106
        }DEBUG_API("<-XAAdaptationGst_CreateFixedSizeVideoPP");
19
hgs
parents:
diff changeset
  1107
    return vpp;
25
hgs
parents: 21
diff changeset
  1108
    }
19
hgs
parents:
diff changeset
  1109
hgs
parents:
diff changeset
  1110
/**
hgs
parents:
diff changeset
  1111
 * GstElement* XAAdaptationGst_CreateVideoPPBlackScr( )
hgs
parents:
diff changeset
  1112
 * @return GstElement* - return newly created gst pipeline element
hgs
parents:
diff changeset
  1113
 * Description: Create video processing pipeline for black screen
hgs
parents:
diff changeset
  1114
 */
25
hgs
parents: 21
diff changeset
  1115
GstElement* XAAdaptationGst_CreateVideoPPBlackScr()
hgs
parents: 21
diff changeset
  1116
    {
19
hgs
parents:
diff changeset
  1117
    GstElement *vppBScr;
hgs
parents:
diff changeset
  1118
    DEBUG_API("->XAAdaptationGst_CreateVideoPPBlackScr");
hgs
parents:
diff changeset
  1119
    vppBScr = gst_pipeline_new("videoppBScr");
25
hgs
parents: 21
diff changeset
  1120
    if (vppBScr)
hgs
parents: 21
diff changeset
  1121
        {
hgs
parents: 21
diff changeset
  1122
        GstPad *ghostsrc = NULL;
hgs
parents: 21
diff changeset
  1123
        GstElement *testVideo = NULL, *scale = NULL;
hgs
parents: 21
diff changeset
  1124
        GstElement *ffmpegcolorspace = NULL;
19
hgs
parents:
diff changeset
  1125
25
hgs
parents: 21
diff changeset
  1126
        testVideo = gst_element_factory_make("videotestsrc", "videotest");
hgs
parents: 21
diff changeset
  1127
        if (testVideo)
hgs
parents: 21
diff changeset
  1128
            {
19
hgs
parents:
diff changeset
  1129
            DEBUG_INFO("Created videotestsrc element");
hgs
parents:
diff changeset
  1130
25
hgs
parents: 21
diff changeset
  1131
            g_object_set(G_OBJECT(testVideo), "pattern", (gint) 2,
hgs
parents: 21
diff changeset
  1132
                    "num-buffers", (gint) 1, NULL);
19
hgs
parents:
diff changeset
  1133
            gst_bin_add(GST_BIN(vppBScr), testVideo);
25
hgs
parents: 21
diff changeset
  1134
            }
19
hgs
parents:
diff changeset
  1135
hgs
parents:
diff changeset
  1136
        scale = gst_element_factory_make("videoscale", "BSrc_scale");
25
hgs
parents: 21
diff changeset
  1137
        if (scale)
hgs
parents: 21
diff changeset
  1138
            {
19
hgs
parents:
diff changeset
  1139
            DEBUG_INFO("Created videoscale element");
hgs
parents:
diff changeset
  1140
            gst_bin_add(GST_BIN(vppBScr), scale);
hgs
parents:
diff changeset
  1141
            /* make this bin link point*/
25
hgs
parents: 21
diff changeset
  1142
            ghostsrc = gst_element_get_static_pad(scale, "src");
hgs
parents: 21
diff changeset
  1143
            if (ghostsrc)
hgs
parents: 21
diff changeset
  1144
                {
hgs
parents: 21
diff changeset
  1145
                gst_element_add_pad(vppBScr, gst_ghost_pad_new(
hgs
parents: 21
diff changeset
  1146
                        "videoppBSrc_src", ghostsrc));
19
hgs
parents:
diff changeset
  1147
                gst_object_unref(GST_OBJECT(ghostsrc));
25
hgs
parents: 21
diff changeset
  1148
                }
19
hgs
parents:
diff changeset
  1149
            }
25
hgs
parents: 21
diff changeset
  1150
        ffmpegcolorspace = gst_element_factory_make("ffmpegcolorspace",
hgs
parents: 21
diff changeset
  1151
                "BlackScrFfmpeg");
19
hgs
parents:
diff changeset
  1152
        gst_bin_add(GST_BIN(vppBScr), ffmpegcolorspace);
25
hgs
parents: 21
diff changeset
  1153
        if (!(gst_element_link_many(testVideo, ffmpegcolorspace, scale, NULL)))
hgs
parents: 21
diff changeset
  1154
            {
19
hgs
parents:
diff changeset
  1155
            DEBUG_ERR("Could not link videoppBSrc elements!!");
hgs
parents:
diff changeset
  1156
            gst_object_unref(vppBScr);
hgs
parents:
diff changeset
  1157
            vppBScr = NULL;
25
hgs
parents: 21
diff changeset
  1158
            }
hgs
parents: 21
diff changeset
  1159
        }DEBUG_API("<-XAAdaptationGst_CreateVideoPPBlackScr");
hgs
parents: 21
diff changeset
  1160
    return vppBScr;
19
hgs
parents:
diff changeset
  1161
    }
hgs
parents:
diff changeset
  1162
hgs
parents:
diff changeset
  1163
/**
hgs
parents:
diff changeset
  1164
 * GstElement* XAAdaptationGst_CreateInputSelector( )
hgs
parents:
diff changeset
  1165
 * @return GstElement* - return newly created input selector
hgs
parents:
diff changeset
  1166
 * Description: Create input selector to processing between black screen and video screen
hgs
parents:
diff changeset
  1167
 */
25
hgs
parents: 21
diff changeset
  1168
GstElement* XAAdaptationGst_CreateInputSelector()
hgs
parents: 21
diff changeset
  1169
    {
19
hgs
parents:
diff changeset
  1170
    GstElement *inputSelector;
hgs
parents:
diff changeset
  1171
    DEBUG_API("->XAAdaptationGst_CreateInputSelector");
25
hgs
parents: 21
diff changeset
  1172
    inputSelector = gst_element_factory_make("input-selector",
hgs
parents: 21
diff changeset
  1173
            "input-selector");
hgs
parents: 21
diff changeset
  1174
    if (inputSelector)
hgs
parents: 21
diff changeset
  1175
        {
19
hgs
parents:
diff changeset
  1176
        g_object_set(G_OBJECT(inputSelector), "select-all", TRUE, NULL);
25
hgs
parents: 21
diff changeset
  1177
        }DEBUG_API("<-XAAdaptationGst_CreateInputSelector");
hgs
parents: 21
diff changeset
  1178
    return inputSelector;
19
hgs
parents:
diff changeset
  1179
    }
hgs
parents:
diff changeset
  1180
hgs
parents:
diff changeset
  1181
/**
hgs
parents:
diff changeset
  1182
 * GstElement* XAAdaptationGst_CreateAudioPP( )
hgs
parents:
diff changeset
  1183
 * @return GstElement* - return newly created gst pipeline element
hgs
parents:
diff changeset
  1184
 * Description: Create video processing pipeline
hgs
parents:
diff changeset
  1185
 */
25
hgs
parents: 21
diff changeset
  1186
GstElement* XAAdaptationGst_CreateAudioPP()
hgs
parents: 21
diff changeset
  1187
    {
19
hgs
parents:
diff changeset
  1188
    GstElement *app;
hgs
parents:
diff changeset
  1189
    gboolean ok = TRUE;
hgs
parents:
diff changeset
  1190
    DEBUG_API("->XAAdaptationGst_CreateAudioPP");
hgs
parents:
diff changeset
  1191
    app = gst_pipeline_new("audiopp");
25
hgs
parents: 21
diff changeset
  1192
    if (app)
hgs
parents: 21
diff changeset
  1193
        {
19
hgs
parents:
diff changeset
  1194
        GstPad *ghostsink, *ghostsrc;
25
hgs
parents: 21
diff changeset
  1195
        GstElement *ac, *vol, *eq, *queue, *pan, *ac2;
19
hgs
parents:
diff changeset
  1196
25
hgs
parents: 21
diff changeset
  1197
        /* first and last elements should be audioconverts to
hgs
parents: 21
diff changeset
  1198
         *  match sink and encoder formats */
hgs
parents: 21
diff changeset
  1199
        ac = gst_element_factory_make("audioconvert", "pp_ac");
19
hgs
parents:
diff changeset
  1200
        if (ac)
25
hgs
parents: 21
diff changeset
  1201
            {
19
hgs
parents:
diff changeset
  1202
            ok = gst_bin_add(GST_BIN(app), ac);
hgs
parents:
diff changeset
  1203
            /* make this bin link point*/
hgs
parents:
diff changeset
  1204
            if (ok)
25
hgs
parents: 21
diff changeset
  1205
                {
hgs
parents: 21
diff changeset
  1206
                ghostsink = gst_element_get_static_pad(ac, "sink");
hgs
parents: 21
diff changeset
  1207
                ok = gst_element_add_pad(app, gst_ghost_pad_new("sink",
hgs
parents: 21
diff changeset
  1208
                        ghostsink));
19
hgs
parents:
diff changeset
  1209
                gst_object_unref(GST_OBJECT(ghostsink));
25
hgs
parents: 21
diff changeset
  1210
                }
19
hgs
parents:
diff changeset
  1211
            }
25
hgs
parents: 21
diff changeset
  1212
        ac2 = gst_element_factory_make("audioconvert", "pp_ac2");
19
hgs
parents:
diff changeset
  1213
        if (ac2 && ok)
25
hgs
parents: 21
diff changeset
  1214
            {
19
hgs
parents:
diff changeset
  1215
            ok = gst_bin_add(GST_BIN(app), ac2);
hgs
parents:
diff changeset
  1216
            /* make this bin link point*/
hgs
parents:
diff changeset
  1217
            if (ok)
25
hgs
parents: 21
diff changeset
  1218
                {
hgs
parents: 21
diff changeset
  1219
                ghostsrc = gst_element_get_static_pad(ac2, "src");
hgs
parents: 21
diff changeset
  1220
                ok = gst_element_add_pad(app, gst_ghost_pad_new("src",
hgs
parents: 21
diff changeset
  1221
                        ghostsrc));
hgs
parents: 21
diff changeset
  1222
                gst_object_unref(GST_OBJECT(ghostsrc));
hgs
parents: 21
diff changeset
  1223
                }
hgs
parents: 21
diff changeset
  1224
            }
hgs
parents: 21
diff changeset
  1225
hgs
parents: 21
diff changeset
  1226
        vol = gst_element_factory_make("volume", "pp_vol");
hgs
parents: 21
diff changeset
  1227
        /* create volume controller */
hgs
parents: 21
diff changeset
  1228
        if (vol && ok)
19
hgs
parents:
diff changeset
  1229
            {
25
hgs
parents: 21
diff changeset
  1230
            ok = gst_bin_add(GST_BIN(app), vol);
hgs
parents: 21
diff changeset
  1231
            g_object_set(G_OBJECT(vol), "volume", (gdouble) 1, NULL);
hgs
parents: 21
diff changeset
  1232
            }
hgs
parents: 21
diff changeset
  1233
        /* create 10-band equalizer */
hgs
parents: 21
diff changeset
  1234
        eq = gst_element_factory_make("equalizer-10bands", "pp_equ");
hgs
parents: 21
diff changeset
  1235
        if (eq && ok)
hgs
parents: 21
diff changeset
  1236
            {
hgs
parents: 21
diff changeset
  1237
            ok = gst_bin_add(GST_BIN(app), eq);
hgs
parents: 21
diff changeset
  1238
            }
hgs
parents: 21
diff changeset
  1239
        /* create audio queue */
hgs
parents: 21
diff changeset
  1240
        queue = gst_element_factory_make("queue", "app_queue");
hgs
parents: 21
diff changeset
  1241
        if (queue && ok)
hgs
parents: 21
diff changeset
  1242
            {
hgs
parents: 21
diff changeset
  1243
            ok = gst_bin_add(GST_BIN(app), queue);
hgs
parents: 21
diff changeset
  1244
            g_object_set(G_OBJECT (queue), "max-size-buffers", 2, NULL);
hgs
parents: 21
diff changeset
  1245
            }
hgs
parents: 21
diff changeset
  1246
        /* create audio pan effect */
hgs
parents: 21
diff changeset
  1247
        pan = gst_element_factory_make("audiopanorama", "pp_pan");
hgs
parents: 21
diff changeset
  1248
        if (pan && ok)
hgs
parents: 21
diff changeset
  1249
            {
hgs
parents: 21
diff changeset
  1250
            ok = gst_bin_add(GST_BIN(app), pan);
hgs
parents: 21
diff changeset
  1251
            }
hgs
parents: 21
diff changeset
  1252
hgs
parents: 21
diff changeset
  1253
        if (ac && ok)
hgs
parents: 21
diff changeset
  1254
            {
hgs
parents: 21
diff changeset
  1255
            if (queue)
hgs
parents: 21
diff changeset
  1256
                {
hgs
parents: 21
diff changeset
  1257
                ok = gst_element_link(ac, queue);
hgs
parents: 21
diff changeset
  1258
                }
hgs
parents: 21
diff changeset
  1259
            else if (vol)
hgs
parents: 21
diff changeset
  1260
                {
hgs
parents: 21
diff changeset
  1261
                ok = gst_element_link(ac, vol);
hgs
parents: 21
diff changeset
  1262
                }
hgs
parents: 21
diff changeset
  1263
            else if (pan)
hgs
parents: 21
diff changeset
  1264
                {
hgs
parents: 21
diff changeset
  1265
                ok = gst_element_link(ac, pan);
hgs
parents: 21
diff changeset
  1266
                }
hgs
parents: 21
diff changeset
  1267
            else if (eq)
hgs
parents: 21
diff changeset
  1268
                {
hgs
parents: 21
diff changeset
  1269
                ok = gst_element_link(ac, eq);
hgs
parents: 21
diff changeset
  1270
                }
hgs
parents: 21
diff changeset
  1271
            else if (ac2)
hgs
parents: 21
diff changeset
  1272
                {
hgs
parents: 21
diff changeset
  1273
                ok = gst_element_link(ac, ac2);
hgs
parents: 21
diff changeset
  1274
                }
hgs
parents: 21
diff changeset
  1275
            }
hgs
parents: 21
diff changeset
  1276
        if (queue && ok)
hgs
parents: 21
diff changeset
  1277
            {
hgs
parents: 21
diff changeset
  1278
            if (vol)
hgs
parents: 21
diff changeset
  1279
                {
hgs
parents: 21
diff changeset
  1280
                ok = gst_element_link(queue, vol);
hgs
parents: 21
diff changeset
  1281
                }
hgs
parents: 21
diff changeset
  1282
            else if (pan)
hgs
parents: 21
diff changeset
  1283
                {
hgs
parents: 21
diff changeset
  1284
                ok = gst_element_link(queue, pan);
hgs
parents: 21
diff changeset
  1285
                }
hgs
parents: 21
diff changeset
  1286
            else if (eq)
hgs
parents: 21
diff changeset
  1287
                {
hgs
parents: 21
diff changeset
  1288
                ok = gst_element_link(queue, eq);
hgs
parents: 21
diff changeset
  1289
                }
hgs
parents: 21
diff changeset
  1290
            else if (ac2)
hgs
parents: 21
diff changeset
  1291
                {
hgs
parents: 21
diff changeset
  1292
                ok = gst_element_link(queue, ac2);
hgs
parents: 21
diff changeset
  1293
                }
hgs
parents: 21
diff changeset
  1294
            }
hgs
parents: 21
diff changeset
  1295
        if (vol && ok)
hgs
parents: 21
diff changeset
  1296
            {
hgs
parents: 21
diff changeset
  1297
            if (pan)
hgs
parents: 21
diff changeset
  1298
                {
hgs
parents: 21
diff changeset
  1299
                ok = gst_element_link(vol, pan);
hgs
parents: 21
diff changeset
  1300
                }
hgs
parents: 21
diff changeset
  1301
            else if (eq)
hgs
parents: 21
diff changeset
  1302
                {
hgs
parents: 21
diff changeset
  1303
                ok = gst_element_link(vol, eq);
hgs
parents: 21
diff changeset
  1304
                }
hgs
parents: 21
diff changeset
  1305
            else if (ac2)
hgs
parents: 21
diff changeset
  1306
                {
hgs
parents: 21
diff changeset
  1307
                ok = gst_element_link(vol, ac2);
hgs
parents: 21
diff changeset
  1308
                }
hgs
parents: 21
diff changeset
  1309
            }
hgs
parents: 21
diff changeset
  1310
        if (pan && ok)
hgs
parents: 21
diff changeset
  1311
            {
hgs
parents: 21
diff changeset
  1312
            if (eq)
hgs
parents: 21
diff changeset
  1313
                {
hgs
parents: 21
diff changeset
  1314
                ok = gst_element_link(pan, eq);
hgs
parents: 21
diff changeset
  1315
                }
hgs
parents: 21
diff changeset
  1316
            else if (ac2)
hgs
parents: 21
diff changeset
  1317
                {
hgs
parents: 21
diff changeset
  1318
                ok = gst_element_link(pan, ac2);
hgs
parents: 21
diff changeset
  1319
                }
hgs
parents: 21
diff changeset
  1320
            }
hgs
parents: 21
diff changeset
  1321
        if (eq && ok)
hgs
parents: 21
diff changeset
  1322
            {
hgs
parents: 21
diff changeset
  1323
            if (ac2)
hgs
parents: 21
diff changeset
  1324
                {
hgs
parents: 21
diff changeset
  1325
                ok = gst_element_link(eq, ac2);
hgs
parents: 21
diff changeset
  1326
                }
hgs
parents: 21
diff changeset
  1327
            }
hgs
parents: 21
diff changeset
  1328
hgs
parents: 21
diff changeset
  1329
        if (ac)
hgs
parents: 21
diff changeset
  1330
            {
hgs
parents: 21
diff changeset
  1331
            // ghost sink above
hgs
parents: 21
diff changeset
  1332
            }
hgs
parents: 21
diff changeset
  1333
        else if (queue && ok)
hgs
parents: 21
diff changeset
  1334
            {
hgs
parents: 21
diff changeset
  1335
            /* make this bin link point*/
hgs
parents: 21
diff changeset
  1336
            ghostsink = gst_element_get_static_pad(queue, "sink");
hgs
parents: 21
diff changeset
  1337
            ok = gst_element_add_pad(app,
hgs
parents: 21
diff changeset
  1338
                    gst_ghost_pad_new("sink", ghostsink));
hgs
parents: 21
diff changeset
  1339
            gst_object_unref(GST_OBJECT(ghostsink));
hgs
parents: 21
diff changeset
  1340
            }
hgs
parents: 21
diff changeset
  1341
        else if (vol && ok)
hgs
parents: 21
diff changeset
  1342
            {
hgs
parents: 21
diff changeset
  1343
            /* make this bin link point*/
hgs
parents: 21
diff changeset
  1344
            ghostsink = gst_element_get_static_pad(vol, "sink");
hgs
parents: 21
diff changeset
  1345
            ok = gst_element_add_pad(app,
hgs
parents: 21
diff changeset
  1346
                    gst_ghost_pad_new("sink", ghostsink));
hgs
parents: 21
diff changeset
  1347
            gst_object_unref(GST_OBJECT(ghostsink));
hgs
parents: 21
diff changeset
  1348
            }
hgs
parents: 21
diff changeset
  1349
        else if (pan && ok)
hgs
parents: 21
diff changeset
  1350
            {
hgs
parents: 21
diff changeset
  1351
            /* make this bin link point*/
hgs
parents: 21
diff changeset
  1352
            ghostsink = gst_element_get_static_pad(pan, "sink");
hgs
parents: 21
diff changeset
  1353
            ok = gst_element_add_pad(app,
hgs
parents: 21
diff changeset
  1354
                    gst_ghost_pad_new("sink", ghostsink));
hgs
parents: 21
diff changeset
  1355
            gst_object_unref(GST_OBJECT(ghostsink));
hgs
parents: 21
diff changeset
  1356
            }
hgs
parents: 21
diff changeset
  1357
        else if (eq && ok)
hgs
parents: 21
diff changeset
  1358
            {
hgs
parents: 21
diff changeset
  1359
            /* make this bin link point*/
hgs
parents: 21
diff changeset
  1360
            ghostsink = gst_element_get_static_pad(eq, "sink");
hgs
parents: 21
diff changeset
  1361
            ok = gst_element_add_pad(app,
hgs
parents: 21
diff changeset
  1362
                    gst_ghost_pad_new("sink", ghostsink));
hgs
parents: 21
diff changeset
  1363
            gst_object_unref(GST_OBJECT(ghostsink));
hgs
parents: 21
diff changeset
  1364
            }
hgs
parents: 21
diff changeset
  1365
        else if (ac2 && ok)
hgs
parents: 21
diff changeset
  1366
            {
hgs
parents: 21
diff changeset
  1367
            /* make this bin link point*/
hgs
parents: 21
diff changeset
  1368
            ghostsink = gst_element_get_static_pad(ac2, "sink");
hgs
parents: 21
diff changeset
  1369
            ok = gst_element_add_pad(app,
hgs
parents: 21
diff changeset
  1370
                    gst_ghost_pad_new("sink", ghostsink));
hgs
parents: 21
diff changeset
  1371
            gst_object_unref(GST_OBJECT(ghostsink));
hgs
parents: 21
diff changeset
  1372
            }
hgs
parents: 21
diff changeset
  1373
hgs
parents: 21
diff changeset
  1374
        if (ac2)
hgs
parents: 21
diff changeset
  1375
            {
hgs
parents: 21
diff changeset
  1376
            // ghost src above
hgs
parents: 21
diff changeset
  1377
            }
hgs
parents: 21
diff changeset
  1378
        else if (eq && ok)
hgs
parents: 21
diff changeset
  1379
            {
hgs
parents: 21
diff changeset
  1380
            /* make this bin link point*/
hgs
parents: 21
diff changeset
  1381
            ghostsrc = gst_element_get_static_pad(eq, "src");
hgs
parents: 21
diff changeset
  1382
            ok = gst_element_add_pad(app, gst_ghost_pad_new("src", ghostsrc));
hgs
parents: 21
diff changeset
  1383
            gst_object_unref(GST_OBJECT(ghostsrc));
hgs
parents: 21
diff changeset
  1384
            }
hgs
parents: 21
diff changeset
  1385
        else if (pan && ok)
hgs
parents: 21
diff changeset
  1386
            {
hgs
parents: 21
diff changeset
  1387
            /* make this bin link point*/
hgs
parents: 21
diff changeset
  1388
            ghostsrc = gst_element_get_static_pad(pan, "src");
hgs
parents: 21
diff changeset
  1389
            ok = gst_element_add_pad(app, gst_ghost_pad_new("src", ghostsrc));
hgs
parents: 21
diff changeset
  1390
            gst_object_unref(GST_OBJECT(ghostsrc));
hgs
parents: 21
diff changeset
  1391
            }
hgs
parents: 21
diff changeset
  1392
        else if (vol && ok)
hgs
parents: 21
diff changeset
  1393
            {
hgs
parents: 21
diff changeset
  1394
            /* make this bin link point*/
hgs
parents: 21
diff changeset
  1395
            ghostsrc = gst_element_get_static_pad(vol, "src");
hgs
parents: 21
diff changeset
  1396
            ok = gst_element_add_pad(app, gst_ghost_pad_new("src", ghostsrc));
hgs
parents: 21
diff changeset
  1397
            gst_object_unref(GST_OBJECT(ghostsrc));
hgs
parents: 21
diff changeset
  1398
            }
hgs
parents: 21
diff changeset
  1399
        else if (queue && ok)
hgs
parents: 21
diff changeset
  1400
            {
hgs
parents: 21
diff changeset
  1401
            /* make this bin link point*/
hgs
parents: 21
diff changeset
  1402
            ghostsrc = gst_element_get_static_pad(queue, "src");
hgs
parents: 21
diff changeset
  1403
            ok = gst_element_add_pad(app, gst_ghost_pad_new("src", ghostsrc));
hgs
parents: 21
diff changeset
  1404
            gst_object_unref(GST_OBJECT(ghostsrc));
hgs
parents: 21
diff changeset
  1405
            }
hgs
parents: 21
diff changeset
  1406
        else if (ac && ok)
hgs
parents: 21
diff changeset
  1407
            {
hgs
parents: 21
diff changeset
  1408
            /* make this bin link point*/
hgs
parents: 21
diff changeset
  1409
            ghostsrc = gst_element_get_static_pad(ac, "src");
hgs
parents: 21
diff changeset
  1410
            ok = gst_element_add_pad(app, gst_ghost_pad_new("src", ghostsrc));
hgs
parents: 21
diff changeset
  1411
            gst_object_unref(GST_OBJECT(ghostsrc));
hgs
parents: 21
diff changeset
  1412
            }
hgs
parents: 21
diff changeset
  1413
hgs
parents: 21
diff changeset
  1414
        //        if( !(gst_element_link_many(ac, queue, vol, ac2, NULL)) )
hgs
parents: 21
diff changeset
  1415
        //        if( !(gst_element_link_many(ac, queue, vol, pan, eq, ac2, NULL)) )
hgs
parents: 21
diff changeset
  1416
        if (!ok)
hgs
parents: 21
diff changeset
  1417
            {
hgs
parents: 21
diff changeset
  1418
            DEBUG_ERR("Could not link audiopp elements!!");
hgs
parents: 21
diff changeset
  1419
            gst_object_unref(app);
hgs
parents: 21
diff changeset
  1420
            app = NULL;
19
hgs
parents:
diff changeset
  1421
            }
hgs
parents:
diff changeset
  1422
        }
hgs
parents:
diff changeset
  1423
25
hgs
parents: 21
diff changeset
  1424
    DEBUG_API("<-XAAdaptationGst_CreateAudioPP");
hgs
parents: 21
diff changeset
  1425
    return app;
19
hgs
parents:
diff changeset
  1426
    }
hgs
parents:
diff changeset
  1427
hgs
parents:
diff changeset
  1428
/* called when pad is actually blocking/ gets unblocked*/
25
hgs
parents: 21
diff changeset
  1429
void XAAdaptationGst_PadBlockCb(GstPad *pad, gboolean blocked,
hgs
parents: 21
diff changeset
  1430
        gpointer user_data)
hgs
parents: 21
diff changeset
  1431
    {
19
hgs
parents:
diff changeset
  1432
    DEBUG_API_A2("->XAAdaptationGst_PadBlockCb   pad \"%s\" of \"%s\" ",
25
hgs
parents: 21
diff changeset
  1433
            GST_OBJECT_NAME(pad),
hgs
parents: 21
diff changeset
  1434
            GST_OBJECT_NAME(gst_pad_get_parent_element(pad)) );
19
hgs
parents:
diff changeset
  1435
    DEBUG_API_A1("<-XAAdaptationGst_PadBlockCb   blocked:%d",blocked);
25
hgs
parents: 21
diff changeset
  1436
    }
19
hgs
parents:
diff changeset
  1437
hgs
parents:
diff changeset
  1438
/* utility to set same fields for all media types in caps */
25
hgs
parents: 21
diff changeset
  1439
void XAAdaptationGst_SetAllCaps(GstCaps * caps, char *field, ...)
hgs
parents: 21
diff changeset
  1440
    {
19
hgs
parents:
diff changeset
  1441
    GstStructure *structure;
hgs
parents:
diff changeset
  1442
    va_list var_args;
hgs
parents:
diff changeset
  1443
    int i;
hgs
parents:
diff changeset
  1444
25
hgs
parents: 21
diff changeset
  1445
    for (i = 0; i < gst_caps_get_size(caps); i++)
hgs
parents: 21
diff changeset
  1446
        {
hgs
parents: 21
diff changeset
  1447
        structure = gst_caps_get_structure(caps, i);
19
hgs
parents:
diff changeset
  1448
        va_start (var_args, field);
25
hgs
parents: 21
diff changeset
  1449
        gst_structure_set_valist(structure, field, var_args);
19
hgs
parents:
diff changeset
  1450
        va_end (var_args);
25
hgs
parents: 21
diff changeset
  1451
        }
19
hgs
parents:
diff changeset
  1452
    }
hgs
parents:
diff changeset
  1453