Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / capture / video / fake_video_capture_device.h
bloba0dd4e0a3bdefaebe202507894de1b1fe1827c0f
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 FakeVideoCaptureDeviceType {
26 USING_OWN_BUFFERS,
27 USING_OWN_BUFFERS_TRIPLANAR,
28 USING_CLIENT_BUFFERS,
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;
41 private:
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_;
61 int frame_count_;
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);
71 } // namespace media
73 #endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_