* The core of the receive_frame_wrapper for the decoders implementing * the simple API. Certain decoders might consume partial packets without * returning any output, so this function needs to be called in a loop until it * returns EAGAIN. **/
| 415 | * returns EAGAIN. |
| 416 | **/ |
| 417 | static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples) |
| 418 | { |
| 419 | AVCodecInternal *avci = avctx->internal; |
| 420 | DecodeContext *dc = decode_ctx(avci); |
| 421 | AVPacket *const pkt = avci->in_pkt; |
| 422 | const FFCodec *const codec = ffcodec(avctx->codec); |
| 423 | int got_frame, consumed; |
| 424 | int ret; |
| 425 | |
| 426 | if (!pkt->data && !avci->draining) { |
| 427 | av_packet_unref(pkt); |
| 428 | ret = ff_decode_get_packet(avctx, pkt); |
| 429 | if (ret < 0 && ret != AVERROR_EOF) |
| 430 | return ret; |
| 431 | } |
| 432 | |
| 433 | // Some codecs (at least wma lossless) will crash when feeding drain packets |
| 434 | // after EOF was signaled. |
| 435 | if (avci->draining_done) |
| 436 | return AVERROR_EOF; |
| 437 | |
| 438 | if (!pkt->data && |
| 439 | !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) |
| 440 | return AVERROR_EOF; |
| 441 | |
| 442 | got_frame = 0; |
| 443 | |
| 444 | frame->pict_type = dc->initial_pict_type; |
| 445 | frame->flags |= dc->intra_only_flag; |
| 446 | consumed = codec->cb.decode(avctx, frame, &got_frame, pkt); |
| 447 | |
| 448 | if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)) |
| 449 | frame->pkt_dts = pkt->dts; |
| 450 | emms_c(); |
| 451 | |
| 452 | if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { |
| 453 | ret = (!got_frame || frame->flags & AV_FRAME_FLAG_DISCARD) |
| 454 | ? AVERROR(EAGAIN) |
| 455 | : 0; |
| 456 | } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { |
| 457 | ret = !got_frame ? AVERROR(EAGAIN) |
| 458 | : discard_samples(avctx, frame, discarded_samples); |
| 459 | } else |
| 460 | av_assert0(0); |
| 461 | |
| 462 | if (ret == AVERROR(EAGAIN)) |
| 463 | av_frame_unref(frame); |
| 464 | |
| 465 | // FF_CODEC_CB_TYPE_DECODE decoders must not return AVERROR EAGAIN |
| 466 | // code later will add AVERROR(EAGAIN) to a pointer |
| 467 | av_assert0(consumed != AVERROR(EAGAIN)); |
| 468 | if (consumed < 0) |
| 469 | ret = consumed; |
| 470 | if (consumed >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO) |
| 471 | consumed = pkt->size; |
| 472 | |
| 473 | if (!ret) |
| 474 | av_assert0(frame->buf[0]); |
no test coverage detected