OLD | NEW |
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> mojo_streams; |
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 streams_.emplace_back( | 81 streams_.emplace_back( |
85 new MojoDemuxerStreamImpl(audio, MakeRequest(&audio_stream))); | 82 new MojoDemuxerStreamImpl(s, MakeRequest(&stream_proxy))); |
86 MojoDemuxerStreamImpl* mojo_stream = streams_.back().get(); | 83 MojoDemuxerStreamImpl* mojo_stream = streams_.back().get(); |
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)); | 88 base::Unretained(this), mojo_stream)); |
92 streams.push_back(std::move(audio_stream)); | 89 mojo_streams.push_back(std::move(stream_proxy)); |
93 } | |
94 | |
95 if (video) { | |
96 mojom::DemuxerStreamPtr video_stream; | |
97 streams_.emplace_back( | |
98 new MojoDemuxerStreamImpl(video, MakeRequest(&video_stream))); | |
99 MojoDemuxerStreamImpl* mojo_stream = streams_.back().get(); | |
100 // Using base::Unretained(this) is safe because |this| owns |mojo_stream|, | |
101 // and the error handler can't be invoked once |mojo_stream| is destroyed. | |
102 mojo_stream->set_connection_error_handler( | |
103 base::Bind(&MojoRenderer::OnDemuxerStreamConnectionError, | |
104 base::Unretained(this), mojo_stream)); | |
105 streams.push_back(std::move(video_stream)); | |
106 } | 90 } |
107 | 91 |
108 BindRemoteRendererIfNeeded(); | 92 BindRemoteRendererIfNeeded(); |
109 | 93 |
110 mojom::RendererClientAssociatedPtrInfo client_ptr_info; | 94 mojom::RendererClientAssociatedPtrInfo client_ptr_info; |
111 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group()); | 95 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group()); |
112 | 96 |
113 // Using base::Unretained(this) is safe because |this| owns | 97 // Using base::Unretained(this) is safe because |this| owns |
114 // |remote_renderer_|, and the callback won't be dispatched if | 98 // |remote_renderer_|, and the callback won't be dispatched if |
115 // |remote_renderer_| is destroyed. | 99 // |remote_renderer_| is destroyed. |
116 remote_renderer_->Initialize( | 100 remote_renderer_->Initialize( |
117 std::move(client_ptr_info), std::move(streams), base::nullopt, | 101 std::move(client_ptr_info), std::move(mojo_streams), base::nullopt, |
118 base::nullopt, | 102 base::nullopt, |
119 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client)); | 103 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client)); |
120 } | 104 } |
121 | 105 |
122 void MojoRenderer::InitializeRendererFromUrl(media::RendererClient* client) { | 106 void MojoRenderer::InitializeRendererFromUrl(media::RendererClient* client) { |
123 DVLOG(2) << __func__; | 107 DVLOG(2) << __func__; |
124 DCHECK(task_runner_->BelongsToCurrentThread()); | 108 DCHECK(task_runner_->BelongsToCurrentThread()); |
125 | 109 |
126 BindRemoteRendererIfNeeded(); | 110 BindRemoteRendererIfNeeded(); |
127 | 111 |
128 mojom::RendererClientAssociatedPtrInfo client_ptr_info; | 112 mojom::RendererClientAssociatedPtrInfo client_ptr_info; |
129 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group()); | 113 client_binding_.Bind(&client_ptr_info, remote_renderer_.associated_group()); |
130 | 114 |
131 MediaUrlParams url_params = demuxer_stream_provider_->GetMediaUrlParams(); | 115 MediaUrlParams url_params = media_resource_->GetMediaUrlParams(); |
132 | 116 |
133 // Using base::Unretained(this) is safe because |this| owns | 117 // Using base::Unretained(this) is safe because |this| owns |
134 // |remote_renderer_|, and the callback won't be dispatched if | 118 // |remote_renderer_|, and the callback won't be dispatched if |
135 // |remote_renderer_| is destroyed. | 119 // |remote_renderer_| is destroyed. |
136 std::vector<mojom::DemuxerStreamPtr> streams; | 120 std::vector<mojom::DemuxerStreamPtr> streams; |
137 remote_renderer_->Initialize( | 121 remote_renderer_->Initialize( |
138 std::move(client_ptr_info), std::move(streams), url_params.media_url, | 122 std::move(client_ptr_info), std::move(streams), url_params.media_url, |
139 url_params.first_party_for_cookies, | 123 url_params.first_party_for_cookies, |
140 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client)); | 124 base::Bind(&MojoRenderer::OnInitialized, base::Unretained(this), client)); |
141 } | 125 } |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); | 375 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); |
392 | 376 |
393 if (!flush_cb_.is_null()) | 377 if (!flush_cb_.is_null()) |
394 base::ResetAndReturn(&flush_cb_).Run(); | 378 base::ResetAndReturn(&flush_cb_).Run(); |
395 | 379 |
396 if (!cdm_attached_cb_.is_null()) | 380 if (!cdm_attached_cb_.is_null()) |
397 base::ResetAndReturn(&cdm_attached_cb_).Run(false); | 381 base::ResetAndReturn(&cdm_attached_cb_).Run(false); |
398 } | 382 } |
399 | 383 |
400 } // namespace media | 384 } // namespace media |
OLD | NEW |