Browse code

lavf: add a raw WavPack muxer.

Anton Khirnov authored on 2013/05/29 00:44:18
Showing 5 changed files
... ...
@@ -22,6 +22,7 @@ version 10:
22 22
 - Escape 130 video decoder
23 23
 - support for slice multithreading in libavfilter
24 24
 - VC-1 interlaced B-frame support
25
+- support for WavPack muxing (raw and in Matroska)
25 26
 
26 27
 
27 28
 version 9:
... ...
@@ -335,6 +335,7 @@ OBJS-$(CONFIG_WSVQA_DEMUXER)             += westwood_vqa.o
335 335
 OBJS-$(CONFIG_WTV_DEMUXER)               += wtv.o asfdec.o asf.o asfcrypt.o \
336 336
                                             avlanguage.o mpegts.o isom.o
337 337
 OBJS-$(CONFIG_WV_DEMUXER)                += wvdec.o wv.o apetag.o img2.o
338
+OBJS-$(CONFIG_WV_MUXER)                  += wvenc.o wv.o apetag.o
338 339
 OBJS-$(CONFIG_XA_DEMUXER)                += xa.o
339 340
 OBJS-$(CONFIG_XMV_DEMUXER)               += xmv.o
340 341
 OBJS-$(CONFIG_XWMA_DEMUXER)              += xwma.o
... ...
@@ -247,7 +247,7 @@ void av_register_all(void)
247 247
     REGISTER_DEMUXER (WSAUD,            wsaud);
248 248
     REGISTER_DEMUXER (WSVQA,            wsvqa);
249 249
     REGISTER_DEMUXER (WTV,              wtv);
250
-    REGISTER_DEMUXER (WV,               wv);
250
+    REGISTER_MUXDEMUX(WV,               wv);
251 251
     REGISTER_DEMUXER (XA,               xa);
252 252
     REGISTER_DEMUXER (XMV,              xmv);
253 253
     REGISTER_DEMUXER (XWMA,             xwma);
... ...
@@ -30,8 +30,8 @@
30 30
 #include "libavutil/avutil.h"
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 55
33
-#define LIBAVFORMAT_VERSION_MINOR  0
34
-#define LIBAVFORMAT_VERSION_MICRO  1
33
+#define LIBAVFORMAT_VERSION_MINOR  1
34
+#define LIBAVFORMAT_VERSION_MICRO  0
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
37 37
                                                LIBAVFORMAT_VERSION_MINOR, \
38 38
new file mode 100644
... ...
@@ -0,0 +1,88 @@
0
+/*
1
+ * This file is part of Libav.
2
+ *
3
+ * Libav 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
+ * Libav 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 Libav; if not, write to the Free Software
15
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+#include "libavutil/attributes.h"
19
+
20
+#include "apetag.h"
21
+#include "avformat.h"
22
+#include "wv.h"
23
+
24
+typedef struct WvMuxContext {
25
+    int64_t samples;
26
+} WvMuxContext;
27
+
28
+static av_cold int wv_write_header(AVFormatContext *ctx)
29
+{
30
+    if (ctx->nb_streams > 1 ||
31
+        ctx->streams[0]->codec->codec_id != AV_CODEC_ID_WAVPACK) {
32
+        av_log(ctx, AV_LOG_ERROR, "This muxer only supports a single WavPack stream.\n");
33
+        return AVERROR(EINVAL);
34
+    }
35
+
36
+    return 0;
37
+}
38
+
39
+static int wv_write_packet(AVFormatContext *ctx, AVPacket *pkt)
40
+{
41
+    WvMuxContext *s = ctx->priv_data;
42
+    WvHeader header;
43
+    int ret;
44
+
45
+    if (pkt->size < WV_HEADER_SIZE ||
46
+        (ret = ff_wv_parse_header(&header, pkt->data)) < 0) {
47
+        av_log(ctx, AV_LOG_ERROR, "Invalid WavPack packet.\n");
48
+        return AVERROR(EINVAL);
49
+    }
50
+    s->samples += header.samples;
51
+
52
+    avio_write(ctx->pb, pkt->data, pkt->size);
53
+    avio_flush(ctx->pb);
54
+
55
+    return 0;
56
+}
57
+
58
+static av_cold int wv_write_trailer(AVFormatContext *ctx)
59
+{
60
+    WvMuxContext *s = ctx->priv_data;
61
+
62
+    /* update total number of samples in the first block */
63
+    if (ctx->pb->seekable && s->samples &&
64
+        s->samples < UINT32_MAX) {
65
+        int64_t pos = avio_tell(ctx->pb);
66
+        avio_seek(ctx->pb, 12, SEEK_SET);
67
+        avio_wl32(ctx->pb, s->samples);
68
+        avio_seek(ctx->pb, pos, SEEK_SET);
69
+    }
70
+
71
+    ff_ape_write_tag(ctx);
72
+    return 0;
73
+}
74
+
75
+AVOutputFormat ff_wv_muxer = {
76
+    .name              = "wv",
77
+    .long_name         = NULL_IF_CONFIG_SMALL("raw WavPack"),
78
+    .mime_type         = "audio/x-wavpack",
79
+    .extensions        = "wv",
80
+    .priv_data_size    = sizeof(WvMuxContext),
81
+    .audio_codec       = AV_CODEC_ID_WAVPACK,
82
+    .video_codec       = AV_CODEC_ID_NONE,
83
+    .write_header      = wv_write_header,
84
+    .write_packet      = wv_write_packet,
85
+    .write_trailer     = wv_write_trailer,
86
+    .flags             = AVFMT_NOTIMESTAMPS,
87
+};