30#include "config_components.h"
71#define OFFSET(x) offsetof(WAVDemuxContext, x)
72#define DEC AV_OPT_FLAG_DECODING_PARAM
74#define W64_DEMUXER_OPTIONS_OFFSET (1 * CONFIG_WAV_DEMUXER)
86 wav->
max_size = max_size < 0 ? 4096 : max_size;
92 if (CONFIG_SPDIF_DEMUXER &&
s->streams[0]->codecpar->codec_tag == 1) {
107 s->streams[0]->codecpar->codec_id = codec;
121#if CONFIG_WAV_DEMUXER
164 if (
p->buf_size <= 32)
166 if (!memcmp(
p->buf + 8,
"WAVE", 4)) {
167 if (!memcmp(
p->buf,
"RIFF", 4) || !memcmp(
p->buf,
"RIFX", 4))
172 else if ((!memcmp(
p->buf,
"RF64", 4) ||
173 !memcmp(
p->buf,
"BW64", 4)) &&
174 !memcmp(
p->buf + 12,
"ds64", 4))
180static void handle_stream_probing(
AVStream *st)
199 handle_stream_probing(st);
224 if (
size != (32 + ((
version==3)?0:8) + 4*num_streams))
234 for (
i = 0;
i < num_streams;
i++) {
274 char temp[131], *coding_history;
276 uint64_t time_reference;
277 int64_t umid_parts[8], umid_mask = 0;
279 if ((ret = wav_parse_bext_string(
s,
"description", 256)) < 0 ||
280 (ret = wav_parse_bext_string(
s,
"originator", 32)) < 0 ||
281 (ret = wav_parse_bext_string(
s,
"originator_reference", 32)) < 0 ||
282 (ret = wav_parse_bext_string(
s,
"origination_date", 10)) < 0 ||
283 (ret = wav_parse_bext_string(
s,
"origination_time", 8)) < 0)
293 for (x = 0; x < 8; x++)
294 umid_mask |= umid_parts[x] =
avio_rb64(
s->pb);
298 if (umid_parts[4] == 0 && umid_parts[5] == 0 &&
299 umid_parts[6] == 0 && umid_parts[7] == 0) {
302 "0x%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64,
303 umid_parts[0], umid_parts[1],
304 umid_parts[2], umid_parts[3]);
308 "0x%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64
309 "%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64,
310 umid_parts[0], umid_parts[1],
311 umid_parts[2], umid_parts[3],
312 umid_parts[4], umid_parts[5],
313 umid_parts[6], umid_parts[7]);
331 if (coding_history_size > 1024 * 1024) {
332 av_log(
s,
AV_LOG_ERROR,
"BEXT coding history too large (%"PRId64
")\n", coding_history_size);
336 if (!(coding_history =
av_malloc(coding_history_size + 1)))
339 if ((ret =
ffio_read_size(
s->pb, coding_history, coding_history_size)) < 0) {
344 coding_history[coding_history_size] = 0;
345 if ((ret =
av_dict_set(&
s->metadata,
"coding_history", coding_history,
354 {
"description",
"comment" },
355 {
"originator",
"encoded_by" },
356 {
"origination_date",
"date" },
357 {
"origination_time",
"creation_time" },
366 int rf64 = 0, bw64 = 0;
371 int ret, got_fmt = 0, got_xma2 = 0;
372 int64_t next_tag_ofs, data_ofs = -1;
381 case MKTAG(
'R',
'I',
'F',
'F'):
383 case MKTAG(
'R',
'I',
'F',
'X'):
386 case MKTAG(
'R',
'F',
'6',
'4'):
389 case MKTAG(
'B',
'W',
'6',
'4'):
418 if (data_size < 0 || sample_count < 0) {
420 "ds64: data_size = %"PRId64
", sample_count = %"PRId64
"\n",
421 data_size, sample_count);
442 case MKTAG(
'f',
'm',
't',
' '):
444 if (!got_xma2 && !got_fmt && (ret = wav_parse_fmt_tag(
s,
size, st)) < 0) {
451 case MKTAG(
'X',
'M',
'A',
'2'):
453 if (!got_fmt && !got_xma2 && (ret = wav_parse_xma2_tag(
s,
size, st)) < 0) {
460 case MKTAG(
'd',
'a',
't',
'a'):
463 "found no 'fmt ' tag before the 'data' tag\n");
469 next_tag_ofs = wav->
data_end + (data_size & 1);
470 }
else if (
size > 0 &&
size != 0xFFFFFFFF) {
476 "file may be invalid\n");
478 next_tag_ofs = wav->
data_end = INT64_MAX;
489 case MKTAG(
'f',
'a',
'c',
't'):
493 case MKTAG(
'b',
'e',
'x',
't'):
494 if ((ret = wav_parse_bext_tag(
s,
size)) < 0)
497 case MKTAG(
'S',
'M',
'V',
'0'):
540 case MKTAG(
'L',
'I',
'S',
'T'):
541 case
MKTAG(
'l',
'i',
's',
't'):
547 case MKTAG(
'I',
'N',
'F',
'O'):
550 case MKTAG(
'a',
'd',
't',
'l'):
551 if (
s->nb_chapters > 0) {
555 unsigned id, sub_size;
564 avio_get_str(pb, sub_size - 4, cue_label,
sizeof(cue_label));
567 for (
int i = 0;
i <
s->nb_chapters;
i++) {
568 if (
s->chapters[
i]->id ==
id) {
569 av_dict_set(&
s->chapters[
i]->metadata,
"title", cue_label, 0);
578 case MKTAG(
'I',
'D',
'3',
' '):
579 case
MKTAG(
'i',
'd',
'3',
' '): {
582 if (id3v2_extra_meta) {
590 case MKTAG(
'c',
'u',
'e',
' '):
591 if (
size >= 4 && got_fmt && st->codecpar->sample_rate > 0) {
595 if (
size >= nb_cues * 24LL + 4LL) {
596 for (
int i = 0;
i < nb_cues;
i++) {
615 wav_seek_tag(wav, pb, next_tag_ofs) < 0) {
621 if (!got_fmt && !got_xma2) {
633 if (data_size > (INT64_MAX>>3)) {
665 sample_count = (data_size << 3)
715 if (!memcmp(guid, guid1, 16))
729 if (CONFIG_SPDIF_DEMUXER && wav->
spdif == 1)
753 if (
avio_seek(
s->pb, new_pos, SEEK_SET) < 0) {
785 if (CONFIG_W64_DEMUXER && wav->
w64)
788 left = find_tag(wav,
s->pb,
MKTAG(
'd',
'a',
't',
'a'));
810 pkt->stream_index = 0;
823 if (stream_index != 0 && (!vst || stream_index != vst->
index))
826 int64_t smv_timestamp = timestamp;
827 if (stream_index == 0)
850static const AVClass wav_demuxer_class = {
851 .class_name =
"WAV demuxer",
861 .p.priv_class = &wav_demuxer_class,
871#if CONFIG_W64_DEMUXER
874 if (
p->buf_size <= 40)
899 if (
avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8)
937 block_align =
FFMAX(block_align,
964 uint32_t count, chunk_size,
i;
971 for (
i = 0;
i < count;
i++) {
972 char chunk_key[5], *
value;
1010 handle_stream_probing(st);
1021static const AVClass w64_demuxer_class = {
1022 .class_name =
"W64 demuxer",
1033 .p.priv_class = &w64_demuxer_class,
static const GUIDParseTable * find_guid(ff_asf_guid guid)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
uint64_t avio_rb64(AVIOContext *s)
int64_t avio_size(AVIOContext *s)
Get the filesize.
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a UTF-16 string from pb and convert it to UTF-8.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
unsigned int avio_rl16(AVIOContext *s)
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
unsigned int avio_rl32(AVIOContext *s)
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
unsigned int avio_rl24(AVIOContext *s)
unsigned int avio_rb32(AVIOContext *s)
int avio_r8(AVIOContext *s)
uint64_t avio_rl64(AVIOContext *s)
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int read_probe(const AVProbeData *p)
static __device__ float fabs(float a)
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.
#define FF_INFMT_FLAG_ID3V2_AUTO
Automatically parse ID3v2 metadata.
int ff_get_extradata(void *logctx, AVCodecParameters *par, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
static int64_t filesize(AVIOContext *pb)
static int read_header(FFV1Context *f, RangeCoder *c)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
AVCodecID
Identify the syntax and semantics of the bitstream.
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
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 AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define av_fourcc2str(fourcc)
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define LIBAVUTIL_VERSION_INT
void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta, unsigned int max_search_size)
Read an ID3v2 tag, including supported extra metadata.
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header.
int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Add metadata for all PRIV tags in the ID3v2 header.
int ff_id3v2_parse_chapters(AVFormatContext *s, ID3v2ExtraMeta *cur)
Create chapters for all CHAP tags found in the ID3v2 header.
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
common internal api header.
#define FF_SANE_NB_CHANNELS
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
#define MKTAG(a, b, c, d)
Memory handling functions.
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
const AVMetadataConv ff_riff_info_conv[]
internal header for RIFF based (de)muxers do NOT include this in end user applications
int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian)
int ff_read_riff_info(AVFormatContext *s, int64_t size)
const AVCodecTag *const ff_wav_codec_tags_list[]
int ff_spdif_probe(const uint8_t *p_buf, int buf_size, enum AVCodecID *codec)
int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
int extradata_size
Size of the extradata content in bytes.
int height
The height of the video frame in pixels.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
AVChannelLayout ch_layout
The channel layout and number of channels.
int width
The width of the video frame in pixels.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
int block_align
The number of bytes per coded audio frame, required by some formats.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
This structure stores compressed data.
This structure contains the data a format has to probe a file.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int64_t duration
Decoding: duration of the stream, in stream time base.
int id
Format-specific stream ID.
int index
stream index in AVFormatContext
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int probe_packets
Number of packets to buffer for codec probing.
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
enum AVStreamParseType need_parsing
const uint8_t ff_w64_guid_wave[16]
const uint8_t ff_w64_guid_summarylist[16]
const uint8_t ff_w64_guid_riff[16]
const uint8_t ff_w64_guid_data[16]
const uint8_t ff_w64_guid_fact[16]
const uint8_t ff_w64_guid_fmt[16]
static void set_spdif(AVFormatContext *s, WAVDemuxContext *wav)
static const AVOption demux_options[]
#define W64_DEMUXER_OPTIONS_OFFSET
static void set_max_size(AVStream *st, WAVDemuxContext *wav)