ext/ogg/: Fix the case where the muxer would mark pages as delta frames when they...
authorWim Taymans <wim.taymans@gmail.com>
Wed, 15 Sep 2004 15:37:36 +0000 (15:37 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Wed, 15 Sep 2004 15:37:36 +0000 (15:37 +0000)
Original commit message from CVS:
* ext/ogg/gstoggdemux.c: (gst_ogg_pad_push):
* ext/ogg/gstoggmux.c: (gst_ogg_mux_next_buffer),
(gst_ogg_mux_send_headers), (gst_ogg_mux_loop):
Fix the case where the muxer would mark pages as delta
frames when they are not (vorbis only ogg).

ChangeLog
ext/ogg/gstoggdemux.c
ext/ogg/gstoggmux.c

index e1bad93..a1018be 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2004-09-15  Wim Taymans  <wim@fluendo.com>
+
+       * ext/ogg/gstoggdemux.c: (gst_ogg_pad_push):
+       * ext/ogg/gstoggmux.c: (gst_ogg_mux_next_buffer),
+       (gst_ogg_mux_send_headers), (gst_ogg_mux_loop):
+       Fix the case where the muxer would mark pages as delta
+       frames when they are not (vorbis only ogg).
+
 2004-09-15  Ronald S. Bultje  <rbultje@ronald.bitfreak.net>
 
        * gst/playback/gstplaybasebin.c: (state_change), (setup_source),
index 8a2f7ff..bcde77f 100644 (file)
@@ -533,7 +533,8 @@ gst_ogg_demux_src_event (GstPad * pad, GstEvent * event)
 
       GST_OGG_SET_STATE (ogg, GST_OGG_STATE_SEEK);
       FOR_PAD_IN_CURRENT_CHAIN (ogg, pad,
-          pad->flags |= GST_OGG_PAD_NEEDS_DISCONT;);
+          pad->flags |= GST_OGG_PAD_NEEDS_DISCONT;
+          );
       GST_DEBUG_OBJECT (ogg,
           "initiating seeking to format %d, offset %" G_GUINT64_FORMAT, format,
           offset);
@@ -606,7 +607,8 @@ gst_ogg_demux_handle_event (GstPad * pad, GstEvent * event)
       gst_event_unref (event);
       GST_FLAG_UNSET (ogg, GST_OGG_FLAG_WAIT_FOR_DISCONT);
       FOR_PAD_IN_CURRENT_CHAIN (ogg, pad,
-          pad->flags |= GST_OGG_PAD_NEEDS_DISCONT;);
+          pad->flags |= GST_OGG_PAD_NEEDS_DISCONT;
+          );
       break;
     default:
       gst_pad_event_default (pad, event);
@@ -876,7 +878,8 @@ _find_chain_get_unknown_part (GstOggDemux * ogg, gint64 * start, gint64 * end)
   *end = G_MAXINT64;
 
   g_assert (ogg->current_chain >= 0);
-  FOR_PAD_IN_CURRENT_CHAIN (ogg, pad, *start = MAX (*start, pad->end_offset););
+  FOR_PAD_IN_CURRENT_CHAIN (ogg, pad, *start = MAX (*start, pad->end_offset);
+      );
 
   if (ogg->setup_state == SETUP_FIND_LAST_CHAIN) {
     *end = gst_file_pad_get_length (ogg->sinkpad);
@@ -1005,7 +1008,8 @@ _find_streams_check (GstOggDemux * ogg)
   } else {
     endpos = G_MAXINT64;
     FOR_PAD_IN_CHAIN (ogg, pad, ogg->chains->len - 1,
-        endpos = MIN (endpos, pad->start_offset););
+        endpos = MIN (endpos, pad->start_offset);
+        );
   }
   if (!ogg->seek_skipped || gst_ogg_demux_position (ogg) >= endpos) {
     /* have we found the endposition for all streams yet? */
index 04eecc5..045821a 100644 (file)
@@ -720,8 +720,8 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
       buf = GST_BUFFER (pad->headers->data);
       pad->headers = g_list_remove (pad->headers, buf);
     } else {
-      /* create empty buffer for the stream */
-      buf = gst_buffer_new_and_alloc (0);
+      buf = pad->buffer;
+      gst_buffer_ref (buf);
     }
 
     /* create a packet from the buffer */
@@ -860,20 +860,23 @@ gst_ogg_mux_loop (GstElement * element)
    * to flush the current page */
   if (ogg_mux->pulling && best &&
       ogg_mux->pulling != best && ogg_mux->pulling->buffer) {
+    GstOggPad *pad = ogg_mux->pulling;
+
     GstClockTime last_ts =
-        GST_BUFFER_TIMESTAMP (ogg_mux->pulling->buffer) +
-        GST_BUFFER_DURATION (ogg_mux->pulling->buffer);
+        GST_BUFFER_TIMESTAMP (pad->buffer) + GST_BUFFER_DURATION (pad->buffer);
     /* if the next packet in the current page is going to make the page 
      * too long, we need to flush */
     if (last_ts > ogg_mux->next_ts + ogg_mux->max_delay) {
       ogg_page page;
 
-      while (ogg_stream_flush (&ogg_mux->pulling->stream, &page)) {
-        gst_ogg_mux_push_page (ogg_mux, &page, ogg_mux->pulling->first_delta);
+      while (ogg_stream_flush (&pad->stream, &page)) {
+        gst_ogg_mux_push_page (ogg_mux, &page, pad->first_delta);
         /* increment the page number counter */
-        ogg_mux->pulling->pageno++;
-        ogg_mux->pulling->first_delta = TRUE;
+        pad->pageno++;
+        /* mark other pages as delta */
+        pad->first_delta = TRUE;
       }
+      pad->new_page = TRUE;
       ogg_mux->pulling = NULL;
     }
   }
@@ -961,6 +964,7 @@ gst_ogg_mux_loop (GstElement * element)
         gst_ogg_mux_push_page (ogg_mux, &page, pad->first_delta);
         /* increment the page number counter */
         pad->pageno++;
+        /* mark other pages as delta */
         pad->first_delta = TRUE;
       }
       pad->new_page = TRUE;
@@ -982,6 +986,12 @@ gst_ogg_mux_loop (GstElement * element)
           /* if we get it on the pad with deltaunits,
            * we mark the page as non delta */
           pad->first_delta = FALSE;
+        } else if (ogg_mux->delta_pad != NULL) {
+          /* if there are pads with delta frames, we
+           * must mark this one as delta */
+          pad->first_delta = TRUE;
+        } else {
+          pad->first_delta = FALSE;
         }
       }
       pad->new_page = FALSE;
@@ -1000,18 +1010,28 @@ gst_ogg_mux_loop (GstElement * element)
 
     /* let ogg write out the pages now. The packet we got could end 
      * up in more than one page so we need to write them all */
-    while (ogg_stream_pageout (&pad->stream, &page) > 0) {
-      /* we have a complete page now, we can push the page 
-       * and make sure to pull on a new pad the next time around */
+    if (ogg_stream_pageout (&pad->stream, &page) > 0) {
+      /* push the page */
       gst_ogg_mux_push_page (ogg_mux, &page, pad->first_delta);
-      /* increment the page number counter */
       pad->pageno++;
+      /* mark next pages as delta */
+      pad->first_delta = TRUE;
+
+      /* use an inner loop her to flush the remaining pages and
+       * mark them as delta frames as well */
+      while (ogg_stream_pageout (&pad->stream, &page) > 0) {
+        /* we have a complete page now, we can push the page 
+         * and make sure to pull on a new pad the next time around */
+        gst_ogg_mux_push_page (ogg_mux, &page, pad->first_delta);
+        /* increment the page number counter */
+        pad->pageno++;
+      }
+      /* need a new page as well */
+      pad->new_page = TRUE;
+      pad->duration = 0;
       /* we're done pulling on this pad, make sure to choose a new 
        * pad for pulling in the next iteration */
       ogg_mux->pulling = NULL;
-      pad->first_delta = TRUE;
-      pad->duration = 0;
-      pad->new_page = TRUE;
     }
   }
 }