comparison vc1.c @ 4465:5c94205a4730 libavcodec

VC-1 parser
author kostya
date Sat, 03 Feb 2007 06:39:50 +0000
parents b619aebd8469
children 1dea76bf254f
comparison
equal deleted inserted replaced
4464:b619aebd8469 4465:5c94205a4730
4472 vc1_decode_end, 4472 vc1_decode_end,
4473 vc1_decode_frame, 4473 vc1_decode_frame,
4474 CODEC_CAP_DELAY, 4474 CODEC_CAP_DELAY,
4475 NULL 4475 NULL
4476 }; 4476 };
4477
4478 #ifdef CONFIG_VC1_PARSER
4479 /**
4480 * finds the end of the current frame in the bitstream.
4481 * @return the position of the first byte of the next frame, or -1
4482 */
4483 static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf,
4484 int buf_size) {
4485 int pic_found, i;
4486 uint32_t state;
4487
4488 pic_found= pc->frame_start_found;
4489 state= pc->state;
4490
4491 i=0;
4492 if(!pic_found){
4493 for(i=0; i<buf_size; i++){
4494 state= (state<<8) | buf[i];
4495 if(state == VC1_CODE_FRAME || state == VC1_CODE_FIELD){
4496 i++;
4497 pic_found=1;
4498 break;
4499 }
4500 }
4501 }
4502
4503 if(pic_found){
4504 /* EOF considered as end of frame */
4505 if (buf_size == 0)
4506 return 0;
4507 for(; i<buf_size; i++){
4508 state= (state<<8) | buf[i];
4509 if(IS_MARKER(state) && state != VC1_CODE_FIELD && state != VC1_CODE_SLICE){
4510 pc->frame_start_found=0;
4511 pc->state=-1;
4512 return i-3;
4513 }
4514 }
4515 }
4516 pc->frame_start_found= pic_found;
4517 pc->state= state;
4518 return END_NOT_FOUND;
4519 }
4520
4521 static int vc1_parse(AVCodecParserContext *s,
4522 AVCodecContext *avctx,
4523 uint8_t **poutbuf, int *poutbuf_size,
4524 const uint8_t *buf, int buf_size)
4525 {
4526 ParseContext *pc = s->priv_data;
4527 int next;
4528
4529 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
4530 next= buf_size;
4531 }else{
4532 next= vc1_find_frame_end(pc, buf, buf_size);
4533
4534 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
4535 *poutbuf = NULL;
4536 *poutbuf_size = 0;
4537 return buf_size;
4538 }
4539 }
4540 *poutbuf = (uint8_t *)buf;
4541 *poutbuf_size = buf_size;
4542 return next;
4543 }
4544
4545 int vc1_split(AVCodecContext *avctx,
4546 const uint8_t *buf, int buf_size)
4547 {
4548 int i;
4549 uint32_t state= -1;
4550
4551 for(i=0; i<buf_size; i++){
4552 state= (state<<8) | buf[i];
4553 if(IS_MARKER(state) && state != VC1_CODE_SEQHDR && state != VC1_CODE_ENTRYPOINT)
4554 return i-3;
4555 }
4556 return 0;
4557 }
4558
4559 AVCodecParser vc1_parser = {
4560 { CODEC_ID_VC1 },
4561 sizeof(ParseContext1),
4562 NULL,
4563 vc1_parse,
4564 ff_parse1_close,
4565 vc1_split,
4566 };
4567 #endif /* CONFIG_VC1_PARSER */