diff options
author | James Almer <jamrial@gmail.com> | 2017-03-22 15:27:30 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2017-03-23 11:44:58 -0300 |
commit | 005da88c1ee231eddd9924ad8173aeeab6366165 (patch) | |
tree | 2ccf866b5c1c921ff4922cd400a0904a05cca297 /libavcodec | |
parent | 4f727fbc7330e726d003e2961fa676ddaf86f994 (diff) | |
download | ffmpeg-005da88c1ee231eddd9924ad8173aeeab6366165.tar.gz |
avcodec/mediacodec: convert to stdatomic
Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/mediacodec.c | 5 | ||||
-rw-r--r-- | libavcodec/mediacodecdec.c | 1 | ||||
-rw-r--r-- | libavcodec/mediacodecdec_common.c | 13 | ||||
-rw-r--r-- | libavcodec/mediacodecdec_common.h | 5 |
4 files changed, 11 insertions, 13 deletions
diff --git a/libavcodec/mediacodec.c b/libavcodec/mediacodec.c index 4ad5921bc2..610bb49a73 100644 --- a/libavcodec/mediacodec.c +++ b/libavcodec/mediacodec.c @@ -31,7 +31,6 @@ #include <jni.h> #include "libavcodec/avcodec.h" -#include "libavutil/atomic.h" #include "libavutil/mem.h" #include "ffjni.h" @@ -90,9 +89,9 @@ void av_mediacodec_default_free(AVCodecContext *avctx) int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render) { MediaCodecDecContext *ctx = buffer->ctx; - int released = avpriv_atomic_int_add_and_fetch(&buffer->released, 1); + int released = atomic_fetch_add(&buffer->released, 1); - if (released == 1) { + if (!released) { return ff_AMediaCodec_releaseOutputBuffer(ctx->codec, buffer->index, render); } diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c index 2e645caafd..3ada3fa698 100644 --- a/libavcodec/mediacodecdec.c +++ b/libavcodec/mediacodecdec.c @@ -29,7 +29,6 @@ #include "libavutil/opt.h" #include "libavutil/intreadwrite.h" #include "libavutil/pixfmt.h" -#include "libavutil/atomic.h" #include "avcodec.h" #include "h264_parse.h" diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index dfc7f5514a..2ec25c581d 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -23,7 +23,6 @@ #include <string.h> #include <sys/types.h> -#include "libavutil/atomic.h" #include "libavutil/common.h" #include "libavutil/mem.h" #include "libavutil/log.h" @@ -143,7 +142,7 @@ static enum AVPixelFormat mcdec_map_color_format(AVCodecContext *avctx, static void ff_mediacodec_dec_ref(MediaCodecDecContext *s) { - avpriv_atomic_int_add_and_fetch(&s->refcount, 1); + atomic_fetch_add(&s->refcount, 1); } static void ff_mediacodec_dec_unref(MediaCodecDecContext *s) @@ -151,7 +150,7 @@ static void ff_mediacodec_dec_unref(MediaCodecDecContext *s) if (!s) return; - if (!avpriv_atomic_int_add_and_fetch(&s->refcount, -1)) { + if (atomic_fetch_sub(&s->refcount, 1) == 1) { if (s->codec) { ff_AMediaCodec_delete(s->codec); s->codec = NULL; @@ -176,7 +175,7 @@ static void mediacodec_buffer_release(void *opaque, uint8_t *data) { AVMediaCodecBuffer *buffer = opaque; MediaCodecDecContext *ctx = buffer->ctx; - int released = avpriv_atomic_int_get(&buffer->released); + int released = atomic_load(&buffer->released); if (!released) { ff_AMediaCodec_releaseOutputBuffer(ctx->codec, buffer->index, 0); @@ -221,7 +220,7 @@ FF_ENABLE_DEPRECATION_WARNINGS goto fail; } - buffer->released = 0; + atomic_init(&buffer->released, 0); frame->buf[0] = av_buffer_create(NULL, 0, @@ -465,7 +464,7 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, AV_PIX_FMT_NONE, }; - s->refcount = 1; + atomic_init(&s->refcount, 1); pix_fmt = ff_get_format(avctx, pix_fmts); if (pix_fmt == AV_PIX_FMT_MEDIACODEC) { @@ -725,7 +724,7 @@ int ff_mediacodec_dec_decode(AVCodecContext *avctx, MediaCodecDecContext *s, int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s) { - if (!s->surface || avpriv_atomic_int_get(&s->refcount) == 1) { + if (!s->surface || atomic_load(&s->refcount) == 1) { int ret; /* No frames (holding a reference to the codec) are retained by the diff --git a/libavcodec/mediacodecdec_common.h b/libavcodec/mediacodecdec_common.h index c00c2e89f3..10f38277b5 100644 --- a/libavcodec/mediacodecdec_common.h +++ b/libavcodec/mediacodecdec_common.h @@ -24,6 +24,7 @@ #define AVCODEC_MEDIACODECDEC_COMMON_H #include <stdint.h> +#include <stdatomic.h> #include <sys/types.h> #include "libavutil/frame.h" @@ -34,7 +35,7 @@ typedef struct MediaCodecDecContext { - volatile int refcount; + atomic_int refcount; char *codec_name; @@ -88,7 +89,7 @@ typedef struct MediaCodecBuffer { MediaCodecDecContext *ctx; ssize_t index; int64_t pts; - volatile int released; + atomic_int released; } MediaCodecBuffer; |