| @@ -57,6 +57,20 @@ · 56 unmodified lines |
| 57 | 57 | typedef struct DecodeContext { |
| 58 | 58 | AVCodecInternal avci; |
| 59 | 59 | |
| 60 | + /** |
| 61 | + * This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats |
| 62 | + * (those whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set) |
| 63 | + * to set the flag generically. |
| 64 | + */ |
| 65 | + int intra_only_flag; |
| 66 | + |
| 67 | + /** |
| 68 | + * This is set to AV_PICTURE_TYPE_I for intra only video decoders |
| 69 | + * and to AV_PICTURE_TYPE_NONE for other decoders. It is used to set |
| 70 | + * the AVFrame's pict_type before the decoder receives it. |
| 71 | + */ |
| 72 | + enum AVPictureType initial_pict_type; |
| 73 | + |
| 60 | 74 | /* to prevent infinite loop on errors when draining */ |
| 61 | 75 | int nb_draining_errors; |
| 62 | 76 | |
| @@ -382,6 +396,7 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca · 319 unmodified lines |
| 382 | 396 | static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples) |
| 383 | 397 | { |
| 384 | 398 | AVCodecInternal *avci = avctx->internal; |
| 399 | + DecodeContext *dc = decode_ctx(avci); |
| 385 | 400 | AVPacket *const pkt = avci->in_pkt; |
| 386 | 401 | const FFCodec *const codec = ffcodec(avctx->codec); |
| 387 | 402 | int got_frame, consumed; |
| @@ -409,6 +424,8 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, · 21 unmodified lines |
| 409 | 424 | if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) { |
| 410 | 425 | consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt); |
| 411 | 426 | } else { |
| 427 | + frame->pict_type = dc->initial_pict_type; |
| 428 | + frame->flags |= dc->intra_only_flag; |
| 412 | 429 | consumed = codec->cb.decode(avctx, frame, &got_frame, pkt); |
| 413 | 430 | |
| 414 | 431 | if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)) |
| @@ -598,6 +615,8 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 183 unmodified lines |
| 598 | 615 | av_assert0(!frame->buf[0]); |
| 599 | 616 | |
| 600 | 617 | if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) { |
| 618 | + frame->pict_type = dc->initial_pict_type; |
| 619 | + frame->flags |= dc->intra_only_flag; |
| 601 | 620 | ret = codec->cb.receive_frame(avctx, frame); |
| 602 | 621 | emms_c(); |
| 603 | 622 | if (!ret) { |
| @@ -627,8 +646,7 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 23 unmodified lines |
| 627 | 646 | frame->width = avctx->width; |
| 628 | 647 | if (!frame->height) |
| 629 | 648 | frame->height = avctx->height; |
| 630 | | − } else |
| 631 | | − frame->flags |= AV_FRAME_FLAG_KEY; |
| 649 | + } |
| 632 | 650 | |
| 633 | 651 | ret = fill_frame_props(avctx, frame); |
| 634 | 652 | if (ret < 0) { |
| @@ -1794,6 +1812,13 @@ int ff_decode_preinit(AVCodecContext *avctx) · 1159 unmodified lines |
| 1794 | 1812 | DecodeContext *dc = decode_ctx(avci); |
| 1795 | 1813 | int ret = 0; |
| 1796 | 1814 | |
| 1815 | + dc->initial_pict_type = AV_PICTURE_TYPE_NONE; |
| 1816 | + if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) { |
| 1817 | + dc->intra_only_flag = AV_FRAME_FLAG_KEY; |
| 1818 | + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) |
| 1819 | + dc->initial_pict_type = AV_PICTURE_TYPE_I; |
| 1820 | + } |
| 1821 | + |
| 1797 | 1822 | /* if the decoder init function was already called previously, |
| 1798 | 1823 | * free the already allocated subtitle_header before overwriting it */ |
| 1799 | 1824 | av_freep(&avctx->subtitle_header); |