22#include "config_components.h"
56#define OFFSET(x) offsetof(OGGContext, x)
57#define PARAM AV_OPT_FLAG_ENCODING_PARAM
62 {
"serial_offset",
"serial number offset, -1 to derive it from the stream headers",
64 {
"page_duration",
"preferred page duration, in microseconds",
70 .class_name =
"Ogg (audio/video/Speex/Opus) muxer",
80 for (
int i = 0;
i < 3;
i++)
88 uint8_t buf[4 + 1 + 1 + 8 + 4 + 4 + 4 + 1 + 255], *ptr = buf, *crc_pos;
92 bytestream_put_le32(&ptr,
MKTAG(
'O',
'g',
'g',
'S'));
93 bytestream_put_byte(&ptr, 0);
94 bytestream_put_byte(&ptr,
page->flags | extra_flags);
95 bytestream_put_le64(&ptr,
page->granule);
96 bytestream_put_le32(&ptr, oggstream->
serial_num);
99 bytestream_put_le32(&ptr, 0);
100 bytestream_put_byte(&ptr,
page->segments_count);
103 crc =
av_crc(crc_table, 0, buf, ptr - buf);
105 bytestream_put_be32(&crc_pos, crc);
127 int64_t next_granule, cur_granule;
136 return next_granule > cur_granule;
181 int total_segments =
size / 255 + 1;
182 const uint8_t *p =
data;
207 for (
i = 0;
i < total_segments; ) {
210 segments =
FFMIN(total_segments -
i, 255 -
page->segments_count);
212 if (
i && !
page->segments_count)
215 memset(
page->segments+
page->segments_count, 255, segments - 1);
216 page->segments_count += segments - 1;
219 page->segments[
page->segments_count++] =
len - (segments-1)*255;
227 if (
i == total_segments)
228 page->granule = granule;
238 if (
page->segments_count == 255) {
242 if (
ogg->pref_duration > 0 && next - start >=
ogg->pref_duration) {
259 AVChapter **chapters,
unsigned int nb_chapters)
288 int first_header_size,
int comment_type,
289 const char *
name,
int framing_bit)
297 oggstream->
header_len[0] < first_header_size) {
309 framing_bit,
NULL, 0);
314 bytestream_put_byte(&p, comment_type);
345 for (p =
ogg->page_list; p; ) {
347 s->streams[p->page.stream_index]->priv_data;
368 for (
int i = 0;
i < 3;
i++)
393 for (
i = 0;
i <
s->nb_streams;
i++) {
422 memset(oggstream, 0,
sizeof(*oggstream));
435 err = mapping->
init(
s, st);
440 serial_num =
i +
ogg->serial_offset;
459 for (j = 0; j <
s->nb_streams; j++) {
460 oggstream =
s->streams[j]->priv_data;
470 for (j = 0; j <
s->nb_streams; j++) {
473 for (
i = 1;
i < 3;
i++) {
503 if (!new_extradata) {
517 size_t metadata_size, extradata_size;
526 !memcmp(new_extradata, par->
extradata, extradata_size))
527 new_extradata =
NULL;
529 if (!side_metadata && !new_extradata)
536 "the stream headers are already written!\n");
540 if (
s->nb_streams > 1)
545 "This codec does not support starting a new Ogg link");
570 memcpy(par->
extradata, new_extradata, extradata_size);
594 if (oggcontext->
ended)
628 for (
i = 0;
i <
s->nb_streams;
i++) {
644 for (
i = 0;
i <
s->nb_streams;
i++) {
663 for (
i = 0;
i <
s->nb_streams;
i++) {
681 .p.mime_type =
"application/ogg",
682 .p.extensions =
"ogg"
689#if !CONFIG_OPUS_MUXER
694 .
p.audio_codec = CONFIG_LIBVORBIS_ENCODER ?
712 .p.mime_type =
"audio/ogg",
713 .p.extensions =
"oga",
731 .p.mime_type =
"video/ogg",
732 .p.extensions =
"ogv",
734 .
p.audio_codec = CONFIG_LIBVORBIS_ENCODER ?
736 .
p.video_codec = CONFIG_LIBTHEORA_ENCODER ?
753 .p.mime_type =
"audio/ogg",
754 .p.extensions =
"spx",
772 .p.mime_type =
"audio/ogg",
773 .p.extensions =
"opus",
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
void avio_w8(AVIOContext *s, int b)
@ AVIO_DATA_MARKER_FLUSH_POINT
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void ffio_init_write_context(FFIOContext *s, uint8_t *buffer, int buffer_size)
Wrap a buffer in an AVIOContext for writing.
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static void deinit(AVFormatContext *s)
Public header for CRC hash function implementation.
void(* flush)(AVBSFContext *ctx)
int(* init)(AVBSFContext *ctx)
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static unsigned int nb_streams
static void write_header(FFV1Context *f)
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
int av_packet_unpack_dictionary(const uint8_t *data, size_t size, AVDictionary **dict)
Unpack a dictionary from side_data.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define MKTAG(a, b, c, d)
Memory handling functions.
#define FF_OFMT_FLAG_ALLOW_FLUSH
This flag indicates that the muxer stores data internally and supports flushing it.
static int ogg_write_header(AVFormatContext *s)
static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page)
static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
static void ogg_cleanup_stream(AVStream *st)
static int ogg_key_granule(const OGGStreamContext *oggstream, int64_t granule)
static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
static void ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
static int ogg_reset_cur_page(OGGStreamContext *oggstream)
static const OGGMuxerMapping * ogg_find_mapping(enum AVCodecID codec_id)
static const AVClass ogg_muxer_class
static int ogg_serial_in_use(AVFormatContext *s, int nb_streams, unsigned serial_num)
static unsigned ogg_bitexact_serial(const OGGStreamContext *oggstream, unsigned seed)
Derive a bitexact serial number from the stream's header packets, which makes links muxed apart unlik...
static int ogg_skip_new_link(AVFormatContext *s, const uint8_t *new_extradata, const char *reason)
Keep the current link when a new one cannot be started.
static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
static const OGGMuxerMapping *const ogg_mappings[]
static int ogg_check_new_link(AVFormatContext *s, AVPacket *pkt)
static void ogg_free(AVFormatContext *s)
static void ogg_write_pages(AVFormatContext *s, int flush)
static int64_t ogg_granule_to_timestamp(const OGGStreamContext *oggstream, int64_t granule)
static int ogg_init(AVFormatContext *s)
static int ogg_write_trailer(AVFormatContext *s)
int ff_ogg_build_xiph_headers(AVFormatContext *s, AVStream *st, int first_header_size, int comment_type, const char *name, int framing_bit)
Build the headers of a codec using the Xiph header layout: identification, comment and setup packets ...
uint8_t * ff_ogg_write_vorbiscomment(int64_t offset, int bitexact, int *header_len, AVDictionary **m, int framing_bit, AVChapter **chapters, unsigned int nb_chapters)
Allocate a comment header packet holding a VorbisComment.
static int ogg_buffer_data(AVFormatContext *s, AVStream *st, const uint8_t *data, unsigned size, int64_t granule, int header)
const OGGMuxerMapping ff_ogg_speex_muxer_mapping
const OGGMuxerMapping ff_ogg_theora_muxer_mapping
const OGGMuxerMapping ff_ogg_vp8_muxer_mapping
const OGGMuxerMapping ff_ogg_flac_muxer_mapping
const OGGMuxerMapping ff_ogg_vorbis_muxer_mapping
const OGGMuxerMapping ff_ogg_opus_muxer_mapping
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
static uint8_t page[OGG_PAGE_MAX_SIZE]
static const uint16_t table[]
static const uint8_t header[24]
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
This struct describes the properties of an encoded stream.
int extradata_size
Size of the extradata content in bytes.
enum AVMediaType codec_type
General type of the encoded data.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int64_t pref_duration
preferred page duration (0 => fill all segments)
int ended
a new link could not be started, the packets that follow are dropped
Codec mapping of the muxer: the parts of the Ogg encapsulation that depend on the codec.
int new_links
a new link can replace the current one
int(* init)(AVFormatContext *s, AVStream *st)
Build the header packets in OGGStreamContext.header, adjusting the stream time base when the codec se...
size_t priv_data_size
size of OGGStreamContext.priv_data
int optional_extradata
the headers can be built without extradata
const char *(* new_link_refused)(const AVStream *st, const AVPacket *pkt, const uint8_t *new_extradata, size_t size)
int64_t(* packet_granule)(AVStream *st, const AVPacket *pkt)
struct OGGPageList * next
unsigned granule_shift
Granule layout, set by the mapping.
unsigned serial_num
serial number
unsigned page_count
number of page buffered
const OGGMuxerMapping * mapping
void * priv_data
state of the mapping
int packet_granule_offset
added to the end timestamp of a packet without packet_granule
int64_t granule_delta_mask
int64_t granule_key_mask
bits all clear on keyframes, 0 when no granule marks one
int packet_seen
true when packets have been submitted
int64_t last_granule
last packet granule
static int write_trailer(AVFormatContext *s1)
int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size, int first_header_size, const uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use.