FFmpeg: libavformat/flacdec.c Source File
Go to the documentation of this file. 1 /*
2 * Raw FLAC demuxer
3 * Copyright (c) 2001 Fabrice Bellard
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
31
32 #define SEEKPOINT_SIZE 18
33
38
40 {
42 /* the real seek index offset should be the size of metadata blocks with the offset in the frame blocks */
45 }
46
48 {
49 int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0;
54 if (!st)
59 /* the parameters will be extracted from the compressed bitstream */
60
61 /* if fLaC marker is not found, assume there is no header */
64 return 0;
65 }
66
67 /* process metadata blocks */
72 &metadata_size);
73 switch (metadata_type) {
74 /* allocate and read metadata block for supported types */
83 }
86 }
87 break;
88 /* skip metadata block for unsupported types */
89 default:
93 }
94
96 uint32_t samplerate;
98
99 /* STREAMINFO can only occur once */
100 if (found_streaminfo) {
102 }
105 }
106 found_streaminfo = 1;
110
111 /* get sample rate and sample count from STREAMINFO header;
112 * other parameters will be extracted by the parser */
115
116 /* set time base and duration */
117 if (samplerate > 0) {
121 }
123 uint8_t isrc[13];
124 uint64_t start;
126 int i, chapters, track, ti;
127 if (metadata_size < 431)
130 chapters = bytestream_get_byte(&
offset) - 1;
131 if (chapters <= 0)
133 for (
i = 0;
i < chapters;
i++) {
136 start = bytestream_get_be64(&
offset);
137 track = bytestream_get_byte(&
offset);
139 isrc[12] = 0;
141 ti = bytestream_get_byte(&
offset);
145 }
153 }
155 const uint8_t *seekpoint =
buffer;
159 for(
i=0;
i<seek_point_count;
i++) {
160 int64_t timestamp = bytestream_get_be64(&seekpoint);
161 int64_t
pos = bytestream_get_be64(&seekpoint);
162 /* skip number of samples */
163 bytestream_get_be16(&seekpoint);
165 }
166 }
168 }
169 else {
170
171 /* STREAMINFO must be the first block */
172 if (!found_streaminfo) {
174 }
175 /* process supported blocks other than STREAMINFO */
178
182 }
else if (
ret > 0) {
184 }
185
186 /* parse the channels mask if present */
187 chmask =
av_dict_get(
s->metadata,
"WAVEFORMATEXTENSIBLE_CHANNEL_MASK",
NULL, 0);
188 if (chmask) {
192 "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
193 } else {
196 }
197 }
198 }
200 }
201 }
202
206
208 return 0;
209
213 }
214
216 {
217 if ((p->
buf[2] & 0xF0) == 0)
// blocksize code invalid
218 return 0;
219 if ((p->
buf[2] & 0x0F) == 0x0F)
// sample rate code invalid
220 return 0;
222 // channel mode invalid
223 return 0;
224 if ((p->
buf[3] & 0x06) == 0x06)
// bits per sample code invalid
225 return 0;
226 if ((p->
buf[3] & 0x01) == 0x01)
// reserved bit set
227 return 0;
229 }
230
232 {
235
236 /* file header + metadata header + checked bytes of streaminfo */
243
244 if (memcmp(p->
buf,
"fLaC", 4))
245 return 0;
248 min_block_size >= 16 &&
249 max_block_size >= min_block_size &&
253 }
254
255 return 0;
256 }
257
259 int64_t *ppos, int64_t pos_limit)
260 {
267
270
272 if (!parser){
274 }
276
277 for (;;){
280
284 continue;
285 else {
288 }
289 }
293
297 // seeking may not have started from beginning of a frame
298 // calculate frame start position from next frame backwards
301 break;
302 }
304 break;
305 }
308 }
309
317
319 return -1;
320 }
321
324 return -1;
325
329 return 0;
330 }
331 return -1;
332 }
333
343 .extensions = "flac",
347 };
AVChapter * avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_LOG_WARNING
Something somehow does not look correct.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
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.
int ff_replaygain_export(AVStream *st, AVDictionary *metadata)
Parse replaygain tags and export them as per-stream side data.
FFRawDemuxerContext rawctx
int buf_size
Size of buf except extra allocated bytes.
@ FLAC_METADATA_TYPE_CUESHEET
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
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
AVCodecParserContext * av_parser_init(int codec_id)
int64_t duration
Decoding: duration of the stream, in stream time base.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
enum AVStreamParseType need_parsing
@ FLAC_METADATA_TYPE_STREAMINFO
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
static av_always_inline void flac_parse_block_header(const uint8_t *block_header, int *last, int *type, int *size)
Parse the metadata block parameters from the header.
@ FLAC_METADATA_TYPE_SEEKTABLE
This structure contains the data a format has to probe a file.
#define FLAC_STREAMINFO_SIZE
AVChannelLayout ch_layout
Audio only.
int ff_flac_parse_picture(AVFormatContext *s, uint8_t **bufp, int buf_size, int truncate_workaround)
Parse a FLAC METADATA_BLOCK_PICTURE.
int extradata_size
Size of the extradata content in bytes.
unsigned int avio_rl32(AVIOContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
int64_t next_frame_offset
#define AV_NOPTS_VALUE
Undefined timestamp value.
static const uint8_t header[24]
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
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
#define RETURN_ERROR(code)
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
FF_ENABLE_DEPRECATION_WARNINGS int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AV_INPUT_BUFFER_PADDING_SIZE
#define FLAC_MAX_CHANNELS
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
@ FLAC_METADATA_TYPE_PICTURE
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define PARSER_FLAG_USE_CODEC_TS
Filter the word "frame" indicates either a video frame or a group of audio samples
@ FLAC_METADATA_TYPE_VORBIS_COMMENT
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
Parse a packet.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define flags(name, subs,...)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MKTAG(a, b, c, d)
int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m, const uint8_t *buf, int size, int parse_picture)
Parse Vorbis comments.
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
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
void av_parser_close(AVCodecParserContext *s)
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
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Generated on Wed Aug 24 2022 21:41:25 for FFmpeg by
doxygen
1.8.17