FFmpeg
Loading...
Searching...
No Matches
mediacodec_surface.c
Go to the documentation of this file.
1/*
2 * Android MediaCodec Surface functions
3 *
4 * Copyright (c) 2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
5 *
6 * This file is part of FFmpeg.
7 *
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.
12 *
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.
17 *
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
21 */
22
23#include <android/native_window.h>
24#include <jni.h>
25
26#include "libavutil/mem.h"
27#include "ffjni.h"
28#include "mediacodec_surface.h"
29
30FFANativeWindow *ff_mediacodec_surface_ref(void *surface, void *native_window, void *log_ctx)
31{
32 FFANativeWindow *ret;
33
34 ret = av_mallocz(sizeof(*ret));
35 if (!ret)
36 return NULL;
37
38 if (surface) {
39 JNIEnv *env = NULL;
40
41 env = ff_jni_get_env(log_ctx);
42 if (env)
43 ret->surface = (*env)->NewGlobalRef(env, surface);
44 }
45
46 if (native_window) {
47 ANativeWindow_acquire(native_window);
48 ret->native_window = native_window;
49 }
50
51 if (!ret->surface && !ret->native_window) {
52 av_log(log_ctx, AV_LOG_ERROR, "Both surface and native_window are NULL\n");
53 av_freep(&ret);
54 }
55
56 return ret;
57}
58
60{
61 if (!window)
62 return 0;
63
64 if (window->surface) {
65 JNIEnv *env = NULL;
66
67 env = ff_jni_get_env(log_ctx);
68 if (env)
69 (*env)->DeleteGlobalRef(env, window->surface);
70 }
71
72 if (window->native_window)
73 ANativeWindow_release(window->native_window);
74
76
77 return 0;
78}
#define NULL
Definition coverity.c:32
static SDL_Window * window
Definition ffplay.c:365
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
JNIEnv * ff_jni_get_env(void *log_ctx)
Definition ffjni.c:53
FFANativeWindow * ff_mediacodec_surface_ref(void *surface, void *native_window, void *log_ctx)
int ff_mediacodec_surface_unref(FFANativeWindow *window, void *log_ctx)
Memory handling functions.
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)