Originally committed as revision 8881 to svn://svn.ffmpeg.org/ffmpeg/trunk
Unified · Split
| @@ -276,6 +276,7 @@ OBJS-$(CONFIG_XVID) += xvidff.o xvid_rc.o · 275 unmodified lines | ||
| 276 | 276 | OBJS-$(CONFIG_AAC_PARSER) += parser.o |
| 277 | 277 | OBJS-$(CONFIG_AC3_PARSER) += parser.o ac3tab.o |
| 278 | 278 | OBJS-$(CONFIG_CAVSVIDEO_PARSER) += cavs.o parser.o |
| 279 | +OBJS-$(CONFIG_DCA_PARSER) += dca_parser.o | |
| 279 | 280 | OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsubdec.o |
| 280 | 281 | OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsubdec.o |
| 281 | 282 | OBJS-$(CONFIG_H261_PARSER) += h261.o |
| @@ -35,15 +35,7 @@ · 34 unmodified lines | ||
| 35 | 35 | #include "bitstream.h" |
| 36 | 36 | #include "dcadata.h" |
| 37 | 37 | #include "dcahuff.h" |
| 38 | −#include "parser.h" | |
| 39 | − | |
| 40 | −/** DCA syncwords, also used for bitstream type detection */ | |
| 41 | −//@{ | |
| 42 | −#define DCA_MARKER_RAW_BE 0x7FFE8001 | |
| 43 | −#define DCA_MARKER_RAW_LE 0xFE7F0180 | |
| 44 | −#define DCA_MARKER_14B_BE 0x1FFFE800 | |
| 45 | −#define DCA_MARKER_14B_LE 0xFF1F00E8 | |
| 46 | −//@} | |
| 38 | +#include "dca.h" | |
| 47 | 39 | |
| 48 | 40 | //#define TRACE |
| 49 | 41 | |
| @@ -1255,102 +1247,3 @@ AVCodec dca_decoder = { · 1205 unmodified lines | ||
| 1255 | 1247 | .init = dca_decode_init, |
| 1256 | 1248 | .decode = dca_decode_frame, |
| 1257 | 1249 | }; |
| 1258 | − | |
| 1259 | −#ifdef CONFIG_DCA_PARSER | |
| 1260 | − | |
| 1261 | −typedef struct DCAParseContext { | |
| 1262 | − ParseContext pc; | |
| 1263 | − uint32_t lastmarker; | |
| 1264 | −} DCAParseContext; | |
| 1265 | − | |
| 1266 | −#define IS_MARKER(state, i, buf, buf_size) \ | |
| 1267 | − ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \ | |
| 1268 | − || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \ | |
| 1269 | − || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE) | |
| 1270 | − | |
| 1271 | −/** | |
| 1272 | − * finds the end of the current frame in the bitstream. | |
| 1273 | − * @return the position of the first byte of the next frame, or -1 | |
| 1274 | − */ | |
| 1275 | −static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf, | |
| 1276 | − int buf_size) | |
| 1277 | −{ | |
| 1278 | − int start_found, i; | |
| 1279 | − uint32_t state; | |
| 1280 | − ParseContext *pc = &pc1->pc; | |
| 1281 | − | |
| 1282 | − start_found = pc->frame_start_found; | |
| 1283 | − state = pc->state; | |
| 1284 | − | |
| 1285 | − i = 0; | |
| 1286 | − if (!start_found) { | |
| 1287 | − for (i = 0; i < buf_size; i++) { | |
| 1288 | − state = (state << 8) | buf[i]; | |
| 1289 | − if (IS_MARKER(state, i, buf, buf_size)) { | |
| 1290 | − if (pc1->lastmarker && state == pc1->lastmarker) { | |
| 1291 | − start_found = 1; | |
| 1292 | − break; | |
| 1293 | − } else if (!pc1->lastmarker) { | |
| 1294 | − start_found = 1; | |
| 1295 | − pc1->lastmarker = state; | |
| 1296 | − break; | |
| 1297 | − } | |
| 1298 | − } | |
| 1299 | − } | |
| 1300 | − } | |
| 1301 | − if (start_found) { | |
| 1302 | − for (; i < buf_size; i++) { | |
| 1303 | − state = (state << 8) | buf[i]; | |
| 1304 | − if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) { | |
| 1305 | − pc->frame_start_found = 0; | |
| 1306 | − pc->state = -1; | |
| 1307 | − return i - 3; | |
| 1308 | − } | |
| 1309 | − } | |
| 1310 | − } | |
| 1311 | − pc->frame_start_found = start_found; | |
| 1312 | − pc->state = state; | |
| 1313 | − return END_NOT_FOUND; | |
| 1314 | −} | |
| 1315 | − | |
| 1316 | −static int dca_parse_init(AVCodecParserContext * s) | |
| 1317 | −{ | |
| 1318 | − DCAParseContext *pc1 = s->priv_data; | |
| 1319 | − | |
| 1320 | − pc1->lastmarker = 0; | |
| 1321 | − return 0; | |
| 1322 | −} | |
| 1323 | − | |
| 1324 | −static int dca_parse(AVCodecParserContext * s, | |
| 1325 | − AVCodecContext * avctx, | |
| 1326 | − uint8_t ** poutbuf, int *poutbuf_size, | |
| 1327 | − const uint8_t * buf, int buf_size) | |
| 1328 | −{ | |
| 1329 | − DCAParseContext *pc1 = s->priv_data; | |
| 1330 | − ParseContext *pc = &pc1->pc; | |
| 1331 | − int next; | |
| 1332 | − | |
| 1333 | − if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { | |
| 1334 | − next = buf_size; | |
| 1335 | − } else { | |
| 1336 | − next = dca_find_frame_end(pc1, buf, buf_size); | |
| 1337 | − | |
| 1338 | − if (ff_combine_frame(pc, next, (uint8_t **) & buf, &buf_size) < 0) { | |
| 1339 | − *poutbuf = NULL; | |
| 1340 | − *poutbuf_size = 0; | |
| 1341 | − return buf_size; | |
| 1342 | − } | |
| 1343 | − } | |
| 1344 | − *poutbuf = (uint8_t *) buf; | |
| 1345 | − *poutbuf_size = buf_size; | |
| 1346 | − return next; | |
| 1347 | −} | |
| 1348 | − | |
| 1349 | −AVCodecParser dca_parser = { | |
| 1350 | − {CODEC_ID_DTS}, | |
| 1351 | − sizeof(DCAParseContext), | |
| 1352 | − dca_parse_init, | |
| 1353 | − dca_parse, | |
| 1354 | − ff_parse_close, | |
| 1355 | −}; | |
| 1356 | −#endif /* CONFIG_DCA_PARSER */ | |
| @@ -0,0 +1,29 @@ | ||
| 1 | +/* | |
| 2 | + * DCA compatible decoder | |
| 3 | + * Copyright (C) 2004 Gildas Bazin | |
| 4 | + * Copyright (C) 2004 Benjamin Zores | |
| 5 | + * Copyright (C) 2006 Benjamin Larsson | |
| 6 | + * Copyright (C) 2007 Konstantin Shishkov | |
| 7 | + * | |
| 8 | + * This file is part of FFmpeg. | |
| 9 | + * | |
| 10 | + * FFmpeg is free software; you can redistribute it and/or | |
| 11 | + * modify it under the terms of the GNU Lesser General Public | |
| 12 | + * License as published by the Free Software Foundation; either | |
| 13 | + * version 2.1 of the License, or (at your option) any later version. | |
| 14 | + * | |
| 15 | + * FFmpeg is distributed in the hope that it will be useful, | |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 18 | + * Lesser General Public License for more details. | |
| 19 | + * | |
| 20 | + * You should have received a copy of the GNU Lesser General Public | |
| 21 | + * License along with FFmpeg; if not, write to the Free Software | |
| 22 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 23 | + */ | |
| 24 | + | |
| 25 | +/** DCA syncwords, also used for bitstream type detection */ | |
| 26 | +#define DCA_MARKER_RAW_BE 0x7FFE8001 | |
| 27 | +#define DCA_MARKER_RAW_LE 0xFE7F0180 | |
| 28 | +#define DCA_MARKER_14B_BE 0x1FFFE800 | |
| 29 | +#define DCA_MARKER_14B_LE 0xFF1F00E8 | |
| @@ -0,0 +1,127 @@ | ||
| 1 | +/* | |
| 2 | + * DCA parser | |
| 3 | + * Copyright (C) 2004 Gildas Bazin | |
| 4 | + * Copyright (C) 2004 Benjamin Zores | |
| 5 | + * Copyright (C) 2006 Benjamin Larsson | |
| 6 | + * Copyright (C) 2007 Konstantin Shishkov | |
| 7 | + * | |
| 8 | + * This file is part of FFmpeg. | |
| 9 | + * | |
| 10 | + * FFmpeg is free software; you can redistribute it and/or | |
| 11 | + * modify it under the terms of the GNU Lesser General Public | |
| 12 | + * License as published by the Free Software Foundation; either | |
| 13 | + * version 2.1 of the License, or (at your option) any later version. | |
| 14 | + * | |
| 15 | + * FFmpeg is distributed in the hope that it will be useful, | |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 18 | + * Lesser General Public License for more details. | |
| 19 | + * | |
| 20 | + * You should have received a copy of the GNU Lesser General Public | |
| 21 | + * License along with FFmpeg; if not, write to the Free Software | |
| 22 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 23 | + */ | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * @file dca_parser.c | |
| 27 | + */ | |
| 28 | + | |
| 29 | +#include "avcodec.h" | |
| 30 | +#include "parser.h" | |
| 31 | +#include "dca.h" | |
| 32 | + | |
| 33 | +typedef struct DCAParseContext { | |
| 34 | + ParseContext pc; | |
| 35 | + uint32_t lastmarker; | |
| 36 | +} DCAParseContext; | |
| 37 | + | |
| 38 | +#define IS_MARKER(state, i, buf, buf_size) \ | |
| 39 | + ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \ | |
| 40 | + || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \ | |
| 41 | + || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE) | |
| 42 | + | |
| 43 | +/** | |
| 44 | + * finds the end of the current frame in the bitstream. | |
| 45 | + * @return the position of the first byte of the next frame, or -1 | |
| 46 | + */ | |
| 47 | +static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf, | |
| 48 | + int buf_size) | |
| 49 | +{ | |
| 50 | + int start_found, i; | |
| 51 | + uint32_t state; | |
| 52 | + ParseContext *pc = &pc1->pc; | |
| 53 | + | |
| 54 | + start_found = pc->frame_start_found; | |
| 55 | + state = pc->state; | |
| 56 | + | |
| 57 | + i = 0; | |
| 58 | + if (!start_found) { | |
| 59 | + for (i = 0; i < buf_size; i++) { | |
| 60 | + state = (state << 8) | buf[i]; | |
| 61 | + if (IS_MARKER(state, i, buf, buf_size)) { | |
| 62 | + if (pc1->lastmarker && state == pc1->lastmarker) { | |
| 63 | + start_found = 1; | |
| 64 | + break; | |
| 65 | + } else if (!pc1->lastmarker) { | |
| 66 | + start_found = 1; | |
| 67 | + pc1->lastmarker = state; | |
| 68 | + break; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + } | |
| 72 | + } | |
| 73 | + if (start_found) { | |
| 74 | + for (; i < buf_size; i++) { | |
| 75 | + state = (state << 8) | buf[i]; | |
| 76 | + if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) { | |
| 77 | + pc->frame_start_found = 0; | |
| 78 | + pc->state = -1; | |
| 79 | + return i - 3; | |
| 80 | + } | |
| 81 | + } | |
| 82 | + } | |
| 83 | + pc->frame_start_found = start_found; | |
| 84 | + pc->state = state; | |
| 85 | + return END_NOT_FOUND; | |
| 86 | +} | |
| 87 | + | |
| 88 | +static int dca_parse_init(AVCodecParserContext * s) | |
| 89 | +{ | |
| 90 | + DCAParseContext *pc1 = s->priv_data; | |
| 91 | + | |
| 92 | + pc1->lastmarker = 0; | |
| 93 | + return 0; | |
| 94 | +} | |
| 95 | + | |
| 96 | +static int dca_parse(AVCodecParserContext * s, | |
| 97 | + AVCodecContext * avctx, | |
| 98 | + uint8_t ** poutbuf, int *poutbuf_size, | |
| 99 | + const uint8_t * buf, int buf_size) | |
| 100 | +{ | |
| 101 | + DCAParseContext *pc1 = s->priv_data; | |
| 102 | + ParseContext *pc = &pc1->pc; | |
| 103 | + int next; | |
| 104 | + | |
| 105 | + if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { | |
| 106 | + next = buf_size; | |
| 107 | + } else { | |
| 108 | + next = dca_find_frame_end(pc1, buf, buf_size); | |
| 109 | + | |
| 110 | + if (ff_combine_frame(pc, next, (uint8_t **) & buf, &buf_size) < 0) { | |
| 111 | + *poutbuf = NULL; | |
| 112 | + *poutbuf_size = 0; | |
| 113 | + return buf_size; | |
| 114 | + } | |
| 115 | + } | |
| 116 | + *poutbuf = (uint8_t *) buf; | |
| 117 | + *poutbuf_size = buf_size; | |
| 118 | + return next; | |
| 119 | +} | |
| 120 | + | |
| 121 | +AVCodecParser dca_parser = { | |
| 122 | + {CODEC_ID_DTS}, | |
| 123 | + sizeof(DCAParseContext), | |
| 124 | + dca_parse_init, | |
| 125 | + dca_parse, | |
| 126 | + ff_parse_close, | |
| 127 | +}; | |