Go to the documentation of this file.
89 #define SPDIF_FLAG_BIGENDIAN 0x01
98 {
"spdif_flags",
"IEC 61937 encapsulation flags", offsetof(
IEC61937Context, spdif_flags),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM, .unit =
"spdif_flags" },
100 {
"dtshd_rate",
"mux complete DTS frames in HD mode at the specified IEC958 rate (in Hz, default 0=disabled)", offsetof(
IEC61937Context, dtshd_rate),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 768000,
AV_OPT_FLAG_ENCODING_PARAM },
101 {
"dtshd_fallback_time",
"min secs to strip HD for after an overflow (-1: till the end, default 60)", offsetof(
IEC61937Context, dtshd_fallback),
AV_OPT_TYPE_INT, {.i64 = 60}, -1, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM },
115 int bitstream_mode =
pkt->
data[5] & 0x7;
125 static const uint8_t eac3_repeat[4] = {6, 3, 2, 1};
130 if (bsid > 10 && (
pkt->
data[4] & 0xc0) != 0xc0)
131 repeat = eac3_repeat[(
pkt->
data[4] & 0x30) >> 4];
141 if (++
ctx->hd_buf_count < repeat){
146 ctx->pkt_offset = 24576;
147 ctx->out_buf =
ctx->hd_buf[0];
148 ctx->out_bytes =
ctx->hd_buf_filled;
149 ctx->length_code =
ctx->hd_buf_filled;
151 ctx->hd_buf_count = 0;
152 ctx->hd_buf_filled = 0;
166 case 512:
return 0x0;
167 case 1024:
return 0x1;
168 case 2048:
return 0x2;
169 case 4096:
return 0x3;
170 case 8192:
return 0x4;
171 case 16384:
return 0x5;
177 int sample_rate,
int blocks)
180 static const char dtshd_start_code[10] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe };
195 period =
ctx->dtshd_rate * (blocks << 5) / sample_rate;
200 "impossible repetition period of %d for the current DTS stream"
201 " (blocks = %d, sample rate = %d)\n",
ctx->dtshd_rate,
period,
202 blocks << 5, sample_rate);
216 if (
sizeof(dtshd_start_code) + 2 + pkt_size
218 if (!
ctx->dtshd_skip)
220 "temporarily sending core only\n");
221 if (
ctx->dtshd_fallback > 0)
222 ctx->dtshd_skip = sample_rate *
ctx->dtshd_fallback / (blocks << 5);
228 if (
ctx->dtshd_skip && core_size) {
229 pkt_size = core_size;
230 if (
ctx->dtshd_fallback >= 0)
234 ctx->out_bytes =
sizeof(dtshd_start_code) + 2 + pkt_size;
238 ctx->length_code =
FFALIGN(
ctx->out_bytes + 0x8, 0x10) - 0x8;
244 ctx->out_buf =
ctx->hd_buf[0];
246 memcpy(
ctx->hd_buf[0], dtshd_start_code,
sizeof(dtshd_start_code));
247 AV_WB16(
ctx->hd_buf[0] +
sizeof(dtshd_start_code), pkt_size);
248 memcpy(
ctx->hd_buf[0] +
sizeof(dtshd_start_code) + 2,
pkt->
data, pkt_size);
264 switch (syncword_dts) {
272 ctx->extra_bswap = 1;
281 ctx->extra_bswap = 1;
310 if (core_size && core_size < pkt->
size) {
311 ctx->out_bytes = core_size;
312 ctx->length_code = core_size << 3;
315 ctx->pkt_offset = blocks << 7;
317 if (
ctx->out_bytes ==
ctx->pkt_offset) {
321 ctx->use_preamble = 0;
340 int layer = 3 - ((
pkt->
data[1] >> 1) & 3);
341 int extension =
pkt->
data[2] & 1;
343 if (layer == 3 ||
version == 1) {
348 if (
version == 2 && extension) {
350 ctx->pkt_offset = 4608;
385 "%"PRIu32
" samples in AAC frame not supported\n",
samples);
397 #define MAT_PKT_OFFSET 61440
398 #define MAT_FRAME_SIZE 61424
401 0x07, 0x9E, 0x00, 0x03, 0x84, 0x01, 0x01, 0x01, 0x80, 0x00, 0x56, 0xA5, 0x3B, 0xF4, 0x81, 0x83,
402 0x49, 0x80, 0x77, 0xE0,
405 0xC3, 0xC1, 0x42, 0x49, 0x3B, 0xFA, 0x82, 0x83, 0x49, 0x80, 0x77, 0xE0,
408 0xC3, 0xC2, 0xC0, 0xC4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x11,
411 #define MAT_CODE(position, data) { .pos = position, .code = data, .len = sizeof(data) }
413 static const struct {
426 uint8_t *hd_buf =
ctx->hd_buf[
ctx->hd_buf_idx];
428 int padding_remaining = 0;
429 uint16_t input_timing;
430 int total_frame_size =
pkt->
size;
431 const uint8_t *dataptr =
pkt->
data;
432 int data_remaining =
pkt->
size;
448 ctx->truehd_samples_per_frame = 40 << (ratebits & 3);
450 ctx->truehd_samples_per_frame);
453 if (!
ctx->truehd_samples_per_frame)
457 if (
ctx->truehd_prev_size) {
458 uint16_t delta_samples = input_timing -
ctx->truehd_prev_time;
468 int delta_bytes = delta_samples * 2560 /
ctx->truehd_samples_per_frame;
471 padding_remaining = delta_bytes -
ctx->truehd_prev_size;
474 delta_samples, delta_bytes);
477 if (padding_remaining < 0 || padding_remaining >=
MAT_FRAME_SIZE / 2) {
479 ctx->truehd_prev_time, input_timing,
ctx->truehd_samples_per_frame);
480 padding_remaining = 0;
491 while (padding_remaining || data_remaining ||
496 int code_len =
mat_codes[next_code_idx].len;
497 int code_len_remaining = code_len;
500 ctx->hd_buf_filled += code_len;
508 ctx->out_buf = hd_buf;
509 ctx->hd_buf_idx ^= 1;
510 hd_buf =
ctx->hd_buf[
ctx->hd_buf_idx];
511 ctx->hd_buf_filled = 0;
517 if (padding_remaining) {
519 int counted_as_padding =
FFMIN(padding_remaining,
521 padding_remaining -= counted_as_padding;
522 code_len_remaining -= counted_as_padding;
525 if (code_len_remaining)
526 total_frame_size += code_len_remaining;
529 if (padding_remaining) {
533 memset(hd_buf +
ctx->hd_buf_filled, 0, padding_to_insert);
534 ctx->hd_buf_filled += padding_to_insert;
535 padding_remaining -= padding_to_insert;
537 if (padding_remaining)
541 if (data_remaining) {
545 memcpy(hd_buf +
ctx->hd_buf_filled, dataptr, data_to_insert);
546 ctx->hd_buf_filled += data_to_insert;
547 dataptr += data_to_insert;
548 data_remaining -= data_to_insert;
552 ctx->truehd_prev_size = total_frame_size;
553 ctx->truehd_prev_time = input_timing;
556 total_frame_size,
ctx->hd_buf_filled);
574 switch (
s->streams[0]->codecpar->codec_id) {
603 s->streams[0]->codecpar->codec_id);
634 ctx->use_preamble = 1;
635 ctx->extra_bswap = 0;
640 if (!
ctx->pkt_offset)
649 if (
ctx->use_preamble) {
667 if (
ctx->out_bytes & 1)
673 ctx->data_type,
ctx->out_bytes,
ctx->pkt_offset);
681 .p.extensions =
"spdif",
int truehd_samples_per_frame
samples per frame for padding calculation
static enum IEC61937DataType mpeg_data_type[2][3]
int extra_bswap
extra bswap for payload (for LE DTS => standard BE DTS)
#define AV_LOG_WARNING
Something somehow does not look correct.
@ IEC61937_MPEG2_AAC_LSF_4096
MPEG-2 AAC ADTS quarter-rate low sampling frequency.
static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt)
uint16_t truehd_prev_time
input_timing from the last frame
int truehd_prev_size
previous frame size in bytes, including any MAT codes
#define DCA_SYNCWORD_CORE_14B_BE
int pkt_offset
data burst repetition period in bytes
static const uint8_t mat_start_code[20]
int buffer_size
size of allocated buffer
static int spdif_header_truehd(AVFormatContext *s, AVPacket *pkt)
@ IEC61937_MPEG2_LAYER1_LSF
MPEG-2, layer-1 low sampling frequency.
static av_always_inline void spdif_put_16(IEC61937Context *ctx, AVIOContext *pb, unsigned int val)
int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames)
Extract the number of samples and frames from AAC data.
void avio_wl16(AVIOContext *s, unsigned int val)
static const AVClass spdif_class
if it could not because there are no more frames
static double val(void *priv, double ch)
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
static int spdif_header_dts4(AVFormatContext *s, AVPacket *pkt, int core_size, int sample_rate, int blocks)
#define SPDIF_FLAG_BIGENDIAN
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
void ff_spdif_bswap_buf16(uint16_t *dst, const uint16_t *src, int w)
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
@ IEC61937_MPEG2_EXT
MPEG-2 data with extension.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
const uint32_t ff_dca_sample_rates[16]
enum IEC61937DataType data_type
burst info - reference to type of payload of the data-burst
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without period
static int spdif_header_dts(AVFormatContext *s, AVPacket *pkt)
const char * av_default_item_name(void *ptr)
Return the context name.
int hd_buf_count
number of frames in the hd audio buffer (eac3)
@ IEC61937_DTSHD
DTS HD data.
void ffio_fill(AVIOContext *s, int b, int64_t count)
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
@ IEC61937_DTS3
DTS type III (2048 samples)
static const struct @416 mat_codes[]
@ IEC61937_MPEG1_LAYER23
MPEG-1 layer 2 or 3 data or MPEG-2 without extension.
static int spdif_header_eac3(AVFormatContext *s, AVPacket *pkt)
#define DCA_SYNCWORD_CORE_BE
const uint8_t * out_buf
pointer to the outgoing data before byte-swapping
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int(* header_info)(AVFormatContext *s, AVPacket *pkt)
function, which generates codec dependent header information.
@ IEC61937_DTS2
DTS type II (1024 samples)
static const uint8_t mat_end_code[16]
int out_bytes
amount of outgoing bytes
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define DCA_SYNCWORD_CORE_14B_LE
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int length_code
length code in bits or bytes, depending on data type
@ IEC61937_DTS1
DTS type I (512 samples)
static int spdif_write_header(AVFormatContext *s)
uint8_t * buffer
allocated buffer, used for swap bytes
#define i(width, name, range_min, range_max)
#define FF_OFMT_FLAG_MAX_ONE_OF_EACH
If this flag is set, it indicates that for each codec type whose corresponding default codec (i....
int dtshd_skip
counter used for skipping DTS-HD frames
int use_preamble
preamble enabled (disabled for exactly pre-padded DTS)
@ IEC61937_MPEG1_LAYER1
MPEG-1 layer 1.
@ IEC61937_EAC3
E-AC-3 data.
#define DCA_SYNCWORD_SUBSTREAM
@ IEC61937_MPEG2_AAC_LSF_2048
MPEG-2 AAC ADTS half-rate low sampling frequency.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define AV_INPUT_BUFFER_PADDING_SIZE
int hd_buf_size
size of the hd audio buffer (eac3, dts4)
#define BURST_HEADER_SIZE
static int spdif_dts4_subtype(int period)
@ IEC61937_TRUEHD
TrueHD data.
@ AV_OPT_TYPE_INT
Underlying C type is int.
Filter the word “frame” indicates either a video frame or a group of audio samples
int hd_buf_filled
amount of bytes in the hd audio buffer (eac3, truehd)
#define MAT_CODE(position, data)
uint8_t * hd_buf[2]
allocated buffers to concatenate hd audio frames
#define DCA_SYNCWORD_CORE_LE
@ IEC61937_MPEG2_LAYER2_LSF
MPEG-2, layer-2 low sampling frequency.
#define avpriv_request_sample(...)
This structure stores compressed data.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
static int spdif_header_ac3(AVFormatContext *s, AVPacket *pkt)
static const uint8_t mat_middle_code[12]
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
void avio_wb16(AVIOContext *s, unsigned int val)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
const FFOutputFormat ff_spdif_muxer
static const AVOption options[]
@ IEC61937_MPEG2_AAC
MPEG-2 AAC ADTS.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void spdif_deinit(AVFormatContext *s)
int hd_buf_idx
active hd buffer index (truehd)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
static const uint16_t spdif_mpeg_pkt_offset[2][3]
@ IEC61937_MPEG2_LAYER3_LSF
MPEG-2, layer-3 low sampling frequency.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16