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/memory/weak_ptr.h"
16 #include "base/threading/thread.h"
17 #include "base/threading/thread_checker.h"
18 #include "base/time/time.h"
19 #include "media/capture/video/video_capture_device.h"
23 class MEDIA_EXPORT FakeVideoCaptureDevice
: public VideoCaptureDevice
{
25 enum FakeVideoCaptureDeviceType
{
27 USING_OWN_BUFFERS_TRIPLANAR
,
31 static int FakeCapturePeriodMs() { return kFakeCapturePeriodMs
; }
33 explicit FakeVideoCaptureDevice(FakeVideoCaptureDeviceType device_type
);
34 ~FakeVideoCaptureDevice() override
;
36 // VideoCaptureDevice implementation.
37 void AllocateAndStart(const VideoCaptureParams
& params
,
38 scoped_ptr
<Client
> client
) override
;
39 void StopAndDeAllocate() override
;
42 static const int kFakeCapturePeriodMs
= 50;
44 void CaptureUsingOwnBuffers(base::TimeTicks expected_execution_time
);
45 void CaptureUsingClientBuffers(VideoCapturePixelFormat pixel_format
,
46 VideoPixelStorage pixel_storage
,
47 base::TimeTicks expected_execution_time
);
48 void BeepAndScheduleNextCapture(
49 base::TimeTicks expected_execution_time
,
50 const base::Callback
<void(base::TimeTicks
)>& next_capture
);
52 // |thread_checker_| is used to check that all methods are called in the
53 // correct thread that owns the object.
54 base::ThreadChecker thread_checker_
;
56 const FakeVideoCaptureDeviceType device_type_
;
58 scoped_ptr
<VideoCaptureDevice::Client
> client_
;
59 // |fake_frame_| is used for capturing on Own Buffers.
60 scoped_ptr
<uint8
[]> fake_frame_
;
62 VideoCaptureFormat capture_format_
;
64 // FakeVideoCaptureDevice post tasks to itself for frame construction and
65 // needs to deal with asynchronous StopAndDeallocate().
66 base::WeakPtrFactory
<FakeVideoCaptureDevice
> weak_factory_
;
68 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice
);
73 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_