FFmpeg: libavformat/spdifdec.c Source File
Go to the documentation of this file. 1 /*
2 * IEC 61937 demuxer
3 * Copyright (c) 2010 Anssi Hannula <anssi.hannula at iki.fi>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * IEC 61937 demuxer, used for compressed data in S/PDIF
25 * @author Anssi Hannula
26 */
27
29
32
36
39 const char *buf,
int *
offset,
41 {
45
46 switch (data_type & 0xff) {
50 break;
54 break;
58 break;
62 break;
66 if (
s)
/* be silent during a probe */
69 }
72 break;
76 break;
80 break;
84 break;
88 break;
92 break;
96 break;
100 break;
101 default:
102 if (
s) {
/* be silent during a probe */
104 data_type);
105 }
107 }
108 return 0;
109 }
110
111 /* Largest offset between bursts we currently handle, i.e. AAC with
112 samples = 4096 */
113 #define SPDIF_MAX_OFFSET 16384
114
116 {
119 }
120
122 {
123 const uint8_t *buf = p_buf;
125 const uint8_t *expected_code = buf + 7;
127 int sync_codes = 0;
128 int consecutive_codes = 0;
130
131 for (; buf < probe_end; buf++) {
133
135 && buf[1] < 0x37) {
136 sync_codes++;
137
138 if (buf == expected_code) {
139 if (++consecutive_codes >= 2)
141 } else
142 consecutive_codes = 0;
143
145 break;
146
147 /* continue probing to find more sync codes */
149
150 /* skip directly to the next sync code */
152 &buf[5], &
offset, codec)) {
153 if (buf +
offset >= p_buf + buf_size)
154 break;
155 expected_code = buf +
offset;
156 buf = expected_code - 7;
157 }
158 }
159 }
160
161 if (!sync_codes)
162 return 0;
163
164 if (sync_codes >= 6)
165 /* good amount of sync codes but with unexpected offsets */
167
168 /* some sync codes were found */
170 }
171
173 {
175 return 0;
176 }
177
179 {
180 switch (
type & 0xff) {
183 default:
185 }
186 }
187
189 {
195
200 }
201
204
205 if (pkt_size_bits % 16)
207
211
213
216 }
218
223 }
224
225 /* skip over the padding to the beginning of the next frame */
227
228 if (!
s->nb_streams) {
229 /* first packet, create a stream */
231 if (!st) {
233 }
238 }
else if (
codec_id !=
s->streams[0]->codecpar->codec_id) {
241 }
242
243 if (!
s->bit_rate &&
s->streams[0]->codecpar->sample_rate)
244 /* stream bitrate matches 16-bit stereo PCM bitrate for currently
245 supported codecs */
246 s->bit_rate = 2 * 16LL *
s->streams[0]->codecpar->sample_rate;
247
248 return 0;
249 }
250
258 };
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
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
enum AVMediaType codec_type
General type of the encoded data.
#define AVERROR_EOF
End of file.
#define AV_AAC_ADTS_HEADER_SIZE
@ IEC61937_MPEG2_LAYER1_LSF
MPEG-2, layer-1 low sampling frequency.
int buf_size
Size of buf except extra allocated bytes.
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.
int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
if it could not because there are no more frames
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
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 type
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
unsigned int avio_rl16(AVIOContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_spdif_bswap_buf16(uint16_t *dst, const uint16_t *src, int w)
@ IEC61937_MPEG2_EXT
MPEG-2 data with extension.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
enum AVStreamParseType need_parsing
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int spdif_get_pkt_size_bits(int type, int code)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
This structure contains the data a format has to probe a file.
AVCodecID
Identify the syntax and semantics of the bitstream.
@ IEC61937_DTS3
DTS type III (2048 samples)
static int spdif_get_offset_and_codec(AVFormatContext *s, enum IEC61937DataType data_type, const char *buf, int *offset, enum AVCodecID *codec)
@ IEC61937_MPEG1_LAYER23
MPEG-1 layer 2 or 3 data or MPEG-2 without extension.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ IEC61937_DTS2
DTS type II (1024 samples)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int avio_r8(AVIOContext *s)
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 offset
@ IEC61937_DTS1
DTS type I (512 samples)
int ff_spdif_probe(const uint8_t *p_buf, int buf_size, enum AVCodecID *codec)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
@ IEC61937_MPEG1_LAYER1
MPEG-1 layer 1.
@ IEC61937_EAC3
E-AC-3 data.
static int spdif_probe(const AVProbeData *p)
#define BURST_HEADER_SIZE
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Filter the word "frame" indicates either a video frame or a group of audio samples
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
@ IEC61937_MPEG2_LAYER2_LSF
MPEG-2, layer-2 low sampling frequency.
#define avpriv_request_sample(...)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
int64_t pos
byte position in stream, -1 if unknown
static int spdif_read_header(AVFormatContext *s)
@ IEC61937_MPEG2_AAC
MPEG-2 AAC ADTS.
static const uint16_t spdif_mpeg_pkt_offset[2][3]
@ IEC61937_MPEG2_LAYER3_LSF
MPEG-2, layer-3 low sampling frequency.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
const AVInputFormat ff_spdif_demuxer
Generated on Tue Feb 28 2023 21:34:10 for FFmpeg by
doxygen
1.8.17