Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / capture / video / fake_video_capture_device.h
blobc45bfea6e09e154c9f57bbf986f9d638dd324458
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_
11 #include <string>
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"
21 namespace media {
23 class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice {
24 public:
25 enum class BufferOwnership {
26 OWN_BUFFERS,
27 CLIENT_BUFFERS,
30 enum class BufferPlanarity {
31 PACKED,
32 TRIPLANAR,
35 static int FakeCapturePeriodMs() { return kFakeCapturePeriodMs; }
37 FakeVideoCaptureDevice(BufferOwnership buffer_ownership,
38 BufferPlanarity planarity);
39 ~FakeVideoCaptureDevice() override;
41 // VideoCaptureDevice implementation.
42 void AllocateAndStart(const VideoCaptureParams& params,
43 scoped_ptr<Client> client) override;
44 void StopAndDeAllocate() override;
46 private:
47 static const int kFakeCapturePeriodMs = 50;
49 void CaptureUsingOwnBuffers(base::TimeTicks expected_execution_time);
50 void CaptureUsingClientBuffers(base::TimeTicks expected_execution_time);
51 void BeepAndScheduleNextCapture(
52 base::TimeTicks expected_execution_time,
53 const base::Callback<void(base::TimeTicks)>& next_capture);
55 // |thread_checker_| is used to check that all methods are called in the
56 // correct thread that owns the object.
57 base::ThreadChecker thread_checker_;
59 const BufferOwnership buffer_ownership_;
60 const BufferPlanarity planarity_;
62 scoped_ptr<VideoCaptureDevice::Client> client_;
63 // |fake_frame_| is used for capturing on Own Buffers.
64 scoped_ptr<uint8[]> fake_frame_;
65 int frame_count_;
66 VideoCaptureFormat capture_format_;
68 // FakeVideoCaptureDevice post tasks to itself for frame construction and
69 // needs to deal with asynchronous StopAndDeallocate().
70 base::WeakPtrFactory<FakeVideoCaptureDevice> weak_factory_;
72 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice);
75 } // namespace media
77 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_