From 22fe18c1c02a4b0fda7ca22d2927577cfa48d29f Mon Sep 17 00:00:00 2001 From: Baptiste Coudurier Date: Wed, 14 Jul 2010 23:21:18 +0000 Subject: In ogg muxer, use dyn buffer to compute crc of the page, fix muxing with pipe when page buffer is bigger than default buffer size. Max page is 65k. Originally committed as revision 24242 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/oggenc.c | 56 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'libavformat/oggenc.c') diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index c35b497496..01e4c01c2c 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -63,36 +63,50 @@ typedef struct { OGGPageList *page_list; } OGGContext; -static void ogg_update_checksum(AVFormatContext *s, int64_t crc_offset) +static void ogg_update_checksum(AVFormatContext *s, ByteIOContext *pb, int64_t crc_offset) { - 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); - url_fseek(s->pb, pos, SEEK_SET); + int64_t pos = url_ftell(pb); + uint32_t checksum = get_checksum(pb); + url_fseek(pb, crc_offset, SEEK_SET); + put_be32(pb, checksum); + url_fseek(pb, pos, SEEK_SET); } -static void ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags) +static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags) { OGGStreamContext *oggstream = s->streams[page->stream_index]->priv_data; + ByteIOContext *pb; int64_t crc_offset; + int ret, size; + uint8_t *buf; - init_checksum(s->pb, ff_crc04C11DB7_update, 0); - put_tag(s->pb, "OggS"); - put_byte(s->pb, 0); - put_byte(s->pb, page->flags | extra_flags); - put_le64(s->pb, page->granule); - put_le32(s->pb, oggstream->serial_num); - put_le32(s->pb, oggstream->page_counter++); - crc_offset = url_ftell(s->pb); - put_le32(s->pb, 0); // crc - put_byte(s->pb, page->segments_count); - put_buffer(s->pb, page->segments, page->segments_count); - put_buffer(s->pb, page->data, page->size); - - ogg_update_checksum(s, crc_offset); + ret = url_open_dyn_buf(&pb); + if (ret < 0) + return ret; + init_checksum(pb, ff_crc04C11DB7_update, 0); + put_tag(pb, "OggS"); + put_byte(pb, 0); + put_byte(pb, page->flags | extra_flags); + put_le64(pb, page->granule); + put_le32(pb, oggstream->serial_num); + put_le32(pb, oggstream->page_counter++); + crc_offset = url_ftell(pb); + put_le32(pb, 0); // crc + put_byte(pb, page->segments_count); + put_buffer(pb, page->segments, page->segments_count); + put_buffer(pb, page->data, page->size); + + ogg_update_checksum(s, pb, crc_offset); + put_flush_packet(pb); + + size = url_close_dyn_buf(pb, &buf); + if (size < 0) + return size; + + put_buffer(s->pb, buf, size); put_flush_packet(s->pb); oggstream->page_count--; + return 0; } static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, OGGPage *page) -- cgit v1.2.1