diff --git a/libavdevice/v4l2-common.h b/libavdevice/v4l2-common.h index 40c716489fe94dc36ca61d5b0ff7425e0a2688a7..0cbaec8bb9b17ff534a2a28843718dec0e3ea46f 100644 --- a/libavdevice/v4l2-common.h +++ b/libavdevice/v4l2-common.h @@ -35,7 +35,6 @@ #endif #include <linux/videodev2.h> #endif -#include "libavutil/atomic.h" #include "libavutil/avassert.h" #include "libavutil/imgutils.h" #include "libavutil/log.h" diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index dada8cedeadfea40e6cbbd4ed10b2e915c41dade..15629755a1125792fcfb0dc0dfac8e79e499a9ec 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -30,6 +30,8 @@ * V4L2_PIX_FMT_* and AV_PIX_FMT_* */ +#include <stdatomic.h> + #include "v4l2-common.h" #include <dirent.h> @@ -78,7 +80,7 @@ struct video_data { int64_t last_time_m; int buffers; - volatile int buffers_queued; + atomic_int buffers_queued; void **buf_start; unsigned int *buf_len; char *standard; @@ -402,7 +404,7 @@ static int enqueue_buffer(struct video_data *s, struct v4l2_buffer *buf) res = AVERROR(errno); av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", av_err2str(res)); } else { - avpriv_atomic_int_add_and_fetch(&s->buffers_queued, 1); + atomic_fetch_add(&s->buffers_queued, 1); } return res; @@ -510,9 +512,9 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) av_log(ctx, AV_LOG_ERROR, "Invalid buffer index received.\n"); return AVERROR(EINVAL); } - avpriv_atomic_int_add_and_fetch(&s->buffers_queued, -1); + atomic_fetch_add(&s->buffers_queued, -1); // always keep at least one buffer queued - av_assert0(avpriv_atomic_int_get(&s->buffers_queued) >= 1); + av_assert0(atomic_load(&s->buffers_queued) >= 1); #ifdef V4L2_BUF_FLAG_ERROR if (buf.flags & V4L2_BUF_FLAG_ERROR) { @@ -538,7 +540,7 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) } /* Image is at s->buff_start[buf.index] */ - if (avpriv_atomic_int_get(&s->buffers_queued) == FFMAX(s->buffers / 8, 1)) { + if (atomic_load(&s->buffers_queued) == FFMAX(s->buffers / 8, 1)) { /* when we start getting low on queued buffers, fall back on copying data */ res = av_new_packet(pkt, buf.bytesused); if (res < 0) { @@ -607,7 +609,7 @@ static int mmap_start(AVFormatContext *ctx) return res; } } - s->buffers_queued = s->buffers; + atomic_store(&s->buffers_queued, s->buffers); type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (v4l2_ioctl(s->fd, VIDIOC_STREAMON, &type) < 0) { @@ -1000,7 +1002,7 @@ static int v4l2_read_close(AVFormatContext *ctx) { struct video_data *s = ctx->priv_data; - if (avpriv_atomic_int_get(&s->buffers_queued) != s->buffers) + if (atomic_load(&s->buffers_queued) != s->buffers) av_log(ctx, AV_LOG_WARNING, "Some buffers are still owned by the caller on " "close.\n");