mirror of
https://github.com/mpv-player/mpv
synced 2025-04-01 23:00:41 +00:00
core: add common function to initialize AVPacket
Audio and video had their own (very similar) functions to initialize an AVPacket (ffmpeg's packet struct) from a demux_packet (mplayer's packet struct). Add a common function for these. Also use this function for sd_lavc_conv. This is actually a functional change, as some libavfilter subtitle demuxers add weird out-of-band stuff as side-data.
This commit is contained in:
parent
13a1ce16f9
commit
9f4261de65
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user