• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   virtual ~FakeVideoCaptureDevice();
27 
28   // VideoCaptureDevice implementation.
29   virtual void AllocateAndStart(
30       const VideoCaptureParams& params,
31       scoped_ptr<VideoCaptureDevice::Client> client) OVERRIDE;
32   virtual void StopAndDeAllocate() OVERRIDE;
33 
34   // Sets the formats to use sequentially when the device is configured as
35   // variable capture resolution. Works only before AllocateAndStart() or
36   // after StopAndDeallocate().
37   void PopulateVariableFormatsRoster(const VideoCaptureFormats& formats);
38 
39  private:
40   // Called on the |capture_thread_| only.
41   void OnAllocateAndStart(const VideoCaptureParams& params,
42                           scoped_ptr<Client> client);
43   void OnStopAndDeAllocate();
44   void OnCaptureTask();
45   void Reallocate();
46 
47   // |thread_checker_| is used to check that destructor, AllocateAndStart() and
48   // StopAndDeAllocate() are called in the correct thread that owns the object.
49   base::ThreadChecker thread_checker_;
50 
51   base::Thread capture_thread_;
52   // The following members are only used on the |capture_thread_|.
53   scoped_ptr<VideoCaptureDevice::Client> client_;
54   scoped_ptr<uint8[]> fake_frame_;
55   int frame_count_;
56   VideoCaptureFormat capture_format_;
57 
58   // When the device is allowed to change resolution, this vector holds the
59   // available ones, used sequentially restarting at the end. These two members
60   // are initialised in PopulateFormatRoster() before |capture_thread_| is
61   // running and are subsequently read-only in that thread.
62   std::vector<VideoCaptureFormat> format_roster_;
63   int format_roster_index_;
64 
65   DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice);
66 };
67 
68 }  // namespace media
69 
70 #endif  // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
71