[FFmpeg-devel] [PATCH 3/4] lavc: Add wrapped_avframe decoder
Mark Thompson
sw at jkqxz.net
Sun Sep 3 21:33:46 EEST 2017
On 03/09/17 18:25, Muhammad Faiz wrote:
> On Sun, Sep 3, 2017 at 5:21 AM, Mark Thompson <sw at jkqxz.net> wrote:
>> Intended for use with hardware frames for which rawvideo is not
>> sufficient.
>> ---
>> Kindof nasty. Any thoughts on better ways of achieving the same result (hardware frames out of lavd) very welcome!
>>
>>
>> libavcodec/Makefile | 1 +
>> libavcodec/allcodecs.c | 2 +-
>> libavcodec/wrapped_avframe.c | 31 +++++++++++++++++++++++++++++++
>> 3 files changed, 33 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>> index 999632cf9e..943e5db511 100644
>> --- a/libavcodec/Makefile
>> +++ b/libavcodec/Makefile
>> @@ -653,6 +653,7 @@ OBJS-$(CONFIG_WMV2_DECODER) += wmv2dec.o wmv2.o wmv2data.o \
>> OBJS-$(CONFIG_WMV2_ENCODER) += wmv2enc.o wmv2.o wmv2data.o \
>> msmpeg4.o msmpeg4enc.o msmpeg4data.o
>> OBJS-$(CONFIG_WNV1_DECODER) += wnv1.o
>> +OBJS-$(CONFIG_WRAPPED_AVFRAME_DECODER) += wrapped_avframe.o
>> OBJS-$(CONFIG_WRAPPED_AVFRAME_ENCODER) += wrapped_avframe.o
>> OBJS-$(CONFIG_WS_SND1_DECODER) += ws-snd1.o
>> OBJS-$(CONFIG_XAN_DPCM_DECODER) += dpcm.o
>> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
>> index ce0bc7ecf3..625720578f 100644
>> --- a/libavcodec/allcodecs.c
>> +++ b/libavcodec/allcodecs.c
>> @@ -377,7 +377,7 @@ static void register_all(void)
>> REGISTER_DECODER(VQA, vqa);
>> REGISTER_DECODER(BITPACKED, bitpacked);
>> REGISTER_DECODER(WEBP, webp);
>> - REGISTER_ENCODER(WRAPPED_AVFRAME, wrapped_avframe);
>> + REGISTER_ENCDEC (WRAPPED_AVFRAME, wrapped_avframe);
>> REGISTER_ENCDEC (WMV1, wmv1);
>> REGISTER_ENCDEC (WMV2, wmv2);
>> REGISTER_DECODER(WMV3, wmv3);
>> diff --git a/libavcodec/wrapped_avframe.c b/libavcodec/wrapped_avframe.c
>> index 14360320ff..e66f0cfa4c 100644
>> --- a/libavcodec/wrapped_avframe.c
>> +++ b/libavcodec/wrapped_avframe.c
>> @@ -75,6 +75,28 @@ static int wrapped_avframe_encode(AVCodecContext *avctx, AVPacket *pkt,
>> return 0;
>> }
>>
>> +static int wrapped_avframe_decode(AVCodecContext *avctx, void *data,
>> + int *got_frame, AVPacket *pkt)
>> +{
>> + AVFrame *in, *out;
>> + int err;
>> +
>> + if (pkt->size < sizeof(AVFrame))
>> + return AVERROR(EINVAL);
>> +
>> + in = (AVFrame*)pkt->data;
>> + out = data;
>> +
>> + err = ff_decode_frame_props(avctx, out);
>> + if (err < 0)
>> + return err;
>> +
>> + av_frame_move_ref(out, in);
>> +
>> + *got_frame = 1;
>> + return 0;
>> +}
>> +
>> AVCodec ff_wrapped_avframe_encoder = {
>> .name = "wrapped_avframe",
>> .long_name = NULL_IF_CONFIG_SMALL("AVFrame to AVPacket passthrough"),
>> @@ -83,3 +105,12 @@ AVCodec ff_wrapped_avframe_encoder = {
>> .encode2 = wrapped_avframe_encode,
>> .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
>> };
>> +
>> +AVCodec ff_wrapped_avframe_decoder = {
>> + .name = "wrapped_avframe",
>> + .long_name = NULL_IF_CONFIG_SMALL("AVPacket to AVFrame passthrough"),
>> + .type = AVMEDIA_TYPE_VIDEO,
>> + .id = AV_CODEC_ID_WRAPPED_AVFRAME,
>> + .decode = wrapped_avframe_decode,
>> + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
>> +};
>> --
>> 2.11.0
>
> Security issues:
> https://ffmpeg.org/pipermail/ffmpeg-devel/2015-November/182985.html
Hmm, yeah, urgh. I didn't think of this decoder being callable standalone.
Does anyone want to propose a different solution to the idea of a flag on the packet? That seems straightforward enough.
(Or any other ideas to get the frame out of lavd. For kmsgrab the inability to do that is entirely fatal - it needs to carry the hardware context metadata, so rawvideo just doesn't work.)
Thanks,
- Mark
More information about the ffmpeg-devel
mailing list