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

Unified Diff: media/mojo/services/mojo_video_decoder_service.cc

Issue 1899363002: Finish plumbing MojoVideoDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 7 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
« no previous file with comments | « media/mojo/services/mojo_video_decoder_service.h ('k') | media/mojo/services/service_factory_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/mojo/services/mojo_video_decoder_service.cc
diff --git a/media/mojo/services/mojo_video_decoder_service.cc b/media/mojo/services/mojo_video_decoder_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0656306d8abd055ef72a617db556bad718c9e47c
--- /dev/null
+++ b/media/mojo/services/mojo_video_decoder_service.cc
@@ -0,0 +1,133 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/mojo/services/mojo_video_decoder_service.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/logging.h"
+#include "media/base/decoder_buffer.h"
+#include "media/base/video_decoder.h"
+#include "media/base/video_decoder_config.h"
+#include "media/base/video_frame.h"
+#include "media/mojo/common/media_type_converters.h"
+#include "media/mojo/services/mojo_media_client.h"
+#include "mojo/public/c/system/types.h"
+#include "mojo/public/cpp/system/buffer.h"
+#include "mojo/public/cpp/system/handle.h"
+
+namespace media {
+
+MojoVideoDecoderService::MojoVideoDecoderService(
+ mojo::InterfaceRequest<interfaces::VideoDecoder> request,
+ MojoMediaClient* mojo_media_client)
+ : binding_(this, std::move(request)),
+ mojo_media_client_(mojo_media_client),
+ weak_factory_(this) {
+ weak_this_ = weak_factory_.GetWeakPtr();
+}
+
+MojoVideoDecoderService::~MojoVideoDecoderService() {}
+
+void MojoVideoDecoderService::Construct(
+ interfaces::VideoDecoderClientPtr client,
+ mojo::ScopedDataPipeConsumerHandle decoder_buffer_pipe) {
+ DVLOG(1) << __FUNCTION__;
+ CHECK(!decoder_);
+
+ // TODO(sandersd): Provide callback for requesting a stub.
+ decoder_ = mojo_media_client_->CreateVideoDecoder(
+ base::ThreadTaskRunnerHandle::Get());
+
+ client_ = std::move(client);
+ decoder_buffer_pipe_ = std::move(decoder_buffer_pipe);
+}
+
+void MojoVideoDecoderService::Initialize(
+ interfaces::VideoDecoderConfigPtr config,
+ bool low_delay,
+ const InitializeCallback& callback) {
+ DVLOG(1) << __FUNCTION__;
+
+ if (!decoder_) {
+ callback.Run(false);
+ return;
+ }
+
+ decoder_->Initialize(
+ config.To<VideoDecoderConfig>(), low_delay, nullptr,
+ base::Bind(&MojoVideoDecoderService::OnDecoderInitialized, weak_this_,
+ callback),
+ base::Bind(&MojoVideoDecoderService::OnDecoderOutput, weak_this_));
+}
+
+void MojoVideoDecoderService::OnDecoderInitialized(
+ const InitializeCallback& callback,
+ bool success) {
+ DVLOG(1) << __FUNCTION__;
+ callback.Run(success);
+}
+
+void MojoVideoDecoderService::OnDecoderOutput(
+ const scoped_refptr<VideoFrame>& frame) {
+ DVLOG(1) << __FUNCTION__;
+ client_->OnVideoFrameDecoded(interfaces::VideoFrame::From(frame));
+}
+
+void MojoVideoDecoderService::Decode(interfaces::DecoderBufferPtr buffer,
+ const DecodeCallback& callback) {
+ DVLOG(1) << __FUNCTION__;
+
+ if (!decoder_) {
+ callback.Run(interfaces::DecodeStatus::DECODE_ERROR);
+ return;
+ }
+
+ scoped_refptr<DecoderBuffer> media_buffer(
+ buffer.To<scoped_refptr<DecoderBuffer>>());
+ if (!media_buffer->end_of_stream()) {
+ MojoHandleSignalsState state;
+ CHECK_EQ(
+ MojoWait(decoder_buffer_pipe_.get().value(),
+ MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, &state),
+ MOJO_RESULT_OK);
+ CHECK_EQ(state.satisfied_signals, MOJO_HANDLE_SIGNAL_READABLE);
+ uint32_t data_size =
+ base::checked_cast<uint32_t>(media_buffer->data_size());
dcheng 2016/05/17 06:32:29 This shouldn't be a checked_cast: it's in the GPU
sandersd (OOO until July 31) 2016/05/17 23:05:00 Done.
+ DCHECK_GT(data_size, 0u);
+ uint32_t bytes_read = data_size;
+ CHECK_EQ(
dcheng 2016/05/17 06:32:29 Ditto for this and the other CHECKs in this file w
sandersd (OOO until July 31) 2016/05/17 23:05:00 Done. I also updated MojoAudioDecoderService, alt
+ ReadDataRaw(decoder_buffer_pipe_.get(), media_buffer->writable_data(),
+ &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE),
+ MOJO_RESULT_OK);
+ CHECK_EQ(bytes_read, data_size);
+ }
+
+ decoder_->Decode(media_buffer,
+ base::Bind(&MojoVideoDecoderService::OnDecoderDecoded,
+ weak_this_, callback));
+}
+
+void MojoVideoDecoderService::OnDecoderDecoded(const DecodeCallback& callback,
+ DecodeStatus status) {
+ DVLOG(1) << __FUNCTION__;
+ callback.Run(static_cast<interfaces::DecodeStatus>(status));
+}
+
+void MojoVideoDecoderService::Reset(const ResetCallback& callback) {
+ DVLOG(1) << __FUNCTION__;
+ if (!decoder_) {
+ callback.Run();
+ return;
+ }
+ decoder_->Reset(base::Bind(&MojoVideoDecoderService::OnDecoderReset,
+ weak_this_, callback));
+}
+
+void MojoVideoDecoderService::OnDecoderReset(const ResetCallback& callback) {
+ DVLOG(1) << __FUNCTION__;
+ callback.Run();
+}
+
+} // namespace media
« no previous file with comments | « media/mojo/services/mojo_video_decoder_service.h ('k') | media/mojo/services/service_factory_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698