| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_ | 5 #ifndef MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_ |
| 6 #define MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_ | 6 #define MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 15 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 16 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 18 #include "media/capture/capture_export.h" | 17 #include "media/capture/capture_export.h" |
| 19 #include "media/capture/video/video_capture_device.h" | 18 #include "media/capture/video/video_capture_device.h" |
| 20 | 19 |
| 21 namespace base { | |
| 22 class SingleThreadTaskRunner; | |
| 23 } | |
| 24 | |
| 25 namespace tracked_objects { | 20 namespace tracked_objects { |
| 26 class Location; | 21 class Location; |
| 27 } // namespace tracked_objects | 22 } // namespace tracked_ |
| 28 | 23 |
| 29 namespace media { | 24 namespace media { |
| 30 | 25 |
| 31 // VideoCaptureDevice on Android. The VideoCaptureDevice API's are called | 26 // VideoCaptureDevice on Android. The VideoCaptureDevice API's are called |
| 32 // by VideoCaptureManager on its own thread, while OnFrameAvailable is called | 27 // by VideoCaptureManager on its own thread, while OnFrameAvailable is called |
| 33 // on JAVA thread (i.e., UI thread). Both will access |state_| and |client_|, | 28 // on JAVA thread (i.e., UI thread). Both will access |state_| and |client_|, |
| 34 // but only VideoCaptureManager would change their value. | 29 // but only VideoCaptureManager would change their value. |
| 35 class CAPTURE_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice { | 30 class CAPTURE_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice { |
| 36 public: | 31 public: |
| 37 // Automatically generated enum to interface with Java world. | 32 // Automatically generated enum to interface with Java world. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 const base::android::JavaParamRef<jstring>& message); | 90 const base::android::JavaParamRef<jstring>& message); |
| 96 | 91 |
| 97 // Implement org.chromium.media.VideoCapture.nativeOnPhotoTaken. | 92 // Implement org.chromium.media.VideoCapture.nativeOnPhotoTaken. |
| 98 void OnPhotoTaken(JNIEnv* env, | 93 void OnPhotoTaken(JNIEnv* env, |
| 99 const base::android::JavaParamRef<jobject>& obj, | 94 const base::android::JavaParamRef<jobject>& obj, |
| 100 jlong callback_id, | 95 jlong callback_id, |
| 101 const base::android::JavaParamRef<jbyteArray>& data); | 96 const base::android::JavaParamRef<jbyteArray>& data); |
| 102 | 97 |
| 103 private: | 98 private: |
| 104 enum InternalState { | 99 enum InternalState { |
| 105 kIdle, // The device is opened but not in use. | 100 kIdle, // The device is opened but not in use. |
| 106 kConfigured, // The device has been AllocateAndStart()ed. | 101 kCapturing, // Video is being captured. |
| 107 kError // Hit error. User needs to recover by destroying the object. | 102 kError // Hit error. User needs to recover by destroying the object. |
| 108 }; | 103 }; |
| 109 | 104 |
| 110 VideoPixelFormat GetColorspace(); | 105 VideoPixelFormat GetColorspace(); |
| 111 void SetErrorState(const tracked_objects::Location& from_here, | 106 void SetErrorState(const tracked_objects::Location& from_here, |
| 112 const std::string& reason); | 107 const std::string& reason); |
| 113 | 108 |
| 114 void DoGetPhotoCapabilities(GetPhotoCapabilitiesCallback callback); | 109 base::ThreadChecker thread_checker_; |
| 115 void DoSetPhotoOptions(mojom::PhotoSettingsPtr settings, | |
| 116 SetPhotoOptionsCallback callback); | |
| 117 void DoTakePhoto(TakePhotoCallback callback); | |
| 118 | 110 |
| 119 // Thread on which we are created. | 111 // Prevent racing on accessing |state_| and |client_| since both could be |
| 120 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 112 // accessed from different threads. |
| 121 | |
| 122 // |lock_| protects |state_|, |client_|, |got_first_frame_| and | |
| 123 // |photo_requests_queue_| from concurrent access. | |
| 124 base::Lock lock_; | 113 base::Lock lock_; |
| 125 InternalState state_; | 114 InternalState state_; |
| 126 std::unique_ptr<VideoCaptureDevice::Client> client_; | 115 std::unique_ptr<VideoCaptureDevice::Client> client_; |
| 116 |
| 127 bool got_first_frame_; | 117 bool got_first_frame_; |
| 128 // Photo-related requests waiting for |got_first_frame_| to be served. Android | |
| 129 // APIs need the device capturing or nearly-capturing to be fully oeprational. | |
| 130 std::list<base::Closure> photo_requests_queue_; | |
| 131 | |
| 132 base::TimeTicks expected_next_frame_time_; | 118 base::TimeTicks expected_next_frame_time_; |
| 133 base::TimeTicks first_ref_time_; | 119 base::TimeTicks first_ref_time_; |
| 134 base::TimeDelta frame_interval_; | 120 base::TimeDelta frame_interval_; |
| 135 | 121 |
| 136 // List of |photo_callbacks_| in flight, being served in Java side. | 122 // List of |photo_callbacks_| in flight, being served in Java side. |
| 137 base::Lock photo_callbacks_lock_; | 123 base::Lock photo_callbacks_lock_; |
| 138 std::list<std::unique_ptr<TakePhotoCallback>> photo_callbacks_; | 124 std::list<std::unique_ptr<TakePhotoCallback>> photo_callbacks_; |
| 139 | 125 |
| 140 gfx::Size next_photo_resolution_; | 126 gfx::Size next_photo_resolution_; |
| 141 | 127 |
| 142 const VideoCaptureDeviceDescriptor device_descriptor_; | 128 const VideoCaptureDeviceDescriptor device_descriptor_; |
| 143 VideoCaptureFormat capture_format_; | 129 VideoCaptureFormat capture_format_; |
| 144 | 130 |
| 145 // Java VideoCaptureAndroid instance. | 131 // Java VideoCaptureAndroid instance. |
| 146 base::android::ScopedJavaLocalRef<jobject> j_capture_; | 132 base::android::ScopedJavaLocalRef<jobject> j_capture_; |
| 147 | 133 |
| 148 base::WeakPtrFactory<VideoCaptureDeviceAndroid> weak_ptr_factory_; | |
| 149 | |
| 150 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceAndroid); | 134 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceAndroid); |
| 151 }; | 135 }; |
| 152 | 136 |
| 153 } // namespace media | 137 } // namespace media |
| 154 | 138 |
| 155 #endif // MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_ | 139 #endif // MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_ |
| OLD | NEW |