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 53% |
| rename from media/cast/test/fake_video_encode_accelerator.cc |
| rename to media/video/fake_video_encode_accelerator.cc |
| index 23a6fb315e338d5686b821e8f911447b9602c719..6bff131a84495173d38edcce791bdcabfe8c51a9 100644 |
| --- a/media/cast/test/fake_video_encode_accelerator.cc |
| +++ b/media/video/fake_video_encode_accelerator.cc |
| @@ -2,31 +2,35 @@ |
| // 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; |
| +static const size_t kMinimumOutputBufferSize = 1234; |
|
wuchengli
2014/12/09 14:29:25
Why this has been changed?
hellner1
2014/12/10 22:38:59
It happened during debugging. I put the old value
|
| + |
| +struct FakeVideoEncodeAccelerator::BitstreamBufferRef { |
| + 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) |
| - : task_runner_(task_runner), |
| + const std::vector<uint32>& stored_bitrates) |
| + : child_message_loop_proxy_(task_runner), |
|
wuchengli
2014/12/09 14:29:25
I assume you don't force FakeVEA to run on the chi
hellner1
2014/12/10 22:38:59
Done.
|
| stored_bitrates_(stored_bitrates), |
| 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,19 +42,16 @@ 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_) |
| - return false; |
| - client_ = client; |
| - if (output_profile != media::VP8PROFILE_ANY && |
| - output_profile != media::H264PROFILE_MAIN) { |
| + if (output_profile == VIDEO_CODEC_PROFILE_UNKNOWN) { |
|
wuchengli
2014/12/09 14:29:25
Return false for profile > VIDEO_CODEC_PROFILE_MAX
hellner1
2014/12/10 22:38:59
Done.
|
| return false; |
|
wuchengli
2014/12/09 14:29:25
Why will_initialization_succeed_ is removed?
hellner1
2014/12/10 22:38:59
Done.
|
| } |
| - task_runner_->PostTask( |
| + client_ = client; |
| + child_message_loop_proxy_->PostTask( |
| FROM_HERE, |
| base::Bind(&FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers, |
| weak_this_factory_.GetWeakPtr(), |
| @@ -60,39 +61,45 @@ 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()); |
| - |
| - // 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(); |
| - |
| - 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)); |
| + DCHECK(!available_buffers_.empty()); |
| + |
| + // Create fake encoded frame by just signaling that the buffer contains |
| + // data. Note that the only thing written to the buffer is whether it is |
| + // a key frame or not. |
| + BitstreamBufferRef* buffer = available_buffers_.front().get(); |
| + int32 id = buffer->id; |
| + bool is_key_frame = first_ || force_keyframe; |
| + first_ = false; |
| + |
| + uint8* stream = static_cast<uint8*>(buffer->shm->memory()); |
| + stream[0] = is_key_frame ? 0x00 : 0x01; // Key frame scheme = VP8 |
| + DoBitstreamBufferReady(id, |
|
wuchengli
2014/12/09 14:29:25
Remove DoBitstreamBufferReady and just call client
hellner1
2014/12/10 22:38:59
I have to post here because calling client_->Bitst
wuchengli
2014/12/11 02:14:31
So you'll change this back to PostTask? The latest
hellner1
2014/12/11 19:34:19
Sorry, my bad here. Calling without posting does n
|
| + kMinimumOutputBufferSize, |
| + is_key_frame); |
| + available_buffers_.pop_front(); |
| } |
| void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer( |
| const BitstreamBuffer& buffer) { |
| - available_buffer_ids_.push_back(buffer.id()); |
| + scoped_ptr<base::SharedMemory> shm( |
| + new base::SharedMemory(buffer.handle(), false)); |
| + if (!shm->Map(buffer.size())) { |
| + LOG(ERROR) << "Shared memory failure"; |
| + return; |
| + } |
| + available_buffers_.push_back( |
|
wuchengli
2014/12/09 14:29:25
Can we store BitstreamBuffer in |available_buffers
hellner1
2014/12/10 22:38:59
FYI: this behavior is taken from here: https://cod
wuchengli
2014/12/11 02:14:31
I guess v4l2VEA needs to map the memory in UseOutp
hellner1
2014/12/11 19:34:19
Done.
|
| + scoped_ptr<BitstreamBufferRef>( |
| + new BitstreamBufferRef(buffer.id(), shm.Pass(), buffer.size()))); |
| } |
| void FakeVideoEncodeAccelerator::RequestEncodingParametersChange( |
| uint32 bitrate, |
| uint32 framerate) { |
| - stored_bitrates_->push_back(bitrate); |
| + stored_bitrates_.push_back(bitrate); |
| } |
| void FakeVideoEncodeAccelerator::Destroy() { delete this; } |
| @@ -101,6 +108,11 @@ void FakeVideoEncodeAccelerator::SendDummyFrameForTesting(bool key_frame) { |
| DoBitstreamBufferReady(0, 23, key_frame); |
| } |
| +void FakeVideoEncodeAccelerator::SetWillInitializationSucceed( |
| + bool will_initialization_succeed) { |
| + will_initialization_succeed_ = will_initialization_succeed; |
| +} |
| + |
| void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers( |
| unsigned int input_count, |
| const gfx::Size& input_coded_size, |
| @@ -116,6 +128,4 @@ void FakeVideoEncodeAccelerator::DoBitstreamBufferReady( |
| client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); |
| } |
| -} // namespace test |
| -} // namespace cast |
| } // namespace media |