khronosfws/openmax_al/src/adaptation/xaoutputmixadaptctx.c
changeset 33 5e8b14bae8c3
parent 28 ebf79c79991a
child 36 73253677b50a
equal deleted inserted replaced
28:ebf79c79991a 33:5e8b14bae8c3
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <gst.h>
       
    19 #include "XAOutputMixAdaptCtx.h"
       
    20 #include "XAAdaptation.h"
       
    21 #include "XAStaticCapsAdaptation.h"
       
    22 
       
    23 
       
    24 /*
       
    25  * XAAdaptationBaseCtx* XAOutputMixAdapt_Create()
       
    26  * @returns XAOutputMixAdaptationCtx* - Pointer to created context
       
    27  * Description: Allocates memory for Output Mix Adaptation Context and makes 1st phase initialization
       
    28  */
       
    29 XAAdaptationBaseCtx* XAOutputMixAdapt_Create()
       
    30 {
       
    31     XAOutputMixAdaptationCtx *pSelf = calloc(1, sizeof(XAOutputMixAdaptationCtx));
       
    32 
       
    33     DEBUG_API("->XAOutputMixAdapt_Create");
       
    34     if ( pSelf)
       
    35     {
       
    36         if( XAAdaptationBase_Init(&(pSelf->baseObj),XAOutputMixAdaptation)
       
    37                     != XA_RESULT_SUCCESS )
       
    38         {
       
    39             DEBUG_ERR("Failed to init base context!!!");
       
    40             free(pSelf);
       
    41             pSelf = NULL;
       
    42         }
       
    43         else
       
    44         {
       
    45             XAuint32 devId;
       
    46             pSelf->connectedObjects = g_array_new (FALSE, TRUE, sizeof (XAOMixAdaptConnObj));
       
    47             pSelf->availableDevices = g_array_new (FALSE, TRUE, sizeof (XAuint32));
       
    48             /*initially, only alsasink available*/
       
    49 //            devId = XA_ADAPTID_ALSASINK;
       
    50             devId = XA_ADAPTID_DEVSOUNDSINK;
       
    51             g_array_append_val(pSelf->availableDevices, devId);
       
    52             pSelf->currentrouting = devId;
       
    53         }
       
    54     }
       
    55     DEBUG_API("<-XAOutputMixAdapt_Create");
       
    56     return (XAAdaptationBaseCtx* )pSelf;
       
    57 }
       
    58 
       
    59 /*
       
    60  * XAresult XAOutputMixAdapt_PostInit(XAAdaptationBaseCtx* bCtx)
       
    61  * 2nd phase initialization of Output Mix Adaptation Context
       
    62  */
       
    63 XAresult XAOutputMixAdapt_PostInit(XAAdaptationBaseCtx* bCtx)
       
    64 {
       
    65     XAOutputMixAdaptationCtx* ctx = NULL;
       
    66 
       
    67     DEBUG_API("->XAOutputMixAdapt_PostInit");
       
    68     if(bCtx == NULL || bCtx->ctxId != XAOutputMixAdaptation )
       
    69     {
       
    70         DEBUG_ERR("Invalid parameter!!");
       
    71         DEBUG_API("<-XAOutputMixAdapt_PostInit");
       
    72         return XA_RESULT_PARAMETER_INVALID;
       
    73     }
       
    74     ctx = (XAOutputMixAdaptationCtx*)bCtx;
       
    75 
       
    76     /* check and add devices to pSelf->availableDevices if such detection can be done */
       
    77     DEBUG_API("<-XAOutputMixAdapt_PostInit");
       
    78     return XA_RESULT_SUCCESS;
       
    79 }
       
    80 
       
    81 /*
       
    82  * void XAOutputMixAdapt_Destroy(XAAdaptationBaseCtx* bCtx)
       
    83  * Destroys Output Mix Adaptation Context
       
    84  * @param ctx - Output Mix Adaptation context to be destroyed
       
    85  */
       
    86 void XAOutputMixAdapt_Destroy(XAAdaptationBaseCtx* bCtx)
       
    87 {
       
    88     XAOutputMixAdaptationCtx* ctx = NULL;
       
    89     DEBUG_API("->XAOutputMixAdapt_Destroy");
       
    90     if(bCtx == NULL || bCtx->ctxId != XAOutputMixAdaptation )
       
    91     {
       
    92         DEBUG_ERR("Invalid parameter!!");
       
    93         DEBUG_API("<-XAOutputMixAdapt_Destroy");
       
    94         return;
       
    95     }
       
    96     ctx = (XAOutputMixAdaptationCtx*)bCtx;
       
    97     g_array_free(ctx->connectedObjects, TRUE);
       
    98     g_array_free(ctx->availableDevices, TRUE);
       
    99 
       
   100     XAAdaptationBase_Free( &(ctx->baseObj) );
       
   101     free(ctx);
       
   102     DEBUG_API("<-XAOutputMixAdapt_Destroy");
       
   103 }
       
   104 
       
   105 /*
       
   106  * GstElement* XAOutputMixAdapt_GetSink(XAAdaptationBaseCtx* bCtx)
       
   107  */
       
   108 GstElement* XAOutputMixAdapt_GetSink(XAAdaptationBaseCtx* bCtx)
       
   109 {
       
   110     XAOutputMixAdaptationCtx* mixCtx = NULL;
       
   111     /* create sink for current routing */
       
   112     GstElement* newsink=NULL;
       
   113     XAStaticCapsData temp;
       
   114 
       
   115     DEBUG_API("->XAOutputMixAdapt_GetSink");
       
   116     if(bCtx == NULL || bCtx->ctxId != XAOutputMixAdaptation )
       
   117     {
       
   118         DEBUG_ERR("Invalid parameter!!");
       
   119         DEBUG_API("<-XAOutputMixAdapt_GetSink");
       
   120         return NULL;
       
   121     }
       
   122     mixCtx = (XAOutputMixAdaptationCtx*)bCtx;
       
   123 
       
   124     if(!mixCtx)
       
   125     {
       
   126         DEBUG_ERR("NULL context!");
       
   127         return NULL;
       
   128     }
       
   129 
       
   130     if( XA_RESULT_SUCCESS ==
       
   131         XAStaticCapsAdapt_GetCapsById(XACAP_DEVSNK|XACAP_AUDIO, mixCtx->currentrouting, &temp) )
       
   132     {
       
   133         newsink = gst_element_factory_make((char*)temp.adaptId,(char*)temp.adaptId);
       
   134         if(!newsink)
       
   135         {
       
   136             DEBUG_ERR_A1("Could not create sink \"%s\"!", (char*)temp.adaptId);
       
   137         }
       
   138     }
       
   139     else
       
   140     {
       
   141         DEBUG_ERR_A1("Could not find audio device by id 0x%x", (int)mixCtx->currentrouting);
       
   142     }
       
   143     DEBUG_API("<-XAOutputMixAdapt_GetSink");
       
   144     return newsink;
       
   145 
       
   146 }
       
   147 
       
   148 /*
       
   149  * XAresult XAOutputMixAdapt_ConnectObject(XAAdaptationBaseCtx* omCtx, XAAdaptationBaseCtx* bCtx, GstElement* usedMix)
       
   150  */
       
   151 XAresult XAOutputMixAdapt_ConnectObject(XAAdaptationBaseCtx* omCtx, XAAdaptationBaseCtx* bCtx, GstElement* usedMix)
       
   152 {
       
   153     XAresult ret = XA_RESULT_SUCCESS;
       
   154     XAuint32 i=0;
       
   155     XAOutputMixAdaptationCtx* mixCtx =NULL;
       
   156     DEBUG_API("->XAOutputMixAdapt_ConnectObject");
       
   157     if( !omCtx || omCtx->ctxId!=XAOutputMixAdaptation || !bCtx || !usedMix )
       
   158     {
       
   159         DEBUG_ERR("Invalid attribute!!");
       
   160         DEBUG_API("<-XAOutputMixAdapt_ConnectObject");
       
   161         return XA_RESULT_PARAMETER_INVALID;
       
   162     }
       
   163     mixCtx = (XAOutputMixAdaptationCtx*)omCtx;
       
   164     if( !mixCtx || !bCtx || !usedMix )
       
   165     {
       
   166         DEBUG_ERR("Invalid attribute!!");
       
   167         DEBUG_API("<-XAOutputMixAdapt_DisconnectObject");
       
   168         return XA_RESULT_PARAMETER_INVALID;
       
   169     }
       
   170     for(i=0; i<mixCtx->connectedObjects->len; i++)
       
   171     {
       
   172         if( (g_array_index(mixCtx->connectedObjects, XAOMixAdaptConnObj, i)).ctx == bCtx )
       
   173         {
       
   174             /*item found already*/
       
   175             ret = XA_RESULT_PARAMETER_INVALID;
       
   176             break;
       
   177         }
       
   178     }
       
   179     if(i==mixCtx->connectedObjects->len)
       
   180     {
       
   181         XAOMixAdaptConnObj tmp;
       
   182         tmp.ctx= bCtx;
       
   183         tmp.currentSink = usedMix;
       
   184         g_array_append_val(mixCtx->connectedObjects, tmp);
       
   185     }
       
   186 
       
   187     DEBUG_API("<-XAOutputMixAdapt_ConnectObject");
       
   188     return ret;
       
   189 }
       
   190 
       
   191 /*
       
   192  * XAresult XAOutputMixAdapt_DisconnectObject(XAAdaptationBaseCtx* omCtx, XAAdaptationBaseCtx* bCtx)
       
   193  */
       
   194 XAresult XAOutputMixAdapt_DisconnectObject(XAAdaptationBaseCtx* omCtx, XAAdaptationBaseCtx* bCtx)
       
   195 {
       
   196     XAuint32 i=0;
       
   197     XAOutputMixAdaptationCtx* mixCtx =NULL;
       
   198     DEBUG_API("->XAOutputMixAdapt_DisconnectObject");
       
   199 
       
   200     if( !omCtx || omCtx->ctxId!=XAOutputMixAdaptation || !bCtx )
       
   201     {
       
   202         DEBUG_ERR("Invalid attribute!!");
       
   203         DEBUG_API("<-XAOutputMixAdapt_DisconnectObject");
       
   204         return XA_RESULT_PARAMETER_INVALID;
       
   205     }
       
   206     mixCtx = (XAOutputMixAdaptationCtx*)omCtx;
       
   207 
       
   208     if( !mixCtx || !bCtx )
       
   209     {
       
   210         DEBUG_ERR("Invalid attribute!!");
       
   211         DEBUG_API("<-XAOutputMixAdapt_DisconnectObject");
       
   212         return XA_RESULT_PARAMETER_INVALID;
       
   213     }
       
   214     for(i=0; i<mixCtx->connectedObjects->len; i++)
       
   215     {
       
   216         XAOMixAdaptConnObj* tmp = &(g_array_index(mixCtx->connectedObjects, XAOMixAdaptConnObj, i));
       
   217         if( tmp->ctx == bCtx  )
       
   218         {
       
   219             g_array_remove_index(mixCtx->connectedObjects, i);
       
   220             DEBUG_API("<-XAOutputMixAdapt_DisconnectObject");
       
   221             return XA_RESULT_SUCCESS;
       
   222         }
       
   223     }
       
   224     /*did not find, return error*/
       
   225     DEBUG_ERR("Object not found!");
       
   226     DEBUG_API("<-XAOutputMixAdapt_DisconnectObject");
       
   227     return XA_RESULT_PARAMETER_INVALID;
       
   228 }
       
   229