26 #include "libavutil/avassert.h"
27 #include "libavutil/dict.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/log.h"
30 #include "libavutil/mathematics.h"
31 #include "libavutil/opt.h"
60 #if CONFIG_WAV_DEMUXER
71 offset += offset < INT64_MAX && offset + wav->
unaligned & 1;
85 size = next_tag(pb, &tag);
88 wav_seek_tag(wav, pb, size, SEEK_CUR);
98 if (!memcmp(p->
buf + 8,
"WAVE", 4)) {
99 if (!memcmp(p->
buf,
"RIFF", 4))
104 else if (!memcmp(p->
buf,
"RF64", 4) &&
105 !memcmp(p->
buf + 12,
"ds64", 4))
111 static void handle_stream_probing(
AVStream *st)
132 handle_stream_probing(*st);
141 static inline int wav_parse_bext_string(
AVFormatContext *s,
const char *key,
161 char temp[131], *coding_history;
163 uint64_t time_reference;
164 int64_t umid_parts[8], umid_mask = 0;
166 if ((ret = wav_parse_bext_string(s,
"description", 256)) < 0 ||
167 (ret = wav_parse_bext_string(s,
"originator", 32)) < 0 ||
168 (ret = wav_parse_bext_string(s,
"originator_reference", 32)) < 0 ||
169 (ret = wav_parse_bext_string(s,
"origination_date", 10)) < 0 ||
170 (ret = wav_parse_bext_string(s,
"origination_time", 8)) < 0)
174 snprintf(temp,
sizeof(temp),
"%"PRIu64, time_reference);
180 for (x = 0; x < 8; x++)
185 if (umid_parts[4] == 0 && umid_parts[5] == 0 &&
186 umid_parts[6] == 0 && umid_parts[7] == 0) {
189 "0x%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64,
190 umid_parts[0], umid_parts[1],
191 umid_parts[2], umid_parts[3]);
195 "0x%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64
196 "%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64,
197 umid_parts[0], umid_parts[1],
198 umid_parts[2], umid_parts[3],
199 umid_parts[4], umid_parts[5],
200 umid_parts[6], umid_parts[7]);
215 if (!(coding_history =
av_malloc(size + 1)))
218 if ((ret =
avio_read(s->
pb, coding_history, size)) < 0)
221 coding_history[
size] = 0;
231 {
"description",
"comment" },
232 {
"originator",
"encoded_by" },
233 {
"origination_date",
"date" },
234 {
"origination_time",
"creation_time" },
242 int64_t sample_count = 0;
248 int ret, got_fmt = 0;
249 int64_t next_tag_ofs, data_ofs = -1;
258 rf64 = tag ==
MKTAG(
'R',
'F',
'6',
'4');
259 if (!rf64 && tag !=
MKTAG(
'R',
'I',
'F',
'F'))
263 if (tag !=
MKTAG(
'W',
'A',
'V',
'E'))
277 if (data_size < 0 || sample_count < 0) {
279 "ds64: data_size = %"PRId64
", sample_count = %"PRId64
"\n",
280 data_size, sample_count);
289 size = next_tag(pb, &tag);
296 case MKTAG(
'f',
'm',
't',
' '):
298 if (!got_fmt && (ret = wav_parse_fmt_tag(s, size, &st)) < 0) {
305 case MKTAG(
'd',
'a',
't',
'a'):
308 "found no 'fmt ' tag before the 'data' tag\n");
316 next_tag_ofs = wav->
data_end = size ? next_tag_ofs : INT64_MAX;
324 if (!pb->
seekable || (!rf64 && !size))
327 case MKTAG(
'f',
'a',
'c',
't'):
331 case MKTAG(
'b',
'e',
'x',
't'):
332 if ((ret = wav_parse_bext_tag(s, size)) < 0)
335 case MKTAG(
'S',
'M',
'V',
'0'):
341 if (size !=
MKTAG(
'0',
'2',
'0',
'0')) {
376 case MKTAG(
'L',
'I',
'S',
'T'):
382 case MKTAG(
'I',
'N',
'F',
'O'):
390 wav_seek_tag(wav, pb, next_tag_ofs, SEEK_SET) < 0) {
408 sample_count = (data_size << 3)
435 if (!memcmp(guid, guid1, 16))
442 #define MAX_SIZE 4096
467 int64_t audio_dts, video_dts;
522 left = find_tag(wav, s->
pb,
MKTAG(
'd',
'a',
't',
'a'));
534 if (size < st->codec->block_align)
538 size =
FFMIN(size, left);
548 int stream_index, int64_t timestamp,
int flags)
555 int64_t smv_timestamp = timestamp;
556 if (stream_index == 0)
580 #define OFFSET(x) offsetof(WAVDemuxContext, x)
581 #define DEC AV_OPT_FLAG_DECODING_PARAM
582 static const AVOption demux_options[] = {
587 static const AVClass wav_demuxer_class = {
590 .option = demux_options,
603 .priv_class = &wav_demuxer_class,
607 #if CONFIG_W64_DEMUXER
621 int64_t
size, data_ofs = 0;
633 if (
avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8)
652 if (size <= 24 || INT64_MAX - size <
avio_tell(pb))
679 uint32_t
count, chunk_size, i;
682 end = start +
FFALIGN(size, INT64_C(8)) - 24;
685 for (i = 0; i <
count; i++) {
686 char chunk_key[5], *
value;
718 handle_stream_probing(st);
int ff_read_riff_info(AVFormatContext *s, int64_t size)
const uint8_t ff_w64_guid_wave[16]
int ff_spdif_probe(const uint8_t *p_buf, int buf_size, enum AVCodecID *codec)
const uint8_t ff_w64_guid_fact[16]
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
int64_t pos
byte position in stream, -1 if unknown
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
AVCodecContext * codec
Codec context associated with this stream.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
unsigned char * buffer
Start of the buffer.
const char * av_default_item_name(void *ctx)
Return the context name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const uint8_t offset[511][2]
static av_cold int end(AVCodecContext *avctx)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
enum AVStreamParseType need_parsing
int id
Format-specific stream ID.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
void * priv_data
Format private data.
int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
preferred ID for decoding MPEG audio layer 1, 2 or 3
const AVCodecTag ff_codec_wav_tags[]
unsigned char * buf_end
End of the data, may be less than buffer+buffer_size if the read function returned less data than req...
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
#define CONFIG_W64_DEMUXER
int buf_size
Size of buf except extra allocated bytes.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() and chilren.
int width
picture width / height.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
const uint8_t ff_w64_guid_data[16]
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
const uint8_t ff_w64_guid_riff[16]
static int read_header(FFV1Context *f)
enum AVMediaType codec_type
int sample_rate
samples per second
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
AVIOContext * pb
I/O context.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
#define MKTAG(a, b, c, d)
This structure contains the data a format has to probe a file.
const AVMetadataConv ff_riff_info_conv[]
const uint8_t ff_w64_guid_fmt[16]
int64_t duration
Decoding: duration of the stream, in stream time base.
#define AVERROR_INVALIDDATA
int channels
number of audio channels
const uint8_t ff_w64_guid_summarylist[16]
#define CONFIG_SPDIF_DEMUXER
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...