Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(918)

Side by Side Diff: webrtc/sdk/android/src/jni/native_handle_impl.h

Issue 3009613002: Android: Replace webrtc_jni namespace with nested jni namespace (Closed)
Patch Set: Rebase Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_SDK_ANDROID_SRC_JNI_NATIVE_HANDLE_IMPL_H_ 11 #ifndef WEBRTC_SDK_ANDROID_SRC_JNI_NATIVE_HANDLE_IMPL_H_
12 #define WEBRTC_SDK_ANDROID_SRC_JNI_NATIVE_HANDLE_IMPL_H_ 12 #define WEBRTC_SDK_ANDROID_SRC_JNI_NATIVE_HANDLE_IMPL_H_
13 13
14 #include <jni.h> 14 #include <jni.h>
15 15
16 #include "webrtc/api/video/video_frame.h" 16 #include "webrtc/api/video/video_frame.h"
17 #include "webrtc/api/video/video_frame_buffer.h" 17 #include "webrtc/api/video/video_frame_buffer.h"
18 #include "webrtc/api/video/video_rotation.h" 18 #include "webrtc/api/video/video_rotation.h"
19 #include "webrtc/rtc_base/callback.h" 19 #include "webrtc/rtc_base/callback.h"
20 #include "webrtc/sdk/android/src/jni/jni_helpers.h" 20 #include "webrtc/sdk/android/src/jni/jni_helpers.h"
21 21
22 namespace webrtc_jni { 22 namespace webrtc {
23 namespace jni {
23 24
24 // Open gl texture matrix, in column-major order. Operations are 25 // Open gl texture matrix, in column-major order. Operations are
25 // in-place. 26 // in-place.
26 class Matrix { 27 class Matrix {
27 public: 28 public:
28 Matrix(JNIEnv* jni, jfloatArray a); 29 Matrix(JNIEnv* jni, jfloatArray a);
29 30
30 static Matrix fromAndroidGraphicsMatrix(JNIEnv* jni, jobject j_matrix); 31 static Matrix fromAndroidGraphicsMatrix(JNIEnv* jni, jobject j_matrix);
31 32
32 jfloatArray ToJava(JNIEnv* jni) const; 33 jfloatArray ToJava(JNIEnv* jni) const;
33 34
34 // Crop arguments are relative to original size. 35 // Crop arguments are relative to original size.
35 void Crop(float cropped_width, 36 void Crop(float cropped_width,
36 float cropped_height, 37 float cropped_height,
37 float crop_x, 38 float crop_x,
38 float crop_y); 39 float crop_y);
39 40
40 void Rotate(webrtc::VideoRotation rotation); 41 void Rotate(VideoRotation rotation);
41 42
42 private: 43 private:
43 Matrix() {} 44 Matrix() {}
44 45
45 static void Multiply(const float a[16], const float b[16], float result[16]); 46 static void Multiply(const float a[16], const float b[16], float result[16]);
46 float elem_[16]; 47 float elem_[16];
47 }; 48 };
48 49
49 // Wrapper for texture object. 50 // Wrapper for texture object.
50 struct NativeHandleImpl { 51 struct NativeHandleImpl {
51 NativeHandleImpl(JNIEnv* jni, 52 NativeHandleImpl(JNIEnv* jni,
52 jint j_oes_texture_id, 53 jint j_oes_texture_id,
53 jfloatArray j_transform_matrix); 54 jfloatArray j_transform_matrix);
54 55
55 NativeHandleImpl(int id, const Matrix& matrix); 56 NativeHandleImpl(int id, const Matrix& matrix);
56 57
57 const int oes_texture_id; 58 const int oes_texture_id;
58 Matrix sampling_matrix; 59 Matrix sampling_matrix;
59 }; 60 };
60 61
61 // Base class to differentiate between the old texture frames and the new 62 // Base class to differentiate between the old texture frames and the new
62 // Java-based frames. 63 // Java-based frames.
63 // TODO(sakal): Remove this and AndroidTextureBuffer once they are no longer 64 // TODO(sakal): Remove this and AndroidTextureBuffer once they are no longer
64 // needed. 65 // needed.
65 class AndroidVideoFrameBuffer : public webrtc::VideoFrameBuffer { 66 class AndroidVideoFrameBuffer : public VideoFrameBuffer {
66 public: 67 public:
67 enum class AndroidType { kTextureBuffer, kJavaBuffer }; 68 enum class AndroidType { kTextureBuffer, kJavaBuffer };
68 69
69 virtual AndroidType android_type() = 0; 70 virtual AndroidType android_type() = 0;
70 }; 71 };
71 72
72 class AndroidTextureBuffer : public AndroidVideoFrameBuffer { 73 class AndroidTextureBuffer : public AndroidVideoFrameBuffer {
73 public: 74 public:
74 AndroidTextureBuffer(int width, 75 AndroidTextureBuffer(int width,
75 int height, 76 int height,
76 const NativeHandleImpl& native_handle, 77 const NativeHandleImpl& native_handle,
77 jobject surface_texture_helper, 78 jobject surface_texture_helper,
78 const rtc::Callback0<void>& no_longer_used); 79 const rtc::Callback0<void>& no_longer_used);
79 ~AndroidTextureBuffer(); 80 ~AndroidTextureBuffer();
80 81
81 NativeHandleImpl native_handle_impl() const; 82 NativeHandleImpl native_handle_impl() const;
82 83
83 private: 84 private:
84 Type type() const override; 85 Type type() const override;
85 int width() const override; 86 int width() const override;
86 int height() const override; 87 int height() const override;
87 88
88 rtc::scoped_refptr<webrtc::I420BufferInterface> ToI420() override; 89 rtc::scoped_refptr<I420BufferInterface> ToI420() override;
89 90
90 AndroidType android_type() override { return AndroidType::kTextureBuffer; } 91 AndroidType android_type() override { return AndroidType::kTextureBuffer; }
91 92
92 const int width_; 93 const int width_;
93 const int height_; 94 const int height_;
94 NativeHandleImpl native_handle_; 95 NativeHandleImpl native_handle_;
95 // Raw object pointer, relying on the caller, i.e., 96 // Raw object pointer, relying on the caller, i.e.,
96 // AndroidVideoCapturerJni or the C++ SurfaceTextureHelper, to keep 97 // AndroidVideoCapturerJni or the C++ SurfaceTextureHelper, to keep
97 // a global reference. TODO(nisse): Make this a reference to the C++ 98 // a global reference. TODO(nisse): Make this a reference to the C++
98 // SurfaceTextureHelper instead, but that requires some refactoring 99 // SurfaceTextureHelper instead, but that requires some refactoring
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 jobject video_frame_buffer() const; 131 jobject video_frame_buffer() const;
131 132
132 // Returns an instance of VideoRenderer.I420Frame (deprecated) 133 // Returns an instance of VideoRenderer.I420Frame (deprecated)
133 jobject ToJavaI420Frame(JNIEnv* jni, int rotation); 134 jobject ToJavaI420Frame(JNIEnv* jni, int rotation);
134 135
135 private: 136 private:
136 Type type() const override; 137 Type type() const override;
137 int width() const override; 138 int width() const override;
138 int height() const override; 139 int height() const override;
139 140
140 rtc::scoped_refptr<webrtc::I420BufferInterface> ToI420() override; 141 rtc::scoped_refptr<I420BufferInterface> ToI420() override;
141 142
142 AndroidType android_type() override { return AndroidType::kJavaBuffer; } 143 AndroidType android_type() override { return AndroidType::kJavaBuffer; }
143 144
144 const jmethodID j_release_id_; 145 const jmethodID j_release_id_;
145 const int width_; 146 const int width_;
146 const int height_; 147 const int height_;
147 // Holds a VideoFrame.Buffer. 148 // Holds a VideoFrame.Buffer.
148 const ScopedGlobalRef<jobject> j_video_frame_buffer_; 149 const ScopedGlobalRef<jobject> j_video_frame_buffer_;
149 }; 150 };
150 151
151 class AndroidVideoBufferFactory { 152 class AndroidVideoBufferFactory {
152 public: 153 public:
153 explicit AndroidVideoBufferFactory(JNIEnv* jni); 154 explicit AndroidVideoBufferFactory(JNIEnv* jni);
154 155
155 webrtc::VideoFrame CreateFrame(JNIEnv* jni, 156 VideoFrame CreateFrame(JNIEnv* jni,
156 jobject j_video_frame, 157 jobject j_video_frame,
157 uint32_t timestamp_rtp) const; 158 uint32_t timestamp_rtp) const;
158 159
159 // Wraps a buffer to AndroidVideoBuffer without incrementing the reference 160 // Wraps a buffer to AndroidVideoBuffer without incrementing the reference
160 // count. 161 // count.
161 rtc::scoped_refptr<AndroidVideoBuffer> WrapBuffer( 162 rtc::scoped_refptr<AndroidVideoBuffer> WrapBuffer(
162 JNIEnv* jni, 163 JNIEnv* jni,
163 jobject j_video_frame_buffer) const; 164 jobject j_video_frame_buffer) const;
164 165
165 rtc::scoped_refptr<AndroidVideoBuffer> CreateBuffer( 166 rtc::scoped_refptr<AndroidVideoBuffer> CreateBuffer(
166 JNIEnv* jni, 167 JNIEnv* jni,
167 jobject j_video_frame_buffer) const; 168 jobject j_video_frame_buffer) const;
168 169
169 private: 170 private:
170 ScopedGlobalRef<jclass> j_video_frame_class_; 171 ScopedGlobalRef<jclass> j_video_frame_class_;
171 jmethodID j_get_buffer_id_; 172 jmethodID j_get_buffer_id_;
172 jmethodID j_get_rotation_id_; 173 jmethodID j_get_rotation_id_;
173 jmethodID j_get_timestamp_ns_id_; 174 jmethodID j_get_timestamp_ns_id_;
174 175
175 ScopedGlobalRef<jclass> j_video_frame_buffer_class_; 176 ScopedGlobalRef<jclass> j_video_frame_buffer_class_;
176 jmethodID j_retain_id_; 177 jmethodID j_retain_id_;
177 jmethodID j_release_id_; 178 jmethodID j_release_id_;
178 jmethodID j_get_width_id_; 179 jmethodID j_get_width_id_;
179 jmethodID j_get_height_id_; 180 jmethodID j_get_height_id_;
180 }; 181 };
181 182
182 class JavaVideoFrameFactory { 183 class JavaVideoFrameFactory {
183 public: 184 public:
184 JavaVideoFrameFactory(JNIEnv* jni); 185 JavaVideoFrameFactory(JNIEnv* jni);
185 186
186 jobject ToJavaFrame(JNIEnv* jni, const webrtc::VideoFrame& frame) const; 187 jobject ToJavaFrame(JNIEnv* jni, const VideoFrame& frame) const;
187 188
188 private: 189 private:
189 ScopedGlobalRef<jclass> j_video_frame_class_; 190 ScopedGlobalRef<jclass> j_video_frame_class_;
190 jmethodID j_video_frame_constructor_id_; 191 jmethodID j_video_frame_constructor_id_;
191 }; 192 };
192 193
193 } // namespace webrtc_jni 194 } // namespace jni
195 } // namespace webrtc
194 196
195 #endif // WEBRTC_SDK_ANDROID_SRC_JNI_NATIVE_HANDLE_IMPL_H_ 197 #endif // WEBRTC_SDK_ANDROID_SRC_JNI_NATIVE_HANDLE_IMPL_H_
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/jni/jni_onload.cc ('k') | webrtc/sdk/android/src/jni/native_handle_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698