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; int64_t crc_offset; int page_segments, i; if (size >= 255*255) { granule = -1; size = 255*255; } else if (oggstream->eos) flags |= 4; page_segments = FFMIN((size/255)+!!size, 255); init_checksum(s->pb, ff_crc04C11DB7_update, 0); put_tag(s->pb, "OggS"); put_byte(s->pb, 0); put_byte(s->pb, flags); put_le64(s->pb, granule); put_le32(s->pb, stream_index); 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); for (i = 0; i < page_segments-1; i++) put_byte(s->pb, 255); if (size) { put_byte(s->pb, size - (page_segments-1)*255); put_buffer(s->pb, data, size); } ogg_update_checksum(s, crc_offset); put_flush_packet(s->pb); return size; }
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; 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); av_free(buf); oggstream->page_count--; return 0; }
static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags) { OGGStreamContext *oggstream = (OGGStreamContext *)s->streams[page->stream_index]->priv_data; AVIOContext *pb; int64_t crc_offset; int ret, size; uint8_t *buf; ret = avio_open_dyn_buf(&pb); if (ret < 0) return ret; ffio_init_checksum(pb, ff_crc04C11DB7_update, 0); ffio_wfourcc(pb, (const uint8_t *)"OggS"); avio_w8(pb, 0); avio_w8(pb, page->flags | extra_flags); avio_wl64(pb, page->granule); avio_wl32(pb, oggstream->serial_num); avio_wl32(pb, oggstream->page_counter++); crc_offset = avio_tell(pb); avio_wl32(pb, 0); // crc avio_w8(pb, page->segments_count); avio_write(pb, page->segments, page->segments_count); avio_write(pb, page->data, page->size); ogg_update_checksum(s, pb, crc_offset); avio_flush(pb); size = avio_close_dyn_buf(pb, &buf); if (size < 0) return size; avio_write(s->pb, buf, size); avio_flush(s->pb); av_free(buf); oggstream->page_count--; return 0; }