80 #define SPDIF_FLAG_BIGENDIAN 0x01
89 {
"spdif_flags",
"IEC 61937 encapsulation flags", offsetof(
IEC61937Context, spdif_flags),
AV_OPT_TYPE_FLAGS, {.dbl = 0}, 0, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM,
"spdif_flags" },
91 {
"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, {.dbl = 0}, 0, 768000,
AV_OPT_FLAG_ENCODING_PARAM },
92 {
"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, {.dbl = 60}, -1, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM },
106 int bitstream_mode = pkt->
data[5] & 0x7;
116 static const uint8_t eac3_repeat[4] = {6, 3, 2, 1};
119 if ((pkt->
data[4] & 0xc0) != 0xc0)
120 repeat = eac3_repeat[(pkt->
data[4] & 0x30) >> 4];
154 case 512:
return 0x0;
155 case 1024:
return 0x1;
156 case 2048:
return 0x2;
157 case 4096:
return 0x3;
158 case 8192:
return 0x4;
159 case 16384:
return 0x5;
165 int sample_rate,
int blocks)
168 static const char dtshd_start_code[10] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe };
169 int pkt_size = pkt->
size;
183 period = ctx->
dtshd_rate * (blocks << 5) / sample_rate;
188 "impossible repetition period of %d for the current DTS stream"
189 " (blocks = %d, sample rate = %d)\n", ctx->
dtshd_rate, period,
190 blocks << 5, sample_rate);
204 if (
sizeof(dtshd_start_code) + 2 + pkt_size
208 "temporarily sending core only\n");
217 pkt_size = core_size;
222 ctx->
out_bytes =
sizeof(dtshd_start_code) + 2 + pkt_size;
234 memcpy(ctx->
hd_buf, dtshd_start_code,
sizeof(dtshd_start_code));
236 memcpy(ctx->
hd_buf +
sizeof(dtshd_start_code) + 2, pkt->
data, pkt_size);
252 switch (syncword_dts) {
255 core_size = ((
AV_RB24(pkt->
data + 5) >> 4) & 0x3fff) + 1;
264 (((pkt->
data[5] & 0x07) << 4) | ((pkt->
data[6] & 0x3f) >> 2));
268 (((pkt->
data[4] & 0x07) << 4) | ((pkt->
data[7] & 0x3f) >> 2));
298 if (core_size && core_size < pkt->
size) {
328 int layer = 3 - ((pkt->
data[1] >> 1) & 3);
329 int extension = pkt->
data[2] & 1;
331 if (layer == 3 || version == 1) {
335 av_log(s,
AV_LOG_DEBUG,
"version: %i layer: %i extension: %i\n", version, layer, extension);
336 if (version == 2 && extension) {
391 #define MAT_FRAME_SIZE 61424
392 #define TRUEHD_FRAME_OFFSET 2560
393 #define MAT_MIDDLE_CODE_OFFSET -4
398 int mat_code_length = 0;
399 const char mat_end_code[16] = { 0xC3, 0xC2, 0xC0, 0xC4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x11 };
402 const char mat_start_code[20] = { 0x07, 0x9E, 0x00, 0x03, 0x84, 0x01, 0x01, 0x01, 0x80, 0x00, 0x56, 0xA5, 0x3B, 0xF4, 0x81, 0x83, 0x49, 0x80, 0x77, 0xE0 };
404 memcpy(ctx->
hd_buf, mat_start_code,
sizeof(mat_start_code));
407 const char mat_middle_code[12] = { 0xC3, 0xC1, 0x42, 0x49, 0x3B, 0xFA, 0x82, 0x83, 0x49, 0x80, 0x77, 0xE0 };
410 mat_middle_code,
sizeof(mat_middle_code));
430 memcpy(&ctx->
hd_buf[
MAT_FRAME_SIZE -
sizeof(mat_end_code)], mat_end_code,
sizeof(mat_end_code));
549 .extensions =
"spdif",
557 .priv_class = &
class,
MPEG-2 AAC ADTS half-rate low sampling frequency.
uint8_t * out_buf
pointer to the outgoing data before byte-swapping
void avio_wl16(AVIOContext *s, unsigned int val)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AV_WL32 AV_WL24 AV_WL16 AV_WB32 AV_WB24 AV_RB16
AV_WL32 AV_WL24 AV_WL16 AV_RB32
int pkt_offset
data burst repetition period in bytes
static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt)
struct IEC61937Context IEC61937Context
#define BURST_HEADER_SIZE
MPEG-2, layer-1 low sampling frequency.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int spdif_dts4_subtype(int period)
static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt)
static int spdif_header_dts(AVFormatContext *s, AVPacket *pkt)
void ff_spdif_bswap_buf16(uint16_t *dst, const uint16_t *src, int w)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
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_eac3(AVFormatContext *s, AVPacket *pkt)
int buffer_size
size of allocated buffer
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define DCA_HD_MARKER
DCA-HD specific block starts with this marker.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVOutputFormat ff_spdif_muxer
#define MAT_MIDDLE_CODE_OFFSET
#define SPDIF_FLAG_BIGENDIAN
DTS type II (1024 samples)
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
static int spdif_write_trailer(AVFormatContext *s)
DTS type III (2048 samples)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
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
static const uint32_t dca_sample_rates[16]
AVCodecContext * codec
codec context
#define DCA_MARKER_14B_LE
int void avio_flush(AVIOContext *s)
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
int(* header_info)(AVFormatContext *s, AVPacket *pkt)
function, which generates codec dependent header information.
#define TRUEHD_FRAME_OFFSET
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 AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
static const AVOption options[]
#define AAC_ADTS_HEADER_SIZE
#define DCA_MARKER_RAW_LE
static int spdif_write_header(AVFormatContext *s)
int use_preamble
preamble enabled (disabled for exactly pre-padded DTS)
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
Parse AAC frame header.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int hd_buf_filled
amount of bytes in the hd audio buffer
Describe the class of an AVClass context structure.
int length_code
length code in bits or bytes, depending on data type
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static int spdif_header_truehd(AVFormatContext *s, AVPacket *pkt)
void avio_wb16(AVIOContext *s, unsigned int val)
MPEG-2, layer-2 low sampling frequency.
AV_WL32 AV_WL24 AV_WL16 AV_WB32 AV_RB24
static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
#define DCA_MARKER_14B_BE
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
MPEG-2 data with extension.
int dtshd_skip
counter used for skipping DTS-HD frames
int hd_buf_size
size of the hd audio buffer
MPEG-2 AAC ADTS quarter-rate low sampling frequency.
static const uint16_t spdif_mpeg_pkt_offset[2][3]
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
void * priv_data
Format private data.
static int spdif_header_ac3(AVFormatContext *s, AVPacket *pkt)
static int spdif_header_dts4(AVFormatContext *s, AVPacket *pkt, int core_size, int sample_rate, int blocks)
#define DCA_MARKER_RAW_BE
DCA syncwords, also used for bitstream type detection.
int extra_bswap
extra bswap for payload (for LE DTS => standard BE DTS)
uint8_t * hd_buf
allocated buffer to concatenate hd audio frames
Common code between the AC-3 encoder and decoder.
preferred ID for decoding MPEG audio layer 1, 2 or 3