19
|
1 |
/*
|
25
|
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: AudioEnc Intfc Adaptation for GStreamer
|
|
15 |
*
|
|
16 |
*/
|
19
|
17 |
|
20
|
18 |
#include <gst/gst.h>
|
19
|
19 |
#include "xamediarecorderadaptctx.h"
|
|
20 |
#include "xaaudioencoderitfadaptation.h"
|
|
21 |
#include "xaadaptationgst.h"
|
|
22 |
//#include "XAStaticCapsAdaptation.h"
|
|
23 |
|
|
24 |
/*
|
|
25 |
* XAresult XAAudioEncoderItfAdapt_SetEncoderSettings( XAAdaptationGstCtx *ctx,
|
|
26 |
* XAAudioEncoderSettings *pSettings )
|
|
27 |
* @param XAAdaptationGstCtx *ctx - pointer to Media Recorer adaptation contex
|
|
28 |
* @param XAAudioEncoderSettings *pSettings - Settings to be setted for encoder
|
|
29 |
* @return XAresult ret - return success value
|
|
30 |
* Description: Sets preferred encoder settings for pipeline.
|
|
31 |
*/
|
25
|
32 |
XAresult XAAudioEncoderItfAdapt_SetEncoderSettings(XAAdaptationBaseCtx *ctx,
|
|
33 |
XAAudioEncoderSettings *pSettings)
|
|
34 |
{
|
19
|
35 |
XAresult ret = XA_RESULT_SUCCESS;
|
|
36 |
XAMediaRecorderAdaptationCtx* mCtx = NULL;
|
|
37 |
|
|
38 |
DEBUG_API("->XAAudioEncoderItfAdapt_SetEncoderSettings");
|
25
|
39 |
if (!ctx || (ctx->ctxId != XAMediaRecorderAdaptation) || !pSettings)
|
|
40 |
{
|
19
|
41 |
DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
|
|
42 |
DEBUG_API("<-XAAudioEncoderItfImpl_SetEncoderSettings");
|
|
43 |
return XA_RESULT_PARAMETER_INVALID;
|
25
|
44 |
}
|
19
|
45 |
mCtx = (XAMediaRecorderAdaptationCtx*) ctx;
|
|
46 |
|
25
|
47 |
ret = XAMediaRecorderAdapt_CheckCodec(mCtx, XACAP_AUDIO,
|
|
48 |
pSettings->encoderId);
|
|
49 |
if (ret == XA_RESULT_SUCCESS)
|
|
50 |
{
|
19
|
51 |
/*change of settings - pipeline must be regenerated**/
|
|
52 |
mCtx->encodingchanged = XA_BOOLEAN_TRUE;
|
25
|
53 |
memcpy(&mCtx->audioEncSettings, pSettings,
|
|
54 |
sizeof(XAAudioEncoderSettings));
|
|
55 |
}DEBUG_API("<-XAAudioEncoderItfAdapt_SetEncoderSettings");
|
19
|
56 |
return ret;
|
25
|
57 |
}
|
19
|
58 |
|
28
|
59 |
static gboolean
|
|
60 |
populate_field_settings (GQuark field, const GValue * value, gpointer pfx)
|
|
61 |
{
|
|
62 |
gchar *field_name ;
|
|
63 |
|
|
64 |
gpointer *pfxd = (gpointer*)pfx;
|
|
65 |
XAMediaRecorderAdaptationCtx *ctxx = (XAMediaRecorderAdaptationCtx *) *pfxd;
|
|
66 |
|
|
67 |
field_name = (gchar*)g_quark_to_string (field);
|
|
68 |
|
|
69 |
if((strcasecmp((const char*)field_name,"channels") == 0))
|
|
70 |
{
|
|
71 |
if(GST_VALUE_HOLDS_INT_RANGE(value) == TRUE)
|
|
72 |
{
|
|
73 |
(ctxx)->audioEncSettings.channelsIn = gst_value_get_int_range_max (value);
|
|
74 |
(ctxx)->audioEncSettings.channelsOut = gst_value_get_int_range_max (value);
|
|
75 |
}else
|
|
76 |
{
|
|
77 |
(ctxx)->audioEncSettings.channelsIn = g_value_get_int(value);
|
|
78 |
(ctxx)->audioEncSettings.channelsOut = g_value_get_int(value);
|
|
79 |
}
|
|
80 |
|
|
81 |
}
|
|
82 |
if((strcasecmp((const char*)field_name,"depth") == 0))
|
|
83 |
{
|
|
84 |
if(GST_VALUE_HOLDS_INT_RANGE(value) == TRUE)
|
|
85 |
{
|
|
86 |
(ctxx)->audioEncSettings.bitsPerSample = gst_value_get_int_range_min (value);
|
|
87 |
}else
|
|
88 |
{
|
|
89 |
(ctxx)->audioEncSettings.bitsPerSample = g_value_get_int(value);
|
|
90 |
}
|
|
91 |
}
|
|
92 |
if((strcasecmp((const char*)field_name,"endianness") == 0))
|
|
93 |
{
|
|
94 |
if(GST_VALUE_HOLDS_INT_RANGE(value) == TRUE)
|
|
95 |
{
|
|
96 |
(ctxx)->audioEncSettings.blockAlignment = gst_value_get_int_range_min (value);
|
|
97 |
}else
|
|
98 |
{
|
|
99 |
(ctxx)->audioEncSettings.blockAlignment = g_value_get_int(value);
|
|
100 |
}
|
|
101 |
}
|
|
102 |
if((strcasecmp((const char*)field_name,"bitrate") == 0))
|
|
103 |
{
|
|
104 |
if(GST_VALUE_HOLDS_INT_RANGE(value) == TRUE)
|
|
105 |
{
|
|
106 |
(ctxx)->audioEncSettings.bitRate = gst_value_get_int_range_min (value);
|
|
107 |
}else
|
|
108 |
{
|
|
109 |
(ctxx)->audioEncSettings.bitRate = g_value_get_int(value);
|
|
110 |
}
|
|
111 |
|
|
112 |
}
|
|
113 |
if((strcasecmp((const char*)field_name,"rate") == 0))
|
|
114 |
{
|
|
115 |
if(GST_VALUE_HOLDS_INT_RANGE(value) == TRUE)
|
|
116 |
{
|
|
117 |
(ctxx)->audioEncSettings.sampleRate = gst_value_get_int_range_min (value)*1000;
|
|
118 |
}else
|
|
119 |
{
|
|
120 |
(ctxx)->audioEncSettings.sampleRate = g_value_get_int(value) * 1000;
|
|
121 |
}
|
|
122 |
|
|
123 |
}
|
|
124 |
|
|
125 |
return TRUE;
|
|
126 |
}
|
25
|
127 |
XAresult XAAudioEncoderItfAdapt_GetEncoderSettings(XAAdaptationBaseCtx *bCtx,
|
|
128 |
XAAudioEncoderSettings *pSettings)
|
|
129 |
{
|
19
|
130 |
XAMediaRecorderAdaptationCtx* mCtx = NULL;
|
|
131 |
XAresult ret = XA_RESULT_SUCCESS;
|
28
|
132 |
|
|
133 |
GstElement *encoderelement=NULL,*actualencoder=NULL;
|
|
134 |
GstPad * encoderpad = NULL;
|
|
135 |
GstCaps *encodercaps =NULL;
|
|
136 |
GstStructure *structure = NULL;
|
|
137 |
XAAdaptationGstCtx *ctx = NULL;
|
|
138 |
int value = -1 ;
|
19
|
139 |
|
|
140 |
DEBUG_API("->XAAudioEncoderItfAdapt_GetEncoderSettings");
|
25
|
141 |
if (!bCtx || (bCtx->ctxId != XAMediaRecorderAdaptation) || !pSettings)
|
|
142 |
{
|
19
|
143 |
DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
|
|
144 |
return XA_RESULT_PARAMETER_INVALID;
|
25
|
145 |
}
|
19
|
146 |
mCtx = (XAMediaRecorderAdaptationCtx*) bCtx;
|
28
|
147 |
ctx = (XAAdaptationGstCtx *)bCtx;
|
|
148 |
|
|
149 |
encoderelement = gst_bin_get_by_name((GstBin*)ctx->bin ,"mrcodecbin");
|
|
150 |
if (encoderelement != NULL)
|
|
151 |
{
|
|
152 |
encoderpad = gst_element_get_pad(encoderelement , "sink");
|
|
153 |
if(encoderpad != NULL){
|
|
154 |
encodercaps = gst_pad_get_negotiated_caps(encoderpad);
|
|
155 |
if(encodercaps == NULL)
|
|
156 |
{
|
|
157 |
//pipeline is not in playing state , so getting allowed caps
|
|
158 |
encodercaps = gst_pad_get_allowed_caps(encoderpad);
|
|
159 |
}
|
|
160 |
}
|
|
161 |
else{
|
|
162 |
DEBUG_ERR("No pad named sink in codecbin pad");
|
|
163 |
}
|
|
164 |
if(encodercaps != NULL && encodercaps->structs->len > 0)
|
|
165 |
{
|
|
166 |
structure = gst_caps_get_structure (encodercaps, 0);
|
|
167 |
}
|
|
168 |
else{
|
|
169 |
DEBUG_ERR("no allowed caps for encoderelement");
|
|
170 |
}
|
|
171 |
|
|
172 |
//populate the values based on neotiated caps or allowed caps.
|
|
173 |
gst_structure_foreach (structure, populate_field_settings, (gpointer) &mCtx);
|
|
174 |
|
|
175 |
//finding the actual encoder.
|
|
176 |
if(mCtx->codecbin != NULL){
|
|
177 |
actualencoder = gst_bin_get_by_name((GstBin*)mCtx->codecbin ,"audioenc");
|
|
178 |
}
|
|
179 |
//finding bitrate property
|
|
180 |
if(value == -1 && actualencoder != NULL)
|
|
181 |
{
|
|
182 |
//search in encoder element , property is there or not?
|
|
183 |
g_object_get(G_OBJECT (actualencoder), "bitrate", &value,NULL);
|
|
184 |
}
|
|
185 |
if(mCtx->audioEncSettings.encoderId == XA_AUDIOCODEC_AMR)
|
|
186 |
{
|
|
187 |
g_object_get(G_OBJECT (mCtx->audiosource), "speechbitrate", &value,NULL);
|
|
188 |
}
|
|
189 |
if(value != -1)
|
|
190 |
{
|
|
191 |
mCtx->audioEncSettings.bitRate = value;
|
|
192 |
value =-1;
|
|
193 |
}
|
|
194 |
|
|
195 |
//finding profile property
|
|
196 |
if(value == -1 && actualencoder != NULL)
|
|
197 |
{
|
|
198 |
g_object_get(G_OBJECT (actualencoder), "profile", &value,NULL);
|
|
199 |
}
|
|
200 |
if(value != -1)
|
|
201 |
{
|
|
202 |
mCtx->audioEncSettings.levelSetting = value;
|
|
203 |
value =-1;
|
|
204 |
}
|
|
205 |
|
|
206 |
//finding output-format property
|
|
207 |
if(value == -1 && actualencoder != NULL)
|
|
208 |
{
|
|
209 |
//try to see search in encoder element , property is there or not?
|
|
210 |
g_object_get(G_OBJECT (actualencoder), "output-format", &value,NULL);
|
|
211 |
}
|
|
212 |
if(value != -1)
|
|
213 |
{
|
|
214 |
mCtx->audioEncSettings.streamFormat = value;
|
|
215 |
value =-1;
|
|
216 |
}
|
|
217 |
|
|
218 |
|
|
219 |
//setting these settings to default.
|
|
220 |
mCtx->audioEncSettings.channelMode=0;
|
|
221 |
mCtx->audioEncSettings.rateControl = XA_RATECONTROLMODE_CONSTANTBITRATE;
|
|
222 |
mCtx->audioEncSettings.encodeOptions = 0;
|
|
223 |
|
|
224 |
//unref the caps, pads , elements
|
|
225 |
if(encodercaps != NULL)
|
|
226 |
gst_caps_unref(encodercaps);
|
|
227 |
if(encoderpad!= NULL)
|
|
228 |
gst_object_unref(encoderpad);
|
|
229 |
if(actualencoder!= NULL)
|
|
230 |
gst_object_unref (actualencoder);
|
|
231 |
if(encoderelement!= NULL)
|
|
232 |
gst_object_unref (encoderelement);
|
|
233 |
}else{
|
|
234 |
DEBUG_ERR("Codecbin element Not found ");
|
|
235 |
}
|
|
236 |
memcpy(pSettings, &(mCtx->audioEncSettings),
|
|
237 |
sizeof(XAAudioEncoderSettings));
|
19
|
238 |
DEBUG_API("<-XAAudioEncoderItfAdapt_GetEncoderSettings");
|
|
239 |
return ret;
|
25
|
240 |
}
|