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

Unified Diff: media/mojo/clients/mojo_data_source_impl.cc

Issue 2643743002: Mojify demuxers and allow running {Chunk/FFmpeg}Demuxer in a Utility Process (Closed)
Patch Set: Rebase and make sure to unbind mojom::DemuxerPtr on the bound thread during termination Created 3 years, 10 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/clients/mojo_data_source_impl.h ('k') | media/mojo/clients/mojo_demuxer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/mojo/clients/mojo_data_source_impl.cc
diff --git a/media/mojo/clients/mojo_data_source_impl.cc b/media/mojo/clients/mojo_data_source_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2c5a6af449f10e60520c193a711b5eaed4091e28
--- /dev/null
+++ b/media/mojo/clients/mojo_data_source_impl.cc
@@ -0,0 +1,90 @@
+// Copyright 2017 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/clients/mojo_data_source_impl.h"
+
+#include "media/base/data_buffer.h"
+#include "media/mojo/common/media_type_converters.h"
+#include "media/mojo/common/mojo_data_buffer_converter.h"
+
+namespace media {
+
+MojoDataSourceImpl::MojoDataSourceImpl(
+ media::DataSource* data_source,
+ mojo::InterfaceRequest<mojom::DataSource> request)
+ : binding_(this, std::move(request)),
+ data_source_(data_source),
+ weak_factory_(this) {
+ CHECK(data_source_);
+}
+
+MojoDataSourceImpl::~MojoDataSourceImpl() {}
+
+// This is called when our DataSourceClient has connected itself and is
+// ready to receive messages. Send an initial config and notify it that
+// we are now ready for business.
+void MojoDataSourceImpl::Initialize(const InitializeCallback& callback) {
+ DVLOG(2) << __func__;
+
+ mojo::ScopedDataPipeConsumerHandle remote_consumer_handle;
+
+ // TODO(j.isorce): fix TODO in media/mojo/common/mojo_data_buffer_converter.cc
+ // CreateDataPipe first and reflect the fix here. For now the following value
+ // should be enough for audio + video.
+ // Other option is to set the capacity as a multiple of the bitrate got from
+ // SetBitrate below.
+ mojo_data_buffer_writer_ = MojoDataBufferWriter::Create(
+ /* capacity_num_bytes */ 3 * 1024 * 1024, &remote_consumer_handle);
+
+ callback.Run(std::move(remote_consumer_handle));
+}
+
+void MojoDataSourceImpl::Read(int64_t position,
+ int size,
+ const ReadCallback& callback) {
+ std::unique_ptr<uint8_t[]> data(new uint8_t[size]);
+
+ data_source_->Read(
+ position, size, data.get(),
+ base::Bind(&MojoDataSourceImpl::OnRead, weak_factory_.GetWeakPtr(),
+ callback, base::Passed(std::move(data))));
+}
+
+void MojoDataSourceImpl::OnRead(const ReadCallback& callback,
+ std::unique_ptr<uint8_t[]> data,
+ int size) {
+ mojom::DataBufferPtr mojo_buffer;
+ if (size != media::DataSource::kReadError &&
+ size != media::DataSource::kAborted) {
+ scoped_refptr<media::DataBuffer> buffer =
+ new media::DataBuffer(std::move(data), size);
+ mojo_buffer = mojo_data_buffer_writer_->WriteDataBuffer(buffer);
+ }
+ callback.Run(std::move(mojo_buffer), size);
+}
+
+void MojoDataSourceImpl::Stop() {
+ data_source_->Stop();
+}
+
+void MojoDataSourceImpl::Abort() {
+ data_source_->Abort();
+}
+
+void MojoDataSourceImpl::GetSize(const GetSizeCallback& callback) {
+ int64_t size = 0;
+ bool success = data_source_->GetSize(&size);
+ callback.Run(success, size);
+}
+
+void MojoDataSourceImpl::IsStreaming(const IsStreamingCallback& callback) {
+ bool is_streaming = data_source_->IsStreaming();
+ callback.Run(is_streaming);
+}
+
+void MojoDataSourceImpl::SetBitrate(int bitrate) {
+ data_source_->SetBitrate(bitrate);
+}
+
+} // namespace media
« no previous file with comments | « media/mojo/clients/mojo_data_source_impl.h ('k') | media/mojo/clients/mojo_demuxer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698