• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_ANDROID_ANDROID_IMAGE_READER_ABI_H_
6 #define BASE_ANDROID_ANDROID_IMAGE_READER_ABI_H_
7 
8 // Minimal binary interface definitions for AImage,AImageReader
9 // and ANativeWindow based on include/media/NdkImage.h,
10 // include/media/NdkImageReader.h and include/android/native_window_jni.h
11 // from the Android NDK for platform level 26+. This is only
12 // intended for use from the AndroidImageReader wrapper for building
13 // without NDK platform level support, it is not a general-use header
14 // and is not complete. Only the functions/data types which
15 // are currently needed by media/gpu/android/image_reader_gl_owner.h are
16 // included in this ABI
17 //
18 // Please refer to the API documentation for details:
19 // https://developer.android.com/ndk/reference/group/media (AIMage and
20 // AImageReader)
21 // https://developer.android.com/ndk/reference/group/native-activity
22 // (ANativeWindow)
23 
24 #include <android/native_window.h>
25 #include <media/NdkMediaError.h>
26 
27 #include <jni.h>
28 #include <stdint.h>
29 
30 // Use "C" linkage to match the original header file. This isn't strictly
31 // required since the file is not declaring global functions, but the types
32 // should remain in the global namespace for compatibility, and it's a reminder
33 // that forward declarations elsewhere should use "extern "C" to avoid
34 // namespace issues.
35 extern "C" {
36 
37 // For AImage
38 typedef struct AHardwareBuffer AHardwareBuffer;
39 
40 typedef struct AImage AImage;
41 
42 enum AIMAGE_FORMATS {
43   AIMAGE_FORMAT_YUV_420_888 = 0x23,
44   IMAGE_FORMAT_PRIVATE = 0x22
45 };
46 
47 using pAImage_delete = void (*)(AImage* image);
48 
49 using pAImage_deleteAsync = void (*)(AImage* image, int releaseFenceFd);
50 
51 using pAImage_getHardwareBuffer = media_status_t (*)(const AImage* image,
52                                                      AHardwareBuffer** buffer);
53 
54 using pAImage_getWidth = media_status_t (*)(const AImage* image,
55                                             int32_t* width);
56 
57 using pAImage_getHeight = media_status_t (*)(const AImage* image,
58                                              int32_t* height);
59 
60 // For AImageReader
61 
62 typedef struct AImageReader AImageReader;
63 
64 typedef void (*AImageReader_ImageCallback)(void* context, AImageReader* reader);
65 
66 typedef struct AImageReader_ImageListener {
67   void* context;
68   AImageReader_ImageCallback onImageAvailable;
69 } AImageReader_ImageListener;
70 
71 using pAImageReader_new = media_status_t (*)(int32_t width,
72                                              int32_t height,
73                                              int32_t format,
74                                              int32_t maxImages,
75                                              AImageReader** reader);
76 
77 using pAImageReader_setImageListener =
78     media_status_t (*)(AImageReader* reader,
79                        AImageReader_ImageListener* listener);
80 
81 using pAImageReader_delete = void (*)(AImageReader* reader);
82 
83 using pAImageReader_getWindow = media_status_t (*)(AImageReader* reader,
84                                                    ANativeWindow** window);
85 
86 using pAImageReader_acquireLatestImageAsync =
87     media_status_t (*)(AImageReader* reader,
88                        AImage** image,
89                        int* acquireFenceFd);
90 
91 // For ANativeWindow
92 using pANativeWindow_toSurface = jobject (*)(JNIEnv* env,
93                                              ANativeWindow* window);
94 
95 }  // extern "C"
96 
97 #endif  // BASE_ANDROID_ANDROID_IMAGE_READER_ABI_H_
98