Merge commit '549d0bdca5
'
* commit '549d0bdca5
':
decode: be more explicit about storing the last packet properties
Also copy pkt->size in extract_packet_props(), as it's needed for
AVFrame.pkt_size
Merged-by: James Almer <jamrial@gmail.com>
This commit is contained in:
commit
1fd7627770
5 changed files with 41 additions and 25 deletions
|
@ -118,6 +118,19 @@ fail2:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
av_packet_unref(avci->last_pkt_props);
|
||||||
|
if (pkt) {
|
||||||
|
ret = av_packet_copy_props(avci->last_pkt_props, pkt);
|
||||||
|
if (!ret)
|
||||||
|
avci->last_pkt_props->size = pkt->size; // HACK: Needed for ff_init_buffer_info().
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame)
|
static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -394,7 +407,9 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
|
||||||
if ((avctx->coded_width || avctx->coded_height) && av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
|
if ((avctx->coded_width || avctx->coded_height) && av_image_check_size2(avctx->coded_width, avctx->coded_height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
avctx->internal->pkt = avpkt;
|
ret = extract_packet_props(avci, avpkt);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
ret = apply_param_change(avctx, avpkt);
|
ret = apply_param_change(avctx, avpkt);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -412,7 +427,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
avctx->internal->pkt = &tmp;
|
ret = extract_packet_props(avci, &tmp);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
|
if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
|
||||||
ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
|
ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr,
|
||||||
&tmp);
|
&tmp);
|
||||||
|
@ -438,7 +455,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
fail:
|
fail:
|
||||||
emms_c(); //needed to avoid an emms_c() call before every return;
|
emms_c(); //needed to avoid an emms_c() call before every return;
|
||||||
|
|
||||||
avctx->internal->pkt = NULL;
|
|
||||||
#if FF_API_MERGE_SD
|
#if FF_API_MERGE_SD
|
||||||
if (did_split) {
|
if (did_split) {
|
||||||
av_packet_free_side_data(&tmp);
|
av_packet_free_side_data(&tmp);
|
||||||
|
@ -524,7 +540,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
avctx->internal->pkt = &tmp;
|
ret = extract_packet_props(avci, &tmp);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
|
if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
|
||||||
ret = ff_thread_decode_frame(avctx, frame, got_frame_ptr, &tmp);
|
ret = ff_thread_decode_frame(avctx, frame, got_frame_ptr, &tmp);
|
||||||
else {
|
else {
|
||||||
|
@ -548,7 +566,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
frame->sample_rate = avctx->sample_rate;
|
frame->sample_rate = avctx->sample_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
side= av_packet_get_side_data(avctx->internal->pkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size);
|
side= av_packet_get_side_data(avci->last_pkt_props, AV_PKT_DATA_SKIP_SAMPLES, &side_size);
|
||||||
if(side && side_size>=10) {
|
if(side && side_size>=10) {
|
||||||
avctx->internal->skip_samples = AV_RL32(side) * avctx->internal->skip_samples_multiplier;
|
avctx->internal->skip_samples = AV_RL32(side) * avctx->internal->skip_samples_multiplier;
|
||||||
discard_padding = AV_RL32(side + 4);
|
discard_padding = AV_RL32(side + 4);
|
||||||
|
@ -630,7 +648,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fail:
|
fail:
|
||||||
avctx->internal->pkt = NULL;
|
|
||||||
#if FF_API_MERGE_SD
|
#if FF_API_MERGE_SD
|
||||||
if (did_split) {
|
if (did_split) {
|
||||||
av_packet_free_side_data(&tmp);
|
av_packet_free_side_data(&tmp);
|
||||||
|
@ -862,7 +879,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
*got_sub_ptr = 0;
|
*got_sub_ptr = 0;
|
||||||
} else {
|
} else {
|
||||||
avctx->internal->pkt = &pkt_recoded;
|
ret = extract_packet_props(avctx->internal, &pkt_recoded);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
|
if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
|
||||||
sub->pts = av_rescale_q(avpkt->pts,
|
sub->pts = av_rescale_q(avpkt->pts,
|
||||||
|
@ -912,7 +931,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
|
|
||||||
av_packet_unref(&pkt_recoded);
|
av_packet_unref(&pkt_recoded);
|
||||||
}
|
}
|
||||||
avctx->internal->pkt = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FF_API_MERGE_SD
|
#if FF_API_MERGE_SD
|
||||||
|
@ -1292,7 +1310,7 @@ static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
|
||||||
|
|
||||||
int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame)
|
int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame)
|
||||||
{
|
{
|
||||||
const AVPacket *pkt = avctx->internal->pkt;
|
const AVPacket *pkt = avctx->internal->last_pkt_props;
|
||||||
int i;
|
int i;
|
||||||
static const struct {
|
static const struct {
|
||||||
enum AVPacketSideDataType packet;
|
enum AVPacketSideDataType packet;
|
||||||
|
@ -1338,16 +1356,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
} else {
|
} else {
|
||||||
frame->flags = (frame->flags & ~AV_FRAME_FLAG_DISCARD);
|
frame->flags = (frame->flags & ~AV_FRAME_FLAG_DISCARD);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
frame->pts = AV_NOPTS_VALUE;
|
|
||||||
#if FF_API_PKT_PTS
|
|
||||||
FF_DISABLE_DEPRECATION_WARNINGS
|
|
||||||
frame->pkt_pts = AV_NOPTS_VALUE;
|
|
||||||
FF_ENABLE_DEPRECATION_WARNINGS
|
|
||||||
#endif
|
|
||||||
av_frame_set_pkt_pos (frame, -1);
|
|
||||||
av_frame_set_pkt_duration(frame, 0);
|
|
||||||
av_frame_set_pkt_size (frame, -1);
|
|
||||||
}
|
}
|
||||||
frame->reordered_opaque = avctx->reordered_opaque;
|
frame->reordered_opaque = avctx->reordered_opaque;
|
||||||
|
|
||||||
|
|
|
@ -138,10 +138,10 @@ typedef struct AVCodecInternal {
|
||||||
void *thread_ctx;
|
void *thread_ctx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current packet as passed into the decoder, to avoid having to pass the
|
* Properties (timestamps+side data) extracted from the last packet passed
|
||||||
* packet into every function.
|
* for decoding.
|
||||||
*/
|
*/
|
||||||
const AVPacket *pkt;
|
AVPacket *last_pkt_props;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* temporary buffer used for encoders to store their bitstream
|
* temporary buffer used for encoders to store their bitstream
|
||||||
|
|
|
@ -800,7 +800,7 @@ int ff_frame_thread_init(AVCodecContext *avctx)
|
||||||
}
|
}
|
||||||
*copy->internal = *src->internal;
|
*copy->internal = *src->internal;
|
||||||
copy->internal->thread_ctx = p;
|
copy->internal->thread_ctx = p;
|
||||||
copy->internal->pkt = &p->avpkt;
|
copy->internal->last_pkt_props = &p->avpkt;
|
||||||
|
|
||||||
if (!i) {
|
if (!i) {
|
||||||
src = copy;
|
src = copy;
|
||||||
|
|
|
@ -237,8 +237,8 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
av_frame_set_pkt_pos (frame, avctx->internal->pkt->pos);
|
av_frame_set_pkt_pos (frame, avctx->internal->last_pkt_props->pos);
|
||||||
av_frame_set_pkt_duration(frame, avctx->internal->pkt->duration);
|
av_frame_set_pkt_duration(frame, avctx->internal->last_pkt_props->duration);
|
||||||
|
|
||||||
if (context->tff >= 0) {
|
if (context->tff >= 0) {
|
||||||
frame->interlaced_frame = 1;
|
frame->interlaced_frame = 1;
|
||||||
|
|
|
@ -684,6 +684,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
||||||
goto free_and_end;
|
goto free_and_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avctx->internal->last_pkt_props = av_packet_alloc();
|
||||||
|
if (!avctx->internal->last_pkt_props) {
|
||||||
|
ret = AVERROR(ENOMEM);
|
||||||
|
goto free_and_end;
|
||||||
|
}
|
||||||
|
|
||||||
avctx->internal->skip_samples_multiplier = 1;
|
avctx->internal->skip_samples_multiplier = 1;
|
||||||
|
|
||||||
if (codec->priv_data_size > 0) {
|
if (codec->priv_data_size > 0) {
|
||||||
|
@ -1110,6 +1116,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
av_frame_free(&avctx->internal->to_free);
|
av_frame_free(&avctx->internal->to_free);
|
||||||
av_frame_free(&avctx->internal->buffer_frame);
|
av_frame_free(&avctx->internal->buffer_frame);
|
||||||
av_packet_free(&avctx->internal->buffer_pkt);
|
av_packet_free(&avctx->internal->buffer_pkt);
|
||||||
|
av_packet_free(&avctx->internal->last_pkt_props);
|
||||||
av_freep(&avctx->internal->pool);
|
av_freep(&avctx->internal->pool);
|
||||||
}
|
}
|
||||||
av_freep(&avctx->internal);
|
av_freep(&avctx->internal);
|
||||||
|
@ -1158,6 +1165,7 @@ av_cold int avcodec_close(AVCodecContext *avctx)
|
||||||
av_frame_free(&avctx->internal->to_free);
|
av_frame_free(&avctx->internal->to_free);
|
||||||
av_frame_free(&avctx->internal->buffer_frame);
|
av_frame_free(&avctx->internal->buffer_frame);
|
||||||
av_packet_free(&avctx->internal->buffer_pkt);
|
av_packet_free(&avctx->internal->buffer_pkt);
|
||||||
|
av_packet_free(&avctx->internal->last_pkt_props);
|
||||||
for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
|
for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
|
||||||
av_buffer_pool_uninit(&pool->pools[i]);
|
av_buffer_pool_uninit(&pool->pools[i]);
|
||||||
av_freep(&avctx->internal->pool);
|
av_freep(&avctx->internal->pool);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue