Browse code

Sony Wave64 muxer

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2012/12/28 22:40:55
Showing 13 changed files
... ...
@@ -51,6 +51,7 @@ version <next>:
51 51
 - pp (postproc) filter ported from MPlayer
52 52
 - NIST Sphere demuxer
53 53
 - MPL2, VPlayer, MPlayer, AQTitle, PJS and SubViewer v1 subtitles demuxers and decoders
54
+- Sony Wave64 muxer
54 55
 
55 56
 
56 57
 version 1.0:
... ...
@@ -1899,6 +1899,7 @@ tg2_muxer_select="mov_muxer"
1899 1899
 tgp_muxer_select="mov_muxer"
1900 1900
 vobsub_demuxer_select="mpegps_demuxer"
1901 1901
 w64_demuxer_deps="wav_demuxer"
1902
+w64_muxer_deps="wav_muxer"
1902 1903
 
1903 1904
 # indevs / outdevs
1904 1905
 alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"
... ...
@@ -374,7 +374,7 @@ library:
374 374
 @item Sony OpenMG (OMA)         @tab X @tab X
375 375
     @tab Audio format used in Sony Sonic Stage and Sony Vegas.
376 376
 @item Sony PlayStation STR      @tab   @tab X
377
-@item Sony Wave64 (W64)         @tab   @tab X
377
+@item Sony Wave64 (W64)         @tab X @tab X
378 378
 @item SoX native format         @tab X @tab X
379 379
 @item SUN AU format             @tab X @tab X
380 380
 @item Text files                @tab   @tab X
... ...
@@ -372,7 +372,8 @@ OBJS-$(CONFIG_VOC_DEMUXER)               += vocdec.o voc.o
372 372
 OBJS-$(CONFIG_VOC_MUXER)                 += vocenc.o voc.o
373 373
 OBJS-$(CONFIG_VPLAYER_DEMUXER)           += vplayerdec.o
374 374
 OBJS-$(CONFIG_VQF_DEMUXER)               += vqf.o
375
-OBJS-$(CONFIG_W64_DEMUXER)               += wavdec.o pcm.o
375
+OBJS-$(CONFIG_W64_DEMUXER)               += wavdec.o w64.o pcm.o
376
+OBJS-$(CONFIG_W64_MUXER)                 += wavenc.o w64.o
376 377
 OBJS-$(CONFIG_WAV_DEMUXER)               += wavdec.o pcm.o
377 378
 OBJS-$(CONFIG_WAV_MUXER)                 += wavenc.o
378 379
 OBJS-$(CONFIG_WC3_DEMUXER)               += wc3movie.o
... ...
@@ -282,7 +282,7 @@ void av_register_all(void)
282 282
     REGISTER_MUXDEMUX(VOC,              voc);
283 283
     REGISTER_DEMUXER (VPLAYER,          vplayer);
284 284
     REGISTER_DEMUXER (VQF,              vqf);
285
-    REGISTER_DEMUXER (W64,              w64);
285
+    REGISTER_MUXDEMUX(W64,              w64);
286 286
     REGISTER_MUXDEMUX(WAV,              wav);
287 287
     REGISTER_DEMUXER (WC3,              wc3);
288 288
     REGISTER_MUXER   (WEBM,             webm);
... ...
@@ -30,7 +30,7 @@
30 30
 #include "libavutil/avutil.h"
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 54
33
-#define LIBAVFORMAT_VERSION_MINOR 57
33
+#define LIBAVFORMAT_VERSION_MINOR 58
34 34
 #define LIBAVFORMAT_VERSION_MICRO 100
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
37 37
new file mode 100644
... ...
@@ -0,0 +1,33 @@
0
+/*
1
+ * Copyright (c) 2009 Daniel Verkamp
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#include "w64.h"
21
+
22
+const uint8_t ff_w64_guid_riff[16] = { 'r', 'i', 'f', 'f',
23
+    0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 };
24
+
25
+const uint8_t ff_w64_guid_wave[16] = { 'w', 'a', 'v', 'e',
26
+    0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
27
+
28
+const uint8_t ff_w64_guid_fmt [16] = { 'f', 'm', 't', ' ',
29
+    0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
30
+
31
+const uint8_t ff_w64_guid_data[16] = { 'd', 'a', 't', 'a',
32
+    0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
0 33
new file mode 100644
... ...
@@ -0,0 +1,29 @@
0
+/*
1
+ * This file is part of FFmpeg.
2
+ *
3
+ * FFmpeg is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU Lesser General Public
5
+ * License as published by the Free Software Foundation; either
6
+ * version 2.1 of the License, or (at your option) any later version.
7
+ *
8
+ * FFmpeg is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
+ * Lesser General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Lesser General Public
14
+ * License along with FFmpeg; if not, write to the Free Software
15
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+#ifndef AVFORMAT_W64_H
19
+#define AVFORMAT_W64_H
20
+
21
+#include <stdint.h>
22
+
23
+extern const uint8_t ff_w64_guid_riff[16];
24
+extern const uint8_t ff_w64_guid_wave[16];
25
+extern const uint8_t ff_w64_guid_fmt [16];
26
+extern const uint8_t ff_w64_guid_data[16];
27
+
28
+#endif /* AVFORMAT_W64_H */
... ...
@@ -33,6 +33,7 @@
33 33
 #include "avio_internal.h"
34 34
 #include "pcm.h"
35 35
 #include "riff.h"
36
+#include "w64.h"
36 37
 #include "avio.h"
37 38
 #include "metadata.h"
38 39
 
... ...
@@ -396,9 +397,6 @@ static int64_t find_guid(AVIOContext *pb, const uint8_t guid1[16])
396 396
     return -1;
397 397
 }
398 398
 
399
-static const uint8_t guid_data[16] = { 'd', 'a', 't', 'a',
400
-    0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
401
-
402 399
 #define MAX_SIZE 4096
403 400
 
404 401
 static int wav_read_packet(AVFormatContext *s,
... ...
@@ -455,7 +453,7 @@ smv_out:
455 455
         left= INT_MAX;
456 456
     if (left <= 0){
457 457
         if (CONFIG_W64_DEMUXER && wav->w64)
458
-            left = find_guid(s->pb, guid_data) - 24;
458
+            left = find_guid(s->pb, ff_w64_guid_data) - 24;
459 459
         else
460 460
             left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a'));
461 461
         if (left < 0) {
... ...
@@ -541,21 +539,12 @@ AVInputFormat ff_wav_demuxer = {
541 541
 
542 542
 
543 543
 #if CONFIG_W64_DEMUXER
544
-static const uint8_t guid_riff[16] = { 'r', 'i', 'f', 'f',
545
-    0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 };
546
-
547
-static const uint8_t guid_wave[16] = { 'w', 'a', 'v', 'e',
548
-    0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
549
-
550
-static const uint8_t guid_fmt [16] = { 'f', 'm', 't', ' ',
551
-    0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A };
552
-
553 544
 static int w64_probe(AVProbeData *p)
554 545
 {
555 546
     if (p->buf_size <= 40)
556 547
         return 0;
557
-    if (!memcmp(p->buf,      guid_riff, 16) &&
558
-        !memcmp(p->buf + 24, guid_wave, 16))
548
+    if (!memcmp(p->buf,      ff_w64_guid_riff, 16) &&
549
+        !memcmp(p->buf + 24, ff_w64_guid_wave, 16))
559 550
         return AVPROBE_SCORE_MAX;
560 551
     else
561 552
         return 0;
... ...
@@ -571,19 +560,19 @@ static int w64_read_header(AVFormatContext *s)
571 571
     int ret;
572 572
 
573 573
     avio_read(pb, guid, 16);
574
-    if (memcmp(guid, guid_riff, 16))
574
+    if (memcmp(guid, ff_w64_guid_riff, 16))
575 575
         return -1;
576 576
 
577 577
     if (avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8) /* riff + wave + fmt + sizes */
578 578
         return -1;
579 579
 
580 580
     avio_read(pb, guid, 16);
581
-    if (memcmp(guid, guid_wave, 16)) {
581
+    if (memcmp(guid, ff_w64_guid_wave, 16)) {
582 582
         av_log(s, AV_LOG_ERROR, "could not find wave guid\n");
583 583
         return -1;
584 584
     }
585 585
 
586
-    size = find_guid(pb, guid_fmt);
586
+    size = find_guid(pb, ff_w64_guid_fmt);
587 587
     if (size < 0) {
588 588
         av_log(s, AV_LOG_ERROR, "could not find fmt guid\n");
589 589
         return -1;
... ...
@@ -604,7 +593,7 @@ static int w64_read_header(AVFormatContext *s)
604 604
 
605 605
     avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
606 606
 
607
-    size = find_guid(pb, guid_data);
607
+    size = find_guid(pb, ff_w64_guid_data);
608 608
     if (size < 0) {
609 609
         av_log(s, AV_LOG_ERROR, "could not find data guid\n");
610 610
         return -1;
... ...
@@ -2,6 +2,9 @@
2 2
  * WAV muxer
3 3
  * Copyright (c) 2001, 2002 Fabrice Bellard
4 4
  *
5
+ * Sony Wave64 muxer
6
+ * Copyright (c) 2012 Paul B Mahol
7
+ *
5 8
  * This file is part of FFmpeg.
6 9
  *
7 10
  * FFmpeg is free software; you can redistribute it and/or
... ...
@@ -43,6 +46,7 @@ typedef struct WAVMuxContext {
43 43
     int write_bext;
44 44
 } WAVMuxContext;
45 45
 
46
+#if CONFIG_WAV_MUXER
46 47
 static inline void bwf_write_bext_string(AVFormatContext *s, const char *key, int maxlen)
47 48
 {
48 49
     AVDictionaryEntry *tag;
... ...
@@ -218,3 +222,83 @@ AVOutputFormat ff_wav_muxer = {
218 218
     .codec_tag         = (const AVCodecTag* const []){ ff_codec_wav_tags, 0 },
219 219
     .priv_class        = &wav_muxer_class,
220 220
 };
221
+#endif /* CONFIG_WAV_MUXER */
222
+
223
+#if CONFIG_W64_MUXER
224
+#include "w64.h"
225
+
226
+static void start_guid(AVIOContext *pb, const uint8_t *guid, int64_t *pos)
227
+{
228
+    *pos = avio_tell(pb);
229
+
230
+    avio_write(pb, guid, 16);
231
+    avio_wl64(pb, INT64_MAX);
232
+}
233
+
234
+static void end_guid(AVIOContext *pb, int64_t start)
235
+{
236
+    int64_t end, pos = avio_tell(pb);
237
+
238
+    end = FFALIGN(pos, 8);
239
+    ffio_fill(pb, 0, end - pos);
240
+    avio_seek(pb, start + 16, SEEK_SET);
241
+    avio_wl64(pb, end - start);
242
+    avio_seek(pb, end, SEEK_SET);
243
+}
244
+
245
+static int w64_write_header(AVFormatContext *s)
246
+{
247
+    WAVMuxContext *wav = s->priv_data;
248
+    AVIOContext *pb = s->pb;
249
+    int64_t start;
250
+    int ret;
251
+
252
+    avio_write(pb, ff_w64_guid_riff, sizeof(ff_w64_guid_riff));
253
+    avio_wl64(pb, -1);
254
+    avio_write(pb, ff_w64_guid_wave, sizeof(ff_w64_guid_wave));
255
+    start_guid(pb, ff_w64_guid_fmt, &start);
256
+    if ((ret = ff_put_wav_header(pb, s->streams[0]->codec)) < 0) {
257
+        av_log(s, AV_LOG_ERROR, "%s codec not supported\n",
258
+               s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE");
259
+        return ret;
260
+    }
261
+    end_guid(pb, start);
262
+    start_guid(pb, ff_w64_guid_data, &wav->data);
263
+
264
+    return 0;
265
+}
266
+
267
+static int w64_write_trailer(AVFormatContext *s)
268
+{
269
+    AVIOContext    *pb = s->pb;
270
+    WAVMuxContext *wav = s->priv_data;
271
+    int64_t file_size;
272
+
273
+    if (pb->seekable) {
274
+        end_guid(pb, wav->data);
275
+
276
+        file_size = avio_tell(pb);
277
+        avio_seek(pb, 16, SEEK_SET);
278
+        avio_wl64(pb, file_size);
279
+        avio_seek(pb, file_size, SEEK_SET);
280
+
281
+        avio_flush(pb);
282
+    }
283
+
284
+    return 0;
285
+}
286
+
287
+AVOutputFormat ff_w64_muxer = {
288
+    .name              = "w64",
289
+    .long_name         = NULL_IF_CONFIG_SMALL("Sony Wave64"),
290
+    .extensions        = "w64",
291
+    .priv_data_size    = sizeof(WAVMuxContext),
292
+    .audio_codec       = AV_CODEC_ID_PCM_S16LE,
293
+    .video_codec       = AV_CODEC_ID_NONE,
294
+    .write_header      = w64_write_header,
295
+    .write_packet      = wav_write_packet,
296
+    .write_trailer     = w64_write_trailer,
297
+    .flags             = AVFMT_TS_NONSTRICT,
298
+    .codec_tag         = (const AVCodecTag* const []){ ff_codec_wav_tags, 0 },
299
+};
300
+#endif /* CONFIG_W64_MUXER */
... ...
@@ -45,6 +45,7 @@ FATE_LAVF-$(call ENCDEC2, MPEG2VIDEO, MP2,       MPEGTS)             += ts
45 45
 FATE_LAVF-$(call ENCDEC,  PCM_U8,                VOC)                += voc
46 46
 FATE_LAVF-$(call ENCDEC,  PCM_S16LE,             VOC)                += voc_s16
47 47
 FATE_LAVF-$(call ENCDEC,  PCM_S16LE,             WAV)                += wav
48
+FATE_LAVF-$(call ENCMUX,  PCM_S16LE,             W64)                += w64
48 49
 FATE_LAVF-$(call ENCDEC,  MP2,                   WTV)                += wtv
49 50
 FATE_LAVF-$(call ENCDEC,  XBM,                   IMAGE2)             += xbm
50 51
 FATE_LAVF-$(call ENCDEC,  XWD,                   IMAGE2)             += xwd
... ...
@@ -334,6 +334,10 @@ if [ -n "$do_ircam" ] ; then
334 334
 do_audio_only ircam
335 335
 fi
336 336
 
337
+if [ -n "$do_w64" ] ; then
338
+do_audio_only w64
339
+fi
340
+
337 341
 # pix_fmt conversions
338 342
 
339 343
 if [ -n "$do_pixfmt" ] ; then
340 344
new file mode 100644
... ...
@@ -0,0 +1,3 @@
0
+420bf38762386ae2ba8bf2e85b6cc7f2 *./tests/data/lavf/lavf.w64
1
+90224 ./tests/data/lavf/lavf.w64
2
+./tests/data/lavf/lavf.w64 CRC=0xf1ae5536