392 //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); |
393 devsoundsrc->device = g_strdup(DEFAULT_DEVICE); |
393 devsoundsrc->device = g_strdup(DEFAULT_DEVICE); |
394 devsoundsrc->handle=NULL; |
394 devsoundsrc->handle=NULL; |
395 devsoundsrc->preference = 0; //default=>EMdaPriorityPreferenceNone; |
395 devsoundsrc->preference = 0; //default=>EMdaPriorityPreferenceNone; |
396 devsoundsrc->priority = 0; //default=>EMdaPriorityNormal; |
396 devsoundsrc->priority = 0; //default=>EMdaPriorityNormal; |
397 devsoundsrc->firstimecreatecalled = 0; |
397 devsoundsrc->firstTimeInit = kUnInitialized; |
398 // pthread_mutex_init(&create_mutex1, NULL); |
398 // pthread_mutex_init(&create_mutex1, NULL); |
399 // pthread_cond_init(&create_condition1, NULL); |
399 // pthread_cond_init(&create_condition1, NULL); |
400 //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); |
401 } |
401 } |
402 |
402 |
498 pthread_mutex_lock(&(create_mutex1)); |
498 pthread_mutex_lock(&(create_mutex1)); |
499 pthread_cond_signal(&(create_condition1)); |
499 pthread_cond_signal(&(create_condition1)); |
500 pthread_mutex_unlock(&(create_mutex1)); |
500 pthread_mutex_unlock(&(create_mutex1)); |
501 // TODO obtain mutex here |
501 // TODO obtain mutex here |
502 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED; |
502 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED; |
503 devsoundsrc->firstimecreatecalled = 0; |
|
504 pthread_exit(NULL); |
503 pthread_exit(NULL); |
505 } |
504 } |
506 break; |
505 break; |
507 default: |
506 default: |
508 // TODO obtain mutex here |
507 // TODO obtain mutex here |
770 pthread_mutex_destroy(&create_mutex1); |
769 pthread_mutex_destroy(&create_mutex1); |
771 pthread_cond_destroy(&(create_condition1)); |
770 pthread_cond_destroy(&(create_condition1)); |
772 |
771 |
773 g_free(src->device); |
772 g_free(src->device); |
774 src->device = NULL; |
773 src->device = NULL; |
|
774 src->firstTimeInit = kUnInitialized; |
775 //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 "); |
776 return TRUE; |
776 return TRUE; |
777 } |
777 } |
778 |
778 |
779 static gboolean gst_devsound_src_unlock(GstBaseSrc * bsrc) |
779 static gboolean gst_devsound_src_unlock(GstBaseSrc * bsrc) |
880 GST_OBJECT_LOCK(dsrc); |
880 GST_OBJECT_LOCK(dsrc); |
881 popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue); |
881 popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue); |
882 GST_OBJECT_UNLOCK(dsrc); |
882 GST_OBJECT_UNLOCK(dsrc); |
883 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER POP in CREATE ",NULL); |
883 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER POP in CREATE ",NULL); |
884 if(!popBuffer) |
884 if(!popBuffer) |
885 { |
885 { |
886 return GST_FLOW_UNEXPECTED; |
886 return GST_FLOW_UNEXPECTED; |
|
887 } |
|
888 if(dsrc->firstTimeInit != kPlayed) |
|
889 { |
|
890 dsrc->prevbuffersize = gst_base_src_get_blocksize(src); |
|
891 gst_base_src_set_blocksize (src, GST_BUFFER_SIZE(popBuffer)); |
|
892 (*buf)->size = GST_BUFFER_SIZE(popBuffer); |
887 } |
893 } |
888 // copy the data from the popped buffer based on how much of the incoming |
894 // copy the data from the popped buffer based on how much of the incoming |
889 //buffer size is left to fill. we might have filled the fresh buffer somewhat |
895 //buffer size is left to fill. we might have filled the fresh buffer somewhat |
890 // where the size of the fresh buffer is more then the data remaining in the |
896 // where the size of the fresh buffer is more then the data remaining in the |
891 // popped buffer. |
897 // popped buffer. |
912 { |
918 { |
913 gst_buffer_unref(popBuffer); |
919 gst_buffer_unref(popBuffer); |
914 popBuffer = NULL; |
920 popBuffer = NULL; |
915 } |
921 } |
916 } |
922 } |
917 if( dsrc->firstimecreatecalled < 2 ) |
923 if (dsrc->firstTimeInit == kPlayBufferPreRoll) |
918 {/// nitin changes |
924 { |
919 ++dsrc->firstimecreatecalled; |
925 gst_base_src_set_blocksize (src, dsrc->prevbuffersize); |
920 return GST_FLOW_OK; |
926 dsrc->firstTimeInit = kPlayed; |
|
927 return GST_FLOW_OK; |
921 } |
928 } |
922 } |
929 |
|
930 if (dsrc->firstTimeInit == kPausedToPlaying) |
|
931 { |
|
932 dsrc->firstTimeInit = kPlayBufferPreRoll; |
|
933 return GST_FLOW_OK; |
|
934 } |
|
935 } |
923 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create EXIT ",NULL); |
936 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create EXIT ",NULL); |
924 return GST_FLOW_OK; |
937 return GST_FLOW_OK; |
925 } |
938 } |
926 |
939 |
927 |
940 |
928 static GstStateChangeReturn gst_devsound_src_change_state (GstElement * element, |
941 static GstStateChangeReturn gst_devsound_src_change_state (GstElement * element, |
929 GstStateChange transition) |
942 GstStateChange transition) |
930 { |
943 { |
931 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; |
944 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; |
932 GstDevsoundSrc *src= GST_DEVSOUND_SRC (element); |
945 GstDevsoundSrc *src= GST_DEVSOUND_SRC (element); |
933 |
946 |
934 switch (transition) { |
947 switch (transition) { |
935 |
948 |
936 case GST_STATE_CHANGE_PAUSED_TO_PLAYING: |
949 case GST_STATE_CHANGE_PAUSED_TO_PLAYING: |
|
950 if (src->firstTimeInit != kPlayed) |
|
951 src->firstTimeInit = kPausedToPlaying; |
937 if(cmd == PAUSE) |
952 if(cmd == PAUSE) |
938 { |
953 { |
939 cmd = RESUME; |
954 cmd = RESUME; |
940 pthread_mutex_lock(&create_mutex1); |
955 pthread_mutex_lock(&create_mutex1); |
941 pthread_cond_signal(&create_condition1); |
956 pthread_cond_signal(&create_condition1); |