rtsp: manage writer child source better

Only add the write child source when we have something to write or else
we will dispatch forever without doing anything.
This commit is contained in:
Wim Taymans 2013-06-20 17:28:46 +02:00
parent 82e5ec553b
commit ad6c16fdfc

View file

@ -2779,6 +2779,7 @@ struct _GstRTSPWatch
GSource *readsrc; GSource *readsrc;
GSource *writesrc; GSource *writesrc;
gboolean write_added;
gboolean keep_running; gboolean keep_running;
@ -2962,8 +2963,13 @@ gst_rtsp_source_dispatch_write (GPollableOutputStream * stream,
/* get a new message from the queue */ /* get a new message from the queue */
rec = g_queue_pop_tail (watch->messages); rec = g_queue_pop_tail (watch->messages);
if (rec == NULL) if (rec == NULL) {
if (watch->write_added) {
g_source_remove_child_source ((GSource *) watch, watch->writesrc);
watch->write_added = FALSE;
}
break; break;
}
watch->messages_bytes -= rec->size; watch->messages_bytes -= rec->size;
@ -3037,6 +3043,11 @@ gst_rtsp_source_finalize (GSource * source)
watch->messages_bytes = 0; watch->messages_bytes = 0;
g_free (watch->write_data); g_free (watch->write_data);
if (watch->readsrc)
g_source_unref (watch->readsrc);
if (watch->writesrc)
g_source_unref (watch->writesrc);
g_mutex_clear (&watch->mutex); g_mutex_clear (&watch->mutex);
if (watch->notify) if (watch->notify)
@ -3110,10 +3121,17 @@ gst_rtsp_watch_new (GstRTSPConnection * conn,
void void
gst_rtsp_watch_reset (GstRTSPWatch * watch) gst_rtsp_watch_reset (GstRTSPWatch * watch)
{ {
if (watch->readsrc) if (watch->readsrc) {
g_source_remove_child_source ((GSource *) watch, watch->readsrc); g_source_remove_child_source ((GSource *) watch, watch->readsrc);
if (watch->writesrc) g_source_unref (watch->readsrc);
g_source_remove_child_source ((GSource *) watch, watch->writesrc); }
if (watch->writesrc) {
if (watch->write_added) {
g_source_remove_child_source ((GSource *) watch, watch->writesrc);
watch->write_added = FALSE;
}
g_source_unref (watch->writesrc);
}
if (watch->conn->input_stream) { if (watch->conn->input_stream) {
watch->readsrc = watch->readsrc =
@ -3122,7 +3140,6 @@ gst_rtsp_watch_reset (GstRTSPWatch * watch)
g_source_set_callback (watch->readsrc, g_source_set_callback (watch->readsrc,
(GSourceFunc) gst_rtsp_source_dispatch_read, watch, NULL); (GSourceFunc) gst_rtsp_source_dispatch_read, watch, NULL);
g_source_add_child_source ((GSource *) watch, watch->readsrc); g_source_add_child_source ((GSource *) watch, watch->readsrc);
g_source_unref (watch->readsrc);
} else { } else {
watch->readsrc = NULL; watch->readsrc = NULL;
} }
@ -3133,8 +3150,7 @@ gst_rtsp_watch_reset (GstRTSPWatch * watch)
(watch->conn->output_stream), NULL); (watch->conn->output_stream), NULL);
g_source_set_callback (watch->writesrc, g_source_set_callback (watch->writesrc,
(GSourceFunc) gst_rtsp_source_dispatch_write, watch, NULL); (GSourceFunc) gst_rtsp_source_dispatch_write, watch, NULL);
g_source_add_child_source ((GSource *) watch, watch->writesrc); /* we add the write source when we actually have something to write */
g_source_unref (watch->writesrc);
} else { } else {
watch->writesrc = NULL; watch->writesrc = NULL;
} }
@ -3306,6 +3322,10 @@ gst_rtsp_watch_write_data (GstRTSPWatch * watch, const guint8 * data,
/* make sure the main context will now also check for writability on the /* make sure the main context will now also check for writability on the
* socket */ * socket */
context = ((GSource *) watch)->context; context = ((GSource *) watch)->context;
if (!watch->write_added) {
g_source_add_child_source ((GSource *) watch, watch->writesrc);
watch->write_added = TRUE;
}
if (id != NULL) if (id != NULL)
*id = rec->id; *id = rec->id;