22 #include "libavutil/crc.h"
23 #include "libavutil/mathematics.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/random_seed.h"
34 #define MAX_PAGE_SIZE 65025
74 #define OFFSET(x) offsetof(OGGContext, x)
75 #define PARAM AV_OPT_FLAG_ENCODING_PARAM
78 {
"oggpagesize",
"Set preferred Ogg page size.",
80 {
"pagesize",
"preferred page size in bytes (deprecated)",
82 {
"page_duration",
"preferred page duration, in microseconds",
150 return (granule>>oggstream->
kfgshift) +
151 (granule & ((1<<oggstream->
kfgshift)-1));
160 int64_t next_granule, cur_granule;
169 return next_granule > cur_granule;
212 int total_segments = size / 255 + 1;
231 if (!header && oggstream->
page.
size > 0 &&
236 for (i = 0; i < total_segments; ) {
247 len =
FFMIN(size, segments*255);
249 memcpy(page->
data+page->
size, p, len);
255 if (i == total_segments)
299 bytestream_put_byte(&p, 1);
322 bytestream_put_byte(&p, 0x7F);
324 bytestream_put_byte(&p, 1);
325 bytestream_put_byte(&p, 0);
326 bytestream_put_be16(&p, 1);
328 bytestream_put_byte(&p, 0x00);
329 bytestream_put_be24(&p, 34);
337 bytestream_put_byte(&p, 0x84);
338 bytestream_put_be24(&p, oggstream->
header_len[1] - 4);
343 #define SPEEX_HEADER_SIZE 80
372 #define OPUS_HEADER_SIZE 19
412 unsigned serial_num = i;
441 for (j = 0; j < i; j++) {
500 bytestream_put_byte(&p, header_type);
524 for (i = 1; i < 3; i++) {
573 if (pframe_count >= (1<<oggstream->
kfgshift)) {
584 oggstream->page.start_granule =
pkt->
pts;
592 oggstream->last_granule = granule;
628 .mime_type =
"application/ogg",
629 .extensions =
"ogg,ogv,spx,opus",
637 .priv_class = &ogg_muxer_class,
static int ogg_write_header(AVFormatContext *s)
int64_t last_granule
last packet granule
static int ogg_build_speex_headers(AVCodecContext *avctx, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
#define AV_LOG_WARNING
Something somehow does not look correct.
unsigned page_count
number of page buffered
#define LIBAVUTIL_VERSION_INT
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
AVCodecContext * codec
Codec context associated with this stream.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
uint8_t data[MAX_PAGE_SIZE]
int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, enum FLACExtradataFormat *format, uint8_t **streaminfo_start)
Validate the FLAC extradata.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
static int ogg_build_flac_headers(AVCodecContext *avctx, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
const char * av_default_item_name(void *ctx)
Return the context name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const uint8_t offset[511][2]
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
const OptionDef options[]
static const AVClass ogg_muxer_class
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int ogg_buffer_data(AVFormatContext *s, AVStream *st, uint8_t *data, unsigned size, int64_t granule, int header)
FLAC (Free Lossless Audio Codec) decoder/demuxer common functions.
void * priv_data
Format private data.
struct OGGPageList * next
int pref_size
preferred page size (0 => fill all segments)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int ogg_reset_cur_page(OGGStreamContext *oggstream)
static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
int flags
A combination of AV_PKT_FLAG values.
unsigned int nb_streams
A list of all streams in the file.
static int ogg_write_trailer(AVFormatContext *s)
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
static int write_trailer(AVFormatContext *s1)
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page)
#define FLAC_STREAMINFO_SIZE
#define SPEEX_HEADER_SIZE
static void flush(AVCodecContext *avctx)
static uint8_t * ogg_write_vorbiscomment(int offset, int bitexact, int *header_len, AVDictionary **m, int framing_bit)
enum AVMediaType codec_type
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int sample_rate
samples per second
main external API structure.
static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
AVIOContext * pb
I/O context.
static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
Describe the class of an AVClass context structure.
AVOutputFormat ff_ogg_muxer
rational number numerator/denominator
unsigned long ffio_get_checksum(AVIOContext *s)
int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size, int first_header_size, uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use. ...
unsigned serial_num
serial number
static int ogg_build_opus_headers(AVCodecContext *avctx, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
static int ogg_key_granule(OGGStreamContext *oggstream, int64_t granule)
int kfgshift
for theora granule
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
static void write_header(FFV1Context *f)
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
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)
static void ogg_write_pages(AVFormatContext *s, int flush)
This structure stores compressed data.
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...