[FFmpeg-devel] [PATCH 2/2] avcodec/mediacodec_surface: define and use FFANativeWindow to mimic NDK interface

Aman Gupta ffmpeg at tmm1.net
Fri Sep 6 02:07:20 EEST 2019


From: Aman Gupta <aman at tmm1.net>

This will make it easy to switch to ANativeWindow_fromSurface
and ANativeWindow_release in the future.

Signed-off-by: Aman Gupta <aman at tmm1.net>
---
 libavcodec/mediacodec_surface.c | 11 ++++-------
 libavcodec/mediacodec_surface.h |  7 +++++--
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/mediacodec_surface.c b/libavcodec/mediacodec_surface.c
index efcc4dc63c..a292386e34 100644
--- a/libavcodec/mediacodec_surface.c
+++ b/libavcodec/mediacodec_surface.c
@@ -25,10 +25,9 @@
 #include "ffjni.h"
 #include "mediacodec_surface.h"
 
-void *ff_mediacodec_surface_ref(void *surface, void *log_ctx)
+FFANativeWindow *ff_mediacodec_surface_ref(void *surface, void *log_ctx)
 {
     JNIEnv *env = NULL;
-    void *reference = NULL;
 
     if (!surface)
         return NULL;
@@ -38,12 +37,10 @@ void *ff_mediacodec_surface_ref(void *surface, void *log_ctx)
         return NULL;
     }
 
-    reference = (*env)->NewGlobalRef(env, surface);
-
-    return reference;
+    return (*env)->NewGlobalRef(env, surface);
 }
 
-int ff_mediacodec_surface_unref(void *surface, void *log_ctx)
+int ff_mediacodec_surface_unref(FFANativeWindow *window, void *log_ctx)
 {
     JNIEnv *env = NULL;
 
@@ -52,7 +49,7 @@ int ff_mediacodec_surface_unref(void *surface, void *log_ctx)
         return AVERROR_EXTERNAL;
     }
 
-    (*env)->DeleteGlobalRef(env, surface);
+    (*env)->DeleteGlobalRef(env, window);
 
     return 0;
 }
diff --git a/libavcodec/mediacodec_surface.h b/libavcodec/mediacodec_surface.h
index 0178b8ae71..933dc2bf51 100644
--- a/libavcodec/mediacodec_surface.h
+++ b/libavcodec/mediacodec_surface.h
@@ -25,7 +25,10 @@
 
 #include "libavcodec/avcodec.h"
 
-void *ff_mediacodec_surface_ref(void *surface, void *log_ctx);
-int ff_mediacodec_surface_unref(void *surface, void *log_ctx);
+struct FFANativeWindow;
+typedef struct FFANativeWindow FFANativeWindow;
+
+FFANativeWindow *ff_mediacodec_surface_ref(void *surface, void *log_ctx);
+int ff_mediacodec_surface_unref(FFANativeWindow *window, void *log_ctx);
 
 #endif /* AVCODEC_MEDIACODEC_SURFACE_H */
-- 
2.20.1



More information about the ffmpeg-devel mailing list