Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
... | ... |
@@ -221,6 +221,7 @@ library: |
221 | 221 |
@tab Used in the game Cyberia from Interplay. |
222 | 222 |
@item Delphine Software International CIN @tab @tab X |
223 | 223 |
@tab Multimedia format used by Delphine Software games. |
224 |
+@item Digital Speech Standard (DSS) @tab @tab X |
|
224 | 225 |
@item CD+G @tab @tab X |
225 | 226 |
@tab Video format used by CD+G karaoke disks |
226 | 227 |
@item Commodore CDXL @tab @tab X |
... | ... |
@@ -100,6 +100,7 @@ OBJS-$(CONFIG_DIRAC_MUXER) += rawenc.o |
100 | 100 |
OBJS-$(CONFIG_DNXHD_DEMUXER) += dnxhddec.o rawdec.o |
101 | 101 |
OBJS-$(CONFIG_DNXHD_MUXER) += rawenc.o |
102 | 102 |
OBJS-$(CONFIG_DSICIN_DEMUXER) += dsicin.o |
103 |
+OBJS-$(CONFIG_DSS_DEMUXER) += dss.o |
|
103 | 104 |
OBJS-$(CONFIG_DTS_DEMUXER) += dtsdec.o rawdec.o |
104 | 105 |
OBJS-$(CONFIG_DTS_MUXER) += rawenc.o |
105 | 106 |
OBJS-$(CONFIG_DV_DEMUXER) += dv.o |
... | ... |
@@ -94,6 +94,7 @@ void av_register_all(void) |
94 | 94 |
REGISTER_MUXDEMUX(DIRAC, dirac); |
95 | 95 |
REGISTER_MUXDEMUX(DNXHD, dnxhd); |
96 | 96 |
REGISTER_DEMUXER (DSICIN, dsicin); |
97 |
+ REGISTER_DEMUXER (DSS, dss); |
|
97 | 98 |
REGISTER_MUXDEMUX(DTS, dts); |
98 | 99 |
REGISTER_MUXDEMUX(DV, dv); |
99 | 100 |
REGISTER_DEMUXER (DXA, dxa); |
100 | 101 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,342 @@ |
0 |
+/* |
|
1 |
+ * Digital Speech Standard (DSS) demuxer |
|
2 |
+ * Copyright (c) 2014 Oleksij Rempel <linux@rempel-privat.de> |
|
3 |
+ * |
|
4 |
+ * This file is part of Libav. |
|
5 |
+ * |
|
6 |
+ * Libav 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 |
+ * Libav 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 Libav; 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/attributes.h" |
|
22 |
+#include "libavutil/bswap.h" |
|
23 |
+#include "libavutil/channel_layout.h" |
|
24 |
+#include "libavutil/intreadwrite.h" |
|
25 |
+ |
|
26 |
+#include "avformat.h" |
|
27 |
+#include "internal.h" |
|
28 |
+ |
|
29 |
+#define DSS_HEAD_OFFSET_AUTHOR 0xc |
|
30 |
+#define DSS_AUTHOR_SIZE 16 |
|
31 |
+ |
|
32 |
+#define DSS_HEAD_OFFSET_START_TIME 0x26 |
|
33 |
+#define DSS_HEAD_OFFSET_END_TIME 0x32 |
|
34 |
+#define DSS_TIME_SIZE 12 |
|
35 |
+ |
|
36 |
+#define DSS_HEAD_OFFSET_ACODEC 0x2a4 |
|
37 |
+#define DSS_ACODEC_DSS_SP 0x0 /* SP mode */ |
|
38 |
+#define DSS_ACODEC_G723_1 0x2 /* LP mode */ |
|
39 |
+ |
|
40 |
+#define DSS_HEAD_OFFSET_COMMENT 0x31e |
|
41 |
+#define DSS_COMMENT_SIZE 64 |
|
42 |
+ |
|
43 |
+#define DSS_BLOCK_SIZE 512 |
|
44 |
+#define DSS_HEADER_SIZE (DSS_BLOCK_SIZE * 2) |
|
45 |
+#define DSS_AUDIO_BLOCK_HEADER_SIZE 6 |
|
46 |
+#define DSS_FRAME_SIZE 42 |
|
47 |
+ |
|
48 |
+static const uint8_t frame_size[4] = { 24, 20, 4, 1 }; |
|
49 |
+ |
|
50 |
+typedef struct DSSDemuxContext { |
|
51 |
+ unsigned int audio_codec; |
|
52 |
+ int counter; |
|
53 |
+ int swap; |
|
54 |
+ int dss_sp_swap_byte; |
|
55 |
+ int8_t *dss_sp_buf; |
|
56 |
+} DSSDemuxContext; |
|
57 |
+ |
|
58 |
+static int dss_probe(AVProbeData *p) |
|
59 |
+{ |
|
60 |
+ if (AV_RL32(p->buf) != MKTAG(0x2, 'd', 's', 's')) |
|
61 |
+ return 0; |
|
62 |
+ |
|
63 |
+ return AVPROBE_SCORE_MAX; |
|
64 |
+} |
|
65 |
+ |
|
66 |
+static int dss_read_metadata_date(AVFormatContext *s, unsigned int offset, |
|
67 |
+ const char *key) |
|
68 |
+{ |
|
69 |
+ AVIOContext *pb = s->pb; |
|
70 |
+ char datetime[64], string[DSS_TIME_SIZE + 1] = { 0 }; |
|
71 |
+ int y, month, d, h, minute, sec; |
|
72 |
+ int ret; |
|
73 |
+ |
|
74 |
+ avio_seek(pb, offset, SEEK_SET); |
|
75 |
+ |
|
76 |
+ ret = avio_read(s->pb, string, DSS_TIME_SIZE); |
|
77 |
+ if (ret < DSS_TIME_SIZE) |
|
78 |
+ return ret < 0 ? ret : AVERROR_EOF; |
|
79 |
+ |
|
80 |
+ sscanf(string, "%2d%2d%2d%2d%2d%2d", &y, &month, &d, &h, &minute, &sec); |
|
81 |
+ /* We deal with a two-digit year here, so set the default date to 2000 |
|
82 |
+ * and hope it will never be used in the next century. */ |
|
83 |
+ snprintf(datetime, sizeof(datetime), "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d", |
|
84 |
+ y + 2000, month, d, h, minute, sec); |
|
85 |
+ return av_dict_set(&s->metadata, key, datetime, 0); |
|
86 |
+} |
|
87 |
+ |
|
88 |
+static int dss_read_metadata_string(AVFormatContext *s, unsigned int offset, |
|
89 |
+ unsigned int size, const char *key) |
|
90 |
+{ |
|
91 |
+ AVIOContext *pb = s->pb; |
|
92 |
+ char *value; |
|
93 |
+ int ret; |
|
94 |
+ |
|
95 |
+ avio_seek(pb, offset, SEEK_SET); |
|
96 |
+ |
|
97 |
+ value = av_mallocz(size + 1); |
|
98 |
+ if (!value) |
|
99 |
+ return AVERROR(ENOMEM); |
|
100 |
+ |
|
101 |
+ ret = avio_read(s->pb, value, size); |
|
102 |
+ if (ret < size) { |
|
103 |
+ ret = ret < 0 ? ret : AVERROR_EOF; |
|
104 |
+ goto exit; |
|
105 |
+ } |
|
106 |
+ |
|
107 |
+ ret = av_dict_set(&s->metadata, key, value, 0); |
|
108 |
+ |
|
109 |
+exit: |
|
110 |
+ av_free(value); |
|
111 |
+ return ret; |
|
112 |
+} |
|
113 |
+ |
|
114 |
+static int dss_read_header(AVFormatContext *s) |
|
115 |
+{ |
|
116 |
+ DSSDemuxContext *ctx = s->priv_data; |
|
117 |
+ AVIOContext *pb = s->pb; |
|
118 |
+ AVStream *st; |
|
119 |
+ int ret; |
|
120 |
+ |
|
121 |
+ st = avformat_new_stream(s, NULL); |
|
122 |
+ if (!st) |
|
123 |
+ return AVERROR(ENOMEM); |
|
124 |
+ |
|
125 |
+ ret = dss_read_metadata_string(s, DSS_HEAD_OFFSET_AUTHOR, |
|
126 |
+ DSS_AUTHOR_SIZE, "author"); |
|
127 |
+ if (ret) |
|
128 |
+ return ret; |
|
129 |
+ |
|
130 |
+ ret = dss_read_metadata_date(s, DSS_HEAD_OFFSET_END_TIME, "date"); |
|
131 |
+ if (ret) |
|
132 |
+ return ret; |
|
133 |
+ |
|
134 |
+ ret = dss_read_metadata_string(s, DSS_HEAD_OFFSET_COMMENT, |
|
135 |
+ DSS_COMMENT_SIZE, "comment"); |
|
136 |
+ if (ret) |
|
137 |
+ return ret; |
|
138 |
+ |
|
139 |
+ avio_seek(pb, DSS_HEAD_OFFSET_ACODEC, SEEK_SET); |
|
140 |
+ ctx->audio_codec = avio_r8(pb); |
|
141 |
+ |
|
142 |
+ if (ctx->audio_codec == DSS_ACODEC_DSS_SP) { |
|
143 |
+ st->codec->codec_id = AV_CODEC_ID_DSS_SP; |
|
144 |
+ st->codec->sample_rate = 12000; |
|
145 |
+ } else if (ctx->audio_codec == DSS_ACODEC_G723_1) { |
|
146 |
+ st->codec->codec_id = AV_CODEC_ID_G723_1; |
|
147 |
+ st->codec->sample_rate = 8000; |
|
148 |
+ } else { |
|
149 |
+ avpriv_request_sample(s, "Support for codec %x in DSS", |
|
150 |
+ ctx->audio_codec); |
|
151 |
+ return AVERROR_PATCHWELCOME; |
|
152 |
+ } |
|
153 |
+ |
|
154 |
+ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; |
|
155 |
+ st->codec->channel_layout = AV_CH_LAYOUT_MONO; |
|
156 |
+ st->codec->channels = 1; |
|
157 |
+ |
|
158 |
+ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); |
|
159 |
+ st->start_time = 0; |
|
160 |
+ |
|
161 |
+ /* Jump over header */ |
|
162 |
+ |
|
163 |
+ if (avio_seek(pb, DSS_HEADER_SIZE, SEEK_SET) != DSS_HEADER_SIZE) |
|
164 |
+ return AVERROR(EIO); |
|
165 |
+ |
|
166 |
+ ctx->counter = 0; |
|
167 |
+ ctx->swap = 0; |
|
168 |
+ |
|
169 |
+ ctx->dss_sp_buf = av_malloc(DSS_FRAME_SIZE + 1); |
|
170 |
+ if (!ctx->dss_sp_buf) |
|
171 |
+ return AVERROR(ENOMEM); |
|
172 |
+ |
|
173 |
+ return 0; |
|
174 |
+} |
|
175 |
+ |
|
176 |
+static void dss_skip_audio_header(AVFormatContext *s, AVPacket *pkt) |
|
177 |
+{ |
|
178 |
+ DSSDemuxContext *ctx = s->priv_data; |
|
179 |
+ AVIOContext *pb = s->pb; |
|
180 |
+ |
|
181 |
+ avio_skip(pb, DSS_AUDIO_BLOCK_HEADER_SIZE); |
|
182 |
+ ctx->counter += DSS_BLOCK_SIZE - DSS_AUDIO_BLOCK_HEADER_SIZE; |
|
183 |
+} |
|
184 |
+ |
|
185 |
+static void dss_sp_byte_swap(DSSDemuxContext *ctx, |
|
186 |
+ uint8_t *dst, const uint8_t *src) |
|
187 |
+{ |
|
188 |
+ int i; |
|
189 |
+ |
|
190 |
+ if (ctx->swap) { |
|
191 |
+ for (i = 3; i < DSS_FRAME_SIZE; i += 2) |
|
192 |
+ dst[i] = src[i]; |
|
193 |
+ |
|
194 |
+ for (i = 0; i < DSS_FRAME_SIZE - 2; i += 2) |
|
195 |
+ dst[i] = src[i + 4]; |
|
196 |
+ |
|
197 |
+ dst[1] = ctx->dss_sp_swap_byte; |
|
198 |
+ } else { |
|
199 |
+ memcpy(dst, src, DSS_FRAME_SIZE); |
|
200 |
+ ctx->dss_sp_swap_byte = src[DSS_FRAME_SIZE - 2]; |
|
201 |
+ } |
|
202 |
+ |
|
203 |
+ /* make sure byte 40 is always 0 */ |
|
204 |
+ dst[DSS_FRAME_SIZE - 2] = 0; |
|
205 |
+ ctx->swap ^= 1; |
|
206 |
+} |
|
207 |
+ |
|
208 |
+static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt) |
|
209 |
+{ |
|
210 |
+ DSSDemuxContext *ctx = s->priv_data; |
|
211 |
+ int read_size, ret, offset = 0, buff_offset = 0; |
|
212 |
+ |
|
213 |
+ if (ctx->counter == 0) |
|
214 |
+ dss_skip_audio_header(s, pkt); |
|
215 |
+ |
|
216 |
+ pkt->pos = avio_tell(s->pb); |
|
217 |
+ |
|
218 |
+ if (ctx->swap) { |
|
219 |
+ read_size = DSS_FRAME_SIZE - 2; |
|
220 |
+ buff_offset = 3; |
|
221 |
+ } else |
|
222 |
+ read_size = DSS_FRAME_SIZE; |
|
223 |
+ |
|
224 |
+ ctx->counter -= read_size; |
|
225 |
+ |
|
226 |
+ ret = av_new_packet(pkt, DSS_FRAME_SIZE); |
|
227 |
+ if (ret < 0) |
|
228 |
+ return ret; |
|
229 |
+ |
|
230 |
+ pkt->duration = 0; |
|
231 |
+ pkt->stream_index = 0; |
|
232 |
+ |
|
233 |
+ if (ctx->counter < 0) { |
|
234 |
+ int size2 = ctx->counter + read_size; |
|
235 |
+ |
|
236 |
+ ret = avio_read(s->pb, ctx->dss_sp_buf + offset + buff_offset, |
|
237 |
+ size2 - offset); |
|
238 |
+ if (ret < size2 - offset) |
|
239 |
+ goto error_eof; |
|
240 |
+ |
|
241 |
+ dss_skip_audio_header(s, pkt); |
|
242 |
+ offset = size2; |
|
243 |
+ } |
|
244 |
+ |
|
245 |
+ ret = avio_read(s->pb, ctx->dss_sp_buf + offset + buff_offset, |
|
246 |
+ read_size - offset); |
|
247 |
+ if (ret < read_size - offset) |
|
248 |
+ goto error_eof; |
|
249 |
+ |
|
250 |
+ dss_sp_byte_swap(ctx, pkt->data, ctx->dss_sp_buf); |
|
251 |
+ |
|
252 |
+ if (pkt->data[0] == 0xff) |
|
253 |
+ return AVERROR_INVALIDDATA; |
|
254 |
+ |
|
255 |
+ return pkt->size; |
|
256 |
+ |
|
257 |
+error_eof: |
|
258 |
+ av_free_packet(pkt); |
|
259 |
+ return ret < 0 ? ret : AVERROR_EOF; |
|
260 |
+} |
|
261 |
+ |
|
262 |
+static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt) |
|
263 |
+{ |
|
264 |
+ DSSDemuxContext *ctx = s->priv_data; |
|
265 |
+ int size, byte, ret, offset; |
|
266 |
+ |
|
267 |
+ if (ctx->counter == 0) |
|
268 |
+ dss_skip_audio_header(s, pkt); |
|
269 |
+ |
|
270 |
+ pkt->pos = avio_tell(s->pb); |
|
271 |
+ /* We make one byte-step here. Don't forget to add offset. */ |
|
272 |
+ byte = avio_r8(s->pb); |
|
273 |
+ if (byte == 0xff) |
|
274 |
+ return AVERROR_INVALIDDATA; |
|
275 |
+ |
|
276 |
+ size = frame_size[byte & 3]; |
|
277 |
+ |
|
278 |
+ ctx->counter -= size; |
|
279 |
+ |
|
280 |
+ ret = av_new_packet(pkt, size); |
|
281 |
+ if (ret < 0) |
|
282 |
+ return ret; |
|
283 |
+ |
|
284 |
+ pkt->data[0] = byte; |
|
285 |
+ offset = 1; |
|
286 |
+ pkt->duration = 240; |
|
287 |
+ |
|
288 |
+ pkt->stream_index = 0; |
|
289 |
+ |
|
290 |
+ if (ctx->counter < 0) { |
|
291 |
+ int size2 = ctx->counter + size; |
|
292 |
+ |
|
293 |
+ ret = avio_read(s->pb, pkt->data + offset, |
|
294 |
+ size2 - offset); |
|
295 |
+ if (ret < size2 - offset) { |
|
296 |
+ av_free_packet(pkt); |
|
297 |
+ return ret < 0 ? ret : AVERROR_EOF; |
|
298 |
+ } |
|
299 |
+ |
|
300 |
+ dss_skip_audio_header(s, pkt); |
|
301 |
+ offset = size2; |
|
302 |
+ } |
|
303 |
+ |
|
304 |
+ ret = avio_read(s->pb, pkt->data + offset, size - offset); |
|
305 |
+ if (ret < size - offset) { |
|
306 |
+ av_free_packet(pkt); |
|
307 |
+ return ret < 0 ? ret : AVERROR_EOF; |
|
308 |
+ } |
|
309 |
+ |
|
310 |
+ return pkt->size; |
|
311 |
+} |
|
312 |
+ |
|
313 |
+static int dss_read_packet(AVFormatContext *s, AVPacket *pkt) |
|
314 |
+{ |
|
315 |
+ DSSDemuxContext *ctx = s->priv_data; |
|
316 |
+ |
|
317 |
+ if (ctx->audio_codec == DSS_ACODEC_DSS_SP) |
|
318 |
+ return dss_sp_read_packet(s, pkt); |
|
319 |
+ else |
|
320 |
+ return dss_723_1_read_packet(s, pkt); |
|
321 |
+} |
|
322 |
+ |
|
323 |
+static int dss_read_close(AVFormatContext *s) |
|
324 |
+{ |
|
325 |
+ DSSDemuxContext *ctx = s->priv_data; |
|
326 |
+ |
|
327 |
+ av_free(ctx->dss_sp_buf); |
|
328 |
+ |
|
329 |
+ return 0; |
|
330 |
+} |
|
331 |
+ |
|
332 |
+AVInputFormat ff_dss_demuxer = { |
|
333 |
+ .name = "dss", |
|
334 |
+ .long_name = NULL_IF_CONFIG_SMALL("Digital Speech Standard (DSS)"), |
|
335 |
+ .priv_data_size = sizeof(DSSDemuxContext), |
|
336 |
+ .read_probe = dss_probe, |
|
337 |
+ .read_header = dss_read_header, |
|
338 |
+ .read_packet = dss_read_packet, |
|
339 |
+ .read_close = dss_read_close, |
|
340 |
+ .extensions = "dss" |
|
341 |
+}; |
... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
#include "libavutil/version.h" |
31 | 31 |
|
32 | 32 |
#define LIBAVFORMAT_VERSION_MAJOR 56 |
33 |
-#define LIBAVFORMAT_VERSION_MINOR 11 |
|
33 |
+#define LIBAVFORMAT_VERSION_MINOR 12 |
|
34 | 34 |
#define LIBAVFORMAT_VERSION_MICRO 0 |
35 | 35 |
|
36 | 36 |
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |