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 16 matching lines...) Expand all Loading... |
27 */ | 27 */ |
28 | 28 |
29 #include "talk/app/webrtc/java/jni/androidvideocapturer_jni.h" | 29 #include "talk/app/webrtc/java/jni/androidvideocapturer_jni.h" |
30 #include "talk/app/webrtc/java/jni/classreferenceholder.h" | 30 #include "talk/app/webrtc/java/jni/classreferenceholder.h" |
31 #include "talk/app/webrtc/java/jni/native_handle_impl.h" | 31 #include "talk/app/webrtc/java/jni/native_handle_impl.h" |
32 #include "webrtc/base/bind.h" | 32 #include "webrtc/base/bind.h" |
33 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 33 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
34 | 34 |
35 namespace webrtc_jni { | 35 namespace webrtc_jni { |
36 | 36 |
| 37 namespace { |
| 38 |
| 39 class CameraTextureBuffer : public webrtc::NativeHandleBuffer { |
| 40 public: |
| 41 CameraTextureBuffer(int width, int height, |
| 42 const NativeHandleImpl& native_handle, |
| 43 const rtc::Callback0<void>& no_longer_used) |
| 44 : webrtc::NativeHandleBuffer(&native_handle_, width, height), |
| 45 native_handle_(native_handle), |
| 46 no_longer_used_cb_(no_longer_used) {} |
| 47 |
| 48 ~CameraTextureBuffer() { |
| 49 no_longer_used_cb_(); |
| 50 } |
| 51 |
| 52 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { |
| 53 RTC_NOTREACHED() |
| 54 << "CameraTextureBuffer::NativeToI420Buffer not implemented."; |
| 55 return nullptr; |
| 56 } |
| 57 |
| 58 private: |
| 59 NativeHandleImpl native_handle_; |
| 60 rtc::Callback0<void> no_longer_used_cb_; |
| 61 }; |
| 62 |
| 63 } // anonymous namespace |
| 64 |
37 jobject AndroidVideoCapturerJni::application_context_ = nullptr; | 65 jobject AndroidVideoCapturerJni::application_context_ = nullptr; |
38 | 66 |
39 // static | 67 // static |
40 int AndroidVideoCapturerJni::SetAndroidObjects(JNIEnv* jni, | 68 int AndroidVideoCapturerJni::SetAndroidObjects(JNIEnv* jni, |
41 jobject appliction_context) { | 69 jobject appliction_context) { |
42 if (application_context_) { | 70 if (application_context_) { |
43 jni->DeleteGlobalRef(application_context_); | 71 jni->DeleteGlobalRef(application_context_); |
44 } | 72 } |
45 application_context_ = NewGlobalRef(jni, appliction_context); | 73 application_context_ = NewGlobalRef(jni, appliction_context); |
46 | 74 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 AsyncCapturerInvoke("OnIncomingFrame", | 206 AsyncCapturerInvoke("OnIncomingFrame", |
179 &webrtc::AndroidVideoCapturer::OnIncomingFrame, | 207 &webrtc::AndroidVideoCapturer::OnIncomingFrame, |
180 buffer, rotation, timestamp_ns); | 208 buffer, rotation, timestamp_ns); |
181 } | 209 } |
182 | 210 |
183 void AndroidVideoCapturerJni::OnTextureFrame(int width, | 211 void AndroidVideoCapturerJni::OnTextureFrame(int width, |
184 int height, | 212 int height, |
185 int64_t timestamp_ns, | 213 int64_t timestamp_ns, |
186 const NativeHandleImpl& handle) { | 214 const NativeHandleImpl& handle) { |
187 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer( | 215 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer( |
188 new rtc::RefCountedObject<AndroidTextureBuffer>( | 216 new rtc::RefCountedObject<CameraTextureBuffer>( |
189 width, height, handle, | 217 width, height, handle, |
190 rtc::Bind(&AndroidVideoCapturerJni::ReturnBuffer, this, | 218 rtc::Bind(&AndroidVideoCapturerJni::ReturnBuffer, this, |
191 timestamp_ns))); | 219 timestamp_ns))); |
192 AsyncCapturerInvoke("OnIncomingFrame", | 220 AsyncCapturerInvoke("OnIncomingFrame", |
193 &webrtc::AndroidVideoCapturer::OnIncomingFrame, | 221 &webrtc::AndroidVideoCapturer::OnIncomingFrame, |
194 buffer, 0, timestamp_ns); | 222 buffer, 0, timestamp_ns); |
195 } | 223 } |
196 | 224 |
197 void AndroidVideoCapturerJni::OnOutputFormatRequest(int width, | 225 void AndroidVideoCapturerJni::OnOutputFormatRequest(int width, |
198 int height, | 226 int height, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 (JNIEnv* jni, jclass, jobject j_video_capturer) { | 279 (JNIEnv* jni, jclass, jobject j_video_capturer) { |
252 rtc::scoped_refptr<webrtc::AndroidVideoCapturerDelegate> delegate = | 280 rtc::scoped_refptr<webrtc::AndroidVideoCapturerDelegate> delegate = |
253 new rtc::RefCountedObject<AndroidVideoCapturerJni>(jni, j_video_capturer); | 281 new rtc::RefCountedObject<AndroidVideoCapturerJni>(jni, j_video_capturer); |
254 rtc::scoped_ptr<cricket::VideoCapturer> capturer( | 282 rtc::scoped_ptr<cricket::VideoCapturer> capturer( |
255 new webrtc::AndroidVideoCapturer(delegate)); | 283 new webrtc::AndroidVideoCapturer(delegate)); |
256 // Caller takes ownership of the cricket::VideoCapturer* pointer. | 284 // Caller takes ownership of the cricket::VideoCapturer* pointer. |
257 return jlongFromPointer(capturer.release()); | 285 return jlongFromPointer(capturer.release()); |
258 } | 286 } |
259 | 287 |
260 } // namespace webrtc_jni | 288 } // namespace webrtc_jni |
OLD | NEW |