2 * Android MediaCodec public API functions
4 * Copyright (c) 2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "libavutil/error.h"
27 #if CONFIG_H264_MEDIACODEC_HWACCEL
31 #include "libavcodec/avcodec.h"
32 #include "libavutil/atomic.h"
33 #include "libavutil/mem.h"
36 #include "mediacodec.h"
37 #include "mediacodecdec.h"
39 AVMediaCodecContext *av_mediacodec_alloc_context(void)
41 return av_mallocz(sizeof(AVMediaCodecContext));
44 int av_mediacodec_default_init(AVCodecContext *avctx, AVMediaCodecContext *ctx, void *surface)
49 env = ff_jni_get_env(avctx);
51 return AVERROR_EXTERNAL;
54 ctx->surface = (*env)->NewGlobalRef(env, surface);
56 avctx->hwaccel_context = ctx;
58 av_log(avctx, AV_LOG_ERROR, "Could not create new global reference\n");
59 ret = AVERROR_EXTERNAL;
65 void av_mediacodec_default_free(AVCodecContext *avctx)
69 AVMediaCodecContext *ctx = avctx->hwaccel_context;
75 env = ff_jni_get_env(avctx);
81 (*env)->DeleteGlobalRef(env, ctx->surface);
85 av_freep(&avctx->hwaccel_context);
88 int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render)
90 MediaCodecDecContext *ctx = buffer->ctx;
91 int released = avpriv_atomic_int_add_and_fetch(&buffer->released, 1);
94 return ff_AMediaCodec_releaseOutputBuffer(ctx->codec, buffer->index, render);
104 #include "mediacodec.h"
106 AVMediaCodecContext *av_mediacodec_alloc_context(void)
111 int av_mediacodec_default_init(AVCodecContext *avctx, AVMediaCodecContext *ctx, void *surface)
113 return AVERROR(ENOSYS);
116 void av_mediacodec_default_free(AVCodecContext *avctx)
120 int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render)
122 return AVERROR(ENOSYS);