OLD | NEW |
| (Empty) |
1 // Copyright 2014 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. | |
4 | |
5 #include "media/cast/test/fake_video_encode_accelerator.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/location.h" | |
9 #include "base/logging.h" | |
10 #include "base/single_thread_task_runner.h" | |
11 | |
12 namespace media { | |
13 namespace cast { | |
14 namespace test { | |
15 | |
16 static const unsigned int kMinimumInputCount = 1; | |
17 static const size_t kMinimumOutputBufferSize = 123456; | |
18 | |
19 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator( | |
20 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | |
21 std::vector<uint32>* stored_bitrates) | |
22 : task_runner_(task_runner), | |
23 stored_bitrates_(stored_bitrates), | |
24 client_(NULL), | |
25 first_(true), | |
26 will_initialization_succeed_(true), | |
27 weak_this_factory_(this) { | |
28 DCHECK(stored_bitrates_); | |
29 } | |
30 | |
31 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() { | |
32 weak_this_factory_.InvalidateWeakPtrs(); | |
33 } | |
34 | |
35 std::vector<VideoEncodeAccelerator::SupportedProfile> | |
36 FakeVideoEncodeAccelerator::GetSupportedProfiles() { | |
37 return std::vector<VideoEncodeAccelerator::SupportedProfile>(); | |
38 } | |
39 | |
40 bool FakeVideoEncodeAccelerator::Initialize( | |
41 media::VideoFrame::Format input_format, | |
42 const gfx::Size& input_visible_size, | |
43 VideoCodecProfile output_profile, | |
44 uint32 initial_bitrate, | |
45 Client* client) { | |
46 if (!will_initialization_succeed_) | |
47 return false; | |
48 client_ = client; | |
49 if (output_profile != media::VP8PROFILE_ANY && | |
50 output_profile != media::H264PROFILE_MAIN) { | |
51 return false; | |
52 } | |
53 task_runner_->PostTask( | |
54 FROM_HERE, | |
55 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers, | |
56 weak_this_factory_.GetWeakPtr(), | |
57 kMinimumInputCount, | |
58 input_visible_size, | |
59 kMinimumOutputBufferSize)); | |
60 return true; | |
61 } | |
62 | |
63 void FakeVideoEncodeAccelerator::Encode(const scoped_refptr<VideoFrame>& frame, | |
64 bool force_keyframe) { | |
65 DCHECK(client_); | |
66 DCHECK(!available_buffer_ids_.empty()); | |
67 | |
68 // Fake that we have encoded the frame; resulting in using the full output | |
69 // buffer. | |
70 int32 id = available_buffer_ids_.front(); | |
71 available_buffer_ids_.pop_front(); | |
72 | |
73 bool is_key_fame = force_keyframe; | |
74 if (first_) { | |
75 is_key_fame = true; | |
76 first_ = false; | |
77 } | |
78 task_runner_->PostTask( | |
79 FROM_HERE, | |
80 base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady, | |
81 weak_this_factory_.GetWeakPtr(), | |
82 id, | |
83 kMinimumOutputBufferSize, | |
84 is_key_fame)); | |
85 } | |
86 | |
87 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer( | |
88 const BitstreamBuffer& buffer) { | |
89 available_buffer_ids_.push_back(buffer.id()); | |
90 } | |
91 | |
92 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange( | |
93 uint32 bitrate, | |
94 uint32 framerate) { | |
95 stored_bitrates_->push_back(bitrate); | |
96 } | |
97 | |
98 void FakeVideoEncodeAccelerator::Destroy() { delete this; } | |
99 | |
100 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) { | |
101 DoBitstreamBufferReady(0, 23, key_frame); | |
102 } | |
103 | |
104 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( | |
105 unsigned int input_count, | |
106 const gfx::Size& input_coded_size, | |
107 size_t output_buffer_size) const { | |
108 client_->RequireBitstreamBuffers( | |
109 input_count, input_coded_size, output_buffer_size); | |
110 } | |
111 | |
112 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady( | |
113 int32 bitstream_buffer_id, | |
114 size_t payload_size, | |
115 bool key_frame) const { | |
116 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); | |
117 } | |
118 | |
119 } // namespace test | |
120 } // namespace cast | |
121 } // namespace media | |
OLD | NEW |