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