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

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

Issue 2667283002: Refactor MediaResource to be multi-stream capable (Closed)
Patch Set: 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/filters/ffmpeg_demuxer_unittest.cc ('k') | media/mojo/clients/mojo_renderer_unittest.cc » ('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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 InitializeRendererFromUrl(client); 64 InitializeRendererFromUrl(client);
65 break; 65 break;
66 } 66 }
67 } 67 }
68 68
69 void MojoRenderer::InitializeRendererFromStreams( 69 void MojoRenderer::InitializeRendererFromStreams(
70 media::RendererClient* client) { 70 media::RendererClient* client) {
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 mojom::DemuxerStream for each demuxer stream and bind its lifetime
75 // the pipe. 75 // to the pipe.
76 DemuxerStream* const audio = media_resource_->GetStream(DemuxerStream::AUDIO); 76 std::vector<DemuxerStream*> streams = media_resource_->GetStreams();
77 DemuxerStream* const video = media_resource_->GetStream(DemuxerStream::VIDEO); 77 std::vector<mojom::DemuxerStreamPtr> stream_proxies;
78 78
79 std::vector<mojom::DemuxerStreamPtr> streams; 79 for (const auto& stream : streams) {
80 if (audio) { 80 mojom::DemuxerStreamPtr stream_proxy;
81 mojom::DemuxerStreamPtr audio_stream;
82 std::unique_ptr<MojoDemuxerStreamImpl> mojo_stream = 81 std::unique_ptr<MojoDemuxerStreamImpl> mojo_stream =
83 base::MakeUnique<MojoDemuxerStreamImpl>(audio, 82 base::MakeUnique<MojoDemuxerStreamImpl>(stream,
84 MakeRequest(&audio_stream)); 83 MakeRequest(&stream_proxy));
84
85 // Using base::Unretained(this) is safe because |this| owns |mojo_stream|, 85 // Using base::Unretained(this) is safe because |this| owns |mojo_stream|,
86 // and the error handler can't be invoked once |mojo_stream| is destroyed. 86 // and the error handler can't be invoked once |mojo_stream| is destroyed.
87 mojo_stream->set_connection_error_handler( 87 mojo_stream->set_connection_error_handler(
88 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError, 88 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError,
89 base::Unretained(this), mojo_stream.get())); 89 base::Unretained(this), mojo_stream.get()));
90
90 streams_.push_back(std::move(mojo_stream)); 91 streams_.push_back(std::move(mojo_stream));
91 streams.push_back(std::move(audio_stream)); 92 stream_proxies.push_back(std::move(stream_proxy));
92 }
93
94 if (video) {
95 mojom::DemuxerStreamPtr video_stream;
96 std::unique_ptr<MojoDemuxerStreamImpl> mojo_stream =
97 base::MakeUnique<MojoDemuxerStreamImpl>(video,
98 MakeRequest(&video_stream));
99 // Using base::Unretained(this) is safe because |this| owns |mojo_stream|,
100 // and the error handler can't be invoked once |mojo_stream| is destroyed.
101 mojo_stream->set_connection_error_handler(
102 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError,
103 base::Unretained(this), mojo_stream.get()));
104 streams_.push_back(std::move(mojo_stream));
105 streams.push_back(std::move(video_stream));
106 } 93 }
107 94
108 BindRemoteRendererIfNeeded(); 95 BindRemoteRendererIfNeeded();
109 96
110 mojom::RendererClientAssociatedPtrInfo client_ptr_info; 97 mojom::RendererClientAssociatedPtrInfo client_ptr_info;
111 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group()); 98 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group());
112 99
113 // Using base::Unretained(this) is safe because |this| owns 100 // Using base::Unretained(this) is safe because |this| owns
114 // |remote_renderer_|, and the callback won't be dispatched if 101 // |remote_renderer_|, and the callback won't be dispatched if
115 // |remote_renderer_| is destroyed. 102 // |remote_renderer_| is destroyed.
116 remote_renderer_->Initialize( 103 remote_renderer_->Initialize(
117 std::move(client_ptr_info), std::move(streams), base::nullopt, 104 std::move(client_ptr_info), std::move(stream_proxies), base::nullopt,
118 base::nullopt, 105 base::nullopt,
119 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client)); 106 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client));
120 } 107 }
121 108
122 void MojoRenderer::InitializeRendererFromUrl(media::RendererClient* client) { 109 void MojoRenderer::InitializeRendererFromUrl(media::RendererClient* client) {
123 DVLOG(2) << __func__; 110 DVLOG(2) << __func__;
124 DCHECK(task_runner_->BelongsToCurrentThread()); 111 DCHECK(task_runner_->BelongsToCurrentThread());
125 112
126 BindRemoteRendererIfNeeded(); 113 BindRemoteRendererIfNeeded();
127 114
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); 378 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED);
392 379
393 if (!flush_cb_.is_null()) 380 if (!flush_cb_.is_null())
394 base::ResetAndReturn(&flush_cb_).Run(); 381 base::ResetAndReturn(&flush_cb_).Run();
395 382
396 if (!cdm_attached_cb_.is_null()) 383 if (!cdm_attached_cb_.is_null())
397 base::ResetAndReturn(&cdm_attached_cb_).Run(false); 384 base::ResetAndReturn(&cdm_attached_cb_).Run(false);
398 } 385 }
399 386
400 } // namespace media 387 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_demuxer_unittest.cc ('k') | media/mojo/clients/mojo_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698