87 #define SPDIF_FLAG_BIGENDIAN 0x01 96 {
"spdif_flags",
"IEC 61937 encapsulation flags", offsetof(
IEC61937Context,
spdif_flags),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM,
"spdif_flags" },
98 {
"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 },
99 {
"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 },
113 int bitstream_mode = pkt->
data[5] & 0x7;
123 static const uint8_t eac3_repeat[4] = {6, 3, 2, 1};
126 int bsid = pkt->
data[5] >> 3;
127 if (bsid > 10 && (pkt->
data[4] & 0xc0) != 0xc0)
128 repeat = eac3_repeat[(pkt->
data[4] & 0x30) >> 4];
162 case 512:
return 0x0;
163 case 1024:
return 0x1;
164 case 2048:
return 0x2;
165 case 4096:
return 0x3;
166 case 8192:
return 0x4;
167 case 16384:
return 0x5;
176 static const char dtshd_start_code[10] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe };
177 int pkt_size = pkt->
size;
191 period = ctx->
dtshd_rate * (blocks << 5) / sample_rate;
196 "impossible repetition period of %d for the current DTS stream" 197 " (blocks = %d, sample rate = %d)\n", ctx->
dtshd_rate, period,
198 blocks << 5, sample_rate);
212 if (
sizeof(dtshd_start_code) + 2 + pkt_size
216 "temporarily sending core only\n");
225 pkt_size = core_size;
230 ctx->
out_bytes =
sizeof(dtshd_start_code) + 2 + pkt_size;
242 memcpy(ctx->
hd_buf[0], dtshd_start_code,
sizeof(dtshd_start_code));
243 AV_WB16(ctx->
hd_buf[0] +
sizeof(dtshd_start_code), pkt_size);
244 memcpy(ctx->
hd_buf[0] +
sizeof(dtshd_start_code) + 2, pkt->
data, pkt_size);
260 switch (syncword_dts) {
263 core_size = ((
AV_RB24(pkt->
data + 5) >> 4) & 0x3fff) + 1;
272 (((pkt->
data[5] & 0x07) << 4) | ((pkt->
data[6] & 0x3f) >> 2));
276 (((pkt->
data[4] & 0x07) << 4) | ((pkt->
data[7] & 0x3f) >> 2));
306 if (core_size && core_size < pkt->
size) {
336 int layer = 3 - ((pkt->
data[1] >> 1) & 3);
337 int extension = pkt->
data[2] & 1;
339 if (layer == 3 || version == 1) {
343 av_log(s,
AV_LOG_DEBUG,
"version: %i layer: %i extension: %i\n", version, layer, extension);
344 if (version == 2 && extension) {
381 "%"PRIu32
" samples in AAC frame not supported\n", samples);
393 #define MAT_PKT_OFFSET 61440 394 #define MAT_FRAME_SIZE 61424 397 0x07, 0x9E, 0x00, 0x03, 0x84, 0x01, 0x01, 0x01, 0x80, 0x00, 0x56, 0xA5, 0x3B, 0xF4, 0x81, 0x83,
398 0x49, 0x80, 0x77, 0xE0,
401 0xC3, 0xC1, 0x42, 0x49, 0x3B, 0xFA, 0x82, 0x83, 0x49, 0x80, 0x77, 0xE0,
404 0xC3, 0xC2, 0xC0, 0xC4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x11,
407 #define MAT_CODE(position, data) { .pos = position, .code = data, .len = sizeof(data) } 409 static const struct {
424 int padding_remaining = 0;
425 uint16_t input_timing;
426 int total_frame_size = pkt->
size;
428 int data_remaining = pkt->
size;
437 if (pkt->
data[7] == 0xba)
438 ratebits = pkt->
data[8] >> 4;
439 else if (pkt->
data[7] == 0xbb)
440 ratebits = pkt->
data[9] >> 4;
470 delta_samples, delta_bytes);
473 if (padding_remaining < 0 || padding_remaining >=
MAT_FRAME_SIZE / 2) {
476 padding_remaining = 0;
487 while (padding_remaining || data_remaining ||
492 int code_len =
mat_codes[next_code_idx].len;
493 int code_len_remaining = code_len;
513 if (padding_remaining) {
515 int counted_as_padding =
FFMIN(padding_remaining,
517 padding_remaining -= counted_as_padding;
518 code_len_remaining -= counted_as_padding;
521 if (code_len_remaining)
522 total_frame_size += code_len_remaining;
525 if (padding_remaining) {
531 padding_remaining -= padding_to_insert;
533 if (padding_remaining)
537 if (data_remaining) {
541 memcpy(hd_buf + ctx->
hd_buf_filled, dataptr, data_to_insert);
543 dataptr += data_to_insert;
544 data_remaining -= data_to_insert;
677 .extensions =
"spdif",
685 .priv_class = &spdif_class,
MPEG-2 AAC ADTS half-rate low sampling frequency.
uint8_t * out_buf
pointer to the outgoing data before byte-swapping
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
int hd_buf_idx
active hd buffer index (truehd)
uint8_t * hd_buf[2]
allocated buffers to concatenate hd audio frames
void avio_wl16(AVIOContext *s, unsigned int val)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int truehd_prev_size
previous frame size in bytes, including any MAT codes
int pkt_offset
data burst repetition period in bytes
static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
#define BURST_HEADER_SIZE
MPEG-2, layer-1 low sampling frequency.
static int spdif_dts4_subtype(int period)
#define avpriv_request_sample(...)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
const char * av_default_item_name(void *ptr)
Return the context name.
static const uint8_t mat_start_code[20]
static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt)
int truehd_samples_per_frame
samples per frame for padding calculation
static int spdif_header_dts(AVFormatContext *s, AVPacket *pkt)
void ff_spdif_bswap_buf16(uint16_t *dst, const uint16_t *src, int w)
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
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
if it could not because there are no more frames
static int spdif_header_eac3(AVFormatContext *s, AVPacket *pkt)
static const uint8_t mat_middle_code[12]
int buffer_size
size of allocated buffer
static void spdif_deinit(AVFormatContext *s)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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.
static const AVClass spdif_class
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define DCA_SYNCWORD_CORE_14B_BE
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
AVStream ** streams
A list of all streams in the file.
AVOutputFormat ff_spdif_muxer
#define SPDIF_FLAG_BIGENDIAN
DTS type II (1024 samples)
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
#define DCA_SYNCWORD_CORE_BE
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
DTS type III (2048 samples)
#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.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
preferred ID for decoding MPEG audio layer 1, 2 or 3
MPEG-1 layer 2 or 3 data or MPEG-2 without extension.
MPEG-2, layer-3 low sampling frequency.
int hd_buf_count
number of frames in the hd audio buffer (eac3)
#define DCA_SYNCWORD_CORE_14B_LE
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
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
#define MAT_CODE(position, data)
void ffio_fill(AVIOContext *s, int b, int count)
uint8_t * buffer
allocated buffer, used for swap bytes
int out_bytes
amount of outgoing bytes
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.
const uint32_t avpriv_dca_sample_rates[16]
static av_always_inline void spdif_put_16(IEC61937Context *ctx, AVIOContext *pb, unsigned int val)
enum IEC61937DataType data_type
burst info - reference to type of payload of the data-burst
static enum IEC61937DataType mpeg_data_type[2][3]
#define FF_ARRAY_ELEMS(a)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static const AVOption options[]
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
static int spdif_write_header(AVFormatContext *s)
AVIOContext * pb
I/O context.
int use_preamble
preamble enabled (disabled for exactly pre-padded DTS)
#define DCA_SYNCWORD_CORE_LE
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int hd_buf_filled
amount of bytes in the hd audio buffer (eac3, truehd)
Describe the class of an AVClass context structure.
int length_code
length code in bits or bytes, depending on data type
static int spdif_header_truehd(AVFormatContext *s, AVPacket *pkt)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
void avio_wb16(AVIOContext *s, unsigned int val)
#define flags(name, subs,...)
MPEG-2, layer-2 low sampling frequency.
static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
static const struct @284 mat_codes[]
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
MPEG-2 data with extension.
static const uint8_t mat_end_code[16]
int dtshd_skip
counter used for skipping DTS-HD frames
int hd_buf_size
size of the hd audio buffer (eac3, dts4)
MPEG-2 AAC ADTS quarter-rate low sampling frequency.
static const uint16_t spdif_mpeg_pkt_offset[2][3]
void * priv_data
Format private data.
#define DCA_SYNCWORD_SUBSTREAM
static void write_header(FFV1Context *f)
static int spdif_header_ac3(AVFormatContext *s, AVPacket *pkt)
Filter the word “frame” indicates either a video frame or a group of audio samples
static int spdif_header_dts4(AVFormatContext *s, AVPacket *pkt, int core_size, int sample_rate, int blocks)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
uint16_t truehd_prev_time
input_timing from the last frame
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
int extra_bswap
extra bswap for payload (for LE DTS => standard BE DTS)
static double val(void *priv, double ch)
This structure stores compressed data.
Common code between the AC-3 encoder and decoder.