]> git.sesse.net Git - ffmpeg/blob - libavformat/wav.c
Generalize RIFF INFO tag support; support reading INFO tag in wav
[ffmpeg] / libavformat / wav.c
1 /*
2  * WAV muxer and demuxer
3  * Copyright (c) 2001, 2002 Fabrice Bellard
4  *
5  * Sony Wave64 demuxer
6  * RF64 demuxer
7  * Copyright (c) 2009 Daniel Verkamp
8  *
9  * This file is part of Libav.
10  *
11  * Libav is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * Libav is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with Libav; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24  */
25
26 #include "libavutil/avassert.h"
27 #include "libavutil/dict.h"
28 #include "libavutil/log.h"
29 #include "libavutil/mathematics.h"
30 #include "libavutil/opt.h"
31 #include "avformat.h"
32 #include "avio_internal.h"
33 #include "pcm.h"
34 #include "riff.h"
35 #include "avio.h"
36 #include "metadata.h"
37
38 typedef struct {
39     const AVClass *class;
40     int64_t data;
41     int64_t data_end;
42     int64_t minpts;
43     int64_t maxpts;
44     int last_duration;
45     int w64;
46     int write_bext;
47 } WAVContext;
48
49 #if CONFIG_WAV_MUXER
50 static inline void bwf_write_bext_string(AVFormatContext *s, const char *key, int maxlen)
51 {
52     AVDictionaryEntry *tag;
53     int len = 0;
54
55     if (tag = av_dict_get(s->metadata, key, NULL, 0)) {
56         len = strlen(tag->value);
57         len = FFMIN(len, maxlen);
58         avio_write(s->pb, tag->value, len);
59     }
60
61     ffio_fill(s->pb, 0, maxlen - len);
62 }
63
64 static void bwf_write_bext_chunk(AVFormatContext *s)
65 {
66     AVDictionaryEntry *tmp_tag;
67     uint64_t time_reference = 0;
68     int64_t bext = ff_start_tag(s->pb, "bext");
69
70     bwf_write_bext_string(s, "description", 256);
71     bwf_write_bext_string(s, "originator", 32);
72     bwf_write_bext_string(s, "originator_reference", 32);
73     bwf_write_bext_string(s, "origination_date", 10);
74     bwf_write_bext_string(s, "origination_time", 8);
75
76     if (tmp_tag = av_dict_get(s->metadata, "time_reference", NULL, 0))
77         time_reference = strtoll(tmp_tag->value, NULL, 10);
78     avio_wl64(s->pb, time_reference);
79     avio_wl16(s->pb, 1);  // set version to 1
80
81     if (tmp_tag = av_dict_get(s->metadata, "umid", NULL, 0)) {
82         unsigned char umidpart_str[17] = {0};
83         int i;
84         uint64_t umidpart;
85         int len = strlen(tmp_tag->value+2);
86
87         for (i = 0; i < len/16; i++) {
88             memcpy(umidpart_str, tmp_tag->value + 2 + (i*16), 16);
89             umidpart = strtoll(umidpart_str, NULL, 16);
90             avio_wb64(s->pb, umidpart);
91         }
92         ffio_fill(s->pb, 0, 64 - i*8);
93     } else
94         ffio_fill(s->pb, 0, 64); // zero UMID
95
96     ffio_fill(s->pb, 0, 190); // Reserved
97
98     if (tmp_tag = av_dict_get(s->metadata, "coding_history", NULL, 0))
99         avio_put_str(s->pb, tmp_tag->value);
100
101     ff_end_tag(s->pb, bext);
102 }
103
104 static int wav_write_header(AVFormatContext *s)
105 {
106     WAVContext *wav = s->priv_data;
107     AVIOContext *pb = s->pb;
108     int64_t fmt, fact;
109
110     ffio_wfourcc(pb, "RIFF");
111     avio_wl32(pb, 0); /* file length */
112     ffio_wfourcc(pb, "WAVE");
113
114     /* format header */
115     fmt = ff_start_tag(pb, "fmt ");
116     if (ff_put_wav_header(pb, s->streams[0]->codec) < 0) {
117         av_log(s, AV_LOG_ERROR, "%s codec not supported in WAVE format\n",
118                s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE");
119         return -1;
120     }
121     ff_end_tag(pb, fmt);
122
123     if (s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */
124         && s->pb->seekable) {
125         fact = ff_start_tag(pb, "fact");
126         avio_wl32(pb, 0);
127         ff_end_tag(pb, fact);
128     }
129
130     if (wav->write_bext)
131         bwf_write_bext_chunk(s);
132
133     av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
134     wav->maxpts = wav->last_duration = 0;
135     wav->minpts = INT64_MAX;
136
137     /* data header */
138     wav->data = ff_start_tag(pb, "data");
139
140     avio_flush(pb);
141
142     return 0;
143 }
144
145 static int wav_write_packet(AVFormatContext *s, AVPacket *pkt)
146 {
147     AVIOContext *pb  = s->pb;
148     WAVContext    *wav = s->priv_data;
149     avio_write(pb, pkt->data, pkt->size);
150     if(pkt->pts != AV_NOPTS_VALUE) {
151         wav->minpts        = FFMIN(wav->minpts, pkt->pts);
152         wav->maxpts        = FFMAX(wav->maxpts, pkt->pts);
153         wav->last_duration = pkt->duration;
154     } else
155         av_log(s, AV_LOG_ERROR, "wav_write_packet: NOPTS\n");
156     return 0;
157 }
158
159 static int wav_write_trailer(AVFormatContext *s)
160 {
161     AVIOContext *pb  = s->pb;
162     WAVContext    *wav = s->priv_data;
163     int64_t file_size;
164
165     avio_flush(pb);
166
167     if (s->pb->seekable) {
168         ff_end_tag(pb, wav->data);
169
170         /* update file size */
171         file_size = avio_tell(pb);
172         avio_seek(pb, 4, SEEK_SET);
173         avio_wl32(pb, (uint32_t)(file_size - 8));
174         avio_seek(pb, file_size, SEEK_SET);
175
176         avio_flush(pb);
177
178         if(s->streams[0]->codec->codec_tag != 0x01) {
179             /* Update num_samps in fact chunk */
180             int number_of_samples;
181             number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
182                                            s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num,
183                                            s->streams[0]->time_base.den);
184             avio_seek(pb, wav->data-12, SEEK_SET);
185             avio_wl32(pb, number_of_samples);
186             avio_seek(pb, file_size, SEEK_SET);
187             avio_flush(pb);
188         }
189     }
190     return 0;
191 }
192
193 #define OFFSET(x) offsetof(WAVContext, x)
194 #define ENC AV_OPT_FLAG_ENCODING_PARAM
195 static const AVOption options[] = {
196     { "write_bext", "Write BEXT chunk.", OFFSET(write_bext), AV_OPT_TYPE_INT, { 0 }, 0, 1, ENC },
197     { NULL },
198 };
199
200 static const AVClass wav_muxer_class = {
201     .class_name = "WAV muxer",
202     .item_name  = av_default_item_name,
203     .option     = options,
204     .version    = LIBAVUTIL_VERSION_INT,
205 };
206
207 AVOutputFormat ff_wav_muxer = {
208     .name              = "wav",
209     .long_name         = NULL_IF_CONFIG_SMALL("WAV format"),
210     .mime_type         = "audio/x-wav",
211     .extensions        = "wav",
212     .priv_data_size    = sizeof(WAVContext),
213     .audio_codec       = CODEC_ID_PCM_S16LE,
214     .video_codec       = CODEC_ID_NONE,
215     .write_header      = wav_write_header,
216     .write_packet      = wav_write_packet,
217     .write_trailer     = wav_write_trailer,
218     .codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0},
219     .priv_class = &wav_muxer_class,
220 };
221 #endif /* CONFIG_WAV_MUXER */
222
223
224 #if CONFIG_WAV_DEMUXER
225
226 static int64_t next_tag(AVIOContext *pb, uint32_t *tag)
227 {
228     *tag = avio_rl32(pb);
229     return avio_rl32(pb);
230 }
231
232 /* return the size of the found tag */
233 static int64_t find_tag(AVIOContext *pb, uint32_t tag1)
234 {
235     unsigned int tag;
236     int64_t size;
237
238     for (;;) {
239         if (pb->eof_reached)
240             return -1;
241         size = next_tag(pb, &tag);
242         if (tag == tag1)
243             break;
244         avio_skip(pb, size);
245     }
246     return size;
247 }
248
249 static int wav_probe(AVProbeData *p)
250 {
251     /* check file header */
252     if (p->buf_size <= 32)
253         return 0;
254     if (!memcmp(p->buf + 8, "WAVE", 4)) {
255         if (!memcmp(p->buf, "RIFF", 4))
256             /*
257               Since ACT demuxer has standard WAV header at top of it's own,
258               returning score is decreased to avoid probe conflict
259               between ACT and WAV.
260             */
261             return AVPROBE_SCORE_MAX - 1;
262         else if (!memcmp(p->buf,      "RF64", 4) &&
263                  !memcmp(p->buf + 12, "ds64", 4))
264             return AVPROBE_SCORE_MAX;
265     }
266     return 0;
267 }
268
269 static int wav_parse_fmt_tag(AVFormatContext *s, int64_t size, AVStream **st)
270 {
271     AVIOContext *pb = s->pb;
272     int ret;
273
274     /* parse fmt header */
275     *st = avformat_new_stream(s, NULL);
276     if (!*st)
277         return AVERROR(ENOMEM);
278
279     ret = ff_get_wav_header(pb, (*st)->codec, size);
280     if (ret < 0)
281         return ret;
282     (*st)->need_parsing = AVSTREAM_PARSE_FULL;
283
284     av_set_pts_info(*st, 64, 1, (*st)->codec->sample_rate);
285
286     return 0;
287 }
288
289 static inline int wav_parse_bext_string(AVFormatContext *s, const char *key,
290                                         int length)
291 {
292     char temp[257];
293     int ret;
294
295     av_assert0(length <= sizeof(temp));
296     if ((ret = avio_read(s->pb, temp, length)) < 0)
297         return ret;
298
299     temp[length] = 0;
300
301     if (strlen(temp))
302         return av_dict_set(&s->metadata, key, temp, 0);
303
304     return 0;
305 }
306
307 static int wav_parse_bext_tag(AVFormatContext *s, int64_t size)
308 {
309     char temp[131], *coding_history;
310     int ret, x;
311     uint64_t time_reference;
312     int64_t umid_parts[8], umid_mask = 0;
313
314     if ((ret = wav_parse_bext_string(s, "description", 256)) < 0 ||
315         (ret = wav_parse_bext_string(s, "originator", 32)) < 0 ||
316         (ret = wav_parse_bext_string(s, "originator_reference", 32)) < 0 ||
317         (ret = wav_parse_bext_string(s, "origination_date", 10)) < 0 ||
318         (ret = wav_parse_bext_string(s, "origination_time", 8)) < 0)
319         return ret;
320
321     time_reference = avio_rl64(s->pb);
322     snprintf(temp, sizeof(temp), "%"PRIu64, time_reference);
323     if ((ret = av_dict_set(&s->metadata, "time_reference", temp, 0)) < 0)
324         return ret;
325
326     /* check if version is >= 1, in which case an UMID may be present */
327     if (avio_rl16(s->pb) >= 1) {
328         for (x = 0; x < 8; x++)
329             umid_mask |= umid_parts[x] = avio_rb64(s->pb);
330
331         if (umid_mask) {
332             /* the string formatting below is per SMPTE 330M-2004 Annex C */
333             if (umid_parts[4] == 0 && umid_parts[5] == 0 && umid_parts[6] == 0 && umid_parts[7] == 0) {
334                 /* basic UMID */
335                 snprintf(temp, sizeof(temp), "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64,
336                          umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3]);
337             } else {
338                 /* extended UMID */
339                 snprintf(temp, sizeof(temp), "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64
340                                              "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64,
341                          umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3],
342                          umid_parts[4], umid_parts[5], umid_parts[6], umid_parts[7]);
343             }
344
345             if ((ret = av_dict_set(&s->metadata, "umid", temp, 0)) < 0)
346                 return ret;
347         }
348
349         avio_skip(s->pb, 190);
350     } else
351         avio_skip(s->pb, 254);
352
353     if (size > 602) {
354         /* CodingHistory present */
355         size -= 602;
356
357         if (!(coding_history = av_malloc(size+1)))
358             return AVERROR(ENOMEM);
359
360         if ((ret = avio_read(s->pb, coding_history, size)) < 0)
361             return ret;
362
363         coding_history[size] = 0;
364         if ((ret = av_dict_set(&s->metadata, "coding_history", coding_history,
365                                AV_DICT_DONT_STRDUP_VAL)) < 0)
366             return ret;
367     }
368
369     return 0;
370 }
371
372 static const AVMetadataConv wav_metadata_conv[] = {
373     {"description",      "comment"      },
374     {"originator",       "encoded_by"   },
375     {"origination_date", "date"         },
376     {"origination_time", "creation_time"},
377     {0},
378 };
379
380 /* wav input */
381 static int wav_read_header(AVFormatContext *s,
382                            AVFormatParameters *ap)
383 {
384     int64_t size, av_uninit(data_size);
385     int64_t sample_count=0;
386     int rf64;
387     uint32_t tag, list_type;
388     AVIOContext *pb = s->pb;
389     AVStream *st;
390     WAVContext *wav = s->priv_data;
391     int ret, got_fmt = 0;
392     int64_t next_tag_ofs, data_ofs = -1;
393
394     /* check RIFF header */
395     tag = avio_rl32(pb);
396
397     rf64 = tag == MKTAG('R', 'F', '6', '4');
398     if (!rf64 && tag != MKTAG('R', 'I', 'F', 'F'))
399         return -1;
400     avio_rl32(pb); /* file size */
401     tag = avio_rl32(pb);
402     if (tag != MKTAG('W', 'A', 'V', 'E'))
403         return -1;
404
405     if (rf64) {
406         if (avio_rl32(pb) != MKTAG('d', 's', '6', '4'))
407             return -1;
408         size = avio_rl32(pb);
409         if (size < 16)
410             return -1;
411         avio_rl64(pb); /* RIFF size */
412         data_size = avio_rl64(pb);
413         sample_count = avio_rl64(pb);
414         if (data_size < 0 || sample_count < 0) {
415             av_log(s, AV_LOG_ERROR, "negative data_size and/or sample_count in "
416                    "ds64: data_size = %"PRId64", sample_count = %"PRId64"\n",
417                    data_size, sample_count);
418             return AVERROR_INVALIDDATA;
419         }
420         avio_skip(pb, size - 16); /* skip rest of ds64 chunk */
421     }
422
423     for (;;) {
424         size = next_tag(pb, &tag);
425         next_tag_ofs = avio_tell(pb) + size;
426
427         if (pb->eof_reached)
428             break;
429
430         switch (tag) {
431         case MKTAG('f', 'm', 't', ' '):
432             /* only parse the first 'fmt ' tag found */
433             if (!got_fmt && (ret = wav_parse_fmt_tag(s, size, &st) < 0)) {
434                 return ret;
435             } else if (got_fmt)
436                 av_log(s, AV_LOG_WARNING, "found more than one 'fmt ' tag\n");
437
438             got_fmt = 1;
439             break;
440         case MKTAG('d', 'a', 't', 'a'):
441             if (!got_fmt) {
442                 av_log(s, AV_LOG_ERROR, "found no 'fmt ' tag before the 'data' tag\n");
443                 return AVERROR_INVALIDDATA;
444             }
445
446             if (rf64) {
447                 next_tag_ofs = wav->data_end = avio_tell(pb) + data_size;
448             } else {
449                 data_size = size;
450                 next_tag_ofs = wav->data_end = size ? next_tag_ofs : INT64_MAX;
451             }
452
453             data_ofs = avio_tell(pb);
454
455             /* don't look for footer metadata if we can't seek or if we don't
456              * know where the data tag ends
457              */
458             if (!pb->seekable || (!rf64 && !size))
459                 goto break_loop;
460             break;
461         case MKTAG('f','a','c','t'):
462             if (!sample_count)
463                 sample_count = avio_rl32(pb);
464             break;
465         case MKTAG('b','e','x','t'):
466             if ((ret = wav_parse_bext_tag(s, size)) < 0)
467                 return ret;
468             break;
469         case MKTAG('L', 'I', 'S', 'T'):
470             list_type = avio_rl32(pb);
471             if (size <= 4) {
472                 av_log(s, AV_LOG_ERROR, "too short LIST");
473                 return AVERROR_INVALIDDATA;
474             }
475             switch (list_type) {
476             case MKTAG('I', 'N', 'F', 'O'):
477                 if ((ret = ff_read_riff_info(s, size - 4)) < 0)
478                     return ret;
479             }
480             break;
481         }
482
483         /* seek to next tag unless we know that we'll run into EOF */
484         if ((avio_size(pb) > 0 && next_tag_ofs >= avio_size(pb)) ||
485             avio_seek(pb, next_tag_ofs, SEEK_SET) < 0) {
486             break;
487         }
488     }
489 break_loop:
490     if (data_ofs < 0) {
491         av_log(s, AV_LOG_ERROR, "no 'data' tag found\n");
492         return AVERROR_INVALIDDATA;
493     }
494
495     avio_seek(pb, data_ofs, SEEK_SET);
496
497     if (!sample_count && st->codec->channels && av_get_bits_per_sample(st->codec->codec_id))
498         sample_count = (data_size<<3) / (st->codec->channels * (uint64_t)av_get_bits_per_sample(st->codec->codec_id));
499     if (sample_count)
500         st->duration = sample_count;
501
502     ff_metadata_conv_ctx(s, NULL, wav_metadata_conv);
503     ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv);
504
505     return 0;
506 }
507
508 /** Find chunk with w64 GUID by skipping over other chunks
509  * @return the size of the found chunk
510  */
511 static int64_t find_guid(AVIOContext *pb, const uint8_t guid1[16])
512 {
513     uint8_t guid[16];
514     int64_t size;
515
516     while (!pb->eof_reached) {
517         avio_read(pb, guid, 16);
518         size = avio_rl64(pb);
519         if (size <= 24)
520             return -1;
521         if (!memcmp(guid, guid1, 16))
522             return size;
523         avio_skip(pb, FFALIGN(size, INT64_C(8)) - 24);
524     }
525     return -1;
526 }
527
528 static const uint8_t guid_data[16] = { 'd', 'a', 't', 'a',
529     0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
530
531 #define MAX_SIZE 4096
532
533 static int wav_read_packet(AVFormatContext *s,
534                            AVPacket *pkt)
535 {
536     int ret, size;
537     int64_t left;
538     AVStream *st;
539     WAVContext *wav = s->priv_data;
540
541     st = s->streams[0];
542
543     left = wav->data_end - avio_tell(s->pb);
544     if (left <= 0){
545         if (CONFIG_W64_DEMUXER && wav->w64)
546             left = find_guid(s->pb, guid_data) - 24;
547         else
548             left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a'));
549         if (left < 0)
550             return AVERROR_EOF;
551         wav->data_end= avio_tell(s->pb) + left;
552     }
553
554     size = MAX_SIZE;
555     if (st->codec->block_align > 1) {
556         if (size < st->codec->block_align)
557             size = st->codec->block_align;
558         size = (size / st->codec->block_align) * st->codec->block_align;
559     }
560     size = FFMIN(size, left);
561     ret  = av_get_packet(s->pb, pkt, size);
562     if (ret < 0)
563         return ret;
564     pkt->stream_index = 0;
565
566     return ret;
567 }
568
569 static int wav_read_seek(AVFormatContext *s,
570                          int stream_index, int64_t timestamp, int flags)
571 {
572     AVStream *st;
573
574     st = s->streams[0];
575     switch (st->codec->codec_id) {
576     case CODEC_ID_MP2:
577     case CODEC_ID_MP3:
578     case CODEC_ID_AC3:
579     case CODEC_ID_DTS:
580         /* use generic seeking with dynamically generated indexes */
581         return -1;
582     default:
583         break;
584     }
585     return pcm_read_seek(s, stream_index, timestamp, flags);
586 }
587
588 AVInputFormat ff_wav_demuxer = {
589     .name           = "wav",
590     .long_name      = NULL_IF_CONFIG_SMALL("WAV format"),
591     .priv_data_size = sizeof(WAVContext),
592     .read_probe     = wav_probe,
593     .read_header    = wav_read_header,
594     .read_packet    = wav_read_packet,
595     .read_seek      = wav_read_seek,
596     .flags= AVFMT_GENERIC_INDEX,
597     .codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0},
598 };
599 #endif /* CONFIG_WAV_DEMUXER */
600
601
602 #if CONFIG_W64_DEMUXER
603 static const uint8_t guid_riff[16] = { 'r', 'i', 'f', 'f',
604     0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 };
605
606 static const uint8_t guid_wave[16] = { 'w', 'a', 'v', 'e',
607     0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
608
609 static const uint8_t guid_fmt [16] = { 'f', 'm', 't', ' ',
610     0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
611
612 static int w64_probe(AVProbeData *p)
613 {
614     if (p->buf_size <= 40)
615         return 0;
616     if (!memcmp(p->buf,      guid_riff, 16) &&
617         !memcmp(p->buf + 24, guid_wave, 16))
618         return AVPROBE_SCORE_MAX;
619     else
620         return 0;
621 }
622
623 static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap)
624 {
625     int64_t size;
626     AVIOContext *pb  = s->pb;
627     WAVContext    *wav = s->priv_data;
628     AVStream *st;
629     uint8_t guid[16];
630     int ret;
631
632     avio_read(pb, guid, 16);
633     if (memcmp(guid, guid_riff, 16))
634         return -1;
635
636     if (avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8) /* riff + wave + fmt + sizes */
637         return -1;
638
639     avio_read(pb, guid, 16);
640     if (memcmp(guid, guid_wave, 16)) {
641         av_log(s, AV_LOG_ERROR, "could not find wave guid\n");
642         return -1;
643     }
644
645     size = find_guid(pb, guid_fmt);
646     if (size < 0) {
647         av_log(s, AV_LOG_ERROR, "could not find fmt guid\n");
648         return -1;
649     }
650
651     st = avformat_new_stream(s, NULL);
652     if (!st)
653         return AVERROR(ENOMEM);
654
655     /* subtract chunk header size - normal wav file doesn't count it */
656     ret = ff_get_wav_header(pb, st->codec, size - 24);
657     if (ret < 0)
658         return ret;
659     avio_skip(pb, FFALIGN(size, INT64_C(8)) - size);
660
661     st->need_parsing = AVSTREAM_PARSE_FULL;
662
663     av_set_pts_info(st, 64, 1, st->codec->sample_rate);
664
665     size = find_guid(pb, guid_data);
666     if (size < 0) {
667         av_log(s, AV_LOG_ERROR, "could not find data guid\n");
668         return -1;
669     }
670     wav->data_end = avio_tell(pb) + size - 24;
671     wav->w64      = 1;
672
673     return 0;
674 }
675
676 AVInputFormat ff_w64_demuxer = {
677     .name           = "w64",
678     .long_name      = NULL_IF_CONFIG_SMALL("Sony Wave64 format"),
679     .priv_data_size = sizeof(WAVContext),
680     .read_probe     = w64_probe,
681     .read_header    = w64_read_header,
682     .read_packet    = wav_read_packet,
683     .read_seek      = wav_read_seek,
684     .flags = AVFMT_GENERIC_INDEX,
685     .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0},
686 };
687 #endif /* CONFIG_W64_DEMUXER */