Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / media / video / capture / fake_video_capture_device.h
1 // Copyright (c) 2012 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 // Implementation of a fake VideoCaptureDevice class. Used for testing other
6 // video capture classes when no real hardware is available.
7
8 #ifndef MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
9 #define MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
10
11 #include <string>
12
13 #include "base/atomicops.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/threading/thread.h"
16 #include "base/threading/thread_checker.h"
17 #include "media/video/capture/video_capture_device.h"
18
19 namespace media {
20
21 class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice {
22  public:
23   static const int kFakeCaptureTimeoutMs = 50;
24
25   FakeVideoCaptureDevice();
26   ~FakeVideoCaptureDevice() override;
27
28   // VideoCaptureDevice implementation.
29   void AllocateAndStart(const VideoCaptureParams& params,
30                         scoped_ptr<VideoCaptureDevice::Client> client) override;
31   void StopAndDeAllocate() override;
32
33   // Sets the formats to use sequentially when the device is configured as
34   // variable capture resolution. Works only before AllocateAndStart() or
35   // after StopAndDeallocate().
36   void PopulateVariableFormatsRoster(const VideoCaptureFormats& formats);
37
38  private:
39   // Called on the |capture_thread_| only.
40   void OnAllocateAndStart(const VideoCaptureParams& params,
41                           scoped_ptr<Client> client);
42   void OnStopAndDeAllocate();
43   void OnCaptureTask();
44   void Reallocate();
45
46   // |thread_checker_| is used to check that destructor, AllocateAndStart() and
47   // StopAndDeAllocate() are called in the correct thread that owns the object.
48   base::ThreadChecker thread_checker_;
49
50   base::Thread capture_thread_;
51   // The following members are only used on the |capture_thread_|.
52   scoped_ptr<VideoCaptureDevice::Client> client_;
53   scoped_ptr<uint8[]> fake_frame_;
54   int frame_count_;
55   VideoCaptureFormat capture_format_;
56
57   // When the device is allowed to change resolution, this vector holds the
58   // available ones, used sequentially restarting at the end. These two members
59   // are initialised in PopulateFormatRoster() before |capture_thread_| is
60   // running and are subsequently read-only in that thread.
61   std::vector<VideoCaptureFormat> format_roster_;
62   int format_roster_index_;
63
64   DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice);
65 };
66
67 }  // namespace media
68
69 #endif  // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_