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

Side by Side Diff: media/capture/video/android/video_capture_device_android.h

Issue 2212343003: Reland: ImageCapture: Queue up requests while device not ready (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable Android tests with bug and explanation Created 4 years, 4 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 // 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"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
14 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
15 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "media/capture/capture_export.h" 18 #include "media/capture/capture_export.h"
18 #include "media/capture/video/video_capture_device.h" 19 #include "media/capture/video/video_capture_device.h"
19 20
21 namespace base {
22 class SingleThreadTaskRunner;
23 }
24
20 namespace tracked_objects { 25 namespace tracked_objects {
21 class Location; 26 class Location;
22 } // namespace tracked_ 27 } // namespace tracked_objects
23 28
24 namespace media { 29 namespace media {
25 30
26 // VideoCaptureDevice on Android. The VideoCaptureDevice API's are called 31 // VideoCaptureDevice on Android. The VideoCaptureDevice API's are called
27 // by VideoCaptureManager on its own thread, while OnFrameAvailable is called 32 // by VideoCaptureManager on its own thread, while OnFrameAvailable is called
28 // on JAVA thread (i.e., UI thread). Both will access |state_| and |client_|, 33 // on JAVA thread (i.e., UI thread). Both will access |state_| and |client_|,
29 // but only VideoCaptureManager would change their value. 34 // but only VideoCaptureManager would change their value.
30 class CAPTURE_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice { 35 class CAPTURE_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice {
31 public: 36 public:
32 // Automatically generated enum to interface with Java world. 37 // Automatically generated enum to interface with Java world.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 const base::android::JavaParamRef<jstring>& message); 95 const base::android::JavaParamRef<jstring>& message);
91 96
92 // Implement org.chromium.media.VideoCapture.nativeOnPhotoTaken. 97 // Implement org.chromium.media.VideoCapture.nativeOnPhotoTaken.
93 void OnPhotoTaken(JNIEnv* env, 98 void OnPhotoTaken(JNIEnv* env,
94 const base::android::JavaParamRef<jobject>& obj, 99 const base::android::JavaParamRef<jobject>& obj,
95 jlong callback_id, 100 jlong callback_id,
96 const base::android::JavaParamRef<jbyteArray>& data); 101 const base::android::JavaParamRef<jbyteArray>& data);
97 102
98 private: 103 private:
99 enum InternalState { 104 enum InternalState {
100 kIdle, // The device is opened but not in use. 105 kIdle, // The device is opened but not in use.
101 kCapturing, // Video is being captured. 106 kConfigured, // The device has been AllocateAndStart()ed.
102 kError // Hit error. User needs to recover by destroying the object. 107 kError // Hit error. User needs to recover by destroying the object.
103 }; 108 };
104 109
105 VideoPixelFormat GetColorspace(); 110 VideoPixelFormat GetColorspace();
106 void SetErrorState(const tracked_objects::Location& from_here, 111 void SetErrorState(const tracked_objects::Location& from_here,
107 const std::string& reason); 112 const std::string& reason);
108 113
109 base::ThreadChecker thread_checker_; 114 void DoGetPhotoCapabilities(GetPhotoCapabilitiesCallback callback);
115 void DoSetPhotoOptions(mojom::PhotoSettingsPtr settings,
116 SetPhotoOptionsCallback callback);
117 void DoTakePhoto(TakePhotoCallback callback);
110 118
111 // Prevent racing on accessing |state_| and |client_| since both could be 119 // Thread on which we are created.
112 // accessed from different threads. 120 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
121
122 // |lock_| protects |state_|, |client_|, |got_first_frame_| and
123 // |photo_requests_queue_| from concurrent access.
113 base::Lock lock_; 124 base::Lock lock_;
114 InternalState state_; 125 InternalState state_;
115 std::unique_ptr<VideoCaptureDevice::Client> client_; 126 std::unique_ptr<VideoCaptureDevice::Client> client_;
127 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_;
116 131
117 bool got_first_frame_;
118 base::TimeTicks expected_next_frame_time_; 132 base::TimeTicks expected_next_frame_time_;
119 base::TimeTicks first_ref_time_; 133 base::TimeTicks first_ref_time_;
120 base::TimeDelta frame_interval_; 134 base::TimeDelta frame_interval_;
121 135
122 // List of |photo_callbacks_| in flight, being served in Java side. 136 // List of |photo_callbacks_| in flight, being served in Java side.
123 base::Lock photo_callbacks_lock_; 137 base::Lock photo_callbacks_lock_;
124 std::list<std::unique_ptr<TakePhotoCallback>> photo_callbacks_; 138 std::list<std::unique_ptr<TakePhotoCallback>> photo_callbacks_;
125 139
126 gfx::Size next_photo_resolution_; 140 gfx::Size next_photo_resolution_;
127 141
128 const VideoCaptureDeviceDescriptor device_descriptor_; 142 const VideoCaptureDeviceDescriptor device_descriptor_;
129 VideoCaptureFormat capture_format_; 143 VideoCaptureFormat capture_format_;
130 144
131 // Java VideoCaptureAndroid instance. 145 // Java VideoCaptureAndroid instance.
132 base::android::ScopedJavaLocalRef<jobject> j_capture_; 146 base::android::ScopedJavaLocalRef<jobject> j_capture_;
133 147
148 base::WeakPtrFactory<VideoCaptureDeviceAndroid> weak_ptr_factory_;
149
134 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceAndroid); 150 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceAndroid);
135 }; 151 };
136 152
137 } // namespace media 153 } // namespace media
138 154
139 #endif // MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_ 155 #endif // MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_
OLDNEW
« no previous file with comments | « content/test/data/media/image_capture_test.html ('k') | media/capture/video/android/video_capture_device_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698