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 find_tag(
AVIOContext *pb, uint32_t tag1)
242 size = next_tag(pb, &tag);
255 if (!memcmp(p->
buf + 8,
"WAVE", 4)) {
256 if (!memcmp(p->
buf,
"RIFF", 4))
263 else if (!memcmp(p->
buf,
"RF64", 4) &&
264 !memcmp(p->
buf + 12,
"ds64", 4))
290 static inline int wav_parse_bext_string(
AVFormatContext *s,
const char *key,
310 char temp[131], *coding_history;
312 uint64_t time_reference;
313 int64_t umid_parts[8], umid_mask = 0;
315 if ((ret = wav_parse_bext_string(s,
"description", 256)) < 0 ||
316 (ret = wav_parse_bext_string(s,
"originator", 32)) < 0 ||
317 (ret = wav_parse_bext_string(s,
"originator_reference", 32)) < 0 ||
318 (ret = wav_parse_bext_string(s,
"origination_date", 10)) < 0 ||
319 (ret = wav_parse_bext_string(s,
"origination_time", 8)) < 0)
323 snprintf(temp,
sizeof(temp),
"%"PRIu64, time_reference);
329 for (x = 0; x < 8; x++)
334 if (umid_parts[4] == 0 && umid_parts[5] == 0 && umid_parts[6] == 0 && umid_parts[7] == 0) {
336 snprintf(temp,
sizeof(temp),
"0x%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64,
337 umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3]);
340 snprintf(temp,
sizeof(temp),
"0x%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64
341 "0x%016"PRIX64
"%016"PRIX64
"%016"PRIX64
"%016"PRIX64,
342 umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3],
343 umid_parts[4], umid_parts[5], umid_parts[6], umid_parts[7]);
358 if (!(coding_history =
av_malloc(size+1)))
361 if ((ret =
avio_read(s->
pb, coding_history, size)) < 0)
364 coding_history[
size] = 0;
374 {
"description",
"comment" },
375 {
"originator",
"encoded_by" },
376 {
"origination_date",
"date" },
377 {
"origination_time",
"creation_time"},
386 int64_t sample_count=0;
388 uint32_t
tag, list_type;
392 int ret, got_fmt = 0;
393 int64_t next_tag_ofs, data_ofs = -1;
398 rf64 = tag ==
MKTAG(
'R',
'F',
'6',
'4');
399 if (!rf64 && tag !=
MKTAG(
'R',
'I',
'F',
'F'))
403 if (tag !=
MKTAG(
'W',
'A',
'V',
'E'))
415 if (data_size < 0 || sample_count < 0) {
417 "ds64: data_size = %"PRId64
", sample_count = %"PRId64
"\n",
418 data_size, sample_count);
425 size = next_tag(pb, &tag);
432 case MKTAG(
'f',
'm',
't',
' '):
434 if (!got_fmt && (ret = wav_parse_fmt_tag(s, size, &st) < 0)) {
441 case MKTAG(
'd',
'a',
't',
'a'):
459 if (!pb->
seekable || (!rf64 && !size))
462 case MKTAG(
'f',
'a',
'c',
't'):
466 case MKTAG(
'b',
'e',
'x',
't'):
467 if ((ret = wav_parse_bext_tag(s, size)) < 0)
470 case MKTAG(
'L',
'I',
'S',
'T'):
477 case MKTAG(
'I',
'N',
'F',
'O'):
486 avio_seek(pb, next_tag_ofs, SEEK_SET) < 0) {
512 static int64_t find_guid(
AVIOContext *pb,
const uint8_t guid1[16])
522 if (!memcmp(guid, guid1, 16))
529 static const uint8_t guid_data[16] = {
'd',
'a',
't',
'a',
530 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
532 #define MAX_SIZE 4096
546 if (CONFIG_W64_DEMUXER && wav->
w64)
547 left = find_guid(s->
pb, guid_data) - 24;
549 left = find_tag(s->
pb,
MKTAG(
'd',
'a',
't',
'a'));
557 if (size < st->codec->block_align)
561 size =
FFMIN(size, left);
571 int stream_index, int64_t timestamp,
int flags)
603 #if CONFIG_W64_DEMUXER
604 static const uint8_t guid_riff[16] = {
'r',
'i',
'f',
'f',
605 0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 };
607 static const uint8_t guid_wave[16] = {
'w',
'a',
'v',
'e',
608 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
610 static const uint8_t guid_fmt [16] = {
'f',
'm',
't',
' ',
611 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
617 if (!memcmp(p->
buf, guid_riff, 16) &&
618 !memcmp(p->
buf + 24, guid_wave, 16))
634 if (memcmp(guid, guid_riff, 16))
637 if (
avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8)
641 if (memcmp(guid, guid_wave, 16)) {
646 size = find_guid(pb, guid_fmt);
666 size = find_guid(pb, guid_data);