Disable firewall check. It takes signifficant time, need to be on FILE thread.
[chromium-blink-merge.git] / media / video / capture / android / video_capture_device_android.h
blob958036fe1e94017e1b4cc45490968c9e07d4a5df
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.
5 #ifndef MEDIA_VIDEO_CAPTURE_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_
6 #define MEDIA_VIDEO_CAPTURE_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_
8 #include <jni.h>
9 #include <string>
11 #include "base/android/scoped_java_ref.h"
12 #include "base/synchronization/lock.h"
13 #include "base/threading/thread.h"
14 #include "base/time/time.h"
15 #include "media/base/media_export.h"
16 #include "media/video/capture/video_capture_device.h"
18 namespace media {
20 // VideoCaptureDevice on Android. The VideoCaptureDevice API's are called
21 // by VideoCaptureManager on its own thread, while OnFrameAvailable is called
22 // on JAVA thread (i.e., UI thread). Both will access |state_| and |client_|,
23 // but only VideoCaptureManager would change their value.
24 class MEDIA_EXPORT VideoCaptureDeviceAndroid : public VideoCaptureDevice {
25 public:
26 // Automatically generated enum to interface with Java world.
27 enum AndroidImageFormat {
28 #define DEFINE_ANDROID_IMAGEFORMAT(name, value) name = value,
29 #include "media/video/capture/android/imageformat_list.h"
30 #undef DEFINE_ANDROID_IMAGEFORMAT
33 virtual ~VideoCaptureDeviceAndroid();
35 static VideoCaptureDevice* Create(const Name& device_name);
36 static bool RegisterVideoCaptureDevice(JNIEnv* env);
38 // VideoCaptureDevice implementation.
39 virtual void AllocateAndStart(const VideoCaptureParams& params,
40 scoped_ptr<Client> client) OVERRIDE;
41 virtual void StopAndDeAllocate() OVERRIDE;
43 // Implement org.chromium.media.VideoCapture.nativeOnFrameAvailable.
44 void OnFrameAvailable(
45 JNIEnv* env,
46 jobject obj,
47 jbyteArray data,
48 jint length,
49 jint rotation);
51 private:
52 enum InternalState {
53 kIdle, // The device is opened but not in use.
54 kCapturing, // Video is being captured.
55 kError // Hit error. User needs to recover by destroying the object.
58 explicit VideoCaptureDeviceAndroid(const Name& device_name);
59 bool Init();
60 VideoPixelFormat GetColorspace();
61 void SetErrorState(const std::string& reason);
63 // Prevent racing on accessing |state_| and |client_| since both could be
64 // accessed from different threads.
65 base::Lock lock_;
66 InternalState state_;
67 bool got_first_frame_;
68 base::TimeTicks expected_next_frame_time_;
69 base::TimeDelta frame_interval_;
70 scoped_ptr<VideoCaptureDevice::Client> client_;
72 Name device_name_;
73 VideoCaptureFormat capture_format_;
75 // Java VideoCaptureAndroid instance.
76 base::android::ScopedJavaLocalRef<jobject> j_capture_;
78 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceAndroid);
81 } // namespace media
83 #endif // MEDIA_VIDEO_CAPTURE_ANDROID_VIDEO_CAPTURE_DEVICE_ANDROID_H_