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

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

Issue 2491043003: MediaResource refactoring to support multiple streams (Closed)
Patch Set: rebase 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
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"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "media/base/demuxer_stream_provider.h" 13 #include "media/base/media_resource.h"
14 #include "media/base/pipeline_status.h" 14 #include "media/base/pipeline_status.h"
15 #include "media/base/renderer_client.h" 15 #include "media/base/renderer_client.h"
16 #include "media/base/video_renderer_sink.h" 16 #include "media/base/video_renderer_sink.h"
17 #include "media/mojo/clients/mojo_demuxer_stream_impl.h" 17 #include "media/mojo/clients/mojo_demuxer_stream_impl.h"
18 #include "media/renderers/video_overlay_factory.h" 18 #include "media/renderers/video_overlay_factory.h"
19 19
20 namespace media { 20 namespace media {
21 21
22 MojoRenderer::MojoRenderer( 22 MojoRenderer::MojoRenderer(
23 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 23 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
24 std::unique_ptr<VideoOverlayFactory> video_overlay_factory, 24 std::unique_ptr<VideoOverlayFactory> video_overlay_factory,
25 VideoRendererSink* video_renderer_sink, 25 VideoRendererSink* video_renderer_sink,
26 mojom::RendererPtr remote_renderer) 26 mojom::RendererPtr remote_renderer)
27 : task_runner_(task_runner), 27 : task_runner_(task_runner),
28 video_overlay_factory_(std::move(video_overlay_factory)), 28 video_overlay_factory_(std::move(video_overlay_factory)),
29 video_renderer_sink_(video_renderer_sink), 29 video_renderer_sink_(video_renderer_sink),
30 remote_renderer_info_(remote_renderer.PassInterface()), 30 remote_renderer_info_(remote_renderer.PassInterface()),
31 client_binding_(this), 31 client_binding_(this),
32 media_time_interpolator_(&media_clock_) { 32 media_time_interpolator_(&media_clock_) {
33 DVLOG(1) << __func__; 33 DVLOG(1) << __func__;
34 } 34 }
35 35
36 MojoRenderer::~MojoRenderer() { 36 MojoRenderer::~MojoRenderer() {
37 DVLOG(1) << __func__; 37 DVLOG(1) << __func__;
38 DCHECK(task_runner_->BelongsToCurrentThread()); 38 DCHECK(task_runner_->BelongsToCurrentThread());
39 39
40 CancelPendingCallbacks(); 40 CancelPendingCallbacks();
41 } 41 }
42 42
43 void MojoRenderer::Initialize(DemuxerStreamProvider* demuxer_stream_provider, 43 void MojoRenderer::Initialize(MediaResource* media_resource,
44 media::RendererClient* client, 44 media::RendererClient* client,
45 const PipelineStatusCB& init_cb) { 45 const PipelineStatusCB& init_cb) {
46 DVLOG(1) << __func__; 46 DVLOG(1) << __func__;
47 DCHECK(task_runner_->BelongsToCurrentThread()); 47 DCHECK(task_runner_->BelongsToCurrentThread());
48 DCHECK(demuxer_stream_provider); 48 DCHECK(media_resource);
49 49
50 if (encountered_error_) { 50 if (encountered_error_) {
51 task_runner_->PostTask( 51 task_runner_->PostTask(
52 FROM_HERE, base::Bind(init_cb, PIPELINE_ERROR_INITIALIZATION_FAILED)); 52 FROM_HERE, base::Bind(init_cb, PIPELINE_ERROR_INITIALIZATION_FAILED));
53 return; 53 return;
54 } 54 }
55 55
56 demuxer_stream_provider_ = demuxer_stream_provider; 56 media_resource_ = media_resource;
57 init_cb_ = init_cb; 57 init_cb_ = init_cb;
58 58
59 switch (demuxer_stream_provider_->GetType()) { 59 switch (media_resource_->GetType()) {
60 case DemuxerStreamProvider::Type::STREAM: 60 case MediaResource::Type::STREAM:
61 InitializeRendererFromStreams(client); 61 InitializeRendererFromStreams(client);
62 break; 62 break;
63 case DemuxerStreamProvider::Type::URL: 63 case MediaResource::Type::URL:
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 = 76 std::vector<DemuxerStream*> streams = media_resource_->GetStreams();
77 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO); 77 std::vector<mojom::DemuxerStreamPtr> stream_proxies;
78 DemuxerStream* const video =
79 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO);
80 78
81 std::vector<mojom::DemuxerStreamPtr> streams; 79 for (const auto& s : streams) {
82 if (audio) { 80 mojom::DemuxerStreamPtr stream_proxy;
83 mojom::DemuxerStreamPtr audio_stream;
84 std::unique_ptr<MojoDemuxerStreamImpl> mojo_stream = 81 std::unique_ptr<MojoDemuxerStreamImpl> mojo_stream =
85 base::MakeUnique<MojoDemuxerStreamImpl>(audio, 82 base::MakeUnique<MojoDemuxerStreamImpl>(s, MakeRequest(&stream_proxy));
86 MakeRequest(&audio_stream)); 83
87 // Using base::Unretained(this) is safe because |this| owns |mojo_stream|, 84 // Using base::Unretained(this) is safe because |this| owns |mojo_stream|,
88 // and the error handler can't be invoked once |mojo_stream| is destroyed. 85 // and the error handler can't be invoked once |mojo_stream| is destroyed.
89 mojo_stream->set_connection_error_handler( 86 mojo_stream->set_connection_error_handler(
90 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError, 87 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError,
91 base::Unretained(this), mojo_stream.get())); 88 base::Unretained(this), mojo_stream.get()));
89
90 stream_proxies.push_back(std::move(stream_proxy));
92 streams_.push_back(std::move(mojo_stream)); 91 streams_.push_back(std::move(mojo_stream));
93 streams.push_back(std::move(audio_stream));
94 }
95
96 if (video) {
97 mojom::DemuxerStreamPtr video_stream;
98 std::unique_ptr<MojoDemuxerStreamImpl> mojo_stream =
99 base::MakeUnique<MojoDemuxerStreamImpl>(video,
100 MakeRequest(&video_stream));
101 // Using base::Unretained(this) is safe because |this| owns |mojo_stream|,
102 // and the error handler can't be invoked once |mojo_stream| is destroyed.
103 mojo_stream->set_connection_error_handler(
104 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError,
105 base::Unretained(this), mojo_stream.get()));
106 streams_.push_back(std::move(mojo_stream));
107 streams.push_back(std::move(video_stream));
108 } 92 }
109 93
110 BindRemoteRendererIfNeeded(); 94 BindRemoteRendererIfNeeded();
111 95
112 mojom::RendererClientAssociatedPtrInfo client_ptr_info; 96 mojom::RendererClientAssociatedPtrInfo client_ptr_info;
113 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group()); 97 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group());
114 98
115 // Using base::Unretained(this) is safe because |this| owns 99 // Using base::Unretained(this) is safe because |this| owns
116 // |remote_renderer_|, and the callback won't be dispatched if 100 // |remote_renderer_|, and the callback won't be dispatched if
117 // |remote_renderer_| is destroyed. 101 // |remote_renderer_| is destroyed.
118 remote_renderer_->Initialize( 102 remote_renderer_->Initialize(
119 std::move(client_ptr_info), std::move(streams), base::nullopt, 103 std::move(client_ptr_info), std::move(stream_proxies), base::nullopt,
120 base::nullopt, 104 base::nullopt,
121 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client)); 105 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client));
122 } 106 }
123 107
124 void MojoRenderer::InitializeRendererFromUrl(media::RendererClient* client) { 108 void MojoRenderer::InitializeRendererFromUrl(media::RendererClient* client) {
125 DVLOG(2) << __func__; 109 DVLOG(2) << __func__;
126 DCHECK(task_runner_->BelongsToCurrentThread()); 110 DCHECK(task_runner_->BelongsToCurrentThread());
127 111
128 BindRemoteRendererIfNeeded(); 112 BindRemoteRendererIfNeeded();
129 113
130 mojom::RendererClientAssociatedPtrInfo client_ptr_info; 114 mojom::RendererClientAssociatedPtrInfo client_ptr_info;
131 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group()); 115 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group());
132 116
133 MediaUrlParams url_params = demuxer_stream_provider_->GetMediaUrlParams(); 117 MediaUrlParams url_params = media_resource_->GetMediaUrlParams();
134 118
135 // Using base::Unretained(this) is safe because |this| owns 119 // Using base::Unretained(this) is safe because |this| owns
136 // |remote_renderer_|, and the callback won't be dispatched if 120 // |remote_renderer_|, and the callback won't be dispatched if
137 // |remote_renderer_| is destroyed. 121 // |remote_renderer_| is destroyed.
138 std::vector<mojom::DemuxerStreamPtr> streams; 122 std::vector<mojom::DemuxerStreamPtr> streams;
139 remote_renderer_->Initialize( 123 remote_renderer_->Initialize(
140 std::move(client_ptr_info), std::move(streams), url_params.media_url, 124 std::move(client_ptr_info), std::move(streams), url_params.media_url,
141 url_params.first_party_for_cookies, 125 url_params.first_party_for_cookies,
142 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client)); 126 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client));
143 } 127 }
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); 377 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED);
394 378
395 if (!flush_cb_.is_null()) 379 if (!flush_cb_.is_null())
396 base::ResetAndReturn(&flush_cb_).Run(); 380 base::ResetAndReturn(&flush_cb_).Run();
397 381
398 if (!cdm_attached_cb_.is_null()) 382 if (!cdm_attached_cb_.is_null())
399 base::ResetAndReturn(&cdm_attached_cb_).Run(false); 383 base::ResetAndReturn(&cdm_attached_cb_).Run(false);
400 } 384 }
401 385
402 } // namespace media 386 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698