FFmpeg
Data Structures | Macros | Functions | Variables
enc.c File Reference
#include <float.h>
#include "encode.h"
#include "enc.h"
#include "pvq.h"
#include "enc_psy.h"
#include "tab.h"
#include "libavutil/channel_layout.h"
#include "libavutil/float_dsp.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavutil/opt.h"
#include "bytestream.h"
#include "audio_frame_queue.h"
#include "codec_internal.h"

Go to the source code of this file.

Data Structures

struct  OpusEncContext
 

Macros

#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 void celt_enc_tf (CeltFrame *f, OpusRangeCoder *rc)
 
static void celt_enc_quant_pfilter (OpusRangeCoder *rc, CeltFrame *f)
 
static void exp_quant_coarse (OpusRangeCoder *rc, CeltFrame *f, float last_energy[][CELT_MAX_BANDS], int intra)
 
static void celt_quant_coarse (CeltFrame *f, OpusRangeCoder *rc, float last_energy[][CELT_MAX_BANDS])
 
static void celt_quant_fine (CeltFrame *f, OpusRangeCoder *rc)
 
static void celt_quant_final (OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f)
 
static void celt_encode_frame (OpusEncContext *s, OpusRangeCoder *rc, CeltFrame *f, int index)
 
static int write_opuslacing (uint8_t *dst, int v)
 
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 FFCodecDefault opusenc_defaults []
 
const FFCodec ff_opus_encoder
 

Macro Definition Documentation

◆ OPUSENC_FLAGS

Definition at line 715 of file enc.c.

Function Documentation

◆ opus_write_extradata()

static void opus_write_extradata ( AVCodecContext avctx)
static

Definition at line 67 of file enc.c.

Referenced by opus_encode_init().

◆ opus_gen_toc()

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

Definition at line 80 of file enc.c.

Referenced by opus_packet_assembler().

◆ celt_frame_setup_input()

static void celt_frame_setup_input ( OpusEncContext s,
CeltFrame f 
)
static

Definition at line 123 of file enc.c.

Referenced by celt_encode_frame().

◆ celt_apply_preemph_filter()

static void celt_apply_preemph_filter ( OpusEncContext s,
CeltFrame f 
)
static

Definition at line 163 of file enc.c.

Referenced by celt_encode_frame().

◆ celt_frame_mdct()

static void celt_frame_mdct ( OpusEncContext s,
CeltFrame f 
)
static

Definition at line 198 of file enc.c.

Referenced by celt_encode_frame().

◆ celt_enc_tf()

static void celt_enc_tf ( CeltFrame f,
OpusRangeCoder rc 
)
static

Definition at line 263 of file enc.c.

Referenced by celt_encode_frame().

◆ celt_enc_quant_pfilter()

static void celt_enc_quant_pfilter ( OpusRangeCoder rc,
CeltFrame f 
)
static

Definition at line 290 of file enc.c.

Referenced by celt_encode_frame().

◆ exp_quant_coarse()

static void exp_quant_coarse ( OpusRangeCoder rc,
CeltFrame f,
float  last_energy[][CELT_MAX_BANDS],
int  intra 
)
static

Definition at line 327 of file enc.c.

Referenced by celt_quant_coarse().

◆ celt_quant_coarse()

static void celt_quant_coarse ( CeltFrame f,
OpusRangeCoder rc,
float  last_energy[][CELT_MAX_BANDS] 
)
static

Definition at line 370 of file enc.c.

Referenced by celt_encode_frame().

◆ celt_quant_fine()

static void celt_quant_fine ( CeltFrame f,
OpusRangeCoder rc 
)
static

Definition at line 390 of file enc.c.

Referenced by celt_encode_frame().

◆ celt_quant_final()

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

Definition at line 407 of file enc.c.

Referenced by celt_encode_frame().

◆ celt_encode_frame()

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

Definition at line 425 of file enc.c.

Referenced by opus_encode_frame().

◆ write_opuslacing()

static int write_opuslacing ( uint8_t *  dst,
int  v 
)
inlinestatic

Definition at line 490 of file enc.c.

Referenced by opus_packet_assembler().

◆ opus_packet_assembler()

static void opus_packet_assembler ( OpusEncContext s,
AVPacket avpkt 
)
static

Definition at line 497 of file enc.c.

Referenced by opus_encode_frame().

◆ spawn_empty_frame()

static AVFrame* spawn_empty_frame ( OpusEncContext s)
static

Definition at line 523 of file enc.c.

Referenced by opus_encode_frame(), and opus_encode_init().

◆ opus_encode_frame()

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

Definition at line 547 of file enc.c.

◆ opus_encode_end()

static av_cold int opus_encode_end ( AVCodecContext avctx)
static

Definition at line 615 of file enc.c.

◆ opus_encode_init()

static av_cold int opus_encode_init ( AVCodecContext avctx)
static

Definition at line 633 of file enc.c.

Variable Documentation

◆ opusenc_options

const AVOption opusenc_options[]
static
Initial value:
= {
{ "opus_delay", "Maximum delay in milliseconds", 0x42, AV_OPT_TYPE_FLOAT, { .dbl = OPUS_MAX_LOOKAHEAD }, 2.5f, OPUS_MAX_LOOKAHEAD, OPUSENC_FLAGS, .unit = "max_delay_ms" },
{ "apply_phase_inv", "Apply intensity stereo phase inversion", 0x42, AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, OPUSENC_FLAGS, .unit = "apply_phase_inv" },
{ NULL },
}

Definition at line 716 of file enc.c.

◆ opusenc_class

const AVClass opusenc_class
static
Initial value:
= {
.class_name = "Opus encoder",
.item_name = av_default_item_name,
.option = opusenc_options,
}

Definition at line 722 of file enc.c.

◆ opusenc_defaults

const FFCodecDefault opusenc_defaults[]
static
Initial value:
= {
{ "b", "0" },
{ "compression_level", "10" },
{ NULL },
}

Definition at line 729 of file enc.c.

◆ ff_opus_encoder

const FFCodec ff_opus_encoder
Initial value:
= {
.p.name = "opus",
CODEC_LONG_NAME("Opus"),
.p.type = AVMEDIA_TYPE_AUDIO,
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
.defaults = opusenc_defaults,
.p.priv_class = &opusenc_class,
.priv_data_size = sizeof(OpusEncContext),
.close = opus_encode_end,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.p.supported_samplerates = (const int []){ 48000, 0 },
.p.ch_layouts = (const AVChannelLayout []){ AV_CHANNEL_LAYOUT_MONO,
.p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
}

Definition at line 735 of file enc.c.

AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
opus_encode_init
static av_cold int opus_encode_init(AVCodecContext *avctx)
Definition: enc.c:633
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:393
opusenc_options
static const AVOption opusenc_options[]
Definition: enc.c:716
opusenc_class
static const AVClass opusenc_class
Definition: enc.c:722
OPUS_MAX_LOOKAHEAD
#define OPUS_MAX_LOOKAHEAD
Definition: enc.h:32
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
AV_CODEC_CAP_EXPERIMENTAL
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: codec.h:102
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
opus_encode_end
static av_cold int opus_encode_end(AVCodecContext *avctx)
Definition: enc.c:615
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
opusenc_defaults
static const FFCodecDefault opusenc_defaults[]
Definition: enc.c:729
opus_encode_frame
static int opus_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: enc.c:547
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:317
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:506
OpusEncContext
Definition: enc.c:39
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AV_CODEC_CAP_DELAY
#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: codec.h:76
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:392
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
AV_CODEC_CAP_SMALL_LAST_FRAME
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: codec.h:81
OPUSENC_FLAGS
#define OPUSENC_FLAGS
Definition: enc.c:715