comparison dca.c @ 4899:e153b9ff47d3 libavcodec

Move dca parser to its own file.
author diego
date Thu, 03 May 2007 23:50:24 +0000
parents bcff4564b786
children 777f250df232
comparison
equal deleted inserted replaced
4898:3df69e140c33 4899:e153b9ff47d3
33 #include "avcodec.h" 33 #include "avcodec.h"
34 #include "dsputil.h" 34 #include "dsputil.h"
35 #include "bitstream.h" 35 #include "bitstream.h"
36 #include "dcadata.h" 36 #include "dcadata.h"
37 #include "dcahuff.h" 37 #include "dcahuff.h"
38 #include "parser.h" 38 #include "dca.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 //@}
47 39
48 //#define TRACE 40 //#define TRACE
49 41
50 #define DCA_PRIM_CHANNELS_MAX (5) 42 #define DCA_PRIM_CHANNELS_MAX (5)
51 #define DCA_SUBBANDS (32) 43 #define DCA_SUBBANDS (32)
1253 .id = CODEC_ID_DTS, 1245 .id = CODEC_ID_DTS,
1254 .priv_data_size = sizeof(DCAContext), 1246 .priv_data_size = sizeof(DCAContext),
1255 .init = dca_decode_init, 1247 .init = dca_decode_init,
1256 .decode = dca_decode_frame, 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 */