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

Side by Side Diff: chromecast/media/service/cast_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 | « chromecast/media/cma/test/frame_segmenter_for_test.cc ('k') | media/base/demuxer_perftest.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chromecast/media/service/cast_renderer.h" 5 #include "chromecast/media/service/cast_renderer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "chromecast/base/task_runner_impl.h" 9 #include "chromecast/base/task_runner_impl.h"
10 #include "chromecast/media/base/video_resolution_policy.h" 10 #include "chromecast/media/base/video_resolution_policy.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // Create pipeline. 84 // Create pipeline.
85 MediaPipelineClient pipeline_client; 85 MediaPipelineClient pipeline_client;
86 pipeline_client.error_cb = 86 pipeline_client.error_cb =
87 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr()); 87 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr());
88 pipeline_client.buffering_state_cb = base::Bind( 88 pipeline_client.buffering_state_cb = base::Bind(
89 &CastRenderer::OnBufferingStateChange, weak_factory_.GetWeakPtr()); 89 &CastRenderer::OnBufferingStateChange, weak_factory_.GetWeakPtr());
90 pipeline_.reset(new MediaPipelineImpl()); 90 pipeline_.reset(new MediaPipelineImpl());
91 pipeline_->SetClient(pipeline_client); 91 pipeline_->SetClient(pipeline_client);
92 pipeline_->Initialize(load_type, std::move(backend)); 92 pipeline_->Initialize(load_type, std::move(backend));
93 93
94 // TODO(servolk): Implement support for multiple streams. For now use the
95 // first enabled audio and video streams to preserve the existing behavior.
96 std::vector<::media::DemuxerStream*> streams = media_resource->GetStreams();
97 ::media::DemuxerStream* audio_stream = nullptr;
98 ::media::DemuxerStream* video_stream = nullptr;
99 for (const auto& stream : streams) {
100 if (!audio_stream && stream->enabled() &&
101 stream->type() == ::media::DemuxerStream::AUDIO) {
102 audio_stream = stream;
103 }
104 if (!video_stream && stream->enabled() &&
105 stream->type() == ::media::DemuxerStream::VIDEO) {
106 video_stream = stream;
107 }
108 }
109
94 // Initialize audio. 110 // Initialize audio.
95 ::media::DemuxerStream* audio_stream =
96 media_resource->GetStream(::media::DemuxerStream::AUDIO);
97 if (audio_stream) { 111 if (audio_stream) {
98 AvPipelineClient audio_client; 112 AvPipelineClient audio_client;
99 audio_client.wait_for_key_cb = base::Bind( 113 audio_client.wait_for_key_cb = base::Bind(
100 &CastRenderer::OnWaitingForDecryptionKey, weak_factory_.GetWeakPtr()); 114 &CastRenderer::OnWaitingForDecryptionKey, weak_factory_.GetWeakPtr());
101 audio_client.eos_cb = base::Bind(&CastRenderer::OnEnded, 115 audio_client.eos_cb = base::Bind(&CastRenderer::OnEnded,
102 weak_factory_.GetWeakPtr(), STREAM_AUDIO); 116 weak_factory_.GetWeakPtr(), STREAM_AUDIO);
103 audio_client.playback_error_cb = 117 audio_client.playback_error_cb =
104 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr()); 118 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr());
105 audio_client.statistics_cb = base::Bind(&CastRenderer::OnStatisticsUpdate, 119 audio_client.statistics_cb = base::Bind(&CastRenderer::OnStatisticsUpdate,
106 weak_factory_.GetWeakPtr()); 120 weak_factory_.GetWeakPtr());
107 std::unique_ptr<CodedFrameProvider> frame_provider(new DemuxerStreamAdapter( 121 std::unique_ptr<CodedFrameProvider> frame_provider(new DemuxerStreamAdapter(
108 task_runner_, media_task_runner_factory_, audio_stream)); 122 task_runner_, media_task_runner_factory_, audio_stream));
109 123
110 ::media::PipelineStatus status = 124 ::media::PipelineStatus status =
111 pipeline_->InitializeAudio(audio_stream->audio_decoder_config(), 125 pipeline_->InitializeAudio(audio_stream->audio_decoder_config(),
112 audio_client, std::move(frame_provider)); 126 audio_client, std::move(frame_provider));
113 if (status != ::media::PIPELINE_OK) { 127 if (status != ::media::PIPELINE_OK) {
114 init_cb.Run(status); 128 init_cb.Run(status);
115 return; 129 return;
116 } 130 }
117 audio_stream->EnableBitstreamConverter(); 131 audio_stream->EnableBitstreamConverter();
118 } 132 }
119 133
120 // Initialize video. 134 // Initialize video.
121 ::media::DemuxerStream* video_stream =
122 media_resource->GetStream(::media::DemuxerStream::VIDEO);
123 if (video_stream) { 135 if (video_stream) {
124 VideoPipelineClient video_client; 136 VideoPipelineClient video_client;
125 video_client.av_pipeline_client.wait_for_key_cb = base::Bind( 137 video_client.av_pipeline_client.wait_for_key_cb = base::Bind(
126 &CastRenderer::OnWaitingForDecryptionKey, weak_factory_.GetWeakPtr()); 138 &CastRenderer::OnWaitingForDecryptionKey, weak_factory_.GetWeakPtr());
127 video_client.av_pipeline_client.eos_cb = base::Bind( 139 video_client.av_pipeline_client.eos_cb = base::Bind(
128 &CastRenderer::OnEnded, weak_factory_.GetWeakPtr(), STREAM_VIDEO); 140 &CastRenderer::OnEnded, weak_factory_.GetWeakPtr(), STREAM_VIDEO);
129 video_client.av_pipeline_client.playback_error_cb = 141 video_client.av_pipeline_client.playback_error_cb =
130 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr()); 142 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr());
131 video_client.av_pipeline_client.statistics_cb = base::Bind( 143 video_client.av_pipeline_client.statistics_cb = base::Bind(
132 &CastRenderer::OnStatisticsUpdate, weak_factory_.GetWeakPtr()); 144 &CastRenderer::OnStatisticsUpdate, weak_factory_.GetWeakPtr());
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 269 }
258 270
259 void CastRenderer::OnVideoOpacityChange(bool opaque) { 271 void CastRenderer::OnVideoOpacityChange(bool opaque) {
260 DCHECK(task_runner_->BelongsToCurrentThread()); 272 DCHECK(task_runner_->BelongsToCurrentThread());
261 DCHECK(opaque); 273 DCHECK(opaque);
262 client_->OnVideoOpacityChange(opaque); 274 client_->OnVideoOpacityChange(opaque);
263 } 275 }
264 276
265 } // namespace media 277 } // namespace media
266 } // namespace chromecast 278 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/media/cma/test/frame_segmenter_for_test.cc ('k') | media/base/demuxer_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698