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.
5 // Implementation of a fake VideoCaptureDevice class. Used for testing other
6 // video capture classes when no real hardware is available.
8 #ifndef MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
9 #define MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
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"
21 class MEDIA_EXPORT FakeVideoCaptureDevice
: public VideoCaptureDevice
{
23 static const int kFakeCaptureTimeoutMs
= 50;
25 FakeVideoCaptureDevice();
26 ~FakeVideoCaptureDevice() override
;
28 // VideoCaptureDevice implementation.
29 void AllocateAndStart(const VideoCaptureParams
& params
,
30 scoped_ptr
<VideoCaptureDevice::Client
> client
) override
;
31 void StopAndDeAllocate() override
;
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
);
39 // Called on the |capture_thread_| only.
40 void OnAllocateAndStart(const VideoCaptureParams
& params
,
41 scoped_ptr
<Client
> client
);
42 void OnStopAndDeAllocate();
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_
;
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_
;
55 VideoCaptureFormat capture_format_
;
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_
;
64 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice
);
69 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_