diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 5114c5d1dc..69fae719fe 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2821,14 +2821,13 @@ typedef struct AVCodecContext { */ int error_rate; +#if FF_API_CODEC_PKT /** - * Current packet as passed into the decoder, to avoid having - * to pass the packet into every function. Currently only valid - * inside lavc and get/release_buffer callbacks. - * - decoding: set by avcodec_decode_*, read by get_buffer() for setting pkt_pts - * - encoding: unused + * @deprecated this field is not supposed to be accessed from outside lavc */ + attribute_deprecated AVPacket *pkt; +#endif /** * VBV delay coded in the last frame (in periods of a 27 MHz clock). diff --git a/libavcodec/crystalhd.c b/libavcodec/crystalhd.c index 94f8c85bb9..12a8f8e02b 100644 --- a/libavcodec/crystalhd.c +++ b/libavcodec/crystalhd.c @@ -915,8 +915,8 @@ static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *a H264Context *h = priv->parser->priv_data; index = av_parser_parse2(priv->parser, avctx, &pout, &psize, - in_data, len, avctx->pkt->pts, - avctx->pkt->dts, 0); + in_data, len, avctx->internal->pkt->pts, + avctx->internal->pkt->dts, 0); if (index < 0) { av_log(avctx, AV_LOG_WARNING, "CrystalHD: Failed to parse h.264 packet to " @@ -950,7 +950,7 @@ static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *a * avoiding mangling so we need to build a mapping to values * we know will not be mangled. */ - uint64_t pts = opaque_list_push(priv, avctx->pkt->pts, pic_type); + uint64_t pts = opaque_list_push(priv, avctx->internal->pkt->pts, pic_type); if (!pts) { if (free_data) { av_freep(&in_data); diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 2e216a1f28..6a89696d68 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -97,6 +97,12 @@ typedef struct AVCodecInternal { void *thread_ctx; + /** + * Current packet as passed into the decoder, to avoid having to pass the + * packet into every function. + */ + AVPacket *pkt; + /** * temporary buffer used for encoders to store their bitstream */ diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index b46304fb01..cfbc9643ee 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -656,7 +656,6 @@ int ff_frame_thread_init(AVCodecContext *avctx) } *copy = *src; - copy->pkt = &p->avpkt; copy->internal = av_malloc(sizeof(AVCodecInternal)); if (!copy->internal) { @@ -665,6 +664,7 @@ int ff_frame_thread_init(AVCodecContext *avctx) } *copy->internal = *src->internal; copy->internal->thread_ctx = p; + copy->internal->pkt = &p->avpkt; if (!i) { src = copy; diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c index dd47f532fd..3f4a8fc86d 100644 --- a/libavcodec/rawdec.c +++ b/libavcodec/rawdec.c @@ -25,6 +25,7 @@ */ #include "avcodec.h" +#include "internal.h" #include "raw.h" #include "libavutil/avassert.h" #include "libavutil/buffer.h" @@ -182,9 +183,9 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame, frame->pict_type = AV_PICTURE_TYPE_I; frame->key_frame = 1; frame->reordered_opaque = avctx->reordered_opaque; - frame->pkt_pts = avctx->pkt->pts; - av_frame_set_pkt_pos (frame, avctx->pkt->pos); - av_frame_set_pkt_duration(frame, avctx->pkt->duration); + frame->pkt_pts = avctx->internal->pkt->pts; + av_frame_set_pkt_pos (frame, avctx->internal->pkt->pos); + av_frame_set_pkt_duration(frame, avctx->internal->pkt->duration); if (context->tff >= 0) { frame->interlaced_frame = 1; diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 92374f4888..17ca9c782b 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -729,11 +729,11 @@ FF_ENABLE_DEPRECATION_WARNINGS int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame) { - if (avctx->pkt) { - frame->pkt_pts = avctx->pkt->pts; - av_frame_set_pkt_pos (frame, avctx->pkt->pos); - av_frame_set_pkt_duration(frame, avctx->pkt->duration); - av_frame_set_pkt_size (frame, avctx->pkt->size); + if (avctx->internal->pkt) { + frame->pkt_pts = avctx->internal->pkt->pts; + av_frame_set_pkt_pos (frame, avctx->internal->pkt->pos); + av_frame_set_pkt_duration(frame, avctx->internal->pkt->duration); + av_frame_set_pkt_size (frame, avctx->internal->pkt->size); } else { frame->pkt_pts = AV_NOPTS_VALUE; av_frame_set_pkt_pos (frame, -1); @@ -2026,7 +2026,7 @@ static int add_metadata_from_side_data(AVCodecContext *avctx, AVFrame *frame) const uint8_t *side_metadata; const uint8_t *end; - side_metadata = av_packet_get_side_data(avctx->pkt, + side_metadata = av_packet_get_side_data(avctx->internal->pkt, AV_PKT_DATA_STRINGS_METADATA, &size); if (!side_metadata) goto end; @@ -2084,7 +2084,7 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi goto fail; } - avctx->pkt = &tmp; + avctx->internal->pkt = &tmp; if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr, &tmp); @@ -2110,7 +2110,7 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi fail: emms_c(); //needed to avoid an emms_c() call before every return; - avctx->pkt = NULL; + avctx->internal->pkt = NULL; if (did_split) { av_packet_free_side_data(&tmp); if(ret == tmp.size) @@ -2233,7 +2233,7 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, goto fail; } - avctx->pkt = &tmp; + avctx->internal->pkt = &tmp; if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) ret = ff_thread_decode_frame(avctx, frame, got_frame_ptr, &tmp); else { @@ -2257,7 +2257,7 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, frame->sample_rate = avctx->sample_rate; } - side= av_packet_get_side_data(avctx->pkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size); + side= av_packet_get_side_data(avctx->internal->pkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size); if(side && side_size>=10) { avctx->internal->skip_samples = AV_RL32(side); av_log(avctx, AV_LOG_DEBUG, "skip %d samples due to side data\n", @@ -2312,7 +2312,7 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, } } fail: - avctx->pkt = NULL; + avctx->internal->pkt = NULL; if (did_split) { av_packet_free_side_data(&tmp); if(ret == tmp.size) @@ -2454,7 +2454,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, if (ret < 0) { *got_sub_ptr = 0; } else { - avctx->pkt = &pkt_recoded; + avctx->internal->pkt = &pkt_recoded; if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE) sub->pts = av_rescale_q(avpkt->pts, @@ -2491,7 +2491,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, sub->format = 0; else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB) sub->format = 1; - avctx->pkt = NULL; + avctx->internal->pkt = NULL; } if (did_split) { diff --git a/libavcodec/version.h b/libavcodec/version.h index f0430dacce..ba5b31dfc0 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -111,5 +111,8 @@ #ifndef FF_API_THREAD_OPAQUE #define FF_API_THREAD_OPAQUE (LIBAVCODEC_VERSION_MAJOR < 56) #endif +#ifndef FF_API_CODEC_PKT +#define FF_API_CODEC_PKT (LIBAVCODEC_VERSION_MAJOR < 56) +#endif #endif /* AVCODEC_VERSION_H */