Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / media / video / capture / fake_video_capture_device.h
index 174ba06..96264e8 100644 (file)
 
 #include <string>
 
+#include "base/atomicops.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/threading/thread.h"
+#include "base/threading/thread_checker.h"
 #include "media/video/capture/video_capture_device.h"
 
 namespace media {
 
 class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice {
  public:
-  static VideoCaptureDevice* Create(const Name& device_name);
-  virtual ~FakeVideoCaptureDevice();
-  // Used for testing. This will make sure the next call to Create will
-  // return NULL;
-  static void SetFailNextCreate();
+  static const int kFakeCaptureTimeoutMs = 50;
 
-  static void GetDeviceNames(Names* device_names);
-  static void GetDeviceSupportedFormats(const Name& device,
-                                        VideoCaptureCapabilities* formats);
+  FakeVideoCaptureDevice();
+  virtual ~FakeVideoCaptureDevice();
 
   // VideoCaptureDevice implementation.
   virtual void AllocateAndStart(
-      const VideoCaptureCapability& capture_format,
+      const VideoCaptureParams& params,
       scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE;
   virtual void StopAndDeAllocate() OVERRIDE;
 
- private:
-  // Flag indicating the internal state.
-  enum InternalState {
-    kIdle,
-    kCapturing,
-    kError
-  };
-  FakeVideoCaptureDevice();
+  // Sets the formats to use sequentially when the device is configured as
+  // variable capture resolution. Works only before AllocateAndStart() or
+  // after StopAndDeallocate().
+  void PopulateVariableFormatsRoster(const VideoCaptureFormats& formats);
 
-  // Called on the capture_thread_.
+ private:
+  // Called on the |capture_thread_| only.
+  void OnAllocateAndStart(const VideoCaptureParams& params,
+                          scoped_ptr<Client> client);
+  void OnStopAndDeAllocate();
   void OnCaptureTask();
-
-  // EXPERIMENTAL, similar to allocate, but changes resolution and calls
-  // client->OnFrameInfoChanged(VideoCaptureCapability&)
   void Reallocate();
-  void PopulateCapabilitiesRoster();
 
-  scoped_ptr<VideoCaptureDevice::Client> client_;
-  InternalState state_;
+  // |thread_checker_| is used to check that destructor, AllocateAndStart() and
+  // StopAndDeAllocate() are called in the correct thread that owns the object.
+  base::ThreadChecker thread_checker_;
+
   base::Thread capture_thread_;
+  // The following members are only used on the |capture_thread_|.
+  scoped_ptr<VideoCaptureDevice::Client> client_;
   scoped_ptr<uint8[]> fake_frame_;
   int frame_count_;
-  VideoCaptureCapability capture_format_;
-
-  // When the device is configured as mutating video captures, this vector
-  // holds the available ones which are used in sequence, restarting at the end.
-  std::vector<VideoCaptureCapability> capabilities_roster_;
-  int capabilities_roster_index_;
-
-  static bool fail_next_create_;
+  VideoCaptureFormat capture_format_;
+
+  // When the device is allowed to change resolution, this vector holds the
+  // available ones, used sequentially restarting at the end. These two members
+  // are initialised in PopulateFormatRoster() before |capture_thread_| is
+  // running and are subsequently read-only in that thread.
+  std::vector<VideoCaptureFormat> format_roster_;
+  int format_roster_index_;
 
   DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice);
 };