19
|
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 |
|
20
|
18 |
#include <gst/gst.h>
|
19
|
19 |
#include "xaoutputmixadaptctx.h"
|
|
20 |
#include "xaadaptationgst.h"
|
|
21 |
#include "xacapabilitiesmgr.h"
|
|
22 |
|
|
23 |
|
|
24 |
/*
|
|
25 |
* XAAdaptationGstCtx* 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 = (XAOutputMixAdaptationCtx*)calloc(1, sizeof(XAOutputMixAdaptationCtx));
|
|
32 |
|
|
33 |
DEBUG_API("->XAOutputMixAdapt_Create");
|
|
34 |
if ( pSelf)
|
|
35 |
{
|
|
36 |
if( XAAdaptationBase_Init(&(pSelf->baseObj.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->baseObj;
|
|
57 |
}
|
|
58 |
|
|
59 |
/*
|
|
60 |
* XAresult XAOutputMixAdapt_PostInit(XAAdaptationGstCtx* bCtx)
|
|
61 |
* 2nd phase initialization of Output Mix Adaptation Context
|
|
62 |
*/
|
|
63 |
XAresult XAOutputMixAdapt_PostInit(XAAdaptationGstCtx* bCtx)
|
|
64 |
{
|
|
65 |
DEBUG_API("->XAOutputMixAdapt_PostInit");
|
|
66 |
if(bCtx == NULL || bCtx->baseObj.ctxId != XAOutputMixAdaptation )
|
|
67 |
{
|
|
68 |
DEBUG_ERR("Invalid parameter!!");
|
|
69 |
DEBUG_API("<-XAOutputMixAdapt_PostInit");
|
|
70 |
return XA_RESULT_PARAMETER_INVALID;
|
|
71 |
}
|
|
72 |
|
|
73 |
/* check and add devices to pSelf->availableDevices if such detection can be done */
|
|
74 |
DEBUG_API("<-XAOutputMixAdapt_PostInit");
|
|
75 |
return XA_RESULT_SUCCESS;
|
|
76 |
}
|
|
77 |
|
|
78 |
/*
|
|
79 |
* void XAOutputMixAdapt_Destroy(XAAdaptationGstCtx* bCtx)
|
|
80 |
* Destroys Output Mix Adaptation Context
|
|
81 |
* @param ctx - Output Mix Adaptation context to be destroyed
|
|
82 |
*/
|
|
83 |
void XAOutputMixAdapt_Destroy(XAAdaptationGstCtx* bCtx)
|
|
84 |
{
|
|
85 |
XAOutputMixAdaptationCtx* ctx = NULL;
|
|
86 |
DEBUG_API("->XAOutputMixAdapt_Destroy");
|
|
87 |
if(bCtx == NULL || bCtx->baseObj.ctxId != XAOutputMixAdaptation )
|
|
88 |
{
|
|
89 |
DEBUG_ERR("Invalid parameter!!");
|
|
90 |
DEBUG_API("<-XAOutputMixAdapt_Destroy");
|
|
91 |
return;
|
|
92 |
}
|
|
93 |
ctx = (XAOutputMixAdaptationCtx*)bCtx;
|
|
94 |
g_array_free(ctx->connectedObjects, TRUE);
|
|
95 |
g_array_free(ctx->availableDevices, TRUE);
|
|
96 |
|
|
97 |
XAAdaptationBase_Free( &(ctx->baseObj.baseObj) );
|
|
98 |
free(ctx);
|
|
99 |
DEBUG_API("<-XAOutputMixAdapt_Destroy");
|
|
100 |
}
|
|
101 |
|
|
102 |
/*
|
|
103 |
* GstElement* XAOutputMixAdapt_GetSink(XAAdaptationGstCtx* bCtx)
|
|
104 |
*/
|
|
105 |
GstElement* XAOutputMixAdapt_GetSink(XAAdaptationGstCtx* bCtx)
|
|
106 |
{
|
|
107 |
XAOutputMixAdaptationCtx* mixCtx = NULL;
|
|
108 |
/* create sink for current routing */
|
|
109 |
GstElement* newsink=NULL;
|
|
110 |
XACapabilities temp;
|
|
111 |
|
|
112 |
DEBUG_API("->XAOutputMixAdapt_GetSink");
|
|
113 |
if(bCtx == NULL || bCtx->baseObj.ctxId != XAOutputMixAdaptation )
|
|
114 |
{
|
|
115 |
DEBUG_ERR("Invalid parameter!!");
|
|
116 |
DEBUG_API("<-XAOutputMixAdapt_GetSink");
|
|
117 |
return NULL;
|
|
118 |
}
|
|
119 |
mixCtx = (XAOutputMixAdaptationCtx*)bCtx;
|
|
120 |
|
|
121 |
if(!mixCtx)
|
|
122 |
{
|
|
123 |
DEBUG_ERR("NULL context!");
|
|
124 |
return NULL;
|
|
125 |
}
|
|
126 |
|
|
127 |
if( XA_RESULT_SUCCESS ==
|
|
128 |
XACapabilitiesMgr_GetCapsById(NULL, (XACapsType)((XACapsType)(XACAP_DEVSNK|XACAP_AUDIO)), mixCtx->currentrouting, &temp) )
|
|
129 |
{
|
|
130 |
newsink = gst_element_factory_make((char*)temp.adaptId,(char*)temp.adaptId);
|
|
131 |
if(!newsink)
|
|
132 |
{
|
|
133 |
DEBUG_ERR_A1("Could not create sink \"%s\"!", (char*)temp.adaptId);
|
|
134 |
}
|
|
135 |
}
|
|
136 |
else
|
|
137 |
{
|
|
138 |
DEBUG_ERR_A1("Could not find audio device by id 0x%x", (int)mixCtx->currentrouting);
|
|
139 |
}
|
|
140 |
DEBUG_API("<-XAOutputMixAdapt_GetSink");
|
|
141 |
return newsink;
|
|
142 |
|
|
143 |
}
|
|
144 |
|
|
145 |
/*
|
|
146 |
* XAresult XAOutputMixAdapt_ConnectObject(XAAdaptationGstCtx* omCtx, XAAdaptationGstCtx* bCtx, GstElement* usedMix)
|
|
147 |
*/
|
|
148 |
XAresult XAOutputMixAdapt_ConnectObject(XAAdaptationGstCtx* omCtx, XAAdaptationGstCtx* bCtx, GstElement* usedMix)
|
|
149 |
{
|
|
150 |
XAresult ret = XA_RESULT_SUCCESS;
|
|
151 |
XAuint32 i=0;
|
|
152 |
XAOutputMixAdaptationCtx* mixCtx =NULL;
|
|
153 |
DEBUG_API("->XAOutputMixAdapt_ConnectObject");
|
|
154 |
if( !omCtx || omCtx->baseObj.ctxId!=XAOutputMixAdaptation || !bCtx || !usedMix )
|
|
155 |
{
|
|
156 |
DEBUG_ERR("Invalid attribute!!");
|
|
157 |
DEBUG_API("<-XAOutputMixAdapt_ConnectObject");
|
|
158 |
return XA_RESULT_PARAMETER_INVALID;
|
|
159 |
}
|
|
160 |
mixCtx = (XAOutputMixAdaptationCtx*)omCtx;
|
|
161 |
if( !mixCtx || !bCtx || !usedMix )
|
|
162 |
{
|
|
163 |
DEBUG_ERR("Invalid attribute!!");
|
|
164 |
DEBUG_API("<-XAOutputMixAdapt_DisconnectObject");
|
|
165 |
return XA_RESULT_PARAMETER_INVALID;
|
|
166 |
}
|
|
167 |
for(i=0; i<mixCtx->connectedObjects->len; i++)
|
|
168 |
{
|
|
169 |
if( (g_array_index(mixCtx->connectedObjects, XAOMixAdaptConnObj, i)).ctx == bCtx )
|
|
170 |
{
|
|
171 |
/*item found already*/
|
|
172 |
ret = XA_RESULT_PARAMETER_INVALID;
|
|
173 |
break;
|
|
174 |
}
|
|
175 |
}
|
|
176 |
if(i==mixCtx->connectedObjects->len)
|
|
177 |
{
|
|
178 |
XAOMixAdaptConnObj tmp;
|
|
179 |
tmp.ctx= bCtx;
|
|
180 |
tmp.currentSink = usedMix;
|
|
181 |
g_array_append_val(mixCtx->connectedObjects, tmp);
|
|
182 |
}
|
|
183 |
|
|
184 |
DEBUG_API("<-XAOutputMixAdapt_ConnectObject");
|
|
185 |
return ret;
|
|
186 |
}
|
|
187 |
|
|
188 |
/*
|
|
189 |
* XAresult XAOutputMixAdapt_DisconnectObject(XAAdaptationGstCtx* omCtx, XAAdaptationGstCtx* bCtx)
|
|
190 |
*/
|
|
191 |
XAresult XAOutputMixAdapt_DisconnectObject(XAAdaptationGstCtx* omCtx, XAAdaptationGstCtx* bCtx)
|
|
192 |
{
|
|
193 |
XAuint32 i=0;
|
|
194 |
XAOutputMixAdaptationCtx* mixCtx =NULL;
|
|
195 |
DEBUG_API("->XAOutputMixAdapt_DisconnectObject");
|
|
196 |
|
|
197 |
if( !omCtx || omCtx->baseObj.ctxId!=XAOutputMixAdaptation || !bCtx )
|
|
198 |
{
|
|
199 |
DEBUG_ERR("Invalid attribute!!");
|
|
200 |
DEBUG_API("<-XAOutputMixAdapt_DisconnectObject");
|
|
201 |
return XA_RESULT_PARAMETER_INVALID;
|
|
202 |
}
|
|
203 |
mixCtx = (XAOutputMixAdaptationCtx*)omCtx;
|
|
204 |
|
|
205 |
if( !mixCtx || !bCtx )
|
|
206 |
{
|
|
207 |
DEBUG_ERR("Invalid attribute!!");
|
|
208 |
DEBUG_API("<-XAOutputMixAdapt_DisconnectObject");
|
|
209 |
return XA_RESULT_PARAMETER_INVALID;
|
|
210 |
}
|
|
211 |
for(i=0; i<mixCtx->connectedObjects->len; i++)
|
|
212 |
{
|
|
213 |
XAOMixAdaptConnObj* tmp = &(g_array_index(mixCtx->connectedObjects, XAOMixAdaptConnObj, i));
|
|
214 |
if( tmp->ctx == bCtx )
|
|
215 |
{
|
|
216 |
g_array_remove_index(mixCtx->connectedObjects, i);
|
|
217 |
DEBUG_API("<-XAOutputMixAdapt_DisconnectObject");
|
|
218 |
return XA_RESULT_SUCCESS;
|
|
219 |
}
|
|
220 |
}
|
|
221 |
/*did not find, return error*/
|
|
222 |
DEBUG_ERR("Object not found!");
|
|
223 |
DEBUG_API("<-XAOutputMixAdapt_DisconnectObject");
|
|
224 |
return XA_RESULT_PARAMETER_INVALID;
|
|
225 |
}
|
|
226 |
|