90 GList** aSupportedBitrates); |
91 GList** aSupportedBitrates); |
91 static gint gst_get_speech_encoder_vad_mode(gboolean* aVadMode); |
92 static gint gst_get_speech_encoder_vad_mode(gboolean* aVadMode); |
92 static gint gst_set_speech_encoder_bit_rate(guint aBitrate); |
93 static gint gst_set_speech_encoder_bit_rate(guint aBitrate); |
93 static gint gst_set_speech_encoder_vad_mode(gboolean aVadMode); |
94 static gint gst_set_speech_encoder_vad_mode(gboolean aVadMode); |
94 static void gst_Apply_SpeechEncoder_Update(GstDevsoundSrc *devsoundsrc ); |
95 static void gst_Apply_SpeechEncoder_Update(GstDevsoundSrc *devsoundsrc ); |
95 |
96 static void gst_update_devsound_speech_bitrate(GstDevsoundSrc *devsoundsrc ); |
96 |
97 |
97 /************************* |
98 /************************* |
98 * G711 Encoder Interface |
99 * G711 Encoder Interface |
99 * ***********************/ |
100 * ***********************/ |
100 static void gst_g711_encoder_handler_init(gpointer g_iface, |
101 static void gst_g711_encoder_handler_init(gpointer g_iface, |
211 GST_STATIC_CAPS ("audio/x-raw-int, " |
212 GST_STATIC_CAPS ("audio/x-raw-int, " |
212 "endianness = (int) { " G_STRINGIFY (G_BYTE_ORDER) " }, " |
213 "endianness = (int) { " G_STRINGIFY (G_BYTE_ORDER) " }, " |
213 "signed = (boolean) TRUE, " |
214 "signed = (boolean) TRUE, " |
214 "width = (int) 16, " |
215 "width = (int) 16, " |
215 "depth = (int) 16, " |
216 "depth = (int) 16, " |
216 "rate = (int) [ 8000, 48000 ]," |
217 "rate = (int) { 8000, 16000, 24000, 32000, 48000 }," |
217 "channels = (int) [ 1, 2 ]; " |
218 "channels = (int) [ 1, 2 ]; " |
218 "audio/amr, " |
219 "audio/amr, " |
219 "rate = (int) [ 8000, 48000 ], " |
220 "rate = (int) 8000, " |
220 "channels = (int) [ 1, 2 ]; " |
221 "channels = (int) [ 1, 2 ]; ") |
221 "audio/x-alaw, " |
|
222 "rate = (int) [ 8000, 48000 ], " |
|
223 "channels = (int) [ 1, 2 ]; " |
|
224 "audio/g729, " |
|
225 "rate = (int) [ 8000, 48000 ], " |
|
226 "channels = (int) [ 1, 2 ]; " |
|
227 "audio/ilbc, " |
|
228 "rate = (int) [ 8000, 48000 ], " |
|
229 "channels = (int) [ 1, 2 ]; " |
|
230 "audio/x-mulaw, " |
|
231 "rate = (int) [ 8000, 48000 ], " |
|
232 "channels = (int) [ 1, 2 ]") |
|
233 ); |
222 ); |
234 |
223 |
235 static GstElementClass *parent_class= NULL; |
224 static GstElementClass *parent_class= NULL; |
236 |
225 |
237 static void gst_devsound_src_base_init(gpointer g_class) |
226 static void gst_devsound_src_base_init(gpointer g_class) |
405 GstDevsoundSrc *devsoundsrc= GST_DEVSOUND_SRC (threadarg); |
394 GstDevsoundSrc *devsoundsrc= GST_DEVSOUND_SRC (threadarg); |
406 int buffersize; |
395 int buffersize; |
407 TUint8* gBuffer; |
396 TUint8* gBuffer; |
408 GstBuffer* pushBuffer= NULL; |
397 GstBuffer* pushBuffer= NULL; |
409 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "StartDevSoundThread ",NULL); |
398 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "StartDevSoundThread ",NULL); |
410 open_devsound(&(devsoundsrc->handle)); |
399 int ret = open_devsound(&(devsoundsrc->handle)); |
|
400 |
|
401 if( 0 != ret ) |
|
402 { |
|
403 pthread_mutex_lock(&(create_mutex1)); |
|
404 return_error = ret; |
|
405 pthread_cond_signal(&(create_condition1)); |
|
406 pthread_mutex_unlock(&(create_mutex1)); |
|
407 //return_error = ret; |
|
408 pthread_exit(NULL); |
|
409 } |
411 |
410 |
412 getsupporteddatatypes(devsoundsrc); |
411 getsupporteddatatypes(devsoundsrc); |
413 |
412 |
414 // TODO obtain mutex to update variable here??? |
413 // TODO obtain mutex to update variable here??? |
415 consumer_thread_state = CONSUMER_THREAD_INITIALIZED; |
414 consumer_thread_state = CONSUMER_THREAD_INITIALIZED; |
417 //pre_init_setconf(devsoundsrc); |
416 //pre_init_setconf(devsoundsrc); |
418 |
417 |
419 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Record Init ",NULL); |
418 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Record Init ",NULL); |
420 |
419 |
421 pthread_mutex_lock(&(create_mutex1)); |
420 pthread_mutex_lock(&(create_mutex1)); |
|
421 return_error = ret; |
422 pthread_cond_signal(&(create_condition1)); |
422 pthread_cond_signal(&(create_condition1)); |
423 pthread_mutex_unlock(&(create_mutex1)); |
423 pthread_mutex_unlock(&(create_mutex1)); |
424 |
424 |
425 // Wait until we receive a command from the main thread |
425 // Wait until we receive a command from the main thread |
426 // TODO obtain mutex to read variable here??? |
426 // TODO obtain mutex to read variable here??? |
433 |
433 |
434 // This could happen if client creates sink and deletes it |
434 // This could happen if client creates sink and deletes it |
435 // without putting it to play state |
435 // without putting it to play state |
436 if ( cmd != CLOSE ) |
436 if ( cmd != CLOSE ) |
437 { |
437 { |
438 initialize_devsound(devsoundsrc); |
438 gst_update_devsound_speech_bitrate(devsoundsrc); |
439 |
439 ret = initialize_devsound(devsoundsrc); |
440 recordinit(devsoundsrc->handle); |
440 if( 0 == ret ) |
441 initproperties(devsoundsrc); |
441 { |
|
442 ret = recordinit(devsoundsrc->handle); |
|
443 if( 0 == ret ) |
|
444 initproperties(devsoundsrc); |
|
445 |
|
446 } |
|
447 /// if initialization of devsound failed, return error, |
|
448 /// on return other thread will send CLOSE cmd to exit from thread. |
|
449 if( ret ) |
|
450 { |
|
451 pthread_mutex_lock(&(create_mutex1)); |
|
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 } |
442 } |
460 } |
443 |
461 |
444 while (TRUE) |
462 while (TRUE) |
445 { |
463 { |
446 switch (cmd) |
464 switch (cmd) |
508 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED; |
526 consumer_thread_state = CONSUMER_THREAD_UNINITIALIZED; |
509 pthread_exit(NULL); |
527 pthread_exit(NULL); |
510 break; |
528 break; |
511 } |
529 } |
512 pthread_mutex_lock(&(create_mutex1)); |
530 pthread_mutex_lock(&(create_mutex1)); |
|
531 return_error = call_back_error(devsoundsrc->handle); |
513 pthread_cond_signal(&(create_condition1)); |
532 pthread_cond_signal(&(create_condition1)); |
514 pthread_mutex_unlock(&(create_mutex1)); |
533 pthread_mutex_unlock(&(create_mutex1)); |
515 |
534 |
516 pthread_mutex_lock(&create_mutex1); |
535 pthread_mutex_lock(&create_mutex1); |
517 pthread_cond_wait(&create_condition1, &create_mutex1); |
536 pthread_cond_wait(&create_condition1, &create_mutex1); |
685 } |
704 } |
686 |
705 |
687 static gboolean gst_devsound_src_start(GstBaseSrc * bsrc) |
706 static gboolean gst_devsound_src_start(GstBaseSrc * bsrc) |
688 { |
707 { |
689 GstBuffer *tmp_gstbuffer=NULL; |
708 GstBuffer *tmp_gstbuffer=NULL; |
|
709 gboolean ret = TRUE; |
690 GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc); |
710 GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc); |
691 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start ENTER ",NULL); |
711 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start ENTER ",NULL); |
692 pthread_mutex_init(&create_mutex1, NULL); |
712 pthread_mutex_init(&create_mutex1, NULL); |
693 pthread_cond_init(&create_condition1, NULL); |
713 pthread_cond_init(&create_condition1, NULL); |
694 |
714 |
708 dataqueue = g_queue_new(); |
728 dataqueue = g_queue_new(); |
709 } |
729 } |
710 |
730 |
711 consumer_thread_state = CONSUMER_THREAD_INITIALIZING; |
731 consumer_thread_state = CONSUMER_THREAD_INITIALIZING; |
712 cmd = OPEN; |
732 cmd = OPEN; |
|
733 return_error = 0; |
713 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Thread Create ",NULL); |
734 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Thread Create ",NULL); |
714 pthread_create(&ds_thread, NULL, StartDevSoundThread, (void *)src); |
735 pthread_create(&ds_thread, NULL, StartDevSoundThread, (void *)src); |
715 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "After Thread Create ",NULL); |
736 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "After Thread Create ",NULL); |
716 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Mutex Wait in START ",NULL); |
737 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "Before Mutex Wait in START ",NULL); |
717 if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING) |
738 if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING) |
718 { |
739 { |
719 pthread_mutex_lock(&create_mutex1); |
740 pthread_mutex_lock(&create_mutex1); |
720 pthread_cond_wait(&create_condition1, &create_mutex1); |
741 pthread_cond_wait(&create_condition1, &create_mutex1); |
|
742 ret = !return_error; // should be TRUE on no Error, and FALSE at ERROR. |
721 pthread_mutex_unlock(&create_mutex1); |
743 pthread_mutex_unlock(&create_mutex1); |
722 } |
744 } |
723 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "AFter Mutex Wait in START ",NULL); |
745 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "AFter Mutex Wait in START ",NULL); |
724 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start EXIT ",NULL); |
746 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_start EXIT ",NULL); |
725 return TRUE; |
747 return ret; |
726 /* ERRORS */ |
748 /* ERRORS */ |
727 } |
749 } |
728 |
750 |
729 static gboolean gst_devsound_src_stop(GstBaseSrc * bsrc) |
751 static gboolean gst_devsound_src_stop(GstBaseSrc * bsrc) |
730 { |
752 { |
798 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset, |
820 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset, |
799 guint size, GstBuffer **buf) |
821 guint size, GstBuffer **buf) |
800 { |
822 { |
801 GstDevsoundSrc *dsrc= GST_DEVSOUND_SRC(src); |
823 GstDevsoundSrc *dsrc= GST_DEVSOUND_SRC(src); |
802 int bufferpos=0; |
824 int bufferpos=0; |
|
825 int ret = 0; |
803 |
826 |
804 if(!g_queue_get_length(dataqueue) && (dsrc->eosreceived == TRUE)) |
827 if(!g_queue_get_length(dataqueue) && (dsrc->eosreceived == TRUE)) |
805 { |
828 { |
806 pthread_mutex_lock(&(create_mutex1)); |
829 pthread_mutex_lock(&(create_mutex1)); |
807 pthread_cond_signal(&(create_condition1)); |
830 pthread_cond_signal(&(create_condition1)); |
863 return GST_FLOW_UNEXPECTED; |
886 return GST_FLOW_UNEXPECTED; |
864 } |
887 } |
865 else |
888 else |
866 { |
889 { |
867 cmd = RECORDING; |
890 cmd = RECORDING; |
|
891 return_error = 0; |
868 pthread_mutex_lock(&(create_mutex1)); |
892 pthread_mutex_lock(&(create_mutex1)); |
869 pthread_cond_signal(&(create_condition1)); |
893 pthread_cond_signal(&(create_condition1)); |
870 pthread_mutex_unlock(&(create_mutex1)); |
894 pthread_mutex_unlock(&(create_mutex1)); |
871 |
895 |
872 pthread_mutex_lock(&(create_mutex1)); |
896 pthread_mutex_lock(&(create_mutex1)); |
873 pthread_cond_wait(&(create_condition1), &(create_mutex1)); |
897 pthread_cond_wait(&(create_condition1), &(create_mutex1)); |
|
898 ret = return_error; |
874 pthread_mutex_unlock(&(create_mutex1)); |
899 pthread_mutex_unlock(&(create_mutex1)); |
875 } |
900 } |
876 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER WAIT in CREATE ",NULL); |
901 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER WAIT in CREATE ",NULL); |
877 } |
902 } |
878 |
903 if( KErrInUse == ret || KErrDied == ret || KErrAccessDenied == ret ) |
|
904 { |
|
905 // post error as pre-emption |
|
906 GST_ELEMENT_ERROR (src, RESOURCE, BUSY, |
|
907 (("Pre-emption error.")), |
|
908 ("streaming paused because higher priority app requested resource, Err(%d)", ret)); |
|
909 |
|
910 return GST_FLOW_UNEXPECTED; |
|
911 } |
|
912 else if( KErrNone != ret ) |
|
913 { |
|
914 // no need to post error as base src will post error. |
|
915 return GST_FLOW_ERROR; |
|
916 } |
879 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before POP in CREATE ",NULL); |
917 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before POP in CREATE ",NULL); |
880 GST_OBJECT_LOCK(dsrc); |
918 GST_OBJECT_LOCK(dsrc); |
881 popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue); |
919 popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue); |
882 GST_OBJECT_UNLOCK(dsrc); |
920 GST_OBJECT_UNLOCK(dsrc); |
883 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER POP in CREATE ",NULL); |
921 |
884 if(!popBuffer) |
922 if(!popBuffer ) |
885 { |
923 { |
886 return GST_FLOW_UNEXPECTED; |
924 return GST_FLOW_UNEXPECTED; |
887 } |
925 } |
888 if(dsrc->firstTimeInit != kPlayed) |
926 if(dsrc->firstTimeInit != kPlayed) |
889 { |
927 { |
890 dsrc->prevbuffersize = gst_base_src_get_blocksize(src); |
928 dsrc->prevbuffersize = gst_base_src_get_blocksize(src); |
891 gst_base_src_set_blocksize (src, GST_BUFFER_SIZE(popBuffer)); |
929 gst_base_src_set_blocksize (src, GST_BUFFER_SIZE(popBuffer)); |
892 (*buf)->size = GST_BUFFER_SIZE(popBuffer); |
930 (*buf)->size = GST_BUFFER_SIZE(popBuffer); |
950 if (src->firstTimeInit != kPlayed) |
988 if (src->firstTimeInit != kPlayed) |
951 src->firstTimeInit = kPausedToPlaying; |
989 src->firstTimeInit = kPausedToPlaying; |
952 if(cmd == PAUSE) |
990 if(cmd == PAUSE) |
953 { |
991 { |
954 cmd = RESUME; |
992 cmd = RESUME; |
|
993 return_error = 0; |
955 pthread_mutex_lock(&create_mutex1); |
994 pthread_mutex_lock(&create_mutex1); |
956 pthread_cond_signal(&create_condition1); |
995 pthread_cond_signal(&create_condition1); |
957 pthread_mutex_unlock(&create_mutex1); |
996 pthread_mutex_unlock(&create_mutex1); |
958 |
997 |
959 pthread_mutex_lock(&create_mutex1); |
998 pthread_mutex_lock(&create_mutex1); |
960 pthread_cond_wait(&create_condition1, &create_mutex1); |
999 pthread_cond_wait(&create_condition1, &create_mutex1); |
|
1000 if( return_error ) |
|
1001 ret = GST_STATE_CHANGE_FAILURE; |
961 pthread_mutex_unlock(&create_mutex1); |
1002 pthread_mutex_unlock(&create_mutex1); |
962 } |
1003 } |
963 break; |
1004 break; |
964 default: |
1005 default: |
965 break; |
1006 break; |
971 |
1012 |
972 switch (transition) { |
1013 switch (transition) { |
973 |
1014 |
974 case GST_STATE_CHANGE_PLAYING_TO_PAUSED: |
1015 case GST_STATE_CHANGE_PLAYING_TO_PAUSED: |
975 cmd = PAUSE; |
1016 cmd = PAUSE; |
|
1017 return_error = 0; |
976 pthread_mutex_lock(&create_mutex1); |
1018 pthread_mutex_lock(&create_mutex1); |
977 pthread_cond_signal(&create_condition1); |
1019 pthread_cond_signal(&create_condition1); |
978 pthread_mutex_unlock(&create_mutex1); |
1020 pthread_mutex_unlock(&create_mutex1); |
979 |
1021 |
980 pthread_mutex_lock(&create_mutex1); |
1022 pthread_mutex_lock(&create_mutex1); |
981 pthread_cond_wait(&create_condition1, &create_mutex1); |
1023 pthread_cond_wait(&create_condition1, &create_mutex1); |
|
1024 if( return_error ) |
|
1025 ret = GST_STATE_CHANGE_FAILURE; |
982 pthread_mutex_unlock(&create_mutex1); |
1026 pthread_mutex_unlock(&create_mutex1); |
983 break; |
1027 break; |
984 default: |
1028 default: |
985 break; |
1029 break; |
986 } |
1030 } |
1050 speechvadmode = aVadMode; |
1094 speechvadmode = aVadMode; |
1051 customInfaceUpdate.speechvadmodeupdate = TRUE; |
1095 customInfaceUpdate.speechvadmodeupdate = TRUE; |
1052 return 0; |
1096 return 0; |
1053 } |
1097 } |
1054 |
1098 |
1055 |
1099 static void gst_update_devsound_speech_bitrate(GstDevsoundSrc *devsoundsrc ) |
|
1100 { |
|
1101 if(customInfaceUpdate.speechbitrateupdate == TRUE) |
|
1102 { |
|
1103 update_devsound_speech_bitrate(devsoundsrc->handle,speechbitrate); |
|
1104 customInfaceUpdate.speechbitrateupdate = FALSE; |
|
1105 } |
|
1106 } |
1056 static void gst_Apply_SpeechEncoder_Update(GstDevsoundSrc *devsoundsrc ) |
1107 static void gst_Apply_SpeechEncoder_Update(GstDevsoundSrc *devsoundsrc ) |
1057 { |
1108 { |
1058 if(customInfaceUpdate.speechbitrateupdate == TRUE) |
1109 if(customInfaceUpdate.speechbitrateupdate == TRUE) |
1059 { |
1110 { |
1060 set_speech_encoder_bit_rate(devsoundsrc->handle,speechbitrate); |
1111 set_speech_encoder_bit_rate(devsoundsrc->handle,speechbitrate); |
1249 case GST_EVENT_EOS: |
1300 case GST_EVENT_EOS: |
1250 // end-of-stream, we should close down all stream leftovers here |
1301 // end-of-stream, we should close down all stream leftovers here |
1251 //reset_devsound(sink->handle); |
1302 //reset_devsound(sink->handle); |
1252 src->eosreceived = TRUE; |
1303 src->eosreceived = TRUE; |
1253 cmd = STOP; |
1304 cmd = STOP; |
|
1305 return_error = 0; |
1254 pthread_mutex_lock(&create_mutex1); |
1306 pthread_mutex_lock(&create_mutex1); |
1255 pthread_cond_signal(&create_condition1); |
1307 pthread_cond_signal(&create_condition1); |
1256 pthread_mutex_unlock(&create_mutex1); |
1308 pthread_mutex_unlock(&create_mutex1); |
1257 |
1309 |
1258 pthread_mutex_lock(&create_mutex1); |
1310 pthread_mutex_lock(&create_mutex1); |