Signed-off-by: Anton Khirnov <anton@khirnov.net>
| ... | ... |
@@ -81,6 +81,8 @@ library: |
| 81 | 81 |
@tab Audio format used in some games by CRYO Interactive Entertainment. |
| 82 | 82 |
@item D-Cinema audio @tab X @tab X |
| 83 | 83 |
@item Deluxe Paint Animation @tab @tab X |
| 84 |
+@item DFA @tab @tab X |
|
| 85 |
+ @tab This format is used in Chronomaster game |
|
| 84 | 86 |
@item DV video @tab X @tab X |
| 85 | 87 |
@item DXA @tab @tab X |
| 86 | 88 |
@tab This format is used in the non-Windows version of the Feeble Files |
| ... | ... |
@@ -371,6 +373,8 @@ following image formats are supported: |
| 371 | 371 |
@item Cirrus Logic AccuPak @tab @tab X |
| 372 | 372 |
@tab fourcc: CLJR |
| 373 | 373 |
@item Creative YUV (CYUV) @tab @tab X |
| 374 |
+@item DFA @tab @tab X |
|
| 375 |
+ @tab Codec used in Chronomaster game. |
|
| 374 | 376 |
@item Dirac @tab E @tab E |
| 375 | 377 |
@tab supported through external libdirac/libschroedinger libraries |
| 376 | 378 |
@item Deluxe Paint Animation @tab @tab X |
| ... | ... |
@@ -103,6 +103,7 @@ OBJS-$(CONFIG_COOK_DECODER) += cook.o |
| 103 | 103 |
OBJS-$(CONFIG_CSCD_DECODER) += cscd.o |
| 104 | 104 |
OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o |
| 105 | 105 |
OBJS-$(CONFIG_DCA_DECODER) += dca.o synth_filter.o dcadsp.o |
| 106 |
+OBJS-$(CONFIG_DFA_DECODER) += dfa.o |
|
| 106 | 107 |
OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o |
| 107 | 108 |
OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o \ |
| 108 | 109 |
mpegvideo_enc.o motion_est.o \ |
| ... | ... |
@@ -88,6 +88,7 @@ void avcodec_register_all(void) |
| 88 | 88 |
REGISTER_DECODER (CLJR, cljr); |
| 89 | 89 |
REGISTER_DECODER (CSCD, cscd); |
| 90 | 90 |
REGISTER_DECODER (CYUV, cyuv); |
| 91 |
+ REGISTER_DECODER (DFA, dfa); |
|
| 91 | 92 |
REGISTER_ENCDEC (DNXHD, dnxhd); |
| 92 | 93 |
REGISTER_DECODER (DPX, dpx); |
| 93 | 94 |
REGISTER_DECODER (DSICINVIDEO, dsicinvideo); |
| 218 | 219 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,395 @@ |
| 0 |
+/* |
|
| 1 |
+ * Chronomaster DFA Video Decoder |
|
| 2 |
+ * Copyright (c) 2011 Konstantin Shishkov |
|
| 3 |
+ * based on work by Vladimir "VAG" Gneushev |
|
| 4 |
+ * |
|
| 5 |
+ * This file is part of Libav. |
|
| 6 |
+ * |
|
| 7 |
+ * Libav is free software; you can redistribute it and/or |
|
| 8 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 9 |
+ * License as published by the Free Software Foundation; either |
|
| 10 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 11 |
+ * |
|
| 12 |
+ * Libav is distributed in the hope that it will be useful, |
|
| 13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 15 |
+ * Lesser General Public License for more details. |
|
| 16 |
+ * |
|
| 17 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 18 |
+ * License along with Libav; if not, write to the Free Software |
|
| 19 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 20 |
+ */ |
|
| 21 |
+ |
|
| 22 |
+#include "avcodec.h" |
|
| 23 |
+#include "libavutil/intreadwrite.h" |
|
| 24 |
+#include "bytestream.h" |
|
| 25 |
+#include "libavutil/lzo.h" // for av_memcpy_backptr |
|
| 26 |
+ |
|
| 27 |
+typedef struct DfaContext {
|
|
| 28 |
+ AVFrame pic; |
|
| 29 |
+ |
|
| 30 |
+ uint32_t pal[256]; |
|
| 31 |
+ uint8_t *frame_buf; |
|
| 32 |
+} DfaContext; |
|
| 33 |
+ |
|
| 34 |
+static av_cold int dfa_decode_init(AVCodecContext *avctx) |
|
| 35 |
+{
|
|
| 36 |
+ DfaContext *s = avctx->priv_data; |
|
| 37 |
+ |
|
| 38 |
+ avctx->pix_fmt = PIX_FMT_PAL8; |
|
| 39 |
+ |
|
| 40 |
+ s->frame_buf = av_mallocz(avctx->width * avctx->height + AV_LZO_OUTPUT_PADDING); |
|
| 41 |
+ if (!s->frame_buf) |
|
| 42 |
+ return AVERROR(ENOMEM); |
|
| 43 |
+ |
|
| 44 |
+ return 0; |
|
| 45 |
+} |
|
| 46 |
+ |
|
| 47 |
+static int decode_copy(uint8_t *frame, int width, int height, |
|
| 48 |
+ const uint8_t *src, const uint8_t *src_end) |
|
| 49 |
+{
|
|
| 50 |
+ const int size = width * height; |
|
| 51 |
+ |
|
| 52 |
+ if (src_end - src < size) |
|
| 53 |
+ return -1; |
|
| 54 |
+ bytestream_get_buffer(&src, frame, size); |
|
| 55 |
+ return 0; |
|
| 56 |
+} |
|
| 57 |
+ |
|
| 58 |
+static int decode_tsw1(uint8_t *frame, int width, int height, |
|
| 59 |
+ const uint8_t *src, const uint8_t *src_end) |
|
| 60 |
+{
|
|
| 61 |
+ const uint8_t *frame_start = frame; |
|
| 62 |
+ const uint8_t *frame_end = frame + width * height; |
|
| 63 |
+ int mask = 0x10000, bitbuf = 0; |
|
| 64 |
+ int v, offset, count, segments; |
|
| 65 |
+ |
|
| 66 |
+ segments = bytestream_get_le32(&src); |
|
| 67 |
+ frame += bytestream_get_le32(&src); |
|
| 68 |
+ if (frame < frame_start || frame > frame_end) |
|
| 69 |
+ return -1; |
|
| 70 |
+ while (segments--) {
|
|
| 71 |
+ if (mask == 0x10000) {
|
|
| 72 |
+ if (src >= src_end) |
|
| 73 |
+ return -1; |
|
| 74 |
+ bitbuf = bytestream_get_le16(&src); |
|
| 75 |
+ mask = 1; |
|
| 76 |
+ } |
|
| 77 |
+ if (src_end - src < 2 || frame_end - frame < 2) |
|
| 78 |
+ return -1; |
|
| 79 |
+ if (bitbuf & mask) {
|
|
| 80 |
+ v = bytestream_get_le16(&src); |
|
| 81 |
+ offset = (v & 0x1FFF) << 1; |
|
| 82 |
+ count = ((v >> 13) + 2) << 1; |
|
| 83 |
+ if (frame - offset < frame_start || frame_end - frame < count) |
|
| 84 |
+ return -1; |
|
| 85 |
+ av_memcpy_backptr(frame, offset, count); |
|
| 86 |
+ frame += count; |
|
| 87 |
+ } else {
|
|
| 88 |
+ *frame++ = *src++; |
|
| 89 |
+ *frame++ = *src++; |
|
| 90 |
+ } |
|
| 91 |
+ mask <<= 1; |
|
| 92 |
+ } |
|
| 93 |
+ |
|
| 94 |
+ return 0; |
|
| 95 |
+} |
|
| 96 |
+ |
|
| 97 |
+static int decode_dsw1(uint8_t *frame, int width, int height, |
|
| 98 |
+ const uint8_t *src, const uint8_t *src_end) |
|
| 99 |
+{
|
|
| 100 |
+ const uint8_t *frame_start = frame; |
|
| 101 |
+ const uint8_t *frame_end = frame + width * height; |
|
| 102 |
+ int mask = 0x10000, bitbuf = 0; |
|
| 103 |
+ int v, offset, count, segments; |
|
| 104 |
+ |
|
| 105 |
+ segments = bytestream_get_le16(&src); |
|
| 106 |
+ while (segments--) {
|
|
| 107 |
+ if (mask == 0x10000) {
|
|
| 108 |
+ if (src >= src_end) |
|
| 109 |
+ return -1; |
|
| 110 |
+ bitbuf = bytestream_get_le16(&src); |
|
| 111 |
+ mask = 1; |
|
| 112 |
+ } |
|
| 113 |
+ if (src_end - src < 2 || frame_end - frame < 2) |
|
| 114 |
+ return -1; |
|
| 115 |
+ if (bitbuf & mask) {
|
|
| 116 |
+ v = bytestream_get_le16(&src); |
|
| 117 |
+ offset = (v & 0x1FFF) << 1; |
|
| 118 |
+ count = ((v >> 13) + 2) << 1; |
|
| 119 |
+ if (frame - offset < frame_start || frame_end - frame < count) |
|
| 120 |
+ return -1; |
|
| 121 |
+ // can't use av_memcpy_backptr() since it can overwrite following pixels |
|
| 122 |
+ for (v = 0; v < count; v++) |
|
| 123 |
+ frame[v] = frame[v - offset]; |
|
| 124 |
+ frame += count; |
|
| 125 |
+ } else if (bitbuf & (mask << 1)) {
|
|
| 126 |
+ frame += bytestream_get_le16(&src); |
|
| 127 |
+ } else {
|
|
| 128 |
+ *frame++ = *src++; |
|
| 129 |
+ *frame++ = *src++; |
|
| 130 |
+ } |
|
| 131 |
+ mask <<= 2; |
|
| 132 |
+ } |
|
| 133 |
+ |
|
| 134 |
+ return 0; |
|
| 135 |
+} |
|
| 136 |
+ |
|
| 137 |
+static int decode_dds1(uint8_t *frame, int width, int height, |
|
| 138 |
+ const uint8_t *src, const uint8_t *src_end) |
|
| 139 |
+{
|
|
| 140 |
+ const uint8_t *frame_start = frame; |
|
| 141 |
+ const uint8_t *frame_end = frame + width * height; |
|
| 142 |
+ int mask = 0x10000, bitbuf = 0; |
|
| 143 |
+ int i, v, offset, count, segments; |
|
| 144 |
+ |
|
| 145 |
+ segments = bytestream_get_le16(&src); |
|
| 146 |
+ while (segments--) {
|
|
| 147 |
+ if (mask == 0x10000) {
|
|
| 148 |
+ if (src >= src_end) |
|
| 149 |
+ return -1; |
|
| 150 |
+ bitbuf = bytestream_get_le16(&src); |
|
| 151 |
+ mask = 1; |
|
| 152 |
+ } |
|
| 153 |
+ if (src_end - src < 2 || frame_end - frame < 2) |
|
| 154 |
+ return -1; |
|
| 155 |
+ if (bitbuf & mask) {
|
|
| 156 |
+ v = bytestream_get_le16(&src); |
|
| 157 |
+ offset = (v & 0x1FFF) << 2; |
|
| 158 |
+ count = ((v >> 13) + 2) << 1; |
|
| 159 |
+ if (frame - offset < frame_start || frame_end - frame < count*2 + width) |
|
| 160 |
+ return -1; |
|
| 161 |
+ for (i = 0; i < count; i++) {
|
|
| 162 |
+ frame[0] = frame[1] = |
|
| 163 |
+ frame[width] = frame[width + 1] = frame[-offset]; |
|
| 164 |
+ |
|
| 165 |
+ frame += 2; |
|
| 166 |
+ } |
|
| 167 |
+ } else if (bitbuf & (mask << 1)) {
|
|
| 168 |
+ frame += bytestream_get_le16(&src) * 2; |
|
| 169 |
+ } else {
|
|
| 170 |
+ frame[0] = frame[1] = |
|
| 171 |
+ frame[width] = frame[width + 1] = *src++; |
|
| 172 |
+ frame += 2; |
|
| 173 |
+ frame[0] = frame[1] = |
|
| 174 |
+ frame[width] = frame[width + 1] = *src++; |
|
| 175 |
+ frame += 2; |
|
| 176 |
+ } |
|
| 177 |
+ mask <<= 2; |
|
| 178 |
+ } |
|
| 179 |
+ |
|
| 180 |
+ return 0; |
|
| 181 |
+} |
|
| 182 |
+ |
|
| 183 |
+static int decode_bdlt(uint8_t *frame, int width, int height, |
|
| 184 |
+ const uint8_t *src, const uint8_t *src_end) |
|
| 185 |
+{
|
|
| 186 |
+ const uint8_t *frame_end = frame + width * height; |
|
| 187 |
+ uint8_t *line_ptr; |
|
| 188 |
+ int count, lines, segments; |
|
| 189 |
+ |
|
| 190 |
+ count = bytestream_get_le16(&src); |
|
| 191 |
+ if (count >= height || width * count < 0) |
|
| 192 |
+ return -1; |
|
| 193 |
+ frame += width * count; |
|
| 194 |
+ lines = bytestream_get_le16(&src); |
|
| 195 |
+ if (frame + lines * width > frame_end || src >= src_end) |
|
| 196 |
+ return -1; |
|
| 197 |
+ |
|
| 198 |
+ while (lines--) {
|
|
| 199 |
+ line_ptr = frame; |
|
| 200 |
+ frame += width; |
|
| 201 |
+ segments = *src++; |
|
| 202 |
+ while (segments--) {
|
|
| 203 |
+ if (src_end - src < 3) |
|
| 204 |
+ return -1; |
|
| 205 |
+ line_ptr += *src++; |
|
| 206 |
+ if (line_ptr >= frame) |
|
| 207 |
+ return -1; |
|
| 208 |
+ count = (int8_t)*src++; |
|
| 209 |
+ if (count >= 0) {
|
|
| 210 |
+ if (line_ptr + count > frame || src_end - src < count) |
|
| 211 |
+ return -1; |
|
| 212 |
+ bytestream_get_buffer(&src, line_ptr, count); |
|
| 213 |
+ } else {
|
|
| 214 |
+ count = -count; |
|
| 215 |
+ if (line_ptr + count > frame || src >= src_end) |
|
| 216 |
+ return -1; |
|
| 217 |
+ memset(line_ptr, *src++, count); |
|
| 218 |
+ } |
|
| 219 |
+ line_ptr += count; |
|
| 220 |
+ } |
|
| 221 |
+ } |
|
| 222 |
+ |
|
| 223 |
+ return 0; |
|
| 224 |
+} |
|
| 225 |
+ |
|
| 226 |
+static int decode_wdlt(uint8_t *frame, int width, int height, |
|
| 227 |
+ const uint8_t *src, const uint8_t *src_end) |
|
| 228 |
+{
|
|
| 229 |
+ const uint8_t *frame_end = frame + width * height; |
|
| 230 |
+ uint8_t *line_ptr; |
|
| 231 |
+ int count, i, v, lines, segments; |
|
| 232 |
+ |
|
| 233 |
+ lines = bytestream_get_le16(&src); |
|
| 234 |
+ if (frame + lines * width > frame_end || src >= src_end) |
|
| 235 |
+ return -1; |
|
| 236 |
+ |
|
| 237 |
+ while (lines--) {
|
|
| 238 |
+ segments = bytestream_get_le16(&src); |
|
| 239 |
+ while ((segments & 0xC000) == 0xC000) {
|
|
| 240 |
+ frame -= (int16_t)segments * width; |
|
| 241 |
+ if (frame >= frame_end) |
|
| 242 |
+ return -1; |
|
| 243 |
+ segments = bytestream_get_le16(&src); |
|
| 244 |
+ } |
|
| 245 |
+ if (segments & 0x8000) {
|
|
| 246 |
+ frame[width - 1] = segments & 0xFF; |
|
| 247 |
+ segments = bytestream_get_le16(&src); |
|
| 248 |
+ } |
|
| 249 |
+ line_ptr = frame; |
|
| 250 |
+ frame += width; |
|
| 251 |
+ while (segments--) {
|
|
| 252 |
+ if (src_end - src < 2) |
|
| 253 |
+ return -1; |
|
| 254 |
+ line_ptr += *src++; |
|
| 255 |
+ if (line_ptr >= frame) |
|
| 256 |
+ return -1; |
|
| 257 |
+ count = (int8_t)*src++; |
|
| 258 |
+ if (count >= 0) {
|
|
| 259 |
+ if (line_ptr + count*2 > frame || src_end - src < count*2) |
|
| 260 |
+ return -1; |
|
| 261 |
+ bytestream_get_buffer(&src, line_ptr, count*2); |
|
| 262 |
+ line_ptr += count * 2; |
|
| 263 |
+ } else {
|
|
| 264 |
+ count = -count; |
|
| 265 |
+ if (line_ptr + count*2 > frame || src_end - src < 2) |
|
| 266 |
+ return -1; |
|
| 267 |
+ v = bytestream_get_le16(&src); |
|
| 268 |
+ for (i = 0; i < count; i++) |
|
| 269 |
+ bytestream_put_le16(&line_ptr, v); |
|
| 270 |
+ } |
|
| 271 |
+ } |
|
| 272 |
+ } |
|
| 273 |
+ |
|
| 274 |
+ return 0; |
|
| 275 |
+} |
|
| 276 |
+ |
|
| 277 |
+static int decode_unk6(uint8_t *frame, int width, int height, |
|
| 278 |
+ const uint8_t *src, const uint8_t *src_end) |
|
| 279 |
+{
|
|
| 280 |
+ return -1; |
|
| 281 |
+} |
|
| 282 |
+ |
|
| 283 |
+static int decode_blck(uint8_t *frame, int width, int height, |
|
| 284 |
+ const uint8_t *src, const uint8_t *src_end) |
|
| 285 |
+{
|
|
| 286 |
+ memset(frame, 0, width * height); |
|
| 287 |
+ return 0; |
|
| 288 |
+} |
|
| 289 |
+ |
|
| 290 |
+ |
|
| 291 |
+typedef int (*chunk_decoder)(uint8_t *frame, int width, int height, |
|
| 292 |
+ const uint8_t *src, const uint8_t *src_end); |
|
| 293 |
+ |
|
| 294 |
+static const chunk_decoder decoder[8] = {
|
|
| 295 |
+ decode_copy, decode_tsw1, decode_bdlt, decode_wdlt, |
|
| 296 |
+ decode_unk6, decode_dsw1, decode_blck, decode_dds1, |
|
| 297 |
+}; |
|
| 298 |
+ |
|
| 299 |
+static const char* chunk_name[8] = {
|
|
| 300 |
+ "COPY", "TSW1", "BDLT", "WDLT", "????", "DSW1", "BLCK", "DDS1" |
|
| 301 |
+}; |
|
| 302 |
+ |
|
| 303 |
+static int dfa_decode_frame(AVCodecContext *avctx, |
|
| 304 |
+ void *data, int *data_size, |
|
| 305 |
+ AVPacket *avpkt) |
|
| 306 |
+{
|
|
| 307 |
+ DfaContext *s = avctx->priv_data; |
|
| 308 |
+ const uint8_t *buf = avpkt->data; |
|
| 309 |
+ const uint8_t *buf_end = avpkt->data + avpkt->size; |
|
| 310 |
+ const uint8_t *tmp_buf; |
|
| 311 |
+ uint32_t chunk_type, chunk_size; |
|
| 312 |
+ uint8_t *dst; |
|
| 313 |
+ int ret; |
|
| 314 |
+ int i, pal_elems; |
|
| 315 |
+ |
|
| 316 |
+ if (s->pic.data[0]) |
|
| 317 |
+ avctx->release_buffer(avctx, &s->pic); |
|
| 318 |
+ |
|
| 319 |
+ if ((ret = avctx->get_buffer(avctx, &s->pic))) {
|
|
| 320 |
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
| 321 |
+ return ret; |
|
| 322 |
+ } |
|
| 323 |
+ |
|
| 324 |
+ while (buf < buf_end) {
|
|
| 325 |
+ chunk_size = AV_RL32(buf + 4); |
|
| 326 |
+ chunk_type = AV_RL32(buf + 8); |
|
| 327 |
+ buf += 12; |
|
| 328 |
+ if (buf_end - buf < chunk_size) {
|
|
| 329 |
+ av_log(avctx, AV_LOG_ERROR, "Chunk size is too big (%d bytes)\n", chunk_size); |
|
| 330 |
+ return -1; |
|
| 331 |
+ } |
|
| 332 |
+ if (!chunk_type) |
|
| 333 |
+ break; |
|
| 334 |
+ if (chunk_type == 1) {
|
|
| 335 |
+ pal_elems = FFMIN(chunk_size / 3, 256); |
|
| 336 |
+ tmp_buf = buf; |
|
| 337 |
+ for (i = 0; i < pal_elems; i++) {
|
|
| 338 |
+ s->pal[i] = bytestream_get_be24(&tmp_buf) << 2; |
|
| 339 |
+ s->pal[i] |= (s->pal[i] >> 6) & 0x333; |
|
| 340 |
+ } |
|
| 341 |
+ s->pic.palette_has_changed = 1; |
|
| 342 |
+ } else if (chunk_type <= 9) {
|
|
| 343 |
+ if (decoder[chunk_type - 2](s->frame_buf, avctx->width, avctx->height, |
|
| 344 |
+ buf, buf + chunk_size)) {
|
|
| 345 |
+ av_log(avctx, AV_LOG_ERROR, "Error decoding %s chunk\n", |
|
| 346 |
+ chunk_name[chunk_type - 2]); |
|
| 347 |
+ return -1; |
|
| 348 |
+ } |
|
| 349 |
+ } else {
|
|
| 350 |
+ av_log(avctx, AV_LOG_WARNING, "Ignoring unknown chunk type %d\n", |
|
| 351 |
+ chunk_type); |
|
| 352 |
+ } |
|
| 353 |
+ buf += chunk_size; |
|
| 354 |
+ } |
|
| 355 |
+ |
|
| 356 |
+ buf = s->frame_buf; |
|
| 357 |
+ dst = s->pic.data[0]; |
|
| 358 |
+ for (i = 0; i < avctx->height; i++) {
|
|
| 359 |
+ memcpy(dst, buf, avctx->width); |
|
| 360 |
+ dst += s->pic.linesize[0]; |
|
| 361 |
+ buf += avctx->width; |
|
| 362 |
+ } |
|
| 363 |
+ memcpy(s->pic.data[1], s->pal, sizeof(s->pal)); |
|
| 364 |
+ |
|
| 365 |
+ *data_size = sizeof(AVFrame); |
|
| 366 |
+ *(AVFrame*)data = s->pic; |
|
| 367 |
+ |
|
| 368 |
+ return avpkt->size; |
|
| 369 |
+} |
|
| 370 |
+ |
|
| 371 |
+static av_cold int dfa_decode_end(AVCodecContext *avctx) |
|
| 372 |
+{
|
|
| 373 |
+ DfaContext *s = avctx->priv_data; |
|
| 374 |
+ |
|
| 375 |
+ if (s->pic.data[0]) |
|
| 376 |
+ avctx->release_buffer(avctx, &s->pic); |
|
| 377 |
+ |
|
| 378 |
+ av_freep(&s->frame_buf); |
|
| 379 |
+ |
|
| 380 |
+ return 0; |
|
| 381 |
+} |
|
| 382 |
+ |
|
| 383 |
+AVCodec ff_dfa_decoder = {
|
|
| 384 |
+ "dfa", |
|
| 385 |
+ AVMEDIA_TYPE_VIDEO, |
|
| 386 |
+ CODEC_ID_DFA, |
|
| 387 |
+ sizeof(DfaContext), |
|
| 388 |
+ dfa_decode_init, |
|
| 389 |
+ NULL, |
|
| 390 |
+ dfa_decode_end, |
|
| 391 |
+ dfa_decode_frame, |
|
| 392 |
+ CODEC_CAP_DR1, |
|
| 393 |
+ .long_name = NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
|
|
| 394 |
+}; |
| ... | ... |
@@ -21,7 +21,7 @@ |
| 21 | 21 |
#define AVCODEC_VERSION_H |
| 22 | 22 |
|
| 23 | 23 |
#define LIBAVCODEC_VERSION_MAJOR 52 |
| 24 |
-#define LIBAVCODEC_VERSION_MINOR 115 |
|
| 24 |
+#define LIBAVCODEC_VERSION_MINOR 116 |
|
| 25 | 25 |
#define LIBAVCODEC_VERSION_MICRO 0 |
| 26 | 26 |
|
| 27 | 27 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| ... | ... |
@@ -55,6 +55,7 @@ OBJS-$(CONFIG_CDG_DEMUXER) += cdg.o |
| 55 | 55 |
OBJS-$(CONFIG_CRC_MUXER) += crcenc.o |
| 56 | 56 |
OBJS-$(CONFIG_DAUD_DEMUXER) += daud.o |
| 57 | 57 |
OBJS-$(CONFIG_DAUD_MUXER) += daud.o |
| 58 |
+OBJS-$(CONFIG_DFA_DEMUXER) += dfa.o |
|
| 58 | 59 |
OBJS-$(CONFIG_DIRAC_DEMUXER) += diracdec.o rawdec.o |
| 59 | 60 |
OBJS-$(CONFIG_DIRAC_MUXER) += rawenc.o |
| 60 | 61 |
OBJS-$(CONFIG_DNXHD_DEMUXER) += dnxhddec.o rawdec.o |
| ... | ... |
@@ -75,6 +75,7 @@ void av_register_all(void) |
| 75 | 75 |
REGISTER_DEMUXER (CDG, cdg); |
| 76 | 76 |
REGISTER_MUXER (CRC, crc); |
| 77 | 77 |
REGISTER_MUXDEMUX (DAUD, daud); |
| 78 |
+ REGISTER_DEMUXER (DFA, dfa); |
|
| 78 | 79 |
REGISTER_MUXDEMUX (DIRAC, dirac); |
| 79 | 80 |
REGISTER_MUXDEMUX (DNXHD, dnxhd); |
| 80 | 81 |
REGISTER_DEMUXER (DSICIN, dsicin); |
| 81 | 82 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,119 @@ |
| 0 |
+/* |
|
| 1 |
+ * Chronomaster DFA Format 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 "libavutil/intreadwrite.h" |
|
| 22 |
+#include "avformat.h" |
|
| 23 |
+ |
|
| 24 |
+static int dfa_probe(AVProbeData *p) |
|
| 25 |
+{
|
|
| 26 |
+ if (p->buf_size < 4 || AV_RL32(p->buf) != MKTAG('D', 'F', 'I', 'A'))
|
|
| 27 |
+ return 0; |
|
| 28 |
+ |
|
| 29 |
+ return AVPROBE_SCORE_MAX; |
|
| 30 |
+} |
|
| 31 |
+ |
|
| 32 |
+static int dfa_read_header(AVFormatContext *s, |
|
| 33 |
+ AVFormatParameters *ap) |
|
| 34 |
+{
|
|
| 35 |
+ AVIOContext *pb = s->pb; |
|
| 36 |
+ AVStream *st; |
|
| 37 |
+ int frames; |
|
| 38 |
+ uint32_t mspf; |
|
| 39 |
+ |
|
| 40 |
+ if (avio_rl32(pb) != MKTAG('D', 'F', 'I', 'A')) {
|
|
| 41 |
+ av_log(s, AV_LOG_ERROR, "Invalid magic for DFA\n"); |
|
| 42 |
+ return AVERROR_INVALIDDATA; |
|
| 43 |
+ } |
|
| 44 |
+ avio_skip(pb, 2); // unused |
|
| 45 |
+ frames = avio_rl16(pb); |
|
| 46 |
+ |
|
| 47 |
+ st = av_new_stream(s, 0); |
|
| 48 |
+ if (!st) |
|
| 49 |
+ return AVERROR(ENOMEM); |
|
| 50 |
+ |
|
| 51 |
+ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; |
|
| 52 |
+ st->codec->codec_id = CODEC_ID_DFA; |
|
| 53 |
+ st->codec->width = avio_rl16(pb); |
|
| 54 |
+ st->codec->height = avio_rl16(pb); |
|
| 55 |
+ mspf = avio_rl32(pb); |
|
| 56 |
+ if (!mspf) {
|
|
| 57 |
+ av_log(s, AV_LOG_WARNING, "Zero FPS reported, defaulting to 10\n"); |
|
| 58 |
+ mspf = 100; |
|
| 59 |
+ } |
|
| 60 |
+ av_set_pts_info(st, 24, mspf, 1000); |
|
| 61 |
+ avio_skip(pb, 128 - 16); // padding |
|
| 62 |
+ st->duration = frames; |
|
| 63 |
+ |
|
| 64 |
+ return 0; |
|
| 65 |
+} |
|
| 66 |
+ |
|
| 67 |
+static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt) |
|
| 68 |
+{
|
|
| 69 |
+ AVIOContext *pb = s->pb; |
|
| 70 |
+ uint32_t frame_size; |
|
| 71 |
+ int ret, first = 1; |
|
| 72 |
+ |
|
| 73 |
+ if (pb->eof_reached) |
|
| 74 |
+ return AVERROR_EOF; |
|
| 75 |
+ |
|
| 76 |
+ if (av_get_packet(pb, pkt, 12) != 12) |
|
| 77 |
+ return AVERROR(EIO); |
|
| 78 |
+ while (!pb->eof_reached) {
|
|
| 79 |
+ if (!first) {
|
|
| 80 |
+ ret = av_append_packet(pb, pkt, 12); |
|
| 81 |
+ if (ret < 0) {
|
|
| 82 |
+ av_free_packet(pkt); |
|
| 83 |
+ return ret; |
|
| 84 |
+ } |
|
| 85 |
+ } else |
|
| 86 |
+ first = 0; |
|
| 87 |
+ frame_size = AV_RL32(pkt->data + pkt->size - 8); |
|
| 88 |
+ if (frame_size > INT_MAX - 4) {
|
|
| 89 |
+ av_log(s, AV_LOG_ERROR, "Too large chunk size: %d\n", frame_size); |
|
| 90 |
+ return AVERROR(EIO); |
|
| 91 |
+ } |
|
| 92 |
+ if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) {
|
|
| 93 |
+ if (frame_size) {
|
|
| 94 |
+ av_log(s, AV_LOG_WARNING, "skipping %d bytes of end-of-frame marker chunk\n", |
|
| 95 |
+ frame_size); |
|
| 96 |
+ avio_skip(pb, frame_size); |
|
| 97 |
+ } |
|
| 98 |
+ return 0; |
|
| 99 |
+ } |
|
| 100 |
+ ret = av_append_packet(pb, pkt, frame_size); |
|
| 101 |
+ if (ret < 0) {
|
|
| 102 |
+ av_free_packet(pkt); |
|
| 103 |
+ return ret; |
|
| 104 |
+ } |
|
| 105 |
+ } |
|
| 106 |
+ |
|
| 107 |
+ return 0; |
|
| 108 |
+} |
|
| 109 |
+ |
|
| 110 |
+AVInputFormat ff_dfa_demuxer = {
|
|
| 111 |
+ "dfa", |
|
| 112 |
+ NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
|
|
| 113 |
+ 0, |
|
| 114 |
+ dfa_probe, |
|
| 115 |
+ dfa_read_header, |
|
| 116 |
+ dfa_read_packet, |
|
| 117 |
+ .flags = AVFMT_GENERIC_INDEX, |
|
| 118 |
+}; |
| ... | ... |
@@ -24,7 +24,7 @@ |
| 24 | 24 |
#include "libavutil/avutil.h" |
| 25 | 25 |
|
| 26 | 26 |
#define LIBAVFORMAT_VERSION_MAJOR 52 |
| 27 |
-#define LIBAVFORMAT_VERSION_MINOR 103 |
|
| 27 |
+#define LIBAVFORMAT_VERSION_MINOR 104 |
|
| 28 | 28 |
#define LIBAVFORMAT_VERSION_MICRO 0 |
| 29 | 29 |
|
| 30 | 30 |
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |