OLD | NEW |
(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_VIDEO_CAPTURE_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_ |
| 6 #define MEDIA_VIDEO_CAPTURE_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/synchronization/lock.h" |
| 13 #include "base/threading/thread.h" |
| 14 #include "media/video/capture/video_capture_device.h" |
| 15 |
| 16 namespace media { |
| 17 |
| 18 // VideoCaptureDevice on Android. The VideoCaptureDevice API's are called |
| 19 // by VideoCaptureManager on its own thread, while OnFrameAvailable is called |
| 20 // on JAVA thread (i.e., UI thread). Both will access |state_| and |observer_|, |
| 21 // but only VideoCaptureManager would change their value. |
| 22 class VideoCaptureDeviceAndroid : public VideoCaptureDevice { |
| 23 public: |
| 24 virtual ~VideoCaptureDeviceAndroid(); |
| 25 |
| 26 static VideoCaptureDevice* Create(const Name& device_name); |
| 27 static bool RegisterVideoCaptureDevice(JNIEnv* env); |
| 28 |
| 29 // VideoCaptureDevice implementation. |
| 30 virtual void Allocate(int width, |
| 31 int height, |
| 32 int frame_rate, |
| 33 EventHandler* observer) OVERRIDE; |
| 34 virtual void Start() OVERRIDE; |
| 35 virtual void Stop() OVERRIDE; |
| 36 virtual void DeAllocate() OVERRIDE; |
| 37 virtual const Name& device_name() OVERRIDE; |
| 38 |
| 39 // Implement org.chromium.media.VideoCapture.nativeOnFrameAvailable. |
| 40 void OnFrameAvailable( |
| 41 JNIEnv* env, |
| 42 jobject obj, |
| 43 jbyteArray data, |
| 44 jint length, |
| 45 jint rotation, |
| 46 jboolean flip_vert, |
| 47 jboolean flip_horiz); |
| 48 |
| 49 private: |
| 50 enum InternalState { |
| 51 kIdle, // The device is opened but not in use. |
| 52 kAllocated, // All resouces have been allocated and camera can be started. |
| 53 kCapturing, // Video is being captured. |
| 54 kError // Hit error. User needs to recover by destroying the object. |
| 55 }; |
| 56 |
| 57 explicit VideoCaptureDeviceAndroid(const Name& device_name); |
| 58 bool Init(); |
| 59 void SetErrorState(const std::string& reason); |
| 60 |
| 61 // Prevent racing on accessing |state_| and |observer_| since both could be |
| 62 // accessed from different threads. |
| 63 base::Lock lock_; |
| 64 InternalState state_; |
| 65 VideoCaptureDevice::EventHandler* observer_; |
| 66 |
| 67 Name device_name_; |
| 68 VideoCaptureCapability current_settings_; |
| 69 scoped_ptr<uint8[]> rotation_buffer_; |
| 70 int rotation_; |
| 71 |
| 72 // Java VideoCaptureAndroid instance. |
| 73 base::android::ScopedJavaGlobalRef<jobject> j_capture_; |
| 74 |
| 75 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceAndroid); |
| 76 }; |
| 77 |
| 78 } // namespace media |
| 79 |
| 80 #endif // MEDIA_VIDEO_CAPTURE_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_ |
OLD | NEW |