51 static inline void bwf_write_bext_string(
AVFormatContext *s,
const char *key,
int maxlen)
57 len = strlen(tag->
value);
58 len =
FFMIN(len, maxlen);
68 uint64_t time_reference = 0;
71 bwf_write_bext_string(s,
"description", 256);
72 bwf_write_bext_string(s,
"originator", 32);
73 bwf_write_bext_string(s,
"originator_reference", 32);
74 bwf_write_bext_string(s,
"origination_date", 10);
75 bwf_write_bext_string(s,
"origination_time", 8);
78 time_reference = strtoll(tmp_tag->
value,
NULL, 10);
83 unsigned char umidpart_str[17] = {0};
88 for (i = 0; i < len/16; i++) {
89 memcpy(umidpart_str, tmp_tag->
value + 2 + (i*16), 16);
90 umidpart = strtoll(umidpart_str,
NULL, 16);
132 bwf_write_bext_chunk(s);
174 avio_wl32(pb, (uint32_t)(file_size - 8));
181 int number_of_samples;
194 #define OFFSET(x) offsetof(WAVContext, x)
195 #define ENC AV_OPT_FLAG_ENCODING_PARAM
201 static const AVClass wav_muxer_class = {
211 .mime_type =
"audio/x-wav",
220 .priv_class = &wav_muxer_class,
225 #if CONFIG_WAV_DEMUXER
234 static int64_t wav_seek_tag(
AVIOContext *s, int64_t offset,
int whence)
236 return avio_seek(s, offset + (offset & 1), whence);
240 static int64_t find_tag(
AVIOContext *pb, uint32_t tag1)
248 size = next_tag(pb, &tag);
251 wav_seek_tag(pb, size, SEEK_CUR);
261 if (!memcmp(p->
buf + 8,
"WAVE", 4)) {
262 if (!memcmp(p->
buf,
"RIFF", 4))
269 else if (!memcmp(p->
buf,
"RF64", 4) &&
270 !memcmp(p->
buf + 12,
"ds64", 4))
296 static inline int wav_parse_bext_string(
AVFormatContext *s,
const char *key,
316 char temp[131], *coding_history;
318 uint64_t time_reference;
319 int64_t umid_parts[8], umid_mask = 0;
321 if ((ret = wav_parse_bext_string(s,
"description", 256)) < 0 ||
322 (ret = wav_parse_bext_string(s,
"originator", 32)) < 0 ||
323 (ret = wav_parse_bext_string(s,
"originator_reference", 32)) < 0 ||
324 (ret = wav_parse_bext_string(s,
"origination_date", 10)) < 0 ||
325 (ret = wav_parse_bext_string(s,
"origination_time", 8)) < 0)
329 snprintf(temp,
sizeof(temp),
"%"PRIu64, time_reference);
335 for (x = 0; x < 8; x++)
340 if (umid_parts[4] == 0 && umid_parts[5] == 0 && umid_parts[6] == 0 && umid_parts[7] == 0) {
342 snprintf(temp,
sizeof(temp),
"0x%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64,
343 umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3]);
346 snprintf(temp,
sizeof(temp),
"0x%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64
347 "0x%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64,
348 umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3],
349 umid_parts[4], umid_parts[5], umid_parts[6], umid_parts[7]);
364 if (!(coding_history =
av_malloc(size+1)))
367 if ((ret =
avio_read(s->
pb, coding_history, size)) < 0)
370 coding_history[
size] = 0;
380 {
"description",
"comment" },
381 {
"originator",
"encoded_by" },
382 {
"origination_date",
"date" },
383 {
"origination_time",
"creation_time"},
392 int64_t sample_count=0;
394 uint32_t
tag, list_type;
398 int ret, got_fmt = 0;
399 int64_t next_tag_ofs, data_ofs = -1;
404 rf64 = tag ==
MKTAG(
'R',
'F',
'6',
'4');
405 if (!rf64 && tag !=
MKTAG(
'R',
'I',
'F',
'F'))
409 if (tag !=
MKTAG(
'W',
'A',
'V',
'E'))
421 if (data_size < 0 || sample_count < 0) {
423 "ds64: data_size = %"PRId64
", sample_count = %"PRId64
"\n",
424 data_size, sample_count);
431 size = next_tag(pb, &tag);
438 case MKTAG(
'f',
'm',
't',
' '):
440 if (!got_fmt && (ret = wav_parse_fmt_tag(s, size, &st) < 0)) {
447 case MKTAG(
'd',
'a',
't',
'a'):
465 if (!pb->
seekable || (!rf64 && !size))
468 case MKTAG(
'f',
'a',
'c',
't'):
472 case MKTAG(
'b',
'e',
'x',
't'):
473 if ((ret = wav_parse_bext_tag(s, size)) < 0)
476 case MKTAG(
'L',
'I',
'S',
'T'):
483 case MKTAG(
'I',
'N',
'F',
'O'):
492 wav_seek_tag(pb, next_tag_ofs, SEEK_SET) < 0) {
518 static int64_t find_guid(
AVIOContext *pb,
const uint8_t guid1[16])
528 if (!memcmp(guid, guid1, 16))
535 static const uint8_t guid_data[16] = {
'd',
'a',
't',
'a',
536 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
538 #define MAX_SIZE 4096
553 left = find_guid(s->
pb, guid_data) - 24;
555 left = find_tag(s->
pb,
MKTAG(
'd',
'a',
't',
'a'));
563 if (size < st->codec->block_align)
567 size =
FFMIN(size, left);
577 int stream_index, int64_t timestamp,
int flags)
609 #if CONFIG_W64_DEMUXER
610 static const uint8_t guid_riff[16] = {
'r',
'i',
'f',
'f',
611 0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 };
613 static const uint8_t guid_wave[16] = {
'w',
'a',
'v',
'e',
614 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
616 static const uint8_t guid_fmt [16] = {
'f',
'm',
't',
' ',
617 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
623 if (!memcmp(p->
buf, guid_riff, 16) &&
624 !memcmp(p->
buf + 24, guid_wave, 16))
640 if (memcmp(guid, guid_riff, 16))
643 if (
avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8)
647 if (memcmp(guid, guid_wave, 16)) {
652 size = find_guid(pb, guid_fmt);
672 size = find_guid(pb, guid_data);
void avio_wb64(AVIOContext *s, uint64_t val)
void avio_wl16(AVIOContext *s, unsigned int val)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t avio_size(AVIOContext *s)
Get the filesize.
void ff_end_tag(AVIOContext *pb, int64_t start)
int64_t ff_start_tag(AVIOContext *pb, const char *tag)
#define AV_LOG_WARNING
Something somehow does not look correct.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void avio_wl32(AVIOContext *s, unsigned int val)
enum AVStreamParseType need_parsing
static int read_header(FFV1Context *f)
#define AVERROR_EOF
End of file.
uint64_t avio_rb64(AVIOContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
int av_get_bits_per_sample(enum CodecID codec_id)
Return codec bits per sample.
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
void avio_wl64(AVIOContext *s, uint64_t val)
unsigned int avio_rl32(AVIOContext *s)
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. ...
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
const char * name
Name of the codec implementation.
const AVCodecTag ff_codec_wav_tags[]
AVCodecContext * codec
codec context
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int void avio_flush(AVIOContext *s)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void ffio_fill(AVIOContext *s, int b, int count)
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() and chilren.
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
static int read_probe(AVProbeData *p)
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
int sample_rate
samples per second
static const OptionDef options[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
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.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
This structure contains the data a format has to probe a file.
const AVMetadataConv ff_riff_info_conv[]
int64_t duration
Decoding: duration of the stream, in stream time base.
unsigned int avio_rl16(AVIOContext *s)
int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
int eof_reached
true if eof reached
int channels
number of audio channels
void * priv_data
Format private data.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define MKTAG(a, b, c, d)
int ff_read_riff_info(AVFormatContext *s, int64_t size)
uint64_t avio_rl64(AVIOContext *s)
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.
preferred ID for decoding MPEG audio layer 1, 2 or 3