[MOVED FROM GST-P-FARSIGHT] Make dtmf src code nicer

20070916194101-3e2dc-a8be8c509c65400d1d3962da02e67d15d2054316.gz
This commit is contained in:
Olivier Crete 2007-09-16 19:41:01 +00:00 committed by Edward Hervey
parent 8c5930fadb
commit 64efe461ff

View File

@ -633,19 +633,18 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
do { do {
if (dtmfsrc->paused)
goto paused;
if (dtmfsrc->last_event == NULL) { if (dtmfsrc->last_event == NULL) {
GST_DEBUG_OBJECT (dtmfsrc, "popping"); GST_DEBUG_OBJECT (dtmfsrc, "popping");
event = g_async_queue_pop (dtmfsrc->event_queue); event = g_async_queue_pop (dtmfsrc->event_queue);
GST_DEBUG_OBJECT (dtmfsrc, "popped %d", event->event_type); GST_DEBUG_OBJECT (dtmfsrc, "popped %d", event->event_type);
if (event->event_type == DTMF_EVENT_TYPE_STOP) { switch (event->event_type) {
case DTMF_EVENT_TYPE_STOP:
GST_WARNING_OBJECT (dtmfsrc, GST_WARNING_OBJECT (dtmfsrc,
"Received a DTMF stop event when already stopped"); "Received a DTMF stop event when already stopped");
} else if (event->event_type == DTMF_EVENT_TYPE_START) { break;
case DTMF_EVENT_TYPE_START:
gst_dtmf_prepare_timestamps (dtmfsrc); gst_dtmf_prepare_timestamps (dtmfsrc);
/* Don't forget to get exclusive access to the stream */ /* Don't forget to get exclusive access to the stream */
@ -653,41 +652,53 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
event->packet_count = 0; event->packet_count = 0;
dtmfsrc->last_event = event; dtmfsrc->last_event = event;
} else if (event->event_type == DTMF_EVENT_TYPE_PAUSE_TASK) { break;
case DTMF_EVENT_TYPE_PAUSE_TASK:
/* /*
* We're pushing it back because it has to stay in there until * We're pushing it back because it has to stay in there until
* the task is really paused (and the queue will then be flushed) * the task is really paused (and the queue will then be flushed)
*/ */
GST_DEBUG_OBJECT (dtmfsrc, "pushing pause_task..."); GST_DEBUG_OBJECT (dtmfsrc, "pushing pause_task...");
GST_OBJECT_LOCK (dtmfsrc);
if (dtmfsrc->paused) { if (dtmfsrc->paused) {
g_async_queue_push (dtmfsrc->event_queue, event); g_async_queue_push (dtmfsrc->event_queue, event);
goto paused; goto paused_locked;
} }
GST_OBJECT_UNLOCK (dtmfsrc);
break;
} }
} else if (dtmfsrc->last_event->packet_count * dtmfsrc->interval >= } else if (dtmfsrc->last_event->packet_count * dtmfsrc->interval >=
MIN_DUTY_CYCLE) { MIN_DUTY_CYCLE) {
event = g_async_queue_try_pop (dtmfsrc->event_queue); event = g_async_queue_try_pop (dtmfsrc->event_queue);
if (event != NULL) { if (event != NULL) {
if (event->event_type == DTMF_EVENT_TYPE_START) {
switch (event->event_type) {
case DTMF_EVENT_TYPE_START:
GST_WARNING_OBJECT (dtmfsrc, GST_WARNING_OBJECT (dtmfsrc,
"Received two consecutive DTMF start events"); "Received two consecutive DTMF start events");
} else if (event->event_type == DTMF_EVENT_TYPE_STOP) { break;
case DTMF_EVENT_TYPE_STOP:
gst_dtmf_src_set_stream_lock (dtmfsrc, FALSE); gst_dtmf_src_set_stream_lock (dtmfsrc, FALSE);
g_free (dtmfsrc->last_event); g_free (dtmfsrc->last_event);
dtmfsrc->last_event = NULL; dtmfsrc->last_event = NULL;
} else if (event->event_type == DTMF_EVENT_TYPE_PAUSE_TASK) { break;
case DTMF_EVENT_TYPE_PAUSE_TASK:
/* /*
* We're pushing it back because it has to stay in there until * We're pushing it back because it has to stay in there until
* the task is really paused (and the queue will then be flushed) * the task is really paused (and the queue will then be flushed)
*/ */
GST_DEBUG_OBJECT (dtmfsrc, "pushing pause_task..."); GST_DEBUG_OBJECT (dtmfsrc, "pushing pause_task...");
GST_OBJECT_LOCK (dtmfsrc);
if (dtmfsrc->paused) { if (dtmfsrc->paused) {
g_async_queue_push (dtmfsrc->event_queue, event); g_async_queue_push (dtmfsrc->event_queue, event);
goto paused; goto paused_locked;
} }
GST_OBJECT_UNLOCK (dtmfsrc);
break;
} }
} }
} }
@ -730,6 +741,9 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
GST_DEBUG_OBJECT (dtmfsrc, "returning a buffer"); GST_DEBUG_OBJECT (dtmfsrc, "returning a buffer");
return GST_FLOW_OK; return GST_FLOW_OK;
paused_locked:
GST_OBJECT_UNLOCK (dtmfsrc);
paused: paused:
if (dtmfsrc->last_event) { if (dtmfsrc->last_event) {
@ -811,12 +825,6 @@ gst_dtmf_src_change_state (GstElement * element, GstStateChange transition)
goto failure; goto failure;
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
GST_DEBUG_OBJECT (dtmfsrc, "PLAYING TO PAUSED");
no_preroll = TRUE;
break;
case GST_STATE_CHANGE_PAUSED_TO_READY: case GST_STATE_CHANGE_PAUSED_TO_READY:
GST_DEBUG_OBJECT (dtmfsrc, "Flushing event queue"); GST_DEBUG_OBJECT (dtmfsrc, "Flushing event queue");
/* Flushing the event queue */ /* Flushing the event queue */
@ -827,8 +835,6 @@ gst_dtmf_src_change_state (GstElement * element, GstStateChange transition)
event = g_async_queue_try_pop (dtmfsrc->event_queue); event = g_async_queue_try_pop (dtmfsrc->event_queue);
} }
/* Indicate that we don't do PRE_ROLL */
no_preroll = TRUE;
break; break;
default: default:
break; break;