gst_plugins_symbian/gst/devsound/gstdevsoundsink.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
    30 #include "gstg711decoderinterface.h"
    30 #include "gstg711decoderinterface.h"
    31 #include "gstg729decoderinterface.h"
    31 #include "gstg729decoderinterface.h"
    32 #include "gstilbcdecoderinterface.h"
    32 #include "gstilbcdecoderinterface.h"
    33 #include "string.h"
    33 #include "string.h"
    34 #include <glib_global.h>
    34 #include <glib_global.h>
    35 #ifdef AV_SYNC
       
    36 #include <gst/audio/gstaudioclock.h>
       
    37 #endif /*AV_SYNC*/
       
    38 
       
    39 
    35 
    40 GST_DEBUG_CATEGORY_EXTERN (devsound_debug);
    36 GST_DEBUG_CATEGORY_EXTERN (devsound_debug);
    41 #ifdef GST_CAT_DEFAULT
       
    42 #undef GST_CAT_DEFAULT
       
    43 #endif
       
    44 
       
    45 #define GST_CAT_DEFAULT devsound_debug
    37 #define GST_CAT_DEFAULT devsound_debug
    46 
    38 
    47 /* elementfactory information */
    39 /* elementfactory information */
    48 static const GstElementDetails gst_devsound_sink_details=
    40 static const GstElementDetails gst_devsound_sink_details=
    49 GST_ELEMENT_DETAILS ("Audio Sink (DEVSOUND)",
    41 GST_ELEMENT_DETAILS ("Audio Sink (DEVSOUND)",
    65         const GValue * value, GParamSpec * pspec);
    57         const GValue * value, GParamSpec * pspec);
    66 
    58 
    67 static GstCaps *gst_devsound_sink_getcaps(GstBaseSink * bsink);
    59 static GstCaps *gst_devsound_sink_getcaps(GstBaseSink * bsink);
    68 static gboolean gst_devsound_sink_setcaps(GstBaseSink *bsink, GstCaps *caps);
    60 static gboolean gst_devsound_sink_setcaps(GstBaseSink *bsink, GstCaps *caps);
    69 
    61 
       
    62 
    70 static gboolean gst_devsound_sink_event(GstBaseSink * asink, GstEvent * event);
    63 static gboolean gst_devsound_sink_event(GstBaseSink * asink, GstEvent * event);
    71 #ifdef AV_SYNC
       
    72 static void gst_devsound_sink_get_times(GstBaseSink * bsink, GstBuffer * buffer,
       
    73     GstClockTime * start, GstClockTime * end);
       
    74 static GstClock *gst_devsound_sink_provide_clock (GstElement * element);
       
    75 static GstClockTime gst_devsound_sink_get_time (GstClock * clock,
       
    76     gpointer user_data);
       
    77 #endif /*AV_SYNC*/
       
    78 
       
    79 static GstStateChangeReturn gst_devsound_sink_change_state (GstElement * element,
       
    80     GstStateChange transition);
       
    81 
       
    82 
    64 
    83 static void *StartDevSoundThread(void *threadid);
    65 static void *StartDevSoundThread(void *threadid);
       
    66 
    84 
    67 
    85 //Error concealment interface impl
    68 //Error concealment interface impl
    86 static void gst_error_concealment_handler_init (gpointer g_iface,
    69 static void gst_error_concealment_handler_init (gpointer g_iface,
    87     gpointer iface_data);
    70     gpointer iface_data);
    88 static gint gst_ConcealErrorForNextBuffer(void);
    71 static gint gst_ConcealErrorForNextBuffer();
    89 static gint gst_SetFrameMode(gboolean aFrameMode);
    72 static gint gst_SetFrameMode(gboolean aFrameMode);
    90 static gint gst_FrameModeRqrdForEC(gboolean* aFrameModeRqrd);
    73 static gint gst_FrameModeRqrdForEC(gboolean* aFrameModeRqrd);
    91 static void gst_Apply_ErrorConcealment_Update(GstDevsoundSink* dssink);
    74 static void gst_Apply_ErrorConcealment_Update(GstDevsoundSink* dssink);
    92 
    75 
    93 //G711 interface impl
    76 //G711 interface impl
   101 
    84 
   102 
    85 
   103 //G729 interface impl
    86 //G729 interface impl
   104 static void gst_g729_decoder_handler_init (gpointer g_iface,
    87 static void gst_g729_decoder_handler_init (gpointer g_iface,
   105     gpointer iface_data);
    88     gpointer iface_data);
   106 static gint gst_BadLsfNextBuffer(void);
    89 static gint gst_BadLsfNextBuffer();
   107 static void gst_Apply_G729_Decoder_Update(GstDevsoundSink* dssink );
    90 static void gst_Apply_G729_Decoder_Update(GstDevsoundSink* dssink );
   108 
    91 
   109 //Ilbc interface impl
    92 //Ilbc interface impl
   110 static void gst_ilbc_decoder_handler_init (gpointer g_iface,
    93 static void gst_ilbc_decoder_handler_init (gpointer g_iface,
   111     gpointer iface_data);
    94     gpointer iface_data);
   112 static gint gst_GetIlbcCng(gboolean* aCng);
    95 static gint gst_GetIlbcCng(gboolean* aCng);
   113 static gint gst_SetIlbcCng(gboolean aCng);
    96 static gint gst_SetIlbcCng(gboolean aCng);
   114 static gint gst_SetIlbcDecoderMode(enum TIlbcDecodeMode aDecodeMode);
    97 static gint gst_SetIlbcDecoderMode(enum TIlbcDecodeMode aDecodeMode);
   115 static void  gst_Apply_Ilbc_Decoder_Update(GstDevsoundSink* dssink );
    98 static void  gst_Apply_Ilbc_Decoder_Update(GstDevsoundSink* dssink );
   116 
    99 
   117 static void get_PopulateIntfcProperties(GstDevsoundSink* dssink);
       
   118 
   100 
   119 static gboolean gst_sink_start (GstBaseSink * sink);
   101 static gboolean gst_sink_start (GstBaseSink * sink);
   120 static gboolean gst_sink_stop (GstBaseSink * sink);
   102 static gboolean gst_sink_stop (GstBaseSink * sink);
   121 static GstFlowReturn gst_sink_render (GstBaseSink * sink,
   103 static GstFlowReturn gst_sink_render (GstBaseSink * sink,
   122     GstBuffer * buffer);
   104     GstBuffer * buffer);
   176     PROP_0,
   158     PROP_0,
   177     PROP_DEVICE,
   159     PROP_DEVICE,
   178     VOLUME,
   160     VOLUME,
   179     MAXVOLUME,
   161     MAXVOLUME,
   180     VOLUMERAMP,
   162     VOLUMERAMP,
   181 /*    CHANNELS,*/
   163     CHANNELS,
   182     LEFTBALANCE,
   164     LEFTBALANCE,
   183     RIGHTBALANCE,
   165     RIGHTBALANCE,
   184 /*    RATE,*/
   166     RATE,
   185     PRIORITY,
   167     PRIORITY,
   186     PREFERENCE,
   168     PREFERENCE,
   187 /*    SAMPLESPLAYED,*/
   169     SAMPLESPLAYED,
   188 /*    FOURCC, //FOURCC is not needed*/
   170     FOURCC, //FOURCC is not needed
   189 /*    MIMETYPE,*/
   171     MIMETYPE,
   190     OUTPUTDEVICE
   172     OUTPUTDEVICE
   191     };
   173     };
   192 
   174 
   193 enum command_to_consumer_thread_enum
   175 enum command_to_consumer_thread_enum
   194     {
   176     {
   195     OPEN = 2,
   177     OPEN = 2,
   196     PLAYING,
   178     WRITEDATA,
   197     PAUSE,
       
   198     RESUME,
       
   199     /*UPDATE,*/
   179     /*UPDATE,*/
   200     WAIT,
       
   201     CLOSE
   180     CLOSE
   202     };
   181     };
   203 enum command_to_consumer_thread_enum cmd;
   182 enum command_to_consumer_thread_enum cmd;
   204 
   183 
   205 static GstStaticPadTemplate devsoundsink_sink_factory=
   184 static GstStaticPadTemplate devsoundsink_sink_factory=
   206     GST_STATIC_PAD_TEMPLATE ("sink",
   185     GST_STATIC_PAD_TEMPLATE ("sink",
   207         GST_PAD_SINK,
   186         GST_PAD_SINK,
   208         GST_PAD_ALWAYS,
   187         GST_PAD_ALWAYS,
   209         GST_STATIC_CAPS ("audio/x-raw-int, " "endianness = (int) { " G_STRINGIFY (G_BYTE_ORDER) " }, " "signed = (boolean) TRUE, " "width = (int) 16, " "depth = (int) 16, " "rate = (int) [ 8000, 48000 ]," "channels = (int) [ 1, 2 ]; "
   188         GST_STATIC_CAPS ("audio/x-raw-int, "
   210                 "audio/amr, " "rate = (int) 8000, " "channels = (int) 1 ; "
   189                 "endianness = (int) { " G_STRINGIFY (G_BYTE_ORDER) " }, "
   211                 "audio/AMR, " "rate = (int) 8000, " "channels = (int) 1 ; "
   190                 "signed = (boolean) TRUE, "
   212                 "audio/x-alaw, " "rate = (int) [ 8000, 48000 ], " "channels = (int) [ 1, 2 ]; "
   191                 "width = (int) 16, "
   213                 "audio/g729, " "rate = (int) [ 8000, 48000 ], " "channels = (int) [ 1, 2 ]; "
   192                 "depth = (int) 16, "
   214                 "audio/mpeg, mpegversion = (int) 1, layer = (int) [ 1, 3 ], rate = (int) [ 8000, 48000 ], channels = (int) [ 1, 2 ]; "                
   193                 "rate = (int) [ 8000, 48000 ],"
   215                 "audio/ilbc, " "rate = (int) [ 8000, 48000 ], " "channels = (int) [ 1, 2 ]; "
   194                 "channels = (int) [ 1, 2 ]; "
   216                 "audio/x-mulaw, " "rate = (int) [ 8000, 48000 ], " "channels = (int) [ 1, 2 ]")
   195                 "audio/amr, "
       
   196                 //"width = (int) 8, "
       
   197                 //"depth = (int) 8, "
       
   198                 "rate = (int) 8000, "
       
   199                 "channels = (int) 1 ; "
       
   200                 "audio/x-alaw, "
       
   201                 "rate = (int) [ 8000, 48000 ], "
       
   202                 "channels = (int) [ 1, 2 ]; "
       
   203                 "audio/g729, "
       
   204                 "rate = (int) [ 8000, 48000 ], "
       
   205                 "channels = (int) [ 1, 2 ]; "
       
   206                 "audio/mp3, "
       
   207                 "rate = (int) [ 8000, 48000 ], "
       
   208                 "channels = (int) [ 1, 2 ]; "                
       
   209                 "audio/ilbc, "
       
   210                 "rate = (int) [ 8000, 48000 ], "
       
   211                 "channels = (int) [ 1, 2 ]; "
       
   212                 "audio/x-mulaw, "
       
   213                 "rate = (int) [ 8000, 48000 ], "
       
   214                 "channels = (int) [ 1, 2 ]")
   217                 );
   215                 );
   218 
   216 
   219 static GstElementClass *parent_class= NULL;
   217 static GstElementClass *parent_class= NULL;
   220 
   218 
   221 GType gst_devsound_sink_get_type(void)
   219 GType gst_devsound_sink_get_type(void)
   262                NULL
   260                NULL
   263                };
   261                };
   264 
   262 
   265         devsoundsink_type =
   263         devsoundsink_type =
   266         g_type_register_static (GST_TYPE_BASE_SINK, "GstDevsoundSink",
   264         g_type_register_static (GST_TYPE_BASE_SINK, "GstDevsoundSink",
   267             &devsoundsink_info, (GTypeFlags)0);
   265             &devsoundsink_info, 0);
   268 
   266 
   269 
   267 
   270         g_type_add_interface_static (devsoundsink_type, GST_TYPE_ERROR_CONCEALMENT,
   268         g_type_add_interface_static (devsoundsink_type, GST_TYPE_ERROR_CONCEALMENT,
   271          &error_concealment_info);
   269          &error_concealment_info);
   272 
   270 
   284     return devsoundsink_type;
   282     return devsoundsink_type;
   285     }
   283     }
   286 
   284 
   287 static void gst_devsound_sink_dispose(GObject * object)
   285 static void gst_devsound_sink_dispose(GObject * object)
   288     {
   286     {
   289     GstDevsoundSink *devsoundsink = GST_DEVSOUND_SINK (object);
   287     GstDevsoundSink *devsoundsink= GST_DEVSOUND_SINK (object);
   290 
   288 
   291     if (devsoundsink->probed_caps)
   289     if (devsoundsink->probed_caps)
   292         {
   290         {
   293         gst_caps_unref(devsoundsink->probed_caps);
   291         gst_caps_unref(devsoundsink->probed_caps);
   294         devsoundsink->probed_caps = NULL;
   292         devsoundsink->probed_caps = NULL;
   295         }
   293         }
   296 #ifdef AV_SYNC
   294 
   297     if (devsoundsink->clock)
       
   298         {
       
   299         gst_object_unref (devsoundsink->clock);
       
   300         }
       
   301     devsoundsink->clock = NULL;
       
   302 #endif /*AV_SYNC*/
       
   303     G_OBJECT_CLASS (parent_class)->dispose (object);
   295     G_OBJECT_CLASS (parent_class)->dispose (object);
   304     }
   296     }
   305 
   297 
   306 static void gst_devsound_sink_base_init(gpointer g_class)
   298 static void gst_devsound_sink_base_init(gpointer g_class)
   307     {
   299     {
   330 
   322 
   331     gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_devsound_sink_dispose);
   323     gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_devsound_sink_dispose);
   332     gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_devsound_sink_finalise);
   324     gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_devsound_sink_finalise);
   333     gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_devsound_sink_get_property);
   325     gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_devsound_sink_get_property);
   334     gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_devsound_sink_set_property);
   326     gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_devsound_sink_set_property);
   335     
   327 
   336     
       
   337     gstelement_class->change_state = GST_DEBUG_FUNCPTR(gst_devsound_sink_change_state);
       
   338     
       
   339     g_object_class_install_property(gobject_class, PROP_DEVICE,
   328     g_object_class_install_property(gobject_class, PROP_DEVICE,
   340             g_param_spec_string("device", "Device", "Devsound device ",
   329             g_param_spec_string("device", "Device", "Devsound device ",
   341             DEFAULT_DEVICE, (GParamFlags)G_PARAM_READWRITE));
   330             DEFAULT_DEVICE, G_PARAM_READWRITE));
   342 
   331 
   343     g_object_class_install_property(gobject_class, VOLUME,
   332     g_object_class_install_property(gobject_class, VOLUME,
   344                 g_param_spec_int("volume", "Volume", "Devsound volume",
   333                 g_param_spec_int("volume", "Volume", "Devsound volume",
   345                         -1, G_MAXINT, -1, (GParamFlags)G_PARAM_READWRITE));
   334                         -1, G_MAXINT, -1, G_PARAM_READWRITE));
   346 
   335 
   347     g_object_class_install_property(gobject_class, VOLUMERAMP,
   336     g_object_class_install_property(gobject_class, VOLUMERAMP,
   348               g_param_spec_int("volumeramp", "VolumeRamp", "Devsound volume ramp",
   337               g_param_spec_int("volumeramp", "VolumeRamp", "Devsound volume ramp",
   349                       -1, G_MAXINT, -1, (GParamFlags)G_PARAM_READWRITE));
   338                       -1, G_MAXINT, -1, G_PARAM_READWRITE));
   350 
   339 
   351     g_object_class_install_property(gobject_class, MAXVOLUME,
   340     g_object_class_install_property(gobject_class, MAXVOLUME,
   352             g_param_spec_int("maxvolume", "MaxVolume", "Devsound max volume",
   341             g_param_spec_int("maxvolume", "MaxVolume", "Devsound max volume",
   353                     -1, G_MAXINT, -1, G_PARAM_READABLE));
   342                     -1, G_MAXINT, -1, G_PARAM_READABLE));
   354 
   343 
   355     g_object_class_install_property(gobject_class, LEFTBALANCE,
   344     g_object_class_install_property(gobject_class, LEFTBALANCE,
   356                   g_param_spec_int("leftbalance", "Left Balance", "Left Balance",
   345                   g_param_spec_int("leftbalance", "Left Balance", "Left Balance",
   357                           -1, G_MAXINT, -1, (GParamFlags)G_PARAM_READWRITE));
   346                           -1, G_MAXINT, -1, G_PARAM_READWRITE));
   358 
   347 
   359     g_object_class_install_property(gobject_class, RIGHTBALANCE,
   348     g_object_class_install_property(gobject_class, RIGHTBALANCE,
   360                    g_param_spec_int("rightbalance", "Right Balance", "Right Balance",
   349                    g_param_spec_int("rightbalance", "Right Balance", "Right Balance",
   361                            -1, G_MAXINT, -1, (GParamFlags)G_PARAM_READWRITE));
   350                            -1, G_MAXINT, -1, G_PARAM_READWRITE));
   362 /*
   351 
   363     g_object_class_install_property(gobject_class, SAMPLESPLAYED,
   352     g_object_class_install_property(gobject_class, SAMPLESPLAYED,
   364                       g_param_spec_int("samplesplayed", "Samples Played", "Samples Played",
   353                       g_param_spec_int("samplesplayed", "Samples Played", "Samples Played",
   365                               -1, G_MAXINT, -1, G_PARAM_READABLE));
   354                               -1, G_MAXINT, -1, G_PARAM_READABLE));
   366 */
   355 
   367     g_object_class_install_property(gobject_class, PRIORITY,
   356     g_object_class_install_property(gobject_class, PRIORITY,
   368             g_param_spec_int("priority", "Priority", "Priority ", -1,
   357             g_param_spec_int("priority", "Priority", "Priority ", -1,
   369                     G_MAXINT, -1,
   358                     G_MAXINT, -1,
   370                     (GParamFlags)G_PARAM_READWRITE));
   359                     G_PARAM_READWRITE));
   371 
   360 
   372     g_object_class_install_property(gobject_class, PREFERENCE,
   361     g_object_class_install_property(gobject_class, PREFERENCE,
   373             g_param_spec_int("preference", "Preference", "Preference ", -1,
   362             g_param_spec_int("preference", "Preference", "Preference ", -1,
   374                     G_MAXINT, -1,
   363                     G_MAXINT, -1,
   375                     (GParamFlags)G_PARAM_READWRITE));
   364                     G_PARAM_READWRITE));
   376 /*
   365 
   377     g_object_class_install_property(gobject_class, RATE,
   366     g_object_class_install_property(gobject_class, RATE,
   378             g_param_spec_int("rate", "Rate", "Rate ", -1,
   367             g_param_spec_int("rate", "Rate", "Rate ", -1,
   379                     G_MAXINT, -1,
   368                     G_MAXINT, -1,
   380                     G_PARAM_READWRITE));
   369                     G_PARAM_READWRITE));
   381 
   370 
   382     g_object_class_install_property(gobject_class, CHANNELS,
   371     g_object_class_install_property(gobject_class, CHANNELS,
   383             g_param_spec_int("channels", "Channels", "Channels ", -1,
   372             g_param_spec_int("channels", "Channels", "Channels ", -1,
   384                     G_MAXINT, -1,
   373                     G_MAXINT, -1,
   385                     G_PARAM_READWRITE));
   374                     G_PARAM_READWRITE));
   386 */
   375 
   387     g_object_class_install_property(gobject_class, OUTPUTDEVICE,
   376     g_object_class_install_property(gobject_class, OUTPUTDEVICE,
   388              g_param_spec_int("outputdevice", "Output Device", "Output Device ", -1,
   377              g_param_spec_int("outputdevice", "Output Device", "Output Device ", -1,
   389                      G_MAXINT, -1,
   378                      G_MAXINT, -1,
   390                      (GParamFlags)G_PARAM_READWRITE));
   379                      G_PARAM_READWRITE));
   391     
   380     
   392 #ifdef AV_SYNC
       
   393     gstelement_class->provide_clock = GST_DEBUG_FUNCPTR (gst_devsound_sink_provide_clock);
       
   394 #endif /*AV_SYNC*/
       
   395 
       
   396     gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_sink_start);
   381     gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_sink_start);
   397     gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_sink_stop);
   382     gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_sink_stop);
   398     gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_sink_render);
   383     gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_sink_render);
   399 
   384 
   400     gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_devsound_sink_getcaps);
   385     gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_devsound_sink_getcaps);
   401     gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_devsound_sink_setcaps);
   386     gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_devsound_sink_setcaps);
   402     gstbasesink_class->event    = GST_DEBUG_FUNCPTR (gst_devsound_sink_event);
   387     gstbasesink_class->event    = GST_DEBUG_FUNCPTR (gst_devsound_sink_event);
   403 #ifdef AV_SYNC
   388     }
   404     gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_devsound_sink_get_times);
   389 
   405 #endif /*AV_SYNC*/
   390 static void gst_devsound_sink_init(GstDevsoundSink * devsoundsink)
   406     }
   391     {
   407 
   392     GST_DEBUG_OBJECT(devsoundsink, "initializing devsoundsink");
   408 static void gst_devsound_sink_init(GstDevsoundSink * dssink)
   393     devsoundsink->device = g_strdup(DEFAULT_DEVICE);
   409     {
   394     devsoundsink->handle = NULL;
   410     GST_DEBUG_OBJECT(dssink, "initializing devsoundsink");
   395     devsoundsink->preference = 0; //default=>EMdaPriorityPreferenceNone;
   411     dssink->device = g_strdup(DEFAULT_DEVICE);
   396     devsoundsink->priority = 0;   //default=>EMdaPriorityNormal;
   412     dssink->handle = NULL;
       
   413     dssink->preference = 0; //default=>EMdaPriorityPreferenceNone;
       
   414     dssink->priority = 0;   //default=>EMdaPriorityNormal;
       
   415 #ifdef AV_SYNC
       
   416     dssink->time_or_samples_played = 0;
       
   417     dssink->timeplayedavailable = FALSE;
       
   418     /* Create the provided clock. */
       
   419     dssink->clock = gst_audio_clock_new ("clock", gst_devsound_sink_get_time, dssink);
       
   420 #endif /*AV_SYNC*/
       
   421     pthread_mutex_init(&ds_mutex, NULL);
   397     pthread_mutex_init(&ds_mutex, NULL);
   422     pthread_cond_init(&ds_condition, NULL);
   398     pthread_cond_init(&ds_condition, NULL);
   423     }
   399     }
   424 
   400 
   425 static void *StartDevSoundThread(void *threadarg)
   401 static void *StartDevSoundThread(void *threadarg)
   426     {
   402     {
   427     GstDevsoundSink *dssink;
   403 
       
   404     GstDevsoundSink *devsound;
   428 
   405 
   429     gint remainingDataLen = 0;
   406     gint remainingDataLen = 0;
   430     GstBuffer *buffer = NULL;
   407     GstBuffer *buffer = NULL;
   431     gboolean lastBufferSet=FALSE;
   408     gboolean lastBufferSet=FALSE;
   432     dssink = (GstDevsoundSink*) threadarg;
   409     devsound = (GstDevsoundSink*) threadarg;
   433 
   410 
   434     // TODO handle error here
   411     open_devsound(&(devsound->handle));
   435     open_devsound(&(dssink->handle));
       
   436 #ifdef AV_SYNC
       
   437     dssink->timeplayedavailable = is_timeplayed_supported(dssink->handle);
       
   438 #endif /*AV_SYNC*/
       
   439 
   412 
   440 
   413 
   441     //get supported (in/out)put datatypes
   414     //get supported (in/out)put datatypes
   442     //from devsound to build caps
   415     //from devsound to build caps
   443     getsupporteddatatypes(dssink);
   416     getsupporteddatatypes(devsound);
   444 
   417 
   445     // TODO obtain mutex to update variable here???
   418     // TODO obtain mutex to update variable here???
   446     consumer_thread_state = CONSUMER_THREAD_INITIALIZED;
   419     consumer_thread_state = CONSUMER_THREAD_INITIALIZED;
   447 
   420 
   448     // Signal any waiting threads that consumer thread creation was successful.
   421     // Signal any waiting threads that consumer thread creation was successful.
   463     // without putting it to play state
   436     // without putting it to play state
   464     if ( cmd != CLOSE )
   437     if ( cmd != CLOSE )
   465         {
   438         {
   466         //TODO if there is preemption we have to somehow signal
   439         //TODO if there is preemption we have to somehow signal
   467         //the pipeline in the render
   440         //the pipeline in the render
   468         initialize_devsound(dssink);
   441         initialize_devsound(devsound);
   469 
   442 
   470         playinit(dssink->handle);
   443         playinit(devsound->handle);
   471         dssink->eosreceived = FALSE;
   444         initproperties(devsound);
   472         initproperties(dssink);
       
   473         }
   445         }
   474     while (1)
   446     while (1)
   475         {
   447         {
   476         switch (cmd)
   448         switch (cmd)
   477             {
   449             {
   478             case PAUSE:
   450             case WRITEDATA:
   479                 pause_devsound(dssink);
       
   480                 cmd = WAIT;
       
   481                 break;
       
   482                 
       
   483             case RESUME:
       
   484                 resume_devsound(dssink);
       
   485                 cmd = PLAYING;
       
   486                 break;
       
   487             
       
   488             case WAIT:
       
   489                 pthread_mutex_lock(&ds_mutex);
       
   490                 pthread_cond_signal(&ds_condition);
       
   491                 pthread_mutex_unlock(&ds_mutex);
       
   492                             
       
   493                 pthread_mutex_lock(&ds_mutex);
       
   494                 pthread_cond_wait(&ds_condition, &ds_mutex);
       
   495                 pthread_mutex_unlock(&ds_mutex);
       
   496                 break;
       
   497                 
       
   498             case PLAYING:
       
   499                 {
   451                 {
   500                 pre_init_setconf(dssink);
   452                 pre_init_setconf(devsound);
   501                 gst_Apply_ErrorConcealment_Update(dssink);
   453                 gst_Apply_ErrorConcealment_Update(devsound);
   502                 gst_Apply_G711_Decoder_Update(dssink);
   454                 gst_Apply_G711_Decoder_Update(devsound);
   503                 gst_Apply_G729_Decoder_Update(dssink);
   455                 gst_Apply_G729_Decoder_Update(devsound);
   504                 gst_Apply_Ilbc_Decoder_Update(dssink);
   456                 gst_Apply_Ilbc_Decoder_Update(devsound);
   505 
   457 
   506                 // TODO we could do this in BTBF callback
   458                 // TODO we could do this in BTBF callback
   507                 populateproperties(dssink);
   459                 populateproperties(devsound);
   508                 get_PopulateIntfcProperties(dssink);
   460 
   509                 
   461                 framemodereq = devsound->framemodereq;
       
   462                 g711cng = devsound->g711cng;
       
   463                 ilbccng = devsound->ilbccng;
       
   464                 output = devsound->output;
       
   465 
   510                 if(buffer_queue->length > 0)
   466                 if(buffer_queue->length > 0)
   511                     {
   467                     {
   512                     if (remainingDataLen == 0)
   468                     if (remainingDataLen == 0)
   513                         {
   469                         {
   514                         // TODO enable lock and unlock
   470                         // TODO enable lock and unlock
   515                         GST_OBJECT_LOCK (dssink);
   471                         GST_OBJECT_LOCK (devsound);
   516                         buffer = GST_BUFFER_CAST(g_queue_peek_head(buffer_queue));
   472                         buffer = GST_BUFFER_CAST(g_queue_peek_head(buffer_queue));
   517                         GST_OBJECT_UNLOCK(dssink);
   473                         GST_OBJECT_UNLOCK(devsound);
   518                         remainingDataLen = GST_BUFFER_SIZE(buffer);
   474                         remainingDataLen = GST_BUFFER_SIZE(buffer);
   519                         }
   475                         }
   520 
   476 
   521                     lastBufferSet =  GST_BUFFER_FLAG_IS_SET(buffer,GST_BUFFER_FLAG_LAST);
   477                     lastBufferSet =  GST_BUFFER_FLAG_IS_SET(buffer,GST_BUFFER_FLAG_LAST);
   522                     remainingDataLen = write_data(dssink->handle,
   478                     remainingDataLen = write_data(devsound->handle,
   523                             GST_BUFFER_DATA(buffer) + (GST_BUFFER_SIZE(buffer) - remainingDataLen),
   479                             GST_BUFFER_DATA(buffer) + (GST_BUFFER_SIZE(buffer) - remainingDataLen),
   524                             remainingDataLen,
   480                             remainingDataLen,
   525                             lastBufferSet);
   481                             lastBufferSet);
   526 
   482 
   527                     if (remainingDataLen == 0)
   483                     if (remainingDataLen == 0)
   528                         {
   484                         {
   529                         GST_OBJECT_LOCK (dssink);
   485                         GST_OBJECT_LOCK (devsound);
   530                         buffer = GST_BUFFER_CAST(g_queue_pop_head(buffer_queue));
   486                         buffer = GST_BUFFER_CAST(g_queue_pop_head(buffer_queue));
   531                         GST_OBJECT_UNLOCK(dssink);
   487                         GST_OBJECT_UNLOCK(devsound);
   532                         gst_buffer_unref(buffer);
   488                         gst_buffer_unref(buffer);
   533                         buffer = NULL;
   489                         buffer = NULL;
   534                         }
   490                         }
   535 
   491 
   536                     if (lastBufferSet && remainingDataLen == 0)
   492                     if (lastBufferSet && remainingDataLen == 0)
   537                         {
   493                         {
   538                         lastBufferSet = FALSE;
   494                         // Last Buffer is already sent to DevSound
   539                         dssink->eosreceived = FALSE;
   495                         // and we have received PlayError so now we exit
   540                         playinit(dssink->handle);
   496                         // from the big loop next time
   541                         initproperties(dssink);
   497 /*
   542                         get_PopulateIntfcProperties(dssink);
   498                         pthread_mutex_lock(&ds_mutex);
   543                         cmd = WAIT;
   499                         pthread_cond_signal(&ds_condition);
   544                         }
   500                         pthread_mutex_unlock(&ds_mutex);
       
   501 */
       
   502                         cmd = CLOSE;
       
   503                        }
   545                     }
   504                     }
   546                 else
   505                 else
   547                     {
   506                     {
   548                     cmd = WAIT;
   507                     pthread_mutex_lock(&ds_mutex);
       
   508                     pthread_cond_wait(&ds_condition, &ds_mutex);
       
   509                     pthread_mutex_unlock(&ds_mutex);
   549                     }
   510                     }
   550                 }
   511                 }
   551                 break;
   512                 break;
   552             case CLOSE:
   513             case CLOSE:
   553                 {
   514                 {
   554                 close_devsound(dssink);
   515                 close_devsound(devsound);
   555                 dssink->handle= NULL;
   516                 devsound->handle= NULL;
   556                 pthread_mutex_lock(&ds_mutex);
   517                 pthread_mutex_lock(&ds_mutex);
   557                 pthread_cond_signal(&ds_condition);
   518                 pthread_cond_signal(&ds_condition);
   558                 pthread_mutex_unlock(&ds_mutex);
   519                 pthread_mutex_unlock(&ds_mutex);
   559                 // TODO obtain mutex here
   520                 // TODO obtain mutex here
   560                 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;
   521                 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;
   574     }
   535     }
   575 
   536 
   576 static gboolean gst_sink_start (GstBaseSink * sink)
   537 static gboolean gst_sink_start (GstBaseSink * sink)
   577     {
   538     {
   578     GstBuffer *tmp_gstbuffer=NULL;
   539     GstBuffer *tmp_gstbuffer=NULL;
   579     GstDevsoundSink *dssink = GST_DEVSOUND_SINK(sink);
   540     GstDevsoundSink *devsound = GST_DEVSOUND_SINK(sink);
   580 
   541 
   581     if(buffer_queue)
   542     if(buffer_queue)
   582         {
   543         {
   583         while (buffer_queue->length)
   544         while (buffer_queue->length)
   584             {
   545             {
   594           buffer_queue = g_queue_new();
   555           buffer_queue = g_queue_new();
   595           }
   556           }
   596 
   557 
   597     consumer_thread_state = CONSUMER_THREAD_INITIALIZING;
   558     consumer_thread_state = CONSUMER_THREAD_INITIALIZING;
   598     cmd = OPEN;
   559     cmd = OPEN;
   599     pthread_create(&ds_thread,  NULL, StartDevSoundThread, (void *)dssink);
   560     pthread_create(&ds_thread,  NULL, StartDevSoundThread, (void *)devsound);
   600 
   561 
   601     // Wait until consumer thread is created
   562     // Wait until consumer thread is created
   602     // TODO : obtain mutex to retreive thread state?
   563     // TODO : obtain mutex to retreive thread state?
   603     if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING)
   564     if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING)
   604         {
   565         {
   611     }
   572     }
   612 
   573 
   613 static gboolean gst_sink_stop (GstBaseSink * sink)
   574 static gboolean gst_sink_stop (GstBaseSink * sink)
   614     {
   575     {
   615     GstBuffer *tmp_gstbuffer=NULL;
   576     GstBuffer *tmp_gstbuffer=NULL;
   616     GstDevsoundSink *dssink = GST_DEVSOUND_SINK(sink);
   577     GstDevsoundSink *devsound = GST_DEVSOUND_SINK(sink);
   617 
   578 
   618     cmd = CLOSE;
   579     cmd = CLOSE;
   619 
   580 
   620     pthread_mutex_lock(&ds_mutex);
   581     pthread_mutex_lock(&ds_mutex);
   621     pthread_cond_signal(&ds_condition);
   582     pthread_cond_signal(&ds_condition);
   622     pthread_mutex_unlock(&ds_mutex);
   583     pthread_mutex_unlock(&ds_mutex);
   623 
   584 
   624     pthread_mutex_lock(&ds_mutex);
   585     GST_OBJECT_LOCK(devsound);
   625     pthread_cond_wait(&ds_condition, &ds_mutex);
       
   626     pthread_mutex_unlock(&ds_mutex);
       
   627     
       
   628 
       
   629     GST_OBJECT_LOCK(dssink);
       
   630     while (buffer_queue->length)
   586     while (buffer_queue->length)
   631         {
   587         {
   632         tmp_gstbuffer = (GstBuffer*)g_queue_pop_tail(buffer_queue);
   588         tmp_gstbuffer = (GstBuffer*)g_queue_pop_tail(buffer_queue);
   633         gst_buffer_unref(tmp_gstbuffer);
   589         gst_buffer_unref(tmp_gstbuffer);
   634         }
   590         }
   635     g_queue_free(buffer_queue);
   591     g_queue_free(buffer_queue);
   636     buffer_queue = NULL;
   592     buffer_queue = NULL;
   637     GST_OBJECT_UNLOCK(dssink);
   593     GST_OBJECT_UNLOCK(devsound);
   638 
   594 
   639     return TRUE;
   595     return TRUE;
   640     }
   596     }
   641 
   597 
   642 static GstFlowReturn gst_sink_render (GstBaseSink * sink,
   598 static GstFlowReturn gst_sink_render (GstBaseSink * sink,
   643     GstBuffer * buffer)
   599     GstBuffer * buffer)
   644     {
   600     {
   645     GstDevsoundSink *dssink = GST_DEVSOUND_SINK(sink);
   601     GstDevsoundSink *devsound = GST_DEVSOUND_SINK(sink);
   646     GstBuffer* tmp;
   602     GstBuffer* tmp;
   647 
   603 
   648     if (get_ds_cb_error(dssink->handle))
   604     if (get_ds_cb_error(devsound->handle))
   649         {
   605         {
   650         return GST_FLOW_CUSTOM_ERROR;
   606         return GST_FLOW_CUSTOM_ERROR;
   651         }
   607         }
   652         
   608         
   653     tmp = gst_buffer_copy(buffer);
   609     tmp = gst_buffer_copy(buffer);
   654  
   610  
   655     GST_OBJECT_LOCK (dssink);
   611     GST_OBJECT_LOCK (devsound);
   656     g_queue_push_tail (buffer_queue, tmp);
   612     g_queue_push_tail (buffer_queue, tmp);
   657     GST_OBJECT_UNLOCK (dssink);
   613     GST_OBJECT_UNLOCK (devsound);
   658 
   614 
   659     cmd = PLAYING;
   615     cmd = WRITEDATA;
   660     pthread_mutex_lock(&ds_mutex);
   616     pthread_mutex_lock(&ds_mutex);
   661     pthread_cond_signal(&ds_condition);
   617     pthread_cond_signal(&ds_condition);
   662     pthread_mutex_unlock(&ds_mutex);
   618     pthread_mutex_unlock(&ds_mutex);
   663 
   619 
   664     return GST_FLOW_OK;
   620     return GST_FLOW_OK;
   665     }
   621     }
   666 
   622 
   667 static void gst_devsound_sink_finalise(GObject * object)
   623 static void gst_devsound_sink_finalise(GObject * object)
   668     {
   624     {
   669     GstDevsoundSink *devsoundsink = GST_DEVSOUND_SINK (object);
   625     GstDevsoundSink *devsoundsink= GST_DEVSOUND_SINK (object);
   670     g_free(devsoundsink->device);
   626     g_free(devsoundsink->device);
   671 
   627 
   672     }
   628     }
   673 
   629 
   674 static void gst_devsound_sink_set_property(GObject * object, guint prop_id,
   630 static void gst_devsound_sink_set_property(GObject * object, guint prop_id,
   688                 {
   644                 {
   689                 gst_caps_unref(sink->probed_caps);
   645                 gst_caps_unref(sink->probed_caps);
   690                 sink->probed_caps = NULL;
   646                 sink->probed_caps = NULL;
   691                 }
   647                 }
   692             break;
   648             break;
   693 /*        case CHANNELS:
   649         case CHANNELS:
   694             sink->channels = g_value_get_int(value);
   650             sink->channels = g_value_get_int(value);
   695             sink->pending.channelsupdate = TRUE;
   651             sink->pending.channelsupdate = TRUE;
   696             break;
   652             break;
   697         case RATE:
   653         case RATE:
   698             sink->rate = g_value_get_int(value);
   654             sink->rate = g_value_get_int(value);
   699             //Convert rate to something devsound understands
   655             //Convert rate to something devsound understands
   700             sink->rate = gst_devsound_sink_get_rate(sink->rate);
   656             sink->rate = gst_devsound_sink_get_rate(sink->rate);
   701             sink->pending.rateupdate = TRUE;
   657             sink->pending.rateupdate = TRUE;
   702             break;
   658             break;
   703 */        case VOLUME:
   659         case VOLUME:
   704             sink->volume = g_value_get_int(value);
   660             sink->volume = g_value_get_int(value);
   705             sink->pending.volumeupdate = TRUE;
   661             sink->pending.volumeupdate = TRUE;
   706             break;
   662             break;
   707         case LEFTBALANCE:
   663         case LEFTBALANCE:
   708             sink->leftbalance = g_value_get_int(value);
   664             sink->leftbalance = g_value_get_int(value);
   722             break;
   678             break;
   723         case PREFERENCE:
   679         case PREFERENCE:
   724             sink->preference = g_value_get_int(value);
   680             sink->preference = g_value_get_int(value);
   725             sink->pending.preferenceupdate = TRUE;
   681             sink->pending.preferenceupdate = TRUE;
   726             break;
   682             break;
   727 /*        case FOURCC: //FOURCC is not needed
   683         case FOURCC: //FOURCC is not needed
   728             sink->fourcc = g_value_get_int(value);
   684             sink->fourcc = g_value_get_int(value);
   729             sink->pending.fourccupdate = TRUE;
   685             sink->pending.fourccupdate = TRUE;
   730             break;
   686             break;
       
   687 
   731         case MIMETYPE:
   688         case MIMETYPE:
   732             sink->mimetype = g_value_dup_string(value);
   689             sink->mimetype = g_value_dup_string(value);
   733             break;*/
   690             break;
   734         case OUTPUTDEVICE:
   691         case OUTPUTDEVICE:
   735             sink->output = g_value_get_int(value);
   692             sink->output = g_value_get_int(value);
   736             sink->pending.outputupdate = TRUE;
   693             sink->pending.outputupdate = TRUE;
   737             break;
   694             break;
   738         default:
   695         default:
   751     switch (prop_id)
   708     switch (prop_id)
   752         {
   709         {
   753         case PROP_DEVICE:
   710         case PROP_DEVICE:
   754             g_value_set_string(value, sink->device);
   711             g_value_set_string(value, sink->device);
   755             break;
   712             break;
   756 /*        case CHANNELS:
   713         case CHANNELS:
   757             g_value_set_int(value, sink->channels);
   714             g_value_set_int(value, sink->channels);
   758             break;
   715             break;
   759         case RATE:
   716         case RATE:
   760             g_value_set_int(value, sink->rate);
   717             g_value_set_int(value, sink->rate);
   761             break;*/
   718             break;
   762         case VOLUME:
   719         case VOLUME:
   763             g_value_set_int(value, sink->volume);
   720             g_value_set_int(value, sink->volume);
   764             break;
   721             break;
   765         case MAXVOLUME:
   722         case MAXVOLUME:
   766             g_value_set_int(value, sink->maxvolume);
   723             g_value_set_int(value, sink->maxvolume);
   767             break;
   724             break;
   768 /*        case SAMPLESPLAYED:
   725         case SAMPLESPLAYED:
   769               g_value_set_int(value, sink->samplesplayed);
   726               g_value_set_int(value, sink->samplesplayed);
   770               break;*/
   727               break;
   771         case OUTPUTDEVICE:
   728         case OUTPUTDEVICE:
   772               g_value_set_int(value, sink->output);
   729               g_value_set_int(value, sink->output);
   773               break;
   730               break;
   774         default:
   731         default:
   775             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   732             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   823         }
   780         }
   824     else if (!strncmp(mimetype, "audio/g729", 10))
   781     else if (!strncmp(mimetype, "audio/g729", 10))
   825         {
   782         {
   826         devsoundsink->fourcc = 0x39323747; //KMccFourCCIdG729   
   783         devsoundsink->fourcc = 0x39323747; //KMccFourCCIdG729   
   827         }
   784         }
   828     else if (!strncmp(mimetype, "audio/mpeg", 10))
   785     else if (!strncmp(mimetype, "audio/mp3", 9))
   829         {
   786         {
   830         devsoundsink->fourcc = 0x33504d20; //KMMFFourCCCodeMP3    
   787         devsoundsink->fourcc = 0x33504d20; //KMMFFourCCCodeMP3    
   831         }
   788         }
   832     else
   789     else
   833         {
   790         {
   964 
   921 
   965 
   922 
   966 
   923 
   967 static gboolean gst_devsound_sink_event(GstBaseSink *asink, GstEvent *event)
   924 static gboolean gst_devsound_sink_event(GstBaseSink *asink, GstEvent *event)
   968     {
   925     {
   969     GstDevsoundSink *sink = GST_DEVSOUND_SINK (asink);
   926     GstDevsoundSink *sink= GST_DEVSOUND_SINK (asink);
   970     GstBuffer* lastBuffer = NULL;
   927     GstBuffer* lastBuffer = NULL;
   971     switch (GST_EVENT_TYPE (event))
   928     switch (GST_EVENT_TYPE (event))
   972         {
   929         {
   973         case GST_EVENT_EOS:
   930         case GST_EVENT_EOS:
   974             // end-of-stream, we should close down all stream leftovers here
   931             // end-of-stream, we should close down all stream leftovers here
   975             //reset_devsound(sink->handle);
   932             //reset_devsound(sink->handle);
   976             sink->eosreceived = TRUE;
   933 
   977             if(buffer_queue->length)
   934             if(buffer_queue->length)
   978                 {
   935                 {
   979                 GST_OBJECT_LOCK(sink);
   936                 GST_OBJECT_LOCK(sink);
   980                 lastBuffer = GST_BUFFER(g_queue_peek_tail(buffer_queue));
   937                 lastBuffer = GST_BUFFER(g_queue_peek_tail(buffer_queue));
   981                 GST_BUFFER_FLAG_SET(lastBuffer,GST_BUFFER_FLAG_LAST);
   938                 GST_BUFFER_FLAG_SET(lastBuffer,GST_BUFFER_FLAG_LAST);
   986                 lastBuffer = gst_buffer_new();
   943                 lastBuffer = gst_buffer_new();
   987                 GST_BUFFER_FLAG_SET(lastBuffer,GST_BUFFER_FLAG_LAST);
   944                 GST_BUFFER_FLAG_SET(lastBuffer,GST_BUFFER_FLAG_LAST);
   988                 GST_OBJECT_LOCK(sink);
   945                 GST_OBJECT_LOCK(sink);
   989                 g_queue_push_tail(buffer_queue,lastBuffer);
   946                 g_queue_push_tail(buffer_queue,lastBuffer);
   990                 GST_OBJECT_UNLOCK(sink);
   947                 GST_OBJECT_UNLOCK(sink);
   991                 cmd = PLAYING;
   948                 cmd = WRITEDATA;
   992                 pthread_mutex_lock(&ds_mutex);
   949                 pthread_mutex_lock(&ds_mutex);
   993                 pthread_cond_signal(&ds_condition);
   950                 pthread_cond_signal(&ds_condition);
   994                 pthread_mutex_unlock(&ds_mutex);
   951                 pthread_mutex_unlock(&ds_mutex);
   995                 }
   952                 }
   996             pthread_mutex_lock(&ds_mutex);
   953             pthread_mutex_lock(&ds_mutex);
  1003         }
   960         }
  1004 
   961 
  1005     return TRUE;
   962     return TRUE;
  1006     }
   963     }
  1007 
   964 
  1008 #ifdef AV_SYNC
       
  1009 static void gst_devsound_sink_get_times (GstBaseSink * bsink, GstBuffer * buffer,
       
  1010     GstClockTime * start, GstClockTime * end)
       
  1011     {
       
  1012     /* Like GstBaseAudioSink, we set these to NONE */
       
  1013     *start = GST_CLOCK_TIME_NONE;
       
  1014     *end = GST_CLOCK_TIME_NONE;
       
  1015     }
       
  1016 
       
  1017 static GstClock *gst_devsound_sink_provide_clock (GstElement * element)
       
  1018     {
       
  1019     GstDevsoundSink *sink = GST_DEVSOUND_SINK (element);
       
  1020     return GST_CLOCK (gst_object_ref (sink->clock));
       
  1021     }
       
  1022 
       
  1023 static GstClockTime gst_devsound_sink_get_time (GstClock * clock, gpointer user_data)
       
  1024     {
       
  1025     GstClockTime result = 0;
       
  1026     GstDevsoundSink *sink = GST_DEVSOUND_SINK (user_data);
       
  1027 
       
  1028     /* The value returned must be in nano seconds. 1 sec = 1000000000 nano seconds (9 zeros)*/
       
  1029     /*If time played is available from DevSound (a3f devsound onwards) get it*/
       
  1030     if (sink->timeplayedavailable)
       
  1031         {
       
  1032         result = sink->time_or_samples_played;
       
  1033         }
       
  1034     else if ((sink->time_or_samples_played > 0 ) && (sink->rate > 0 ))/*This is a pre-a3f devsound. So calculate times played based on samples played*/
       
  1035         { /*GST_SECOND = 1000000000*/
       
  1036         result = gst_util_uint64_scale_int (sink->time_or_samples_played, GST_SECOND, sink->rate);
       
  1037         }
       
  1038     GST_LOG_OBJECT (sink, "Time: %" GST_TIME_FORMAT, GST_TIME_ARGS (result));
       
  1039     return result;
       
  1040     }
       
  1041 #endif /*AV_SYNC*/
       
  1042 
       
  1043 static GstStateChangeReturn gst_devsound_sink_change_state (GstElement * element, GstStateChange transition)
       
  1044     {
       
  1045     GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
       
  1046     GstDevsoundSink *sink= GST_DEVSOUND_SINK (element);
       
  1047     
       
  1048     switch (transition)
       
  1049         {
       
  1050         case GST_STATE_CHANGE_NULL_TO_READY:
       
  1051             {
       
  1052 #ifdef AV_SYNC
       
  1053             sink->time_or_samples_played = 0;
       
  1054 #endif /*AV_SYNC*/			
       
  1055             }
       
  1056             break;
       
  1057 
       
  1058         case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
       
  1059             if(cmd == WAIT)
       
  1060                 {
       
  1061                 cmd = RESUME;
       
  1062                 pthread_mutex_lock(&ds_mutex);
       
  1063                 pthread_cond_signal(&ds_condition);
       
  1064                 pthread_mutex_unlock(&ds_mutex);
       
  1065                 
       
  1066                 pthread_mutex_lock(&ds_mutex);
       
  1067                 pthread_cond_wait(&ds_condition, &ds_mutex);
       
  1068                 pthread_mutex_unlock(&ds_mutex);
       
  1069                 }
       
  1070             break;
       
  1071         default:
       
  1072             break;
       
  1073         }
       
  1074 
       
  1075     ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
       
  1076       if (G_UNLIKELY (ret == GST_STATE_CHANGE_FAILURE))
       
  1077         goto activate_failed;
       
  1078 
       
  1079       switch (transition) {
       
  1080           
       
  1081           case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
       
  1082               cmd = PAUSE;
       
  1083               pthread_mutex_lock(&ds_mutex);
       
  1084               pthread_cond_signal(&ds_condition);
       
  1085               pthread_mutex_unlock(&ds_mutex);
       
  1086               
       
  1087               pthread_mutex_lock(&ds_mutex);
       
  1088               pthread_cond_wait(&ds_condition, &ds_mutex);
       
  1089               pthread_mutex_unlock(&ds_mutex);
       
  1090               break;
       
  1091           default:
       
  1092               break;
       
  1093           }
       
  1094       
       
  1095       return ret;
       
  1096     
       
  1097     activate_failed:
       
  1098       {
       
  1099         GST_DEBUG_OBJECT (sink,
       
  1100             "element failed to change states -- activation problem?");
       
  1101         return GST_STATE_CHANGE_FAILURE;
       
  1102       }    
       
  1103     }
       
  1104 
       
  1105 
   965 
  1106 /************************************
   966 /************************************
  1107 * Error Concealment Interface begins
   967 * Error Concealment Interface begins
  1108 * **********************************/
   968 * **********************************/
  1109 static void gst_error_concealment_handler_init (gpointer g_iface,
   969 static void gst_error_concealment_handler_init (gpointer g_iface,
  1223     }
  1083     }
  1224 
  1084 
  1225 static gint gst_BadLsfNextBuffer()
  1085 static gint gst_BadLsfNextBuffer()
  1226     {
  1086     {
  1227     customInfaceUpdate.g729badlsfnextbufferupdate = TRUE;
  1087     customInfaceUpdate.g729badlsfnextbufferupdate = TRUE;
  1228     return 0;
       
  1229     }
  1088     }
  1230 
  1089 
  1231 static void gst_Apply_G729_Decoder_Update(GstDevsoundSink* dssink )
  1090 static void gst_Apply_G729_Decoder_Update(GstDevsoundSink* dssink )
  1232     {
  1091     {
  1233     if(customInfaceUpdate.g729badlsfnextbufferupdate)
  1092     if(customInfaceUpdate.g729badlsfnextbufferupdate)
  1281         {
  1140         {
  1282         set_ilbcdecodermode(dssink->handle,ilbcdecodemode);
  1141         set_ilbcdecodermode(dssink->handle,ilbcdecodemode);
  1283         customInfaceUpdate.ilbcdecodermodeupdate = FALSE;
  1142         customInfaceUpdate.ilbcdecodermodeupdate = FALSE;
  1284         }
  1143         }
  1285     }
  1144     }
  1286 
       
  1287 static void get_PopulateIntfcProperties(GstDevsoundSink* dssink)
       
  1288     {
       
  1289     framemode_rqrd_for_ec(dssink->handle,&framemodereq);   
       
  1290 
       
  1291     get_cng(dssink->handle,&g711cng);
       
  1292     
       
  1293     get_ilbccng(dssink->handle,&ilbccng);
       
  1294     }
       
  1295