FFmpeg
Loading...
Searching...
No Matches
libopusenc.c File Reference
#include <opus.h>
#include <opus_multistream.h>
#include "libavutil/channel_layout.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "encode.h"
#include "libopus.h"
#include "audio_frame_queue.h"
#include "vorbis_data.h"

Go to the source code of this file.

Data Structures

struct  LibopusEncOpts
 
struct  LibopusEncContext
 

Macros

#define OFFSET(x)
 
#define FLAGS   AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static void libopus_write_header (AVCodecContext *avctx, int stream_count, int coupled_stream_count, int mapping_family, const uint8_t *channel_mapping)
 
static int libopus_configure_encoder (AVCodecContext *avctx, OpusMSEncoder *enc, LibopusEncOpts *opts)
 
static int libopus_check_max_channels (AVCodecContext *avctx, int max_channels)
 
static int libopus_check_vorbis_layout (AVCodecContext *avctx, int mapping_family)
 
static int libopus_validate_layout_and_get_channel_map (AVCodecContext *avctx, int mapping_family, const uint8_t **channel_map_result)
 
static av_cold int libopus_encode_init (AVCodecContext *avctx)
 
static void libopus_copy_samples_with_channel_map (uint8_t *dst, const uint8_t *src, const uint8_t *channel_map, int nb_channels, int nb_samples, int bytes_per_sample)
 
static int libopus_encode (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 
static av_cold int libopus_encode_close (AVCodecContext *avctx)
 

Variables

static const uint8_t opus_coupled_streams [8]
 
static const uint8_t opus_vorbis_channel_map [8][8]
 
static const uint8_t libavcodec_libopus_channel_map [8][8]
 
static const AVOption libopus_options []
 
static const AVClass libopus_class
 
static const FFCodecDefault libopus_defaults []
 
static const int libopus_sample_rates []
 
const FFCodec ff_libopus_encoder
 

Macro Definition Documentation

◆ OFFSET

#define OFFSET ( x)
Value:
offsetof(LibopusEncContext, opts.x)
static AVDictionary * opts

Definition at line 541 of file libopusenc.c.

◆ FLAGS

Definition at line 542 of file libopusenc.c.

Function Documentation

◆ libopus_write_header()

static void libopus_write_header ( AVCodecContext * avctx,
int stream_count,
int coupled_stream_count,
int mapping_family,
const uint8_t * channel_mapping )
static

Definition at line 90 of file libopusenc.c.

Referenced by libopus_encode_init().

◆ libopus_configure_encoder()

static int libopus_configure_encoder ( AVCodecContext * avctx,
OpusMSEncoder * enc,
LibopusEncOpts * opts )
static

Definition at line 114 of file libopusenc.c.

Referenced by libopus_encode_init().

◆ libopus_check_max_channels()

static int libopus_check_max_channels ( AVCodecContext * avctx,
int max_channels )
static

Definition at line 190 of file libopusenc.c.

Referenced by libopus_validate_layout_and_get_channel_map().

◆ libopus_check_vorbis_layout()

static int libopus_check_vorbis_layout ( AVCodecContext * avctx,
int mapping_family )
static

Definition at line 201 of file libopusenc.c.

Referenced by libopus_validate_layout_and_get_channel_map().

◆ libopus_validate_layout_and_get_channel_map()

static int libopus_validate_layout_and_get_channel_map ( AVCodecContext * avctx,
int mapping_family,
const uint8_t ** channel_map_result )
static

Definition at line 222 of file libopusenc.c.

Referenced by libopus_encode_init().

◆ libopus_encode_init()

static av_cold int libopus_encode_init ( AVCodecContext * avctx)
static

Definition at line 267 of file libopusenc.c.

◆ libopus_copy_samples_with_channel_map()

static void libopus_copy_samples_with_channel_map ( uint8_t * dst,
const uint8_t * src,
const uint8_t * channel_map,
int nb_channels,
int nb_samples,
int bytes_per_sample )
static

Definition at line 451 of file libopusenc.c.

Referenced by libopus_encode().

◆ libopus_encode()

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

Definition at line 465 of file libopusenc.c.

◆ libopus_encode_close()

static av_cold int libopus_encode_close ( AVCodecContext * avctx)
static

Definition at line 528 of file libopusenc.c.

Variable Documentation

◆ opus_coupled_streams

const uint8_t opus_coupled_streams[8]
static
Initial value:
= {
0, 1, 1, 2, 2, 2, 2, 3
}

Definition at line 62 of file libopusenc.c.

Referenced by libopus_encode_init().

◆ opus_vorbis_channel_map

const uint8_t opus_vorbis_channel_map[8][8]
static
Initial value:
= {
{ 0 },
{ 0, 1 },
{ 0, 2, 1 },
{ 0, 1, 2, 3 },
{ 0, 4, 1, 2, 3 },
{ 0, 4, 1, 2, 3, 5 },
{ 0, 4, 1, 2, 3, 5, 6 },
{ 0, 6, 1, 2, 3, 4, 5, 7 },
}

Definition at line 67 of file libopusenc.c.

Referenced by libopus_encode_init().

◆ libavcodec_libopus_channel_map

const uint8_t libavcodec_libopus_channel_map[8][8]
static
Initial value:
= {
{ 0 },
{ 0, 1 },
{ 0, 1, 2 },
{ 0, 1, 2, 3 },
{ 0, 1, 3, 4, 2 },
{ 0, 1, 4, 5, 2, 3 },
{ 0, 1, 5, 6, 2, 4, 3 },
{ 0, 1, 6, 7, 4, 5, 2, 3 },
}

Definition at line 79 of file libopusenc.c.

Referenced by libopus_encode_init().

◆ libopus_options

const AVOption libopus_options[]
static
Initial value:
= {
{ "application", "Intended application type", OFFSET(application), AV_OPT_TYPE_INT, { .i64 = OPUS_APPLICATION_AUDIO }, OPUS_APPLICATION_VOIP, OPUS_APPLICATION_RESTRICTED_LOWDELAY, FLAGS, .unit = "application" },
{ "voip", "Favor improved speech intelligibility", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_VOIP }, 0, 0, FLAGS, .unit = "application" },
{ "audio", "Favor faithfulness to the input", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_AUDIO }, 0, 0, FLAGS, .unit = "application" },
{ "lowdelay", "Restrict to only the lowest delay modes, disable voice-optimized modes", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_RESTRICTED_LOWDELAY }, 0, 0, FLAGS, .unit = "application" },
{ "frame_duration", "Duration of a frame in milliseconds", OFFSET(frame_duration), AV_OPT_TYPE_FLOAT, { .dbl = 20.0 }, 2.5, 120.0, FLAGS },
{ "packet_loss", "Expected packet loss percentage", OFFSET(packet_loss), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100, FLAGS },
{ "fec", "Enable inband FEC. Expected packet loss must be non-zero", OFFSET(fec), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ "vbr", "Variable bit rate mode", OFFSET(vbr), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 2, FLAGS, .unit = "vbr" },
{ "off", "Use constant bit rate", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, FLAGS, .unit = "vbr" },
{ "on", "Use variable bit rate", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, .unit = "vbr" },
{ "constrained", "Use constrained VBR", 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, FLAGS, .unit = "vbr" },
{ "mapping_family", "Channel Mapping Family", OFFSET(mapping_family), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 255, FLAGS, .unit = "mapping_family" },
{ "dtx", "Enable DTX (Discontinuous transmission)", OFFSET(dtx), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ NULL },
}
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326

Definition at line 543 of file libopusenc.c.

◆ libopus_class

const AVClass libopus_class
static
Initial value:
= {
.class_name = "libopus",
.item_name = av_default_item_name,
.option = libopus_options,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static const AVOption libopus_options[]
Definition libopusenc.c:543

Definition at line 563 of file libopusenc.c.

◆ libopus_defaults

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

Definition at line 570 of file libopusenc.c.

◆ libopus_sample_rates

const int libopus_sample_rates[]
static
Initial value:
= {
48000, 24000, 16000, 12000, 8000, 0,
}

Definition at line 576 of file libopusenc.c.

◆ ff_libopus_encoder

const FFCodec ff_libopus_encoder
Initial value:
= {
.p.name = "libopus",
CODEC_LONG_NAME("libopus Opus"),
.p.type = AVMEDIA_TYPE_AUDIO,
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
.priv_data_size = sizeof(LibopusEncContext),
.p.priv_class = &libopus_class,
.defaults = libopus_defaults,
.p.wrapper_name = "libopus",
}
#define CODEC_SAMPLERATES_ARRAY(array)
#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(...)
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#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:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition codec.h:84
@ AV_CODEC_ID_OPUS
Definition codec_id.h:513
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AV_SAMPLE_FMT_FLT
float
Definition samplefmt.h:60
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition samplefmt.h:58
static av_cold int libopus_encode_init(AVCodecContext *avctx)
Definition libopusenc.c:267
static const int libopus_sample_rates[]
Definition libopusenc.c:576
static av_cold int libopus_encode_close(AVCodecContext *avctx)
Definition libopusenc.c:528
static const FFCodecDefault libopus_defaults[]
Definition libopusenc.c:570
static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition libopusenc.c:465
static const AVClass libopus_class
Definition libopusenc.c:563

Definition at line 580 of file libopusenc.c.