gst_plugins_symbian/gst/devsound/gstdevsoundsrc.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
    21  */
    21  */
    22 
    22 
    23 #ifdef HAVE_CONFIG_H
    23 #ifdef HAVE_CONFIG_H
    24 #include "config.h"
    24 #include "config.h"
    25 #endif
    25 #endif
    26 #include <gst/gst.h>
    26 
    27 #include <e32err.h> 
       
    28 #include <gqueue.h>
    27 #include <gqueue.h>
    29 #include "common.h"
    28 #include "common.h"
    30 #include "gstdevsoundsrc.h"
    29 #include "gstdevsoundsrc.h"
    31 
    30 
    32 #include <glib_global.h>
    31 #include <glib_global.h>
    35 #include "gstg729encoderinterface.h"
    34 #include "gstg729encoderinterface.h"
    36 #include "gstilbcencoderinterface.h"
    35 #include "gstilbcencoderinterface.h"
    37 #include "string.h"
    36 #include "string.h"
    38 
    37 
    39 GST_DEBUG_CATEGORY_EXTERN (devsoundsrc_debug);
    38 GST_DEBUG_CATEGORY_EXTERN (devsoundsrc_debug);
    40 #ifdef GST_CAT_DEFAULT
       
    41 #undef GST_CAT_DEFAULT
       
    42 #endif
       
    43 
       
    44 #define GST_CAT_DEFAULT devsoundsrc_debug
    39 #define GST_CAT_DEFAULT devsoundsrc_debug
    45 
    40 
    46 /* elementfactory information */
    41 /* elementfactory information */
    47 static const GstElementDetails gst_devsound_src_details=
    42 static const GstElementDetails gst_devsound_src_details=
    48 GST_ELEMENT_DETAILS ("Audio Src (DEVSOUND)",
    43 GST_ELEMENT_DETAILS ("Audio Src (DEVSOUND)",
    73 static gboolean gst_devsound_src_get_size(GstBaseSrc * src, guint64 * size);
    68 static gboolean gst_devsound_src_get_size(GstBaseSrc * src, guint64 * size);
    74 
    69 
    75 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset,
    70 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset,
    76         guint size, GstBuffer **buf);
    71         guint size, GstBuffer **buf);
    77 static void *StartDevSoundThread(void *threadid);
    72 static void *StartDevSoundThread(void *threadid);
    78 
       
    79 static gboolean gst_devsound_src_event(GstBaseSrc * asrc, GstEvent * event);
       
    80 
       
    81 static GstStateChangeReturn gst_devsound_src_change_state (GstElement * element,
       
    82     GstStateChange transition);
       
    83 
    73 
    84 /*********************************
    74 /*********************************
    85  * Speech Encoder Config Interface
    75  * Speech Encoder Config Interface
    86  * ******************************/
    76  * ******************************/
    87 static void gst_speech_encoder_config_handler_init(gpointer g_iface,
    77 static void gst_speech_encoder_config_handler_init(gpointer g_iface,
    91         GList** aSupportedBitrates);
    81         GList** aSupportedBitrates);
    92 static gint gst_get_speech_encoder_vad_mode(gboolean* aVadMode);
    82 static gint gst_get_speech_encoder_vad_mode(gboolean* aVadMode);
    93 static gint gst_set_speech_encoder_bit_rate(guint aBitrate);
    83 static gint gst_set_speech_encoder_bit_rate(guint aBitrate);
    94 static gint gst_set_speech_encoder_vad_mode(gboolean aVadMode);
    84 static gint gst_set_speech_encoder_vad_mode(gboolean aVadMode);
    95 static void gst_Apply_SpeechEncoder_Update(GstDevsoundSrc *devsoundsrc );
    85 static void gst_Apply_SpeechEncoder_Update(GstDevsoundSrc *devsoundsrc );
    96 static void gst_update_devsound_speech_bitrate(GstDevsoundSrc *devsoundsrc );
    86 
    97 
    87 
    98 /*************************
    88 /*************************
    99  * G711 Encoder Interface
    89  * G711 Encoder Interface
   100  * ***********************/
    90  * ***********************/
   101 static void gst_g711_encoder_handler_init(gpointer g_iface,
    91 static void gst_g711_encoder_handler_init(gpointer g_iface,
   127 static void gst_Apply_IlbcEncoder_Update(GstDevsoundSrc *devsoundsrc );
   117 static void gst_Apply_IlbcEncoder_Update(GstDevsoundSrc *devsoundsrc );
   128 
   118 
   129 
   119 
   130 static gint gst_devsound_src_get_rate(gint rate);
   120 static gint gst_devsound_src_get_rate(gint rate);
   131 
   121 
   132 static void post_symbian_error ( GstBaseSrc* element, int symbian_error );
       
   133 
   122 
   134 typedef struct _GstCustomIfaceUpdate GstCustomIfaceUpdate;
   123 typedef struct _GstCustomIfaceUpdate GstCustomIfaceUpdate;
   135 
   124 
   136 struct _GstCustomIfaceUpdate{
   125 struct _GstCustomIfaceUpdate{
   137 gboolean  speechbitrateupdate;
   126 gboolean  speechbitrateupdate;
   173 int dataCopied = 0;
   162 int dataCopied = 0;
   174 
   163 
   175 enum command_to_consumer_thread_enum
   164 enum command_to_consumer_thread_enum
   176     {
   165     {
   177     OPEN = 2,
   166     OPEN = 2,
   178     RECORDING,
   167     READDATA,
   179     PAUSE,
       
   180     RESUME,
       
   181     STOP,
       
   182     /*UPDATE,*/
   168     /*UPDATE,*/
   183     CLOSE
   169     CLOSE
   184     };
   170     };
   185 enum command_to_consumer_thread_enum cmd;
   171 enum command_to_consumer_thread_enum cmd;
   186 int return_error;
   172 
   187 enum
   173 enum
   188     {
   174     {
   189     LAST_SIGNAL
   175     LAST_SIGNAL
   190     };
   176     };
   191 
   177 
   213         GST_STATIC_CAPS ("audio/x-raw-int, "
   199         GST_STATIC_CAPS ("audio/x-raw-int, "
   214                 "endianness = (int) { " G_STRINGIFY (G_BYTE_ORDER) " }, "
   200                 "endianness = (int) { " G_STRINGIFY (G_BYTE_ORDER) " }, "
   215                 "signed = (boolean) TRUE, "
   201                 "signed = (boolean) TRUE, "
   216                 "width = (int) 16, "
   202                 "width = (int) 16, "
   217                 "depth = (int) 16, "
   203                 "depth = (int) 16, "
   218                 "rate = (int) { 8000, 16000, 24000, 32000, 48000 },"
   204                 "rate = (int) [ 8000, 48000 ],"
   219                 "channels = (int) [ 1, 2 ]; "
   205                 "channels = (int) [ 1, 2 ]; "
   220                 "audio/amr, "
   206                 "audio/amr, "
   221                 "rate = (int) 8000, "
   207                 "rate = (int) [ 8000, 48000 ], "
   222                 "channels = (int) [ 1, 2 ]; ")
   208                 "channels = (int) [ 1, 2 ]; "
       
   209                 "audio/x-alaw, "
       
   210                 "rate = (int) [ 8000, 48000 ], "
       
   211                 "channels = (int) [ 1, 2 ]; "
       
   212                 "audio/g729, "
       
   213                 "rate = (int) [ 8000, 48000 ], "
       
   214                 "channels = (int) [ 1, 2 ]; "
       
   215                 "audio/ilbc, "
       
   216                 "rate = (int) [ 8000, 48000 ], "
       
   217                 "channels = (int) [ 1, 2 ]; "
       
   218                 "audio/x-mulaw, "
       
   219                 "rate = (int) [ 8000, 48000 ], "
       
   220                 "channels = (int) [ 1, 2 ]")
   223                 );
   221                 );
   224 
   222 
   225 static GstElementClass *parent_class= NULL;
   223 static GstElementClass *parent_class= NULL;
   226 
   224 
   227 static void gst_devsound_src_base_init(gpointer g_class)
   225 static void gst_devsound_src_base_init(gpointer g_class)
   276          NULL
   274          NULL
   277          };
   275          };
   278 
   276 
   279     devsoundsrc_type =
   277     devsoundsrc_type =
   280     g_type_register_static (GST_TYPE_PUSH_SRC, "GstDevsoundSrc",
   278     g_type_register_static (GST_TYPE_PUSH_SRC, "GstDevsoundSrc",
   281             &devsoundsrc_info, (GTypeFlags)0);
   279             &devsoundsrc_info, 0);
   282 
   280 
   283     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_SPEECH_ENCODER_CONFIG,
   281     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_SPEECH_ENCODER_CONFIG,
   284             &speech_encoder_config_info);
   282             &speech_encoder_config_info);
   285 
   283 
   286     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_G711_ENCODER,
   284     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_G711_ENCODER,
   319 
   317 
   320     gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_devsound_src_dispose);
   318     gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_devsound_src_dispose);
   321     gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_devsound_src_get_property);
   319     gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_devsound_src_get_property);
   322     gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_devsound_src_set_property);
   320     gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_devsound_src_set_property);
   323 
   321 
   324     gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_devsound_src_change_state);
       
   325     
       
   326     g_object_class_install_property(gobject_class, PROP_DEVICE,
   322     g_object_class_install_property(gobject_class, PROP_DEVICE,
   327             g_param_spec_string("device", "Device", "Devsound device ",
   323             g_param_spec_string("device", "Device", "Devsound device ",
   328                     DEFAULT_DEVICE, (GParamFlags)G_PARAM_READWRITE));
   324                     DEFAULT_DEVICE, G_PARAM_READWRITE));
   329 
   325 
   330     g_object_class_install_property(gobject_class, GAIN, g_param_spec_int(
   326     g_object_class_install_property(gobject_class, GAIN, g_param_spec_int(
   331             "gain", "Gain", "Devsound src gain", -1, G_MAXINT, -1,
   327             "gain", "Gain", "Devsound src gain", -1, G_MAXINT, -1,
   332             (GParamFlags)G_PARAM_READWRITE));
   328             G_PARAM_READWRITE));
   333 
   329 
   334     g_object_class_install_property(gobject_class, MAXGAIN, g_param_spec_int(
   330     g_object_class_install_property(gobject_class, MAXGAIN, g_param_spec_int(
   335             "maxgain", "MaxGain", "Devsound src max gain", -1, G_MAXINT, -1,
   331             "maxgain", "MaxGain", "Devsound src max gain", -1, G_MAXINT, -1,
   336             G_PARAM_READABLE));
   332             G_PARAM_READABLE));
   337 
   333 
   338     g_object_class_install_property(gobject_class, LEFTBALANCE,
   334     g_object_class_install_property(gobject_class, LEFTBALANCE,
   339             g_param_spec_int("leftbalance", "Left Balance", "Left Balance",
   335             g_param_spec_int("leftbalance", "Left Balance", "Left Balance",
   340                     -1, G_MAXINT, -1, (GParamFlags)G_PARAM_READWRITE));
   336                     -1, G_MAXINT, -1, G_PARAM_READWRITE));
   341 
   337 
   342     g_object_class_install_property(gobject_class, RIGHTBALANCE,
   338     g_object_class_install_property(gobject_class, RIGHTBALANCE,
   343             g_param_spec_int("rightbalance", "Right Balance",
   339             g_param_spec_int("rightbalance", "Right Balance",
   344                     "Right Balance", -1, G_MAXINT, -1, (GParamFlags)G_PARAM_READWRITE));
   340                     "Right Balance", -1, G_MAXINT, -1, G_PARAM_READWRITE));
   345 
   341 
   346     g_object_class_install_property(gobject_class, SAMPLESRECORDED,
   342     g_object_class_install_property(gobject_class, SAMPLESRECORDED,
   347             g_param_spec_int("samplesrecorded", "Samples Recorded",
   343             g_param_spec_int("samplesrecorded", "Samples Recorded",
   348                     "Samples Recorded", -1, G_MAXINT, -1, G_PARAM_READABLE));
   344                     "Samples Recorded", -1, G_MAXINT, -1, G_PARAM_READABLE));
   349 
   345 
   350     g_object_class_install_property(gobject_class, PRIORITY,
   346     g_object_class_install_property(gobject_class, PRIORITY,
   351             g_param_spec_int("priority", "Priority", "Priority ", -1,
   347             g_param_spec_int("priority", "Priority", "Priority ", -1,
   352             G_MAXINT, -1,
   348             G_MAXINT, -1,
   353             (GParamFlags)G_PARAM_READWRITE));
   349             G_PARAM_READWRITE));
   354 
   350 
   355     g_object_class_install_property(gobject_class, PREFERENCE,
   351     g_object_class_install_property(gobject_class, PREFERENCE,
   356             g_param_spec_int("preference", "Preference", "Preference ", -1,
   352             g_param_spec_int("preference", "Preference", "Preference ", -1,
   357             G_MAXINT, -1,
   353             G_MAXINT, -1,
   358             (GParamFlags)G_PARAM_READWRITE));
   354             G_PARAM_READWRITE));
   359 
   355 
   360     g_object_class_install_property(gobject_class, RATE,
   356     g_object_class_install_property(gobject_class, RATE,
   361             g_param_spec_int("rate", "Rate", "Rate ", -1,
   357             g_param_spec_int("rate", "Rate", "Rate ", -1,
   362                     G_MAXINT, -1,
   358                     G_MAXINT, -1,
   363                     (GParamFlags)G_PARAM_READWRITE));
   359                     G_PARAM_READWRITE));
   364 
   360 
   365     g_object_class_install_property(gobject_class, CHANNELS,
   361     g_object_class_install_property(gobject_class, CHANNELS,
   366             g_param_spec_int("channels", "Channels", "Channels ", -1,
   362             g_param_spec_int("channels", "Channels", "Channels ", -1,
   367                     G_MAXINT, -1,
   363                     G_MAXINT, -1,
   368                     (GParamFlags)G_PARAM_READWRITE));
   364                     G_PARAM_READWRITE));
   369     
       
   370     gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_devsound_src_start);
   365     gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_devsound_src_start);
   371     gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_devsound_src_stop);
   366     gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_devsound_src_stop);
   372     gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_getcaps);
   367     gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_getcaps);
   373     gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_setcaps);
   368     gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_setcaps);
   374     gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_devsound_src_event);
   369 
   375     gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_devsound_src_create);
   370     gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_devsound_src_create);
   376     }
   371     }
   377 
   372 
   378 static void gst_devsound_src_init(GstDevsoundSrc * devsoundsrc)
   373 static void gst_devsound_src_init(GstDevsoundSrc * devsoundsrc)
   379     {
   374     {
   380     GST_DEBUG_OBJECT(devsoundsrc, "initializing devsoundsrc");
   375     GST_DEBUG_OBJECT(devsoundsrc, "initializing devsoundsrc");
   381     gst_base_src_set_live(GST_BASE_SRC(devsoundsrc), TRUE);
       
   382     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init ENTER ",NULL);
   376     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init ENTER ",NULL);
   383     devsoundsrc->device = g_strdup(DEFAULT_DEVICE);
   377     devsoundsrc->device = g_strdup(DEFAULT_DEVICE);
   384     devsoundsrc->handle=NULL;
   378     devsoundsrc->handle=NULL;
   385     devsoundsrc->preference = 0; //default=>EMdaPriorityPreferenceNone;
   379     devsoundsrc->preference = 0; //default=>EMdaPriorityPreferenceNone;
   386     devsoundsrc->priority = 0;   //default=>EMdaPriorityNormal;
   380     devsoundsrc->priority = 0;   //default=>EMdaPriorityNormal;
   387     devsoundsrc->firstTimeInit = kUnInitialized;
   381     pthread_mutex_init(&create_mutex1, NULL);
   388 //    pthread_mutex_init(&create_mutex1, NULL);
   382     pthread_cond_init(&create_condition1, NULL);
   389 //    pthread_cond_init(&create_condition1, NULL);
       
   390     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init EXIT ",NULL);
   383     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init EXIT ",NULL);
   391     }
   384     }
   392 
   385 
   393 static void *StartDevSoundThread(void *threadarg)
   386 static void *StartDevSoundThread(void *threadarg)
   394     {
   387     {
   395     GstDevsoundSrc *devsoundsrc= GST_DEVSOUND_SRC (threadarg);
   388     GstDevsoundSrc *devsoundsrc= GST_DEVSOUND_SRC (threadarg);
   396     int buffersize;
   389     int buffersize;
   397     TUint8* gBuffer;
   390     TUint8* gBuffer;
   398     GstBuffer* pushBuffer= NULL;
   391     GstBuffer* pushBuffer= NULL;
   399     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "StartDevSoundThread ",NULL);
   392     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "StartDevSoundThread ",NULL);
   400     int ret = open_devsound(&(devsoundsrc->handle));
   393     open_devsound(&(devsoundsrc->handle));
   401     
       
   402     if( KErrNone != ret )
       
   403         {
       
   404         pthread_mutex_lock(&(create_mutex1));
       
   405         return_error = ret;
       
   406         pthread_cond_signal(&(create_condition1));
       
   407         pthread_mutex_unlock(&(create_mutex1));
       
   408         pthread_exit(NULL);
       
   409         }
       
   410 
   394 
   411     getsupporteddatatypes(devsoundsrc);
   395     getsupporteddatatypes(devsoundsrc);
   412 
   396 
   413 // TODO obtain mutex to update variable here???
   397 // TODO obtain mutex to update variable here???
   414     consumer_thread_state = CONSUMER_THREAD_INITIALIZED;
   398     consumer_thread_state = CONSUMER_THREAD_INITIALIZED;
   416     //pre_init_setconf(devsoundsrc);
   400     //pre_init_setconf(devsoundsrc);
   417 
   401 
   418     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Record Init ",NULL);
   402     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Record Init ",NULL);
   419 
   403 
   420     pthread_mutex_lock(&(create_mutex1));
   404     pthread_mutex_lock(&(create_mutex1));
   421     return_error = ret;
       
   422     pthread_cond_signal(&(create_condition1));
   405     pthread_cond_signal(&(create_condition1));
   423     pthread_mutex_unlock(&(create_mutex1));
   406     pthread_mutex_unlock(&(create_mutex1));
   424 
   407 
   425     // Wait until we receive a command from the main thread
   408     // Wait until we receive a command from the main thread
   426     // TODO obtain mutex to read variable here???
   409     // TODO obtain mutex to read variable here???
   433 
   416 
   434     // This could happen if client creates sink and deletes it
   417     // This could happen if client creates sink and deletes it
   435     // without putting it to play state
   418     // without putting it to play state
   436     if ( cmd != CLOSE )
   419     if ( cmd != CLOSE )
   437         {
   420         {
   438         gst_update_devsound_speech_bitrate(devsoundsrc);
   421         initialize_devsound(devsoundsrc);
   439         ret = initialize_devsound(devsoundsrc);
   422     
   440         if( KErrNone == ret )
   423         recordinit(devsoundsrc->handle);
       
   424         initproperties(devsoundsrc);
       
   425         }
       
   426     //cmd = READDATA;
       
   427     while (1)
       
   428         {
       
   429         //set/get properties
       
   430         //***************************************
       
   431         pre_init_setconf(devsoundsrc);
       
   432         gst_Apply_SpeechEncoder_Update(devsoundsrc);
       
   433         gst_Apply_G711Encoder_Update(devsoundsrc);
       
   434         gst_Apply_G729Encoder_Update(devsoundsrc );
       
   435         gst_Apply_IlbcEncoder_Update(devsoundsrc );
       
   436 
       
   437         populateproperties(devsoundsrc);
       
   438 
       
   439         supportedbitrates = devsoundsrc->supportedbitrates;
       
   440         //numofbitrates = devsoundsrc->numofbitrates;
       
   441         speechbitrate = devsoundsrc->speechbitrate;
       
   442         speechvadmode = devsoundsrc->speechvadmode;
       
   443         g711vadmode = devsoundsrc->g711vadmode;
       
   444         g729vadmode  = devsoundsrc->g729vadmode;
       
   445         ilbcvadmode = devsoundsrc->ilbcvadmode;
       
   446 
       
   447 
       
   448         //****************************************
       
   449         //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Before Buffer Alloc ",NULL);
       
   450         buffersize = get_databuffer_size(devsoundsrc->handle);
       
   451         get_databuffer(devsoundsrc->handle, &gBuffer);
       
   452         pushBuffer = gst_buffer_new_and_alloc(buffersize);
       
   453         //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Buffer Alloc ",NULL);
       
   454         if (GST_BUFFER_DATA(pushBuffer))
   441             {
   455             {
   442                 ret = recordinit(devsoundsrc->handle);
   456             memcpy(GST_BUFFER_DATA(pushBuffer),gBuffer,buffersize);
   443                 if( KErrNone == ret )
       
   444                     initproperties(devsoundsrc);
       
   445         
       
   446             }
   457             }
   447         /// if initialization of devsound failed, return error,
   458         else
   448         /// on return other thread will send CLOSE cmd to exit from thread.
       
   449         if( ret )
       
   450             {
   459             {
   451             pthread_mutex_lock(&(create_mutex1));
   460             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Push buffer alloc failed ",NULL);
   452             return_error = ret;
       
   453             pthread_cond_signal(&(create_condition1));
       
   454             pthread_mutex_unlock(&(create_mutex1));
       
   455             
       
   456             pthread_mutex_lock(&create_mutex1);
       
   457             pthread_cond_wait(&create_condition1, &create_mutex1);
       
   458             pthread_mutex_unlock(&create_mutex1);
       
   459             }
   461             }
   460         }
   462 
   461 
   463         if (dataqueue)
   462     while (TRUE)
   464             {
   463         {
   465             GST_OBJECT_LOCK(devsoundsrc);
       
   466             g_queue_push_head (dataqueue,pushBuffer);
       
   467             GST_OBJECT_UNLOCK(devsoundsrc);
       
   468             //signalmutex_create(devsoundsrc->handle);
       
   469             if(dataqueue->length == 1 && (cmd != CLOSE))
       
   470                 {
       
   471                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Before signal in DevSoundt ",NULL);
       
   472                 pthread_mutex_lock(&(create_mutex1));
       
   473                 pthread_cond_signal(&(create_condition1));
       
   474                 pthread_mutex_unlock(&(create_mutex1));
       
   475                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After signal in DevSoundt ",NULL);
       
   476                 }
       
   477             //cmd = READDATA;
       
   478             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Before DevSnd Wait ",NULL);
       
   479             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After DevSnd Wait ",NULL);
       
   480            }
       
   481         else
       
   482             {
       
   483             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "dataqueue is NULL, CLOSE now ",NULL);
       
   484             cmd = CLOSE;
       
   485             }
       
   486 
   464         switch (cmd)
   487         switch (cmd)
   465             {
   488             {
   466             case PAUSE:
   489             case READDATA:
   467                 pause_devsound(devsoundsrc);
       
   468                 break;
       
   469                 
       
   470             case RESUME:
       
   471                 resume_devsound(devsoundsrc);
       
   472                 break;
       
   473             
       
   474             case STOP:
       
   475                 stop_devsound(devsoundsrc);
       
   476                 break;
       
   477                 
       
   478             case RECORDING:
       
   479                 {
   490                 {
   480                 pre_init_setconf(devsoundsrc);
       
   481 //                gst_Apply_SpeechEncoder_Update(devsoundsrc);
       
   482                 gst_Apply_G711Encoder_Update(devsoundsrc);
       
   483                 gst_Apply_G729Encoder_Update(devsoundsrc );
       
   484                 gst_Apply_IlbcEncoder_Update(devsoundsrc );
       
   485 
       
   486                 populateproperties(devsoundsrc);
       
   487 
       
   488                 supportedbitrates = devsoundsrc->supportedbitrates;
       
   489                 //numofbitrates = devsoundsrc->numofbitrates;
       
   490                 speechbitrate = devsoundsrc->speechbitrate;
       
   491                 speechvadmode = devsoundsrc->speechvadmode;
       
   492                 g711vadmode = devsoundsrc->g711vadmode;
       
   493                 g729vadmode  = devsoundsrc->g729vadmode;
       
   494                 ilbcvadmode = devsoundsrc->ilbcvadmode;
       
   495 
       
   496                 buffersize = get_databuffer_size(devsoundsrc->handle);
       
   497                 get_databuffer(devsoundsrc->handle, &gBuffer);
       
   498                 pushBuffer = gst_buffer_new_and_alloc(buffersize);
       
   499                 memcpy(GST_BUFFER_DATA(pushBuffer),gBuffer,buffersize);
       
   500                 
       
   501                 GST_OBJECT_LOCK(devsoundsrc);
       
   502                 g_queue_push_head (dataqueue,pushBuffer);
       
   503                 GST_OBJECT_UNLOCK(devsoundsrc);
       
   504                 
       
   505                 record_data(devsoundsrc->handle);
   491                 record_data(devsoundsrc->handle);
   506                 }
   492                 }
   507                 break;
   493                 break;
   508             case CLOSE:
   494             case CLOSE:
   509                 {
   495                 {
   514                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After handle NULL ",NULL);
   500                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After handle NULL ",NULL);
   515 
   501 
   516                 pthread_mutex_lock(&(create_mutex1));
   502                 pthread_mutex_lock(&(create_mutex1));
   517                 pthread_cond_signal(&(create_condition1));
   503                 pthread_cond_signal(&(create_condition1));
   518                 pthread_mutex_unlock(&(create_mutex1));
   504                 pthread_mutex_unlock(&(create_mutex1));
   519                 // TODO obtain mutex here
   505 				// TODO obtain mutex here
   520                 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;
   506                 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;
   521                 pthread_exit(NULL);
   507                 pthread_exit(NULL);
   522                 }
   508                 }
   523                 break;
   509                 break;
   524             default:
   510             default:
   525                 // TODO obtain mutex here
   511                 // TODO obtain mutex here
   526                 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;          
   512                 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;			
   527                 pthread_exit(NULL);
   513                 pthread_exit(NULL);
   528                 break;
   514                 break;
   529             }
   515             }
   530         pthread_mutex_lock(&(create_mutex1));
   516         }
   531         return_error = call_back_error(devsoundsrc->handle);
   517     // TODO obtain mutex here
   532         pthread_cond_signal(&(create_condition1));
   518     consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;
   533         pthread_mutex_unlock(&(create_mutex1));
   519     pthread_exit(NULL);
   534         
       
   535         pthread_mutex_lock(&create_mutex1);
       
   536         pthread_cond_wait(&create_condition1, &create_mutex1);
       
   537         pthread_mutex_unlock(&create_mutex1);
       
   538         }
       
   539     }
   520     }
   540 
   521 
   541 static void gst_devsound_src_set_property(GObject * object, guint prop_id,
   522 static void gst_devsound_src_set_property(GObject * object, guint prop_id,
   542         const GValue * value, GParamSpec * pspec)
   523         const GValue * value, GParamSpec * pspec)
   543     {
   524     {
   704     }
   685     }
   705 
   686 
   706 static gboolean gst_devsound_src_start(GstBaseSrc * bsrc)
   687 static gboolean gst_devsound_src_start(GstBaseSrc * bsrc)
   707     {
   688     {
   708     GstBuffer *tmp_gstbuffer=NULL;	
   689     GstBuffer *tmp_gstbuffer=NULL;	
   709     gboolean ret = TRUE;
       
   710     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
   690     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
   711     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start ENTER ",NULL);
   691     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start ENTER ",NULL);
   712     pthread_mutex_init(&create_mutex1, NULL);
   692 
   713     pthread_cond_init(&create_condition1, NULL);
       
   714     
       
   715     if(dataqueue)
   693     if(dataqueue)
   716         {
   694         {
   717         while (g_queue_get_length(dataqueue))
   695         while (dataqueue->length)
   718             {
   696             {
   719             tmp_gstbuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
   697             tmp_gstbuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
   720             gst_buffer_unref(tmp_gstbuffer);
   698             gst_buffer_unref(tmp_gstbuffer);
   721             }
   699             }
   722         g_queue_free(dataqueue);
   700         g_queue_free(dataqueue);
   728           dataqueue = g_queue_new();
   706           dataqueue = g_queue_new();
   729           }
   707           }
   730 
   708 
   731     consumer_thread_state = CONSUMER_THREAD_INITIALIZING;
   709     consumer_thread_state = CONSUMER_THREAD_INITIALIZING;
   732     cmd = OPEN;
   710     cmd = OPEN;
   733     return_error = KErrNone;
       
   734     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Thread Create ",NULL);
   711     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Thread Create ",NULL);
   735     pthread_create(&ds_thread, NULL, StartDevSoundThread, (void *)src);
   712     pthread_create(&ds_thread, NULL, StartDevSoundThread, (void *)src);
   736     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "After Thread Create ",NULL);
   713     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "After Thread Create ",NULL);
   737     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Mutex Wait in START ",NULL);
   714     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Mutex Wait in START ",NULL);
   738     if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING)
   715     if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING)
   739         {
   716         {
   740         pthread_mutex_lock(&create_mutex1);
   717         pthread_mutex_lock(&create_mutex1);
   741         pthread_cond_wait(&create_condition1, &create_mutex1);
   718         pthread_cond_wait(&create_condition1, &create_mutex1);
   742         ret = !return_error; // should be TRUE on no Error, and FALSE at ERROR.
       
   743         pthread_mutex_unlock(&create_mutex1);
   719         pthread_mutex_unlock(&create_mutex1);
   744         }
   720         }
   745     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "AFter Mutex Wait in START ",NULL);
   721     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "AFter Mutex Wait in START ",NULL);
   746     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start EXIT ",NULL);
   722     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start EXIT ",NULL);
   747     if ( return_error )
   723     return TRUE;
   748         post_symbian_error( bsrc,return_error );
       
   749     return ret;
       
   750     /* ERRORS */
   724     /* ERRORS */
   751     }
   725     }
   752 
   726 
   753 static gboolean gst_devsound_src_stop(GstBaseSrc * bsrc)
   727 static gboolean gst_devsound_src_stop(GstBaseSrc * bsrc)
   754     {
   728     {
   755 	
   729 	
   756     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
   730     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
   757     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_stop ENTER ");
   731     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_stop ENTER ");
   758     cmd = CLOSE;
   732     cmd = CLOSE;
   759     pthread_mutex_lock(&(create_mutex1));
   733 
   760     pthread_cond_signal(&(create_condition1));
       
   761     pthread_mutex_unlock(&(create_mutex1));
       
   762     //GST_OBJECT_LOCK (src);
   734     //GST_OBJECT_LOCK (src);
   763     pthread_mutex_lock(&(create_mutex1));
   735     pthread_mutex_lock(&(create_mutex1));
   764     pthread_cond_wait(&(create_condition1), &(create_mutex1));
   736     pthread_cond_wait(&(create_condition1), &(create_mutex1));
   765     pthread_mutex_unlock(&(create_mutex1));
   737     pthread_mutex_unlock(&(create_mutex1));
   766     //GST_OBJECT_UNLOCK (src);
   738     //GST_OBJECT_UNLOCK (src);
   772         dataleft = 0;   //Arun'S changes
   744         dataleft = 0;   //Arun'S changes
   773         }
   745         }
   774     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before QUEUE Lock in STOP ");
   746     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before QUEUE Lock in STOP ");
   775     GST_OBJECT_LOCK(src);
   747     GST_OBJECT_LOCK(src);
   776     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "After QUEUE Lock in STOP ");
   748     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "After QUEUE Lock in STOP ");
   777     while (g_queue_get_length(dataqueue))
   749     while (dataqueue->length)
   778         {
   750         {
   779         //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Removing DATAQUEUE elements ENTER ");
   751         //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Removing DATAQUEUE elements ENTER ");
   780         popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
   752         popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
   781         gst_buffer_unref(popBuffer);
   753         gst_buffer_unref(popBuffer);
   782         popBuffer = NULL;
   754         popBuffer = NULL;
   790     GST_OBJECT_UNLOCK(src);
   762     GST_OBJECT_UNLOCK(src);
   791 
   763 
   792     pthread_mutex_destroy(&create_mutex1);
   764     pthread_mutex_destroy(&create_mutex1);
   793     pthread_cond_destroy(&(create_condition1));
   765     pthread_cond_destroy(&(create_condition1));
   794 
   766 
       
   767 
   795     g_free(src->device);
   768     g_free(src->device);
   796     src->device = NULL;
       
   797     src->firstTimeInit = kUnInitialized;
       
   798     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_stop EXIT ");
   769     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_stop EXIT ");
   799     return TRUE;
   770     return TRUE;
   800     }
   771     }
   801 
   772 
   802 static gboolean gst_devsound_src_unlock(GstBaseSrc * bsrc)
   773 static gboolean gst_devsound_src_unlock(GstBaseSrc * bsrc)
   821 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset,
   792 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset,
   822         guint size, GstBuffer **buf)
   793         guint size, GstBuffer **buf)
   823     {
   794     {
   824     GstDevsoundSrc *dsrc= GST_DEVSOUND_SRC(src);
   795     GstDevsoundSrc *dsrc= GST_DEVSOUND_SRC(src);
   825     int bufferpos=0;
   796     int bufferpos=0;
   826     int ret = KErrNone;
       
   827     
       
   828     if(!g_queue_get_length(dataqueue) && (dsrc->eosreceived == TRUE))
       
   829         {
       
   830         pthread_mutex_lock(&(create_mutex1));
       
   831         pthread_cond_signal(&(create_condition1));
       
   832         pthread_mutex_unlock(&(create_mutex1));
       
   833         post_symbian_error( src,KErrCancel );
       
   834         return GST_FLOW_UNEXPECTED;
       
   835         }
       
   836     
       
   837     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create ENTER ");
   797     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create ENTER ");
   838 
   798 
   839     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before Buffer Alloc in CREATE ",NULL);
   799     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before Buffer Alloc in CREATE ",NULL);
   840     *buf = gst_buffer_try_new_and_alloc(size);
   800     *buf = gst_buffer_try_new_and_alloc(size);
   841     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFter Buffer Alloc in CREATE ",NULL);
   801     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFter Buffer Alloc in CREATE ",NULL);
   842     if(*buf == NULL)
   802 
   843     {
       
   844         post_symbian_error( src,KErrNoMemory );
       
   845         return GST_FLOW_UNEXPECTED;
       
   846     }        
       
   847     
       
   848     while (size > 0)
   803     while (size > 0)
   849         {
   804         {
   850         if (dataleft >= size)
   805         if (dataleft >= size)
   851             {
   806             {
   852             // if there is some data left in the popped buffer previously whose size
   807             // if there is some data left in the popped buffer previously whose size
   882                 popBuffer = NULL;
   837                 popBuffer = NULL;
   883                 }
   838                 }
   884 
   839 
   885             // we wait here if the dataqueue length is 0 and we need data
   840             // we wait here if the dataqueue length is 0 and we need data
   886             // to be filled in the queue from the DevSound Thread
   841             // to be filled in the queue from the DevSound Thread
   887             if (!g_queue_get_length(dataqueue))
   842             if (!dataqueue->length)
   888                 {
   843                 {
   889                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before WAIT in CREATE ",NULL);
   844                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before WAIT in CREATE ",NULL);
   890                 if(dsrc->eosreceived == TRUE)
   845                 cmd = READDATA;
   891                     {
   846                 pthread_mutex_lock(&(create_mutex1));
   892                     post_symbian_error( src,KErrCancel );
   847                 pthread_cond_signal(&(create_condition1));
   893                     return GST_FLOW_UNEXPECTED;
   848                 pthread_mutex_unlock(&(create_mutex1));
   894                     }
   849                 
   895                 else
   850                 pthread_mutex_lock(&(create_mutex1));
   896                     {
   851                 pthread_cond_wait(&(create_condition1), &(create_mutex1));
   897                     cmd = RECORDING;
   852                 pthread_mutex_unlock(&(create_mutex1));
   898                     return_error = KErrNone;
       
   899                     pthread_mutex_lock(&(create_mutex1));
       
   900                     pthread_cond_signal(&(create_condition1));
       
   901                     pthread_mutex_unlock(&(create_mutex1));
       
   902                     
       
   903                     pthread_mutex_lock(&(create_mutex1));
       
   904                     pthread_cond_wait(&(create_condition1), &(create_mutex1));
       
   905                     ret = return_error;
       
   906                     pthread_mutex_unlock(&(create_mutex1));
       
   907                     }
       
   908                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER WAIT in CREATE ",NULL);
   853                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER WAIT in CREATE ",NULL);
   909                 }
   854                 }
   910             if( ret )
   855 
   911             { 
       
   912                 post_symbian_error( src,ret );
       
   913                 return GST_FLOW_UNEXPECTED;
       
   914             }
       
   915             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before POP in CREATE ",NULL);
   856             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before POP in CREATE ",NULL);
   916             GST_OBJECT_LOCK(dsrc);
   857             GST_OBJECT_LOCK(dsrc);
   917             popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
   858             popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
   918             GST_OBJECT_UNLOCK(dsrc);
   859             GST_OBJECT_UNLOCK(dsrc);
   919            
   860             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER POP in CREATE ",NULL);
   920             if(!popBuffer )
   861 
   921             {
       
   922                 post_symbian_error( src,KErrNoMemory );
       
   923                 return GST_FLOW_UNEXPECTED;
       
   924             }
       
   925             if(dsrc->firstTimeInit != kPlayed)
       
   926                 {        
       
   927                 dsrc->prevbuffersize = gst_base_src_get_blocksize(src);
       
   928                 gst_base_src_set_blocksize (src, GST_BUFFER_SIZE(popBuffer));
       
   929                 (*buf)->size = GST_BUFFER_SIZE(popBuffer);
       
   930                 }
       
   931             // copy the data from the popped buffer based on how much of the incoming
   862             // copy the data from the popped buffer based on how much of the incoming
   932             //buffer size is left to fill. we might have filled the fresh buffer somewhat
   863             //buffer size is left to fill. we might have filled the fresh buffer somewhat
   933             // where the size of the fresh buffer is more then the data remaining in the
   864             // where the size of the fresh buffer is more then the data remaining in the
   934             // popped buffer.
   865             // popped buffer.
   935             if (size < GST_BUFFER_SIZE(popBuffer))
   866             if (size < GST_BUFFER_SIZE(popBuffer))
   955                 {
   886                 {
   956                 gst_buffer_unref(popBuffer);
   887                 gst_buffer_unref(popBuffer);
   957                 popBuffer = NULL;
   888                 popBuffer = NULL;
   958                 }
   889                 }
   959             }
   890             }
   960         if (dsrc->firstTimeInit == kPlayBufferPreRoll)
   891         }
   961             {
       
   962             gst_base_src_set_blocksize (src, dsrc->prevbuffersize);
       
   963             dsrc->firstTimeInit = kPlayed;
       
   964             return GST_FLOW_OK;
       
   965             }
       
   966         
       
   967         if (dsrc->firstTimeInit == kPausedToPlaying)
       
   968             {
       
   969             dsrc->firstTimeInit = kPlayBufferPreRoll;
       
   970             return GST_FLOW_OK;
       
   971             }
       
   972        }
       
   973     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create EXIT ",NULL);
   892     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create EXIT ",NULL);
   974     return GST_FLOW_OK;
   893     return GST_FLOW_OK;
   975     }
   894     }
   976 
       
   977 
       
   978 static GstStateChangeReturn gst_devsound_src_change_state (GstElement * element,
       
   979     GstStateChange transition)
       
   980     {
       
   981     GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
       
   982     GstDevsoundSrc *src= GST_DEVSOUND_SRC (element);
       
   983  
       
   984     switch (transition) {
       
   985         
       
   986         case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
       
   987             if (src->firstTimeInit != kPlayed)
       
   988             src->firstTimeInit = kPausedToPlaying;
       
   989             if(cmd == PAUSE)
       
   990                 {
       
   991                 cmd = RESUME;
       
   992                 return_error = KErrNone;
       
   993                 pthread_mutex_lock(&create_mutex1);
       
   994                 pthread_cond_signal(&create_condition1);
       
   995                 pthread_mutex_unlock(&create_mutex1);
       
   996                 
       
   997                 pthread_mutex_lock(&create_mutex1);
       
   998                 pthread_cond_wait(&create_condition1, &create_mutex1);
       
   999                 if( return_error )
       
  1000                     {
       
  1001                     post_symbian_error( GST_BASE_SRC(element),return_error );
       
  1002                     ret = GST_STATE_CHANGE_FAILURE;
       
  1003                     }
       
  1004                 pthread_mutex_unlock(&create_mutex1);
       
  1005                 }
       
  1006             break;
       
  1007         default:
       
  1008             break;
       
  1009         }
       
  1010 
       
  1011     ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
       
  1012       if (G_UNLIKELY (ret == GST_STATE_CHANGE_FAILURE))
       
  1013         goto activate_failed;
       
  1014 
       
  1015       switch (transition) {
       
  1016           
       
  1017           case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
       
  1018               cmd = PAUSE;
       
  1019               return_error = KErrNone;
       
  1020               pthread_mutex_lock(&create_mutex1);
       
  1021               pthread_cond_signal(&create_condition1);
       
  1022               pthread_mutex_unlock(&create_mutex1);
       
  1023               
       
  1024               pthread_mutex_lock(&create_mutex1);
       
  1025               pthread_cond_wait(&create_condition1, &create_mutex1);
       
  1026               if( return_error )
       
  1027                   {
       
  1028                   post_symbian_error( GST_BASE_SRC(element),return_error );
       
  1029                   ret = GST_STATE_CHANGE_FAILURE;
       
  1030                   }            
       
  1031               pthread_mutex_unlock(&create_mutex1);
       
  1032               break;
       
  1033           default:
       
  1034               break;
       
  1035           }
       
  1036       
       
  1037       return ret;
       
  1038     
       
  1039     activate_failed:
       
  1040       {
       
  1041         GST_DEBUG_OBJECT (src,
       
  1042             "element failed to change states -- activation problem?");
       
  1043         return GST_STATE_CHANGE_FAILURE;
       
  1044       }    
       
  1045     }
       
  1046 
       
  1047 
   895 
  1048 static gboolean gst_devsound_src_is_seekable(GstBaseSrc * bsrc)
   896 static gboolean gst_devsound_src_is_seekable(GstBaseSrc * bsrc)
  1049     {
   897     {
  1050     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
   898     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
  1051     return FALSE;
   899     return FALSE;
  1099     speechvadmode = aVadMode;
   947     speechvadmode = aVadMode;
  1100     customInfaceUpdate.speechvadmodeupdate = TRUE;
   948     customInfaceUpdate.speechvadmodeupdate = TRUE;
  1101     return 0;
   949     return 0;
  1102     }
   950     }
  1103 
   951 
  1104 static void gst_update_devsound_speech_bitrate(GstDevsoundSrc *devsoundsrc )
   952 
  1105     {
       
  1106     if(customInfaceUpdate.speechbitrateupdate == TRUE)
       
  1107         {
       
  1108         update_devsound_speech_bitrate(devsoundsrc->handle,speechbitrate);
       
  1109         customInfaceUpdate.speechbitrateupdate = FALSE;
       
  1110         }
       
  1111     }
       
  1112 static void gst_Apply_SpeechEncoder_Update(GstDevsoundSrc *devsoundsrc )
   953 static void gst_Apply_SpeechEncoder_Update(GstDevsoundSrc *devsoundsrc )
  1113     {
   954     {
  1114     if(customInfaceUpdate.speechbitrateupdate == TRUE)
   955     if(customInfaceUpdate.speechbitrateupdate == TRUE)
  1115         {
   956         {
  1116         set_speech_encoder_bit_rate(devsoundsrc->handle,speechbitrate);
   957         set_speech_encoder_bit_rate(devsoundsrc->handle,speechbitrate);
  1294         }
  1135         }
  1295     return result;
  1136     return result;
  1296 
  1137 
  1297     }
  1138     }
  1298 
  1139 
  1299 static gboolean gst_devsound_src_event(GstBaseSrc *asrc, GstEvent *event)
       
  1300     {
       
  1301     int retValue = FALSE;
       
  1302     GstDevsoundSrc *src = GST_DEVSOUND_SRC(asrc);
       
  1303     switch (GST_EVENT_TYPE (event))
       
  1304         {
       
  1305         case GST_EVENT_EOS:
       
  1306             // end-of-stream, we should close down all stream leftovers here
       
  1307             //reset_devsound(sink->handle);
       
  1308             src->eosreceived = TRUE;
       
  1309             cmd = STOP;
       
  1310             return_error = KErrNone;
       
  1311             pthread_mutex_lock(&create_mutex1);
       
  1312             pthread_cond_signal(&create_condition1);
       
  1313             pthread_mutex_unlock(&create_mutex1);
       
  1314             
       
  1315             pthread_mutex_lock(&create_mutex1);
       
  1316             pthread_cond_wait(&create_condition1, &create_mutex1);
       
  1317             pthread_mutex_unlock(&create_mutex1);
       
  1318             
       
  1319             if(g_queue_get_length(dataqueue))
       
  1320                 {
       
  1321                 pthread_mutex_lock(&create_mutex1);
       
  1322                 pthread_cond_wait(&create_condition1, &create_mutex1);
       
  1323                 pthread_mutex_unlock(&create_mutex1);
       
  1324                 }
       
  1325             
       
  1326             gst_pad_push_event (asrc->srcpad, gst_event_new_eos ());
       
  1327             retValue = TRUE;
       
  1328             break;
       
  1329         default:
       
  1330             retValue = FALSE;
       
  1331             break;
       
  1332         }
       
  1333     
       
  1334     return retValue;
       
  1335     }
       
  1336 
       
  1337 static void 
       
  1338 post_symbian_error ( GstBaseSrc* element, int symbian_error )
       
  1339 {
       
  1340     switch (symbian_error)
       
  1341     {
       
  1342 
       
  1343         case KErrNone:
       
  1344             break;
       
  1345         case KErrNotFound:
       
  1346             GST_ELEMENT_ERROR (element, RESOURCE, NOT_FOUND,
       
  1347                 (("resource not found error.")),
       
  1348                 ("streaming paused because resource not found, Err(%d)", symbian_error));               
       
  1349             break;
       
  1350         case KErrCancel:
       
  1351             GST_ELEMENT_ERROR (element, RESOURCE, CLOSE,
       
  1352                 (("resource request canceled.")),
       
  1353                 ("streaming paused because resource request canceled, Err(%d)", symbian_error));               
       
  1354             break;
       
  1355         case KErrNoMemory:
       
  1356             GST_ELEMENT_ERROR (element, RESOURCE, NO_SPACE_LEFT,
       
  1357                 (("Error out of memory")),
       
  1358                 ("streaming paused because of no memory, Err(%d)", symbian_error));               
       
  1359             break;
       
  1360         case KErrNotSupported:
       
  1361             GST_ELEMENT_ERROR (element, RESOURCE, READ,
       
  1362                 (("resource not supported.")),
       
  1363                 ("streaming paused because resource not supported, Err(%d)", symbian_error));               
       
  1364             break;
       
  1365         case KErrNotReady:
       
  1366             GST_ELEMENT_ERROR (element, RESOURCE, TOO_LAZY,
       
  1367                 (("resource is not ready for request.")),
       
  1368                 ("streaming paused because resource is not ready, Err(%d)", symbian_error));               
       
  1369             break;
       
  1370         case KErrPermissionDenied:
       
  1371             GST_ELEMENT_ERROR (element, RESOURCE, READ,
       
  1372                 (("Permission Denied.")),
       
  1373                 ("streaming paused because permission denied, Err(%d)", symbian_error));               
       
  1374             break;
       
  1375         case KErrTimedOut:
       
  1376             GST_ELEMENT_ERROR (element, RESOURCE, TOO_LAZY,
       
  1377                 (("Timed Out.")),
       
  1378                 ("streaming paused because timed out, Err(%d)", symbian_error));               
       
  1379             break;
       
  1380         case KErrHardwareNotAvailable:
       
  1381             GST_ELEMENT_ERROR (element, RESOURCE, NOT_FOUND,
       
  1382                 (("Hardware Not Available.")),
       
  1383                 ("streaming paused because hardware not available, Err(%d)", symbian_error));               
       
  1384             break;
       
  1385         case KErrCorrupt:
       
  1386             GST_ELEMENT_ERROR (element, RESOURCE, FAILED,
       
  1387                 (("Corrupted data.")),
       
  1388                 ("streaming paused because of corrupted data, Err(%d)", symbian_error));               
       
  1389             break;
       
  1390         case KErrUnderflow:
       
  1391             GST_ELEMENT_ERROR (element, STREAM, FAILED,
       
  1392                 (("Under flow.")),
       
  1393                 ("streaming paused because of under flow, Err(%d)", symbian_error));               
       
  1394             break;
       
  1395         case KErrOverflow:
       
  1396             GST_ELEMENT_ERROR (element, STREAM, FAILED,
       
  1397                 (("Over flow.")),
       
  1398                 ("streaming paused because of over flow, Err(%d)", symbian_error));    
       
  1399             break;
       
  1400 
       
  1401         case KErrInUse:
       
  1402             GST_ELEMENT_ERROR (element, RESOURCE, BUSY,
       
  1403                 (("Resource In Use.")),
       
  1404                 ("streaming paused because resource in use, Err(%d)", symbian_error));            
       
  1405             break;
       
  1406             
       
  1407         case KErrDied:
       
  1408             GST_ELEMENT_ERROR (element, RESOURCE, BUSY,
       
  1409                 (("Error Resource Died.")),
       
  1410                 ("streaming paused because resource died., Err(%d)", symbian_error));            
       
  1411             break;
       
  1412             
       
  1413         case KErrAccessDenied:            
       
  1414             GST_ELEMENT_ERROR (element, RESOURCE, BUSY,
       
  1415                 (("Resource Access Denied.")),
       
  1416                 ("streaming paused because resource access denied, Err(%d)", symbian_error));            
       
  1417             break;
       
  1418             
       
  1419         default:
       
  1420             GST_ELEMENT_ERROR (element, STREAM, FAILED,
       
  1421                 (("internal data flow error.")),
       
  1422                 ("streaming paused because of internal data flow error., Err(%d)", symbian_error));            
       
  1423             break;
       
  1424     }
       
  1425 }
       
  1426