gst_plugins_symbian/gst/devsound/gstdevsoundsrc.c
changeset 20 7e3786c5ed27
parent 14 32e421e6175c
child 22 8d4f92b9230e
equal deleted inserted replaced
19:24ed0baaf8e5 20:7e3786c5ed27
    34 #include "gstg729encoderinterface.h"
    34 #include "gstg729encoderinterface.h"
    35 #include "gstilbcencoderinterface.h"
    35 #include "gstilbcencoderinterface.h"
    36 #include "string.h"
    36 #include "string.h"
    37 
    37 
    38 GST_DEBUG_CATEGORY_EXTERN (devsoundsrc_debug);
    38 GST_DEBUG_CATEGORY_EXTERN (devsoundsrc_debug);
       
    39 #ifdef GST_CAT_DEFAULT
       
    40 #undef GST_CAT_DEFAULT
       
    41 #endif
       
    42 
    39 #define GST_CAT_DEFAULT devsoundsrc_debug
    43 #define GST_CAT_DEFAULT devsoundsrc_debug
    40 
    44 
    41 /* elementfactory information */
    45 /* elementfactory information */
    42 static const GstElementDetails gst_devsound_src_details=
    46 static const GstElementDetails gst_devsound_src_details=
    43 GST_ELEMENT_DETAILS ("Audio Src (DEVSOUND)",
    47 GST_ELEMENT_DETAILS ("Audio Src (DEVSOUND)",
   282          NULL
   286          NULL
   283          };
   287          };
   284 
   288 
   285     devsoundsrc_type =
   289     devsoundsrc_type =
   286     g_type_register_static (GST_TYPE_PUSH_SRC, "GstDevsoundSrc",
   290     g_type_register_static (GST_TYPE_PUSH_SRC, "GstDevsoundSrc",
   287             &devsoundsrc_info, 0);
   291             &devsoundsrc_info, (GTypeFlags)0);
   288 
   292 
   289     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_SPEECH_ENCODER_CONFIG,
   293     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_SPEECH_ENCODER_CONFIG,
   290             &speech_encoder_config_info);
   294             &speech_encoder_config_info);
   291 
   295 
   292     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_G711_ENCODER,
   296     g_type_add_interface_static (devsoundsrc_type, GST_TYPE_G711_ENCODER,
   329 
   333 
   330     gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_devsound_src_change_state);
   334     gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_devsound_src_change_state);
   331     
   335     
   332     g_object_class_install_property(gobject_class, PROP_DEVICE,
   336     g_object_class_install_property(gobject_class, PROP_DEVICE,
   333             g_param_spec_string("device", "Device", "Devsound device ",
   337             g_param_spec_string("device", "Device", "Devsound device ",
   334                     DEFAULT_DEVICE, G_PARAM_READWRITE));
   338                     DEFAULT_DEVICE, (GParamFlags)G_PARAM_READWRITE));
   335 
   339 
   336     g_object_class_install_property(gobject_class, GAIN, g_param_spec_int(
   340     g_object_class_install_property(gobject_class, GAIN, g_param_spec_int(
   337             "gain", "Gain", "Devsound src gain", -1, G_MAXINT, -1,
   341             "gain", "Gain", "Devsound src gain", -1, G_MAXINT, -1,
   338             G_PARAM_READWRITE));
   342             (GParamFlags)G_PARAM_READWRITE));
   339 
   343 
   340     g_object_class_install_property(gobject_class, MAXGAIN, g_param_spec_int(
   344     g_object_class_install_property(gobject_class, MAXGAIN, g_param_spec_int(
   341             "maxgain", "MaxGain", "Devsound src max gain", -1, G_MAXINT, -1,
   345             "maxgain", "MaxGain", "Devsound src max gain", -1, G_MAXINT, -1,
   342             G_PARAM_READABLE));
   346             G_PARAM_READABLE));
   343 
   347 
   344     g_object_class_install_property(gobject_class, LEFTBALANCE,
   348     g_object_class_install_property(gobject_class, LEFTBALANCE,
   345             g_param_spec_int("leftbalance", "Left Balance", "Left Balance",
   349             g_param_spec_int("leftbalance", "Left Balance", "Left Balance",
   346                     -1, G_MAXINT, -1, G_PARAM_READWRITE));
   350                     -1, G_MAXINT, -1, (GParamFlags)G_PARAM_READWRITE));
   347 
   351 
   348     g_object_class_install_property(gobject_class, RIGHTBALANCE,
   352     g_object_class_install_property(gobject_class, RIGHTBALANCE,
   349             g_param_spec_int("rightbalance", "Right Balance",
   353             g_param_spec_int("rightbalance", "Right Balance",
   350                     "Right Balance", -1, G_MAXINT, -1, G_PARAM_READWRITE));
   354                     "Right Balance", -1, G_MAXINT, -1, (GParamFlags)G_PARAM_READWRITE));
   351 
   355 
   352     g_object_class_install_property(gobject_class, SAMPLESRECORDED,
   356     g_object_class_install_property(gobject_class, SAMPLESRECORDED,
   353             g_param_spec_int("samplesrecorded", "Samples Recorded",
   357             g_param_spec_int("samplesrecorded", "Samples Recorded",
   354                     "Samples Recorded", -1, G_MAXINT, -1, G_PARAM_READABLE));
   358                     "Samples Recorded", -1, G_MAXINT, -1, G_PARAM_READABLE));
   355 
   359 
   356     g_object_class_install_property(gobject_class, PRIORITY,
   360     g_object_class_install_property(gobject_class, PRIORITY,
   357             g_param_spec_int("priority", "Priority", "Priority ", -1,
   361             g_param_spec_int("priority", "Priority", "Priority ", -1,
   358             G_MAXINT, -1,
   362             G_MAXINT, -1,
   359             G_PARAM_READWRITE));
   363             (GParamFlags)G_PARAM_READWRITE));
   360 
   364 
   361     g_object_class_install_property(gobject_class, PREFERENCE,
   365     g_object_class_install_property(gobject_class, PREFERENCE,
   362             g_param_spec_int("preference", "Preference", "Preference ", -1,
   366             g_param_spec_int("preference", "Preference", "Preference ", -1,
   363             G_MAXINT, -1,
   367             G_MAXINT, -1,
   364             G_PARAM_READWRITE));
   368             (GParamFlags)G_PARAM_READWRITE));
   365 
   369 
   366     g_object_class_install_property(gobject_class, RATE,
   370     g_object_class_install_property(gobject_class, RATE,
   367             g_param_spec_int("rate", "Rate", "Rate ", -1,
   371             g_param_spec_int("rate", "Rate", "Rate ", -1,
   368                     G_MAXINT, -1,
   372                     G_MAXINT, -1,
   369                     G_PARAM_READWRITE));
   373                     (GParamFlags)G_PARAM_READWRITE));
   370 
   374 
   371     g_object_class_install_property(gobject_class, CHANNELS,
   375     g_object_class_install_property(gobject_class, CHANNELS,
   372             g_param_spec_int("channels", "Channels", "Channels ", -1,
   376             g_param_spec_int("channels", "Channels", "Channels ", -1,
   373                     G_MAXINT, -1,
   377                     G_MAXINT, -1,
   374                     G_PARAM_READWRITE));
   378                     (GParamFlags)G_PARAM_READWRITE));
   375     
   379     
   376     gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_devsound_src_start);
   380     gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_devsound_src_start);
   377     gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_devsound_src_stop);
   381     gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_devsound_src_stop);
   378     gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_getcaps);
   382     gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_getcaps);
   379     gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_setcaps);
   383     gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_setcaps);
   388     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init ENTER ",NULL);
   392     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init ENTER ",NULL);
   389     devsoundsrc->device = g_strdup(DEFAULT_DEVICE);
   393     devsoundsrc->device = g_strdup(DEFAULT_DEVICE);
   390     devsoundsrc->handle=NULL;
   394     devsoundsrc->handle=NULL;
   391     devsoundsrc->preference = 0; //default=>EMdaPriorityPreferenceNone;
   395     devsoundsrc->preference = 0; //default=>EMdaPriorityPreferenceNone;
   392     devsoundsrc->priority = 0;   //default=>EMdaPriorityNormal;
   396     devsoundsrc->priority = 0;   //default=>EMdaPriorityNormal;
   393     pthread_mutex_init(&create_mutex1, NULL);
   397     devsoundsrc->firstimecreatecalled = 0;
   394     pthread_cond_init(&create_condition1, NULL);
   398 //    pthread_mutex_init(&create_mutex1, NULL);
       
   399 //    pthread_cond_init(&create_condition1, NULL);
   395     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init EXIT ",NULL);
   400     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init EXIT ",NULL);
   396     }
   401     }
   397 
   402 
   398 static void *StartDevSoundThread(void *threadarg)
   403 static void *StartDevSoundThread(void *threadarg)
   399     {
   404     {
   493                 pthread_mutex_lock(&(create_mutex1));
   498                 pthread_mutex_lock(&(create_mutex1));
   494                 pthread_cond_signal(&(create_condition1));
   499                 pthread_cond_signal(&(create_condition1));
   495                 pthread_mutex_unlock(&(create_mutex1));
   500                 pthread_mutex_unlock(&(create_mutex1));
   496                 // TODO obtain mutex here
   501                 // TODO obtain mutex here
   497                 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;
   502                 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED;
       
   503                 devsoundsrc->firstimecreatecalled = 0;
   498                 pthread_exit(NULL);
   504                 pthread_exit(NULL);
   499                 }
   505                 }
   500                 break;
   506                 break;
   501             default:
   507             default:
   502                 // TODO obtain mutex here
   508                 // TODO obtain mutex here
   682 static gboolean gst_devsound_src_start(GstBaseSrc * bsrc)
   688 static gboolean gst_devsound_src_start(GstBaseSrc * bsrc)
   683     {
   689     {
   684     GstBuffer *tmp_gstbuffer=NULL;	
   690     GstBuffer *tmp_gstbuffer=NULL;	
   685     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
   691     GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc);
   686     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start ENTER ",NULL);
   692     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start ENTER ",NULL);
   687 
   693     pthread_mutex_init(&create_mutex1, NULL);
       
   694     pthread_cond_init(&create_condition1, NULL);
       
   695     
   688     if(dataqueue)
   696     if(dataqueue)
   689         {
   697         {
   690         while (g_queue_get_length(dataqueue))
   698         while (g_queue_get_length(dataqueue))
   691             {
   699             {
   692             tmp_gstbuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
   700             tmp_gstbuffer = (GstBuffer*)g_queue_pop_tail(dataqueue);
   761 
   769 
   762     pthread_mutex_destroy(&create_mutex1);
   770     pthread_mutex_destroy(&create_mutex1);
   763     pthread_cond_destroy(&(create_condition1));
   771     pthread_cond_destroy(&(create_condition1));
   764 
   772 
   765     g_free(src->device);
   773     g_free(src->device);
       
   774     src->device = NULL;
   766     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_stop EXIT ");
   775     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_stop EXIT ");
   767     return TRUE;
   776     return TRUE;
   768     }
   777     }
   769 
   778 
   770 static gboolean gst_devsound_src_unlock(GstBaseSrc * bsrc)
   779 static gboolean gst_devsound_src_unlock(GstBaseSrc * bsrc)
   903                 {
   912                 {
   904                 gst_buffer_unref(popBuffer);
   913                 gst_buffer_unref(popBuffer);
   905                 popBuffer = NULL;
   914                 popBuffer = NULL;
   906                 }
   915                 }
   907             }
   916             }
       
   917             if( dsrc->firstimecreatecalled < 2 )
       
   918             {/// nitin changes
       
   919                 ++dsrc->firstimecreatecalled;
       
   920                 return GST_FLOW_OK;
       
   921             }
   908         }
   922         }
   909     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create EXIT ",NULL);
   923     //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create EXIT ",NULL);
   910     return GST_FLOW_OK;
   924     return GST_FLOW_OK;
   911     }
   925     }
   912 
   926