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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« 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