ext/ogg/gstoggmux.c: Fix EOS on multiple streams.

Original commit message from CVS:
* ext/ogg/gstoggmux.c: (gst_ogg_mux_queue_pads),
(gst_ogg_mux_get_headers), (gst_ogg_mux_send_headers),
(gst_ogg_mux_collected), (gst_ogg_mux_change_state):
Fix EOS on multiple streams.
More debugging.
This commit is contained in:
Wim Taymans 2005-11-17 10:56:14 +00:00
parent 928996eb94
commit 6002986857
2 changed files with 57 additions and 117 deletions

View file

@ -1,3 +1,11 @@
2005-11-17 Wim Taymans <wim@fluendo.com>
* ext/ogg/gstoggmux.c: (gst_ogg_mux_queue_pads),
(gst_ogg_mux_get_headers), (gst_ogg_mux_send_headers),
(gst_ogg_mux_collected), (gst_ogg_mux_change_state):
Fix EOS on multiple streams.
More debugging.
2005-11-16 Wim Taymans <wim@fluendo.com> 2005-11-16 Wim Taymans <wim@fluendo.com>
* ext/ogg/gstoggdemux.c: (gst_ogg_demux_configure_segment), * ext/ogg/gstoggdemux.c: (gst_ogg_demux_configure_segment),

View file

@ -434,78 +434,6 @@ gst_ogg_mux_handle_src_event (GstPad * pad, GstEvent * event)
return gst_pad_event_default (pad, event); return gst_pad_event_default (pad, event);
} }
#if 0
static GstBuffer *
gst_ogg_mux_next_buffer (GstOggPad * pad, gboolean * interrupt)
{
GstData *data = NULL;
GstBuffer *buffer = NULL;
while (buffer == NULL) {
//gst_pad_pull (pad->pad, &buffer);
GST_DEBUG ("muxer: pulled %s:%s %p", GST_DEBUG_PAD_NAME (pad->pad), data);
/* if it's an event, handle it */
if (GST_IS_EVENT (data)) {
GstEventType type;
GstOggMux *ogg_mux;
GstEvent *event = GST_EVENT (data);
ogg_mux = GST_OGG_MUX (gst_pad_get_parent (pad->pad));
type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
switch (type) {
case GST_EVENT_EOS:
pad->eos = TRUE;
gst_event_unref (event);
return NULL;
case GST_EVENT_DISCONTINUOUS:
{
guint64 start_value, end_value;
if (gst_event_discont_get_value (event, GST_FORMAT_TIME,
&start_value, &end_value)) {
GST_DEBUG_OBJECT (ogg_mux,
"got discont of %" G_GUINT64_FORMAT " and %" G_GUINT64_FORMAT
" on pad %s:%s", start_value, end_value,
GST_DEBUG_PAD_NAME (pad->pad));
}
pad->offset = start_value;
gst_event_unref (event);
}
break;
default:
gst_pad_event_default (pad->pad, event);
break;
}
data = NULL;
} else {
GstBuffer *buf = GST_BUFFER (data);
gboolean incaps;
incaps = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_IN_CAPS);
/* if we need headers */
if (pad->state == GST_OGG_PAD_STATE_CONTROL) {
/* and we have one */
if (incaps) {
GST_DEBUG ("muxer: got incaps buffer in control state, ignoring");
/* just ignore */
gst_buffer_unref (buf);
/* pull next one in next iteration */
data = NULL;
} else {
GST_DEBUG
("muxer: got data buffer in control state, switching to data mode");
/* this is a data buffer so switch to data state */
pad->state = GST_OGG_PAD_STATE_DATA;
}
}
}
}
return GST_BUFFER (data);
}
#endif
static GstBuffer * static GstBuffer *
gst_ogg_mux_buffer_from_page (GstOggMux * mux, ogg_page * page, gboolean delta) gst_ogg_mux_buffer_from_page (GstOggMux * mux, ogg_page * page, gboolean delta)
{ {
@ -725,12 +653,15 @@ gst_ogg_mux_queue_pads (GstOggMux * ogg_mux)
walk = g_slist_next (walk); walk = g_slist_next (walk);
GST_DEBUG_OBJECT (ogg_mux, "looking at pad %p", pad);
/* try to get a new buffer for this pad if needed and possible */ /* try to get a new buffer for this pad if needed and possible */
if (pad->buffer == NULL) { if (pad->buffer == NULL) {
GstBuffer *buf; GstBuffer *buf;
gboolean incaps; gboolean incaps;
buf = gst_collectpads_pop (ogg_mux->collect, data); buf = gst_collectpads_pop (ogg_mux->collect, data);
GST_DEBUG_OBJECT (ogg_mux, "popping buffer %p", buf);
/* On EOS we get a NULL buffer */ /* On EOS we get a NULL buffer */
if (buf != NULL) { if (buf != NULL) {
@ -739,19 +670,20 @@ gst_ogg_mux_queue_pads (GstOggMux * ogg_mux)
if (pad->state == GST_OGG_PAD_STATE_CONTROL) { if (pad->state == GST_OGG_PAD_STATE_CONTROL) {
/* and we have one */ /* and we have one */
if (incaps) { if (incaps) {
GST_DEBUG ("muxer: got incaps buffer in control state, ignoring"); GST_DEBUG_OBJECT (ogg_mux,
"got incaps buffer in control state, ignoring");
/* just ignore */ /* just ignore */
gst_buffer_unref (buf); gst_buffer_unref (buf);
buf = NULL; buf = NULL;
} else { } else {
GST_DEBUG ("muxer: got data buffer in control state, switching " GST_DEBUG_OBJECT (ogg_mux,
"to data mode"); "got data buffer in control state, switching " "to data mode");
/* this is a data buffer so switch to data state */ /* this is a data buffer so switch to data state */
pad->state = GST_OGG_PAD_STATE_DATA; pad->state = GST_OGG_PAD_STATE_DATA;
} }
} }
} else { } else {
GST_DEBUG ("EOS on pad"); GST_DEBUG_OBJECT (ogg_mux, "EOS on pad");
pad->eos = TRUE; pad->eos = TRUE;
} }
@ -761,9 +693,12 @@ gst_ogg_mux_queue_pads (GstOggMux * ogg_mux)
/* we should have a buffer now, see if it is the best pad to /* we should have a buffer now, see if it is the best pad to
* pull on */ * pull on */
if (pad->buffer) { if (pad->buffer) {
if (gst_ogg_mux_compare_pads (ogg_mux, bestpad, pad) > 0) if (gst_ogg_mux_compare_pads (ogg_mux, bestpad, pad) > 0) {
GST_DEBUG_OBJECT (ogg_mux, "best pad now %p", pad);
bestpad = pad; bestpad = pad;
}
} else if (!pad->eos) { } else if (!pad->eos) {
GST_DEBUG_OBJECT (ogg_mux, "hungry pad %p", pad);
still_hungry = pad; still_hungry = pad;
} }
} }
@ -788,7 +723,7 @@ gst_ogg_mux_get_headers (GstOggPad * pad)
ogg_mux = GST_OGG_MUX (GST_PAD_PARENT (thepad)); ogg_mux = GST_OGG_MUX (GST_PAD_PARENT (thepad));
GST_LOG ("getting headers from pad %s:%s", GST_DEBUG_PAD_NAME (thepad)); GST_LOG_OBJECT (thepad, "getting headers");
caps = gst_pad_get_negotiated_caps (thepad); caps = gst_pad_get_negotiated_caps (thepad);
if (caps != NULL) { if (caps != NULL) {
@ -797,34 +732,34 @@ gst_ogg_mux_get_headers (GstOggPad * pad)
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
streamheader = gst_structure_get_value (structure, "streamheader"); streamheader = gst_structure_get_value (structure, "streamheader");
if (streamheader != NULL) { if (streamheader != NULL) {
GST_LOG ("got header"); GST_LOG_OBJECT (thepad, "got header");
if (G_VALUE_TYPE (streamheader) == GST_TYPE_ARRAY) { if (G_VALUE_TYPE (streamheader) == GST_TYPE_ARRAY) {
GArray *bufarr = g_value_peek_pointer (streamheader); GArray *bufarr = g_value_peek_pointer (streamheader);
gint i; gint i;
GST_LOG ("got fixed list"); GST_LOG_OBJECT (thepad, "got fixed list");
for (i = 0; i < bufarr->len; i++) { for (i = 0; i < bufarr->len; i++) {
GValue *bufval = &g_array_index (bufarr, GValue, i); GValue *bufval = &g_array_index (bufarr, GValue, i);
GST_LOG ("item %d", i); GST_LOG_OBJECT (thepad, "item %d", i);
if (G_VALUE_TYPE (bufval) == GST_TYPE_BUFFER) { if (G_VALUE_TYPE (bufval) == GST_TYPE_BUFFER) {
GstBuffer *buf = g_value_peek_pointer (bufval); GstBuffer *buf = g_value_peek_pointer (bufval);
GST_LOG ("adding item %d to header list", i); GST_LOG_OBJECT (thepad, "adding item %d to header list", i);
gst_buffer_ref (buf); gst_buffer_ref (buf);
res = g_list_append (res, buf); res = g_list_append (res, buf);
} }
} }
} else { } else {
GST_LOG ("streamheader is not fixed list"); GST_LOG_OBJECT (thepad, "streamheader is not fixed list");
} }
} else { } else {
GST_LOG ("caps done have streamheader"); GST_LOG_OBJECT (thepad, "caps done have streamheader");
} }
} else { } else {
GST_LOG ("got empty caps as negotiated format"); GST_LOG_OBJECT (thepad, "got empty caps as negotiated format");
} }
return res; return res;
} }
@ -883,7 +818,7 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
hbufs = NULL; hbufs = NULL;
ret = GST_FLOW_OK; ret = GST_FLOW_OK;
GST_LOG ("collecting headers"); GST_LOG_OBJECT (mux, "collecting headers");
walk = mux->collect->data; walk = mux->collect->data;
while (walk) { while (walk) {
@ -895,7 +830,7 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
walk = g_slist_next (walk); walk = g_slist_next (walk);
GST_LOG ("looking at pad %s:%s", GST_DEBUG_PAD_NAME (thepad)); GST_LOG_OBJECT (mux, "looking at pad %s:%s", GST_DEBUG_PAD_NAME (thepad));
/* if the pad has no buffer, we don't care */ /* if the pad has no buffer, we don't care */
if (pad->buffer == NULL) if (pad->buffer == NULL)
@ -905,7 +840,7 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
pad->headers = gst_ogg_mux_get_headers (pad); pad->headers = gst_ogg_mux_get_headers (pad);
} }
GST_LOG ("creating first headers"); GST_LOG_OBJECT (mux, "creating first headers");
walk = mux->collect->data; walk = mux->collect->data;
while (walk) { while (walk) {
GstOggPad *pad; GstOggPad *pad;
@ -921,7 +856,8 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
pad->packetno = 0; pad->packetno = 0;
GST_LOG ("looping over headers for pad %s:%s", GST_DEBUG_PAD_NAME (thepad)); GST_LOG_OBJECT (mux, "looping over headers for pad %s:%s",
GST_DEBUG_PAD_NAME (thepad));
if (pad->headers) { if (pad->headers) {
buf = GST_BUFFER (pad->headers->data); buf = GST_BUFFER (pad->headers->data);
@ -954,16 +890,16 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
ogg_stream_packetin (&pad->stream, &packet); ogg_stream_packetin (&pad->stream, &packet);
gst_buffer_unref (buf); gst_buffer_unref (buf);
GST_LOG ("flushing page with first packet"); GST_LOG_OBJECT (mux, "flushing page with first packet");
while (ogg_stream_flush (&pad->stream, &page)) { while (ogg_stream_flush (&pad->stream, &page)) {
GstBuffer *hbuf = gst_ogg_mux_buffer_from_page (mux, &page, FALSE); GstBuffer *hbuf = gst_ogg_mux_buffer_from_page (mux, &page, FALSE);
GST_LOG ("swapped out page"); GST_LOG_OBJECT (mux, "swapped out page");
hbufs = g_list_append (hbufs, hbuf); hbufs = g_list_append (hbufs, hbuf);
} }
} }
GST_LOG ("creating next headers"); GST_LOG_OBJECT (mux, "creating next headers");
walk = mux->collect->data; walk = mux->collect->data;
while (walk) { while (walk) {
GstOggPad *pad; GstOggPad *pad;
@ -974,7 +910,8 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
walk = walk->next; walk = walk->next;
GST_LOG ("looping over headers for pad %s:%s", GST_DEBUG_PAD_NAME (thepad)); GST_LOG_OBJECT (mux, "looping over headers for pad %s:%s",
GST_DEBUG_PAD_NAME (thepad));
hwalk = pad->headers; hwalk = pad->headers;
while (hwalk) { while (hwalk) {
@ -1002,21 +939,22 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
/* if last header, flush page */ /* if last header, flush page */
if (hwalk == NULL) { if (hwalk == NULL) {
GST_LOG ("flushing page as packet %d is first or last packet", GST_LOG_OBJECT (mux,
"flushing page as packet %d is first or last packet",
pad->packetno); pad->packetno);
while (ogg_stream_flush (&pad->stream, &page)) { while (ogg_stream_flush (&pad->stream, &page)) {
GstBuffer *hbuf = gst_ogg_mux_buffer_from_page (mux, &page, FALSE); GstBuffer *hbuf = gst_ogg_mux_buffer_from_page (mux, &page, FALSE);
GST_LOG ("swapped out page"); GST_LOG_OBJECT (mux, "swapped out page");
hbufs = g_list_append (hbufs, hbuf); hbufs = g_list_append (hbufs, hbuf);
} }
} else { } else {
GST_LOG ("try to swap out page"); GST_LOG_OBJECT (mux, "try to swap out page");
/* just try to swap out a page then */ /* just try to swap out a page then */
while (ogg_stream_pageout (&pad->stream, &page) > 0) { while (ogg_stream_pageout (&pad->stream, &page) > 0) {
GstBuffer *hbuf = gst_ogg_mux_buffer_from_page (mux, &page, FALSE); GstBuffer *hbuf = gst_ogg_mux_buffer_from_page (mux, &page, FALSE);
GST_LOG ("swapped out page"); GST_LOG_OBJECT (mux, "swapped out page");
hbufs = g_list_append (hbufs, hbuf); hbufs = g_list_append (hbufs, hbuf);
} }
} }
@ -1079,18 +1017,18 @@ gst_ogg_mux_collected (GstCollectPads * pads, GstOggMux * ogg_mux)
gint64 granulepos = 0; gint64 granulepos = 0;
GstClockTime timestamp; GstClockTime timestamp;
GST_DEBUG ("collected"); GST_DEBUG_OBJECT (ogg_mux, "collected");
/* queue buffers on all pads; find a buffer with the lowest timestamp */ /* queue buffers on all pads; find a buffer with the lowest timestamp */
best = gst_ogg_mux_queue_pads (ogg_mux); best = gst_ogg_mux_queue_pads (ogg_mux);
if (best && !best->buffer) if (best && !best->buffer)
return GST_FLOW_OK; return GST_FLOW_OK;
GST_DEBUG ("best pad %p", best); GST_DEBUG_OBJECT (ogg_mux, "best pad %p, pulling %p", best, ogg_mux->pulling);
if (!best) { /* EOS : FIXME !! We need to handle EOS correctly, and set EOS if (!best) { /* EOS : FIXME !! We need to handle EOS correctly, and set EOS
flags on the ogg pages. */ flags on the ogg pages. */
GST_DEBUG ("Pushing EOS"); GST_DEBUG_OBJECT (ogg_mux, "Pushing EOS");
gst_pad_push_event (ogg_mux->srcpad, gst_event_new_eos ()); gst_pad_push_event (ogg_mux->srcpad, gst_event_new_eos ());
return GST_FLOW_WRONG_STATE; return GST_FLOW_WRONG_STATE;
} }
@ -1132,6 +1070,7 @@ gst_ogg_mux_collected (GstCollectPads * pads, GstOggMux * ogg_mux)
/* if we don't know which pad to pull on, use the best one */ /* if we don't know which pad to pull on, use the best one */
if (ogg_mux->pulling == NULL) { if (ogg_mux->pulling == NULL) {
ogg_mux->pulling = best; ogg_mux->pulling = best;
GST_DEBUG_OBJECT (ogg_mux, "pulling now %p", ogg_mux->pulling);
/* remember timestamp of first buffer for this new pad */ /* remember timestamp of first buffer for this new pad */
if (ogg_mux->pulling != NULL) { if (ogg_mux->pulling != NULL) {
ogg_mux->next_ts = GST_BUFFER_TIMESTAMP (ogg_mux->pulling->buffer); ogg_mux->next_ts = GST_BUFFER_TIMESTAMP (ogg_mux->pulling->buffer);
@ -1152,8 +1091,15 @@ gst_ogg_mux_collected (GstCollectPads * pads, GstOggMux * ogg_mux)
gint64 duration; gint64 duration;
gboolean force_flush; gboolean force_flush;
GST_DEBUG_OBJECT (ogg_mux, "pulling now %p", ogg_mux->pulling);
/* now see if we have a buffer */ /* now see if we have a buffer */
buf = pad->buffer; buf = pad->buffer;
if (buf == NULL) {
GST_DEBUG_OBJECT (ogg_mux, "pad was EOS");
ogg_mux->pulling = NULL;
return GST_FLOW_OK;
}
delta_unit = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT); delta_unit = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
duration = GST_BUFFER_DURATION (buf); duration = GST_BUFFER_DURATION (buf);
@ -1168,22 +1114,8 @@ gst_ogg_mux_collected (GstCollectPads * pads, GstOggMux * ogg_mux)
packet.b_o_s = (pad->packetno == 0); packet.b_o_s = (pad->packetno == 0);
packet.packetno = pad->packetno++; packet.packetno = pad->packetno++;
#if 0
/* read ahead one more buffer to find EOS */
tmpbuf = gst_ogg_mux_next_buffer (pad, &interrupt);
if (interrupt)
return;
/* data exhausted on this pad */
if (tmpbuf == NULL) {
/* stop pulling from the pad */
ogg_mux->pulling = NULL;
}
/* mark EOS */
packet.e_o_s = (tmpbuf == NULL ? 1 : 0);
#else
packet.e_o_s = 0; packet.e_o_s = 0;
tmpbuf = NULL; tmpbuf = NULL;
#endif
/* we flush when we see a new keyframe */ /* we flush when we see a new keyframe */
force_flush = (pad->prev_delta && !delta_unit); force_flush = (pad->prev_delta && !delta_unit);
@ -1396,6 +1328,9 @@ gst_ogg_mux_change_state (GstElement * element, GstStateChange transition)
break; break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING: case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break; break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
gst_collectpads_stop (ogg_mux->collect);
break;
default: default:
break; break;
} }
@ -1405,9 +1340,6 @@ gst_ogg_mux_change_state (GstElement * element, GstStateChange transition)
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED: case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break; break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
gst_collectpads_stop (ogg_mux->collect);
break;
case GST_STATE_CHANGE_READY_TO_NULL: case GST_STATE_CHANGE_READY_TO_NULL:
gst_ogg_mux_clear_collectpads (ogg_mux->collect); gst_ogg_mux_clear_collectpads (ogg_mux->collect);
break; break;