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/memory/scoped_ptr.h"
14 #include "base/threading/thread.h"
15 #include "media/video/capture/video_capture_device.h"
19 class MEDIA_EXPORT FakeVideoCaptureDevice
: public VideoCaptureDevice
{
21 static VideoCaptureDevice
* Create(const Name
& device_name
);
22 virtual ~FakeVideoCaptureDevice();
23 // Used for testing. This will make sure the next call to Create will
25 static void SetFailNextCreate();
27 static void GetDeviceNames(Names
* device_names
);
29 // VideoCaptureDevice implementation.
30 virtual void Allocate(const VideoCaptureCapability
& capture_format
,
31 VideoCaptureDevice::EventHandler
* observer
) OVERRIDE
;
32 virtual void Start() OVERRIDE
;
33 virtual void Stop() OVERRIDE
;
34 virtual void DeAllocate() OVERRIDE
;
35 virtual const Name
& device_name() OVERRIDE
;
38 // Flag indicating the internal state.
45 explicit FakeVideoCaptureDevice(const Name
& device_name
);
47 // Called on the capture_thread_.
50 // EXPERIMENTAL, similar to allocate, but changes resolution and calls
51 // observer->OnFrameInfoChanged(VideoCaptureCapability&)
53 void PopulateCapabilitiesRoster();
56 VideoCaptureDevice::EventHandler
* observer_
;
58 base::Thread capture_thread_
;
59 scoped_ptr
<uint8
[]> fake_frame_
;
61 VideoCaptureCapability capture_format_
;
63 // When the device is configured as mutating video captures, this vector
64 // holds the available ones which are used in sequence, restarting at the end.
65 std::vector
<VideoCaptureCapability
> capabilities_roster_
;
66 int capabilities_roster_index_
;
68 static bool fail_next_create_
;
70 DISALLOW_IMPLICIT_CONSTRUCTORS(FakeVideoCaptureDevice
);
75 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_