Signed-off-by: Paul B Mahol <onemda@gmail.com>
Peter Ross authored on 2016/04/30 01:48:45... | ... |
@@ -29,6 +29,7 @@ version <next>: |
29 | 29 |
- VAAPI-accelerated format conversion and scaling |
30 | 30 |
- libnpp/CUDA-accelerated format conversion and scaling |
31 | 31 |
- Duck TrueMotion 2.0 Real Time decoder |
32 |
+- Wideband Single-bit Data (WSD) demuxer |
|
32 | 33 |
|
33 | 34 |
version 3.0: |
34 | 35 |
- Common Encryption (CENC) MP4 encoding and decoding support |
... | ... |
@@ -493,6 +493,7 @@ OBJS-$(CONFIG_WEBP_MUXER) += webpenc.o |
493 | 493 |
OBJS-$(CONFIG_WEBVTT_DEMUXER) += webvttdec.o subtitles.o |
494 | 494 |
OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o |
495 | 495 |
OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o |
496 |
+OBJS-$(CONFIG_WSD_DEMUXER) += wsddec.o rawdec.o |
|
496 | 497 |
OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood_vqa.o |
497 | 498 |
OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv_common.o asf.o \ |
498 | 499 |
avlanguage.o |
... | ... |
@@ -335,6 +335,7 @@ void av_register_all(void) |
335 | 335 |
REGISTER_MUXER (WEBP, webp); |
336 | 336 |
REGISTER_MUXDEMUX(WEBVTT, webvtt); |
337 | 337 |
REGISTER_DEMUXER (WSAUD, wsaud); |
338 |
+ REGISTER_DEMUXER (WSD, wsd); |
|
338 | 339 |
REGISTER_DEMUXER (WSVQA, wsvqa); |
339 | 340 |
REGISTER_MUXDEMUX(WTV, wtv); |
340 | 341 |
REGISTER_DEMUXER (WVE, wve); |
... | ... |
@@ -30,8 +30,8 @@ |
30 | 30 |
#include "libavutil/version.h" |
31 | 31 |
|
32 | 32 |
#define LIBAVFORMAT_VERSION_MAJOR 57 |
33 |
-#define LIBAVFORMAT_VERSION_MINOR 34 |
|
34 |
-#define LIBAVFORMAT_VERSION_MICRO 103 |
|
33 |
+#define LIBAVFORMAT_VERSION_MINOR 35 |
|
34 |
+#define LIBAVFORMAT_VERSION_MICRO 100 |
|
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,172 @@ |
0 |
+/* |
|
1 |
+ * Wideband Single-bit Data (WSD) demuxer |
|
2 |
+ * Copyright (c) 2014 Peter Ross |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+#include "libavutil/intreadwrite.h" |
|
22 |
+#include "libavutil/timecode.h" |
|
23 |
+#include "avformat.h" |
|
24 |
+#include "internal.h" |
|
25 |
+#include "rawdec.h" |
|
26 |
+ |
|
27 |
+static int wsd_probe(AVProbeData *p) |
|
28 |
+{ |
|
29 |
+ if (p->buf_size < 45 || memcmp(p->buf, "1bit", 4) || |
|
30 |
+ !AV_RB32(p->buf + 36) || !p->buf[44] || |
|
31 |
+ (p->buf[0] >= 0x10 && (AV_RB32(p->buf + 20) < 0x80 || AV_RB32(p->buf + 24) < 0x80))) |
|
32 |
+ return 0; |
|
33 |
+ return AVPROBE_SCORE_MAX; |
|
34 |
+} |
|
35 |
+ |
|
36 |
+static int empty_string(const char *buf, unsigned size) |
|
37 |
+{ |
|
38 |
+ while (size--) { |
|
39 |
+ if (*buf++ != ' ') |
|
40 |
+ return 0; |
|
41 |
+ } |
|
42 |
+ return 1; |
|
43 |
+} |
|
44 |
+ |
|
45 |
+static int wsd_to_av_channel_layoyt(AVFormatContext *s, int bit) |
|
46 |
+{ |
|
47 |
+ switch (bit) { |
|
48 |
+ case 2: return AV_CH_BACK_RIGHT; |
|
49 |
+ case 3: |
|
50 |
+ avpriv_request_sample(s, "Rr-middle"); |
|
51 |
+ break; |
|
52 |
+ case 4: return AV_CH_BACK_CENTER; |
|
53 |
+ case 5: |
|
54 |
+ avpriv_request_sample(s, "Lr-middle"); |
|
55 |
+ break; |
|
56 |
+ case 6: return AV_CH_BACK_LEFT; |
|
57 |
+ case 24: return AV_CH_LOW_FREQUENCY; |
|
58 |
+ case 26: return AV_CH_FRONT_RIGHT; |
|
59 |
+ case 27: return AV_CH_FRONT_RIGHT_OF_CENTER; |
|
60 |
+ case 28: return AV_CH_FRONT_CENTER; |
|
61 |
+ case 29: return AV_CH_FRONT_LEFT_OF_CENTER; |
|
62 |
+ case 30: return AV_CH_FRONT_LEFT; |
|
63 |
+ default: |
|
64 |
+ av_log(s, AV_LOG_WARNING, "reserved channel assignment\n"); |
|
65 |
+ break; |
|
66 |
+ } |
|
67 |
+ return 0; |
|
68 |
+} |
|
69 |
+ |
|
70 |
+static int get_metadata(AVFormatContext *s, const char *const tag, const unsigned size) |
|
71 |
+{ |
|
72 |
+ uint8_t *buf; |
|
73 |
+ if (!(size + 1)) |
|
74 |
+ return AVERROR(ENOMEM); |
|
75 |
+ |
|
76 |
+ buf = av_malloc(size + 1); |
|
77 |
+ if (!buf) |
|
78 |
+ return AVERROR(ENOMEM); |
|
79 |
+ |
|
80 |
+ if (avio_read(s->pb, buf, size) != size) { |
|
81 |
+ av_free(buf); |
|
82 |
+ return AVERROR(EIO); |
|
83 |
+ } |
|
84 |
+ |
|
85 |
+ if (empty_string(buf, size)) { |
|
86 |
+ av_free(buf); |
|
87 |
+ return 0; |
|
88 |
+ } |
|
89 |
+ |
|
90 |
+ buf[size] = 0; |
|
91 |
+ av_dict_set(&s->metadata, tag, buf, AV_DICT_DONT_STRDUP_VAL); |
|
92 |
+ return 0; |
|
93 |
+} |
|
94 |
+ |
|
95 |
+static int wsd_read_header(AVFormatContext *s) |
|
96 |
+{ |
|
97 |
+ AVIOContext *pb = s->pb; |
|
98 |
+ AVStream *st; |
|
99 |
+ int version; |
|
100 |
+ uint32_t text_offset, data_offset, channel_assign; |
|
101 |
+ char playback_time[AV_TIMECODE_STR_SIZE]; |
|
102 |
+ |
|
103 |
+ st = avformat_new_stream(s, NULL); |
|
104 |
+ if (!st) |
|
105 |
+ return AVERROR(ENOMEM); |
|
106 |
+ |
|
107 |
+ avio_skip(pb, 8); |
|
108 |
+ version = avio_r8(pb); |
|
109 |
+ av_log(s, AV_LOG_DEBUG, "version: %i.%i\n", version >> 4, version & 0xF); |
|
110 |
+ avio_skip(pb, 11); |
|
111 |
+ |
|
112 |
+ if (version < 0x10) { |
|
113 |
+ text_offset = 0x80; |
|
114 |
+ data_offset = 0x800; |
|
115 |
+ avio_skip(pb, 8); |
|
116 |
+ } else { |
|
117 |
+ text_offset = avio_rb32(pb); |
|
118 |
+ data_offset = avio_rb32(pb); |
|
119 |
+ } |
|
120 |
+ |
|
121 |
+ avio_skip(pb, 4); |
|
122 |
+ av_timecode_make_smpte_tc_string(playback_time, avio_rb32(pb), 0); |
|
123 |
+ av_dict_set(&s->metadata, "playback_time", playback_time, 0); |
|
124 |
+ |
|
125 |
+ st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; |
|
126 |
+ st->codecpar->codec_id = s->iformat->raw_codec_id; |
|
127 |
+ st->codecpar->sample_rate = avio_rb32(pb) / 8; |
|
128 |
+ avio_skip(pb, 4); |
|
129 |
+ st->codecpar->channels = avio_r8(pb) & 0xF; |
|
130 |
+ if (!st->codecpar->channels) |
|
131 |
+ return AVERROR_INVALIDDATA; |
|
132 |
+ |
|
133 |
+ avio_skip(pb, 3); |
|
134 |
+ channel_assign = avio_rb32(pb); |
|
135 |
+ if (!(channel_assign & 1)) { |
|
136 |
+ int i; |
|
137 |
+ for (i = 1; i < 32; i++) |
|
138 |
+ if (channel_assign & (1 << i)) |
|
139 |
+ st->codecpar->channel_layout |= wsd_to_av_channel_layoyt(s, i); |
|
140 |
+ } |
|
141 |
+ |
|
142 |
+ avio_skip(pb, 16); |
|
143 |
+ if (avio_rb32(pb)) |
|
144 |
+ avpriv_request_sample(s, "emphasis"); |
|
145 |
+ |
|
146 |
+ if (avio_seek(pb, text_offset, SEEK_SET) >= 0) { |
|
147 |
+ get_metadata(s, "title", 128); |
|
148 |
+ get_metadata(s, "composer", 128); |
|
149 |
+ get_metadata(s, "song_writer", 128); |
|
150 |
+ get_metadata(s, "artist", 128); |
|
151 |
+ get_metadata(s, "album", 128); |
|
152 |
+ get_metadata(s, "genre", 32); |
|
153 |
+ get_metadata(s, "date", 32); |
|
154 |
+ get_metadata(s, "location", 32); |
|
155 |
+ get_metadata(s, "comment", 512); |
|
156 |
+ get_metadata(s, "user", 512); |
|
157 |
+ } |
|
158 |
+ |
|
159 |
+ return avio_seek(pb, data_offset, SEEK_SET); |
|
160 |
+} |
|
161 |
+ |
|
162 |
+AVInputFormat ff_wsd_demuxer = { |
|
163 |
+ .name = "wsd", |
|
164 |
+ .long_name = NULL_IF_CONFIG_SMALL("Wideband Single-bit Data (WSD)"), |
|
165 |
+ .read_probe = wsd_probe, |
|
166 |
+ .read_header = wsd_read_header, |
|
167 |
+ .read_packet = ff_raw_read_partial_packet, |
|
168 |
+ .extensions = "wsd", |
|
169 |
+ .flags = AVFMT_GENERIC_INDEX | AVFMT_NO_BYTE_SEEK, |
|
170 |
+ .raw_codec_id = AV_CODEC_ID_DSD_MSBF, |
|
171 |
+}; |