Signed-off-by: Martin Storsjö <martin@martin.st>
Kostya Shishkov authored on 2011/11/01 19:58:44... | ... |
@@ -99,6 +99,7 @@ easier to use. The changes are: |
99 | 99 |
AVCodecContext deprecated. Codec private options should be used instead. |
100 | 100 |
- Properly working defaults in libx264 wrapper, support for native presets. |
101 | 101 |
- Encrypted OMA files support |
102 |
+- Discworld II BMV decoding support |
|
102 | 103 |
|
103 | 104 |
|
104 | 105 |
version 0.7: |
... | ... |
@@ -67,6 +67,7 @@ library: |
67 | 67 |
@item Brute Force & Ignorance @tab @tab X |
68 | 68 |
@tab Used in the game Flash Traffic: City of Angels. |
69 | 69 |
@item BWF @tab X @tab X |
70 |
+@item Discworld II BMV @tab @tab X |
|
70 | 71 |
@item Interplay C93 @tab @tab X |
71 | 72 |
@tab Used in the game Cyberia from Interplay. |
72 | 73 |
@item Delphine Software International CIN @tab @tab X |
... | ... |
@@ -376,6 +377,7 @@ following image formats are supported: |
376 | 376 |
@tab AVS1-P2, JiZhun profile, encoding through external library libxavs |
377 | 377 |
@item Delphine Software International CIN video @tab @tab X |
378 | 378 |
@tab Codec used in Delphine Software International games. |
379 |
+@item Discworld II BMV Video @tab @tab X |
|
379 | 380 |
@item Cinepak @tab @tab X |
380 | 381 |
@item Cirrus Logic AccuPak @tab @tab X |
381 | 382 |
@tab fourcc: CLJR |
... | ... |
@@ -608,6 +610,7 @@ following image formats are supported: |
608 | 608 |
@tab Used in Bink and Smacker files in many games. |
609 | 609 |
@item Delphine Software International CIN audio @tab @tab X |
610 | 610 |
@tab Codec used in Delphine Software International games. |
611 |
+@item Discworld II BMV Audio @tab @tab X |
|
611 | 612 |
@item COOK @tab @tab X |
612 | 613 |
@tab All versions except 5.1 are supported. |
613 | 614 |
@item DCA (DTS Coherent Acoustics) @tab @tab X |
... | ... |
@@ -94,6 +94,8 @@ OBJS-$(CONFIG_BINKAUDIO_DCT_DECODER) += binkaudio.o wma.o |
94 | 94 |
OBJS-$(CONFIG_BINKAUDIO_RDFT_DECODER) += binkaudio.o wma.o |
95 | 95 |
OBJS-$(CONFIG_BMP_DECODER) += bmp.o msrledec.o |
96 | 96 |
OBJS-$(CONFIG_BMP_ENCODER) += bmpenc.o |
97 |
+OBJS-$(CONFIG_BMV_VIDEO_DECODER) += bmv.o |
|
98 |
+OBJS-$(CONFIG_BMV_AUDIO_DECODER) += bmv.o |
|
97 | 99 |
OBJS-$(CONFIG_C93_DECODER) += c93.o |
98 | 100 |
OBJS-$(CONFIG_CAVS_DECODER) += cavs.o cavsdec.o cavsdsp.o \ |
99 | 101 |
mpeg12data.o mpegvideo.o |
... | ... |
@@ -81,6 +81,7 @@ void avcodec_register_all(void) |
81 | 81 |
REGISTER_DECODER (BFI, bfi); |
82 | 82 |
REGISTER_DECODER (BINK, bink); |
83 | 83 |
REGISTER_ENCDEC (BMP, bmp); |
84 |
+ REGISTER_DECODER (BMV_VIDEO, bmv_video); |
|
84 | 85 |
REGISTER_DECODER (C93, c93); |
85 | 86 |
REGISTER_DECODER (CAVS, cavs); |
86 | 87 |
REGISTER_DECODER (CDGRAPHICS, cdgraphics); |
... | ... |
@@ -242,6 +243,7 @@ void avcodec_register_all(void) |
242 | 242 |
REGISTER_DECODER (ATRAC3, atrac3); |
243 | 243 |
REGISTER_DECODER (BINKAUDIO_DCT, binkaudio_dct); |
244 | 244 |
REGISTER_DECODER (BINKAUDIO_RDFT, binkaudio_rdft); |
245 |
+ REGISTER_DECODER (BMV_AUDIO, bmv_audio); |
|
245 | 246 |
REGISTER_DECODER (COOK, cook); |
246 | 247 |
REGISTER_DECODER (DCA, dca); |
247 | 248 |
REGISTER_DECODER (DSICINAUDIO, dsicinaudio); |
... | ... |
@@ -219,6 +219,7 @@ enum CodecID { |
219 | 219 |
CODEC_ID_G729, |
220 | 220 |
#endif |
221 | 221 |
CODEC_ID_UTVIDEO, |
222 |
+ CODEC_ID_BMV_VIDEO, |
|
222 | 223 |
|
223 | 224 |
/* various PCM "codecs" */ |
224 | 225 |
CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs |
... | ... |
@@ -359,6 +360,7 @@ enum CodecID { |
359 | 359 |
CODEC_ID_8SVX_EXP, |
360 | 360 |
CODEC_ID_8SVX_FIB, |
361 | 361 |
#endif |
362 |
+ CODEC_ID_BMV_AUDIO, |
|
362 | 363 |
|
363 | 364 |
/* subtitle codecs */ |
364 | 365 |
CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs. |
365 | 366 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,360 @@ |
0 |
+/* |
|
1 |
+ * Discworld II BMV video and audio decoder |
|
2 |
+ * Copyright (c) 2011 Konstantin Shishkov |
|
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 "avcodec.h" |
|
22 |
+#include "bytestream.h" |
|
23 |
+ |
|
24 |
+enum BMVFlags{ |
|
25 |
+ BMV_NOP = 0, |
|
26 |
+ BMV_END, |
|
27 |
+ BMV_DELTA, |
|
28 |
+ BMV_INTRA, |
|
29 |
+ |
|
30 |
+ BMV_SCROLL = 0x04, |
|
31 |
+ BMV_PALETTE = 0x08, |
|
32 |
+ BMV_COMMAND = 0x10, |
|
33 |
+ BMV_AUDIO = 0x20, |
|
34 |
+ BMV_EXT = 0x40, |
|
35 |
+ BMV_PRINT = 0x80 |
|
36 |
+}; |
|
37 |
+ |
|
38 |
+#define SCREEN_WIDE 640 |
|
39 |
+#define SCREEN_HIGH 429 |
|
40 |
+ |
|
41 |
+typedef struct BMVDecContext { |
|
42 |
+ AVCodecContext *avctx; |
|
43 |
+ AVFrame pic; |
|
44 |
+ |
|
45 |
+ uint8_t *frame, frame_base[SCREEN_WIDE * (SCREEN_HIGH + 1)]; |
|
46 |
+ uint32_t pal[256]; |
|
47 |
+ const uint8_t *stream; |
|
48 |
+} BMVDecContext; |
|
49 |
+ |
|
50 |
+#define NEXT_BYTE(v) v = forward ? v + 1 : v - 1; |
|
51 |
+ |
|
52 |
+static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, int frame_off) |
|
53 |
+{ |
|
54 |
+ int val, saved_val = 0; |
|
55 |
+ int tmplen = src_len; |
|
56 |
+ const uint8_t *src, *source_end = source + src_len; |
|
57 |
+ uint8_t *frame_end = frame + SCREEN_WIDE * SCREEN_HIGH; |
|
58 |
+ uint8_t *dst, *dst_end; |
|
59 |
+ int len, mask; |
|
60 |
+ int forward = (frame_off <= -SCREEN_WIDE) || (frame_off >= 0); |
|
61 |
+ int read_two_nibbles, flag; |
|
62 |
+ int advance_mode; |
|
63 |
+ int mode = 0; |
|
64 |
+ int i; |
|
65 |
+ |
|
66 |
+ if (src_len <= 0) |
|
67 |
+ return -1; |
|
68 |
+ |
|
69 |
+ if (forward) { |
|
70 |
+ src = source; |
|
71 |
+ dst = frame; |
|
72 |
+ dst_end = frame_end; |
|
73 |
+ } else { |
|
74 |
+ src = source + src_len - 1; |
|
75 |
+ dst = frame_end - 1; |
|
76 |
+ dst_end = frame - 1; |
|
77 |
+ } |
|
78 |
+ for (;;) { |
|
79 |
+ int shift = 0; |
|
80 |
+ flag = 0; |
|
81 |
+ |
|
82 |
+ /* The mode/len decoding is a bit strange: |
|
83 |
+ * values are coded as variable-length codes with nibble units, |
|
84 |
+ * code end is signalled by two top bits in the nibble being nonzero. |
|
85 |
+ * And since data is bytepacked and we read two nibbles at a time, |
|
86 |
+ * we may get a nibble belonging to the next code. |
|
87 |
+ * Hence this convoluted loop. |
|
88 |
+ */ |
|
89 |
+ if (!mode || (tmplen == 4)) { |
|
90 |
+ if (src < source || src >= source_end) |
|
91 |
+ return -1; |
|
92 |
+ val = *src; |
|
93 |
+ read_two_nibbles = 1; |
|
94 |
+ } else { |
|
95 |
+ val = saved_val; |
|
96 |
+ read_two_nibbles = 0; |
|
97 |
+ } |
|
98 |
+ if (!(val & 0xC)) { |
|
99 |
+ for (;;) { |
|
100 |
+ if (!read_two_nibbles) { |
|
101 |
+ if (src < source || src >= source_end) |
|
102 |
+ return -1; |
|
103 |
+ shift += 2; |
|
104 |
+ val |= *src << shift; |
|
105 |
+ if (*src & 0xC) |
|
106 |
+ break; |
|
107 |
+ } |
|
108 |
+ // two upper bits of the nibble is zero, |
|
109 |
+ // so shift top nibble value down into their place |
|
110 |
+ read_two_nibbles = 0; |
|
111 |
+ shift += 2; |
|
112 |
+ mask = (1 << shift) - 1; |
|
113 |
+ val = ((val >> 2) & ~mask) | (val & mask); |
|
114 |
+ NEXT_BYTE(src); |
|
115 |
+ if ((val & (0xC << shift))) { |
|
116 |
+ flag = 1; |
|
117 |
+ break; |
|
118 |
+ } |
|
119 |
+ } |
|
120 |
+ } else if (mode) { |
|
121 |
+ flag = tmplen != 4; |
|
122 |
+ } |
|
123 |
+ if (flag) { |
|
124 |
+ tmplen = 4; |
|
125 |
+ } else { |
|
126 |
+ saved_val = val >> (4 + shift); |
|
127 |
+ tmplen = 0; |
|
128 |
+ val &= (1 << (shift + 4)) - 1; |
|
129 |
+ NEXT_BYTE(src); |
|
130 |
+ } |
|
131 |
+ advance_mode = val & 1; |
|
132 |
+ len = (val >> 1) - 1; |
|
133 |
+ mode += 1 + advance_mode; |
|
134 |
+ if (mode >= 4) |
|
135 |
+ mode -= 3; |
|
136 |
+ if (FFABS(dst_end - dst) < len) |
|
137 |
+ return -1; |
|
138 |
+ switch (mode) { |
|
139 |
+ case 1: |
|
140 |
+ if (forward) { |
|
141 |
+ if (dst - frame + SCREEN_WIDE < frame_off || |
|
142 |
+ frame_end - dst < frame_off + len) |
|
143 |
+ return -1; |
|
144 |
+ for (i = 0; i < len; i++) |
|
145 |
+ dst[i] = dst[frame_off + i]; |
|
146 |
+ dst += len; |
|
147 |
+ } else { |
|
148 |
+ dst -= len; |
|
149 |
+ if (dst - frame + SCREEN_WIDE < frame_off || |
|
150 |
+ frame_end - dst < frame_off + len) |
|
151 |
+ return -1; |
|
152 |
+ for (i = len - 1; i >= 0; i--) |
|
153 |
+ dst[i] = dst[frame_off + i]; |
|
154 |
+ } |
|
155 |
+ break; |
|
156 |
+ case 2: |
|
157 |
+ if (forward) { |
|
158 |
+ if (source + src_len - src < len) |
|
159 |
+ return -1; |
|
160 |
+ memcpy(dst, src, len); |
|
161 |
+ dst += len; |
|
162 |
+ src += len; |
|
163 |
+ } else { |
|
164 |
+ if (src - source < len) |
|
165 |
+ return -1; |
|
166 |
+ dst -= len; |
|
167 |
+ src -= len; |
|
168 |
+ memcpy(dst, src, len); |
|
169 |
+ } |
|
170 |
+ break; |
|
171 |
+ case 3: |
|
172 |
+ val = forward ? dst[-1] : dst[1]; |
|
173 |
+ if (forward) { |
|
174 |
+ memset(dst, val, len); |
|
175 |
+ dst += len; |
|
176 |
+ } else { |
|
177 |
+ dst -= len; |
|
178 |
+ memset(dst, val, len); |
|
179 |
+ } |
|
180 |
+ break; |
|
181 |
+ default: |
|
182 |
+ break; |
|
183 |
+ } |
|
184 |
+ if (dst == dst_end) |
|
185 |
+ return 0; |
|
186 |
+ } |
|
187 |
+ return 0; |
|
188 |
+} |
|
189 |
+ |
|
190 |
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt) |
|
191 |
+{ |
|
192 |
+ BMVDecContext * const c = avctx->priv_data; |
|
193 |
+ int type, scr_off; |
|
194 |
+ int i; |
|
195 |
+ uint8_t *srcptr, *outptr; |
|
196 |
+ |
|
197 |
+ c->stream = pkt->data; |
|
198 |
+ type = bytestream_get_byte(&c->stream); |
|
199 |
+ if (type & BMV_AUDIO) { |
|
200 |
+ int blobs = bytestream_get_byte(&c->stream); |
|
201 |
+ if (pkt->size < blobs * 65 + 2) { |
|
202 |
+ av_log(avctx, AV_LOG_ERROR, "Audio data doesn't fit in frame\n"); |
|
203 |
+ return AVERROR_INVALIDDATA; |
|
204 |
+ } |
|
205 |
+ c->stream += blobs * 65; |
|
206 |
+ } |
|
207 |
+ if (type & BMV_COMMAND) { |
|
208 |
+ int command_size = (type & BMV_PRINT) ? 8 : 10; |
|
209 |
+ if (c->stream - pkt->data + command_size > pkt->size) { |
|
210 |
+ av_log(avctx, AV_LOG_ERROR, "Command data doesn't fit in frame\n"); |
|
211 |
+ return AVERROR_INVALIDDATA; |
|
212 |
+ } |
|
213 |
+ c->stream += command_size; |
|
214 |
+ } |
|
215 |
+ if (type & BMV_PALETTE) { |
|
216 |
+ if (c->stream - pkt->data > pkt->size - 768) { |
|
217 |
+ av_log(avctx, AV_LOG_ERROR, "Palette data doesn't fit in frame\n"); |
|
218 |
+ return AVERROR_INVALIDDATA; |
|
219 |
+ } |
|
220 |
+ for (i = 0; i < 256; i++) |
|
221 |
+ c->pal[i] = bytestream_get_be24(&c->stream); |
|
222 |
+ } |
|
223 |
+ if (type & BMV_SCROLL) { |
|
224 |
+ if (c->stream - pkt->data > pkt->size - 2) { |
|
225 |
+ av_log(avctx, AV_LOG_ERROR, "Screen offset data doesn't fit in frame\n"); |
|
226 |
+ return AVERROR_INVALIDDATA; |
|
227 |
+ } |
|
228 |
+ scr_off = (int16_t)bytestream_get_le16(&c->stream); |
|
229 |
+ } else if ((type & BMV_INTRA) == BMV_INTRA) { |
|
230 |
+ scr_off = -640; |
|
231 |
+ } else { |
|
232 |
+ scr_off = 0; |
|
233 |
+ } |
|
234 |
+ |
|
235 |
+ if (decode_bmv_frame(c->stream, pkt->size - (c->stream - pkt->data), c->frame, scr_off)) { |
|
236 |
+ av_log(avctx, AV_LOG_ERROR, "Error decoding frame data\n"); |
|
237 |
+ return AVERROR_INVALIDDATA; |
|
238 |
+ } |
|
239 |
+ |
|
240 |
+ memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE); |
|
241 |
+ c->pic.palette_has_changed = type & BMV_PALETTE; |
|
242 |
+ |
|
243 |
+ outptr = c->pic.data[0]; |
|
244 |
+ srcptr = c->frame; |
|
245 |
+ |
|
246 |
+ for (i = 0; i < avctx->height; i++) { |
|
247 |
+ memcpy(outptr, srcptr, avctx->width); |
|
248 |
+ srcptr += avctx->width; |
|
249 |
+ outptr += c->pic.linesize[0]; |
|
250 |
+ } |
|
251 |
+ |
|
252 |
+ *data_size = sizeof(AVFrame); |
|
253 |
+ *(AVFrame*)data = c->pic; |
|
254 |
+ |
|
255 |
+ /* always report that the buffer was completely consumed */ |
|
256 |
+ return pkt->size; |
|
257 |
+} |
|
258 |
+ |
|
259 |
+static av_cold int decode_init(AVCodecContext *avctx) |
|
260 |
+{ |
|
261 |
+ BMVDecContext * const c = avctx->priv_data; |
|
262 |
+ |
|
263 |
+ c->avctx = avctx; |
|
264 |
+ avctx->pix_fmt = PIX_FMT_PAL8; |
|
265 |
+ |
|
266 |
+ c->pic.reference = 1; |
|
267 |
+ if (avctx->get_buffer(avctx, &c->pic) < 0) { |
|
268 |
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
269 |
+ return -1; |
|
270 |
+ } |
|
271 |
+ |
|
272 |
+ c->frame = c->frame_base + 640; |
|
273 |
+ |
|
274 |
+ return 0; |
|
275 |
+} |
|
276 |
+ |
|
277 |
+static av_cold int decode_end(AVCodecContext *avctx) |
|
278 |
+{ |
|
279 |
+ BMVDecContext *c = avctx->priv_data; |
|
280 |
+ |
|
281 |
+ if (c->pic.data[0]) |
|
282 |
+ avctx->release_buffer(avctx, &c->pic); |
|
283 |
+ |
|
284 |
+ return 0; |
|
285 |
+} |
|
286 |
+ |
|
287 |
+static const int bmv_aud_mults[16] = { |
|
288 |
+ 16512, 8256, 4128, 2064, 1032, 516, 258, 192, 129, 88, 64, 56, 48, 40, 36, 32 |
|
289 |
+}; |
|
290 |
+ |
|
291 |
+static av_cold int bmv_aud_decode_init(AVCodecContext *avctx) |
|
292 |
+{ |
|
293 |
+ |
|
294 |
+ if (avctx->channels != 2) { |
|
295 |
+ av_log(avctx, AV_LOG_INFO, "invalid number of channels\n"); |
|
296 |
+ return AVERROR(EINVAL); |
|
297 |
+ } |
|
298 |
+ |
|
299 |
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16; |
|
300 |
+ |
|
301 |
+ return 0; |
|
302 |
+} |
|
303 |
+ |
|
304 |
+static int bmv_aud_decode_frame(AVCodecContext *avctx, void *data, int *data_size, |
|
305 |
+ AVPacket *avpkt) |
|
306 |
+{ |
|
307 |
+ const uint8_t *buf = avpkt->data; |
|
308 |
+ int buf_size = avpkt->size; |
|
309 |
+ int blocks = 0, total_blocks, i; |
|
310 |
+ int out_size; |
|
311 |
+ int16_t *output_samples = data; |
|
312 |
+ int scale[2]; |
|
313 |
+ |
|
314 |
+ total_blocks = *buf++; |
|
315 |
+ if (buf_size < total_blocks * 65 + 1) { |
|
316 |
+ av_log(avctx, AV_LOG_ERROR, "expected %d bytes, got %d\n", |
|
317 |
+ total_blocks * 65 + 1, buf_size); |
|
318 |
+ return AVERROR_INVALIDDATA; |
|
319 |
+ } |
|
320 |
+ out_size = total_blocks * 64 * sizeof(*output_samples); |
|
321 |
+ if (*data_size < out_size) { |
|
322 |
+ av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n"); |
|
323 |
+ return AVERROR(EINVAL); |
|
324 |
+ } |
|
325 |
+ |
|
326 |
+ for (blocks = 0; blocks < total_blocks; blocks++) { |
|
327 |
+ uint8_t code = *buf++; |
|
328 |
+ code = (code >> 1) | (code << 7); |
|
329 |
+ scale[0] = bmv_aud_mults[code & 0xF]; |
|
330 |
+ scale[1] = bmv_aud_mults[code >> 4]; |
|
331 |
+ for (i = 0; i < 32; i++) { |
|
332 |
+ *output_samples++ = av_clip_int16((scale[0] * (int8_t)*buf++) >> 5); |
|
333 |
+ *output_samples++ = av_clip_int16((scale[1] * (int8_t)*buf++) >> 5); |
|
334 |
+ } |
|
335 |
+ } |
|
336 |
+ |
|
337 |
+ *data_size = out_size; |
|
338 |
+ return buf_size; |
|
339 |
+} |
|
340 |
+ |
|
341 |
+AVCodec ff_bmv_video_decoder = { |
|
342 |
+ .name = "bmv_video", |
|
343 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
344 |
+ .id = CODEC_ID_BMV_VIDEO, |
|
345 |
+ .priv_data_size = sizeof(BMVDecContext), |
|
346 |
+ .init = decode_init, |
|
347 |
+ .close = decode_end, |
|
348 |
+ .decode = decode_frame, |
|
349 |
+ .long_name = NULL_IF_CONFIG_SMALL("Discworld II BMV video"), |
|
350 |
+}; |
|
351 |
+ |
|
352 |
+AVCodec ff_bmv_audio_decoder = { |
|
353 |
+ .name = "bmv_audio", |
|
354 |
+ .type = AVMEDIA_TYPE_AUDIO, |
|
355 |
+ .id = CODEC_ID_BMV_AUDIO, |
|
356 |
+ .init = bmv_aud_decode_init, |
|
357 |
+ .decode = bmv_aud_decode_frame, |
|
358 |
+ .long_name = NULL_IF_CONFIG_SMALL("Discworld II BMV audio"), |
|
359 |
+}; |
... | ... |
@@ -21,7 +21,7 @@ |
21 | 21 |
#define AVCODEC_VERSION_H |
22 | 22 |
|
23 | 23 |
#define LIBAVCODEC_VERSION_MAJOR 53 |
24 |
-#define LIBAVCODEC_VERSION_MINOR 16 |
|
24 |
+#define LIBAVCODEC_VERSION_MINOR 17 |
|
25 | 25 |
#define LIBAVCODEC_VERSION_MICRO 0 |
26 | 26 |
|
27 | 27 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
... | ... |
@@ -46,6 +46,7 @@ OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o voc.o |
46 | 46 |
OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o |
47 | 47 |
OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o |
48 | 48 |
OBJS-$(CONFIG_BINK_DEMUXER) += bink.o |
49 |
+OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o |
|
49 | 50 |
OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o |
50 | 51 |
OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o riff.o isom.o |
51 | 52 |
OBJS-$(CONFIG_CAVSVIDEO_DEMUXER) += cavsvideodec.o rawdec.o |
... | ... |
@@ -70,6 +70,7 @@ void av_register_all(void) |
70 | 70 |
REGISTER_DEMUXER (BETHSOFTVID, bethsoftvid); |
71 | 71 |
REGISTER_DEMUXER (BFI, bfi); |
72 | 72 |
REGISTER_DEMUXER (BINK, bink); |
73 |
+ REGISTER_DEMUXER (BMV, bmv); |
|
73 | 74 |
REGISTER_DEMUXER (C93, c93); |
74 | 75 |
REGISTER_DEMUXER (CAF, caf); |
75 | 76 |
REGISTER_MUXDEMUX (CAVSVIDEO, cavsvideo); |
76 | 77 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,136 @@ |
0 |
+/* |
|
1 |
+ * Discworld II BMV demuxer |
|
2 |
+ * Copyright (c) 2011 Konstantin Shishkov. |
|
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 "avformat.h" |
|
22 |
+ |
|
23 |
+enum BMVFlags { |
|
24 |
+ BMV_NOP = 0, |
|
25 |
+ BMV_END, |
|
26 |
+ BMV_DELTA, |
|
27 |
+ BMV_INTRA, |
|
28 |
+ |
|
29 |
+ BMV_AUDIO = 0x20, |
|
30 |
+}; |
|
31 |
+ |
|
32 |
+typedef struct BMVContext { |
|
33 |
+ uint8_t *packet; |
|
34 |
+ int size; |
|
35 |
+ int get_next; |
|
36 |
+ int64_t audio_pos; |
|
37 |
+} BMVContext; |
|
38 |
+ |
|
39 |
+static int bmv_read_header(AVFormatContext *s, AVFormatParameters *ap) |
|
40 |
+{ |
|
41 |
+ AVStream *st, *ast; |
|
42 |
+ BMVContext *c = s->priv_data; |
|
43 |
+ |
|
44 |
+ st = avformat_new_stream(s, 0); |
|
45 |
+ if (!st) |
|
46 |
+ return AVERROR(ENOMEM); |
|
47 |
+ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; |
|
48 |
+ st->codec->codec_id = CODEC_ID_BMV_VIDEO; |
|
49 |
+ st->codec->width = 640; |
|
50 |
+ st->codec->height = 429; |
|
51 |
+ st->codec->pix_fmt = PIX_FMT_PAL8; |
|
52 |
+ av_set_pts_info(st, 16, 1, 12); |
|
53 |
+ ast = avformat_new_stream(s, 0); |
|
54 |
+ if (!ast) |
|
55 |
+ return AVERROR(ENOMEM); |
|
56 |
+ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; |
|
57 |
+ ast->codec->codec_id = CODEC_ID_BMV_AUDIO; |
|
58 |
+ ast->codec->channels = 2; |
|
59 |
+ ast->codec->sample_rate = 22050; |
|
60 |
+ av_set_pts_info(ast, 16, 1, 22050); |
|
61 |
+ |
|
62 |
+ c->get_next = 1; |
|
63 |
+ c->audio_pos = 0; |
|
64 |
+ return 0; |
|
65 |
+} |
|
66 |
+ |
|
67 |
+static int bmv_read_packet(AVFormatContext *s, AVPacket *pkt) |
|
68 |
+{ |
|
69 |
+ BMVContext *c = s->priv_data; |
|
70 |
+ int type; |
|
71 |
+ void *tmp; |
|
72 |
+ |
|
73 |
+ while (c->get_next) { |
|
74 |
+ if (s->pb->eof_reached) |
|
75 |
+ return AVERROR_EOF; |
|
76 |
+ type = avio_r8(s->pb); |
|
77 |
+ if (type == BMV_NOP) |
|
78 |
+ continue; |
|
79 |
+ if (type == BMV_END) |
|
80 |
+ return AVERROR_EOF; |
|
81 |
+ c->size = avio_rl24(s->pb); |
|
82 |
+ if (!c->size) |
|
83 |
+ return AVERROR_INVALIDDATA; |
|
84 |
+ tmp = av_realloc(c->packet, c->size + 1); |
|
85 |
+ if (!tmp) |
|
86 |
+ return AVERROR(ENOMEM); |
|
87 |
+ c->packet = tmp; |
|
88 |
+ c->packet[0] = type; |
|
89 |
+ if (avio_read(s->pb, c->packet + 1, c->size) != c->size) |
|
90 |
+ return AVERROR(EIO); |
|
91 |
+ if (type & BMV_AUDIO) { |
|
92 |
+ int audio_size = c->packet[1] * 65 + 1; |
|
93 |
+ if (audio_size >= c->size) { |
|
94 |
+ av_log(s, AV_LOG_ERROR, "Reported audio size %d is bigger than packet size (%d)\n", |
|
95 |
+ audio_size, c->size); |
|
96 |
+ return AVERROR_INVALIDDATA; |
|
97 |
+ } |
|
98 |
+ if (av_new_packet(pkt, audio_size) < 0) |
|
99 |
+ return AVERROR(ENOMEM); |
|
100 |
+ memcpy(pkt->data, c->packet + 1, pkt->size); |
|
101 |
+ pkt->stream_index = 1; |
|
102 |
+ pkt->pts = c->audio_pos; |
|
103 |
+ pkt->duration = c->packet[1] * 32; |
|
104 |
+ c->audio_pos += pkt->duration; |
|
105 |
+ c->get_next = 0; |
|
106 |
+ return pkt->size; |
|
107 |
+ } else |
|
108 |
+ break; |
|
109 |
+ } |
|
110 |
+ if (av_new_packet(pkt, c->size + 1) < 0) |
|
111 |
+ return AVERROR(ENOMEM); |
|
112 |
+ pkt->stream_index = 0; |
|
113 |
+ c->get_next = 1; |
|
114 |
+ memcpy(pkt->data, c->packet, pkt->size); |
|
115 |
+ return pkt->size; |
|
116 |
+} |
|
117 |
+ |
|
118 |
+static int bmv_read_close(AVFormatContext *s) |
|
119 |
+{ |
|
120 |
+ BMVContext *c = s->priv_data; |
|
121 |
+ |
|
122 |
+ av_freep(&c->packet); |
|
123 |
+ |
|
124 |
+ return 0; |
|
125 |
+} |
|
126 |
+ |
|
127 |
+AVInputFormat ff_bmv_demuxer = { |
|
128 |
+ .name = "bmv", |
|
129 |
+ .long_name = NULL_IF_CONFIG_SMALL("Discworld II BMV"), |
|
130 |
+ .priv_data_size = sizeof(BMVContext), |
|
131 |
+ .read_header = bmv_read_header, |
|
132 |
+ .read_packet = bmv_read_packet, |
|
133 |
+ .read_close = bmv_read_close, |
|
134 |
+ .extensions = "bmv" |
|
135 |
+}; |
... | ... |
@@ -24,7 +24,7 @@ |
24 | 24 |
#include "libavutil/avutil.h" |
25 | 25 |
|
26 | 26 |
#define LIBAVFORMAT_VERSION_MAJOR 53 |
27 |
-#define LIBAVFORMAT_VERSION_MINOR 13 |
|
27 |
+#define LIBAVFORMAT_VERSION_MINOR 14 |
|
28 | 28 |
#define LIBAVFORMAT_VERSION_MICRO 0 |
29 | 29 |
|
30 | 30 |
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |