OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/cast/test/fake_video_encode_accelerator.h" | 5 #include "media/video/fake_video_encode_accelerator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop_proxy.h" | |
10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
11 | 12 |
12 namespace media { | 13 namespace media { |
13 namespace cast { | |
14 namespace test { | |
15 | 14 |
16 static const unsigned int kMinimumInputCount = 1; | 15 static const unsigned int kMinimumInputCount = 1; |
17 static const size_t kMinimumOutputBufferSize = 123456; | 16 static const size_t kMinimumOutputBufferSize = 123456; |
18 | 17 |
18 struct FakeVideoEncodeAccelerator::BitstreamBufferRef { | |
wuchengli
2014/12/12 03:35:50
Can remove because not used anymore.
hellner1
2014/12/12 19:24:41
Done.
| |
19 BitstreamBufferRef(int id, scoped_ptr<base::SharedMemory> shm, size_t size) | |
20 : id(id), shm(shm.Pass()), size(size) {} | |
21 const int id; | |
22 const scoped_ptr<base::SharedMemory> shm; | |
23 const size_t size; | |
24 }; | |
25 | |
19 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator( | 26 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator( |
20 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 27 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
21 std::vector<uint32>* stored_bitrates) | |
22 : task_runner_(task_runner), | 28 : task_runner_(task_runner), |
23 stored_bitrates_(stored_bitrates), | 29 will_initialization_succeed_(true), |
24 client_(NULL), | 30 client_(NULL), |
25 first_(true), | 31 first_(true), |
26 will_initialization_succeed_(true), | 32 weak_this_factory_(this) {} |
27 weak_this_factory_(this) { | |
28 DCHECK(stored_bitrates_); | |
29 } | |
30 | 33 |
31 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() { | 34 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() { |
32 weak_this_factory_.InvalidateWeakPtrs(); | 35 weak_this_factory_.InvalidateWeakPtrs(); |
33 } | 36 } |
34 | 37 |
35 std::vector<VideoEncodeAccelerator::SupportedProfile> | 38 std::vector<VideoEncodeAccelerator::SupportedProfile> |
36 FakeVideoEncodeAccelerator::GetSupportedProfiles() { | 39 FakeVideoEncodeAccelerator::GetSupportedProfiles() { |
37 return std::vector<VideoEncodeAccelerator::SupportedProfile>(); | 40 return std::vector<VideoEncodeAccelerator::SupportedProfile>(); |
38 } | 41 } |
39 | 42 |
40 bool FakeVideoEncodeAccelerator::Initialize( | 43 bool FakeVideoEncodeAccelerator::Initialize( |
41 media::VideoFrame::Format input_format, | 44 VideoFrame::Format input_format, |
42 const gfx::Size& input_visible_size, | 45 const gfx::Size& input_visible_size, |
43 VideoCodecProfile output_profile, | 46 VideoCodecProfile output_profile, |
44 uint32 initial_bitrate, | 47 uint32 initial_bitrate, |
45 Client* client) { | 48 Client* client) { |
46 if (!will_initialization_succeed_) | 49 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; | 50 return false; |
52 } | 51 } |
52 if (output_profile == VIDEO_CODEC_PROFILE_UNKNOWN || | |
53 output_profile > VIDEO_CODEC_PROFILE_MAX) { | |
54 return false; | |
55 } | |
56 client_ = client; | |
53 task_runner_->PostTask( | 57 task_runner_->PostTask( |
54 FROM_HERE, | 58 FROM_HERE, |
55 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers, | 59 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers, |
56 weak_this_factory_.GetWeakPtr(), | 60 weak_this_factory_.GetWeakPtr(), |
57 kMinimumInputCount, | 61 kMinimumInputCount, |
58 input_visible_size, | 62 input_visible_size, |
59 kMinimumOutputBufferSize)); | 63 kMinimumOutputBufferSize)); |
60 return true; | 64 return true; |
61 } | 65 } |
62 | 66 |
63 void FakeVideoEncodeAccelerator::Encode(const scoped_refptr<VideoFrame>& frame, | 67 void FakeVideoEncodeAccelerator::Encode( |
64 bool force_keyframe) { | 68 const scoped_refptr<VideoFrame>& frame, |
69 bool force_keyframe) { | |
65 DCHECK(client_); | 70 DCHECK(client_); |
66 DCHECK(!available_buffer_ids_.empty()); | 71 DCHECK(!available_buffers_.empty()); |
67 | 72 |
68 // Fake that we have encoded the frame; resulting in using the full output | 73 BitstreamBuffer buffer = available_buffers_.front(); |
69 // buffer. | 74 int32 id = buffer.id(); |
70 int32 id = available_buffer_ids_.front(); | 75 bool is_key_frame = first_ || force_keyframe; |
71 available_buffer_ids_.pop_front(); | 76 first_ = false; |
72 | 77 |
73 bool is_key_fame = force_keyframe; | 78 client_->BitstreamBufferReady(id, kMinimumOutputBufferSize, is_key_frame); |
wuchengli
2014/12/12 03:35:50
Sorry. After thinking again, all client methods (R
hellner1
2014/12/12 19:24:41
This class assumes that it is called on the task_r
wuchengli
2014/12/13 02:10:22
Basically all VEA methods should be called on the
| |
74 if (first_) { | 79 available_buffers_.pop_front(); |
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 } | 80 } |
86 | 81 |
87 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer( | 82 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer( |
88 const BitstreamBuffer& buffer) { | 83 const BitstreamBuffer& buffer) { |
89 available_buffer_ids_.push_back(buffer.id()); | 84 available_buffers_.push_back(buffer); |
90 } | 85 } |
91 | 86 |
92 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange( | 87 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange( |
93 uint32 bitrate, | 88 uint32 bitrate, |
94 uint32 framerate) { | 89 uint32 framerate) { |
95 stored_bitrates_->push_back(bitrate); | 90 stored_bitrates_.push_back(bitrate); |
96 } | 91 } |
97 | 92 |
98 void FakeVideoEncodeAccelerator::Destroy() { delete this; } | 93 void FakeVideoEncodeAccelerator::Destroy() { delete this; } |
99 | 94 |
100 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) { | 95 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) { |
101 DoBitstreamBufferReady(0, 23, key_frame); | 96 client_->BitstreamBufferReady(0, 23, key_frame); |
97 } | |
98 | |
99 void FakeVideoEncodeAccelerator::SetWillInitializationSucceed( | |
100 bool will_initialization_succeed) { | |
101 will_initialization_succeed_ = will_initialization_succeed; | |
102 } | 102 } |
103 | 103 |
104 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( | 104 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( |
105 unsigned int input_count, | 105 unsigned int input_count, |
106 const gfx::Size& input_coded_size, | 106 const gfx::Size& input_coded_size, |
107 size_t output_buffer_size) const { | 107 size_t output_buffer_size) const { |
108 client_->RequireBitstreamBuffers( | 108 client_->RequireBitstreamBuffers( |
109 input_count, input_coded_size, output_buffer_size); | 109 input_count, input_coded_size, output_buffer_size); |
110 } | 110 } |
111 | 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 | 112 } // namespace media |
OLD | NEW |