diff options
author | Clément Bœsch <u@pkh.me> | 2017-03-22 19:55:18 +0300 |
---|---|---|
committer | Clément Bœsch <u@pkh.me> | 2017-03-22 19:55:18 +0300 |
commit | b7336faa39b8ea26d01817cb6a7bf26a795d0580 (patch) | |
tree | 2fc8c539f10bede9357e421e32c9b744d9efe120 /libavdevice/v4l2.c | |
parent | 443e9692935f1f6c9abefbc842e9f2f5ae6b065d (diff) | |
parent | 3a165c187da7d74f46f6c1778294e8c5a3a7151f (diff) |
Merge commit '3a165c187da7d74f46f6c1778294e8c5a3a7151f'
* commit '3a165c187da7d74f46f6c1778294e8c5a3a7151f':
v4l2: convert to stdatomic
Merged-by: Clément Bœsch <u@pkh.me>
Diffstat (limited to 'libavdevice/v4l2.c')
-rw-r--r-- | libavdevice/v4l2.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index dada8cedea..15629755a1 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"); |