Mercurial > libavcodec.hg
comparison cavs.c @ 4177:127d84a4c8e0 libavcodec
move all cavs-parsing to cavs.c
This should help building parser without decoder
author | stefang |
---|---|
date | Sun, 12 Nov 2006 20:18:07 +0000 |
parents | 23da44e8fd05 |
children | f623a9939995 |
comparison
equal
deleted
inserted
replaced
4176:23da44e8fd05 | 4177:127d84a4c8e0 |
---|---|
29 #include "bitstream.h" | 29 #include "bitstream.h" |
30 #include "golomb.h" | 30 #include "golomb.h" |
31 #include "mpegvideo.h" | 31 #include "mpegvideo.h" |
32 #include "cavsdata.h" | 32 #include "cavsdata.h" |
33 | 33 |
34 #ifdef CONFIG_CAVS_DECODER | |
34 typedef struct { | 35 typedef struct { |
35 MpegEncContext s; | 36 MpegEncContext s; |
36 Picture picture; ///< currently decoded frame | 37 Picture picture; ///< currently decoded frame |
37 Picture DPB[2]; ///< reference frames | 38 Picture DPB[2]; ///< reference frames |
38 int dist[2]; ///< temporal distances from current frame to ref frames | 39 int dist[2]; ///< temporal distances from current frame to ref frames |
1316 if(!h->top_qp) | 1317 if(!h->top_qp) |
1317 init_top_lines(h); | 1318 init_top_lines(h); |
1318 return 0; | 1319 return 0; |
1319 } | 1320 } |
1320 | 1321 |
1321 /** | |
1322 * finds the end of the current frame in the bitstream. | |
1323 * @return the position of the first byte of the next frame, or -1 | |
1324 */ | |
1325 int ff_cavs_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) { | |
1326 int pic_found, i; | |
1327 uint32_t state; | |
1328 | |
1329 pic_found= pc->frame_start_found; | |
1330 state= pc->state; | |
1331 | |
1332 i=0; | |
1333 if(!pic_found){ | |
1334 for(i=0; i<buf_size; i++){ | |
1335 state= (state<<8) | buf[i]; | |
1336 if(state == PIC_I_START_CODE || state == PIC_PB_START_CODE){ | |
1337 i++; | |
1338 pic_found=1; | |
1339 break; | |
1340 } | |
1341 } | |
1342 } | |
1343 | |
1344 if(pic_found){ | |
1345 /* EOF considered as end of frame */ | |
1346 if (buf_size == 0) | |
1347 return 0; | |
1348 for(; i<buf_size; i++){ | |
1349 state= (state<<8) | buf[i]; | |
1350 if((state&0xFFFFFF00) == 0x100){ | |
1351 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ | |
1352 pc->frame_start_found=0; | |
1353 pc->state=-1; | |
1354 return i-3; | |
1355 } | |
1356 } | |
1357 } | |
1358 } | |
1359 pc->frame_start_found= pic_found; | |
1360 pc->state= state; | |
1361 return END_NOT_FOUND; | |
1362 } | |
1363 | |
1364 void ff_cavs_flush(AVCodecContext * avctx) { | 1322 void ff_cavs_flush(AVCodecContext * avctx) { |
1365 AVSContext *h = avctx->priv_data; | 1323 AVSContext *h = avctx->priv_data; |
1366 h->got_keyframe = 0; | 1324 h->got_keyframe = 0; |
1367 } | 1325 } |
1368 | 1326 |
1498 cavs_decode_end, | 1456 cavs_decode_end, |
1499 cavs_decode_frame, | 1457 cavs_decode_frame, |
1500 CODEC_CAP_DR1 | CODEC_CAP_DELAY, | 1458 CODEC_CAP_DR1 | CODEC_CAP_DELAY, |
1501 .flush= ff_cavs_flush, | 1459 .flush= ff_cavs_flush, |
1502 }; | 1460 }; |
1461 #endif /* CONFIG_CAVS_DECODER */ | |
1462 | |
1463 #ifdef CONFIG_CAVSVIDEO_PARSER | |
1464 /** | |
1465 * finds the end of the current frame in the bitstream. | |
1466 * @return the position of the first byte of the next frame, or -1 | |
1467 */ | |
1468 static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf, | |
1469 int buf_size) { | |
1470 int pic_found, i; | |
1471 uint32_t state; | |
1472 | |
1473 pic_found= pc->frame_start_found; | |
1474 state= pc->state; | |
1475 | |
1476 i=0; | |
1477 if(!pic_found){ | |
1478 for(i=0; i<buf_size; i++){ | |
1479 state= (state<<8) | buf[i]; | |
1480 if(state == PIC_I_START_CODE || state == PIC_PB_START_CODE){ | |
1481 i++; | |
1482 pic_found=1; | |
1483 break; | |
1484 } | |
1485 } | |
1486 } | |
1487 | |
1488 if(pic_found){ | |
1489 /* EOF considered as end of frame */ | |
1490 if (buf_size == 0) | |
1491 return 0; | |
1492 for(; i<buf_size; i++){ | |
1493 state= (state<<8) | buf[i]; | |
1494 if((state&0xFFFFFF00) == 0x100){ | |
1495 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ | |
1496 pc->frame_start_found=0; | |
1497 pc->state=-1; | |
1498 return i-3; | |
1499 } | |
1500 } | |
1501 } | |
1502 } | |
1503 pc->frame_start_found= pic_found; | |
1504 pc->state= state; | |
1505 return END_NOT_FOUND; | |
1506 } | |
1507 | |
1508 static int cavsvideo_parse(AVCodecParserContext *s, | |
1509 AVCodecContext *avctx, | |
1510 uint8_t **poutbuf, int *poutbuf_size, | |
1511 const uint8_t *buf, int buf_size) | |
1512 { | |
1513 ParseContext *pc = s->priv_data; | |
1514 int next; | |
1515 | |
1516 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ | |
1517 next= buf_size; | |
1518 }else{ | |
1519 next= cavs_find_frame_end(pc, buf, buf_size); | |
1520 | |
1521 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { | |
1522 *poutbuf = NULL; | |
1523 *poutbuf_size = 0; | |
1524 return buf_size; | |
1525 } | |
1526 } | |
1527 *poutbuf = (uint8_t *)buf; | |
1528 *poutbuf_size = buf_size; | |
1529 return next; | |
1530 } | |
1531 | |
1532 AVCodecParser cavsvideo_parser = { | |
1533 { CODEC_ID_CAVS }, | |
1534 sizeof(ParseContext1), | |
1535 NULL, | |
1536 cavsvideo_parse, | |
1537 ff_parse1_close, | |
1538 ff_mpeg4video_split, | |
1539 }; | |
1540 #endif /* CONFIG_CAVSVIDEO_PARSER */ |