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

Side by Side Diff: media/mojo/clients/mojo_renderer.cc

Issue 2383663002: Make mojo renderer capable of supporting multiple streams/tracks (Closed)
Patch Set: nit 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_renderer.h ('k') | media/mojo/interfaces/renderer.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/mojo/clients/mojo_renderer.h" 5 #include "media/mojo/clients/mojo_renderer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 DVLOG(1) << __func__; 71 DVLOG(1) << __func__;
72 DCHECK(task_runner_->BelongsToCurrentThread()); 72 DCHECK(task_runner_->BelongsToCurrentThread());
73 73
74 // Create audio and video mojom::DemuxerStream and bind its lifetime to 74 // Create audio and video mojom::DemuxerStream and bind its lifetime to
75 // the pipe. 75 // the pipe.
76 DemuxerStream* const audio = 76 DemuxerStream* const audio =
77 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO); 77 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO);
78 DemuxerStream* const video = 78 DemuxerStream* const video =
79 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO); 79 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO);
80 80
81 mojom::DemuxerStreamPtr audio_stream; 81 std::vector<mojom::DemuxerStreamPtr> streams;
82 if (audio) { 82 if (audio) {
83 audio_stream_.reset( 83 mojom::DemuxerStreamPtr audio_stream;
84 new MojoDemuxerStreamImpl(audio, MakeRequest(&audio_stream))); 84 std::unique_ptr<MojoDemuxerStreamImpl> mojo_stream =
85 // Using base::Unretained(this) is safe because |this| owns 85 base::MakeUnique<MojoDemuxerStreamImpl>(audio,
86 // |audio_stream_|, and the error handler can't be invoked once 86 MakeRequest(&audio_stream));
87 // |audio_stream_| is destroyed. 87 // Using base::Unretained(this) is safe because |this| owns |mojo_stream|,
88 audio_stream_->set_connection_error_handler( 88 // and the error handler can't be invoked once |mojo_stream| is destroyed.
89 mojo_stream->set_connection_error_handler(
89 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError, 90 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError,
90 base::Unretained(this), DemuxerStream::AUDIO)); 91 base::Unretained(this), mojo_stream.get()));
92 streams_.push_back(std::move(mojo_stream));
93 streams.push_back(std::move(audio_stream));
91 } 94 }
92 95
93 mojom::DemuxerStreamPtr video_stream;
94 if (video) { 96 if (video) {
95 video_stream_.reset( 97 mojom::DemuxerStreamPtr video_stream;
96 new MojoDemuxerStreamImpl(video, MakeRequest(&video_stream))); 98 std::unique_ptr<MojoDemuxerStreamImpl> mojo_stream =
97 // Using base::Unretained(this) is safe because |this| owns 99 base::MakeUnique<MojoDemuxerStreamImpl>(video,
98 // |video_stream_|, and the error handler can't be invoked once 100 MakeRequest(&video_stream));
99 // |video_stream_| is destroyed. 101 // Using base::Unretained(this) is safe because |this| owns |mojo_stream|,
100 video_stream_->set_connection_error_handler( 102 // and the error handler can't be invoked once |mojo_stream| is destroyed.
103 mojo_stream->set_connection_error_handler(
101 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError, 104 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError,
102 base::Unretained(this), DemuxerStream::VIDEO)); 105 base::Unretained(this), mojo_stream.get()));
106 streams_.push_back(std::move(mojo_stream));
107 streams.push_back(std::move(video_stream));
103 } 108 }
104 109
105 BindRemoteRendererIfNeeded(); 110 BindRemoteRendererIfNeeded();
106 111
107 mojom::RendererClientAssociatedPtrInfo client_ptr_info; 112 mojom::RendererClientAssociatedPtrInfo client_ptr_info;
108 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group()); 113 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group());
109 114
110 // Using base::Unretained(this) is safe because |this| owns 115 // Using base::Unretained(this) is safe because |this| owns
111 // |remote_renderer_|, and the callback won't be dispatched if 116 // |remote_renderer_|, and the callback won't be dispatched if
112 // |remote_renderer_| is destroyed. 117 // |remote_renderer_| is destroyed.
113 remote_renderer_->Initialize( 118 remote_renderer_->Initialize(
114 std::move(client_ptr_info), std::move(audio_stream), 119 std::move(client_ptr_info), std::move(streams), base::nullopt,
115 std::move(video_stream), base::nullopt, base::nullopt, 120 base::nullopt,
116 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client)); 121 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client));
117 } 122 }
118 123
119 void MojoRenderer::InitializeRendererFromUrl(media::RendererClient* client) { 124 void MojoRenderer::InitializeRendererFromUrl(media::RendererClient* client) {
120 DVLOG(2) << __func__; 125 DVLOG(2) << __func__;
121 DCHECK(task_runner_->BelongsToCurrentThread()); 126 DCHECK(task_runner_->BelongsToCurrentThread());
122 127
123 BindRemoteRendererIfNeeded(); 128 BindRemoteRendererIfNeeded();
124 129
125 mojom::RendererClientAssociatedPtrInfo client_ptr_info; 130 mojom::RendererClientAssociatedPtrInfo client_ptr_info;
126 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group()); 131 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group());
127 132
128 MediaUrlParams url_params = demuxer_stream_provider_->GetMediaUrlParams(); 133 MediaUrlParams url_params = demuxer_stream_provider_->GetMediaUrlParams();
129 134
130 // Using base::Unretained(this) is safe because |this| owns 135 // Using base::Unretained(this) is safe because |this| owns
131 // |remote_renderer_|, and the callback won't be dispatched if 136 // |remote_renderer_|, and the callback won't be dispatched if
132 // |remote_renderer_| is destroyed. 137 // |remote_renderer_| is destroyed.
138 std::vector<mojom::DemuxerStreamPtr> streams;
133 remote_renderer_->Initialize( 139 remote_renderer_->Initialize(
134 std::move(client_ptr_info), mojom::DemuxerStreamPtr(), 140 std::move(client_ptr_info), std::move(streams), url_params.media_url,
135 mojom::DemuxerStreamPtr(), url_params.media_url,
136 url_params.first_party_for_cookies, 141 url_params.first_party_for_cookies,
137 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client)); 142 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client));
138 } 143 }
139 144
140 void MojoRenderer::SetCdm(CdmContext* cdm_context, 145 void MojoRenderer::SetCdm(CdmContext* cdm_context,
141 const CdmAttachedCB& cdm_attached_cb) { 146 const CdmAttachedCB& cdm_attached_cb) {
142 DVLOG(1) << __func__; 147 DVLOG(1) << __func__;
143 DCHECK(task_runner_->BelongsToCurrentThread()); 148 DCHECK(task_runner_->BelongsToCurrentThread());
144 DCHECK(cdm_context); 149 DCHECK(cdm_context);
145 DCHECK(!cdm_attached_cb.is_null()); 150 DCHECK(!cdm_attached_cb.is_null());
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 DVLOG(1) << __func__; 313 DVLOG(1) << __func__;
309 DCHECK(task_runner_->BelongsToCurrentThread()); 314 DCHECK(task_runner_->BelongsToCurrentThread());
310 315
311 encountered_error_ = true; 316 encountered_error_ = true;
312 CancelPendingCallbacks(); 317 CancelPendingCallbacks();
313 318
314 if (client_) 319 if (client_)
315 client_->OnError(PIPELINE_ERROR_DECODE); 320 client_->OnError(PIPELINE_ERROR_DECODE);
316 } 321 }
317 322
318 void MojoRenderer::OnDemuxerStreamConnectionError(DemuxerStream::Type type) { 323 void MojoRenderer::OnDemuxerStreamConnectionError(
319 DVLOG(1) << __func__ << ": " << type; 324 MojoDemuxerStreamImpl* stream) {
325 DVLOG(1) << __func__ << ": stream=" << stream;
320 DCHECK(task_runner_->BelongsToCurrentThread()); 326 DCHECK(task_runner_->BelongsToCurrentThread());
321 327
322 if (type == DemuxerStream::AUDIO) { 328 for (auto& s : streams_) {
323 audio_stream_.reset(); 329 if (s.get() == stream) {
324 } else if (type == DemuxerStream::VIDEO) { 330 s.reset();
325 video_stream_.reset(); 331 return;
326 } else { 332 }
327 NOTREACHED() << "Unexpected demuxer stream type: " << type;
328 } 333 }
334 NOTREACHED() << "Unrecognized demuxer stream=" << stream;
329 } 335 }
330 336
331 void MojoRenderer::BindRemoteRendererIfNeeded() { 337 void MojoRenderer::BindRemoteRendererIfNeeded() {
332 DVLOG(2) << __func__; 338 DVLOG(2) << __func__;
333 DCHECK(task_runner_->BelongsToCurrentThread()); 339 DCHECK(task_runner_->BelongsToCurrentThread());
334 340
335 // If |remote_renderer_| has already been bound, do nothing. 341 // If |remote_renderer_| has already been bound, do nothing.
336 // Note that after Bind() is called, |remote_renderer_| is always bound even 342 // Note that after Bind() is called, |remote_renderer_| is always bound even
337 // after connection error. 343 // after connection error.
338 if (remote_renderer_.is_bound()) 344 if (remote_renderer_.is_bound())
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); 393 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED);
388 394
389 if (!flush_cb_.is_null()) 395 if (!flush_cb_.is_null())
390 base::ResetAndReturn(&flush_cb_).Run(); 396 base::ResetAndReturn(&flush_cb_).Run();
391 397
392 if (!cdm_attached_cb_.is_null()) 398 if (!cdm_attached_cb_.is_null())
393 base::ResetAndReturn(&cdm_attached_cb_).Run(false); 399 base::ResetAndReturn(&cdm_attached_cb_).Run(false);
394 } 400 }
395 401
396 } // namespace media 402 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/clients/mojo_renderer.h ('k') | media/mojo/interfaces/renderer.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698