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 virtual ~FakeVideoCaptureDevice();
28 // VideoCaptureDevice implementation.
29 virtual void AllocateAndStart(
30 const VideoCaptureParams
& params
,
31 scoped_ptr
<VideoCaptureDevice::Client
> client
) OVERRIDE
;
32 virtual void StopAndDeAllocate() OVERRIDE
;
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
);
40 // Called on the |capture_thread_| only.
41 void OnAllocateAndStart(const VideoCaptureParams
& params
,
42 scoped_ptr
<Client
> client
);
43 void OnStopAndDeAllocate();
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_
;
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_
;
56 VideoCaptureFormat capture_format_
;
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_
;
65 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice
);
70 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_