summaryrefslogtreecommitdiffstats
path: root/libavcodec/v4l2_m2m.h
diff options
context:
space:
mode:
authorMark Thompson <sw@jkqxz.net>2018-01-09 23:56:41 +0100
committerMark Thompson <sw@jkqxz.net>2018-01-21 00:37:35 +0000
commita0c624e299730c8c5800375c2f5f3c6c200053ff (patch)
tree6a7b9312d0b25d9a65d160d62165675d4985bdfb /libavcodec/v4l2_m2m.h
parent6c1c6c6c71fc776c6dd25d13861b036dad2cdc1b (diff)
downloadffmpeg-streaming-a0c624e299730c8c5800375c2f5f3c6c200053ff.zip
ffmpeg-streaming-a0c624e299730c8c5800375c2f5f3c6c200053ff.tar.gz
avcodec: v4l2_m2m: fix races around freeing data on close
Refcount all of the context information. This also fixes a potential segmentation fault when accessing freed memory (buffer returned after the codec has been closed). Tested-by: Jorge Ramirez-Ortiz <jorge.ramirez.ortiz@gmail.com>
Diffstat (limited to 'libavcodec/v4l2_m2m.h')
-rw-r--r--libavcodec/v4l2_m2m.h35
1 files changed, 28 insertions, 7 deletions
diff --git a/libavcodec/v4l2_m2m.h b/libavcodec/v4l2_m2m.h
index afa3987..452bf0d 100644
--- a/libavcodec/v4l2_m2m.h
+++ b/libavcodec/v4l2_m2m.h
@@ -38,11 +38,9 @@
#define V4L_M2M_DEFAULT_OPTS \
{ "num_output_buffers", "Number of buffers in the output context",\
- OFFSET(output.num_buffers), AV_OPT_TYPE_INT, { .i64 = 16 }, 6, INT_MAX, FLAGS }
+ OFFSET(num_output_buffers), AV_OPT_TYPE_INT, { .i64 = 16 }, 6, INT_MAX, FLAGS }
-typedef struct V4L2m2mContext
-{
- AVClass *class;
+typedef struct V4L2m2mContext {
char devname[PATH_MAX];
int fd;
@@ -50,18 +48,41 @@ typedef struct V4L2m2mContext
V4L2Context capture;
V4L2Context output;
- /* refcount of buffers held by the user */
- atomic_uint refcount;
-
/* dynamic stream reconfig */
AVCodecContext *avctx;
sem_t refsync;
+ atomic_uint refcount;
int reinit;
/* null frame/packet received */
int draining;
+
+ /* Reference to self; only valid while codec is active. */
+ AVBufferRef *self_ref;
} V4L2m2mContext;
+typedef struct V4L2m2mPriv
+{
+ AVClass *class;
+
+ V4L2m2mContext *context;
+ AVBufferRef *context_ref;
+
+ int num_output_buffers;
+ int num_capture_buffers;
+} V4L2m2mPriv;
+
+/**
+ * Allocate a new context and references for a V4L2 M2M instance.
+ *
+ * @param[in] ctx The AVCodecContext instantiated by the encoder/decoder.
+ * @param[out] ctx The V4L2m2mContext.
+ *
+ * @returns 0 in success, a negative error code otherwise.
+ */
+int ff_v4l2_m2m_create_context(AVCodecContext *avctx, V4L2m2mContext **s);
+
+
/**
* Probes the video nodes looking for the required codec capabilities.
*
OpenPOWER on IntegriCloud