FFmpeg
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 
30 FFANativeWindow *ff_mediacodec_surface_ref(void *surface, void *native_window, void *log_ctx)
31 {
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 
75  av_free(window);
76 
77  return 0;
78 }
mediacodec_surface.h
window
static SDL_Window * window
Definition: ffplay.c:360
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
NULL
#define NULL
Definition: coverity.c:32
ff_jni_get_env
JNIEnv * ff_jni_get_env(void *log_ctx)
Definition: ffjni.c:53
ff_mediacodec_surface_unref
int ff_mediacodec_surface_unref(FFANativeWindow *window, void *log_ctx)
Definition: mediacodec_surface.c:59
FFANativeWindow
Definition: mediacodec_surface.h:28
ffjni.h
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
ff_mediacodec_surface_ref
FFANativeWindow * ff_mediacodec_surface_ref(void *surface, void *native_window, void *log_ctx)
Definition: mediacodec_surface.c:30
ret
ret
Definition: filter_design.txt:187
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
jni.h