21#include <vorbis/vorbisenc.h>
43#define LIBVORBIS_FRAME_SIZE 64
45#define BUFFER_SIZE (1024 * 64)
72 .class_name =
"libvorbis",
85 { 0, 2, 1, 5, 6, 4, 3 },
86 { 0, 2, 1, 6, 7, 4, 5, 3 },
93 case OV_EINVAL:
return AVERROR(EINVAL);
94 case OV_EIMPL:
return AVERROR(EINVAL);
115 if ((ret = vorbis_encode_setup_vbr(vi,
channels,
124 if ((ret = vorbis_encode_setup_managed(vi,
channels,
130 if (minrate == -1 && maxrate == -1)
131 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET,
NULL)))
137 cfreq = avctx->
cutoff / 1000.0;
138 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)))
144 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &
s->iblock)))
167 "output stream will have incorrect "
168 "channel layout.\n",
name);
171 "will use Vorbis channel layout for "
176 if ((ret = vorbis_encode_setup_init(vi)))
192 if ((ret = vorbis_analysis_init(&vd, vi))) {
196 if ((ret = vorbis_block_init(&vd, &vb))) {
198 vorbis_dsp_clear(&vd);
202 if ((ret = vorbis_analysis_wrote(&vd, 0)) < 0) {
209 if ((ret = vorbis_analysis_blockout(&vd, &vb)) == 1) {
210 if ((ret = vorbis_analysis(&vb,
NULL)) < 0) {
215 if ((ret = vorbis_bitrate_addblock(&vb)) < 0) {
222 ret = vorbis_bitrate_flushpacket(&vd, &
op);
233 vorbis_block_clear(&vb);
234 vorbis_dsp_clear(&vd);
242 return 1 + l / 255 + l;
250 if (
s->dsp_initialized)
251 vorbis_analysis_wrote(&
s->vd, 0);
253 vorbis_block_clear(&
s->vb);
254 vorbis_dsp_clear(&
s->vd);
255 vorbis_info_clear(&
s->vi);
271 vorbis_info_init(&
s->vi);
276 if ((ret = vorbis_analysis_init(&
s->vd, &
s->vi))) {
281 s->dsp_initialized = 1;
282 if ((ret = vorbis_block_init(&
s->vd, &
s->vb))) {
288 vorbis_comment_init(&
s->vc);
292 ret = vorbis_analysis_headerout(&
s->vd, &
s->vc, &
header, &header_comm,
294 vorbis_comment_clear(&
s->vc);
315 memcpy(&p[
offset], header_comm.packet, header_comm.bytes);
316 offset += header_comm.bytes;
317 memcpy(&p[
offset], header_code.packet, header_code.bytes);
318 offset += header_code.bytes;
354 const int samples =
frame->nb_samples;
358 buffer = vorbis_analysis_buffer(&
s->vd, samples);
365 if ((ret = vorbis_analysis_wrote(&
s->vd, samples)) < 0) {
372 if (!
s->eof &&
s->afq.frame_alloc)
373 if ((ret = vorbis_analysis_wrote(&
s->vd, 0)) < 0) {
381 while ((ret = vorbis_analysis_blockout(&
s->vd, &
s->vb)) == 1) {
382 if ((ret = vorbis_analysis(&
s->vb,
NULL)) < 0)
384 if ((ret = vorbis_bitrate_addblock(&
s->vb)) < 0)
388 while ((ret = vorbis_bitrate_flushpacket(&
s->vd, &
op)) == 1) {
428 .p.name =
"libvorbis",
442 .p.wrapper_name =
"libvorbis",
const FFCodec ff_libvorbis_encoder
static const FFCodecDefault defaults[]
av_cold void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
int ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, AVPacket *pkt)
Remove frame(s) from the queue.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
Public libavutil channel layout APIs header.
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define CODEC_SAMPLEFMTS(...)
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
Encode extradata length to a buffer.
int(* init)(AVBSFContext *ctx)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
static av_always_inline int64_t ff_samples_to_time_base(const AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
#define AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_5POINT0
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
#define AV_CHANNEL_LAYOUT_2_2
#define AV_CHANNEL_LAYOUT_5POINT0_BACK
#define AV_CHANNEL_LAYOUT_5POINT1
#define AV_CHANNEL_LAYOUT_SURROUND
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
#define AV_CHANNEL_LAYOUT_7POINT1
#define AV_CHANNEL_LAYOUT_QUAD
#define AV_CHANNEL_LAYOUT_6POINT1
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
size_t av_fifo_can_write(const AVFifo *f)
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
#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.
@ AV_SAMPLE_FMT_FLTP
float, planar
#define LIBAVUTIL_VERSION_INT
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Libavcodec version macros.
static av_cold int libvorbis_encode_close(AVCodecContext *avctx)
static int libvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static int vorbis_error_to_averror(int ov_err)
static const AVClass vorbis_class
static av_cold int libvorbis_get_priming_samples(vorbis_info *vi, AVCodecContext *avctx)
static av_cold int libvorbis_encode_init(AVCodecContext *avctx)
static const uint8_t vorbis_encoding_channel_layout_offsets[8][8]
#define LIBVORBIS_FRAME_SIZE
static int xiph_len(int l)
static av_cold int libvorbis_setup(vorbis_info *vi, AVCodecContext *avctx)
Memory handling functions.
static int ogg_packet(AVFormatContext *s, int *sid, int *dstart, int *dsize, int64_t *fpos)
find the next Ogg packet
static const uint8_t header[24]
An AVChannelLayout holds information about the channel layout of audio data.
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
int global_quality
Global quality for codecs which cannot change it per frame.
int64_t bit_rate
the average bitrate
int initial_padding
Audio only.
int sample_rate
samples per second
int64_t rc_max_rate
maximum bitrate
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int64_t rc_min_rate
minimum bitrate
int cutoff
Audio cutoff bandwidth (0 means "automatic")
int frame_size
Number of samples per channel in an audio frame.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
vorbis_dsp_state vd
DSP state used for analysis.
int dsp_initialized
vd has been initialized
AudioFrameQueue afq
frame queue for timestamps
vorbis_comment vc
VorbisComment info.
double iblock
impulse block bias option
AVVorbisParseContext vp
parse context to get durations
AVFifo * pkt_fifo
output packet buffer
AVClass * av_class
class for AVOptions
vorbis_info vi
vorbis_info used during init
vorbis_block vb
vorbis_block used for analysis
static void error(const char *err)
int av_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf, int buf_size)
Get the duration for a Vorbis packet.
int ff_vorbis_parse_init(AVVorbisParseContext *s, const uint8_t *extradata, int extradata_size)
A public API for Vorbis parsing.