| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TODO(scherkus): clean up PipelineImpl... too many crazy function names, | 5 // TODO(scherkus): clean up PipelineImpl... too many crazy function names, |
| 6 // potential deadlocks, etc... | 6 // potential deadlocks, etc... |
| 7 | 7 |
| 8 #include "media/base/pipeline_impl.h" | 8 #include "media/base/pipeline_impl.h" |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 DCHECK(IsRunning()); | 579 DCHECK(IsRunning()); |
| 580 | 580 |
| 581 // Disable renderer on the message loop. | 581 // Disable renderer on the message loop. |
| 582 message_loop_->PostTask(FROM_HERE, | 582 message_loop_->PostTask(FROM_HERE, |
| 583 base::Bind(&PipelineImpl::DisableAudioRendererTask, this)); | 583 base::Bind(&PipelineImpl::DisableAudioRendererTask, this)); |
| 584 media_log_->AddEvent( | 584 media_log_->AddEvent( |
| 585 media_log_->CreateEvent(MediaLogEvent::AUDIO_RENDERER_DISABLED)); | 585 media_log_->CreateEvent(MediaLogEvent::AUDIO_RENDERER_DISABLED)); |
| 586 } | 586 } |
| 587 | 587 |
| 588 // Called from any thread. | 588 // Called from any thread. |
| 589 void PipelineImpl::OnFilterInitialize() { | 589 void PipelineImpl::OnFilterInitialize(PipelineStatus status) { |
| 590 // Continue the initialize task by proceeding to the next stage. | 590 // Continue the initialize task by proceeding to the next stage. |
| 591 message_loop_->PostTask(FROM_HERE, | 591 message_loop_->PostTask( |
| 592 base::Bind(&PipelineImpl::InitializeTask, this)); | 592 FROM_HERE, base::Bind(&PipelineImpl::InitializeTask, this, status)); |
| 593 } | 593 } |
| 594 | 594 |
| 595 // Called from any thread. | 595 // Called from any thread. |
| 596 void PipelineImpl::OnFilterStateTransition() { | 596 void PipelineImpl::OnFilterStateTransition() { |
| 597 message_loop_->PostTask(FROM_HERE, | 597 message_loop_->PostTask(FROM_HERE, |
| 598 base::Bind(&PipelineImpl::FilterStateTransitionTask, this)); | 598 base::Bind(&PipelineImpl::FilterStateTransitionTask, this)); |
| 599 } | 599 } |
| 600 | 600 |
| 601 // Called from any thread. | 601 // Called from any thread. |
| 602 // This method makes the FilterStatusCB behave like a Closure. It | 602 // This method makes the FilterStatusCB behave like a Closure. It |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 // VideoDecoder to the Demuxer's video stream, and then connects the | 654 // VideoDecoder to the Demuxer's video stream, and then connects the |
| 655 // VideoDecoder to a VideoRenderer. | 655 // VideoDecoder to a VideoRenderer. |
| 656 // | 656 // |
| 657 // When all required filters have been created and have called their | 657 // When all required filters have been created and have called their |
| 658 // FilterHost's InitializationComplete() method, the pipeline will update its | 658 // FilterHost's InitializationComplete() method, the pipeline will update its |
| 659 // state to kStarted and |init_callback_|, will be executed. | 659 // state to kStarted and |init_callback_|, will be executed. |
| 660 // | 660 // |
| 661 // TODO(hclam): InitializeTask() is now starting the pipeline asynchronously. It | 661 // TODO(hclam): InitializeTask() is now starting the pipeline asynchronously. It |
| 662 // works like a big state change table. If we no longer need to start filters | 662 // works like a big state change table. If we no longer need to start filters |
| 663 // in order, we need to get rid of all the state change. | 663 // in order, we need to get rid of all the state change. |
| 664 void PipelineImpl::InitializeTask() { | 664 void PipelineImpl::InitializeTask(PipelineStatus last_stage_status) { |
| 665 DCHECK_EQ(MessageLoop::current(), message_loop_); | 665 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 666 | 666 |
| 667 if (last_stage_status != PIPELINE_OK) { |
| 668 // Currently only VideoDecoders have a recoverable error code. |
| 669 if (state_ == kInitVideoDecoder && |
| 670 last_stage_status == DECODER_ERROR_NOT_SUPPORTED) { |
| 671 pipeline_init_state_->composite_->RemoveFilter( |
| 672 pipeline_init_state_->video_decoder_.get()); |
| 673 state_ = kInitAudioRenderer; |
| 674 } else { |
| 675 SetError(last_stage_status); |
| 676 } |
| 677 } |
| 678 |
| 667 // If we have received the stop or error signal, return immediately. | 679 // If we have received the stop or error signal, return immediately. |
| 668 if (IsPipelineStopPending() || IsPipelineStopped() || !IsPipelineOk()) | 680 if (IsPipelineStopPending() || IsPipelineStopped() || !IsPipelineOk()) |
| 669 return; | 681 return; |
| 670 | 682 |
| 671 DCHECK(state_ == kInitDemuxer || | 683 DCHECK(state_ == kInitDemuxer || |
| 672 state_ == kInitAudioDecoder || | 684 state_ == kInitAudioDecoder || |
| 673 state_ == kInitAudioRenderer || | 685 state_ == kInitAudioRenderer || |
| 674 state_ == kInitVideoDecoder || | 686 state_ == kInitVideoDecoder || |
| 675 state_ == kInitVideoRenderer); | 687 state_ == kInitVideoRenderer); |
| 676 | 688 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 stop_cb.Run(status_); | 1116 stop_cb.Run(status_); |
| 1105 } | 1117 } |
| 1106 } | 1118 } |
| 1107 | 1119 |
| 1108 tearing_down_ = false; | 1120 tearing_down_ = false; |
| 1109 error_caused_teardown_ = false; | 1121 error_caused_teardown_ = false; |
| 1110 } | 1122 } |
| 1111 | 1123 |
| 1112 bool PipelineImpl::PrepareFilter(scoped_refptr<Filter> filter) { | 1124 bool PipelineImpl::PrepareFilter(scoped_refptr<Filter> filter) { |
| 1113 bool ret = pipeline_init_state_->composite_->AddFilter(filter.get()); | 1125 bool ret = pipeline_init_state_->composite_->AddFilter(filter.get()); |
| 1114 | 1126 if (!ret) |
| 1115 if (!ret) { | |
| 1116 SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); | 1127 SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 1117 } | |
| 1118 return ret; | 1128 return ret; |
| 1119 } | 1129 } |
| 1120 | 1130 |
| 1121 void PipelineImpl::InitializeDemuxer() { | 1131 void PipelineImpl::InitializeDemuxer() { |
| 1122 DCHECK_EQ(MessageLoop::current(), message_loop_); | 1132 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 1123 DCHECK(IsPipelineOk()); | 1133 DCHECK(IsPipelineOk()); |
| 1124 | 1134 |
| 1125 filter_collection_->GetDemuxerFactory()->Build( | 1135 filter_collection_->GetDemuxerFactory()->Build( |
| 1126 url_, base::Bind(&PipelineImpl::OnDemuxerBuilt, this)); | 1136 url_, base::Bind(&PipelineImpl::OnDemuxerBuilt, this)); |
| 1127 } | 1137 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1148 demuxer_ = demuxer; | 1158 demuxer_ = demuxer; |
| 1149 demuxer_->set_host(this); | 1159 demuxer_->set_host(this); |
| 1150 | 1160 |
| 1151 { | 1161 { |
| 1152 base::AutoLock auto_lock(lock_); | 1162 base::AutoLock auto_lock(lock_); |
| 1153 // We do not want to start the clock running. We only want to set the base | 1163 // We do not want to start the clock running. We only want to set the base |
| 1154 // media time so our timestamp calculations will be correct. | 1164 // media time so our timestamp calculations will be correct. |
| 1155 clock_->SetTime(demuxer_->GetStartTime()); | 1165 clock_->SetTime(demuxer_->GetStartTime()); |
| 1156 } | 1166 } |
| 1157 | 1167 |
| 1158 OnFilterInitialize(); | 1168 OnFilterInitialize(PIPELINE_OK); |
| 1159 } | 1169 } |
| 1160 | 1170 |
| 1161 bool PipelineImpl::InitializeAudioDecoder( | 1171 bool PipelineImpl::InitializeAudioDecoder( |
| 1162 const scoped_refptr<Demuxer>& demuxer) { | 1172 const scoped_refptr<Demuxer>& demuxer) { |
| 1163 DCHECK_EQ(MessageLoop::current(), message_loop_); | 1173 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 1164 DCHECK(IsPipelineOk()); | 1174 DCHECK(IsPipelineOk()); |
| 1165 | 1175 |
| 1166 scoped_refptr<DemuxerStream> stream = | 1176 scoped_refptr<DemuxerStream> stream = |
| 1167 demuxer->GetStream(DemuxerStream::AUDIO); | 1177 demuxer->GetStream(DemuxerStream::AUDIO); |
| 1168 | 1178 |
| 1169 if (!stream) | 1179 if (!stream) |
| 1170 return false; | 1180 return false; |
| 1171 | 1181 |
| 1172 scoped_refptr<AudioDecoder> audio_decoder; | 1182 scoped_refptr<AudioDecoder> audio_decoder; |
| 1173 filter_collection_->SelectAudioDecoder(&audio_decoder); | 1183 filter_collection_->SelectAudioDecoder(&audio_decoder); |
| 1174 | 1184 |
| 1175 if (!audio_decoder) { | 1185 if (!audio_decoder) { |
| 1176 SetError(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); | 1186 SetError(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); |
| 1177 return false; | 1187 return false; |
| 1178 } | 1188 } |
| 1179 | 1189 |
| 1180 if (!PrepareFilter(audio_decoder)) | 1190 if (!PrepareFilter(audio_decoder)) |
| 1181 return false; | 1191 return false; |
| 1182 | 1192 |
| 1183 pipeline_init_state_->audio_decoder_ = audio_decoder; | 1193 pipeline_init_state_->audio_decoder_ = audio_decoder; |
| 1184 audio_decoder->Initialize( | 1194 audio_decoder->Initialize( |
| 1185 stream, | 1195 stream, |
| 1186 base::Bind(&PipelineImpl::OnFilterInitialize, this), | 1196 base::Bind(&PipelineImpl::OnFilterInitialize, this, PIPELINE_OK), |
| 1187 base::Bind(&PipelineImpl::OnUpdateStatistics, this)); | 1197 base::Bind(&PipelineImpl::OnUpdateStatistics, this)); |
| 1188 return true; | 1198 return true; |
| 1189 } | 1199 } |
| 1190 | 1200 |
| 1191 bool PipelineImpl::InitializeVideoDecoder( | 1201 bool PipelineImpl::InitializeVideoDecoder( |
| 1192 const scoped_refptr<Demuxer>& demuxer) { | 1202 const scoped_refptr<Demuxer>& demuxer) { |
| 1193 DCHECK_EQ(MessageLoop::current(), message_loop_); | 1203 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 1194 DCHECK(IsPipelineOk()); | 1204 DCHECK(IsPipelineOk()); |
| 1195 | 1205 |
| 1196 scoped_refptr<DemuxerStream> stream; | 1206 scoped_refptr<DemuxerStream> stream; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 if (!audio_renderer_) { | 1243 if (!audio_renderer_) { |
| 1234 SetError(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); | 1244 SetError(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); |
| 1235 return false; | 1245 return false; |
| 1236 } | 1246 } |
| 1237 | 1247 |
| 1238 if (!PrepareFilter(audio_renderer_)) | 1248 if (!PrepareFilter(audio_renderer_)) |
| 1239 return false; | 1249 return false; |
| 1240 | 1250 |
| 1241 audio_renderer_->Initialize( | 1251 audio_renderer_->Initialize( |
| 1242 decoder, | 1252 decoder, |
| 1243 base::Bind(&PipelineImpl::OnFilterInitialize, this), | 1253 base::Bind(&PipelineImpl::OnFilterInitialize, this, PIPELINE_OK), |
| 1244 base::Bind(&PipelineImpl::OnAudioUnderflow, this)); | 1254 base::Bind(&PipelineImpl::OnAudioUnderflow, this)); |
| 1245 return true; | 1255 return true; |
| 1246 } | 1256 } |
| 1247 | 1257 |
| 1248 bool PipelineImpl::InitializeVideoRenderer( | 1258 bool PipelineImpl::InitializeVideoRenderer( |
| 1249 const scoped_refptr<VideoDecoder>& decoder) { | 1259 const scoped_refptr<VideoDecoder>& decoder) { |
| 1250 DCHECK_EQ(MessageLoop::current(), message_loop_); | 1260 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 1251 DCHECK(IsPipelineOk()); | 1261 DCHECK(IsPipelineOk()); |
| 1252 | 1262 |
| 1253 if (!decoder) | 1263 if (!decoder) |
| 1254 return false; | 1264 return false; |
| 1255 | 1265 |
| 1256 filter_collection_->SelectVideoRenderer(&video_renderer_); | 1266 filter_collection_->SelectVideoRenderer(&video_renderer_); |
| 1257 if (!video_renderer_) { | 1267 if (!video_renderer_) { |
| 1258 SetError(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); | 1268 SetError(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); |
| 1259 return false; | 1269 return false; |
| 1260 } | 1270 } |
| 1261 | 1271 |
| 1262 if (!PrepareFilter(video_renderer_)) | 1272 if (!PrepareFilter(video_renderer_)) |
| 1263 return false; | 1273 return false; |
| 1264 | 1274 |
| 1265 video_renderer_->Initialize( | 1275 video_renderer_->Initialize( |
| 1266 decoder, | 1276 decoder, |
| 1267 base::Bind(&PipelineImpl::OnFilterInitialize, this), | 1277 base::Bind(&PipelineImpl::OnFilterInitialize, this, PIPELINE_OK), |
| 1268 base::Bind(&PipelineImpl::OnUpdateStatistics, this)); | 1278 base::Bind(&PipelineImpl::OnUpdateStatistics, this)); |
| 1269 return true; | 1279 return true; |
| 1270 } | 1280 } |
| 1271 | 1281 |
| 1272 void PipelineImpl::TearDownPipeline() { | 1282 void PipelineImpl::TearDownPipeline() { |
| 1273 DCHECK_EQ(MessageLoop::current(), message_loop_); | 1283 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 1274 DCHECK_NE(kStopped, state_); | 1284 DCHECK_NE(kStopped, state_); |
| 1275 | 1285 |
| 1276 DCHECK(!tearing_down_ || // Teardown on Stop(). | 1286 DCHECK(!tearing_down_ || // Teardown on Stop(). |
| 1277 (tearing_down_ && error_caused_teardown_) || // Teardown on error. | 1287 (tearing_down_ && error_caused_teardown_) || // Teardown on error. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 message_loop_->PostTask(FROM_HERE, | 1424 message_loop_->PostTask(FROM_HERE, |
| 1415 base::Bind(&PipelineImpl::NotifyCanPlayThrough, this)); | 1425 base::Bind(&PipelineImpl::NotifyCanPlayThrough, this)); |
| 1416 } | 1426 } |
| 1417 | 1427 |
| 1418 void PipelineImpl::NotifyCanPlayThrough() { | 1428 void PipelineImpl::NotifyCanPlayThrough() { |
| 1419 DCHECK_EQ(MessageLoop::current(), message_loop_); | 1429 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 1420 NotifyNetworkEventTask(CAN_PLAY_THROUGH); | 1430 NotifyNetworkEventTask(CAN_PLAY_THROUGH); |
| 1421 } | 1431 } |
| 1422 | 1432 |
| 1423 } // namespace media | 1433 } // namespace media |
| OLD | NEW |