| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/mojo/clients/mojo_data_source_impl.h" |
| 6 |
| 7 #include "media/base/data_buffer.h" |
| 8 #include "media/mojo/common/media_type_converters.h" |
| 9 #include "media/mojo/common/mojo_data_buffer_converter.h" |
| 10 |
| 11 namespace media { |
| 12 |
| 13 MojoDataSourceImpl::MojoDataSourceImpl( |
| 14 media::DataSource* data_source, |
| 15 mojo::InterfaceRequest<mojom::DataSource> request) |
| 16 : binding_(this, std::move(request)), |
| 17 data_source_(data_source), |
| 18 weak_factory_(this) { |
| 19 CHECK(data_source_); |
| 20 } |
| 21 |
| 22 MojoDataSourceImpl::~MojoDataSourceImpl() {} |
| 23 |
| 24 // This is called when our DataSourceClient has connected itself and is |
| 25 // ready to receive messages. Send an initial config and notify it that |
| 26 // we are now ready for business. |
| 27 void MojoDataSourceImpl::Initialize(const InitializeCallback& callback) { |
| 28 DVLOG(2) << __func__; |
| 29 |
| 30 mojo::ScopedDataPipeConsumerHandle remote_consumer_handle; |
| 31 |
| 32 // TODO(j.isorce): fix TODO in media/mojo/common/mojo_data_buffer_converter.cc |
| 33 // CreateDataPipe first and reflect the fix here. For now the following value |
| 34 // should be enough for audio + video. |
| 35 // Other option is to set the capacity as a multiple of the bitrate got from |
| 36 // SetBitrate below. |
| 37 mojo_data_buffer_writer_ = MojoDataBufferWriter::Create( |
| 38 /* capacity_num_bytes */ 3 * 1024 * 1024, &remote_consumer_handle); |
| 39 |
| 40 callback.Run(std::move(remote_consumer_handle)); |
| 41 } |
| 42 |
| 43 void MojoDataSourceImpl::Read(int64_t position, |
| 44 int size, |
| 45 const ReadCallback& callback) { |
| 46 std::unique_ptr<uint8_t[]> data(new uint8_t[size]); |
| 47 |
| 48 data_source_->Read( |
| 49 position, size, data.get(), |
| 50 base::Bind(&MojoDataSourceImpl::OnRead, weak_factory_.GetWeakPtr(), |
| 51 callback, base::Passed(std::move(data)))); |
| 52 } |
| 53 |
| 54 void MojoDataSourceImpl::OnRead(const ReadCallback& callback, |
| 55 std::unique_ptr<uint8_t[]> data, |
| 56 int size) { |
| 57 mojom::DataBufferPtr mojo_buffer; |
| 58 if (size != media::DataSource::kReadError && |
| 59 size != media::DataSource::kAborted) { |
| 60 scoped_refptr<media::DataBuffer> buffer = |
| 61 new media::DataBuffer(std::move(data), size); |
| 62 mojo_buffer = mojo_data_buffer_writer_->WriteDataBuffer(buffer); |
| 63 } |
| 64 callback.Run(std::move(mojo_buffer), size); |
| 65 } |
| 66 |
| 67 void MojoDataSourceImpl::Stop() { |
| 68 data_source_->Stop(); |
| 69 } |
| 70 |
| 71 void MojoDataSourceImpl::Abort() { |
| 72 data_source_->Abort(); |
| 73 } |
| 74 |
| 75 void MojoDataSourceImpl::GetSize(const GetSizeCallback& callback) { |
| 76 int64_t size = 0; |
| 77 bool success = data_source_->GetSize(&size); |
| 78 callback.Run(success, size); |
| 79 } |
| 80 |
| 81 void MojoDataSourceImpl::IsStreaming(const IsStreamingCallback& callback) { |
| 82 bool is_streaming = data_source_->IsStreaming(); |
| 83 callback.Run(is_streaming); |
| 84 } |
| 85 |
| 86 void MojoDataSourceImpl::SetBitrate(int bitrate) { |
| 87 data_source_->SetBitrate(bitrate); |
| 88 } |
| 89 |
| 90 } // namespace media |
| OLD | NEW |