gst_plugins_symbian/gst/devsound/gstdevsoundsrc.c
changeset 2 5505e8908944
parent 0 0e761a78d257
child 7 567bb019e3e3
equal deleted inserted replaced
1:4c282e7dd6d3 2:5505e8908944
       
     1 /* GStreamer
       
     2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
       
     3  *               2000,2005 Wim Taymans <wim@fluendo.com>
       
     4  *
       
     5  * gstdevsoundsrc.c:
       
     6  *
       
     7  * This library is free software; you can redistribute it and/or
       
     8  * modify it under the terms of the GNU Library General Public
       
     9  * License as published by the Free Software Foundation; either
       
    10  * version 2 of the License, or (at your option) any later version.
       
    11  *
       
    12  * This library is distributed in the hope that it will be useful,
       
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    15  * Library General Public License for more details.
       
    16  *
       
    17  * You should have received a copy of the GNU Library General Public
       
    18  * License along with this library; if not, write to the
       
    19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    20  * Boston, MA 02111-1307, USA.
       
    21  */
       
    22 
       
    23 #ifdef HAVE_CONFIG_H
       
    24 #include "config.h"
       
    25 #endif
       
    26 
       
    27 #include <gqueue.h>
       
    28 #include "common.h"
       
    29 #include "gstdevsoundsrc.h"
       
    30 
       
    31 #include <glib_global.h>
       
    32 #include "gstg711encoderinterface.h"
       
    33 #include "gstspeechencoderconfig.h"
       
    34 #include "gstg729encoderinterface.h"
       
    35 #include "gstilbcencoderinterface.h"
       
    36 #include "string.h"
       
    37 
       
    38 GST_DEBUG_CATEGORY_EXTERN (devsoundsrc_debug);
       
    39 #define GST_CAT_DEFAULT devsoundsrc_debug
       
    40 
       
    41 /* elementfactory information */
       
    42 static const GstElementDetails gst_devsound_src_details=
       
    43 GST_ELEMENT_DETAILS ("Audio Src (DEVSOUND)",
       
    44         "Src/Audio",
       
    45         "Record via Devsound",
       
    46         " "
       
    47 );
       
    48 
       
    49 static void gst_devsound_src_base_init(gpointer g_class);
       
    50 static void gst_devsound_src_class_init(GstDevsoundSrcClass * klass);
       
    51 static void gst_devsound_src_init(GstDevsoundSrc * devsoundsrc);
       
    52 
       
    53 static void gst_devsound_src_dispose(GObject * object);
       
    54 
       
    55 static void gst_devsound_src_get_property(GObject * object, guint prop_id,
       
    56         GValue * value, GParamSpec * pspec);
       
    57 static void gst_devsound_src_set_property(GObject * object, guint prop_id,
       
    58         const GValue * value, GParamSpec * pspec);
       
    59 
       
    60 static GstCaps *gst_devsound_src_getcaps(GstBaseSrc * bsrc);
       
    61 static gboolean gst_devsound_src_setcaps(GstBaseSrc *bsrc, GstCaps *caps);
       
    62 
       
    63 static gboolean gst_devsound_src_start(GstBaseSrc * bsrc);
       
    64 static gboolean gst_devsound_src_stop(GstBaseSrc * bsrc);
       
    65 static gboolean gst_devsound_src_unlock(GstBaseSrc * bsrc);
       
    66 static gboolean gst_devsound_src_unlock_stop(GstBaseSrc * bsrc);
       
    67 static gboolean gst_devsound_src_is_seekable(GstBaseSrc * bsrc);
       
    68 static gboolean gst_devsound_src_get_size(GstBaseSrc * src, guint64 * size);
       
    69 
       
    70 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset,
       
    71         guint size, GstBuffer **buf);
       
    72 static void *StartDevSoundThread(void *threadid);
       
    73 
       
    74 /*********************************
       
    75  * Speech Encoder Config Interface
       
    76  * ******************************/
       
    77 static void gst_speech_encoder_config_handler_init(gpointer g_iface,
       
    78         gpointer iface_data);
       
    79 static gint gst_get_speech_encoder_bit_rate(guint* aBitrate);
       
    80 static gint gst_get_speech_encoder_supported_bit_rates(
       
    81         GList** aSupportedBitrates);
       
    82 static gint gst_get_speech_encoder_vad_mode(gboolean* aVadMode);
       
    83 static gint gst_set_speech_encoder_bit_rate(guint aBitrate);
       
    84 static gint gst_set_speech_encoder_vad_mode(gboolean aVadMode);
       
    85 static void gst_Apply_SpeechEncoder_Update(GstDevsoundSrc *devsoundsrc );
       
    86 
       
    87 
       
    88 /*************************
       
    89  * G711 Encoder Interface
       
    90  * ***********************/
       
    91 static void gst_g711_encoder_handler_init(gpointer g_iface,
       
    92         gpointer iface_data);
       
    93 static gint gst_get_g711_encoder_vad_mode(gboolean* aVadMode);
       
    94 static gint gst_set_g711_encoder_mode(enum TG711EncodeMode aEncodeMode);
       
    95 static gint gst_set_g711_vad_mode(gboolean aVadMode);
       
    96 static void gst_Apply_G711Encoder_Update(GstDevsoundSrc *devsoundsrc );
       
    97 
       
    98 
       
    99 /*************************
       
   100  * 729 Encoder Interface
       
   101  * ***********************/
       
   102 static void gst_g729_encoder_handler_init(gpointer g_iface,
       
   103         gpointer iface_data);
       
   104 static gint gst_set_g729_vad_mode(TBool aVadMode);
       
   105 static gint gst_get_g729_vad_mode(TBool* aVadMode);
       
   106 static void gst_Apply_G729Encoder_Update(GstDevsoundSrc *devsoundsrc );
       
   107 
       
   108 
       
   109 /*************************
       
   110  * ilbc Encoder Interface
       
   111  * ***********************/
       
   112 static void gst_ilbc_encoder_handler_init(gpointer g_iface,
       
   113         gpointer iface_data);
       
   114 static gint gst_set_ilbc_encoder_mode(enum TIlbcEncodeMode aEncodeMode);
       
   115 static gint gst_set_ilbc_vad_mode(gboolean aVadMode);
       
   116 static gint gst_get_ilbc_vad_mode(gboolean* aVadMode);
       
   117 static void gst_Apply_IlbcEncoder_Update(GstDevsoundSrc *devsoundsrc );
       
   118 
       
   119 
       
   120 static gint gst_devsound_src_get_rate(gint rate);
       
   121 
       
   122 
       
   123 typedef struct _GstCustomIfaceUpdate GstCustomIfaceUpdate;
       
   124 
       
   125 struct _GstCustomIfaceUpdate{
       
   126 gboolean  speechbitrateupdate;
       
   127 gboolean  speechvadmodeupdate;
       
   128 gboolean  g711encodermodeupdate;
       
   129 gboolean  g711vadmodeupdate;
       
   130 gboolean  g729vadmodeupdate;
       
   131 gboolean  ilbcencodermodeupdate;
       
   132 gboolean  ilbcvadmodeupdate;
       
   133 };
       
   134 GstCustomIfaceUpdate customInfaceUpdate = {0,0,0,0,0,0,0};
       
   135 
       
   136 guint speechbitrate;
       
   137 gboolean speechvadmode;
       
   138 enum TG711EncodeMode g711encodemode;
       
   139 gboolean g711vadmode;
       
   140 GList* supportedbitrates;
       
   141 gint numofbitrates;
       
   142 gboolean g729vadmode;
       
   143 enum TIlbcEncodeMode ilbcencodemode;
       
   144 gboolean ilbcvadmode;
       
   145 
       
   146 pthread_t ds_thread;
       
   147 pthread_mutex_t create_mutex1;
       
   148 pthread_cond_t create_condition1;
       
   149 
       
   150 enum consumer_thread_state_enum {
       
   151    CONSUMER_THREAD_UNINITIALIZED,
       
   152    CONSUMER_THREAD_INITIALIZING,
       
   153    CONSUMER_THREAD_INITIALIZED
       
   154 };
       
   155 enum consumer_thread_state_enum consumer_thread_state;
       
   156 
       
   157 
       
   158 
       
   159 GQueue* dataqueue= NULL;
       
   160 GstBuffer* popBuffer= NULL;
       
   161 int dataleft = 0;
       
   162 int dataCopied = 0;
       
   163 
       
   164 enum command_to_consumer_thread_enum
       
   165     {
       
   166     OPEN = 2,
       
   167     READDATA,
       
   168     /*UPDATE,*/
       
   169     CLOSE
       
   170     };
       
   171 enum command_to_consumer_thread_enum cmd;
       
   172 
       
   173 enum
       
   174     {
       
   175     LAST_SIGNAL
       
   176     };
       
   177 
       
   178 #define DEFAULT_DEVICE  "default"
       
   179 
       
   180 enum
       
   181     {
       
   182     PROP_0,
       
   183     PROP_DEVICE,
       
   184     GAIN,
       
   185     MAXGAIN,
       
   186     CHANNELS,
       
   187     LEFTBALANCE,
       
   188     RIGHTBALANCE,
       
   189     RATE,
       
   190     PRIORITY,
       
   191     PREFERENCE,
       
   192     SAMPLESRECORDED
       
   193     };
       
   194 
       
   195 static GstStaticPadTemplate devsound_src_factory=
       
   196     GST_STATIC_PAD_TEMPLATE ("src",
       
   197         GST_PAD_SRC,
       
   198         GST_PAD_ALWAYS,
       
   199         GST_STATIC_CAPS ("audio/x-raw-int, "
       
   200                 "endianness = (int) { " G_STRINGIFY (G_BYTE_ORDER) " }, "
       
   201                 "signed = (boolean) TRUE, "
       
   202                 "width = (int) 16, "
       
   203                 "depth = (int) 16, "
       
   204                 "rate = (int) [ 8000, 48000 ],"
       
   205                 "channels = (int) [ 1, 2 ]; "
       
   206                 "audio/amr, "
       
   207                 "rate = (int) [ 8000, 48000 ], "
       
   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 ]")
       
   221                 );
       
   222 
       
   223 static GstElementClass *parent_class= NULL;
       
   224 
       
   225 static void gst_devsound_src_base_init(gpointer g_class)
       
   226     {
       
   227     GstElementClass *element_class= GST_ELEMENT_CLASS (g_class);
       
   228 
       
   229     gst_element_class_set_details(element_class, &gst_devsound_src_details);
       
   230 
       
   231     gst_element_class_add_pad_template(element_class,
       
   232             gst_static_pad_template_get(&devsound_src_factory));
       
   233     }
       
   234 
       
   235 GType gst_devsound_src_get_type(void)
       
   236     {
       
   237     static GType devsoundsrc_type = 0;
       
   238 
       
   239     if (!devsoundsrc_type)
       
   240         {
       
   241         static const GTypeInfo devsoundsrc_info =
       
   242             {
       
   243             sizeof(GstDevsoundSrcClass), gst_devsound_src_base_init, NULL,
       
   244                     (GClassInitFunc) gst_devsound_src_class_init, NULL, NULL,
       
   245                     sizeof(GstDevsoundSrc), 0,
       
   246                     (GInstanceInitFunc) gst_devsound_src_init
       
   247 ,        };
       
   248 
       
   249     static const GInterfaceInfo speech_encoder_config_info =
       
   250         {
       
   251         gst_speech_encoder_config_handler_init,
       
   252         NULL,
       
   253         NULL
       
   254         };
       
   255 
       
   256     static const GInterfaceInfo g711_encoder_info =
       
   257         {
       
   258         gst_g711_encoder_handler_init,
       
   259         NULL,
       
   260         NULL
       
   261         };
       
   262 
       
   263     static const GInterfaceInfo g729_encoder_info =
       
   264          {
       
   265          gst_g729_encoder_handler_init,
       
   266          NULL,
       
   267          NULL
       
   268          };
       
   269 
       
   270     static const GInterfaceInfo ilbc_encoder_info =
       
   271          {
       
   272          gst_ilbc_encoder_handler_init,
       
   273          NULL,
       
   274          NULL
       
   275          };
       
   276 
       
   277     devsoundsrc_type =
       
   278     g_type_register_static (GST_TYPE_PUSH_SRC, "GstDevsoundSrc",
       
   279             &devsoundsrc_info, 0);
       
   280 
       
   281     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_SPEECH_ENCODER_CONFIG,
       
   282             &speech_encoder_config_info);
       
   283 
       
   284     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_G711_ENCODER,
       
   285             &g711_encoder_info);
       
   286 
       
   287     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_G729_ENCODER,
       
   288               &g729_encoder_info);
       
   289 
       
   290     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_ILBC_ENCODER,
       
   291               &ilbc_encoder_info);
       
   292 
       
   293     }
       
   294 
       
   295 return devsoundsrc_type;
       
   296 }
       
   297 
       
   298 static void gst_devsound_src_dispose(GObject * object)
       
   299     {
       
   300     GstDevsoundSrc *devsoundsrc= GST_DEVSOUND_SRC (object);
       
   301     G_OBJECT_CLASS (parent_class)->dispose (object);
       
   302     }
       
   303 
       
   304 static void gst_devsound_src_class_init(GstDevsoundSrcClass * klass)
       
   305     {
       
   306     GObjectClass *gobject_class;
       
   307     GstElementClass *gstelement_class;
       
   308     GstBaseSrcClass *gstbasesrc_class;
       
   309     GstPushSrcClass *gstpushsrc_class;
       
   310 
       
   311     gobject_class = (GObjectClass *) klass;
       
   312     gstelement_class = (GstElementClass *) klass;
       
   313     gstbasesrc_class = (GstBaseSrcClass *) klass;
       
   314     gstpushsrc_class = (GstPushSrcClass *) klass;
       
   315 
       
   316     parent_class = g_type_class_peek_parent(klass);
       
   317 
       
   318     gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_devsound_src_dispose);
       
   319     gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_devsound_src_get_property);
       
   320     gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_devsound_src_set_property);
       
   321 
       
   322     g_object_class_install_property(gobject_class, PROP_DEVICE,
       
   323             g_param_spec_string("device", "Device", "Devsound device ",
       
   324                     DEFAULT_DEVICE, G_PARAM_READWRITE));
       
   325 
       
   326     g_object_class_install_property(gobject_class, GAIN, g_param_spec_int(
       
   327             "gain", "Gain", "Devsound src gain", -1, G_MAXINT, -1,
       
   328             G_PARAM_READWRITE));
       
   329 
       
   330     g_object_class_install_property(gobject_class, MAXGAIN, g_param_spec_int(
       
   331             "maxgain", "MaxGain", "Devsound src max gain", -1, G_MAXINT, -1,
       
   332             G_PARAM_READABLE));
       
   333 
       
   334     g_object_class_install_property(gobject_class, LEFTBALANCE,
       
   335             g_param_spec_int("leftbalance", "Left Balance", "Left Balance",
       
   336                     -1, G_MAXINT, -1, G_PARAM_READWRITE));
       
   337 
       
   338     g_object_class_install_property(gobject_class, RIGHTBALANCE,
       
   339             g_param_spec_int("rightbalance", "Right Balance",
       
   340                     "Right Balance", -1, G_MAXINT, -1, G_PARAM_READWRITE));
       
   341 
       
   342     g_object_class_install_property(gobject_class, SAMPLESRECORDED,
       
   343             g_param_spec_int("samplesrecorded", "Samples Recorded",
       
   344                     "Samples Recorded", -1, G_MAXINT, -1, G_PARAM_READABLE));
       
   345 
       
   346     g_object_class_install_property(gobject_class, PRIORITY,
       
   347             g_param_spec_int("priority", "Priority", "Priority ", -1,
       
   348             G_MAXINT, -1,
       
   349             G_PARAM_READWRITE));
       
   350 
       
   351     g_object_class_install_property(gobject_class, PREFERENCE,
       
   352             g_param_spec_int("preference", "Preference", "Preference ", -1,
       
   353             G_MAXINT, -1,
       
   354             G_PARAM_READWRITE));
       
   355 
       
   356     g_object_class_install_property(gobject_class, RATE,
       
   357             g_param_spec_int("rate", "Rate", "Rate ", -1,
       
   358                     G_MAXINT, -1,
       
   359                     G_PARAM_READWRITE));
       
   360 
       
   361     g_object_class_install_property(gobject_class, CHANNELS,
       
   362             g_param_spec_int("channels", "Channels", "Channels ", -1,
       
   363                     G_MAXINT, -1,
       
   364                     G_PARAM_READWRITE));
       
   365     gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_devsound_src_start);
       
   366     gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_devsound_src_stop);
       
   367     gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_getcaps);
       
   368     gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_setcaps);
       
   369 
       
   370     gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_devsound_src_create);
       
   371     }
       
   372 
       
   373 static void gst_devsound_src_init(GstDevsoundSrc * devsoundsrc)
       
   374     {
       
   375     GST_DEBUG_OBJECT(devsoundsrc, "initializing devsoundsrc");
       
   376     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init ENTER ",NULL);
       
   377     devsoundsrc->device = g_strdup(DEFAULT_DEVICE);
       
   378     devsoundsrc->handle=NULL;
       
   379     devsoundsrc->preference = 0; //default=>EMdaPriorityPreferenceNone;
       
   380     devsoundsrc->priority = 0;   //default=>EMdaPriorityNormal;
       
   381     pthread_mutex_init(&create_mutex1, NULL);
       
   382     pthread_cond_init(&create_condition1, NULL);
       
   383     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init EXIT ",NULL);
       
   384     }
       
   385 
       
   386 static void *StartDevSoundThread(void *threadarg)
       
   387     {
       
   388     GstDevsoundSrc *devsoundsrc= GST_DEVSOUND_SRC (threadarg);
       
   389     int buffersize;
       
   390     TUint8* gBuffer;
       
   391     GstBuffer* pushBuffer= NULL;
       
   392     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "StartDevSoundThread ",NULL);
       
   393     open_devsound(&(devsoundsrc->handle));
       
   394 
       
   395     getsupporteddatatypes(devsoundsrc);
       
   396 
       
   397 // TODO obtain mutex to update variable here???
       
   398     consumer_thread_state = CONSUMER_THREAD_INITIALIZED;
       
   399 	
       
   400     //pre_init_setconf(devsoundsrc);
       
   401 
       
   402     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Record Init ",NULL);
       
   403 
       
   404     pthread_mutex_lock(&(create_mutex1));
       
   405     pthread_cond_signal(&(create_condition1));
       
   406     pthread_mutex_unlock(&(create_mutex1));
       
   407 
       
   408     // Wait until we receive a command from the main thread
       
   409     // TODO obtain mutex to read variable here???
       
   410     while ( cmd == OPEN )
       
   411         {
       
   412         pthread_mutex_lock(&create_mutex1);
       
   413         pthread_cond_wait(&create_condition1, &create_mutex1);
       
   414         pthread_mutex_unlock(&create_mutex1);
       
   415         }
       
   416 
       
   417     // This could happen if client creates sink and deletes it
       
   418     // without putting it to play state
       
   419     if ( cmd != CLOSE )
       
   420         {
       
   421         initialize_devsound(devsoundsrc);
       
   422     
       
   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))
       
   455             {
       
   456             memcpy(GST_BUFFER_DATA(pushBuffer),gBuffer,buffersize);
       
   457             }
       
   458         else
       
   459             {
       
   460             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Push buffer alloc failed ",NULL);
       
   461             }
       
   462 
       
   463         if (dataqueue)
       
   464             {
       
   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 
       
   487         switch (cmd)
       
   488             {
       
   489             case READDATA:
       
   490                 {
       
   491                 record_data(devsoundsrc->handle);
       
   492                 }
       
   493                 break;
       
   494             case CLOSE:
       
   495                 {
       
   496                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Before Close DevSound ",NULL);
       
   497                 close_devsound(devsoundsrc);
       
   498                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Close DevSound ",NULL);
       
   499                 devsoundsrc->handle= NULL;
       
   500                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After handle NULL ",NULL);
       
   501 
       
   502                 pthread_mutex_lock(&(create_mutex1));
       
   503                 pthread_cond_signal(&(create_condition1));
       
   504                 pthread_mutex_unlock(&(create_mutex1));
       
   505 				// TODO obtain mutex here
       
   506                 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;
       
   507                 pthread_exit(NULL);
       
   508                 }
       
   509                 break;
       
   510             default:
       
   511                 // TODO obtain mutex here
       
   512                 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;			
       
   513                 pthread_exit(NULL);
       
   514                 break;
       
   515             }
       
   516         }
       
   517     // TODO obtain mutex here
       
   518     consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;
       
   519     pthread_exit(NULL);
       
   520     }
       
   521 
       
   522 static void gst_devsound_src_set_property(GObject * object, guint prop_id,
       
   523         const GValue * value, GParamSpec * pspec)
       
   524     {
       
   525     GstDevsoundSrc *src;
       
   526 
       
   527     src = GST_DEVSOUND_SRC (object);
       
   528 
       
   529     switch (prop_id)
       
   530         {
       
   531         case PROP_DEVICE:
       
   532             if (src->device)
       
   533                 g_free(src->device);
       
   534             src->device = g_value_dup_string(value);
       
   535             if (src->probed_caps)
       
   536                 {
       
   537                 gst_caps_unref(src->probed_caps);
       
   538                 src->probed_caps = NULL;
       
   539                 }
       
   540             break;
       
   541         case CHANNELS:
       
   542             src->channels = g_value_get_int(value);
       
   543             src->pending.channelsupdate = TRUE;
       
   544             break;
       
   545         case RATE:
       
   546             src->rate = g_value_get_int(value);
       
   547             //Convert rate to something devsound understands
       
   548             src->rate = gst_devsound_src_get_rate(src->rate);
       
   549             src->pending.rateupdate = TRUE;
       
   550             break;
       
   551         case GAIN:
       
   552             src->gain = g_value_get_int(value);
       
   553             src->pending.gainupdate = TRUE;
       
   554             break;
       
   555         case LEFTBALANCE:
       
   556             src->leftbalance = g_value_get_int(value);
       
   557             src->pending.leftbalanceupdate = TRUE;
       
   558             break;
       
   559         case RIGHTBALANCE:
       
   560             src->rightbalance = g_value_get_int(value);
       
   561             src->pending.rightbalanceupdate = TRUE;
       
   562             break;
       
   563         case PRIORITY:
       
   564             src->priority = g_value_get_int(value);
       
   565             src->pending.priorityupdate = TRUE;
       
   566             break;
       
   567         case PREFERENCE:
       
   568             src->preference = g_value_get_int(value);
       
   569             src->pending.preferenceupdate = TRUE;
       
   570             break;
       
   571         default:
       
   572             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       
   573             break;
       
   574         }
       
   575     }
       
   576 
       
   577 static void gst_devsound_src_get_property(GObject * object, guint prop_id,
       
   578         GValue * value, GParamSpec * pspec)
       
   579     {
       
   580     GstDevsoundSrc *src;
       
   581 
       
   582     src = GST_DEVSOUND_SRC (object);
       
   583 
       
   584     switch (prop_id)
       
   585         {
       
   586         case PROP_DEVICE:
       
   587             g_value_set_string(value, src->device);
       
   588             break;
       
   589         case CHANNELS:
       
   590             g_value_set_int(value, src->channels);
       
   591             break;
       
   592         case RATE:
       
   593             g_value_set_int(value, src->rate);
       
   594             break;
       
   595         case GAIN:
       
   596             g_value_set_int(value, src->gain);
       
   597             break;
       
   598         case MAXGAIN:
       
   599             g_value_set_int(value, src->maxgain);
       
   600             break;
       
   601         case SAMPLESRECORDED:
       
   602             g_value_set_int(value, src->samplesrecorded);
       
   603             break;
       
   604         default:
       
   605             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       
   606             break;
       
   607         }
       
   608     }
       
   609 
       
   610 static gboolean gst_devsound_src_setcaps(GstBaseSrc *bsrc, GstCaps *caps)
       
   611     {
       
   612     GstDevsoundSrc *devsoundsrc;
       
   613     GstStructure *structure;
       
   614     const gchar *mimetype;
       
   615     int rate;
       
   616     int channel;
       
   617 
       
   618     devsoundsrc = GST_DEVSOUND_SRC (bsrc);
       
   619     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_setcaps ENTER ",NULL);
       
   620     structure = gst_caps_get_structure(caps, 0);
       
   621     mimetype = gst_structure_get_name(structure);
       
   622 
       
   623     gst_structure_get_int(structure, "rate", &rate);
       
   624     gst_structure_get_int(structure, "channels", &channel);
       
   625 
       
   626     devsoundsrc->rate = gst_devsound_src_get_rate(rate);
       
   627     devsoundsrc->channels = channel;
       
   628 
       
   629     set_channels(devsoundsrc->handle, devsoundsrc->channels);
       
   630 
       
   631     set_rate(devsoundsrc->handle, devsoundsrc->rate);
       
   632 
       
   633     if (!strncmp(mimetype, "audio/x-raw-int", 15))
       
   634         {
       
   635         devsoundsrc->fourcc = 0x36315020; //KMMFFourCCCodePCM16
       
   636         }
       
   637     else if (!strncmp(mimetype, "audio/amr", 9))
       
   638         {
       
   639         devsoundsrc->fourcc = 0x524d4120; //KMMFFourCCCodeAMR
       
   640         }
       
   641     else if (!strncmp(mimetype, "audio/x-mulaw", 13)||
       
   642              !strncmp(mimetype,"audio/x-alaw", 12))
       
   643         {
       
   644         devsoundsrc->fourcc = 0x31313747; //KMccFourCCIdG711
       
   645         }
       
   646     else if (!strncmp(mimetype, "audio/ilbc", 10))
       
   647         {
       
   648         devsoundsrc->fourcc = 0x43424c49; //KMccFourCCIdILBC
       
   649         }
       
   650     else if (!strncmp(mimetype, "audio/g729", 10))
       
   651         {
       
   652         devsoundsrc->fourcc = 0x39323747; //KMccFourCCIdG729
       
   653         }
       
   654     else
       
   655         {
       
   656         devsoundsrc->fourcc = 0x36315020; //KMMFFourCCCodePCM16
       
   657         }
       
   658 
       
   659     set_fourcc(devsoundsrc->handle, devsoundsrc->fourcc);
       
   660     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Before Signal DevSound from STOP",NULL);
       
   661     pthread_mutex_lock(&(create_mutex1));
       
   662     pthread_cond_signal(&(create_condition1));
       
   663     pthread_mutex_unlock(&(create_mutex1));
       
   664     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Signal DevSound from STOP ",NULL);
       
   665     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_setcaps EXIT ",NULL);
       
   666     return TRUE;
       
   667     }
       
   668 
       
   669 static GstCaps * gst_devsound_src_getcaps(GstBaseSrc * bsrc)
       
   670     {
       
   671     GstDevsoundSrc *devsoundsrc;
       
   672     GstCaps *caps;
       
   673     GstPadTemplate *pad_template;
       
   674 
       
   675     devsoundsrc = GST_DEVSOUND_SRC (bsrc);
       
   676 
       
   677     GST_DEBUG_OBJECT(devsoundsrc, "getcaps called");
       
   678 
       
   679     pad_template = gst_static_pad_template_get(&devsound_src_factory);
       
   680     caps = gst_caps_copy(gst_pad_template_get_caps(pad_template));
       
   681 
       
   682     gst_object_unref(pad_template);
       
   683 
       
   684     return caps;
       
   685     }
       
   686 
       
   687 static gboolean gst_devsound_src_start(GstBaseSrc * bsrc)
       
   688     {
       
   689     GstBuffer *tmp_gstbuffer=NULL;	
       
   690     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
       
   691     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start ENTER ",NULL);
       
   692 
       
   693     if(dataqueue)
       
   694         {
       
   695         while (dataqueue->length)
       
   696             {
       
   697             tmp_gstbuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
       
   698             gst_buffer_unref(tmp_gstbuffer);
       
   699             }
       
   700         g_queue_free(dataqueue);
       
   701         dataqueue = NULL;
       
   702         }
       
   703     
       
   704     if(dataqueue == NULL)
       
   705           {
       
   706           dataqueue = g_queue_new();
       
   707           }
       
   708 
       
   709     consumer_thread_state = CONSUMER_THREAD_INITIALIZING;
       
   710     cmd = OPEN;
       
   711     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Thread Create ",NULL);
       
   712     pthread_create(&ds_thread, NULL, StartDevSoundThread, (void *)src);
       
   713     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "After Thread Create ",NULL);
       
   714     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Mutex Wait in START ",NULL);
       
   715     if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING)
       
   716         {
       
   717         pthread_mutex_lock(&create_mutex1);
       
   718         pthread_cond_wait(&create_condition1, &create_mutex1);
       
   719         pthread_mutex_unlock(&create_mutex1);
       
   720         }
       
   721     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "AFter Mutex Wait in START ",NULL);
       
   722     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start EXIT ",NULL);
       
   723     return TRUE;
       
   724     /* ERRORS */
       
   725     }
       
   726 
       
   727 static gboolean gst_devsound_src_stop(GstBaseSrc * bsrc)
       
   728     {
       
   729 	
       
   730     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
       
   731     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_stop ENTER ");
       
   732     cmd = CLOSE;
       
   733 
       
   734     //GST_OBJECT_LOCK (src);
       
   735     pthread_mutex_lock(&(create_mutex1));
       
   736     pthread_cond_wait(&(create_condition1), &(create_mutex1));
       
   737     pthread_mutex_unlock(&(create_mutex1));
       
   738     //GST_OBJECT_UNLOCK (src);
       
   739 
       
   740     if (popBuffer)
       
   741         {
       
   742         gst_buffer_unref(popBuffer);
       
   743         popBuffer = NULL;
       
   744         dataleft = 0;   //Arun'S changes
       
   745         }
       
   746     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before QUEUE Lock in STOP ");
       
   747     GST_OBJECT_LOCK(src);
       
   748     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "After QUEUE Lock in STOP ");
       
   749     while (dataqueue->length)
       
   750         {
       
   751         //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Removing DATAQUEUE elements ENTER ");
       
   752         popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
       
   753         gst_buffer_unref(popBuffer);
       
   754         popBuffer = NULL;
       
   755         dataleft = 0; //Arun'S changes
       
   756         //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Removing DATAQUEUE elements EXIT ");
       
   757         }
       
   758     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Queue FREE ");
       
   759     g_queue_free(dataqueue);
       
   760     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "After Queue FREE ");
       
   761     dataqueue = NULL;
       
   762     GST_OBJECT_UNLOCK(src);
       
   763 
       
   764     pthread_mutex_destroy(&create_mutex1);
       
   765     pthread_cond_destroy(&(create_condition1));
       
   766 
       
   767 
       
   768     g_free(src->device);
       
   769     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_stop EXIT ");
       
   770     return TRUE;
       
   771     }
       
   772 
       
   773 static gboolean gst_devsound_src_unlock(GstBaseSrc * bsrc)
       
   774     {
       
   775     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
       
   776 
       
   777     GST_LOG_OBJECT(src, "Flushing");
       
   778     GST_OBJECT_LOCK (src);
       
   779     GST_OBJECT_UNLOCK (src);
       
   780 
       
   781     return TRUE;
       
   782     }
       
   783 
       
   784 static gboolean gst_devsound_src_unlock_stop(GstBaseSrc * bsrc)
       
   785     {
       
   786     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
       
   787 
       
   788     GST_LOG_OBJECT(src, "No longer flushing");
       
   789     return TRUE;
       
   790     }
       
   791 
       
   792 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset,
       
   793         guint size, GstBuffer **buf)
       
   794     {
       
   795     GstDevsoundSrc *dsrc= GST_DEVSOUND_SRC(src);
       
   796     int bufferpos=0;
       
   797     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create ENTER ");
       
   798 
       
   799     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before Buffer Alloc in CREATE ",NULL);
       
   800     *buf = gst_buffer_try_new_and_alloc(size);
       
   801     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFter Buffer Alloc in CREATE ",NULL);
       
   802 
       
   803     while (size > 0)
       
   804         {
       
   805         if (dataleft >= size)
       
   806             {
       
   807             // if there is some data left in the popped buffer previously whose size
       
   808             // is more then the buffer which is incoming fresh to get filled, fill it
       
   809             //here. and if the data left in the popped buffer is 0, then unref it
       
   810             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "dataleft >=size in CREATE ", NULL);
       
   811             memcpy(GST_BUFFER_DATA(*buf)+bufferpos,GST_BUFFER_DATA(popBuffer)+dataCopied,size);
       
   812             bufferpos+=size;
       
   813             dataCopied += size;
       
   814             dataleft = GST_BUFFER_SIZE(popBuffer) - dataCopied;
       
   815             size = 0;
       
   816             if (dataleft == 0)
       
   817                 {
       
   818                 dataCopied = 0;
       
   819                 gst_buffer_unref(popBuffer);
       
   820                 popBuffer = NULL;
       
   821                 }
       
   822             }
       
   823         else
       
   824             {
       
   825             // if the dataleft in the popped buffer is greater then 0 and  less then
       
   826             // the size of data needed for the fresh buffer. copy the remaining data
       
   827             // from the popped buffer and then unref it.
       
   828             if (dataleft > 0)
       
   829                 {
       
   830                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "dataleft >0 in CREATE ",NULL);
       
   831                 memcpy(GST_BUFFER_DATA(*buf)+bufferpos,GST_BUFFER_DATA(popBuffer)+dataCopied,dataleft);
       
   832                 size -= dataleft;
       
   833                 bufferpos += dataleft;
       
   834                 dataCopied = 0;
       
   835                 dataleft = 0;
       
   836                 gst_buffer_unref(popBuffer);
       
   837                 popBuffer = NULL;
       
   838                 }
       
   839 
       
   840             // we wait here if the dataqueue length is 0 and we need data
       
   841             // to be filled in the queue from the DevSound Thread
       
   842             if (!dataqueue->length)
       
   843                 {
       
   844                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before WAIT in CREATE ",NULL);
       
   845                 cmd = READDATA;
       
   846                 pthread_mutex_lock(&(create_mutex1));
       
   847                 pthread_cond_signal(&(create_condition1));
       
   848                 pthread_mutex_unlock(&(create_mutex1));
       
   849                 
       
   850                 pthread_mutex_lock(&(create_mutex1));
       
   851                 pthread_cond_wait(&(create_condition1), &(create_mutex1));
       
   852                 pthread_mutex_unlock(&(create_mutex1));
       
   853                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER WAIT in CREATE ",NULL);
       
   854                 }
       
   855 
       
   856             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before POP in CREATE ",NULL);
       
   857             GST_OBJECT_LOCK(dsrc);
       
   858             popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
       
   859             GST_OBJECT_UNLOCK(dsrc);
       
   860             //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER POP in CREATE ",NULL);
       
   861 
       
   862             // copy the data from the popped buffer based on how much of the incoming
       
   863             //buffer size is left to fill. we might have filled the fresh buffer somewhat
       
   864             // where the size of the fresh buffer is more then the data remaining in the
       
   865             // popped buffer.
       
   866             if (size < GST_BUFFER_SIZE(popBuffer))
       
   867                 {
       
   868                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "SIZE < POPBUFFER CREATE ",NULL);
       
   869                 memcpy(GST_BUFFER_DATA(*buf)+ bufferpos,GST_BUFFER_DATA(popBuffer),size);
       
   870                 bufferpos+=size;
       
   871                 dataCopied = size;
       
   872                 dataleft = GST_BUFFER_SIZE(popBuffer) - dataCopied;
       
   873                 size = 0;
       
   874                 }
       
   875             else
       
   876                 {
       
   877                 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "SIZE >= POPBUFFER CREATE ",NULL);
       
   878                 memcpy(GST_BUFFER_DATA(*buf)+ bufferpos,GST_BUFFER_DATA(popBuffer),GST_BUFFER_SIZE(popBuffer));
       
   879                 bufferpos+=GST_BUFFER_SIZE(popBuffer);
       
   880                 dataCopied = 0;
       
   881                 dataleft = 0;
       
   882                 size = size - GST_BUFFER_SIZE(popBuffer);
       
   883                 }
       
   884 
       
   885             if (!dataleft)
       
   886                 {
       
   887                 gst_buffer_unref(popBuffer);
       
   888                 popBuffer = NULL;
       
   889                 }
       
   890             }
       
   891         }
       
   892     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create EXIT ",NULL);
       
   893     return GST_FLOW_OK;
       
   894     }
       
   895 
       
   896 static gboolean gst_devsound_src_is_seekable(GstBaseSrc * bsrc)
       
   897     {
       
   898     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
       
   899     return FALSE;
       
   900     }
       
   901 
       
   902 static gboolean gst_devsound_src_get_size(GstBaseSrc * bsrc, guint64 * size)
       
   903     {
       
   904     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
       
   905     return TRUE;
       
   906     }
       
   907 
       
   908 static void gst_speech_encoder_config_handler_init(gpointer g_iface,
       
   909         gpointer iface_data)
       
   910     {
       
   911     GstSpeechEncoderConfigIntfc *iface =
       
   912             (GstSpeechEncoderConfigIntfc *) g_iface;
       
   913 
       
   914     iface->GetBitrate = gst_get_speech_encoder_bit_rate;
       
   915     iface->GetSupportedBitrates = gst_get_speech_encoder_supported_bit_rates;
       
   916     iface->GetVadMode = gst_get_speech_encoder_vad_mode;
       
   917     iface->SetBitrate = gst_set_speech_encoder_bit_rate;
       
   918     iface->SetVadMode = gst_set_speech_encoder_vad_mode;
       
   919 
       
   920     }
       
   921 
       
   922 static gint gst_get_speech_encoder_bit_rate(guint* aBitrate)
       
   923     {
       
   924     *aBitrate = speechbitrate;
       
   925     return 0;
       
   926     }
       
   927 static gint gst_get_speech_encoder_supported_bit_rates(
       
   928         GList** aSupportedBitrate)
       
   929     {
       
   930     *aSupportedBitrate = supportedbitrates;
       
   931     return 0;
       
   932     }
       
   933 static gint gst_get_speech_encoder_vad_mode(gboolean* aVadMode)
       
   934     {
       
   935     *aVadMode = speechvadmode;
       
   936     return 0;
       
   937     }
       
   938 static gint gst_set_speech_encoder_bit_rate(guint aBitrate)
       
   939     {
       
   940     speechbitrate = aBitrate;
       
   941     customInfaceUpdate.speechbitrateupdate = TRUE;
       
   942     return 0;
       
   943     }
       
   944 
       
   945 static gint gst_set_speech_encoder_vad_mode(gboolean aVadMode)
       
   946     {
       
   947     speechvadmode = aVadMode;
       
   948     customInfaceUpdate.speechvadmodeupdate = TRUE;
       
   949     return 0;
       
   950     }
       
   951 
       
   952 
       
   953 static void gst_Apply_SpeechEncoder_Update(GstDevsoundSrc *devsoundsrc )
       
   954     {
       
   955     if(customInfaceUpdate.speechbitrateupdate == TRUE)
       
   956         {
       
   957         set_speech_encoder_bit_rate(devsoundsrc->handle,speechbitrate);
       
   958         customInfaceUpdate.speechbitrateupdate = FALSE;
       
   959         }
       
   960     if(customInfaceUpdate.speechvadmodeupdate == TRUE)
       
   961         {
       
   962         set_speech_encoder_vad_mode(devsoundsrc->handle,speechvadmode);
       
   963         customInfaceUpdate.speechvadmodeupdate = FALSE;
       
   964         }
       
   965     }
       
   966 
       
   967 static void gst_g711_encoder_handler_init(gpointer g_iface,
       
   968         gpointer iface_data)
       
   969     {
       
   970     GstG711EncoderIntfc *iface = (GstG711EncoderIntfc *) g_iface;
       
   971 
       
   972     iface->GetVadMode = gst_get_g711_encoder_vad_mode;
       
   973     iface->SetEncoderMode = gst_set_g711_encoder_mode;
       
   974     iface->SetVadMode = gst_set_g711_vad_mode;
       
   975 
       
   976     }
       
   977 
       
   978 static gint gst_get_g711_encoder_vad_mode(gboolean* aVadMode)
       
   979     {
       
   980     *aVadMode = g711vadmode;
       
   981     return 0;
       
   982     }
       
   983 
       
   984 static gint gst_set_g711_encoder_mode(enum TG711EncodeMode aEncodeMode)
       
   985     {
       
   986     g711encodemode = aEncodeMode;
       
   987     customInfaceUpdate.g711encodermodeupdate = TRUE;
       
   988     return 0;
       
   989     }
       
   990 static gint gst_set_g711_vad_mode(gboolean aVadMode)
       
   991     {
       
   992     g711vadmode = aVadMode;
       
   993     customInfaceUpdate.g711vadmodeupdate = TRUE;
       
   994     return 0;
       
   995     }
       
   996 
       
   997 
       
   998 static void gst_Apply_G711Encoder_Update(GstDevsoundSrc *devsoundsrc )
       
   999     {
       
  1000 
       
  1001     if(customInfaceUpdate.g711encodermodeupdate == TRUE)
       
  1002         {
       
  1003         set_g711_encoder_mode(devsoundsrc->handle,g711encodemode);
       
  1004         customInfaceUpdate.g711encodermodeupdate = FALSE;
       
  1005         }
       
  1006     if(customInfaceUpdate.g711vadmodeupdate == TRUE)
       
  1007         {
       
  1008         set_g711_vad_mode(devsoundsrc->handle,g711vadmode);
       
  1009         customInfaceUpdate.g711vadmodeupdate = FALSE;
       
  1010         }
       
  1011     }
       
  1012 
       
  1013 static void gst_g729_encoder_handler_init(gpointer g_iface,
       
  1014         gpointer iface_data)
       
  1015     {
       
  1016 
       
  1017     GstG729EncoderIntfc *iface = (GstG729EncoderIntfc *) g_iface;
       
  1018 
       
  1019     iface->GetVadMode = gst_get_g729_vad_mode;
       
  1020     iface->SetVadMode = gst_set_g729_vad_mode;
       
  1021 
       
  1022     }
       
  1023 
       
  1024 static gint gst_set_g729_vad_mode(TBool aVadMode)
       
  1025     {
       
  1026     g729vadmode = aVadMode;
       
  1027     customInfaceUpdate.g729vadmodeupdate = TRUE;
       
  1028     return 0;
       
  1029     }
       
  1030 
       
  1031 static gint gst_get_g729_vad_mode(TBool* aVadMode)
       
  1032     {
       
  1033     *aVadMode = g729vadmode;
       
  1034     return 0;
       
  1035     }
       
  1036 static void gst_Apply_G729Encoder_Update(GstDevsoundSrc *devsoundsrc )
       
  1037     {
       
  1038     if(customInfaceUpdate.g729vadmodeupdate)
       
  1039         {
       
  1040         set_g729_vad_mode(devsoundsrc->handle,g729vadmode);
       
  1041         customInfaceUpdate.g729vadmodeupdate = FALSE;
       
  1042         }
       
  1043 
       
  1044     }
       
  1045 
       
  1046 static void gst_ilbc_encoder_handler_init(gpointer g_iface,
       
  1047         gpointer iface_data)
       
  1048     {
       
  1049     GstIlbcEncoderIntfc *iface = (GstIlbcEncoderIntfc *) g_iface;
       
  1050 
       
  1051     iface->GetVadMode = gst_get_ilbc_vad_mode;
       
  1052     iface->SetEncoderMode = gst_set_ilbc_encoder_mode;
       
  1053     iface->SetVadMode = gst_set_ilbc_vad_mode;
       
  1054     }
       
  1055 
       
  1056 static gint gst_set_ilbc_encoder_mode(enum TIlbcEncodeMode aEncodeMode)
       
  1057     {
       
  1058     ilbcencodemode = aEncodeMode;
       
  1059     return 0;
       
  1060     }
       
  1061 
       
  1062 static gint gst_set_ilbc_vad_mode(gboolean aVadMode)
       
  1063     {
       
  1064     ilbcvadmode = aVadMode;
       
  1065     return 0;
       
  1066     }
       
  1067 
       
  1068 static gint gst_get_ilbc_vad_mode(gboolean* aVadMode)
       
  1069     {
       
  1070     *aVadMode = ilbcvadmode;
       
  1071     return 0;
       
  1072     }
       
  1073 
       
  1074 static void gst_Apply_IlbcEncoder_Update(GstDevsoundSrc *devsoundsrc )
       
  1075     {
       
  1076     if(customInfaceUpdate.ilbcencodermodeupdate)
       
  1077         {
       
  1078         set_ilbc_encoder_mode(devsoundsrc->handle,ilbcencodemode);
       
  1079         customInfaceUpdate.ilbcencodermodeupdate = FALSE;
       
  1080         }
       
  1081     if(customInfaceUpdate.ilbcvadmodeupdate)
       
  1082          {
       
  1083          set_ilbc_vad_mode(devsoundsrc->handle,ilbcvadmode);
       
  1084          customInfaceUpdate.ilbcvadmodeupdate = FALSE;
       
  1085          }
       
  1086 
       
  1087     }
       
  1088 
       
  1089 static gint gst_devsound_src_get_rate(gint rate)
       
  1090     {
       
  1091     gint result;
       
  1092 
       
  1093     switch (rate)
       
  1094         {
       
  1095         case 8000:
       
  1096             result=0x00000001;//EMMFSampleRate8000Hz;
       
  1097             break;
       
  1098         case 11025:
       
  1099             result=0x00000002;//EMMFSampleRate11025Hz;
       
  1100             break;
       
  1101         case 16000:
       
  1102             result=0x00000004;//EMMFSampleRate16000Hz;
       
  1103             break;
       
  1104         case 22050:
       
  1105             result=0x00000008;//EMMFSampleRate22050Hz;
       
  1106             break;
       
  1107         case 32000:
       
  1108             result=0x00000010;//EMMFSampleRate32000Hz;
       
  1109             break;
       
  1110         case 44100:
       
  1111             result=0x00000020;//EMMFSampleRate44100Hz;
       
  1112             break;
       
  1113         case 48000:
       
  1114             result=0x00000040;//EMMFSampleRate48000Hz;
       
  1115             break;
       
  1116         case 88200:
       
  1117             result=0x00000080;//EMMFSampleRate88200Hz;
       
  1118             break;
       
  1119         case 96000:
       
  1120             result= 0x00000100;//EMMFSampleRate96000Hz;
       
  1121             break;
       
  1122         case 12000:
       
  1123             result=0x00000200;//EMMFSampleRate12000Hz;
       
  1124             break;
       
  1125         case 24000:
       
  1126             result=0x00000400;//EMMFSampleRate24000Hz;
       
  1127             break;
       
  1128         case 64000:
       
  1129             result=0x00000800; //EMMFSampleRate64000Hz;
       
  1130             break;
       
  1131         default:
       
  1132             result=0x00000001;//EMMFSampleRate8000Hz;
       
  1133             break;
       
  1134 
       
  1135         }
       
  1136     return result;
       
  1137 
       
  1138     }
       
  1139