blob: c45bfea6e09e154c9f57bbf986f9d638dd324458 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Implementation of a fake VideoCaptureDevice class. Used for testing other
// video capture classes when no real hardware is available.
#ifndef MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
#define MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
#include <string>
#include "base/atomicops.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
#include "media/capture/video/video_capture_device.h"
namespace media {
class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice {
public:
enum class BufferOwnership {
OWN_BUFFERS,
CLIENT_BUFFERS,
};
enum class BufferPlanarity {
PACKED,
TRIPLANAR,
};
static int FakeCapturePeriodMs() { return kFakeCapturePeriodMs; }
FakeVideoCaptureDevice(BufferOwnership buffer_ownership,
BufferPlanarity planarity);
~FakeVideoCaptureDevice() override;
// VideoCaptureDevice implementation.
void AllocateAndStart(const VideoCaptureParams& params,
scoped_ptr<Client> client) override;
void StopAndDeAllocate() override;
private:
static const int kFakeCapturePeriodMs = 50;
void CaptureUsingOwnBuffers(base::TimeTicks expected_execution_time);
void CaptureUsingClientBuffers(base::TimeTicks expected_execution_time);
void BeepAndScheduleNextCapture(
base::TimeTicks expected_execution_time,
const base::Callback<void(base::TimeTicks)>& next_capture);
// |thread_checker_| is used to check that all methods are called in the
// correct thread that owns the object.
base::ThreadChecker thread_checker_;
const BufferOwnership buffer_ownership_;
const BufferPlanarity planarity_;
scoped_ptr<VideoCaptureDevice::Client> client_;
// |fake_frame_| is used for capturing on Own Buffers.
scoped_ptr<uint8[]> fake_frame_;
int frame_count_;
VideoCaptureFormat capture_format_;
// FakeVideoCaptureDevice post tasks to itself for frame construction and
// needs to deal with asynchronous StopAndDeallocate().
base::WeakPtrFactory<FakeVideoCaptureDevice> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureDevice);
};
} // namespace media
#endif // MEDIA_VIDEO_CAPTURE_FAKE_VIDEO_CAPTURE_DEVICE_H_
|