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>>()); |
dcheng
2016/05/11 07:37:45
Which process is this running in? And where does t
sandersd (OOO until July 31)
2016/05/11 18:20:18
That does indeed look bad. Where can I find docume
dcheng
2016/05/11 18:26:24
https://www.chromium.org/developers/design-documen
sandersd (OOO until July 31)
2016/05/11 22:49:42
This looks large enough that it should be a separa
|
+ 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()); |
+ DCHECK_GT(data_size, 0u); |
+ uint32_t bytes_read = data_size; |
+ CHECK_EQ( |
+ 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, |
dcheng
2016/05/11 07:37:45
Why do we need a trampoline callback here?
sandersd (OOO until July 31)
2016/05/11 18:20:18
Because we can't cast |callback| from mojo::Callba
dcheng
2016/05/11 22:15:06
Blah. Going to ask the Mojo people about this toda
|
+ 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 |