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

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 6 years 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 55%
rename from media/cast/test/fake_video_encode_accelerator.cc
rename to media/video/fake_video_encode_accelerator.cc
index 23a6fb315e338d5686b821e8f911447b9602c719..9f39541dd681b8066c90aa2448a75d21310f96ab 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 {
+ 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,39 +64,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
wuchengli 2014/12/11 02:14:31 Can remove this because is_key_frame is communicat
hellner1 2014/12/11 19:34:19 Indeed. I forgot to remove it. Thanks for the ping
+ DoBitstreamBufferReady(id,
+ 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(
+ 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 +111,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 +131,4 @@ void FakeVideoEncodeAccelerator::DoBitstreamBufferReady(
client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame);
}
-} // namespace test
-} // namespace cast
} // namespace media
« media/video/fake_video_encode_accelerator.h ('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