OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 29 matching lines...) Expand all Loading... | |
40 int AndroidVideoCapturerJni::SetAndroidObjects(JNIEnv* jni, | 40 int AndroidVideoCapturerJni::SetAndroidObjects(JNIEnv* jni, |
41 jobject appliction_context) { | 41 jobject appliction_context) { |
42 if (application_context_) { | 42 if (application_context_) { |
43 jni->DeleteGlobalRef(application_context_); | 43 jni->DeleteGlobalRef(application_context_); |
44 } | 44 } |
45 application_context_ = NewGlobalRef(jni, appliction_context); | 45 application_context_ = NewGlobalRef(jni, appliction_context); |
46 | 46 |
47 return 0; | 47 return 0; |
48 } | 48 } |
49 | 49 |
50 AndroidVideoCapturerJni::AndroidVideoCapturerJni(JNIEnv* jni, | 50 AndroidVideoCapturerJni::AndroidVideoCapturerJni( |
51 jobject j_video_capturer) | 51 JNIEnv* jni, |
52 : j_capturer_global_(jni, j_video_capturer), | 52 jobject j_video_capturer, |
53 jobject j_surface_texture_helper) | |
54 : j_video_capturer_(jni, j_video_capturer), | |
55 j_surface_texture_helper_(jni, j_surface_texture_helper), | |
53 j_video_capturer_class_( | 56 j_video_capturer_class_( |
54 jni, FindClass(jni, "org/webrtc/VideoCapturerAndroid")), | 57 jni, FindClass(jni, "org/webrtc/VideoCapturerAndroid")), |
55 j_observer_class_( | 58 j_observer_class_( |
56 jni, | 59 jni, |
57 FindClass(jni, | 60 FindClass(jni, |
58 "org/webrtc/VideoCapturerAndroid$NativeObserver")), | 61 "org/webrtc/VideoCapturerAndroid$NativeObserver")), |
59 capturer_(nullptr) { | 62 capturer_(nullptr) { |
60 LOG(LS_INFO) << "AndroidVideoCapturerJni ctor"; | 63 LOG(LS_INFO) << "AndroidVideoCapturerJni ctor"; |
61 thread_checker_.DetachFromThread(); | 64 thread_checker_.DetachFromThread(); |
62 } | 65 } |
63 | 66 |
64 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { | 67 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { |
65 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; | 68 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; |
66 jni()->CallVoidMethod( | 69 jni()->CallVoidMethod( |
67 *j_capturer_global_, | 70 *j_video_capturer_, |
68 GetMethodID(jni(), *j_video_capturer_class_, "release", "()V")); | 71 GetMethodID(jni(), *j_video_capturer_class_, "release", "()V")); |
69 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.release()"; | 72 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.release()"; |
70 } | 73 } |
71 | 74 |
72 void AndroidVideoCapturerJni::Start(int width, int height, int framerate, | 75 void AndroidVideoCapturerJni::Start(int width, int height, int framerate, |
73 webrtc::AndroidVideoCapturer* capturer) { | 76 webrtc::AndroidVideoCapturer* capturer) { |
74 LOG(LS_INFO) << "AndroidVideoCapturerJni start"; | 77 LOG(LS_INFO) << "AndroidVideoCapturerJni start"; |
75 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 78 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
76 { | 79 { |
77 rtc::CritScope cs(&capturer_lock_); | 80 rtc::CritScope cs(&capturer_lock_); |
78 RTC_CHECK(capturer_ == nullptr); | 81 RTC_CHECK(capturer_ == nullptr); |
79 RTC_CHECK(invoker_.get() == nullptr); | 82 RTC_CHECK(invoker_.get() == nullptr); |
80 capturer_ = capturer; | 83 capturer_ = capturer; |
81 invoker_.reset(new rtc::GuardedAsyncInvoker()); | 84 invoker_.reset(new rtc::GuardedAsyncInvoker()); |
82 } | 85 } |
83 jobject j_frame_observer = | 86 jobject j_frame_observer = |
84 jni()->NewObject(*j_observer_class_, | 87 jni()->NewObject(*j_observer_class_, |
85 GetMethodID(jni(), *j_observer_class_, "<init>", "(J)V"), | 88 GetMethodID(jni(), *j_observer_class_, "<init>", "(J)V"), |
86 jlongFromPointer(this)); | 89 jlongFromPointer(this)); |
87 CHECK_EXCEPTION(jni()) << "error during NewObject"; | 90 CHECK_EXCEPTION(jni()) << "error during NewObject"; |
88 | 91 |
89 jmethodID m = GetMethodID( | 92 jmethodID m = GetMethodID( |
90 jni(), *j_video_capturer_class_, "startCapture", | 93 jni(), *j_video_capturer_class_, "startCapture", |
91 "(IIILandroid/content/Context;" | 94 "(IIILandroid/content/Context;" |
92 "Lorg/webrtc/VideoCapturerAndroid$CapturerObserver;)V"); | 95 "Lorg/webrtc/VideoCapturerAndroid$CapturerObserver;)V"); |
93 jni()->CallVoidMethod(*j_capturer_global_, | 96 jni()->CallVoidMethod(*j_video_capturer_, |
94 m, width, height, | 97 m, width, height, |
95 framerate, | 98 framerate, |
96 application_context_, | 99 application_context_, |
97 j_frame_observer); | 100 j_frame_observer); |
98 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.startCapture"; | 101 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.startCapture"; |
99 } | 102 } |
100 | 103 |
101 void AndroidVideoCapturerJni::Stop() { | 104 void AndroidVideoCapturerJni::Stop() { |
102 LOG(LS_INFO) << "AndroidVideoCapturerJni stop"; | 105 LOG(LS_INFO) << "AndroidVideoCapturerJni stop"; |
103 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 106 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
104 { | 107 { |
105 rtc::CritScope cs(&capturer_lock_); | 108 rtc::CritScope cs(&capturer_lock_); |
106 // Destroying |invoker_| will cancel all pending calls to |capturer_|. | 109 // Destroying |invoker_| will cancel all pending calls to |capturer_|. |
107 invoker_ = nullptr; | 110 invoker_ = nullptr; |
108 capturer_ = nullptr; | 111 capturer_ = nullptr; |
109 } | 112 } |
110 jmethodID m = GetMethodID(jni(), *j_video_capturer_class_, | 113 jmethodID m = GetMethodID(jni(), *j_video_capturer_class_, |
111 "stopCapture", "()V"); | 114 "stopCapture", "()V"); |
112 jni()->CallVoidMethod(*j_capturer_global_, m); | 115 jni()->CallVoidMethod(*j_video_capturer_, m); |
113 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.stopCapture"; | 116 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.stopCapture"; |
114 LOG(LS_INFO) << "AndroidVideoCapturerJni stop done"; | 117 LOG(LS_INFO) << "AndroidVideoCapturerJni stop done"; |
115 } | 118 } |
116 | 119 |
117 template <typename... Args> | 120 template <typename... Args> |
118 void AndroidVideoCapturerJni::AsyncCapturerInvoke( | 121 void AndroidVideoCapturerJni::AsyncCapturerInvoke( |
119 const char* method_name, | 122 const char* method_name, |
120 void (webrtc::AndroidVideoCapturer::*method)(Args...), | 123 void (webrtc::AndroidVideoCapturer::*method)(Args...), |
121 typename Identity<Args>::type... args) { | 124 typename Identity<Args>::type... args) { |
122 rtc::CritScope cs(&capturer_lock_); | 125 rtc::CritScope cs(&capturer_lock_); |
123 if (!invoker_) { | 126 if (!invoker_) { |
124 LOG(LS_WARNING) << method_name << "() called for closed capturer."; | 127 LOG(LS_WARNING) << method_name << "() called for closed capturer."; |
125 return; | 128 return; |
126 } | 129 } |
127 invoker_->AsyncInvoke<void>(rtc::Bind(method, capturer_, args...)); | 130 invoker_->AsyncInvoke<void>(rtc::Bind(method, capturer_, args...)); |
128 } | 131 } |
129 | 132 |
130 void AndroidVideoCapturerJni::ReturnBuffer(int64_t time_stamp) { | 133 void AndroidVideoCapturerJni::ReturnBuffer(int64_t time_stamp) { |
131 jmethodID m = GetMethodID(jni(), *j_video_capturer_class_, | 134 jmethodID m = GetMethodID(jni(), *j_video_capturer_class_, |
132 "returnBuffer", "(J)V"); | 135 "returnBuffer", "(J)V"); |
133 jni()->CallVoidMethod(*j_capturer_global_, m, time_stamp); | 136 jni()->CallVoidMethod(*j_video_capturer_, m, time_stamp); |
134 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.returnBuffer"; | 137 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.returnBuffer"; |
135 } | 138 } |
136 | 139 |
137 std::string AndroidVideoCapturerJni::GetSupportedFormats() { | 140 std::string AndroidVideoCapturerJni::GetSupportedFormats() { |
138 jmethodID m = | 141 jmethodID m = |
139 GetMethodID(jni(), *j_video_capturer_class_, | 142 GetMethodID(jni(), *j_video_capturer_class_, |
140 "getSupportedFormatsAsJson", "()Ljava/lang/String;"); | 143 "getSupportedFormatsAsJson", "()Ljava/lang/String;"); |
141 jstring j_json_caps = | 144 jstring j_json_caps = |
142 (jstring) jni()->CallObjectMethod(*j_capturer_global_, m); | 145 (jstring) jni()->CallObjectMethod(*j_video_capturer_, m); |
143 CHECK_EXCEPTION(jni()) << "error during supportedFormatsAsJson"; | 146 CHECK_EXCEPTION(jni()) << "error during supportedFormatsAsJson"; |
144 return JavaToStdString(jni(), j_json_caps); | 147 return JavaToStdString(jni(), j_json_caps); |
145 } | 148 } |
146 | 149 |
147 void AndroidVideoCapturerJni::OnCapturerStarted(bool success) { | 150 void AndroidVideoCapturerJni::OnCapturerStarted(bool success) { |
148 LOG(LS_INFO) << "AndroidVideoCapturerJni capture started: " << success; | 151 LOG(LS_INFO) << "AndroidVideoCapturerJni capture started: " << success; |
149 AsyncCapturerInvoke("OnCapturerStarted", | 152 AsyncCapturerInvoke("OnCapturerStarted", |
150 &webrtc::AndroidVideoCapturer::OnCapturerStarted, | 153 &webrtc::AndroidVideoCapturer::OnCapturerStarted, |
151 success); | 154 success); |
152 } | 155 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 << "NativeObserver_nativeOnFrameCaptured: frame is a copy"; | 222 << "NativeObserver_nativeOnFrameCaptured: frame is a copy"; |
220 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer) | 223 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer) |
221 ->OnMemoryBufferFrame(bytes, length, width, height, rotation, timestamp); | 224 ->OnMemoryBufferFrame(bytes, length, width, height, rotation, timestamp); |
222 jni->ReleaseByteArrayElements(j_frame, bytes, JNI_ABORT); | 225 jni->ReleaseByteArrayElements(j_frame, bytes, JNI_ABORT); |
223 } | 226 } |
224 | 227 |
225 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnTextureFrameCaptured) | 228 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnTextureFrameCaptured) |
226 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, | 229 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, |
227 jint j_oes_texture_id, jfloatArray j_transform_matrix, | 230 jint j_oes_texture_id, jfloatArray j_transform_matrix, |
228 jlong j_timestamp) { | 231 jlong j_timestamp) { |
229 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer) | 232 AndroidVideoCapturerJni *capturer = |
230 ->OnTextureFrame(j_width, j_height, j_timestamp, | 233 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer); |
231 NativeHandleImpl(jni, j_oes_texture_id, | 234 capturer->OnTextureFrame(j_width, j_height, j_timestamp, |
232 j_transform_matrix)); | 235 NativeHandleImpl(jni, j_oes_texture_id, |
236 j_transform_matrix, | |
237 capturer->GetSurfaceHelper())); | |
magjed_webrtc
2015/12/03 12:33:58
If this is the only use of GetSurfaceHelper(), I w
| |
233 } | 238 } |
234 | 239 |
235 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeCapturerStarted) | 240 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeCapturerStarted) |
236 (JNIEnv* jni, jclass, jlong j_capturer, jboolean j_success) { | 241 (JNIEnv* jni, jclass, jlong j_capturer, jboolean j_success) { |
237 LOG(LS_INFO) << "NativeObserver_nativeCapturerStarted"; | 242 LOG(LS_INFO) << "NativeObserver_nativeCapturerStarted"; |
238 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnCapturerStarted( | 243 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnCapturerStarted( |
239 j_success); | 244 j_success); |
240 } | 245 } |
241 | 246 |
242 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnOutputFormatRequest) | 247 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnOutputFormatRequest) |
243 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, | 248 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, |
244 jint j_fps) { | 249 jint j_fps) { |
245 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; | 250 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; |
246 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( | 251 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( |
247 j_width, j_height, j_fps); | 252 j_width, j_height, j_fps); |
248 } | 253 } |
249 | 254 |
250 JOW(jlong, VideoCapturerAndroid_nativeCreateVideoCapturer) | 255 JOW(jlong, VideoCapturerAndroid_nativeCreateVideoCapturer) |
251 (JNIEnv* jni, jclass, jobject j_video_capturer) { | 256 (JNIEnv* jni, jclass, |
257 jobject j_video_capturer, jobject j_surface_texture_helper) { | |
252 rtc::scoped_refptr<webrtc::AndroidVideoCapturerDelegate> delegate = | 258 rtc::scoped_refptr<webrtc::AndroidVideoCapturerDelegate> delegate = |
253 new rtc::RefCountedObject<AndroidVideoCapturerJni>(jni, j_video_capturer); | 259 new rtc::RefCountedObject<AndroidVideoCapturerJni>( |
260 jni, j_video_capturer, j_surface_texture_helper); | |
254 rtc::scoped_ptr<cricket::VideoCapturer> capturer( | 261 rtc::scoped_ptr<cricket::VideoCapturer> capturer( |
255 new webrtc::AndroidVideoCapturer(delegate)); | 262 new webrtc::AndroidVideoCapturer(delegate)); |
256 // Caller takes ownership of the cricket::VideoCapturer* pointer. | 263 // Caller takes ownership of the cricket::VideoCapturer* pointer. |
257 return jlongFromPointer(capturer.release()); | 264 return jlongFromPointer(capturer.release()); |
258 } | 265 } |
259 | 266 |
260 } // namespace webrtc_jni | 267 } // namespace webrtc_jni |
OLD | NEW |