Mercurial > libavcodec.hg
comparison utils.c @ 9355:54bc8a2727b0 libavcodec
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
AVPacket argument rather than a const uint8_t *buf + int buf_size. This allows
passing of packet-specific flags from demuxer to decoder, such as the keyframe
flag, which appears necessary to playback corePNG P-frames.
Patch by Thilo Borgmann thilo.borgmann googlemail com, see also the thread
"Google Summer of Code participation" on the mailinglist.
| author | rbultje |
|---|---|
| date | Tue, 07 Apr 2009 15:59:50 +0000 |
| parents | 6a1ad1d933cd |
| children | d31c367da415 |
comparison
equal
deleted
inserted
replaced
| 9354:174309386512 | 9355:54bc8a2727b0 |
|---|---|
| 522 ret = avctx->codec->encode(avctx, buf, buf_size, sub); | 522 ret = avctx->codec->encode(avctx, buf, buf_size, sub); |
| 523 avctx->frame_number++; | 523 avctx->frame_number++; |
| 524 return ret; | 524 return ret; |
| 525 } | 525 } |
| 526 | 526 |
| 527 #if LIBAVCODEC_VERSION_MAJOR < 53 | |
| 527 int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, | 528 int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, |
| 528 int *got_picture_ptr, | 529 int *got_picture_ptr, |
| 529 const uint8_t *buf, int buf_size) | 530 const uint8_t *buf, int buf_size) |
| 530 { | 531 { |
| 532 AVPacket avpkt; | |
| 533 av_init_packet(&avpkt); | |
| 534 avpkt.data = buf; | |
| 535 avpkt.size = buf_size; | |
| 536 | |
| 537 return avcodec_decode_video2(avctx, picture, got_picture_ptr, &avpkt); | |
| 538 } | |
| 539 #endif | |
| 540 | |
| 541 int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, | |
| 542 int *got_picture_ptr, | |
| 543 AVPacket *avpkt) | |
| 544 { | |
| 531 int ret; | 545 int ret; |
| 532 | 546 |
| 533 *got_picture_ptr= 0; | 547 *got_picture_ptr= 0; |
| 534 if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)) | 548 if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)) |
| 535 return -1; | 549 return -1; |
| 536 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){ | 550 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){ |
| 537 ret = avctx->codec->decode(avctx, picture, got_picture_ptr, | 551 ret = avctx->codec->decode(avctx, picture, got_picture_ptr, |
| 538 buf, buf_size); | 552 avpkt); |
| 539 | 553 |
| 540 emms_c(); //needed to avoid an emms_c() call before every return; | 554 emms_c(); //needed to avoid an emms_c() call before every return; |
| 541 | 555 |
| 542 if (*got_picture_ptr) | 556 if (*got_picture_ptr) |
| 543 avctx->frame_number++; | 557 avctx->frame_number++; |
| 545 ret= 0; | 559 ret= 0; |
| 546 | 560 |
| 547 return ret; | 561 return ret; |
| 548 } | 562 } |
| 549 | 563 |
| 564 #if LIBAVCODEC_VERSION_MAJOR < 53 | |
| 550 int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, | 565 int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, |
| 551 int *frame_size_ptr, | 566 int *frame_size_ptr, |
| 552 const uint8_t *buf, int buf_size) | 567 const uint8_t *buf, int buf_size) |
| 553 { | 568 { |
| 569 AVPacket avpkt; | |
| 570 av_init_packet(&avpkt); | |
| 571 avpkt.data = buf; | |
| 572 avpkt.size = buf_size; | |
| 573 | |
| 574 return avcodec_decode_audio3(avctx, samples, frame_size_ptr, &avpkt); | |
| 575 } | |
| 576 #endif | |
| 577 | |
| 578 int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, | |
| 579 int *frame_size_ptr, | |
| 580 AVPacket *avpkt) | |
| 581 { | |
| 554 int ret; | 582 int ret; |
| 555 | 583 |
| 556 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){ | 584 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){ |
| 557 //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough | 585 //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough |
| 558 if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){ | 586 if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){ |
| 559 av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n"); | 587 av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n"); |
| 560 return -1; | 588 return -1; |
| 561 } | 589 } |
| 563 *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){ | 591 *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){ |
| 564 av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr); | 592 av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr); |
| 565 return -1; | 593 return -1; |
| 566 } | 594 } |
| 567 | 595 |
| 568 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, | 596 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, avpkt); |
| 569 buf, buf_size); | |
| 570 avctx->frame_number++; | 597 avctx->frame_number++; |
| 571 }else{ | 598 }else{ |
| 572 ret= 0; | 599 ret= 0; |
| 573 *frame_size_ptr=0; | 600 *frame_size_ptr=0; |
| 574 } | 601 } |
| 575 return ret; | 602 return ret; |
| 576 } | 603 } |
| 577 | 604 |
| 605 #if LIBAVCODEC_VERSION_MAJOR < 53 | |
| 578 int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub, | 606 int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub, |
| 579 int *got_sub_ptr, | 607 int *got_sub_ptr, |
| 580 const uint8_t *buf, int buf_size) | 608 const uint8_t *buf, int buf_size) |
| 581 { | 609 { |
| 610 AVPacket avpkt; | |
| 611 av_init_packet(&avpkt); | |
| 612 avpkt.data = buf; | |
| 613 avpkt.size = buf_size; | |
| 614 | |
| 615 return avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, &avpkt); | |
| 616 } | |
| 617 #endif | |
| 618 | |
| 619 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, | |
| 620 int *got_sub_ptr, | |
| 621 AVPacket *avpkt) | |
| 622 { | |
| 582 int ret; | 623 int ret; |
| 583 | 624 |
| 584 *got_sub_ptr = 0; | 625 *got_sub_ptr = 0; |
| 585 ret = avctx->codec->decode(avctx, sub, got_sub_ptr, | 626 ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt); |
| 586 buf, buf_size); | |
| 587 if (*got_sub_ptr) | 627 if (*got_sub_ptr) |
| 588 avctx->frame_number++; | 628 avctx->frame_number++; |
| 589 return ret; | 629 return ret; |
| 590 } | 630 } |
| 591 | 631 |
