Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Unified Diff: media/video/fake_video_encode_accelerator.cc

Issue 760963003: Adds fake hardware video encoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates according to comments Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 50%
rename from media/cast/test/fake_video_encode_accelerator.cc
rename to media/video/fake_video_encode_accelerator.cc
index 23a6fb315e338d5686b821e8f911447b9602c719..4ca7a236ca1e1a10b8e9b8a4fb57e86f569fd4ce 100644
--- a/media/cast/test/fake_video_encode_accelerator.cc
+++ b/media/video/fake_video_encode_accelerator.cc
@@ -2,7 +2,7 @@
// 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"
@@ -10,23 +10,17 @@
#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;
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),
- client_(NULL),
- first_(true),
will_initialization_succeed_(true),
- weak_this_factory_(this) {
- DCHECK(stored_bitrates_);
-}
+ client_(NULL),
+ next_frame_is_first_frame_(true),
+ weak_this_factory_(this) {}
FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() {
weak_this_factory_.InvalidateWeakPtrs();
@@ -34,22 +28,33 @@ FakeVideoEncodeAccelerator::~FakeVideoEncodeAccelerator() {
std::vector<VideoEncodeAccelerator::SupportedProfile>
FakeVideoEncodeAccelerator::GetSupportedProfiles() {
- return std::vector<VideoEncodeAccelerator::SupportedProfile>();
+ std::vector<VideoEncodeAccelerator::SupportedProfile> profiles;
+ SupportedProfile profile;
+ profile.max_resolution.SetSize(1920, 1088);
+ profile.max_framerate_numerator = 30;
+ profile.max_framerate_denominator = 1;
+
+ profile.profile = media::H264PROFILE_MAIN;
+ profiles.push_back(profile);
+ profile.profile = media::VP8PROFILE_ANY;
+ profiles.push_back(profile);
+ return profiles;
}
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 +65,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());
-
- // 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));
+ queued_frames_.push(force_keyframe);
+ EncodeTask();
}
void FakeVideoEncodeAccelerator::UseOutputBitstreamBuffer(
const BitstreamBuffer& buffer) {
- available_buffer_ids_.push_back(buffer.id());
+ available_buffers_.push_back(buffer);
+ EncodeTask();
}
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);
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady,
+ weak_this_factory_.GetWeakPtr(),
+ 0,
+ 23,
+ key_frame));
+}
+
+void FakeVideoEncodeAccelerator::SetWillInitializationSucceed(
+ bool will_initialization_succeed) {
+ will_initialization_succeed_ = will_initialization_succeed;
}
void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers(
@@ -109,13 +110,31 @@ void FakeVideoEncodeAccelerator::DoRequireBitstreamBuffers(
input_count, input_coded_size, output_buffer_size);
}
+void FakeVideoEncodeAccelerator::EncodeTask() {
+ while (!queued_frames_.empty() && !available_buffers_.empty()) {
+ bool force_key_frame = queued_frames_.front();
+ queued_frames_.pop();
+ int32 bitstream_buffer_id = available_buffers_.front().id();
+ available_buffers_.pop_front();
+ bool key_frame = next_frame_is_first_frame_ || force_key_frame;
+ next_frame_is_first_frame_ = false;
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&FakeVideoEncodeAccelerator::DoBitstreamBufferReady,
+ weak_this_factory_.GetWeakPtr(),
+ bitstream_buffer_id,
+ kMinimumOutputBufferSize,
+ key_frame));
+ }
+}
+
void FakeVideoEncodeAccelerator::DoBitstreamBufferReady(
int32 bitstream_buffer_id,
size_t payload_size,
bool key_frame) const {
- client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame);
+ client_->BitstreamBufferReady(bitstream_buffer_id,
+ payload_size,
+ key_frame);
}
-} // namespace test
-} // namespace cast
} // namespace media
« media/cast/sender/video_sender_unittest.cc ('K') | « media/video/fake_video_encode_accelerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698