FFmpeg
Data Structures | Macros | Functions | Variables
spdifenc.c File Reference

IEC-61937 encapsulation of various formats, used by S/PDIF. More...

#include <inttypes.h>
#include "avformat.h"
#include "avio_internal.h"
#include "spdif.h"
#include "libavcodec/ac3.h"
#include "libavcodec/adts_parser.h"
#include "libavcodec/dca.h"
#include "libavcodec/dca_syncwords.h"
#include "libavutil/opt.h"

Go to the source code of this file.

Data Structures

struct  IEC61937Context
 

Macros

#define SPDIF_FLAG_BIGENDIAN   0x01
 
#define MAT_PKT_OFFSET   61440
 
#define MAT_FRAME_SIZE   61424
 
#define MAT_CODE(position, data)   { .pos = position, .code = data, .len = sizeof(data) }
 

Functions

static int spdif_header_ac3 (AVFormatContext *s, AVPacket *pkt)
 
static int spdif_header_eac3 (AVFormatContext *s, AVPacket *pkt)
 
static int spdif_dts4_subtype (int period)
 
static int spdif_header_dts4 (AVFormatContext *s, AVPacket *pkt, int core_size, int sample_rate, int blocks)
 
static int spdif_header_dts (AVFormatContext *s, AVPacket *pkt)
 
static int spdif_header_mpeg (AVFormatContext *s, AVPacket *pkt)
 
static int spdif_header_aac (AVFormatContext *s, AVPacket *pkt)
 
static int spdif_header_truehd (AVFormatContext *s, AVPacket *pkt)
 
static int spdif_write_header (AVFormatContext *s)
 
static void spdif_deinit (AVFormatContext *s)
 
static av_always_inline void spdif_put_16 (IEC61937Context *ctx, AVIOContext *pb, unsigned int val)
 
static int spdif_write_packet (struct AVFormatContext *s, AVPacket *pkt)
 

Variables

static const AVOption options []
 
static const AVClass spdif_class
 
static enum IEC61937DataType mpeg_data_type [2][3]
 
static const uint8_t mat_start_code [20]
 
static const uint8_t mat_middle_code [12]
 
static const uint8_t mat_end_code [16]
 
struct {
   unsigned int   pos
 
   const uint8_t *   code
 
   unsigned int   len
 
mat_codes []
 
AVOutputFormat ff_spdif_muxer
 

Detailed Description

IEC-61937 encapsulation of various formats, used by S/PDIF.

Author
Bartlomiej Wolowiec
Anssi Hannula
Carl Eugen Hoyos

Definition in file spdifenc.c.

Macro Definition Documentation

#define SPDIF_FLAG_BIGENDIAN   0x01

Definition at line 87 of file spdifenc.c.

Referenced by spdif_put_16(), and spdif_write_packet().

#define MAT_PKT_OFFSET   61440

Definition at line 393 of file spdifenc.c.

Referenced by spdif_header_truehd().

#define MAT_FRAME_SIZE   61424

Definition at line 394 of file spdifenc.c.

Referenced by spdif_header_truehd(), and spdif_write_header().

#define MAT_CODE (   position,
  data 
)    { .pos = position, .code = data, .len = sizeof(data) }

Definition at line 407 of file spdifenc.c.

Function Documentation

static int spdif_header_ac3 ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 110 of file spdifenc.c.

Referenced by spdif_write_header().

static int spdif_header_eac3 ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 120 of file spdifenc.c.

Referenced by spdif_write_header().

static int spdif_dts4_subtype ( int  period)
static

Definition at line 159 of file spdifenc.c.

Referenced by spdif_header_dts4().

static int spdif_header_dts4 ( AVFormatContext s,
AVPacket pkt,
int  core_size,
int  sample_rate,
int  blocks 
)
static

Definition at line 172 of file spdifenc.c.

Referenced by spdif_header_dts().

static int spdif_header_dts ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 249 of file spdifenc.c.

Referenced by spdif_write_header().

static int spdif_header_mpeg ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 332 of file spdifenc.c.

Referenced by spdif_write_header().

static int spdif_header_aac ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 355 of file spdifenc.c.

Referenced by spdif_write_header().

static int spdif_header_truehd ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 419 of file spdifenc.c.

Referenced by spdif_write_header().

static int spdif_write_header ( AVFormatContext s)
static

Definition at line 566 of file spdifenc.c.

static void spdif_deinit ( AVFormatContext s)
static

Definition at line 605 of file spdifenc.c.

static av_always_inline void spdif_put_16 ( IEC61937Context ctx,
AVIOContext pb,
unsigned int  val 
)
static

Definition at line 613 of file spdifenc.c.

Referenced by spdif_write_packet().

static int spdif_write_packet ( struct AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 622 of file spdifenc.c.

Variable Documentation

const AVOption options[]
static
Initial value:
= {
{ "spdif_flags", "IEC 61937 encapsulation flags", 0x42, AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" },
{ "be", "output in big-endian format (for use as s16be)", 0, AV_OPT_TYPE_CONST, {.i64 = SPDIF_FLAG_BIGENDIAN}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" },
{ "dtshd_rate", "mux complete DTS frames in HD mode at the specified IEC958 rate (in Hz, default 0=disabled)", 0x42, AV_OPT_TYPE_INT, {.i64 = 0}, 0, 768000, AV_OPT_FLAG_ENCODING_PARAM },
{ "dtshd_fallback_time", "min secs to strip HD for after an overflow (-1: till the end, default 60)", 0x42, AV_OPT_TYPE_INT, {.i64 = 60}, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
{ NULL },
}
#define NULL
Definition: coverity.c:32
#define SPDIF_FLAG_BIGENDIAN
Definition: spdifenc.c:87
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:278

Definition at line 95 of file spdifenc.c.

const AVClass spdif_class
static
Initial value:
= {
.class_name = "spdif",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
static const AVOption options[]
Definition: spdifenc.c:95

Definition at line 103 of file spdifenc.c.

enum IEC61937DataType mpeg_data_type[2][3]
static
Initial value:
= {
{ IEC61937_MPEG1_LAYER1, IEC61937_MPEG1_LAYER23, IEC61937_MPEG1_LAYER23 },
}
MPEG-2, layer-1 low sampling frequency.
Definition: spdif.h:38
MPEG-1 layer 2 or 3 data or MPEG-2 without extension.
Definition: spdif.h:35
MPEG-2, layer-3 low sampling frequency.
Definition: spdif.h:40
MPEG-1 layer 1.
Definition: spdif.h:34
MPEG-2, layer-2 low sampling frequency.
Definition: spdif.h:39

Definition at line 326 of file spdifenc.c.

Referenced by spdif_header_mpeg().

const uint8_t mat_start_code[20]
static
Initial value:
= {
0x07, 0x9E, 0x00, 0x03, 0x84, 0x01, 0x01, 0x01, 0x80, 0x00, 0x56, 0xA5, 0x3B, 0xF4, 0x81, 0x83,
0x49, 0x80, 0x77, 0xE0,
}

Definition at line 396 of file spdifenc.c.

const uint8_t mat_middle_code[12]
static
Initial value:
= {
0xC3, 0xC1, 0x42, 0x49, 0x3B, 0xFA, 0x82, 0x83, 0x49, 0x80, 0x77, 0xE0,
}

Definition at line 400 of file spdifenc.c.

const uint8_t mat_end_code[16]
static
Initial value:
= {
0xC3, 0xC2, 0xC0, 0xC4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x11,
}

Definition at line 403 of file spdifenc.c.

unsigned int pos

Definition at line 410 of file spdifenc.c.

Referenced by aa_read_packet(), aal_read_packet(), activate(), add_coefficients(), add_entry(), add_index_entry(), add_tonal_components(), add_wave(), add_wave0(), aix_read_packet(), amr_read_packet(), aptx_decode_frame(), aptx_encode_frame(), aqt_read_header(), asf_build_simple_index(), asf_deinterleave(), asf_read_pts(), asf_read_seek(), asf_read_timestamp(), ass_read_header(), ast_read_packet(), async_seek(), at1_imdct_block(), at1_unpack_dequant(), av_parser_parse2(), avcodec_chroma_pos_to_enum(), avi_load_index(), avi_read_header(), avi_read_idx1(), avi_read_seek(), avi_sync(), avio_seek(), avio_seek_time(), avpriv_dv_produce_packet(), block_contrast(), block_matching_multi(), build_huff_tree(), build_vlc(), cache_seek(), cbs_av1_assemble_fragment(), cbs_av1_ref_tile_data(), cbs_av1_split_fragment(), cbs_h2645_replace_ps(), cbs_h2645_write_slice_data(), cbs_h265_read_nal_unit(), cbs_jpeg_read_unit(), cbs_mpeg2_read_unit(), cbs_mpeg2_write_slice(), cbs_vp9_assemble_fragment(), cbs_vp9_read_unit(), cbs_vp9_split_fragment(), cdxl_read_packet(), cfhd_encode_frame(), check_stream_max_drift(), clean_index(), close_file(), codec37_mv(), colormap_nearest_iterative(), compute_quant_matrix(), count_channels(), crypto_seek(), dat_read_packet(), deband_16_c(), deband_16_coupling_c(), deband_8_c(), deband_8_coupling_c(), DECLARE_QUERYINTERFACE(), decode_1p_track(), decode_3_pulses_10bits(), decode_ac_coeffs(), decode_band(), decode_block(), decode_channel_wordlen(), decode_dct(), decode_dlta(), decode_dvd_subtitles(), decode_fixed_vector(), decode_frame(), decode_kfrm(), decode_mad1(), decode_mad1_24(), decode_mb_i(), decode_mous(), decode_move(), decode_mpos(), decode_qu_spectra(), decode_rle(), decode_rle16(), decode_rle_bpp2(), decode_rle_bpp4(), decode_runlen(), decode_short_horizontal_delta(), decode_slice(), decode_type1(), decode_type2(), decode_vol_header(), decompress(), dequant(), describe_payload(), do_blend(), do_block_matching_multi(), dsf_read_packet(), dss_723_1_read_packet(), dss_sp_read_packet(), dts_probe(), dv_encode_video_segment(), dv_read_packet(), dv_read_timecode(), dvdsub_parse_extradata(), dxv_decompress_dxt1(), dxv_decompress_dxt5(), dxv_decompress_opcodes(), ebml_parse(), ebml_read_binary(), ebml_read_master(), ebml_read_num(), encode_packet(), envelope_instant(), envelope_instant16(), envelope_peak(), envelope_peak16(), epic_decode_run_length(), epic_predict_from_NW_NE(), event_loop(), evolve(), fastaudio_decode(), ff_atrac_gain_compensation(), ff_attributes_dump(), ff_dca_downmix_to_stereo_fixed(), ff_dca_downmix_to_stereo_float(), ff_dsd2pcm_translate(), ff_els_decode_unsigned(), ff_end_tag(), ff_h263_resync(), ff_hevc_hls_residual_coding(), ff_hevc_sao_edge_filter_neon_8_wrapper(), ff_inlink_evaluate_timeline_at_frame(), ff_mms_read_header(), ff_mov_cenc_write_sinf_tag(), ff_nut_add_sp(), ff_opencl_filter_load_program_from_file(), ff_opus_rc_enc_laplace(), ff_pcm_read_seek(), ff_rle_count_pixels(), ff_rtp_send_h263_rfc2190(), ff_snappy_peek_uncompressed_length(), ff_vfscanf(), ff_vorbis_floor1_render_list(), ff_wma_init(), ffurl_size(), file_move(), fill_pixels(), fill_scaling_lists(), film_read_seek(), filter_frame(), find_motion(), find_sidx(), find_timestamp_in_playlist(), fits_read_packet(), flac_read_header(), flac_seek(), flic_read_packet(), flic_read_seek(), flv_append_keyframe_info(), flv_write_codec_header(), flv_write_packet(), fsb_read_packet(), fsize(), ftp_seek(), g722_encode_trellis(), gainc_loc_mode0(), generate_noise(), get_attachment(), get_consumed_bytes(), get_line(), get_sr_golomb_shorten(), get_tree_codes(), graticule16_column(), graticule16_row(), graticule_column(), graticule_row(), guess_ni_flag(), gxf_seek(), gxf_write_eos_packet(), gxf_write_flt_packet(), gxf_write_map_packet(), gxf_write_material_data_section(), gxf_write_packet(), gxf_write_track_description(), gxf_write_track_description_section(), gxf_write_umf_media_description(), gxf_write_umf_packet(), gxf_write_umf_track_description(), handle_rstn(), hls_slice_header(), hq_decode_block(), http_read_stream_all(), huffman_decode(), iff_read_packet(), imc_decode_level_coefficients_raw(), init_filter(), interp_point(), intlist_read(), ivi_create_huff_from_desc(), ivi_decode_coded_blocks(), ivr_read_header(), ivr_read_packet(), jacosub_read_header(), jpg_decode_block(), klv_read_packet(), libAVEnumMediaTypes_Clone(), libAVEnumMediaTypes_Reset(), libAVEnumPins_Clone(), libAVEnumPins_Reset(), libssh_seek(), lrc_read_header(), lsf_dequantization(), lsp_interpolate(), lvf_read_packet(), lz4_decompress(), magy_encode_frame(), main(), map_prm_ch_to_spkr(), mark_all_blocks(), matroska_add_index_entries(), matroska_execute_seekhead(), matroska_parse_frame(), matroska_parse_rm_audio(), matroska_parse_webvtt(), matroska_read_header(), mcc_read_header(), microdvd_read_header(), mmf_rate(), mods_read_header(), mods_read_packet(), mov_cenc_write_saio_tag(), mov_cenc_write_saiz_tag(), mov_cenc_write_schi_tag(), mov_cenc_write_senc_tag(), mov_flush_fragment(), mov_write_3gp_udta_tag(), mov_write_audio_tag(), mov_write_av1c_tag(), mov_write_avcc_tag(), mov_write_btrt_tag(), mov_write_chan_tag(), mov_write_chpl_tag(), mov_write_colr_tag(), mov_write_covr(), mov_write_dfla_tag(), mov_write_dinf_tag(), mov_write_dmlp_tag(), mov_write_dops_tag(), mov_write_esds_tag(), mov_write_ftyp_tag(), mov_write_gmhd_tag(), mov_write_gpmd_tag(), mov_write_hdlr_tag(), mov_write_hvcc_tag(), mov_write_ilst_tag(), mov_write_iods_tag(), mov_write_isml_manifest(), mov_write_loci_tag(), mov_write_mdia_tag(), mov_write_mdta_ilst_tag(), mov_write_mdta_keys_tag(), mov_write_meta_tag(), mov_write_minf_tag(), mov_write_moof_tag_internal(), mov_write_moov_tag(), mov_write_ms_tag(), mov_write_mvex_tag(), mov_write_prft_tag(), mov_write_rtp_tag(), mov_write_sdtp_tag(), mov_write_sidx_tag(), mov_write_source_reference_tag(), mov_write_stbl_tag(), mov_write_stco_tag(), mov_write_string_tag(), mov_write_stsc_tag(), mov_write_stsd_tag(), mov_write_stss_tag(), mov_write_stsz_tag(), mov_write_subtitle_tag(), mov_write_tapt_tag(), mov_write_tcmi_tag(), mov_write_tfdt_tag(), mov_write_tfhd_tag(), mov_write_tfra_tag(), mov_write_tfrf_tags(), mov_write_tfxd_tag(), mov_write_tmcd_tag(), mov_write_track_metadata(), mov_write_traf_tag(), mov_write_trak_tag(), mov_write_trun_tag(), mov_write_uuidusmt_tag(), mov_write_video_tag(), mov_write_vpcc_tag(), mov_write_wave_tag(), mov_write_wfex_tag(), mp3_read_packet(), mp3_sync(), mpc8_get_chunk_header(), mpc8_handle_chunk(), mpc8_parse_seektable(), mpc8_read_header(), mpc8_read_packet(), mpegps_read_dts(), mpegts_get_dts(), mpegts_get_pcr(), mpegts_push_data(), mpegts_raw_read_packet(), mpegts_read_header(), mpegts_resync(), mpjpeg_read_header(), mpl2_read_header(), mpsub_read_header(), msrle_decode_8_16_24_32(), mss4_decode_dct(), mv_read_header(), mv_read_packet(), mxf_read_packet(), mxf_update_klv_size(), mxf_write_aes3_desc(), mxf_write_avc_subdesc(), mxf_write_cdci_common(), mxf_write_cdci_desc(), mxf_write_generic_desc(), mxf_write_generic_sound_common(), mxf_write_generic_sound_desc(), mxf_write_h264_desc(), mxf_write_index_table_segment(), mxf_write_mpegvideo_desc(), mxf_write_partition(), mxf_write_random_index_pack(), mxf_write_s436m_anc_desc(), mxf_write_wav_common(), mxf_write_wav_desc(), ni_prepare_read(), nprobe(), nsp_read_header(), nut_read_header(), nut_read_packet(), nut_read_timestamp(), nuv_packet(), nuv_read_dts(), old_codec1(), paint_mouse_pointer(), parse_atoms(), parse_file(), pjs_read_header(), pmp_header(), print_track_chunks(), put_header(), put_id3v2_tags(), put_swf_end_tag(), queue_picture(), r3d_read_reda(), r3d_read_redv(), radix_sort_pass(), rdt_parse_packet(), read_bits(), read_dialogue(), read_header(), read_index(), read_line(), read_moof_duration(), read_odml_index(), read_packet(), read_pakt_chunk(), read_seek(), read_tfra(), read_trun_duration(), realtext_read_header(), rl2_read_packet(), rle_uncompress(), rm_assemble_video_frame(), rm_read_dts(), rm_read_index(), rm_read_packet(), rprobe(), rsd_read_packet(), rv40_loop_filter(), s337m_probe(), s337m_read_packet(), sami_read_header(), sao_edge_filter(), sao_filter_CTB(), sap_read_header(), sap_write_header(), scaling_list_data(), scan_buffer(), scc_read_header(), sdr2_read_packet(), sds_read_packet(), seek_chapter(), seq_decode_op3(), ser_read_packet(), set_param(), set_spdif(), shift_data(), skip_tag(), smacker_read_packet(), smjpeg_read_packet(), spdif_header_truehd(), stl_read_header(), stream_seek(), subviewer1_read_header(), subviewer_read_header(), sup_read_packet(), swf_read_packet(), switch_buffer(), swri_noise_shaping_TMPL(), threedostr_read_packet(), tiff_decode_tag(), tm2_read_stream(), tmv_read_seek(), tscc2_decode_frame(), tta_read_header(), twiddle(), unpack_10bit(), update_co64_offsets(), update_size(), update_stco_offsets(), updatePacketSize(), updateSize(), upgrade_stco_atom(), vdpau_hevc_start_frame(), vectorscope16(), vectorscope8(), vlc_decode_block(), vp56_get_vectors_predictors(), vp6_coeff_order_table_init(), vp6_parse_coeff_models(), vpk_read_packet(), vplayer_read_header(), vqf_read_seek(), waves_synth(), wavesynth_seek(), webvtt_read_header(), wma_decode_superframe(), wmavoice_decode_packet(), write_header(), write_index(), write_table_redirector_legacy_attrib(), wv_unpack_mono(), wv_unpack_stereo(), wv_write_trailer(), x8_decode_intra_mb(), xcorr_coeff(), xmlescape(), and yuv4_read_seek().

const uint8_t* code

Definition at line 411 of file spdifenc.c.

Referenced by spdif_header_truehd().

unsigned int len

Definition at line 412 of file spdifenc.c.

const { ... } mat_codes[]
Initial value:
= {
}
static const uint8_t mat_start_code[20]
Definition: spdifenc.c:396
static const uint8_t mat_middle_code[12]
Definition: spdifenc.c:400
#define MAT_CODE(position, data)
Definition: spdifenc.c:407
#define MAT_FRAME_SIZE
Definition: spdifenc.c:394
static const uint8_t mat_end_code[16]
Definition: spdifenc.c:403

Referenced by spdif_header_truehd().

AVOutputFormat ff_spdif_muxer
Initial value:
= {
.name = "spdif",
.long_name = NULL_IF_CONFIG_SMALL("IEC 61937 (used on S/PDIF - IEC958)"),
.extensions = "spdif",
.priv_data_size = sizeof(IEC61937Context),
.audio_codec = AV_CODEC_ID_AC3,
.video_codec = AV_CODEC_ID_NONE,
.deinit = spdif_deinit,
.priv_class = &spdif_class,
}
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:702
static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt)
Definition: spdifenc.c:622
static void spdif_deinit(AVFormatContext *s)
Definition: spdifenc.c:605
static const AVClass spdif_class
Definition: spdifenc.c:103
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:462
static int spdif_write_header(AVFormatContext *s)
Definition: spdifenc.c:566
#define flags(name, subs,...)
Definition: cbs_av1.c:560
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:346

Definition at line 674 of file spdifenc.c.