396 TUint8* gBuffer; |
397 TUint8* gBuffer; |
397 GstBuffer* pushBuffer= NULL; |
398 GstBuffer* pushBuffer= NULL; |
398 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "StartDevSoundThread ",NULL); |
399 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "StartDevSoundThread ",NULL); |
399 int ret = open_devsound(&(devsoundsrc->handle)); |
400 int ret = open_devsound(&(devsoundsrc->handle)); |
400 |
401 |
401 if( 0 != ret ) |
402 if( KErrNone != ret ) |
402 { |
403 { |
403 pthread_mutex_lock(&(create_mutex1)); |
404 pthread_mutex_lock(&(create_mutex1)); |
404 return_error = ret; |
405 return_error = ret; |
405 pthread_cond_signal(&(create_condition1)); |
406 pthread_cond_signal(&(create_condition1)); |
406 pthread_mutex_unlock(&(create_mutex1)); |
407 pthread_mutex_unlock(&(create_mutex1)); |
407 //return_error = ret; |
|
408 pthread_exit(NULL); |
408 pthread_exit(NULL); |
409 } |
409 } |
410 |
410 |
411 getsupporteddatatypes(devsoundsrc); |
411 getsupporteddatatypes(devsoundsrc); |
412 |
412 |
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 gst_update_devsound_speech_bitrate(devsoundsrc); |
438 gst_update_devsound_speech_bitrate(devsoundsrc); |
439 ret = initialize_devsound(devsoundsrc); |
439 ret = initialize_devsound(devsoundsrc); |
440 if( 0 == ret ) |
440 if( KErrNone == ret ) |
441 { |
441 { |
442 ret = recordinit(devsoundsrc->handle); |
442 ret = recordinit(devsoundsrc->handle); |
443 if( 0 == ret ) |
443 if( KErrNone == ret ) |
444 initproperties(devsoundsrc); |
444 initproperties(devsoundsrc); |
445 |
445 |
446 } |
446 } |
447 /// if initialization of devsound failed, return error, |
447 /// if initialization of devsound failed, return error, |
448 /// on return other thread will send CLOSE cmd to exit from thread. |
448 /// on return other thread will send CLOSE cmd to exit from thread. |
728 dataqueue = g_queue_new(); |
728 dataqueue = g_queue_new(); |
729 } |
729 } |
730 |
730 |
731 consumer_thread_state = CONSUMER_THREAD_INITIALIZING; |
731 consumer_thread_state = CONSUMER_THREAD_INITIALIZING; |
732 cmd = OPEN; |
732 cmd = OPEN; |
733 return_error = 0; |
733 return_error = KErrNone; |
734 //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); |
735 pthread_create(&ds_thread, NULL, StartDevSoundThread, (void *)src); |
735 pthread_create(&ds_thread, NULL, StartDevSoundThread, (void *)src); |
736 //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); |
737 //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); |
738 if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING) |
738 if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING) |
742 ret = !return_error; // should be TRUE on no Error, and FALSE at ERROR. |
742 ret = !return_error; // should be TRUE on no Error, and FALSE at ERROR. |
743 pthread_mutex_unlock(&create_mutex1); |
743 pthread_mutex_unlock(&create_mutex1); |
744 } |
744 } |
745 //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); |
746 //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); |
747 return ret; |
747 if ( return_error ) |
|
748 post_symbian_error( bsrc,return_error ); |
|
749 return ret; |
748 /* ERRORS */ |
750 /* ERRORS */ |
749 } |
751 } |
750 |
752 |
751 static gboolean gst_devsound_src_stop(GstBaseSrc * bsrc) |
753 static gboolean gst_devsound_src_stop(GstBaseSrc * bsrc) |
752 { |
754 { |
753 |
755 |
754 GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc); |
756 GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc); |
755 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_stop ENTER "); |
757 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) src, "gst_devsound_src_stop ENTER "); |
756 cmd = CLOSE; |
758 cmd = CLOSE; |
757 |
|
758 pthread_mutex_lock(&(create_mutex1)); |
759 pthread_mutex_lock(&(create_mutex1)); |
759 pthread_cond_signal(&(create_condition1)); |
760 pthread_cond_signal(&(create_condition1)); |
760 pthread_mutex_unlock(&(create_mutex1)); |
761 pthread_mutex_unlock(&(create_mutex1)); |
761 //GST_OBJECT_LOCK (src); |
762 //GST_OBJECT_LOCK (src); |
762 pthread_mutex_lock(&(create_mutex1)); |
763 pthread_mutex_lock(&(create_mutex1)); |
820 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset, |
821 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset, |
821 guint size, GstBuffer **buf) |
822 guint size, GstBuffer **buf) |
822 { |
823 { |
823 GstDevsoundSrc *dsrc= GST_DEVSOUND_SRC(src); |
824 GstDevsoundSrc *dsrc= GST_DEVSOUND_SRC(src); |
824 int bufferpos=0; |
825 int bufferpos=0; |
825 int ret = 0; |
826 int ret = KErrNone; |
826 |
827 |
827 if(!g_queue_get_length(dataqueue) && (dsrc->eosreceived == TRUE)) |
828 if(!g_queue_get_length(dataqueue) && (dsrc->eosreceived == TRUE)) |
828 { |
829 { |
829 pthread_mutex_lock(&(create_mutex1)); |
830 pthread_mutex_lock(&(create_mutex1)); |
830 pthread_cond_signal(&(create_condition1)); |
831 pthread_cond_signal(&(create_condition1)); |
831 pthread_mutex_unlock(&(create_mutex1)); |
832 pthread_mutex_unlock(&(create_mutex1)); |
832 |
833 post_symbian_error( src,KErrCancel ); |
833 return GST_FLOW_UNEXPECTED; |
834 return GST_FLOW_UNEXPECTED; |
834 } |
835 } |
835 |
836 |
836 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create ENTER "); |
837 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create ENTER "); |
837 |
838 |
838 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before Buffer Alloc in CREATE ",NULL); |
839 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before Buffer Alloc in CREATE ",NULL); |
839 *buf = gst_buffer_try_new_and_alloc(size); |
840 *buf = gst_buffer_try_new_and_alloc(size); |
840 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFter Buffer Alloc in CREATE ",NULL); |
841 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFter Buffer Alloc in CREATE ",NULL); |
841 |
842 if(*buf == NULL) |
|
843 { |
|
844 post_symbian_error( src,KErrNoMemory ); |
|
845 return GST_FLOW_UNEXPECTED; |
|
846 } |
|
847 |
842 while (size > 0) |
848 while (size > 0) |
843 { |
849 { |
844 if (dataleft >= size) |
850 if (dataleft >= size) |
845 { |
851 { |
846 // if there is some data left in the popped buffer previously whose size |
852 // if there is some data left in the popped buffer previously whose size |
881 if (!g_queue_get_length(dataqueue)) |
887 if (!g_queue_get_length(dataqueue)) |
882 { |
888 { |
883 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before WAIT in CREATE ",NULL); |
889 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before WAIT in CREATE ",NULL); |
884 if(dsrc->eosreceived == TRUE) |
890 if(dsrc->eosreceived == TRUE) |
885 { |
891 { |
|
892 post_symbian_error( src,KErrCancel ); |
886 return GST_FLOW_UNEXPECTED; |
893 return GST_FLOW_UNEXPECTED; |
887 } |
894 } |
888 else |
895 else |
889 { |
896 { |
890 cmd = RECORDING; |
897 cmd = RECORDING; |
891 return_error = 0; |
898 return_error = KErrNone; |
892 pthread_mutex_lock(&(create_mutex1)); |
899 pthread_mutex_lock(&(create_mutex1)); |
893 pthread_cond_signal(&(create_condition1)); |
900 pthread_cond_signal(&(create_condition1)); |
894 pthread_mutex_unlock(&(create_mutex1)); |
901 pthread_mutex_unlock(&(create_mutex1)); |
895 |
902 |
896 pthread_mutex_lock(&(create_mutex1)); |
903 pthread_mutex_lock(&(create_mutex1)); |
898 ret = return_error; |
905 ret = return_error; |
899 pthread_mutex_unlock(&(create_mutex1)); |
906 pthread_mutex_unlock(&(create_mutex1)); |
900 } |
907 } |
901 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER WAIT in CREATE ",NULL); |
908 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER WAIT in CREATE ",NULL); |
902 } |
909 } |
903 if( KErrInUse == ret || KErrDied == ret || KErrAccessDenied == ret ) |
910 if( ret ) |
904 { |
911 { |
905 // post error as pre-emption |
912 post_symbian_error( src,ret ); |
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; |
913 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 } |
914 } |
917 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before POP in CREATE ",NULL); |
915 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "Before POP in CREATE ",NULL); |
918 GST_OBJECT_LOCK(dsrc); |
916 GST_OBJECT_LOCK(dsrc); |
919 popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue); |
917 popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue); |
920 GST_OBJECT_UNLOCK(dsrc); |
918 GST_OBJECT_UNLOCK(dsrc); |
921 |
919 |
922 if(!popBuffer ) |
920 if(!popBuffer ) |
923 { |
921 { |
924 return GST_FLOW_UNEXPECTED; |
922 post_symbian_error( src,KErrNoMemory ); |
|
923 return GST_FLOW_UNEXPECTED; |
925 } |
924 } |
926 if(dsrc->firstTimeInit != kPlayed) |
925 if(dsrc->firstTimeInit != kPlayed) |
927 { |
926 { |
928 dsrc->prevbuffersize = gst_base_src_get_blocksize(src); |
927 dsrc->prevbuffersize = gst_base_src_get_blocksize(src); |
929 gst_base_src_set_blocksize (src, GST_BUFFER_SIZE(popBuffer)); |
928 gst_base_src_set_blocksize (src, GST_BUFFER_SIZE(popBuffer)); |
988 if (src->firstTimeInit != kPlayed) |
987 if (src->firstTimeInit != kPlayed) |
989 src->firstTimeInit = kPausedToPlaying; |
988 src->firstTimeInit = kPausedToPlaying; |
990 if(cmd == PAUSE) |
989 if(cmd == PAUSE) |
991 { |
990 { |
992 cmd = RESUME; |
991 cmd = RESUME; |
993 return_error = 0; |
992 return_error = KErrNone; |
994 pthread_mutex_lock(&create_mutex1); |
993 pthread_mutex_lock(&create_mutex1); |
995 pthread_cond_signal(&create_condition1); |
994 pthread_cond_signal(&create_condition1); |
996 pthread_mutex_unlock(&create_mutex1); |
995 pthread_mutex_unlock(&create_mutex1); |
997 |
996 |
998 pthread_mutex_lock(&create_mutex1); |
997 pthread_mutex_lock(&create_mutex1); |
999 pthread_cond_wait(&create_condition1, &create_mutex1); |
998 pthread_cond_wait(&create_condition1, &create_mutex1); |
1000 if( return_error ) |
999 if( return_error ) |
|
1000 { |
|
1001 post_symbian_error( GST_BASE_SRC(element),return_error ); |
1001 ret = GST_STATE_CHANGE_FAILURE; |
1002 ret = GST_STATE_CHANGE_FAILURE; |
|
1003 } |
1002 pthread_mutex_unlock(&create_mutex1); |
1004 pthread_mutex_unlock(&create_mutex1); |
1003 } |
1005 } |
1004 break; |
1006 break; |
1005 default: |
1007 default: |
1006 break; |
1008 break; |
1012 |
1014 |
1013 switch (transition) { |
1015 switch (transition) { |
1014 |
1016 |
1015 case GST_STATE_CHANGE_PLAYING_TO_PAUSED: |
1017 case GST_STATE_CHANGE_PLAYING_TO_PAUSED: |
1016 cmd = PAUSE; |
1018 cmd = PAUSE; |
1017 return_error = 0; |
1019 return_error = KErrNone; |
1018 pthread_mutex_lock(&create_mutex1); |
1020 pthread_mutex_lock(&create_mutex1); |
1019 pthread_cond_signal(&create_condition1); |
1021 pthread_cond_signal(&create_condition1); |
1020 pthread_mutex_unlock(&create_mutex1); |
1022 pthread_mutex_unlock(&create_mutex1); |
1021 |
1023 |
1022 pthread_mutex_lock(&create_mutex1); |
1024 pthread_mutex_lock(&create_mutex1); |
1023 pthread_cond_wait(&create_condition1, &create_mutex1); |
1025 pthread_cond_wait(&create_condition1, &create_mutex1); |
1024 if( return_error ) |
1026 if( return_error ) |
1025 ret = GST_STATE_CHANGE_FAILURE; |
1027 { |
|
1028 post_symbian_error( GST_BASE_SRC(element),return_error ); |
|
1029 ret = GST_STATE_CHANGE_FAILURE; |
|
1030 } |
1026 pthread_mutex_unlock(&create_mutex1); |
1031 pthread_mutex_unlock(&create_mutex1); |
1027 break; |
1032 break; |
1028 default: |
1033 default: |
1029 break; |
1034 break; |
1030 } |
1035 } |
1326 break; |
1331 break; |
1327 } |
1332 } |
1328 |
1333 |
1329 return retValue; |
1334 return retValue; |
1330 } |
1335 } |
1331 |
1336 |
|
1337 static void |
|
1338 post_symbian_error ( GstBaseSrc* element, int symbian_error ) |
|
1339 { |
|
1340 switch (symbian_error) |
|
1341 { |
|
1342 |
|
1343 case KErrNone: |
|
1344 break; |
|
1345 case KErrNotFound: |
|
1346 GST_ELEMENT_ERROR (element, RESOURCE, NOT_FOUND, |
|
1347 (("resource not found error.")), |
|
1348 ("streaming paused because resource not found, Err(%d)", symbian_error)); |
|
1349 break; |
|
1350 case KErrCancel: |
|
1351 GST_ELEMENT_ERROR (element, RESOURCE, CLOSE, |
|
1352 (("resource request canceled.")), |
|
1353 ("streaming paused because resource request canceled, Err(%d)", symbian_error)); |
|
1354 break; |
|
1355 case KErrNoMemory: |
|
1356 GST_ELEMENT_ERROR (element, RESOURCE, NO_SPACE_LEFT, |
|
1357 (("Error out of memory")), |
|
1358 ("streaming paused because of no memory, Err(%d)", symbian_error)); |
|
1359 break; |
|
1360 case KErrNotSupported: |
|
1361 GST_ELEMENT_ERROR (element, RESOURCE, READ, |
|
1362 (("resource not supported.")), |
|
1363 ("streaming paused because resource not supported, Err(%d)", symbian_error)); |
|
1364 break; |
|
1365 case KErrNotReady: |
|
1366 GST_ELEMENT_ERROR (element, RESOURCE, TOO_LAZY, |
|
1367 (("resource is not ready for request.")), |
|
1368 ("streaming paused because resource is not ready, Err(%d)", symbian_error)); |
|
1369 break; |
|
1370 case KErrPermissionDenied: |
|
1371 GST_ELEMENT_ERROR (element, RESOURCE, READ, |
|
1372 (("Permission Denied.")), |
|
1373 ("streaming paused because permission denied, Err(%d)", symbian_error)); |
|
1374 break; |
|
1375 case KErrTimedOut: |
|
1376 GST_ELEMENT_ERROR (element, RESOURCE, TOO_LAZY, |
|
1377 (("Timed Out.")), |
|
1378 ("streaming paused because timed out, Err(%d)", symbian_error)); |
|
1379 break; |
|
1380 case KErrHardwareNotAvailable: |
|
1381 GST_ELEMENT_ERROR (element, RESOURCE, NOT_FOUND, |
|
1382 (("Hardware Not Available.")), |
|
1383 ("streaming paused because hardware not available, Err(%d)", symbian_error)); |
|
1384 break; |
|
1385 case KErrCorrupt: |
|
1386 GST_ELEMENT_ERROR (element, RESOURCE, FAILED, |
|
1387 (("Corrupted data.")), |
|
1388 ("streaming paused because of corrupted data, Err(%d)", symbian_error)); |
|
1389 break; |
|
1390 case KErrUnderflow: |
|
1391 GST_ELEMENT_ERROR (element, STREAM, FAILED, |
|
1392 (("Under flow.")), |
|
1393 ("streaming paused because of under flow, Err(%d)", symbian_error)); |
|
1394 break; |
|
1395 case KErrOverflow: |
|
1396 GST_ELEMENT_ERROR (element, STREAM, FAILED, |
|
1397 (("Over flow.")), |
|
1398 ("streaming paused because of over flow, Err(%d)", symbian_error)); |
|
1399 break; |
|
1400 |
|
1401 case KErrInUse: |
|
1402 GST_ELEMENT_ERROR (element, RESOURCE, BUSY, |
|
1403 (("Resource In Use.")), |
|
1404 ("streaming paused because resource in use, Err(%d)", symbian_error)); |
|
1405 break; |
|
1406 |
|
1407 case KErrDied: |
|
1408 GST_ELEMENT_ERROR (element, RESOURCE, BUSY, |
|
1409 (("Error Resource Died.")), |
|
1410 ("streaming paused because resource died., Err(%d)", symbian_error)); |
|
1411 break; |
|
1412 |
|
1413 case KErrAccessDenied: |
|
1414 GST_ELEMENT_ERROR (element, RESOURCE, BUSY, |
|
1415 (("Resource Access Denied.")), |
|
1416 ("streaming paused because resource access denied, Err(%d)", symbian_error)); |
|
1417 break; |
|
1418 |
|
1419 default: |
|
1420 GST_ELEMENT_ERROR (element, STREAM, FAILED, |
|
1421 (("internal data flow error.")), |
|
1422 ("streaming paused because of internal data flow error., Err(%d)", symbian_error)); |
|
1423 break; |
|
1424 } |
|
1425 } |
|
1426 |