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

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

Issue 2214533002: move //media/capture to //device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_
6 #define MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_
7
8 #include <jni.h>
9 #include <string>
10
11 #include "base/android/scoped_java_ref.h"
12 #include "base/macros.h"
13 #include "base/synchronization/lock.h"
14 #include "base/threading/thread.h"
15 #include "base/threading/thread_checker.h"
16 #include "base/time/time.h"
17 #include "media/capture/capture_export.h"
18 #include "media/capture/video/video_capture_device.h"
19
20 namespace tracked_objects {
21 class Location;
22 } // namespace tracked_
23
24 namespace media {
25
26 // VideoCaptureDevice on Android. The VideoCaptureDevice API's are called
27 // by VideoCaptureManager on its own thread, while OnFrameAvailable is called
28 // on JAVA thread (i.e., UI thread). Both will access |state_| and |client_|,
29 // but only VideoCaptureManager would change their value.
30 class CAPTURE_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice {
31 public:
32 // Automatically generated enum to interface with Java world.
33 //
34 // A Java counterpart will be generated for this enum.
35 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.media
36 enum AndroidImageFormat {
37 // Android graphics ImageFormat mapping, see reference in:
38 // http://developer.android.com/reference/android/graphics/ImageFormat.html
39 ANDROID_IMAGE_FORMAT_NV21 = 17,
40 ANDROID_IMAGE_FORMAT_YUV_420_888 = 35,
41 ANDROID_IMAGE_FORMAT_YV12 = 842094169,
42 ANDROID_IMAGE_FORMAT_UNKNOWN = 0,
43 };
44
45 explicit VideoCaptureDeviceAndroid(
46 const VideoCaptureDeviceDescriptor& device_descriptor);
47 ~VideoCaptureDeviceAndroid() override;
48
49 static VideoCaptureDevice* Create(
50 const VideoCaptureDeviceDescriptor& device_descriptor);
51 static bool RegisterVideoCaptureDevice(JNIEnv* env);
52
53 // Registers the Java VideoCaptureDevice pointer, used by the rest of the
54 // methods of the class to operate the Java capture code. This method must be
55 // called after the class constructor and before AllocateAndStart().
56 bool Init();
57
58 // VideoCaptureDevice implementation.
59 void AllocateAndStart(const VideoCaptureParams& params,
60 std::unique_ptr<Client> client) override;
61 void StopAndDeAllocate() override;
62 void GetPhotoCapabilities(GetPhotoCapabilitiesCallback callback) override;
63 void SetPhotoOptions(mojom::PhotoSettingsPtr settings,
64 SetPhotoOptionsCallback callback) override;
65 void TakePhoto(TakePhotoCallback callback) override;
66
67 // Implement org.chromium.media.VideoCapture.nativeOnFrameAvailable.
68 void OnFrameAvailable(JNIEnv* env,
69 const base::android::JavaParamRef<jobject>& obj,
70 const base::android::JavaParamRef<jbyteArray>& data,
71 jint length,
72 jint rotation);
73
74 // Implement org.chromium.media.VideoCapture.nativeOnI420FrameAvailable.
75 void OnI420FrameAvailable(JNIEnv* env,
76 jobject obj,
77 jobject y_buffer,
78 jint y_stride,
79 jobject u_buffer,
80 jobject v_buffer,
81 jint uv_row_stride,
82 jint uv_pixel_stride,
83 jint width,
84 jint height,
85 jint rotation);
86
87 // Implement org.chromium.media.VideoCapture.nativeOnError.
88 void OnError(JNIEnv* env,
89 const base::android::JavaParamRef<jobject>& obj,
90 const base::android::JavaParamRef<jstring>& message);
91
92 // Implement org.chromium.media.VideoCapture.nativeOnPhotoTaken.
93 void OnPhotoTaken(JNIEnv* env,
94 const base::android::JavaParamRef<jobject>& obj,
95 jlong callback_id,
96 const base::android::JavaParamRef<jbyteArray>& data);
97
98 private:
99 enum InternalState {
100 kIdle, // The device is opened but not in use.
101 kCapturing, // Video is being captured.
102 kError // Hit error. User needs to recover by destroying the object.
103 };
104
105 VideoPixelFormat GetColorspace();
106 void SetErrorState(const tracked_objects::Location& from_here,
107 const std::string& reason);
108
109 base::ThreadChecker thread_checker_;
110
111 // Prevent racing on accessing |state_| and |client_| since both could be
112 // accessed from different threads.
113 base::Lock lock_;
114 InternalState state_;
115 std::unique_ptr<VideoCaptureDevice::Client> client_;
116
117 bool got_first_frame_;
118 base::TimeTicks expected_next_frame_time_;
119 base::TimeTicks first_ref_time_;
120 base::TimeDelta frame_interval_;
121
122 // List of |photo_callbacks_| in flight, being served in Java side.
123 base::Lock photo_callbacks_lock_;
124 std::list<std::unique_ptr<TakePhotoCallback>> photo_callbacks_;
125
126 gfx::Size next_photo_resolution_;
127
128 const VideoCaptureDeviceDescriptor device_descriptor_;
129 VideoCaptureFormat capture_format_;
130
131 // Java VideoCaptureAndroid instance.
132 base::android::ScopedJavaLocalRef<jobject> j_capture_;
133
134 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceAndroid);
135 };
136
137 } // namespace media
138
139 #endif // MEDIA_CAPTURE_VIDEO_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_
OLDNEW
« no previous file with comments | « media/capture/video/android/photo_capabilities.cc ('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