Chromium Code Reviews| Index: media/video/fake_video_encode_accelerator.cc |
| diff --git a/media/cast/test/fake_video_encode_accelerator.cc b/media/video/fake_video_encode_accelerator.cc |
| similarity index 58% |
| rename from media/cast/test/fake_video_encode_accelerator.cc |
| rename to media/video/fake_video_encode_accelerator.cc |
| index 23a6fb315e338d5686b821e8f911447b9602c719..1d94a130508959dd21ff7e884cc35ff716b25d0e 100644 |
| --- a/media/cast/test/fake_video_encode_accelerator.cc |
| +++ b/media/video/fake_video_encode_accelerator.cc |
| @@ -2,31 +2,34 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "media/cast/test/fake_video_encode_accelerator.h" |
| +#include "media/video/fake_video_encode_accelerator.h" |
| #include "base/bind.h" |
| #include "base/location.h" |
| #include "base/logging.h" |
| +#include "base/message_loop/message_loop_proxy.h" |
| #include "base/single_thread_task_runner.h" |
| namespace media { |
| -namespace cast { |
| -namespace test { |
| static const unsigned int kMinimumInputCount = 1; |
| static const size_t kMinimumOutputBufferSize = 123456; |
| +struct FakeVideoEncodeAccelerator::BitstreamBufferRef { |
|
wuchengli
2014/12/12 03:35:50
Can remove because not used anymore.
hellner1
2014/12/12 19:24:41
Done.
|
| + BitstreamBufferRef(int id, scoped_ptr<base::SharedMemory> shm, size_t size) |
| + : id(id), shm(shm.Pass()), size(size) {} |
| + const int id; |
| + const scoped_ptr<base::SharedMemory> shm; |
| + const size_t size; |
| +}; |
| + |
| FakeVideoEncodeAccelerator::FakeVideoEncodeAccelerator( |
| - const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| - std::vector<uint32>* stored_bitrates) |
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
| : task_runner_(task_runner), |
| - stored_bitrates_(stored_bitrates), |
| + will_initialization_succeed_(true), |
| client_(NULL), |
| first_(true), |
| - will_initialization_succeed_(true), |
| - weak_this_factory_(this) { |
| - DCHECK(stored_bitrates_); |
| -} |
| + weak_this_factory_(this) {} |
| FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() { |
| weak_this_factory_.InvalidateWeakPtrs(); |
| @@ -38,18 +41,19 @@ FakeVideoEncodeAccelerator::GetSupportedProfiles() { |
| } |
| bool FakeVideoEncodeAccelerator::Initialize( |
| - media::VideoFrame::Format input_format, |
| + VideoFrame::Format input_format, |
| const gfx::Size& input_visible_size, |
| VideoCodecProfile output_profile, |
| uint32 initial_bitrate, |
| Client* client) { |
| - if (!will_initialization_succeed_) |
| + if (!will_initialization_succeed_) { |
| return false; |
| - client_ = client; |
| - if (output_profile != media::VP8PROFILE_ANY && |
| - output_profile != media::H264PROFILE_MAIN) { |
| + } |
| + if (output_profile == VIDEO_CODEC_PROFILE_UNKNOWN || |
| + output_profile > VIDEO_CODEC_PROFILE_MAX) { |
| return false; |
| } |
| + client_ = client; |
| task_runner_->PostTask( |
| FROM_HERE, |
| base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers, |
| @@ -60,45 +64,41 @@ bool FakeVideoEncodeAccelerator::Initialize( |
| return true; |
| } |
| -void FakeVideoEncodeAccelerator::Encode(const scoped_refptr<VideoFrame>& frame, |
| - bool force_keyframe) { |
| +void FakeVideoEncodeAccelerator::Encode( |
| + const scoped_refptr<VideoFrame>& frame, |
| + bool force_keyframe) { |
| DCHECK(client_); |
| - DCHECK(!available_buffer_ids_.empty()); |
| + DCHECK(!available_buffers_.empty()); |
| - // Fake that we have encoded the frame; resulting in using the full output |
| - // buffer. |
| - int32 id = available_buffer_ids_.front(); |
| - available_buffer_ids_.pop_front(); |
| + BitstreamBuffer buffer = available_buffers_.front(); |
| + int32 id = buffer.id(); |
| + bool is_key_frame = first_ || force_keyframe; |
| + first_ = false; |
| - bool is_key_fame = force_keyframe; |
| - if (first_) { |
| - is_key_fame = true; |
| - first_ = false; |
| - } |
| - task_runner_->PostTask( |
| - FROM_HERE, |
| - base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady, |
| - weak_this_factory_.GetWeakPtr(), |
| - id, |
| - kMinimumOutputBufferSize, |
| - is_key_fame)); |
| + 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
|
| + available_buffers_.pop_front(); |
| } |
| void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer( |
| const BitstreamBuffer& buffer) { |
| - available_buffer_ids_.push_back(buffer.id()); |
| + available_buffers_.push_back(buffer); |
| } |
| void FakeVideoEncodeAccelerator::RequestEncodingParametersChange( |
| uint32 bitrate, |
| uint32 framerate) { |
| - stored_bitrates_->push_back(bitrate); |
| + stored_bitrates_.push_back(bitrate); |
| } |
| void FakeVideoEncodeAccelerator::Destroy() { delete this; } |
| void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) { |
| - DoBitstreamBufferReady(0, 23, key_frame); |
| + client_->BitstreamBufferReady(0, 23, key_frame); |
| +} |
| + |
| +void FakeVideoEncodeAccelerator::SetWillInitializationSucceed( |
| + bool will_initialization_succeed) { |
| + will_initialization_succeed_ = will_initialization_succeed; |
| } |
| void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( |
| @@ -109,13 +109,4 @@ void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( |
| input_count, input_coded_size, output_buffer_size); |
| } |
| -void FakeVideoEncodeAccelerator::DoBitstreamBufferReady( |
| - int32 bitstream_buffer_id, |
| - size_t payload_size, |
| - bool key_frame) const { |
| - client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); |
| -} |
| - |
| -} // namespace test |
| -} // namespace cast |
| } // namespace media |