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

Side by Side Diff: chromecast/media/service/cast_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 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"
11 #include "chromecast/media/cdm/cast_cdm_context.h" 11 #include "chromecast/media/cdm/cast_cdm_context.h"
12 #include "chromecast/media/cma/base/balanced_media_task_runner_factory.h" 12 #include "chromecast/media/cma/base/balanced_media_task_runner_factory.h"
13 #include "chromecast/media/cma/base/cma_logging.h" 13 #include "chromecast/media/cma/base/cma_logging.h"
14 #include "chromecast/media/cma/base/demuxer_stream_adapter.h" 14 #include "chromecast/media/cma/base/demuxer_stream_adapter.h"
15 #include "chromecast/media/cma/pipeline/media_pipeline_impl.h" 15 #include "chromecast/media/cma/pipeline/media_pipeline_impl.h"
16 #include "chromecast/media/cma/pipeline/video_pipeline_client.h" 16 #include "chromecast/media/cma/pipeline/video_pipeline_client.h"
17 #include "chromecast/public/media/media_pipeline_backend.h" 17 #include "chromecast/public/media/media_pipeline_backend.h"
18 #include "chromecast/public/media/media_pipeline_device_params.h" 18 #include "chromecast/public/media/media_pipeline_device_params.h"
19 #include "media/base/audio_decoder_config.h" 19 #include "media/base/audio_decoder_config.h"
20 #include "media/base/demuxer_stream.h" 20 #include "media/base/demuxer_stream.h"
21 #include "media/base/demuxer_stream_provider.h"
22 #include "media/base/media_log.h" 21 #include "media/base/media_log.h"
22 #include "media/base/media_resource.h"
23 #include "media/base/renderer_client.h" 23 #include "media/base/renderer_client.h"
24 24
25 namespace chromecast { 25 namespace chromecast {
26 namespace media { 26 namespace media {
27 27
28 namespace { 28 namespace {
29 // Maximum difference between audio frame PTS and video frame PTS 29 // Maximum difference between audio frame PTS and video frame PTS
30 // for frames read from the DemuxerStream. 30 // for frames read from the DemuxerStream.
31 const base::TimeDelta kMaxDeltaFetcher(base::TimeDelta::FromMilliseconds(2000)); 31 const base::TimeDelta kMaxDeltaFetcher(base::TimeDelta::FromMilliseconds(2000));
32 } // namespace 32 } // namespace
(...skipping 21 matching lines...) Expand all
54 } 54 }
55 55
56 CastRenderer::~CastRenderer() { 56 CastRenderer::~CastRenderer() {
57 CMALOG(kLogControl) << __FUNCTION__ << ": " << this; 57 CMALOG(kLogControl) << __FUNCTION__ << ": " << this;
58 DCHECK(task_runner_->BelongsToCurrentThread()); 58 DCHECK(task_runner_->BelongsToCurrentThread());
59 59
60 if (video_resolution_policy_) 60 if (video_resolution_policy_)
61 video_resolution_policy_->RemoveObserver(this); 61 video_resolution_policy_->RemoveObserver(this);
62 } 62 }
63 63
64 void CastRenderer::Initialize( 64 void CastRenderer::Initialize(::media::MediaResource* media_resource,
65 ::media::DemuxerStreamProvider* demuxer_stream_provider, 65 ::media::RendererClient* client,
66 ::media::RendererClient* client, 66 const ::media::PipelineStatusCB& init_cb) {
67 const ::media::PipelineStatusCB& init_cb) {
68 CMALOG(kLogControl) << __FUNCTION__ << ": " << this; 67 CMALOG(kLogControl) << __FUNCTION__ << ": " << this;
69 DCHECK(task_runner_->BelongsToCurrentThread()); 68 DCHECK(task_runner_->BelongsToCurrentThread());
70 69
71 // Create pipeline backend. 70 // Create pipeline backend.
72 media_resource_usage_.reset( 71 media_resource_usage_.reset(
73 new MediaResourceTracker::ScopedUsage(media_resource_tracker_)); 72 new MediaResourceTracker::ScopedUsage(media_resource_tracker_));
74 backend_task_runner_.reset(new TaskRunnerImpl()); 73 backend_task_runner_.reset(new TaskRunnerImpl());
75 // TODO(erickung): crbug.com/443956. Need to provide right LoadType. 74 // TODO(erickung): crbug.com/443956. Need to provide right LoadType.
76 LoadType load_type = kLoadTypeMediaSource; 75 LoadType load_type = kLoadTypeMediaSource;
77 MediaPipelineDeviceParams::MediaSyncType sync_type = 76 MediaPipelineDeviceParams::MediaSyncType sync_type =
78 (load_type == kLoadTypeMediaStream) 77 (load_type == kLoadTypeMediaStream)
79 ? MediaPipelineDeviceParams::kModeIgnorePts 78 ? MediaPipelineDeviceParams::kModeIgnorePts
80 : MediaPipelineDeviceParams::kModeSyncPts; 79 : MediaPipelineDeviceParams::kModeSyncPts;
81 MediaPipelineDeviceParams params(sync_type, backend_task_runner_.get()); 80 MediaPipelineDeviceParams params(sync_type, backend_task_runner_.get());
82 std::unique_ptr<MediaPipelineBackend> backend = 81 std::unique_ptr<MediaPipelineBackend> backend =
83 create_backend_cb_.Run(params, audio_device_id_); 82 create_backend_cb_.Run(params, audio_device_id_);
84 83
85 // Create pipeline. 84 // Create pipeline.
86 MediaPipelineClient pipeline_client; 85 MediaPipelineClient pipeline_client;
87 pipeline_client.error_cb = 86 pipeline_client.error_cb =
88 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr()); 87 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr());
89 pipeline_client.buffering_state_cb = base::Bind( 88 pipeline_client.buffering_state_cb = base::Bind(
90 &CastRenderer::OnBufferingStateChange, weak_factory_.GetWeakPtr()); 89 &CastRenderer::OnBufferingStateChange, weak_factory_.GetWeakPtr());
91 pipeline_.reset(new MediaPipelineImpl()); 90 pipeline_.reset(new MediaPipelineImpl());
92 pipeline_->SetClient(pipeline_client); 91 pipeline_->SetClient(pipeline_client);
93 pipeline_->Initialize(load_type, std::move(backend)); 92 pipeline_->Initialize(load_type, std::move(backend));
94 93
94 // Obtain the first enabled audio and video streams.
xhwang 2017/02/01 18:26:03 Here and everywhere else, add a TODO to enable mul
servolk 2017/02/01 22:29:11 Done.
95 std::vector<::media::DemuxerStream*> streams = media_resource->GetStreams();
96 ::media::DemuxerStream* audio_stream = nullptr;
97 ::media::DemuxerStream* video_stream = nullptr;
98 for (const auto& s : streams) {
xhwang 2017/02/01 18:26:03 tiny nit: This is a local variable in the loop so
servolk 2017/02/01 22:29:11 Done.
99 if (!audio_stream && s->enabled() &&
100 s->type() == ::media::DemuxerStream::AUDIO) {
101 audio_stream = s;
102 }
103 if (!video_stream && s->enabled() &&
104 s->type() == ::media::DemuxerStream::VIDEO) {
105 video_stream = s;
106 }
107 }
108
95 // Initialize audio. 109 // Initialize audio.
96 ::media::DemuxerStream* audio_stream =
97 demuxer_stream_provider->GetStream(::media::DemuxerStream::AUDIO);
98 if (audio_stream) { 110 if (audio_stream) {
99 AvPipelineClient audio_client; 111 AvPipelineClient audio_client;
100 audio_client.wait_for_key_cb = base::Bind( 112 audio_client.wait_for_key_cb = base::Bind(
101 &CastRenderer::OnWaitingForDecryptionKey, weak_factory_.GetWeakPtr()); 113 &CastRenderer::OnWaitingForDecryptionKey, weak_factory_.GetWeakPtr());
102 audio_client.eos_cb = base::Bind(&CastRenderer::OnEnded, 114 audio_client.eos_cb = base::Bind(&CastRenderer::OnEnded,
103 weak_factory_.GetWeakPtr(), STREAM_AUDIO); 115 weak_factory_.GetWeakPtr(), STREAM_AUDIO);
104 audio_client.playback_error_cb = 116 audio_client.playback_error_cb =
105 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr()); 117 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr());
106 audio_client.statistics_cb = base::Bind(&CastRenderer::OnStatisticsUpdate, 118 audio_client.statistics_cb = base::Bind(&CastRenderer::OnStatisticsUpdate,
107 weak_factory_.GetWeakPtr()); 119 weak_factory_.GetWeakPtr());
108 std::unique_ptr<CodedFrameProvider> frame_provider(new DemuxerStreamAdapter( 120 std::unique_ptr<CodedFrameProvider> frame_provider(new DemuxerStreamAdapter(
109 task_runner_, media_task_runner_factory_, audio_stream)); 121 task_runner_, media_task_runner_factory_, audio_stream));
110 122
111 ::media::PipelineStatus status = 123 ::media::PipelineStatus status =
112 pipeline_->InitializeAudio(audio_stream->audio_decoder_config(), 124 pipeline_->InitializeAudio(audio_stream->audio_decoder_config(),
113 audio_client, std::move(frame_provider)); 125 audio_client, std::move(frame_provider));
114 if (status != ::media::PIPELINE_OK) { 126 if (status != ::media::PIPELINE_OK) {
115 init_cb.Run(status); 127 init_cb.Run(status);
116 return; 128 return;
117 } 129 }
118 audio_stream->EnableBitstreamConverter(); 130 audio_stream->EnableBitstreamConverter();
119 } 131 }
120 132
121 // Initialize video. 133 // Initialize video.
122 ::media::DemuxerStream* video_stream =
123 demuxer_stream_provider->GetStream(::media::DemuxerStream::VIDEO);
124 if (video_stream) { 134 if (video_stream) {
125 VideoPipelineClient video_client; 135 VideoPipelineClient video_client;
126 video_client.av_pipeline_client.wait_for_key_cb = base::Bind( 136 video_client.av_pipeline_client.wait_for_key_cb = base::Bind(
127 &CastRenderer::OnWaitingForDecryptionKey, weak_factory_.GetWeakPtr()); 137 &CastRenderer::OnWaitingForDecryptionKey, weak_factory_.GetWeakPtr());
128 video_client.av_pipeline_client.eos_cb = base::Bind( 138 video_client.av_pipeline_client.eos_cb = base::Bind(
129 &CastRenderer::OnEnded, weak_factory_.GetWeakPtr(), STREAM_VIDEO); 139 &CastRenderer::OnEnded, weak_factory_.GetWeakPtr(), STREAM_VIDEO);
130 video_client.av_pipeline_client.playback_error_cb = 140 video_client.av_pipeline_client.playback_error_cb =
131 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr()); 141 base::Bind(&CastRenderer::OnError, weak_factory_.GetWeakPtr());
132 video_client.av_pipeline_client.statistics_cb = base::Bind( 142 video_client.av_pipeline_client.statistics_cb = base::Bind(
133 &CastRenderer::OnStatisticsUpdate, weak_factory_.GetWeakPtr()); 143 &CastRenderer::OnStatisticsUpdate, weak_factory_.GetWeakPtr());
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 268 }
259 269
260 void CastRenderer::OnVideoOpacityChange(bool opaque) { 270 void CastRenderer::OnVideoOpacityChange(bool opaque) {
261 DCHECK(task_runner_->BelongsToCurrentThread()); 271 DCHECK(task_runner_->BelongsToCurrentThread());
262 DCHECK(opaque); 272 DCHECK(opaque);
263 client_->OnVideoOpacityChange(opaque); 273 client_->OnVideoOpacityChange(opaque);
264 } 274 }
265 275
266 } // namespace media 276 } // namespace media
267 } // namespace chromecast 277 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698