Initial release.
[gst-davinci.git] / ti_plugins / adecoder / src / gstadecoder.c~
blobdec53bc3109d5fbc745e690ce54e16fd75eed68a
1 /*
2  * Plugin Name : adecoder
3  * Description : A Generic (ARM/DSP based) Audio Decoder for for TI Davinci DM644x
4  *
5  * Copyright (C) 2007 Texas Instruments, Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published 
9  * by the Free Software Foundation version 2.1 of the License.
10  *
11  * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
12  * whether express or implied; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  */
19 #ifdef HAVE_CONFIG_H
21 #include "config.h"
23 #endif
25 #include "gstadecoder.h"
27 GST_DEBUG_CATEGORY_STATIC(gstadecoder_debug);
30 #define translate_DspCommError(x) AVPLAYER_APP_DSPCOMM
32 /* elementfactory information */
34 static GstElementDetails adecoder_details =
36     "A Generic Audio Decoder",
38     "Codec/Decoder/Audio",
40     "Decodes Various Audio Formats using the Codec Engine",
42     "Yashwant Vijayakumar"
45 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE("sink",
47                                                                     GST_PAD_SINK,
49                                                                     GST_PAD_ALWAYS,
51                                                                     GST_STATIC_CAPS
53                                                                     ("audio/mpeg, "
55                                                                      "mpegversion = (int) { 1, 2, 4 }, "
57                                                                                                                                          "layer = (int) { 1, 2, 3 }; "
59                                                                                                                                          "audio/x-wma, "
61                                                                                                                                          "wmaversion = (int) { 1, 2, 3 }, "
63                                                                                                                                  "rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, "
65                                                                                                                                  "channels = (int) [ 1, 2 ]"));
68 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE("src",
70                                                                    GST_PAD_SRC,
72                                                                    GST_PAD_ALWAYS,
74                                                                    GST_STATIC_CAPS
76                                                                    ("audio/x-raw-int, "
78                                                                                                                                         "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", "
80                                                                                                                                         "signed = (boolean)true, "
82                                                                                                                                         "width = (int) 16, depth = (int) 16, "
84                                                                                                                                         "rate = (int) {8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, "
86                                                                                                                                         "channels = (int) [ 1, 2 ]"));
90 static GType gst_adecoder_get_type(void)
94     static GType adecoder_type = 0;
96     if (!adecoder_type)
97     {
98                 static const GTypeInfo adecoder_info =
99         {
100             sizeof(GstADecoderClass),
102             (GBaseInitFunc) gst_adecoder_base_init,
104             NULL,
106             (GClassInitFunc) gst_adecoder_class_init,
108             NULL,
110             NULL,
112             sizeof(GstADecoder),
114             0,
116             (GInstanceInitFunc) gst_adecoder_init,
117         };
119         adecoder_type = g_type_register_static(GST_TYPE_ELEMENT, "GstADecoder",&adecoder_info, 0);
121         GST_DEBUG_CATEGORY_INIT(gstadecoder_debug,"adecoder",0,"Generic Audio Decoder Element for the ARM");
123     }
125     return adecoder_type;
130 static GType gst_adecoder_get_engine_type(void)
133         static GType adecoder_engine_type = 0;
135         if(!adecoder_engine_type)
136         {
137                 static GEnumValue engine_types[] =
138                 {
140                         { H264ENGINE, "H264Engine","When running H264 or standalone AAC"},
142                         { MPEG4ENGINE,"MPEG4Engine","When running MPEG4"},
144                         { WMENGINE,"WMEngine","When running WMV or standalone WMA"},
146                         { MP3ENGINE,"MP3Engine","When running standalone MP3"},
148                         { 0,NULL,NULL }
150                 };
152                 adecoder_engine_type = g_enum_register_static("AdecoderEngineName",engine_types);
153         }
155         return adecoder_engine_type;
160 static GType gst_adecoder_get_codec_type(void)
163         static GType adecoder_codec_type = 0;
165         if(!adecoder_codec_type)
166         {
167                 static GEnumValue codec_types[] =
168                 {
169                         { ST_AUDIO_ARM_MP3, "MP3","When running MP3 Decoder"},
171                         { ST_AUDIO_WMA,"WMA","When running WMA Decoder"},
173                         { ST_AUDIO_AAC,"AAC","When running AAC Decoder"},
175                         { ST_AUDIO_DSP_MP3, "MP3","When running MP3 Decoder"},
177                         { 0,NULL,NULL }
179                 };
181                 adecoder_codec_type = g_enum_register_static("AdecoderCodecName",codec_types);
182         }
184         return adecoder_codec_type;
189 static GstCaps *gst_adecoder_sink_getcaps(GstPad * pad)
192     #ifdef DEBUG
194     printf("Sink getcaps invoked\n");
196     #endif
198         return gst_caps_copy(gst_pad_get_pad_template_caps(pad));
203 static GstCaps *gst_adecoder_src_getcaps(GstPad * pad)
206         #ifdef DEBUG
208     printf("Src getcaps invoked\n");
210     #endif
212         return gst_caps_copy(gst_pad_get_pad_template_caps(pad));
217 static gboolean gst_adecoder_sink_setcaps(GstPad * pad, GstCaps * caps)
220     GstADecoder *adecoder;
222     GstStructure *structure;
224     GstCaps *intersection;
226     const guchar *mime;
228     #ifdef DEBUG
230     printf("Inside set caps...\n");
232     #endif
234     adecoder = GST_ADECODER(GST_PAD_PARENT(pad));
236     intersection = gst_caps_intersect(gst_pad_get_pad_template_caps(pad), caps);
238     if (gst_caps_is_empty(intersection))
239     {
240                 #ifdef DEBUG
242         printf(" Caps empty...\n");
244         #endif
246         return FALSE;
247     }
249     gst_caps_unref(intersection);
251     structure = gst_caps_get_structure(caps, 0);
253     mime = gst_structure_get_name(structure);
255     if (!strcmp("audio/mpeg", mime))
256     {
257         int version = 0;
259         gst_structure_get_int(structure, "mpegversion", &version);
261         if (!version){
262              return FALSE;
263         }
265         if (version == 1){                              //version 1  -> mp3
266             adecoder->codec = ST_AUDIO_DSP_MP3;
267             printf("Audio is MP3\n");
268         } 
269         else{                                                   //version 2 or 4 -> aac
270             adecoder->codec = ST_AUDIO_AAC;
271             printf("Audio is AAC\n");
272         }    
273       }else if (!strcmp("audio/x-wma",mime)){
274                 adecoder->codec = ST_AUDIO_WMA;
275                 printf("Audio is WMA\n");
276       }else{
277         printf(" Unknown mime type...\n");
278         return FALSE;
279     }
281     adecoder->isCodecPropSet = TRUE;
282     return TRUE;
286 static void gst_adecoder_base_init(GstADecoderClass * klass)
289     GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
291     klass->sink_template = gst_static_pad_template_get(&sink_template);
293     klass->src_template = gst_static_pad_template_get(&src_template);
295     gst_element_class_add_pad_template(element_class, klass->src_template);
297     gst_element_class_add_pad_template(element_class,klass->sink_template);
299     gst_element_class_set_details(element_class, &adecoder_details);
303 static void gst_adecoder_class_init(GstADecoderClass * klass)
306     GstElementClass *gstelement_class = (GstElementClass *) klass;
308     GObjectClass *object_class = (GObjectClass *)(klass);
310     parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
312     gstelement_class->change_state = gst_adecoder_change_state;
314         object_class->set_property = gst_adecoder_set_property;
316         g_object_class_install_property(object_class,ARG_ENGINE_NAME,g_param_spec_enum ("Engine","Engine","Name of Engine to open"
318         ,GST_TYPE_ADECODER_ENGINE,0,G_PARAM_WRITABLE));
320         g_object_class_install_property(object_class,ARG_CODEC_NAME,g_param_spec_enum ("Codec","Codec","Name of Codec to run"
322         ,GST_TYPE_ADECODER_CODEC,0,G_PARAM_WRITABLE));
324         g_object_class_install_property(object_class,ARG_ENABLE_PROCESSING,g_param_spec_boolean ("Enable_Processing","Enable_Processing","Used during dsp on/off"
326         ,TRUE,G_PARAM_WRITABLE));
330 static void gst_adecoder_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
332         GstADecoder *adecoder = GST_ADECODER(object);
334         switch(prop_id)
335         {
336                 case ARG_ENGINE_NAME:
338                 adecoder->engine = g_value_get_enum(value);
340                 adecoder->isEnginePropSet = TRUE;
342                 #ifdef DEBUG
344                 printf("Engine handle set to value %x\n",adecoder->ce);
346                 #endif
348                 break;
350                 case ARG_CODEC_NAME:
352                 adecoder->codec = g_value_get_enum(value);
354                 adecoder->isCodecPropSet = TRUE;
356                 #ifdef DEBUG
358                 printf("Codec set to enum value %d\n",adecoder->codec);
360                 #endif
362                 break;
364                 case ARG_ENABLE_PROCESSING:
366                 if(adecoder->enable_processing != g_value_get_boolean(value))
367                 {
369                         adecoder->enable_processing = g_value_get_boolean(value);
371                         if(adecoder->enable_processing == TRUE)
372                         {
373                                 #ifdef DEBUG
375                                 printf("Enable_processing\n");
377                                 #endif
379                                 pthread_mutex_unlock(adecoder->start_decode);
380                         }
382                         else
383                         {
384                                 #ifdef DEBUG
386                                 printf("Disable_processing\n");
388                                 #endif
390                                 //pthread_mutex_lock(adecoder->start_decode);
392                         }
393                 }
395                 break;
397                 default:
399                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
401                 break;
403         }
405         //gst_object_unref(adecoder); //getting seg.fault when unref is done.
410 static void gst_adecoder_init(GstADecoder * adecoder)
413     GstADecoderClass *klass = GST_ADECODER_GET_CLASS(adecoder);
415     GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
417     adecoder->sinkpad = gst_pad_new_from_template(klass->sink_template, "sink");
419     gst_pad_set_activate_function(adecoder->sinkpad,GST_DEBUG_FUNCPTR(gst_adecoder_sink_activate));
421     gst_pad_set_activatepull_function(adecoder->sinkpad,GST_DEBUG_FUNCPTR(gst_adecoder_sink_activate_pull));
423     gst_pad_set_event_function(adecoder->sinkpad,GST_DEBUG_FUNCPTR(gst_adecoder_sink_event));
425     gst_pad_set_chain_function(adecoder->sinkpad, gst_adecoder_chain);
427     gst_pad_set_getcaps_function(adecoder->sinkpad,gst_adecoder_sink_getcaps);
429     gst_pad_set_setcaps_function(adecoder->sinkpad,gst_adecoder_sink_setcaps);
431     gst_element_add_pad(GST_ELEMENT(adecoder), adecoder->sinkpad);
433         adecoder->srcpad = gst_pad_new_from_template(klass->src_template, "src");
435     gst_pad_set_event_function(adecoder->srcpad,GST_DEBUG_FUNCPTR(gst_adecoder_src_event));
437         gst_pad_set_getcaps_function(adecoder->srcpad,gst_adecoder_src_getcaps);
439     gst_element_add_pad(GST_ELEMENT(adecoder), adecoder->srcpad);
441     element_class->query = gst_adecoder_query;
443     gst_adecoder_initialize_handle(adecoder);
448 static gboolean gst_adecoder_query(GstElement *element, GstQuery *query)
450         GstStructure *query_struct;
452         GValue bitRate = {0};
454         GValue dspLoad = { 0, };
456         GstADecoder *adecoder = GST_ADECODER(element);
458         g_value_init(&bitRate,G_TYPE_UINT);
460         g_value_set_uint(&bitRate,adecoder->Status->bitRate);
462         g_value_init(&dspLoad, G_TYPE_INT);
464         g_value_set_int(&dspLoad, Engine_getCpuLoad(adecoder->ce));
466         query_struct = gst_query_get_structure(query);
468         gst_structure_set_value(query_struct,"bitRate",&bitRate);
470         gst_structure_set_value(query_struct, "dspCpuLoad", &dspLoad);
471         g_value_unset(&bitRate);
473         g_value_unset(&dspLoad);
475         gst_object_unref(adecoder);
477         return TRUE;
480 static void gst_adecoder_initialize_handle(GstADecoder * adecoder)
483         adecoder->firstFrame = TRUE;
485         adecoder->inbuf = adecoder->inbuf_start_addr = NULL;
487         adecoder->outbuf[0] = NULL;
489         adecoder->outbuf[1] = NULL;
491         adecoder->readOffset = 0;
493         adecoder->codec_handle = NULL;
495         adecoder->ce = NULL;
497         adecoder->bytes_not_decoded = 0;
499         adecoder->bytesConsumed = 0;
501         adecoder->frameCount = 0;
503         adecoder->isEof = FALSE;
505         adecoder->isEos = FALSE;
507         adecoder->codec = 0;
509         adecoder->engine = 0;
511         adecoder->isEnginePropSet = FALSE;
513         adecoder->isCodecPropSet = FALSE;
515         adecoder->isPaused = FALSE;
517         adecoder->isStopped = FALSE;
519         adecoder->frame_time = 0;
521         adecoder->enable_processing = TRUE;
523         adecoder->start_decode = malloc(sizeof(pthread_mutex_t));
525         pthread_mutex_init(adecoder->start_decode, NULL);
527         pthread_mutex_lock(adecoder->start_decode);
531 static gboolean gst_adecoder_sink_activate(GstPad * sinkpad)
534     GstADecoder *adecoder = GST_ADECODER(gst_pad_get_parent(sinkpad));
536     #ifdef DEBUG
538     printf("Sink Activate invoked\n");
540     #endif
542     if (gst_pad_check_pull_range(sinkpad))
543     {
544         adecoder->isInPushMode = FALSE;
546         gst_object_unref(adecoder);
548         return gst_pad_activate_pull(sinkpad, TRUE);
549     }
551     else
552     {
553                 #ifdef DEBUG
555         printf("pull_range not supported on sinkpad\n");
557         printf("Running In Push Mode\n");
559         #endif
561         adecoder->isInPushMode = TRUE;
563         gst_object_unref(adecoder);
565         return gst_pad_activate_push(sinkpad, TRUE);
566     }
571 static gboolean gst_adecoder_sink_activate_pull(GstPad * sinkpad, gboolean active)
574         GstADecoder *adecoder = GST_ADECODER(gst_pad_get_parent(sinkpad));
576         #ifdef DEBUG
578         printf("Activate pull invoked\n");
580         #endif
582         if (active)
584         gst_pad_start_task(sinkpad, (GstTaskFunction) gst_adecoder_loop,sinkpad);/* if we have a scheduler we can start the task */
586         else
588     gst_pad_stop_task(sinkpad);
590         gst_object_unref(adecoder);
592         return TRUE;
596 static void gst_adecoder_loop(GstPad * pad)
598         GstADecoder *adecoder = GST_ADECODER(gst_pad_get_parent(pad));
600         if(adecoder->isEos == FALSE && adecoder->isStopped == FALSE)
601         {
603                 if(adecoder->initialized == FALSE)
604                 {
605                         if((adecoder->initialized = gst_adecoder_decoder_initialize(adecoder,NULL)) == FALSE)
606                         {
607                                 #ifdef DEBUG
609                                 printf("Could not initialize\n");
611                                 #endif
613                                 gst_object_unref(adecoder);
615                                 return;
616                         }
617                 }
619                 if(gst_adecoder_loop_get_data(adecoder) == FALSE)
620                 {
621                         gst_object_unref(adecoder);
623                         return;
624                 }
626                 if (adecoder->enable_processing == FALSE)
627                 {
628 #ifdef DEBUG
630                         printf("Waiting on lock\n");
632 #endif
634                         pthread_mutex_lock(adecoder->start_decode);
636 #ifdef DEBUG
638                         printf("Lock succeeded\n");
640 #endif
642                 }
644                 if (adecoder->isPaused == TRUE)
645                 {
646                         gst_object_unref(adecoder);
648                         return;
649                 }
651                 if(gst_adecoder_process_data(adecoder) == FALSE)
652                 {
653                         gst_object_unref(adecoder);
655                         return;
656                 }
658                 if(adecoder->firstFrame == TRUE)
660                 gst_adecoder_initialize_osssink(adecoder);
662                 gst_adecoder_output_data(adecoder);
664         }
666         gst_object_unref(adecoder);
670 static gboolean gst_adecoder_loop_get_data(GstADecoder *adecoder)
672         GstBuffer *buf = NULL;
674         if(adecoder->bytes_not_decoded < adecoder->inBufSize && adecoder->isEof == FALSE)
675         {
677                 if (gst_pad_pull_range(adecoder->sinkpad,adecoder->readOffset,INPUT_BUFFER_SIZE - adecoder->bytes_not_decoded,&buf) != GST_FLOW_OK)
678                 {
679                         #ifdef DEBUG
681                         printf("Pad pull range failed\n");
683                         #endif
685                         gst_pad_push_event(adecoder->srcpad, gst_event_new_eos());
687                         return FALSE;
689                 }
691                 if(GST_BUFFER_SIZE(buf) < INPUT_BUFFER_SIZE - adecoder->bytes_not_decoded)
693                 adecoder->isEof = TRUE;
695                 memmove(adecoder->inbuf_start_addr,adecoder->inbuf,adecoder->bytes_not_decoded);
697                 adecoder->inbuf = adecoder->inbuf_start_addr;
699                 memcpy((guint8 *) ((guint32) adecoder->inbuf + adecoder->bytes_not_decoded),GST_BUFFER_DATA(buf), GST_BUFFER_SIZE(buf));
701                 adecoder->bytes_not_decoded += GST_BUFFER_SIZE(buf);
703                 adecoder->readOffset += GST_BUFFER_SIZE(buf);
705                 gst_buffer_unref(buf);
707         }
709         if(adecoder->bytes_not_decoded <= 10)
710         {
711                 #ifdef DEBUG
713                 printf("No more data to decode....Sending EOS event to terminate...\n");
715                 printf("Bytes not decoded:%d\n",adecoder->bytes_not_decoded);
717                 #endif
719                 gst_pad_push_event(adecoder->srcpad, gst_event_new_eos());
721                 adecoder->isEos = TRUE;
723                 return FALSE;
725         }
727         return TRUE;
731 static GstFlowReturn gst_adecoder_chain(GstPad * pad,GstBuffer * input_buffer)
734         GstADecoder *adecoder = GST_ADECODER(gst_pad_get_parent(pad));
736         if(adecoder->initialized == FALSE)
737         {
739                 if((adecoder->initialized = gst_adecoder_decoder_initialize(adecoder,input_buffer)) == FALSE)
740                 {
741                         #ifdef DEBUG
743                         printf("Could not initialize\n");
745                         #endif
747                         gst_object_unref(adecoder);
749                         gst_buffer_unref(input_buffer);
751                         return GST_FLOW_ERROR;
752                 }
754                 adecoder->initTimeStamp = GST_BUFFER_TIMESTAMP(input_buffer);
756         }
758         #ifdef DEBUG
760         printf("Buffer size from Demuxer:%d\n",GST_BUFFER_SIZE(input_buffer));
762         #endif
764         if(gst_adecoder_chain_get_data(adecoder,input_buffer) == FALSE)
765         {
767                 gst_object_unref(adecoder);
769                 return GST_FLOW_OK;
770         }
772         while(adecoder->bytes_not_decoded > adecoder->inBufSize && adecoder->isStopped == FALSE)
773         {
774                 if (adecoder->enable_processing == FALSE)
775                 {
776                         #ifdef DEBUG
778                         printf("Waiting on lock\n");
780                         #endif
782                         pthread_mutex_lock(adecoder->start_decode);
784                         #ifdef DEBUG
786                         printf("Lock succeeded\n");
788                         #endif
790                 }
792                 if( gst_adecoder_process_data(adecoder) == FALSE)
793                 {
794                         gst_object_unref(adecoder);
796                         return GST_FLOW_OK;
797                 }
799                 if(adecoder->firstFrame == TRUE)
801                 gst_adecoder_initialize_osssink(adecoder);
804                 if(gst_adecoder_output_data(adecoder) == FALSE)
805                 {
806                         gst_object_unref(adecoder);
808                         return GST_FLOW_ERROR;
809                 }
810         }
812         gst_object_unref(adecoder);
814         return GST_FLOW_OK;
819 static gboolean gst_adecoder_chain_get_data(GstADecoder *adecoder,GstBuffer * buffer)
821         guint32 buf_size = GST_BUFFER_SIZE(buffer);
823         if(adecoder->inbuf != adecoder->inbuf_start_addr)
824         {
826                 memmove(adecoder->inbuf_start_addr,adecoder->inbuf,adecoder->bytes_not_decoded);
828                 adecoder->inbuf = adecoder->inbuf_start_addr;
829         }
831         if(adecoder->bytes_not_decoded + buf_size >= INPUT_BUFFER_SIZE)
832         {
833                 #ifdef DEBUG
835                 printf("Push mode:Not enough memory to save the buffer....current size:%d\n",adecoder->bytes_not_decoded);
837                 #endif
839                 gst_buffer_unref(buffer);
841                 return FALSE;
842         }
844         memcpy((guint8 *) ((guint32) adecoder->inbuf + adecoder->bytes_not_decoded),(char *)(GST_BUFFER_DATA(buffer)),buf_size);
846         gst_buffer_unref(buffer);
848         adecoder->bytes_not_decoded += buf_size;
850         if(adecoder->bytes_not_decoded < adecoder->inBufSize)
852         return FALSE;
854         return TRUE;
859 static gboolean gst_adecoder_process_data(GstADecoder *adecoder)
862         #ifdef DEBUG
864         printf("Before calling AUDDEC_process\n");
866         #endif
868         if(AUDDEC_process(adecoder->codec_handle,&(adecoder->inBufDesc),&(adecoder->outBufDesc),adecoder->InArgs,adecoder->OutArgs) == AUDDEC_EOK)
869         {
871                 #ifdef DEBUG
873                 printf("AUDDEC_process returned successfully,bytesConsumed:%d\n",adecoder->OutArgs->bytesConsumed);
875                 #endif
877                 adecoder->inbuf += adecoder->OutArgs->bytesConsumed;
879                 adecoder->bytes_not_decoded -= adecoder->OutArgs->bytesConsumed;
881                 AUDDEC_control(adecoder->codec_handle,XDM_GETSTATUS,adecoder->DyParams,adecoder->Status);
883                 adecoder->frameCount++;
885                 #ifdef DEBUG
887                 printf("FrameCount:%u FrameLen:%d SampleRate:%d BitsPerSample:%d BitRate:%d ",adecoder->frameCount,
889                 adecoder->Status->frameLen,adecoder->Status->sampleRate,adecoder->Status->outputBitsPerSample,adecoder->Status->bitRate);
891                 if(adecoder->Status->numChannels == IAUDIO_MONO)
893                 printf("IAUDIO_MONO\n");
895                 else
897                 printf("IAUDIO_STEREO\n");
899                 printf("bytes_not_decoded:%d\n",adecoder->bytes_not_decoded);
901                 #endif
903                 return TRUE;
905         }
907         else
908         {
910                 #ifdef DEBUG
912                 printf("AUDDEC_process returned with failure\n");
914                 #endif
916                 return FALSE;
917         }
921 static void gst_adecoder_initialize_osssink(GstADecoder *adecoder)
923         GstCaps *othercaps, *getcaps;
925         GstStructure *structure;
927         gint rate;
929         othercaps = gst_caps_new_simple ("audio/x-raw-int",
931         "endianness", G_TYPE_INT, G_BYTE_ORDER,
933         "signed", G_TYPE_BOOLEAN, TRUE,
935         "width", G_TYPE_INT, 16,
937         "depth", G_TYPE_INT, 16,
939         "rate", G_TYPE_INT,adecoder->Status->sampleRate,
941         "channels", G_TYPE_INT,DEFAULT_NO_OF_OUTPUT_CHANNELS, NULL);
943         if(gst_pad_set_caps(adecoder->srcpad, othercaps) == FALSE)
945         {
946                 #ifdef DEBUG
948                 printf("Initialize osssink failed\n");
950                 #endif
952         }
954         gst_pad_use_fixed_caps(adecoder->srcpad);
956         getcaps = gst_pad_get_caps(adecoder->srcpad);
958         structure = gst_caps_get_structure(getcaps, 0);
960         gst_structure_get_int(structure,"rate",&rate);
962         #ifdef DEBUG
964         printf("Sampling Rate:%d\n",rate);
966         #endif
968         gst_caps_unref(othercaps);
970         if(adecoder->isInPushMode == FALSE)
972         gst_pad_push_event(adecoder->srcpad,
974                                            gst_event_new_new_segment(   FALSE,
976                                                                                                         adecoder->segment.rate,
978                                                                                                         adecoder->segment.format,
980                                                                                                         adecoder->segment.start,
982                                                                                                         adecoder->segment.duration,
984                                                                                                         adecoder->segment.start));
987         if(adecoder->firstFrame == TRUE)
989         adecoder->firstFrame = FALSE;
994 static gboolean gst_adecoder_output_data(GstADecoder *adecoder)
996         GstFlowReturn ret;
998         GstBuffer *outbuf[2];
1000         guint32 frameLen = adecoder->Status->frameLen;
1002         guint32 bitsPerSample = adecoder->Status->outputBitsPerSample;
1004         guint8 numChannels = adecoder->Status->numChannels;
1006     if(frameLen != 0)
1007     {
1008                 int i;
1010                 for( i = 0; (i < adecoder->outBufDesc.numBufs);i++)
1011                 {
1012                         ret = gst_pad_alloc_buffer(adecoder->srcpad, GST_BUFFER_OFFSET_NONE,frameLen * DEFAULT_NO_OF_OUTPUT_CHANNELS * bitsPerSample / 8
1014                         ,GST_PAD_CAPS(adecoder->srcpad),&(outbuf[i]));
1017                         if (ret != GST_FLOW_OK)
1018                         {
1019                                 #ifdef DEBUG
1021                                 printf("failed when allocating a %ld bytes buffer\n",frameLen * DEFAULT_NO_OF_OUTPUT_CHANNELS * bitsPerSample / 8);
1023                                 #endif
1025                                 if ( (adecoder->isInPushMode == FALSE) && (adecoder->isPaused == FALSE) )
1027                                 gst_pad_pause_task(adecoder->sinkpad);
1029                                 return FALSE;
1030                         }
1032                 }
1034                 for( i = 0;(i < adecoder->outBufDesc.numBufs);i++)
1035             {
1037                         if(adecoder->codec == ST_AUDIO_WMA && numChannels == IAUDIO_MONO) //WMA Decoder is not replicating data in case of MONO.
1039                         {
1040                                 memcpy((char *)((unsigned)(adecoder->outbuf[i]) + frameLen * bitsPerSample / 8),
1042                                 (char *)(adecoder->outbuf[i]),frameLen * bitsPerSample / 8);
1044                                 block_to_interleaved((XDAS_Int16 *)(adecoder->outbuf[i]),(XDAS_Int8 *)GST_BUFFER_DATA(outbuf[i]),frameLen);
1046                         }
1048                         else
1050                         {
1051                                 #ifndef INTERLEAVED
1053                                 block_to_interleaved((XDAS_Int16 *)(adecoder->outbuf[i]),(XDAS_Int8 *)GST_BUFFER_DATA(outbuf[i]),frameLen);
1055                                 #endif
1057                                 memcpy((char *)GST_BUFFER_DATA(outbuf[i]),(char *)adecoder->outbuf[i],
1059                                 frameLen * DEFAULT_NO_OF_OUTPUT_CHANNELS * bitsPerSample / 8);
1061                         }
1063                         if (gst_adecoder_send_data(adecoder,outbuf[i]) != GST_FLOW_OK)
1065                         {
1066                                 #ifdef DEBUG
1068                                 printf("Send data to osssink failed\n");
1070                                 #endif
1072                                 return FALSE;
1073                         }
1076                 }
1078         }
1080         return TRUE;
1085 static gboolean gst_adecoder_decoder_initialize(GstADecoder * adecoder,GstBuffer * input_buffer)
1087         #ifdef DEBUG
1089         printf ("Entering gst_adecoder_decoder_initialize...\n");
1091         #endif
1093         if(gst_adecoder_open_engine(adecoder) == FALSE)
1095         return FALSE;
1097         if(gst_adecoder_create_codec(adecoder,input_buffer) == FALSE)
1099         return FALSE;
1101         if(gst_adecoder_initialize_codec(adecoder) == FALSE)
1103         return FALSE;
1105         if(adecoder->isInPushMode == FALSE)
1107         gst_segment_init(&adecoder->segment, GST_FORMAT_TIME);
1109         #ifdef DEBUG
1111         printf ("Exiting gst_adecoder_decoder_initialize...\n");
1113         #endif
1115         return TRUE;
1119 static gboolean gst_adecoder_open_engine(GstADecoder * adecoder)
1122         CERuntime_init();
1124         //GT_set("*=01234567,CE-1");
1126         if(adecoder->isEnginePropSet == TRUE)
1127         {
1128                 switch (adecoder->engine)
1130                 {
1131                         case H264ENGINE:
1133                         #ifdef DEBUG
1135                         printf ("Opening H264 Engine...\n");
1137                         #endif
1139                         adecoder->ce = Engine_open("H264Engine", NULL, NULL);
1141                         break;
1143                         case MPEG4ENGINE:
1145                         #ifdef DEBUG
1147                         printf ("Opening MPEG4 Engine...\n");
1149                         #endif
1151                         adecoder->ce = Engine_open("MPEG4Engine", NULL, NULL);
1153                         break;
1155                         case WMENGINE:
1157                         #ifdef DEBUG
1159                         printf ("Opening WM Engine...\n");
1161                         #endif
1163                         adecoder->ce = Engine_open("WMEngine", NULL, NULL);
1165                         break;
1167                         case MP3ENGINE:
1169                         #ifdef DEBUG
1171                         printf ("Opening MP3 Engine...\n");
1173                         #endif
1175                         adecoder->ce = Engine_open("MP3Engine", NULL, NULL);
1177                         break;
1179                 }
1181         }
1183         else if(adecoder->isCodecPropSet == TRUE)               //standalone case
1184         {
1185                 switch (adecoder->codec)
1187                 {
1188                         case ST_AUDIO_AAC:
1190                         #ifdef DEBUG
1192                         printf ("Opening MPEG4 Engine...\n");
1194                         #endif
1196                         adecoder->ce = Engine_open("MPEG4Engine", NULL, NULL);
1198                         break;
1200                         case ST_AUDIO_WMA:
1202                         #ifdef DEBUG
1204                         printf ("Opening WM Engine...\n");
1206                         #endif
1208                         adecoder->ce = Engine_open("WMEngine", NULL, NULL);
1210                         break;
1212                         case ST_AUDIO_DSP_MP3:
1214                         #ifdef DEBUG
1216                         printf ("Opening MP3 Engine...\n");
1218                         #endif
1220                         adecoder->ce = Engine_open("MP3Engine", NULL, NULL);
1222                         break;
1224                 }
1226         }
1228         else
1229         {
1230                 #ifdef DEBUG
1232                 printf ("Both properties not Set.....Opening H264 Engine by default..\n");
1234                 #endif
1236                 adecoder->ce = Engine_open("H264Engine", NULL, NULL);
1238         }
1240         if( adecoder->ce == NULL)
1241         {
1242                 #ifdef DEBUG
1244                 printf("Engine_open failed\n");
1246                 #endif
1248                 return FALSE;
1249         }
1251         return TRUE;
1256 static gboolean gst_adecoder_create_codec(GstADecoder * adecoder,GstBuffer * input_buffer)
1259     IAUDDEC_Params audParams;
1260     AUDDEC_Handle audDec;
1263     switch (adecoder->codec)
1264     {
1265         case ST_AUDIO_WMA:
1266         {
1267               #ifdef DEBUG
1268                   printf ("Creating WMA Codec...\n");
1269               #endif
1271               audParams.size            =  sizeof(IAUDDEC_Params);
1272               audParams.maxSampleRate   =  48000;
1273               audParams.maxBitrate      =  384000;
1274               audParams.maxNoOfCh       =  IAUDIO_STEREO;
1275               audParams.dataEndianness  =  XDM_BYTE;
1277               audDec = AUDDEC_create(adecoder->ce, "wma9dec", &audParams);
1279               if (audDec == NULL)
1280               {
1281                  #ifdef DEBUG
1282                     printf("Engine handle:%x\n",adecoder->ce);
1283                     printf("AUDDEC_create failed\n");
1284                  #endif
1285                  return FALSE;
1286               }
1287        }
1288        break;
1290        case ST_AUDIO_AAC:
1291        {
1292             #ifdef DEBUG
1293                 printf ("Creating AAC Codec...\n");
1294             #endif
1296             audParams.size             =  sizeof(IAUDDEC_Params);
1297             audParams.maxSampleRate    =  48000;
1298             audParams.maxBitrate       =  448000;
1299             audParams.maxNoOfCh        =  IAUDIO_STEREO;
1300             audParams.dataEndianness   =  XDM_BYTE;
1302             audDec = AUDDEC_create(adecoder->ce, "aachedec", &audParams);
1304             if (audDec == NULL)
1305             {
1306                 #ifdef DEBUG
1307                    printf("AUDDEC_create failed\n");
1308                 #endif
1309                 return FALSE;
1310             }
1311         }
1312         break;
1314         case ST_AUDIO_DSP_MP3:
1315         {
1316             #ifdef DEBUG
1317                 printf ("Creating DSP MP3 Codec...\n");
1318             #endif
1320             audParams.size             =  sizeof(IAUDDEC_Params);
1321             audParams.maxSampleRate    =  48000;
1322             audParams.maxBitrate       =  448000;
1323             audParams.maxNoOfCh        =  IAUDIO_STEREO;
1324             audParams.dataEndianness   =  XDM_BYTE;
1326             audDec = AUDDEC_create(adecoder->ce, "mp3dec", &audParams);
1328             if (audDec == NULL)
1329             {
1330                #ifdef DEBUG
1331                  printf("AUDDEC_create failed\n");
1332                #endif
1333                return FALSE;
1334             }
1335         }
1336         break;
1338         default:
1339                return FALSE;
1340     }
1341     adecoder->codec_handle = audDec;
1343     #ifdef DEBUG
1344         printf ("Exiting Create Codec...\n");
1345     #endif
1346     return TRUE;
1349 static gboolean gst_adecoder_initialize_codec(GstADecoder * adecoder)
1352         IAUDDEC_DynamicParams *audDynamicParams = NULL;
1353         IAUDDEC_Status *audStatus = NULL;
1354         IAUDDEC_InArgs *InArgs = NULL;
1355         IAUDDEC_OutArgs *OutArgs = NULL;
1356         XDAS_Int32 ret1,ret2,ret3,ret4;
1359         #ifdef DEBUG
1360           printf ("Entering gst_adecoder_initialize_codec...\n");
1361         #endif
1363         switch(adecoder->codec)
1364         {
1365                 case ST_AUDIO_WMA:
1366                 {
1367                    InArgs = (IAUDDEC_InArgs *)malloc(sizeof(IAUDDEC_InArgs));                      
1368                    InArgs->size =  sizeof(IAUDDEC_InArgs);
1370                    OutArgs = (IAUDDEC_OutArgs *)malloc(sizeof(IAUDDEC_OutArgs));                      
1371                    OutArgs->size = sizeof(IAUDDEC_OutArgs);
1373                    audStatus = (IAUDDEC_Status *)malloc(sizeof(IAUDDEC_Status));                      
1374                    audStatus->size =    sizeof(IAUDDEC_Status);
1376                    audDynamicParams = (IAUDDEC_DynamicParams *)malloc(sizeof(IAUDDEC_DynamicParams));           
1377                    audDynamicParams->size = sizeof(IAUDDEC_DynamicParams);
1378                 }
1380                 break;
1382                 case ST_AUDIO_AAC:
1383                 {
1384                    audStatus = (IAUDDEC_Status *)malloc(sizeof(IAUDDEC_Status));                      
1385                    audStatus->size =    sizeof(IAUDDEC_Status);
1386                 }
1387                 break;
1388         }
1390         if(InArgs == NULL)
1391         {
1392                 InArgs = (IAUDDEC_InArgs *)malloc(sizeof(IAUDDEC_InArgs));
1393                 InArgs->size = sizeof(IAUDDEC_InArgs);
1394         }
1396         if(audDynamicParams == NULL)
1397         {
1398                 audDynamicParams = (IAUDDEC_DynamicParams *)malloc(sizeof(IAUDDEC_DynamicParams));
1399                 audDynamicParams->size = sizeof(IAUDDEC_DynamicParams);
1400         }
1402         if(OutArgs == NULL)
1403         {
1404                 OutArgs = (IAUDDEC_OutArgs *)malloc(sizeof(IAUDDEC_OutArgs));
1405                 OutArgs->size = sizeof(IAUDDEC_OutArgs);
1406         }
1408         if(audStatus == NULL)
1409         {
1410                 audStatus       = (IAUDDEC_Status *)malloc(sizeof(IAUDDEC_Status));
1411                 audStatus->size = sizeof(IAUDDEC_Status);
1412         }
1414         #ifdef DEBUG
1416            printf("handle:%x audDynamicParams:%x Status:%x\n",adecoder->codec_handle,audDynamicParams,audStatus);
1418         #endif
1420            // ret1 = AUDDEC_control(adecoder->codec_handle,XDM_RESET,audDynamicParams,audStatus);
1422            //   if (ret1 != AUDDEC_EOK)
1423            //{
1424            //#ifdef DEBUG
1425            //  printf("AUDDEC_control() 1 returned failure in gst_adecoder_initialize_codec()\n");
1426            //#endif
1427            //return FALSE;
1428            //}
1431         ret2 = AUDDEC_control(adecoder->codec_handle,XDM_SETDEFAULT,audDynamicParams,audStatus);
1434         #ifdef INTERLEAVED
1435             audDynamicParams->outputFormat = IAUDIO_INTERLEAVED;
1436         #else
1437             audDynamicParams->outputFormat = IAUDIO_BLOCK;
1438         #endif
1440         ret3 = AUDDEC_control(adecoder->codec_handle,XDM_SETPARAMS, audDynamicParams,audStatus);
1441         ret4 = AUDDEC_control(adecoder->codec_handle,XDM_GETBUFINFO, audDynamicParams, audStatus);
1443         if (ret2!= AUDDEC_EOK)
1444         {
1445                 #ifdef DEBUG
1447                 printf("AUDDEC_control() 2 returned failure in gst_adecoder_initialize_codec()\n");
1449                 #endif
1451                 return FALSE;
1452         }
1454         //      if (ret1 != AUDDEC_EOK || ret2!= AUDDEC_EOK || ret3 != AUDDEC_EOK || ret4 != AUDDEC_EOK)
1455         if (ret3 != AUDDEC_EOK)
1456         {
1457                 #ifdef DEBUG
1459                 printf("AUDDEC_control() 3 returned failure in gst_adecoder_initialize_codec()\n");
1461                 #endif
1463                 return FALSE;
1464         }
1466         if (ret4 != AUDDEC_EOK)
1467         {
1468                 #ifdef DEBUG
1470                 printf("AUDDEC_control() 4 returned failure in gst_adecoder_initialize_codec()\n");
1472                 #endif
1474                 return FALSE;
1475         }
1479         adecoder->inBufSize = audStatus->bufInfo.minInBufSize[0];
1481         #ifdef DEBUG
1483         printf("Input buffer size = %ld\n",audStatus->bufInfo.minInBufSize[0]);
1485         #endif
1487         adecoder->inbuf_start_addr = adecoder->inbuf = (XDAS_Int8 *) Memory_contigAlloc(INPUT_BUFFER_SIZE,Memory_DEFAULTALIGNMENT);
1489         if (adecoder->inbuf == NULL)
1490         {
1491                 #ifdef DEBUG
1493                 printf("Failed to allocate input buffer using CMEM\n");
1495                 #endif
1497                 return FALSE;
1498         }
1500         {
1501                 int i;
1503                 for(i = 0;i < audStatus->bufInfo.minNumOutBufs;i++)
1504                 {
1505                         adecoder->outBufSize[i] = audStatus->bufInfo.minOutBufSize[i];
1507                         adecoder->outbuf[i] = (XDAS_Int8 *) Memory_contigAlloc(adecoder->outBufSize[i],Memory_DEFAULTALIGNMENT);
1509                         if(adecoder->outbuf[i] == NULL)
1510                         {
1511                                 #ifdef DEBUG
1513                                 printf("Failed to allocate output buffer using CMEM\n");
1515                                 #endif
1517                                 return FALSE;
1518                         }
1519                 }
1520         }
1523         adecoder->outBufDesc.bufSizes = adecoder->outBufSize;
1525         adecoder->outBufDesc.numBufs = audStatus->bufInfo.minNumOutBufs;
1527         adecoder->inBufDesc.bufSizes = &adecoder->inBufSize;
1529         adecoder->inBufDesc.numBufs = 1;
1531         adecoder->outBufDesc.bufs = adecoder->outbuf;
1533         adecoder->inBufDesc.bufs = &(adecoder->inbuf);
1535     InArgs->numBytes = adecoder->inBufSize;
1537         adecoder->DyParams = audDynamicParams;
1539         adecoder->Status = audStatus;
1541         adecoder->InArgs = InArgs;
1543         adecoder->OutArgs = OutArgs;
1545         #ifdef DEBUG
1547         printf ("Exiting gst_adecoder_initialize_codec...\n");
1549         #endif
1551         return TRUE;
1556 static void block_to_interleaved(XDAS_Int16 *src,XDAS_Int8 *dest,guint32 frameLen)
1558         short i,j;
1560         unsigned short c,c1,c2;
1562         for(i = 0,j = 0;i < frameLen;i++,j += 4)
1563         {
1564                         /* Left Channel */
1566                         c  = src[i];
1568                         c1 = (c >> 8) & 0xff;
1570                         c2 = c & 0xff;
1572                         dest[j] = c2;
1574                         dest[j+1] = c1;
1576                         /* Right Channel  */
1578                         c    = src[i+frameLen];
1580                         c1 = (c >> 8) & 0xff;
1582                         c2 = c & 0xff;
1584                         dest[j+2] = c2;
1586                         dest[j+3] = c1;
1587         }
1591 #ifdef PROFILE
1593 static unsigned long timeDiffMs(struct timespec *pTs1, struct timespec *pTs2)
1595    unsigned long  delta = 0;
1597    pTs1->tv_nsec /= 1000;
1599    pTs2->tv_nsec /= 1000;
1601    delta  = pTs2->tv_nsec > pTs1->tv_nsec ?
1603             (pTs2->tv_sec - pTs1->tv_sec) * 1000000 + (pTs2->tv_nsec - pTs1->tv_nsec) :
1605             (pTs2->tv_sec - pTs1->tv_sec - 1) * 1000000 + (1000000 - pTs1->tv_nsec + pTs2->tv_nsec);
1607    return (delta);
1610 #endif
1612 static GstFlowReturn gst_adecoder_send_data(GstADecoder * adecoder,GstBuffer * buffer)
1614         #ifdef TIMESTAMP_ENABLE
1616         if(adecoder->isInPushMode == TRUE)      //No timestamps in case of Pull mode / Standalone playback.
1617         {
1619                 if(adecoder->frame_time == 0 && adecoder->initTimeStamp != 0)
1621                 adecoder->frame_time = adecoder->initTimeStamp;
1623                 else
1625                 adecoder->frame_time += adecoder->Status->frameLen * NANO_SEC_PER_SEC / adecoder->Status->sampleRate;
1627                 GST_BUFFER_TIMESTAMP(buffer) = adecoder->frame_time;
1629                 #ifdef DEBUG
1631                 printf("Timestamp value:%llu\n",GST_BUFFER_TIMESTAMP(buffer));
1633                 #endif
1634         }
1636         #endif
1638         return gst_pad_push(adecoder->srcpad, buffer);
1641 static gboolean gst_adecoder_sink_event(GstPad * pad, GstEvent * event)
1644     GstADecoder *adecoder = GST_ADECODER(GST_PAD_PARENT(pad));
1646     gboolean ret = TRUE;
1648     #ifdef DEBUG
1650     printf("Got %s event on sink pad\n", GST_EVENT_TYPE_NAME(event));
1652     #endif
1654     switch (GST_EVENT_TYPE(event))
1655     {
1656                 case GST_EVENT_NEWSEGMENT:
1658                 ret = gst_pad_event_default(pad, event);
1660                 break;
1662         case GST_EVENT_FLUSH_START:
1664         ret = gst_pad_event_default(pad, event);
1666         break;
1668         case GST_EVENT_FLUSH_STOP:
1670         ret = gst_pad_event_default(pad, event);
1672         break;
1674         case GST_EVENT_EOS:
1676                 gst_adecoder_decode_remaining(adecoder);
1678         ret = gst_pad_event_default(pad, event);
1680         break;
1682         default:
1684         ret = gst_pad_event_default(pad, event);
1686         break;
1687     }
1689     return ret;
1692 static void gst_adecoder_decode_remaining(GstADecoder * adecoder)
1695         while(adecoder->bytes_not_decoded > 10 && adecoder->isStopped == FALSE)
1696         {
1697                 if(adecoder->enable_processing == FALSE)
1699                 pthread_mutex_lock(adecoder->start_decode);
1701                 gst_adecoder_process_data(adecoder);
1703                 if(gst_adecoder_output_data(adecoder) == FALSE)
1705                 break;
1707         }
1709         #ifdef DEBUG
1711         printf("bytes_not_decoded:%d\n",adecoder->bytes_not_decoded);
1713         #endif
1717 static gboolean gst_adecoder_src_event(GstPad * pad, GstEvent * event)
1719     gboolean res;
1721     GstADecoder *adecoder;
1723     adecoder = GST_ADECODER(GST_PAD_PARENT(pad));
1725     if (adecoder->codec_handle == NULL)
1727     goto no_decoder;
1729     res = gst_pad_push_event(adecoder->sinkpad, event);
1731     return res;
1733     no_decoder:
1734     {
1735         GST_DEBUG_OBJECT(adecoder, "no decoder, cannot handle event");
1737         gst_event_unref(event);
1739         return FALSE;
1740     }
1743 static GstStateChangeReturn gst_adecoder_change_state(GstElement * element, GstStateChange transition)
1745     GstStateChangeReturn result;
1747     GstADecoder *adecoder = GST_ADECODER(element);
1749         switch (transition)
1750     {
1751         case GST_STATE_CHANGE_NULL_TO_READY:
1753         GST_DEBUG_OBJECT(adecoder, "State Changed from NULL_TO_READY\n");
1755         break;
1758         case GST_STATE_CHANGE_READY_TO_PAUSED:
1760         GST_DEBUG_OBJECT(adecoder, "State Changed from READY_TO_PAUSED\n");
1762         break;
1764                 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1766         adecoder->isPaused = FALSE;
1768                 break;
1770                 default:
1772         break;
1773     }
1775     result = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
1777     switch (transition)
1778     {
1779         case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1781         adecoder->isPaused = TRUE;
1783         #ifdef DEBUG
1785         printf("playing to paused\n");
1787         #endif
1789         break;
1791         case GST_STATE_CHANGE_PAUSED_TO_READY:
1793         adecoder->isStopped = TRUE;
1795         #ifdef DEBUG
1797         printf("paused to ready\n");
1799         #endif
1801         break;
1803         case GST_STATE_CHANGE_READY_TO_NULL:
1805         #ifdef DEBUG
1807         printf("Ready to Null\n");
1809         #endif
1811         free(adecoder->DyParams);
1813         free(adecoder->Status);
1815         free(adecoder->InArgs);
1817         free(adecoder->OutArgs);
1819         pthread_mutex_unlock(adecoder->start_decode);
1821         free(adecoder->start_decode);
1823         if (adecoder->inbuf != NULL)
1825                 Memory_contigFree((XDAS_Int8 *) (adecoder->inbuf_start_addr),INPUT_BUFFER_SIZE);
1827                 if (adecoder->outbuf[0] != NULL)
1829                 Memory_contigFree((XDAS_Int8 *) (adecoder->outbuf[0]),adecoder->outBufSize[0]);
1831                 if (adecoder->outbuf[1] != NULL)
1833                 Memory_contigFree((XDAS_Int8 *) (adecoder->outbuf[1]),adecoder->outBufSize[1]);
1835                 AUDDEC_delete(adecoder->codec_handle);
1837         Engine_close(adecoder->ce);
1839                 gst_adecoder_initialize_handle(adecoder);
1841         break;
1843         default:
1845         break;
1846     }
1848     return result;
1851 static gboolean plugin_init(GstPlugin * plugin)
1853     if (!gst_element_register(plugin, "adecoder", GST_RANK_PRIMARY, GST_TYPE_ADECODER))
1855     return FALSE;
1857         return TRUE;
1860 GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
1862                   GST_VERSION_MINOR,
1864                   "adecoder",
1866                   "Audio Decoders",
1868                   plugin_init,
1870                   VERSION,
1872                   GST_LICENSE_UNKNOWN, "adecoder", "http://www.ti.com/")