summaryrefslogtreecommitdiff
path: root/libavcodec/wrapped_avframe.c
diff options
context:
space:
mode:
authorMark Thompson <sw@jkqxz.net>2017-09-02 20:32:27 +0100
committerMark Thompson <sw@jkqxz.net>2017-09-13 22:25:29 +0100
commitc8dea81921504c5e25a705dec4438dc95463f49b (patch)
tree31b4fbfaecca6cb98c03a2d2cdcf63da91d50cb3 /libavcodec/wrapped_avframe.c
parent82342cead15bbc47b84be4c0b50e7fd7401cdb96 (diff)
lavc: Add wrapped_avframe decoder
Intended for use with hardware frames for which rawvideo is not sufficient. Requires the trusted packet flag to be set - decoding fails if not to avoid security issues (the wrapped AVFrame can contain pointers to arbitrary data).
Diffstat (limited to 'libavcodec/wrapped_avframe.c')
-rw-r--r--libavcodec/wrapped_avframe.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/libavcodec/wrapped_avframe.c b/libavcodec/wrapped_avframe.c
index 14360320ff..5f88a668b9 100644
--- a/libavcodec/wrapped_avframe.c
+++ b/libavcodec/wrapped_avframe.c
@@ -75,6 +75,33 @@ 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->flags & AV_PKT_FLAG_TRUSTED)) {
+ // This decoder is not usable with untrusted input.
+ return AVERROR(EPERM);
+ }
+
+ 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 +110,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,
+};