blob: 24eba4b07eea986e068ab2c458c8a43e7eb556cc (
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
78
79
80
81
|
// Copyright 2015 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.
#include "media/cast/sender/fake_video_encode_accelerator_factory.h"
#include "base/callback_helpers.h"
namespace media {
namespace cast {
FakeVideoEncodeAcceleratorFactory::FakeVideoEncodeAcceleratorFactory(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
: task_runner_(task_runner),
will_init_succeed_(true),
auto_respond_(false),
vea_response_count_(0),
shm_response_count_(0),
last_response_vea_(nullptr),
last_response_shm_(nullptr) {}
FakeVideoEncodeAcceleratorFactory::~FakeVideoEncodeAcceleratorFactory() {}
void FakeVideoEncodeAcceleratorFactory::SetInitializationWillSucceed(
bool will_init_succeed) {
will_init_succeed_ = will_init_succeed;
}
void FakeVideoEncodeAcceleratorFactory::SetAutoRespond(bool auto_respond) {
auto_respond_ = auto_respond;
if (auto_respond_) {
if (!vea_response_callback_.is_null())
RespondWithVideoEncodeAccelerator();
if (!shm_response_callback_.is_null())
RespondWithSharedMemory();
}
}
void FakeVideoEncodeAcceleratorFactory::CreateVideoEncodeAccelerator(
const ReceiveVideoEncodeAcceleratorCallback& callback) {
DCHECK(!callback.is_null());
DCHECK(!next_response_vea_);
FakeVideoEncodeAccelerator* const vea =
new FakeVideoEncodeAccelerator(task_runner_);
vea->SetWillInitializationSucceed(will_init_succeed_);
next_response_vea_.reset(vea);
vea_response_callback_ = callback;
if (auto_respond_)
RespondWithVideoEncodeAccelerator();
}
void FakeVideoEncodeAcceleratorFactory::CreateSharedMemory(
size_t size, const ReceiveVideoEncodeMemoryCallback& callback) {
DCHECK(!callback.is_null());
DCHECK(!next_response_shm_);
next_response_shm_.reset(new base::SharedMemory());
CHECK(next_response_shm_->CreateAndMapAnonymous(size));
shm_response_callback_ = callback;
if (auto_respond_)
RespondWithSharedMemory();
}
void FakeVideoEncodeAcceleratorFactory::RespondWithVideoEncodeAccelerator() {
DCHECK(next_response_vea_.get());
last_response_vea_ = next_response_vea_.get();
++vea_response_count_;
base::ResetAndReturn(&vea_response_callback_).Run(
task_runner_, next_response_vea_.Pass());
}
void FakeVideoEncodeAcceleratorFactory::RespondWithSharedMemory() {
DCHECK(next_response_shm_.get());
last_response_shm_ = next_response_shm_.get();
++shm_response_count_;
base::ResetAndReturn(&shm_response_callback_).Run(next_response_shm_.Pass());
}
} // namespace cast
} // namespace media
|