]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/oggenc.c
Print all timebases (idea from netgem)
[ffmpeg] / libavformat / oggenc.c
index af2c5de1221601e5377d651ef24adad5e590f3f3..4fdae05c8f495b98f5352beb90f6110398e80abd 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/crc.h"
+#include "libavcodec/xiph.h"
+#include "libavcodec/bytestream.h"
 #include "avformat.h"
-#include "crc.h"
-#include "xiph.h"
-#include "bytestream.h"
+#include "internal.h"
 
 typedef struct {
     int64_t duration;
@@ -36,9 +37,9 @@ typedef struct {
     int eos;
 } OGGStreamContext;
 
-static void ogg_update_checksum(AVFormatContext *s, offset_t crc_offset)
+static void ogg_update_checksum(AVFormatContext *s, int64_t crc_offset)
 {
-    offset_t pos = url_ftell(s->pb);
+    int64_t pos = url_ftell(s->pb);
     uint32_t checksum = get_checksum(s->pb);
     url_fseek(s->pb, crc_offset, SEEK_SET);
     put_be32(s->pb, checksum);
@@ -49,7 +50,7 @@ static int ogg_write_page(AVFormatContext *s, const uint8_t *data, int size,
                           int64_t granule, int stream_index, int flags)
 {
     OGGStreamContext *oggstream = s->streams[stream_index]->priv_data;
-    offset_t crc_offset;
+    int64_t crc_offset;
     int page_segments, i;
 
     if (size >= 255*255) {
@@ -88,8 +89,8 @@ static int ogg_build_flac_headers(const uint8_t *extradata, int extradata_size,
     uint8_t *p;
     if (extradata_size != 34)
         return -1;
-    oggstream->header_len[0] = 79;
-    oggstream->header[0] = av_mallocz(79); // per ogg flac specs
+    oggstream->header_len[0] = 51;
+    oggstream->header[0] = av_mallocz(51); // per ogg flac specs
     p = oggstream->header[0];
     bytestream_put_byte(&p, 0x7F);
     bytestream_put_buffer(&p, "FLAC", 4);
@@ -202,36 +203,27 @@ static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
     return 0;
 }
 
-int ogg_interleave_per_granule(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
+static int ogg_compare_granule(AVFormatContext *s, AVPacket *next, AVPacket *pkt)
 {
-    AVPacketList *pktl, **next_point, *this_pktl;
+    AVStream *st2 = s->streams[next->stream_index];
+    AVStream *st  = s->streams[pkt ->stream_index];
+
+    int64_t next_granule = av_rescale_q(next->pts + next->duration,
+                                        st2->time_base, AV_TIME_BASE_Q);
+    int64_t cur_granule  = av_rescale_q(pkt ->pts + pkt ->duration,
+                                        st ->time_base, AV_TIME_BASE_Q);
+    return next_granule > cur_granule;
+}
+
+static int ogg_interleave_per_granule(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
+{
+    AVPacketList *pktl;
     int stream_count = 0;
     int streams[MAX_STREAMS] = {0};
     int interleaved = 0;
 
     if (pkt) {
-        AVStream *st = s->streams[pkt->stream_index];
-        this_pktl = av_mallocz(sizeof(AVPacketList));
-        this_pktl->pkt = *pkt;
-        if (pkt->destruct == av_destruct_packet)
-            pkt->destruct = NULL; // not shared -> must keep original from being freed
-        else
-            av_dup_packet(&this_pktl->pkt); // shared -> must dup
-        next_point = &s->packet_buffer;
-        while (*next_point) {
-            AVStream *st2 = s->streams[(*next_point)->pkt.stream_index];
-            AVPacket *next_pkt = &(*next_point)->pkt;
-            int64_t cur_granule, next_granule;
-            next_granule = av_rescale_q(next_pkt->pts + next_pkt->duration,
-                                        st2->time_base, AV_TIME_BASE_Q);
-            cur_granule = av_rescale_q(pkt->pts + pkt->duration,
-                                        st->time_base, AV_TIME_BASE_Q);
-            if (next_granule > cur_granule)
-                break;
-            next_point= &(*next_point)->next;
-        }
-        this_pktl->next= *next_point;
-        *next_point= this_pktl;
+        ff_interleave_add_packet(s, pkt, ogg_compare_granule);
     }
 
     pktl = s->packet_buffer;
@@ -279,9 +271,9 @@ static int ogg_write_trailer(AVFormatContext *s)
 
 AVOutputFormat ogg_muxer = {
     "ogg",
-    "Ogg format",
+    NULL_IF_CONFIG_SMALL("Ogg"),
     "application/ogg",
-    "ogg",
+    "ogg,ogv",
     0,
     CODEC_ID_FLAC,
     CODEC_ID_THEORA,