Merge commit '3a165c187da7d74f46f6c1778294e8c5a3a7151f'

* commit '3a165c187da7d74f46f6c1778294e8c5a3a7151f':
  v4l2: convert to stdatomic

Merged-by: Clément Bœsch <u@pkh.me>
This commit is contained in:
Clément Bœsch 2017-03-22 17:55:18 +01:00
commit b7336faa39
2 changed files with 9 additions and 8 deletions

View File

@ -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"

View File

@ -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");