FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
opusenc.c File Reference
#include "opus_celt.h"
#include "opus_pvq.h"
#include "opustab.h"
#include "libavutil/float_dsp.h"
#include "libavutil/opt.h"
#include "internal.h"
#include "bytestream.h"
#include "audio_frame_queue.h"
#include "libavfilter/bufferqueue.h"

Go to the source code of this file.

Data Structures

struct  OpusEncOptions
 
struct  OpusEncContext
 

Macros

#define FF_BUFQUEUE_SIZE   145
 
#define OPUS_MAX_LOOKAHEAD   ((FF_BUFQUEUE_SIZE - 1)*2.5f)
 
#define OPUS_MAX_CHANNELS   2
 
#define OPUS_MAX_FRAMES_PER_PACKET   48
 
#define OPUS_BLOCK_SIZE(x)   (2 * 15 * (1 << ((x) + 2)))
 
#define OPUS_SAMPLES_TO_BLOCK_SIZE(x)   (ff_log2((x) / (2 * 15)) - 2)
 
#define OPUSENC_FLAGS   AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
 

Functions

static void opus_write_extradata (AVCodecContext *avctx)
 
static int opus_gen_toc (OpusEncContext *s, uint8_t *toc, int *size, int *fsize_needed)
 
static void celt_frame_setup_input (OpusEncContext *s, CeltFrame *f)
 
static void celt_apply_preemph_filter (OpusEncContext *s, CeltFrame *f)
 
static void celt_frame_mdct (OpusEncContext *s, CeltFrame *f)
 
static int celt_frame_map_norm_bands (OpusEncContext *s, CeltFrame *f)
 
static void celt_enc_tf (OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f)
 
static void celt_bitalloc (OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f)
 
static void celt_quant_coarse (OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f)
 
static void celt_quant_fine (OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f)
 
static void celt_quant_final (OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f)
 
static void celt_quant_bands (OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f)
 
static void celt_encode_frame (OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f)
 
static void ff_opus_psy_process (OpusEncContext *s, int end, int *need_more)
 
static void ff_opus_psy_celt_frame_setup (OpusEncContext *s, CeltFrame *f, int index)
 
static void opus_packet_assembler (OpusEncContext *s, AVPacket *avpkt)
 
static AVFramespawn_empty_frame (OpusEncContext *s)
 
static int opus_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 
static av_cold int opus_encode_end (AVCodecContext *avctx)
 
static av_cold int opus_encode_init (AVCodecContext *avctx)
 

Variables

static const AVOption opusenc_options []
 
static const AVClass opusenc_class
 
static const AVCodecDefault opusenc_defaults []
 
AVCodec ff_opus_encoder
 

Macro Definition Documentation

#define FF_BUFQUEUE_SIZE   145

Definition at line 33 of file opusenc.c.

#define OPUS_MAX_LOOKAHEAD   ((FF_BUFQUEUE_SIZE - 1)*2.5f)

Definition at line 36 of file opusenc.c.

#define OPUS_MAX_CHANNELS   2

Definition at line 38 of file opusenc.c.

#define OPUS_MAX_FRAMES_PER_PACKET   48

Definition at line 41 of file opusenc.c.

Referenced by opus_encode_init().

#define OPUS_BLOCK_SIZE (   x)    (2 * 15 * (1 << ((x) + 2)))
#define OPUS_SAMPLES_TO_BLOCK_SIZE (   x)    (ff_log2((x) / (2 * 15)) - 2)

Definition at line 45 of file opusenc.c.

Referenced by ff_opus_psy_process().

Definition at line 1096 of file opusenc.c.

Function Documentation

static void opus_write_extradata ( AVCodecContext avctx)
static

Definition at line 76 of file opusenc.c.

Referenced by opus_encode_init().

static int opus_gen_toc ( OpusEncContext s,
uint8_t toc,
int size,
int fsize_needed 
)
static

Definition at line 89 of file opusenc.c.

Referenced by opus_packet_assembler().

static void celt_frame_setup_input ( OpusEncContext s,
CeltFrame f 
)
static

Definition at line 131 of file opusenc.c.

Referenced by celt_encode_frame().

static void celt_apply_preemph_filter ( OpusEncContext s,
CeltFrame f 
)
static

Definition at line 172 of file opusenc.c.

Referenced by celt_encode_frame().

static void celt_frame_mdct ( OpusEncContext s,
CeltFrame f 
)
static

Definition at line 207 of file opusenc.c.

Referenced by celt_encode_frame().

static int celt_frame_map_norm_bands ( OpusEncContext s,
CeltFrame f 
)
static

Definition at line 252 of file opusenc.c.

Referenced by celt_encode_frame().

static void celt_enc_tf ( OpusEncContext s,
OpusRangeCoder rc,
CeltFrame f 
)
static

Definition at line 287 of file opusenc.c.

Referenced by celt_encode_frame().

static void celt_bitalloc ( OpusEncContext s,
OpusRangeCoder rc,
CeltFrame f 
)
static

Definition at line 314 of file opusenc.c.

Referenced by celt_encode_frame().

static void celt_quant_coarse ( OpusEncContext s,
OpusRangeCoder rc,
CeltFrame f 
)
static

Definition at line 639 of file opusenc.c.

Referenced by celt_encode_frame().

static void celt_quant_fine ( OpusEncContext s,
OpusRangeCoder rc,
CeltFrame f 
)
static

Definition at line 682 of file opusenc.c.

Referenced by celt_encode_frame().

static void celt_quant_final ( OpusEncContext s,
OpusRangeCoder rc,
CeltFrame f 
)
static

Definition at line 700 of file opusenc.c.

Referenced by celt_encode_frame().

static void celt_quant_bands ( OpusEncContext s,
OpusRangeCoder rc,
CeltFrame f 
)
static

Definition at line 719 of file opusenc.c.

Referenced by celt_encode_frame().

static void celt_encode_frame ( OpusEncContext s,
OpusRangeCoder rc,
CeltFrame f 
)
static

Definition at line 812 of file opusenc.c.

Referenced by opus_encode_frame().

static void ff_opus_psy_process ( OpusEncContext s,
int  end,
int need_more 
)
static

Definition at line 858 of file opusenc.c.

Referenced by opus_encode_frame().

static void ff_opus_psy_celt_frame_setup ( OpusEncContext s,
CeltFrame f,
int  index 
)
static

Definition at line 873 of file opusenc.c.

Referenced by opus_encode_frame().

static void opus_packet_assembler ( OpusEncContext s,
AVPacket avpkt 
)
static

Definition at line 903 of file opusenc.c.

Referenced by opus_encode_frame().

static AVFrame* spawn_empty_frame ( OpusEncContext s)
static

Definition at line 919 of file opusenc.c.

Referenced by opus_encode_frame(), and opus_encode_init().

static int opus_encode_frame ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int got_packet_ptr 
)
static

Definition at line 939 of file opusenc.c.

static av_cold int opus_encode_end ( AVCodecContext avctx)
static

Definition at line 1008 of file opusenc.c.

static av_cold int opus_encode_init ( AVCodecContext avctx)
static

Definition at line 1026 of file opusenc.c.

Variable Documentation

const AVOption opusenc_options[]
static
Initial value:
= {
{ "opus_delay", "Maximum delay (and lookahead) in milliseconds", 0x42, AV_OPT_TYPE_FLOAT, { .dbl = OPUS_MAX_LOOKAHEAD }, 2.5f, OPUS_MAX_LOOKAHEAD, OPUSENC_FLAGS },
{ NULL },
}
#define NULL
Definition: coverity.c:32
#define OPUS_MAX_LOOKAHEAD
Definition: opusenc.c:36
#define OPUSENC_FLAGS
Definition: opusenc.c:1096

Definition at line 1097 of file opusenc.c.

const AVClass opusenc_class
static
Initial value:
= {
.class_name = "Opus encoder",
.item_name = av_default_item_name,
.option = opusenc_options,
}
static const AVOption opusenc_options[]
Definition: opusenc.c:1097
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
av_default_item_name

Definition at line 1102 of file opusenc.c.

const AVCodecDefault opusenc_defaults[]
static
Initial value:
= {
{ "b", "0" },
{ "compression_level", "10" },
{ NULL },
}
#define NULL
Definition: coverity.c:32

Definition at line 1109 of file opusenc.c.

AVCodec ff_opus_encoder
Initial value:
= {
.name = "opus",
.long_name = NULL_IF_CONFIG_SMALL("Opus"),
.defaults = opusenc_defaults,
.priv_class = &opusenc_class,
.priv_data_size = sizeof(OpusEncContext),
.encode2 = opus_encode_frame,
.close = opus_encode_end,
.supported_samplerates = (const int []){ 48000, 0 },
.channel_layouts = (const uint64_t []){ AV_CH_LAYOUT_MONO,
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
}
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
float, planar
Definition: samplefmt.h:69
static av_cold int opus_encode_init(AVCodecContext *avctx)
Definition: opusenc.c:1026
static const AVCodecDefault opusenc_defaults[]
Definition: opusenc.c:1109
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_cold int opus_encode_end(AVCodecContext *avctx)
Definition: opusenc.c:1008
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: avcodec.h:1049
#define AV_CH_LAYOUT_STEREO
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:1019
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
static int opus_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: opusenc.c:939
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: avcodec.h:1024
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
static const AVClass opusenc_class
Definition: opusenc.c:1102
#define AV_CH_LAYOUT_MONO

Definition at line 1115 of file opusenc.c.