diff options
-rw-r--r-- | audio/decode/ad_lavc.c | 7 | ||||
-rw-r--r-- | core/av_common.c | 20 | ||||
-rw-r--r-- | core/av_common.h | 2 | ||||
-rw-r--r-- | sub/sd_lavc_conv.c | 5 | ||||
-rw-r--r-- | video/decode/vd_lavc.c | 13 |
5 files changed, 27 insertions, 20 deletions
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 8abc0a6035..b5a4ee1ef8 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -402,13 +402,10 @@ static int decode_new_packet(struct sh_audio *sh) } AVPacket pkt; - av_init_packet(&pkt); + mp_set_av_packet(&pkt, mpkt); pkt.data = start; pkt.size = insize; - if (mpkt && mpkt->avpacket) { - pkt.side_data = mpkt->avpacket->side_data; - pkt.side_data_elems = mpkt->avpacket->side_data_elems; - } + if (pts != MP_NOPTS_VALUE && !packet_already_used) { sh->pts = pts; sh->pts_bytes = 0; diff --git a/core/av_common.c b/core/av_common.c index 5e6c8a4352..a4dc525aa9 100644 --- a/core/av_common.c +++ b/core/av_common.c @@ -18,8 +18,10 @@ #include <assert.h> #include <libavutil/common.h> +#include <libavcodec/avcodec.h> #include "core/mp_talloc.h" +#include "demux/demux_packet.h" #include "av_common.h" #include "codecs.h" @@ -58,6 +60,24 @@ void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st) avctx->bits_per_coded_sample = st->bits_per_coded_sample; } +// Set dst from mpkt. Note that dst is not refcountable. +// mpkt can be NULL to generate empty packets (used to flush delayed data). +// Does not set pts or duration fields. +void mp_set_av_packet(AVPacket *dst, struct demux_packet *mpkt) +{ + av_init_packet(dst); + dst->data = mpkt ? mpkt->buffer : NULL; + dst->size = mpkt ? mpkt->len : 0; + /* Some codecs (ZeroCodec, some cases of PNG) may want keyframe info + * from demuxer. */ + if (mpkt && mpkt->keyframe) + dst->flags |= AV_PKT_FLAG_KEY; + if (mpkt && mpkt->avpacket) { + dst->side_data = mpkt->avpacket->side_data; + dst->side_data_elems = mpkt->avpacket->side_data_elems; + } +} + void mp_add_lavc_decoders(struct mp_decoder_list *list, enum AVMediaType type) { AVCodec *cur = NULL; diff --git a/core/av_common.h b/core/av_common.h index 25593ed3d0..2fa8f127b0 100644 --- a/core/av_common.h +++ b/core/av_common.h @@ -22,8 +22,10 @@ #include <libavcodec/avcodec.h> struct mp_decoder_list; +struct demux_packet; void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st); +void mp_set_av_packet(AVPacket *dst, struct demux_packet *mpkt); void mp_add_lavc_decoders(struct mp_decoder_list *list, enum AVMediaType type); int mp_codec_to_av_codec_id(const char *codec); const char *mp_codec_from_av_codec_id(int codec_id); diff --git a/sub/sd_lavc_conv.c b/sub/sd_lavc_conv.c index 9c7a6f2c5f..5653ad87f9 100644 --- a/sub/sd_lavc_conv.c +++ b/sub/sd_lavc_conv.c @@ -114,9 +114,7 @@ static void decode(struct sd *sd, struct demux_packet *packet) AVPacket pkt; int ret, got_sub; - av_init_packet(&pkt); - pkt.data = packet->buffer; - pkt.size = packet->len; + mp_set_av_packet(&pkt, packet); pkt.pts = packet->pts == MP_NOPTS_VALUE ? AV_NOPTS_VALUE : packet->pts * ts; pkt.duration = packet->duration * ts; @@ -136,7 +134,6 @@ static void decode(struct sd *sd, struct demux_packet *packet) } } - av_free_packet(&pkt); avsubtitle_free(&sub); } diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index fff44edaed..540204bcfd 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -673,17 +673,8 @@ static int decode(struct sh_video *sh, struct demux_packet *packet, else avctx->skip_frame = ctx->skip_frame; - av_init_packet(&pkt); - pkt.data = packet ? packet->buffer : NULL; - pkt.size = packet ? packet->len : 0; - /* Some codecs (ZeroCodec, some cases of PNG) may want keyframe info - * from demuxer. */ - if (packet && packet->keyframe) - pkt.flags |= AV_PKT_FLAG_KEY; - if (packet && packet->avpacket) { - pkt.side_data = packet->avpacket->side_data; - pkt.side_data_elems = packet->avpacket->side_data_elems; - } + mp_set_av_packet(&pkt, packet); + // The avcodec opaque field stupidly supports only int64_t type union pts { int64_t i; double d; }; avctx->reordered_opaque = (union pts){.d = *reordered_pts}.i; |