diff options
author | wm4 <wm4@nowhere> | 2013-06-03 01:55:48 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-06-03 22:40:07 +0200 |
commit | 9f4261de65c18d3a34e70c9f969966ca85c80a8d (patch) | |
tree | f9a563589dff67799230508bcc87fe8001fc0ef1 /core | |
parent | 13a1ce16f9581871cf7ac0d06ece407534a98f89 (diff) | |
download | mpv-9f4261de65c18d3a34e70c9f969966ca85c80a8d.tar.bz2 mpv-9f4261de65c18d3a34e70c9f969966ca85c80a8d.tar.xz |
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.
Diffstat (limited to 'core')
-rw-r--r-- | core/av_common.c | 20 | ||||
-rw-r--r-- | core/av_common.h | 2 |
2 files changed, 22 insertions, 0 deletions
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); |