1/*
2 INTEL CONFIDENTIAL
3 Copyright 2009 Intel Corporation All Rights Reserved.
4 The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel’s prior express written permission.
5
6 No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
7*/
8
9/**
10 * SECTION:mixacpaac
11 * @short_description: Audio configuration parameters for AAC-LC, HEAAC v1, and HEAAC v2 audio format.
12 * @include: mixacpaac.h
13 *
14 * A data object which stores audio specific parameters for the following formats:
15 * <itemizedlist>
16 * <listitem>AAC-LC</listitem>
17 * <listitem>HE-AAC v1</listitem>
18 * <listitem>HE-AAC v2</listitem>
19 * </itemizedlist>
20 *
21 * Additional parameters must be set in the parent object #MixAudioConfigParams
22 */
23
24#include "mixacpaac.h"
25#include <string.h>
26#include <mixlog.h>
27
28static GType _mix_acp_aac_type = 0;
29static MixAudioConfigParamsClass *parent_class = NULL;
30
31#define _do_init { _mix_acp_aac_type = g_define_type_id; }
32
33gboolean mix_acp_aac_copy(MixParams* target, const MixParams *src);
34MixParams* mix_acp_aac_dup(const MixParams *obj);
35gboolean mix_acp_aac_equal(MixParams* first, MixParams *second);
36static void mix_acp_aac_finalize(MixParams *obj);
37
38void mix_aac_print_params(MixAudioConfigParams *obj);
39
40G_DEFINE_TYPE_WITH_CODE(MixAudioConfigParamsAAC, mix_acp_aac, MIX_TYPE_AUDIOCONFIGPARAMS, _do_init);
41
42static void mix_acp_aac_init (MixAudioConfigParamsAAC *self)
43{
44  self->MPEG_id = MIX_AAC_MPEG_ID_NULL;
45  self->bit_stream_format= MIX_AAC_BS_NULL;
46  self->aac_profile=MIX_AAC_PROFILE_NULL;
47  self->aot=0;
48  self->bit_rate_type=MIX_AAC_BR_NULL; /* 0=CBR, 1=VBR */
49  self->CRC=FALSE;
50  self->sbrPresentFlag = -1;
51  self->psPresentFlag = -1;
52  self->pce_present=FALSE; /* Flag. 1- present 0 - not present, for RAW */
53  self->syntc_id[0] = self->syntc_id[1] = 0; /* 0 for ID_SCE(Dula Mono), -1 for raw */
54  self->syntc_tag[0] = self->syntc_tag[1] = 0; /* raw - -1 and 0 -16 for rest of the streams */
55  self->num_syntc_elems = 0;
56  self->aac_sample_rate = 0;
57  self->aac_channels = 0;
58}
59
60static void mix_acp_aac_class_init(MixAudioConfigParamsAACClass *klass)
61{
62  MixParamsClass *mixparams_class = MIX_PARAMS_CLASS(klass);
63
64  /* setup static parent class */
65  parent_class = (MixAudioConfigParamsClass *) g_type_class_peek_parent (klass);
66
67  mixparams_class->finalize = mix_acp_aac_finalize;
68  mixparams_class->copy = (MixParamsCopyFunction)mix_acp_aac_copy;
69  mixparams_class->dup = (MixParamsDupFunction)mix_acp_aac_dup;
70  mixparams_class->equal = (MixParamsEqualFunction)mix_acp_aac_equal;
71
72//  MixAudioConfigParamsClass *acp = MIX_AUDIOCONFIGPARAMS_GET_CLASS(klass);
73  MixAudioConfigParamsClass *acp = (MixAudioConfigParamsClass *)klass;
74  acp->print_params = mix_aac_print_params;
75}
76
77MixAudioConfigParamsAAC *mix_acp_aac_new(void)
78{
79  MixAudioConfigParamsAAC *ret = (MixAudioConfigParamsAAC *)g_type_create_instance (MIX_TYPE_AUDIOCONFIGPARAMSAAC);
80
81  return ret;
82}
83
84void mix_acp_aac_finalize(MixParams *obj)
85{
86  /* clean up here. */
87
88  /* Chain up parent */
89  MixParamsClass *klass = MIX_PARAMS_CLASS(parent_class);
90  if (klass->finalize)
91    klass->finalize(obj);
92}
93
94MixAudioConfigParamsAAC *mix_acp_aac_ref(MixAudioConfigParamsAAC *mix)
95{
96  return (MixAudioConfigParamsAAC*)mix_params_ref(MIX_PARAMS(mix));
97}
98
99/**
100 * mix_acp_aac_dup:
101 * @obj: a #MixAudioConfigParamsAAC object
102 * @returns: a newly allocated duplicate of the object.
103 *
104 * Copy duplicate of the object.
105 */
106MixParams* mix_acp_aac_dup(const MixParams *obj)
107{
108  MixParams *ret = NULL;
109
110  if (MIX_IS_AUDIOCONFIGPARAMSAAC(obj))
111  {
112    MixAudioConfigParamsAAC *duplicate = mix_acp_aac_new();
113    if (mix_acp_aac_copy(MIX_PARAMS(duplicate), MIX_PARAMS(obj)))
114    {
115      ret = MIX_PARAMS(duplicate);
116    }
117    else
118    {
119      mix_acp_aac_unref(duplicate);
120    }
121  }
122
123  return ret;
124}
125
126/**
127 * mix_acp_aac_copy:
128 * @target: copy to target
129 * @src: copy from src
130 * @returns: boolean indicates if copy is successful.
131 *
132 * Copy instance data from @src to @target.
133 */
134gboolean mix_acp_aac_copy(MixParams* target, const MixParams *src)
135{
136  if (MIX_IS_AUDIOCONFIGPARAMSAAC(target) && MIX_IS_AUDIOCONFIGPARAMSAAC(src))
137  {
138    MixAudioConfigParamsAAC *t = MIX_AUDIOCONFIGPARAMSAAC(target);
139    MixAudioConfigParamsAAC *s = MIX_AUDIOCONFIGPARAMSAAC(src);
140
141    t->MPEG_id = s->MPEG_id;
142    t->bit_stream_format = s->bit_stream_format;
143    t->aac_profile = s->aac_profile;
144    t->aot = s->aot;
145    t->bit_rate_type = s->bit_rate_type;
146    t->CRC = s->CRC;
147
148    // Now chainup base class
149    MixParamsClass *klass = MIX_PARAMS_CLASS(parent_class);
150    if (klass->copy)
151    {
152      return klass->copy(MIX_PARAMS_CAST(target), MIX_PARAMS_CAST(src));
153    }
154    else
155      return TRUE;
156  }
157  return FALSE;
158}
159
160/**
161 * mix_acp_aac_equal:
162 * @first: first object to compare
163 * @second: seond object to compare
164 * @returns: boolean indicates if instance are equal.
165 *
166 * Copy instance data from @src to @target.
167 */
168gboolean mix_acp_aac_equal(MixParams* first, MixParams *second)
169{
170  gboolean ret = FALSE;
171
172  if (first && second)
173  {
174    if (first == second) return TRUE;
175  }
176  else
177  {
178    return FALSE;
179  }
180
181  // members within this scope equal. chaining up.
182  MixParamsClass *klass = MIX_PARAMS_CLASS(parent_class);
183  if (klass->equal)
184    ret = klass->equal(first, second);
185  else
186    ret = TRUE;
187
188  if (ret && MIX_IS_AUDIOCONFIGPARAMSAAC(first) && MIX_IS_AUDIOCONFIGPARAMSAAC(second))
189  {
190
191    MixAudioConfigParamsAAC *acp1 = MIX_AUDIOCONFIGPARAMSAAC(first);
192    MixAudioConfigParamsAAC *acp2 = MIX_AUDIOCONFIGPARAMSAAC(second);
193
194    ret = (acp1->MPEG_id == acp2->MPEG_id) &&
195          (acp1->bit_stream_format && acp2->bit_stream_format) &&
196          (acp1->aac_profile == acp2->aac_profile) &&
197          (acp1->aot == acp2->aot) &&
198          (acp1->bit_rate_type == acp2->bit_rate_type) &&
199          (acp1->CRC == acp2->CRC) &&
200          (acp1->sbrPresentFlag == acp2->sbrPresentFlag) &&
201          (acp1->psPresentFlag == acp2->psPresentFlag) &&
202          (acp1->pce_present == acp2->pce_present) &&
203          (acp1->syntc_id[0] == acp2->syntc_id[0]) &&
204          (acp1->syntc_id[1] == acp2->syntc_id[1]) &&
205          (acp1->syntc_tag[0] == acp2->syntc_tag[0]) &&
206          (acp1->syntc_tag[1] == acp2->syntc_tag[1]);
207  }
208
209  return ret;
210}
211
212MIX_RESULT mix_acp_aac_set_bit_stream_format(MixAudioConfigParamsAAC *obj, MixAACBitstreamFormt bit_stream_format)
213{
214  MIX_RESULT ret = MIX_RESULT_SUCCESS;
215
216  if (!obj) return MIX_RESULT_NULL_PTR;
217
218  if (bit_stream_format < MIX_AAC_BS_ADTS && bit_stream_format >= MIX_AAC_BS_LAST)
219  {
220    ret = MIX_RESULT_INVALID_PARAM;
221  }
222  else
223  {
224    obj->bit_stream_format = bit_stream_format;
225  }
226
227  return ret;
228}
229MixAACBitstreamFormt mix_acp_aac_get_bit_stream_format(MixAudioConfigParamsAAC *obj)
230{
231  if (obj)
232    return obj->bit_stream_format;
233  else
234    return MIX_AAC_BS_NULL;
235}
236
237MIX_RESULT mix_acp_aac_set_aac_profile(MixAudioConfigParamsAAC *obj, MixAACProfile aac_profile)
238{
239  MIX_RESULT ret = MIX_RESULT_SUCCESS;
240
241  if (!obj) return MIX_RESULT_NULL_PTR;
242
243  if (aac_profile < MIX_AAC_PROFILE_MAIN || aac_profile >= MIX_AAC_PROFILE_LAST)
244  {
245    ret = MIX_RESULT_INVALID_PARAM;
246  }
247  else
248  {
249    obj->aac_profile = aac_profile;
250  }
251
252  return ret;
253}
254MixAACProfile mix_acp_aac_get_aac_profile(MixAudioConfigParamsAAC *obj)
255{
256  if (obj)
257    return obj->aac_profile;
258  else
259    return MIX_AAC_PROFILE_NULL;
260}
261
262MIX_RESULT mix_acp_aac_set_bit_rate_type(MixAudioConfigParamsAAC *obj, MixAACBitrateType bit_rate_type)
263{
264  MIX_RESULT ret = MIX_RESULT_SUCCESS;
265
266  if (!obj) return MIX_RESULT_NULL_PTR;
267
268  if (bit_rate_type != MIX_AAC_BR_CONSTANT && bit_rate_type != MIX_AAC_BR_VARIABLE)
269  {
270    ret = MIX_RESULT_INVALID_PARAM;
271  }
272  else
273  {
274    obj->bit_rate_type = bit_rate_type;
275  }
276
277  return ret;
278}
279MixAACBitrateType mix_acp_aac_get_bit_rate_type(MixAudioConfigParamsAAC *obj)
280{
281  if (obj)
282    return obj->bit_rate_type;
283  else
284    return MIX_AAC_BR_NULL;
285}
286
287void mix_aac_print_params(MixAudioConfigParams *obj)
288{
289    MixAudioConfigParamsAAC *t = MIX_AUDIOCONFIGPARAMSAAC(obj);
290    mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_INFO, "Mpeg ID: %d\n", t->MPEG_id);
291    mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_INFO, "bit_stream_format: %d\n", t->bit_stream_format);
292    mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_INFO, "aac_profile: %d\n", t->aac_profile);
293    mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_INFO, "aot: %d\n", t->aot);
294    mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_INFO, "bit_rate_type: %d\n", t->bit_rate_type);
295    mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_INFO, "CRC: %d\n", t->CRC);
296    mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_INFO, " \n");
297}
298
299
300MIX_RESULT mix_acp_aac_set_aot(MixAudioConfigParamsAAC *obj, guint aot)
301{
302    if (!obj) return MIX_RESULT_NULL_PTR;
303
304    if (MIX_IS_AUDIOCONFIGPARAMSAAC(obj))
305    {
306        if ((aot == 2) || (aot == 5))
307        {
308            obj->aot=aot;
309            return MIX_RESULT_SUCCESS;
310        }
311        else
312        {
313            return MIX_RESULT_NOT_SUPPORTED;
314        }
315    }
316    else
317    {
318        return MIX_RESULT_INVALID_PARAM;
319    }
320}
321
322guint mix_acp_aac_get_aot(MixAudioConfigParamsAAC *obj)
323{
324    if (MIX_IS_AUDIOCONFIGPARAMSAAC(obj))
325        return obj->aot;
326    else
327        return 0;
328}
329
330
331MIX_RESULT mix_acp_aac_set_mpeg_id(MixAudioConfigParamsAAC *obj, MixAACMpegID mpegid)
332{
333    if (!obj) return MIX_RESULT_NULL_PTR;
334
335    if (MIX_IS_AUDIOCONFIGPARAMSAAC(obj))
336    {
337        if ((mpegid >= MIX_AAC_MPEG_ID_NULL) || (mpegid < MIX_AAC_MPEG_LAST))
338        {
339            obj->MPEG_id=mpegid;
340            return MIX_RESULT_SUCCESS;
341        }
342        else
343        {
344            return MIX_RESULT_NOT_SUPPORTED;
345        }
346    }
347    else
348    {
349        return MIX_RESULT_INVALID_PARAM;
350    }
351}
352
353MixAACMpegID mix_acp_aac_get_mpeg_id(MixAudioConfigParamsAAC *obj)
354{
355    if (MIX_IS_AUDIOCONFIGPARAMSAAC(obj))
356        return obj->MPEG_id;
357    else
358        return MIX_AAC_MPEG_ID_NULL;
359}
360
361