317 |
319 |
318 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_devsound_src_dispose); |
320 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_devsound_src_dispose); |
319 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_devsound_src_get_property); |
321 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); |
322 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_devsound_src_set_property); |
321 |
323 |
|
324 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_devsound_src_change_state); |
|
325 |
322 g_object_class_install_property(gobject_class, PROP_DEVICE, |
326 g_object_class_install_property(gobject_class, PROP_DEVICE, |
323 g_param_spec_string("device", "Device", "Devsound device ", |
327 g_param_spec_string("device", "Device", "Devsound device ", |
324 DEFAULT_DEVICE, G_PARAM_READWRITE)); |
328 DEFAULT_DEVICE, (GParamFlags)G_PARAM_READWRITE)); |
325 |
329 |
326 g_object_class_install_property(gobject_class, GAIN, g_param_spec_int( |
330 g_object_class_install_property(gobject_class, GAIN, g_param_spec_int( |
327 "gain", "Gain", "Devsound src gain", -1, G_MAXINT, -1, |
331 "gain", "Gain", "Devsound src gain", -1, G_MAXINT, -1, |
328 G_PARAM_READWRITE)); |
332 (GParamFlags)G_PARAM_READWRITE)); |
329 |
333 |
330 g_object_class_install_property(gobject_class, MAXGAIN, g_param_spec_int( |
334 g_object_class_install_property(gobject_class, MAXGAIN, g_param_spec_int( |
331 "maxgain", "MaxGain", "Devsound src max gain", -1, G_MAXINT, -1, |
335 "maxgain", "MaxGain", "Devsound src max gain", -1, G_MAXINT, -1, |
332 G_PARAM_READABLE)); |
336 G_PARAM_READABLE)); |
333 |
337 |
334 g_object_class_install_property(gobject_class, LEFTBALANCE, |
338 g_object_class_install_property(gobject_class, LEFTBALANCE, |
335 g_param_spec_int("leftbalance", "Left Balance", "Left Balance", |
339 g_param_spec_int("leftbalance", "Left Balance", "Left Balance", |
336 -1, G_MAXINT, -1, G_PARAM_READWRITE)); |
340 -1, G_MAXINT, -1, (GParamFlags)G_PARAM_READWRITE)); |
337 |
341 |
338 g_object_class_install_property(gobject_class, RIGHTBALANCE, |
342 g_object_class_install_property(gobject_class, RIGHTBALANCE, |
339 g_param_spec_int("rightbalance", "Right Balance", |
343 g_param_spec_int("rightbalance", "Right Balance", |
340 "Right Balance", -1, G_MAXINT, -1, G_PARAM_READWRITE)); |
344 "Right Balance", -1, G_MAXINT, -1, (GParamFlags)G_PARAM_READWRITE)); |
341 |
345 |
342 g_object_class_install_property(gobject_class, SAMPLESRECORDED, |
346 g_object_class_install_property(gobject_class, SAMPLESRECORDED, |
343 g_param_spec_int("samplesrecorded", "Samples Recorded", |
347 g_param_spec_int("samplesrecorded", "Samples Recorded", |
344 "Samples Recorded", -1, G_MAXINT, -1, G_PARAM_READABLE)); |
348 "Samples Recorded", -1, G_MAXINT, -1, G_PARAM_READABLE)); |
345 |
349 |
346 g_object_class_install_property(gobject_class, PRIORITY, |
350 g_object_class_install_property(gobject_class, PRIORITY, |
347 g_param_spec_int("priority", "Priority", "Priority ", -1, |
351 g_param_spec_int("priority", "Priority", "Priority ", -1, |
348 G_MAXINT, -1, |
352 G_MAXINT, -1, |
349 G_PARAM_READWRITE)); |
353 (GParamFlags)G_PARAM_READWRITE)); |
350 |
354 |
351 g_object_class_install_property(gobject_class, PREFERENCE, |
355 g_object_class_install_property(gobject_class, PREFERENCE, |
352 g_param_spec_int("preference", "Preference", "Preference ", -1, |
356 g_param_spec_int("preference", "Preference", "Preference ", -1, |
353 G_MAXINT, -1, |
357 G_MAXINT, -1, |
354 G_PARAM_READWRITE)); |
358 (GParamFlags)G_PARAM_READWRITE)); |
355 |
359 |
356 g_object_class_install_property(gobject_class, RATE, |
360 g_object_class_install_property(gobject_class, RATE, |
357 g_param_spec_int("rate", "Rate", "Rate ", -1, |
361 g_param_spec_int("rate", "Rate", "Rate ", -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, CHANNELS, |
365 g_object_class_install_property(gobject_class, CHANNELS, |
362 g_param_spec_int("channels", "Channels", "Channels ", -1, |
366 g_param_spec_int("channels", "Channels", "Channels ", -1, |
363 G_MAXINT, -1, |
367 G_MAXINT, -1, |
364 G_PARAM_READWRITE)); |
368 (GParamFlags)G_PARAM_READWRITE)); |
|
369 |
365 gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_devsound_src_start); |
370 gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_devsound_src_start); |
366 gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_devsound_src_stop); |
371 gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_devsound_src_stop); |
367 gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_getcaps); |
372 gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_getcaps); |
368 gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_setcaps); |
373 gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_devsound_src_setcaps); |
369 |
374 gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_devsound_src_event); |
370 gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_devsound_src_create); |
375 gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_devsound_src_create); |
371 } |
376 } |
372 |
377 |
373 static void gst_devsound_src_init(GstDevsoundSrc * devsoundsrc) |
378 static void gst_devsound_src_init(GstDevsoundSrc * devsoundsrc) |
374 { |
379 { |
375 GST_DEBUG_OBJECT(devsoundsrc, "initializing devsoundsrc"); |
380 GST_DEBUG_OBJECT(devsoundsrc, "initializing devsoundsrc"); |
|
381 gst_base_src_set_live(GST_BASE_SRC(devsoundsrc), TRUE); |
376 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init ENTER ",NULL); |
382 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init ENTER ",NULL); |
377 devsoundsrc->device = g_strdup(DEFAULT_DEVICE); |
383 devsoundsrc->device = g_strdup(DEFAULT_DEVICE); |
378 devsoundsrc->handle=NULL; |
384 devsoundsrc->handle=NULL; |
379 devsoundsrc->preference = 0; //default=>EMdaPriorityPreferenceNone; |
385 devsoundsrc->preference = 0; //default=>EMdaPriorityPreferenceNone; |
380 devsoundsrc->priority = 0; //default=>EMdaPriorityNormal; |
386 devsoundsrc->priority = 0; //default=>EMdaPriorityNormal; |
381 pthread_mutex_init(&create_mutex1, NULL); |
387 devsoundsrc->firstTimeInit = kUnInitialized; |
382 pthread_cond_init(&create_condition1, NULL); |
388 // pthread_mutex_init(&create_mutex1, NULL); |
|
389 // pthread_cond_init(&create_condition1, NULL); |
383 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init EXIT ",NULL); |
390 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_init EXIT ",NULL); |
384 } |
391 } |
385 |
392 |
386 static void *StartDevSoundThread(void *threadarg) |
393 static void *StartDevSoundThread(void *threadarg) |
387 { |
394 { |
388 GstDevsoundSrc *devsoundsrc= GST_DEVSOUND_SRC (threadarg); |
395 GstDevsoundSrc *devsoundsrc= GST_DEVSOUND_SRC (threadarg); |
389 int buffersize; |
396 int buffersize; |
390 TUint8* gBuffer; |
397 TUint8* gBuffer; |
391 GstBuffer* pushBuffer= NULL; |
398 GstBuffer* pushBuffer= NULL; |
392 //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); |
393 open_devsound(&(devsoundsrc->handle)); |
400 int ret = open_devsound(&(devsoundsrc->handle)); |
|
401 |
|
402 if( KErrNone != ret ) |
|
403 { |
|
404 pthread_mutex_lock(&(create_mutex1)); |
|
405 return_error = ret; |
|
406 pthread_cond_signal(&(create_condition1)); |
|
407 pthread_mutex_unlock(&(create_mutex1)); |
|
408 pthread_exit(NULL); |
|
409 } |
394 |
410 |
395 getsupporteddatatypes(devsoundsrc); |
411 getsupporteddatatypes(devsoundsrc); |
396 |
412 |
397 // TODO obtain mutex to update variable here??? |
413 // TODO obtain mutex to update variable here??? |
398 consumer_thread_state = CONSUMER_THREAD_INITIALIZED; |
414 consumer_thread_state = CONSUMER_THREAD_INITIALIZED; |
416 |
433 |
417 // This could happen if client creates sink and deletes it |
434 // This could happen if client creates sink and deletes it |
418 // without putting it to play state |
435 // without putting it to play state |
419 if ( cmd != CLOSE ) |
436 if ( cmd != CLOSE ) |
420 { |
437 { |
421 initialize_devsound(devsoundsrc); |
438 gst_update_devsound_speech_bitrate(devsoundsrc); |
422 |
439 ret = initialize_devsound(devsoundsrc); |
423 recordinit(devsoundsrc->handle); |
440 if( KErrNone == ret ) |
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 { |
441 { |
456 memcpy(GST_BUFFER_DATA(pushBuffer),gBuffer,buffersize); |
442 ret = recordinit(devsoundsrc->handle); |
|
443 if( KErrNone == ret ) |
|
444 initproperties(devsoundsrc); |
|
445 |
457 } |
446 } |
458 else |
447 /// if initialization of devsound failed, return error, |
|
448 /// on return other thread will send CLOSE cmd to exit from thread. |
|
449 if( ret ) |
459 { |
450 { |
460 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Push buffer alloc failed ",NULL); |
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); |
461 } |
459 } |
462 |
460 } |
463 if (dataqueue) |
461 |
464 { |
462 while (TRUE) |
465 GST_OBJECT_LOCK(devsoundsrc); |
463 { |
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) |
464 switch (cmd) |
488 { |
465 { |
489 case READDATA: |
466 case PAUSE: |
|
467 pause_devsound(devsoundsrc); |
|
468 break; |
|
469 |
|
470 case RESUME: |
|
471 resume_devsound(devsoundsrc); |
|
472 break; |
|
473 |
|
474 case STOP: |
|
475 stop_devsound(devsoundsrc); |
|
476 break; |
|
477 |
|
478 case RECORDING: |
490 { |
479 { |
|
480 pre_init_setconf(devsoundsrc); |
|
481 // gst_Apply_SpeechEncoder_Update(devsoundsrc); |
|
482 gst_Apply_G711Encoder_Update(devsoundsrc); |
|
483 gst_Apply_G729Encoder_Update(devsoundsrc ); |
|
484 gst_Apply_IlbcEncoder_Update(devsoundsrc ); |
|
485 |
|
486 populateproperties(devsoundsrc); |
|
487 |
|
488 supportedbitrates = devsoundsrc->supportedbitrates; |
|
489 //numofbitrates = devsoundsrc->numofbitrates; |
|
490 speechbitrate = devsoundsrc->speechbitrate; |
|
491 speechvadmode = devsoundsrc->speechvadmode; |
|
492 g711vadmode = devsoundsrc->g711vadmode; |
|
493 g729vadmode = devsoundsrc->g729vadmode; |
|
494 ilbcvadmode = devsoundsrc->ilbcvadmode; |
|
495 |
|
496 buffersize = get_databuffer_size(devsoundsrc->handle); |
|
497 get_databuffer(devsoundsrc->handle, &gBuffer); |
|
498 pushBuffer = gst_buffer_new_and_alloc(buffersize); |
|
499 memcpy(GST_BUFFER_DATA(pushBuffer),gBuffer,buffersize); |
|
500 |
|
501 GST_OBJECT_LOCK(devsoundsrc); |
|
502 g_queue_push_head (dataqueue,pushBuffer); |
|
503 GST_OBJECT_UNLOCK(devsoundsrc); |
|
504 |
491 record_data(devsoundsrc->handle); |
505 record_data(devsoundsrc->handle); |
492 } |
506 } |
493 break; |
507 break; |
494 case CLOSE: |
508 case CLOSE: |
495 { |
509 { |
706 dataqueue = g_queue_new(); |
728 dataqueue = g_queue_new(); |
707 } |
729 } |
708 |
730 |
709 consumer_thread_state = CONSUMER_THREAD_INITIALIZING; |
731 consumer_thread_state = CONSUMER_THREAD_INITIALIZING; |
710 cmd = OPEN; |
732 cmd = OPEN; |
|
733 return_error = KErrNone; |
711 //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); |
712 pthread_create(&ds_thread, NULL, StartDevSoundThread, (void *)src); |
735 pthread_create(&ds_thread, NULL, StartDevSoundThread, (void *)src); |
713 //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); |
714 //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); |
715 if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING) |
738 if (consumer_thread_state == CONSUMER_THREAD_INITIALIZING) |
716 { |
739 { |
717 pthread_mutex_lock(&create_mutex1); |
740 pthread_mutex_lock(&create_mutex1); |
718 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. |
719 pthread_mutex_unlock(&create_mutex1); |
743 pthread_mutex_unlock(&create_mutex1); |
720 } |
744 } |
721 //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); |
722 //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); |
723 return TRUE; |
747 if ( return_error ) |
|
748 post_symbian_error( bsrc,return_error ); |
|
749 return ret; |
724 /* ERRORS */ |
750 /* ERRORS */ |
725 } |
751 } |
726 |
752 |
727 static gboolean gst_devsound_src_stop(GstBaseSrc * bsrc) |
753 static gboolean gst_devsound_src_stop(GstBaseSrc * bsrc) |
728 { |
754 { |
729 |
755 |
730 GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc); |
756 GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc); |
731 //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 "); |
732 cmd = CLOSE; |
758 cmd = CLOSE; |
733 |
759 pthread_mutex_lock(&(create_mutex1)); |
|
760 pthread_cond_signal(&(create_condition1)); |
|
761 pthread_mutex_unlock(&(create_mutex1)); |
734 //GST_OBJECT_LOCK (src); |
762 //GST_OBJECT_LOCK (src); |
735 pthread_mutex_lock(&(create_mutex1)); |
763 pthread_mutex_lock(&(create_mutex1)); |
736 pthread_cond_wait(&(create_condition1), &(create_mutex1)); |
764 pthread_cond_wait(&(create_condition1), &(create_mutex1)); |
737 pthread_mutex_unlock(&(create_mutex1)); |
765 pthread_mutex_unlock(&(create_mutex1)); |
738 //GST_OBJECT_UNLOCK (src); |
766 //GST_OBJECT_UNLOCK (src); |
792 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset, |
821 static GstFlowReturn gst_devsound_src_create(GstBaseSrc *src, guint64 offset, |
793 guint size, GstBuffer **buf) |
822 guint size, GstBuffer **buf) |
794 { |
823 { |
795 GstDevsoundSrc *dsrc= GST_DEVSOUND_SRC(src); |
824 GstDevsoundSrc *dsrc= GST_DEVSOUND_SRC(src); |
796 int bufferpos=0; |
825 int bufferpos=0; |
|
826 int ret = KErrNone; |
|
827 |
|
828 if(!g_queue_get_length(dataqueue) && (dsrc->eosreceived == TRUE)) |
|
829 { |
|
830 pthread_mutex_lock(&(create_mutex1)); |
|
831 pthread_cond_signal(&(create_condition1)); |
|
832 pthread_mutex_unlock(&(create_mutex1)); |
|
833 post_symbian_error( src,KErrCancel ); |
|
834 return GST_FLOW_UNEXPECTED; |
|
835 } |
|
836 |
797 //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 "); |
798 |
838 |
799 //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); |
800 *buf = gst_buffer_try_new_and_alloc(size); |
840 *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); |
841 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFter Buffer Alloc in CREATE ",NULL); |
802 |
842 if(*buf == NULL) |
|
843 { |
|
844 post_symbian_error( src,KErrNoMemory ); |
|
845 return GST_FLOW_UNEXPECTED; |
|
846 } |
|
847 |
803 while (size > 0) |
848 while (size > 0) |
804 { |
849 { |
805 if (dataleft >= size) |
850 if (dataleft >= size) |
806 { |
851 { |
807 // 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 |
837 popBuffer = NULL; |
882 popBuffer = NULL; |
838 } |
883 } |
839 |
884 |
840 // we wait here if the dataqueue length is 0 and we need data |
885 // we wait here if the dataqueue length is 0 and we need data |
841 // to be filled in the queue from the DevSound Thread |
886 // to be filled in the queue from the DevSound Thread |
842 if (!dataqueue->length) |
887 if (!g_queue_get_length(dataqueue)) |
843 { |
888 { |
844 //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); |
845 cmd = READDATA; |
890 if(dsrc->eosreceived == TRUE) |
846 pthread_mutex_lock(&(create_mutex1)); |
891 { |
847 pthread_cond_signal(&(create_condition1)); |
892 post_symbian_error( src,KErrCancel ); |
848 pthread_mutex_unlock(&(create_mutex1)); |
893 return GST_FLOW_UNEXPECTED; |
849 |
894 } |
850 pthread_mutex_lock(&(create_mutex1)); |
895 else |
851 pthread_cond_wait(&(create_condition1), &(create_mutex1)); |
896 { |
852 pthread_mutex_unlock(&(create_mutex1)); |
897 cmd = RECORDING; |
|
898 return_error = KErrNone; |
|
899 pthread_mutex_lock(&(create_mutex1)); |
|
900 pthread_cond_signal(&(create_condition1)); |
|
901 pthread_mutex_unlock(&(create_mutex1)); |
|
902 |
|
903 pthread_mutex_lock(&(create_mutex1)); |
|
904 pthread_cond_wait(&(create_condition1), &(create_mutex1)); |
|
905 ret = return_error; |
|
906 pthread_mutex_unlock(&(create_mutex1)); |
|
907 } |
853 //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); |
854 } |
909 } |
855 |
910 if( ret ) |
|
911 { |
|
912 post_symbian_error( src,ret ); |
|
913 return GST_FLOW_UNEXPECTED; |
|
914 } |
856 //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); |
857 GST_OBJECT_LOCK(dsrc); |
916 GST_OBJECT_LOCK(dsrc); |
858 popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue); |
917 popBuffer = (GstBuffer*)g_queue_pop_tail(dataqueue); |
859 GST_OBJECT_UNLOCK(dsrc); |
918 GST_OBJECT_UNLOCK(dsrc); |
860 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "AFTER POP in CREATE ",NULL); |
919 |
861 |
920 if(!popBuffer ) |
|
921 { |
|
922 post_symbian_error( src,KErrNoMemory ); |
|
923 return GST_FLOW_UNEXPECTED; |
|
924 } |
|
925 if(dsrc->firstTimeInit != kPlayed) |
|
926 { |
|
927 dsrc->prevbuffersize = gst_base_src_get_blocksize(src); |
|
928 gst_base_src_set_blocksize (src, GST_BUFFER_SIZE(popBuffer)); |
|
929 (*buf)->size = GST_BUFFER_SIZE(popBuffer); |
|
930 } |
862 // copy the data from the popped buffer based on how much of the incoming |
931 // 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 |
932 //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 |
933 // where the size of the fresh buffer is more then the data remaining in the |
865 // popped buffer. |
934 // popped buffer. |
866 if (size < GST_BUFFER_SIZE(popBuffer)) |
935 if (size < GST_BUFFER_SIZE(popBuffer)) |
886 { |
955 { |
887 gst_buffer_unref(popBuffer); |
956 gst_buffer_unref(popBuffer); |
888 popBuffer = NULL; |
957 popBuffer = NULL; |
889 } |
958 } |
890 } |
959 } |
891 } |
960 if (dsrc->firstTimeInit == kPlayBufferPreRoll) |
|
961 { |
|
962 gst_base_src_set_blocksize (src, dsrc->prevbuffersize); |
|
963 dsrc->firstTimeInit = kPlayed; |
|
964 return GST_FLOW_OK; |
|
965 } |
|
966 |
|
967 if (dsrc->firstTimeInit == kPausedToPlaying) |
|
968 { |
|
969 dsrc->firstTimeInit = kPlayBufferPreRoll; |
|
970 return GST_FLOW_OK; |
|
971 } |
|
972 } |
892 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create EXIT ",NULL); |
973 //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) dsrc, "gst_devsound_src_create EXIT ",NULL); |
893 return GST_FLOW_OK; |
974 return GST_FLOW_OK; |
894 } |
975 } |
|
976 |
|
977 |
|
978 static GstStateChangeReturn gst_devsound_src_change_state (GstElement * element, |
|
979 GstStateChange transition) |
|
980 { |
|
981 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; |
|
982 GstDevsoundSrc *src= GST_DEVSOUND_SRC (element); |
|
983 |
|
984 switch (transition) { |
|
985 |
|
986 case GST_STATE_CHANGE_PAUSED_TO_PLAYING: |
|
987 if (src->firstTimeInit != kPlayed) |
|
988 src->firstTimeInit = kPausedToPlaying; |
|
989 if(cmd == PAUSE) |
|
990 { |
|
991 cmd = RESUME; |
|
992 return_error = KErrNone; |
|
993 pthread_mutex_lock(&create_mutex1); |
|
994 pthread_cond_signal(&create_condition1); |
|
995 pthread_mutex_unlock(&create_mutex1); |
|
996 |
|
997 pthread_mutex_lock(&create_mutex1); |
|
998 pthread_cond_wait(&create_condition1, &create_mutex1); |
|
999 if( return_error ) |
|
1000 { |
|
1001 post_symbian_error( GST_BASE_SRC(element),return_error ); |
|
1002 ret = GST_STATE_CHANGE_FAILURE; |
|
1003 } |
|
1004 pthread_mutex_unlock(&create_mutex1); |
|
1005 } |
|
1006 break; |
|
1007 default: |
|
1008 break; |
|
1009 } |
|
1010 |
|
1011 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); |
|
1012 if (G_UNLIKELY (ret == GST_STATE_CHANGE_FAILURE)) |
|
1013 goto activate_failed; |
|
1014 |
|
1015 switch (transition) { |
|
1016 |
|
1017 case GST_STATE_CHANGE_PLAYING_TO_PAUSED: |
|
1018 cmd = PAUSE; |
|
1019 return_error = KErrNone; |
|
1020 pthread_mutex_lock(&create_mutex1); |
|
1021 pthread_cond_signal(&create_condition1); |
|
1022 pthread_mutex_unlock(&create_mutex1); |
|
1023 |
|
1024 pthread_mutex_lock(&create_mutex1); |
|
1025 pthread_cond_wait(&create_condition1, &create_mutex1); |
|
1026 if( return_error ) |
|
1027 { |
|
1028 post_symbian_error( GST_BASE_SRC(element),return_error ); |
|
1029 ret = GST_STATE_CHANGE_FAILURE; |
|
1030 } |
|
1031 pthread_mutex_unlock(&create_mutex1); |
|
1032 break; |
|
1033 default: |
|
1034 break; |
|
1035 } |
|
1036 |
|
1037 return ret; |
|
1038 |
|
1039 activate_failed: |
|
1040 { |
|
1041 GST_DEBUG_OBJECT (src, |
|
1042 "element failed to change states -- activation problem?"); |
|
1043 return GST_STATE_CHANGE_FAILURE; |
|
1044 } |
|
1045 } |
|
1046 |
895 |
1047 |
896 static gboolean gst_devsound_src_is_seekable(GstBaseSrc * bsrc) |
1048 static gboolean gst_devsound_src_is_seekable(GstBaseSrc * bsrc) |
897 { |
1049 { |
898 GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc); |
1050 GstDevsoundSrc *src= GST_DEVSOUND_SRC(bsrc); |
899 return FALSE; |
1051 return FALSE; |
1135 } |
1294 } |
1136 return result; |
1295 return result; |
1137 |
1296 |
1138 } |
1297 } |
1139 |
1298 |
|
1299 static gboolean gst_devsound_src_event(GstBaseSrc *asrc, GstEvent *event) |
|
1300 { |
|
1301 int retValue = FALSE; |
|
1302 GstDevsoundSrc *src = GST_DEVSOUND_SRC(asrc); |
|
1303 switch (GST_EVENT_TYPE (event)) |
|
1304 { |
|
1305 case GST_EVENT_EOS: |
|
1306 // end-of-stream, we should close down all stream leftovers here |
|
1307 //reset_devsound(sink->handle); |
|
1308 src->eosreceived = TRUE; |
|
1309 cmd = STOP; |
|
1310 return_error = KErrNone; |
|
1311 pthread_mutex_lock(&create_mutex1); |
|
1312 pthread_cond_signal(&create_condition1); |
|
1313 pthread_mutex_unlock(&create_mutex1); |
|
1314 |
|
1315 pthread_mutex_lock(&create_mutex1); |
|
1316 pthread_cond_wait(&create_condition1, &create_mutex1); |
|
1317 pthread_mutex_unlock(&create_mutex1); |
|
1318 |
|
1319 if(g_queue_get_length(dataqueue)) |
|
1320 { |
|
1321 pthread_mutex_lock(&create_mutex1); |
|
1322 pthread_cond_wait(&create_condition1, &create_mutex1); |
|
1323 pthread_mutex_unlock(&create_mutex1); |
|
1324 } |
|
1325 |
|
1326 gst_pad_push_event (asrc->srcpad, gst_event_new_eos ()); |
|
1327 retValue = TRUE; |
|
1328 break; |
|
1329 default: |
|
1330 retValue = FALSE; |
|
1331 break; |
|
1332 } |
|
1333 |
|
1334 return retValue; |
|
1335 } |
|
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 |