avcodec/decode: Set KEY flag+pict_type generically for intra-only codecs
This commit is the analog of 3f11eac757
for decoding: It sets the AV_FRAME_FLAG_KEY and (for video decoders)
also pict_type to AV_PICTURE_TYPE_I. It furthermore stops setting
audio frames as always being key frames -- it is wrong for e.g.
TrueHD/MLP. The latter also affects TAK and DFPWM.
The change already improves output for several decoders where
it has been forgotten to set e.g. pict_type like speedhq, wnv1
or tiff. The latter is the reason for the change to the exif-image-tiff
FATE test reference file.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -57,6 +57,20 @@
|
|||||||
typedef struct DecodeContext {
|
typedef struct DecodeContext {
|
||||||
AVCodecInternal avci;
|
AVCodecInternal avci;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats
|
||||||
|
* (those whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set)
|
||||||
|
* to set the flag generically.
|
||||||
|
*/
|
||||||
|
int intra_only_flag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is set to AV_PICTURE_TYPE_I for intra only video decoders
|
||||||
|
* and to AV_PICTURE_TYPE_NONE for other decoders. It is used to set
|
||||||
|
* the AVFrame's pict_type before the decoder receives it.
|
||||||
|
*/
|
||||||
|
enum AVPictureType initial_pict_type;
|
||||||
|
|
||||||
/* to prevent infinite loop on errors when draining */
|
/* to prevent infinite loop on errors when draining */
|
||||||
int nb_draining_errors;
|
int nb_draining_errors;
|
||||||
|
|
||||||
@ -382,6 +396,7 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca
|
|||||||
static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
|
static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
|
||||||
{
|
{
|
||||||
AVCodecInternal *avci = avctx->internal;
|
AVCodecInternal *avci = avctx->internal;
|
||||||
|
DecodeContext *dc = decode_ctx(avci);
|
||||||
AVPacket *const pkt = avci->in_pkt;
|
AVPacket *const pkt = avci->in_pkt;
|
||||||
const FFCodec *const codec = ffcodec(avctx->codec);
|
const FFCodec *const codec = ffcodec(avctx->codec);
|
||||||
int got_frame, consumed;
|
int got_frame, consumed;
|
||||||
@ -409,6 +424,8 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
|
|||||||
if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
|
if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
|
||||||
consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
|
consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
|
||||||
} else {
|
} else {
|
||||||
|
frame->pict_type = dc->initial_pict_type;
|
||||||
|
frame->flags |= dc->intra_only_flag;
|
||||||
consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
|
consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
|
||||||
|
|
||||||
if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
|
if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
|
||||||
@ -598,6 +615,8 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
|
|||||||
av_assert0(!frame->buf[0]);
|
av_assert0(!frame->buf[0]);
|
||||||
|
|
||||||
if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
|
if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
|
||||||
|
frame->pict_type = dc->initial_pict_type;
|
||||||
|
frame->flags |= dc->intra_only_flag;
|
||||||
ret = codec->cb.receive_frame(avctx, frame);
|
ret = codec->cb.receive_frame(avctx, frame);
|
||||||
emms_c();
|
emms_c();
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
@ -627,8 +646,7 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
|
|||||||
frame->width = avctx->width;
|
frame->width = avctx->width;
|
||||||
if (!frame->height)
|
if (!frame->height)
|
||||||
frame->height = avctx->height;
|
frame->height = avctx->height;
|
||||||
} else
|
}
|
||||||
frame->flags |= AV_FRAME_FLAG_KEY;
|
|
||||||
|
|
||||||
ret = fill_frame_props(avctx, frame);
|
ret = fill_frame_props(avctx, frame);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -1794,6 +1812,13 @@ int ff_decode_preinit(AVCodecContext *avctx)
|
|||||||
DecodeContext *dc = decode_ctx(avci);
|
DecodeContext *dc = decode_ctx(avci);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
dc->initial_pict_type = AV_PICTURE_TYPE_NONE;
|
||||||
|
if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) {
|
||||||
|
dc->intra_only_flag = AV_FRAME_FLAG_KEY;
|
||||||
|
if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
|
||||||
|
dc->initial_pict_type = AV_PICTURE_TYPE_I;
|
||||||
|
}
|
||||||
|
|
||||||
/* if the decoder init function was already called previously,
|
/* if the decoder init function was already called previously,
|
||||||
* free the already allocated subtitle_header before overwriting it */
|
* free the already allocated subtitle_header before overwriting it */
|
||||||
av_freep(&avctx->subtitle_header);
|
av_freep(&avctx->subtitle_header);
|
||||||
|
@ -22,13 +22,11 @@
|
|||||||
* @see doc/multithreading.txt
|
* @see doc/multithreading.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "avcodec_internal.h"
|
#include "avcodec_internal.h"
|
||||||
|
#include "codec_desc.h"
|
||||||
#include "codec_internal.h"
|
#include "codec_internal.h"
|
||||||
#include "decode.h"
|
#include "decode.h"
|
||||||
#include "hwaccel_internal.h"
|
#include "hwaccel_internal.h"
|
||||||
@ -108,6 +106,10 @@ typedef struct PerThreadContext {
|
|||||||
int hwaccel_threadsafe;
|
int hwaccel_threadsafe;
|
||||||
|
|
||||||
atomic_int debug_threads; ///< Set if the FF_DEBUG_THREADS option is set.
|
atomic_int debug_threads; ///< Set if the FF_DEBUG_THREADS option is set.
|
||||||
|
|
||||||
|
/// The following two fields have the same semantics as the DecodeContext field
|
||||||
|
int intra_only_flag;
|
||||||
|
enum AVPictureType initial_pict_type;
|
||||||
} PerThreadContext;
|
} PerThreadContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -220,6 +222,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
|
|||||||
|
|
||||||
av_frame_unref(p->frame);
|
av_frame_unref(p->frame);
|
||||||
p->got_frame = 0;
|
p->got_frame = 0;
|
||||||
|
p->frame->pict_type = p->initial_pict_type;
|
||||||
|
p->frame->flags |= p->intra_only_flag;
|
||||||
p->result = codec->cb.decode(avctx, p->frame, &p->got_frame, p->avpkt);
|
p->result = codec->cb.decode(avctx, p->frame, &p->got_frame, p->avpkt);
|
||||||
|
|
||||||
if ((p->result < 0 || !p->got_frame) && p->frame->buf[0])
|
if ((p->result < 0 || !p->got_frame) && p->frame->buf[0])
|
||||||
@ -763,6 +767,13 @@ static av_cold int init_thread(PerThreadContext *p, int *threads_to_free,
|
|||||||
AVCodecContext *copy;
|
AVCodecContext *copy;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
p->initial_pict_type = AV_PICTURE_TYPE_NONE;
|
||||||
|
if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) {
|
||||||
|
p->intra_only_flag = AV_FRAME_FLAG_KEY;
|
||||||
|
if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
|
||||||
|
p->initial_pict_type = AV_PICTURE_TYPE_I;
|
||||||
|
}
|
||||||
|
|
||||||
atomic_init(&p->state, STATE_INPUT_READY);
|
atomic_init(&p->state, STATE_INPUT_READY);
|
||||||
|
|
||||||
copy = av_memdup(avctx, sizeof(*avctx));
|
copy = av_memdup(avctx, sizeof(*avctx));
|
||||||
|
@ -20,7 +20,7 @@ crop_left=0
|
|||||||
crop_right=0
|
crop_right=0
|
||||||
pix_fmt=rgb24
|
pix_fmt=rgb24
|
||||||
sample_aspect_ratio=1:1
|
sample_aspect_ratio=1:1
|
||||||
pict_type=?
|
pict_type=I
|
||||||
interlaced_frame=0
|
interlaced_frame=0
|
||||||
top_field_first=0
|
top_field_first=0
|
||||||
repeat_pict=0
|
repeat_pict=0
|
||||||
|
Reference in New Issue
Block a user