Chromium Code Reviews| 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" | |
|
miu
2014/12/20 03:37:57
Looks like you don't need this #include.
hellner1
2015/01/07 16:41:31
Done.
| |
| 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 |
| 19 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator( | 18 FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator( |
| 20 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 19 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
| 21 std::vector<uint32>* stored_bitrates) | |
| 22 : task_runner_(task_runner), | 20 : task_runner_(task_runner), |
| 23 stored_bitrates_(stored_bitrates), | 21 will_initialization_succeed_(true), |
| 24 client_(NULL), | 22 client_(NULL), |
| 25 first_(true), | 23 first_(true), |
| 26 will_initialization_succeed_(true), | 24 weak_this_factory_(this) {} |
| 27 weak_this_factory_(this) { | |
| 28 DCHECK(stored_bitrates_); | |
| 29 } | |
| 30 | 25 |
| 31 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() { | 26 FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() { |
| 32 weak_this_factory_.InvalidateWeakPtrs(); | 27 weak_this_factory_.InvalidateWeakPtrs(); |
| 33 } | 28 } |
| 34 | 29 |
| 35 std::vector<VideoEncodeAccelerator::SupportedProfile> | 30 std::vector<VideoEncodeAccelerator::SupportedProfile> |
| 36 FakeVideoEncodeAccelerator::GetSupportedProfiles() { | 31 FakeVideoEncodeAccelerator::GetSupportedProfiles() { |
| 37 return std::vector<VideoEncodeAccelerator::SupportedProfile>(); | 32 return std::vector<VideoEncodeAccelerator::SupportedProfile>(); |
| 38 } | 33 } |
| 39 | 34 |
| 40 bool FakeVideoEncodeAccelerator::Initialize( | 35 bool FakeVideoEncodeAccelerator::Initialize( |
| 41 media::VideoFrame::Format input_format, | 36 VideoFrame::Format input_format, |
| 42 const gfx::Size& input_visible_size, | 37 const gfx::Size& input_visible_size, |
| 43 VideoCodecProfile output_profile, | 38 VideoCodecProfile output_profile, |
| 44 uint32 initial_bitrate, | 39 uint32 initial_bitrate, |
| 45 Client* client) { | 40 Client* client) { |
| 46 if (!will_initialization_succeed_) | 41 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; | 42 return false; |
| 52 } | 43 } |
| 44 if (output_profile == VIDEO_CODEC_PROFILE_UNKNOWN || | |
| 45 output_profile > VIDEO_CODEC_PROFILE_MAX) { | |
| 46 return false; | |
| 47 } | |
| 48 client_ = client; | |
| 53 task_runner_->PostTask( | 49 task_runner_->PostTask( |
| 54 FROM_HERE, | 50 FROM_HERE, |
| 55 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers, | 51 base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers, |
| 56 weak_this_factory_.GetWeakPtr(), | 52 weak_this_factory_.GetWeakPtr(), |
| 57 kMinimumInputCount, | 53 kMinimumInputCount, |
| 58 input_visible_size, | 54 input_visible_size, |
| 59 kMinimumOutputBufferSize)); | 55 kMinimumOutputBufferSize)); |
| 60 return true; | 56 return true; |
| 61 } | 57 } |
| 62 | 58 |
| 63 void FakeVideoEncodeAccelerator::Encode(const scoped_refptr<VideoFrame>& frame, | 59 void FakeVideoEncodeAccelerator::Encode( |
| 64 bool force_keyframe) { | 60 const scoped_refptr<VideoFrame>& frame, |
| 61 bool force_keyframe) { | |
| 65 DCHECK(client_); | 62 DCHECK(client_); |
| 66 DCHECK(!available_buffer_ids_.empty()); | 63 queued_frames_.push(force_keyframe); |
| 67 | 64 EncodeTask(); |
| 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 } | 65 } |
| 86 | 66 |
| 87 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer( | 67 void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer( |
| 88 const BitstreamBuffer& buffer) { | 68 const BitstreamBuffer& buffer) { |
| 89 available_buffer_ids_.push_back(buffer.id()); | 69 available_buffers_.push_back(buffer); |
| 70 EncodeTask(); | |
| 90 } | 71 } |
| 91 | 72 |
| 92 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange( | 73 void FakeVideoEncodeAccelerator::RequestEncodingParametersChange( |
| 93 uint32 bitrate, | 74 uint32 bitrate, |
| 94 uint32 framerate) { | 75 uint32 framerate) { |
| 95 stored_bitrates_->push_back(bitrate); | 76 stored_bitrates_.push_back(bitrate); |
| 96 } | 77 } |
| 97 | 78 |
| 98 void FakeVideoEncodeAccelerator::Destroy() { delete this; } | 79 void FakeVideoEncodeAccelerator::Destroy() { delete this; } |
| 99 | 80 |
| 100 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) { | 81 void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) { |
| 101 DoBitstreamBufferReady(0, 23, key_frame); | 82 task_runner_->PostTask( |
| 83 FROM_HERE, | |
| 84 base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady, | |
| 85 weak_this_factory_.GetWeakPtr(), | |
| 86 0, | |
| 87 23, | |
| 88 key_frame)); | |
| 89 } | |
| 90 | |
| 91 void FakeVideoEncodeAccelerator::SetWillInitializationSucceed( | |
| 92 bool will_initialization_succeed) { | |
| 93 will_initialization_succeed_ = will_initialization_succeed; | |
| 102 } | 94 } |
| 103 | 95 |
| 104 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( | 96 void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( |
| 105 unsigned int input_count, | 97 unsigned int input_count, |
| 106 const gfx::Size& input_coded_size, | 98 const gfx::Size& input_coded_size, |
| 107 size_t output_buffer_size) const { | 99 size_t output_buffer_size) const { |
| 108 client_->RequireBitstreamBuffers( | 100 client_->RequireBitstreamBuffers( |
| 109 input_count, input_coded_size, output_buffer_size); | 101 input_count, input_coded_size, output_buffer_size); |
| 110 } | 102 } |
| 111 | 103 |
| 104 void FakeVideoEncodeAccelerator::EncodeTask() { | |
| 105 while (!queued_frames_.empty() && !available_buffers_.empty()) { | |
| 106 bool force_key_frame = queued_frames_.front(); | |
| 107 queued_frames_.pop(); | |
| 108 int32 bitstream_buffer_id = available_buffers_.front().id(); | |
| 109 available_buffers_.pop_front(); | |
| 110 bool key_frame = first_ || force_key_frame; | |
|
miu
2014/12/20 03:37:57
Please remove extra space after ||.
hellner1
2015/01/07 16:41:31
Good eye! Thanks.
| |
| 111 first_ = false; | |
| 112 task_runner_->PostTask( | |
| 113 FROM_HERE, | |
| 114 base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady, | |
| 115 weak_this_factory_.GetWeakPtr(), | |
| 116 bitstream_buffer_id, | |
| 117 kMinimumOutputBufferSize, | |
| 118 key_frame)); | |
| 119 } | |
| 120 } | |
| 121 | |
| 112 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady( | 122 void FakeVideoEncodeAccelerator::DoBitstreamBufferReady( |
| 113 int32 bitstream_buffer_id, | 123 int32 bitstream_buffer_id, |
| 114 size_t payload_size, | 124 size_t payload_size, |
| 115 bool key_frame) const { | 125 bool key_frame) { |
|
miu
2014/12/20 03:37:58
Why is this not a const method anymore?
hellner1
2015/01/07 16:41:31
Probably (mistakenly) happened during refactoring.
| |
| 116 client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); | 126 client_->BitstreamBufferReady(bitstream_buffer_id, |
| 127 payload_size, | |
| 128 key_frame); | |
| 117 } | 129 } |
| 118 | 130 |
| 119 } // namespace test | |
| 120 } // namespace cast | |
| 121 } // namespace media | 131 } // namespace media |
| OLD | NEW |