+static const uint8_t guid_riff[16] = { 'r', 'i', 'f', 'f',
+ 0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 };
+
+static const uint8_t guid_wave[16] = { 'w', 'a', 'v', 'e',
+ 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
+
+static const uint8_t guid_fmt [16] = { 'f', 'm', 't', ' ',
+ 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
+
+static int w64_probe(AVProbeData *p)
+{
+ if (p->buf_size <= 40)
+ return 0;
+ if (!memcmp(p->buf, guid_riff, 16) &&
+ !memcmp(p->buf + 24, guid_wave, 16))
+ return AVPROBE_SCORE_MAX;
+ else
+ return 0;
+}
+
+static int w64_read_header(AVFormatContext *s)
+{
+ int64_t size;
+ AVIOContext *pb = s->pb;
+ WAVContext *wav = s->priv_data;
+ AVStream *st;
+ uint8_t guid[16];
+ int ret;
+
+ avio_read(pb, guid, 16);
+ if (memcmp(guid, guid_riff, 16))
+ return -1;
+
+ if (avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8) /* riff + wave + fmt + sizes */
+ return -1;
+
+ avio_read(pb, guid, 16);
+ if (memcmp(guid, guid_wave, 16)) {
+ av_log(s, AV_LOG_ERROR, "could not find wave guid\n");
+ return -1;
+ }
+
+ size = find_guid(pb, guid_fmt);
+ if (size < 0) {
+ av_log(s, AV_LOG_ERROR, "could not find fmt guid\n");
+ return -1;
+ }
+
+ st = avformat_new_stream(s, NULL);
+ if (!st)
+ return AVERROR(ENOMEM);
+
+ /* subtract chunk header size - normal wav file doesn't count it */
+ ret = ff_get_wav_header(pb, st->codec, size - 24);
+ if (ret < 0)
+ return ret;
+ avio_skip(pb, FFALIGN(size, INT64_C(8)) - size);
+
+ st->need_parsing = AVSTREAM_PARSE_FULL;
+
+ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+
+ size = find_guid(pb, guid_data);
+ if (size < 0) {
+ av_log(s, AV_LOG_ERROR, "could not find data guid\n");
+ return -1;
+ }
+ wav->data_end = avio_tell(pb) + size - 24;
+ wav->w64 = 1;
+
+ return 0;
+}
+
+AVInputFormat ff_w64_demuxer = {
+ .name = "w64",
+ .long_name = NULL_IF_CONFIG_SMALL("Sony Wave64 format"),
+ .priv_data_size = sizeof(WAVContext),
+ .read_probe = w64_probe,
+ .read_header = w64_read_header,
+ .read_packet = wav_read_packet,
+ .read_seek = wav_read_seek,