OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/pipeline.h" | 5 #include "media/base/pipeline.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 base::AutoLock auto_lock(lock_); | 81 base::AutoLock auto_lock(lock_); |
82 DCHECK(!running_) << "Stop() must complete before destroying object"; | 82 DCHECK(!running_) << "Stop() must complete before destroying object"; |
83 DCHECK(!stop_pending_); | 83 DCHECK(!stop_pending_); |
84 DCHECK(!seek_pending_); | 84 DCHECK(!seek_pending_); |
85 | 85 |
86 media_log_->AddEvent( | 86 media_log_->AddEvent( |
87 media_log_->CreateEvent(MediaLogEvent::PIPELINE_DESTROYED)); | 87 media_log_->CreateEvent(MediaLogEvent::PIPELINE_DESTROYED)); |
88 } | 88 } |
89 | 89 |
90 void Pipeline::Start(scoped_ptr<FilterCollection> collection, | 90 void Pipeline::Start(scoped_ptr<FilterCollection> collection, |
91 const std::string& url, | |
92 const PipelineStatusCB& ended_cb, | 91 const PipelineStatusCB& ended_cb, |
93 const PipelineStatusCB& error_cb, | 92 const PipelineStatusCB& error_cb, |
94 const NetworkEventCB& network_cb, | 93 const NetworkEventCB& network_cb, |
95 const PipelineStatusCB& start_cb) { | 94 const PipelineStatusCB& start_cb) { |
96 base::AutoLock auto_lock(lock_); | 95 base::AutoLock auto_lock(lock_); |
97 CHECK(!running_) << "Media pipeline is already running"; | 96 CHECK(!running_) << "Media pipeline is already running"; |
98 | 97 |
99 running_ = true; | 98 running_ = true; |
100 message_loop_->PostTask(FROM_HERE, base::Bind( | 99 message_loop_->PostTask(FROM_HERE, base::Bind( |
101 &Pipeline::StartTask, this, base::Passed(&collection), | 100 &Pipeline::StartTask, this, base::Passed(&collection), |
102 url, ended_cb, error_cb, network_cb, start_cb)); | 101 ended_cb, error_cb, network_cb, start_cb)); |
103 } | 102 } |
104 | 103 |
105 void Pipeline::Stop(const PipelineStatusCB& stop_cb) { | 104 void Pipeline::Stop(const PipelineStatusCB& stop_cb) { |
106 base::AutoLock auto_lock(lock_); | 105 base::AutoLock auto_lock(lock_); |
107 CHECK(running_) << "Media pipeline isn't running"; | 106 CHECK(running_) << "Media pipeline isn't running"; |
108 | 107 |
109 // Stop the pipeline, which will set |running_| to false on our behalf. | 108 // Stop the pipeline, which will set |running_| to false on our behalf. |
110 message_loop_->PostTask(FROM_HERE, base::Bind( | 109 message_loop_->PostTask(FROM_HERE, base::Bind( |
111 &Pipeline::StopTask, this, stop_cb)); | 110 &Pipeline::StopTask, this, stop_cb)); |
112 } | 111 } |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 void Pipeline::OnUpdateStatistics(const PipelineStatistics& stats) { | 577 void Pipeline::OnUpdateStatistics(const PipelineStatistics& stats) { |
579 base::AutoLock auto_lock(lock_); | 578 base::AutoLock auto_lock(lock_); |
580 statistics_.audio_bytes_decoded += stats.audio_bytes_decoded; | 579 statistics_.audio_bytes_decoded += stats.audio_bytes_decoded; |
581 statistics_.video_bytes_decoded += stats.video_bytes_decoded; | 580 statistics_.video_bytes_decoded += stats.video_bytes_decoded; |
582 statistics_.video_frames_decoded += stats.video_frames_decoded; | 581 statistics_.video_frames_decoded += stats.video_frames_decoded; |
583 statistics_.video_frames_dropped += stats.video_frames_dropped; | 582 statistics_.video_frames_dropped += stats.video_frames_dropped; |
584 media_log_->QueueStatisticsUpdatedEvent(statistics_); | 583 media_log_->QueueStatisticsUpdatedEvent(statistics_); |
585 } | 584 } |
586 | 585 |
587 void Pipeline::StartTask(scoped_ptr<FilterCollection> filter_collection, | 586 void Pipeline::StartTask(scoped_ptr<FilterCollection> filter_collection, |
588 const std::string& url, | |
589 const PipelineStatusCB& ended_cb, | 587 const PipelineStatusCB& ended_cb, |
590 const PipelineStatusCB& error_cb, | 588 const PipelineStatusCB& error_cb, |
591 const NetworkEventCB& network_cb, | 589 const NetworkEventCB& network_cb, |
592 const PipelineStatusCB& start_cb) { | 590 const PipelineStatusCB& start_cb) { |
593 DCHECK_EQ(MessageLoop::current(), message_loop_); | 591 DCHECK_EQ(MessageLoop::current(), message_loop_); |
594 DCHECK_EQ(kCreated, state_); | 592 DCHECK_EQ(kCreated, state_); |
595 filter_collection_ = filter_collection.Pass(); | 593 filter_collection_ = filter_collection.Pass(); |
596 url_ = url; | |
597 ended_cb_ = ended_cb; | 594 ended_cb_ = ended_cb; |
598 error_cb_ = error_cb; | 595 error_cb_ = error_cb; |
599 network_cb_ = network_cb; | 596 network_cb_ = network_cb; |
600 seek_cb_ = start_cb; | 597 seek_cb_ = start_cb; |
601 | 598 |
602 // Kick off initialization. | 599 // Kick off initialization. |
603 pipeline_init_state_.reset(new PipelineInitState()); | 600 pipeline_init_state_.reset(new PipelineInitState()); |
604 pipeline_init_state_->composite = new CompositeFilter(message_loop_); | 601 pipeline_init_state_->composite = new CompositeFilter(message_loop_); |
605 pipeline_init_state_->composite->set_host(this); | 602 pipeline_init_state_->composite->set_host(this); |
606 | 603 |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 bool ret = pipeline_init_state_->composite->AddFilter(filter.get()); | 1089 bool ret = pipeline_init_state_->composite->AddFilter(filter.get()); |
1093 if (!ret) | 1090 if (!ret) |
1094 SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); | 1091 SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); |
1095 return ret; | 1092 return ret; |
1096 } | 1093 } |
1097 | 1094 |
1098 void Pipeline::InitializeDemuxer() { | 1095 void Pipeline::InitializeDemuxer() { |
1099 DCHECK_EQ(MessageLoop::current(), message_loop_); | 1096 DCHECK_EQ(MessageLoop::current(), message_loop_); |
1100 DCHECK(IsPipelineOk()); | 1097 DCHECK(IsPipelineOk()); |
1101 | 1098 |
1102 filter_collection_->GetDemuxerFactory()->Build( | 1099 demuxer_ = filter_collection_->GetDemuxer(); |
1103 url_, base::Bind(&Pipeline::OnDemuxerBuilt, this)); | 1100 if (!demuxer_) { |
1104 } | 1101 SetError(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); |
1105 | |
1106 void Pipeline::OnDemuxerBuilt(PipelineStatus status, Demuxer* demuxer) { | |
1107 if (MessageLoop::current() != message_loop_) { | |
1108 message_loop_->PostTask(FROM_HERE, base::Bind( | |
1109 &Pipeline::OnDemuxerBuilt, this, status, make_scoped_refptr(demuxer))); | |
1110 return; | 1102 return; |
1111 } | 1103 } |
1112 | 1104 |
1113 demuxer_ = demuxer; | 1105 demuxer_->set_host(this); |
| 1106 demuxer_->Initialize(base::Bind(&Pipeline::OnDemuxerInitialized, this)); |
| 1107 } |
| 1108 |
| 1109 void Pipeline::OnDemuxerInitialized(PipelineStatus status) { |
| 1110 if (MessageLoop::current() != message_loop_) { |
| 1111 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 1112 &Pipeline::OnDemuxerInitialized, this, status)); |
| 1113 return; |
| 1114 } |
| 1115 |
1114 if (status != PIPELINE_OK) { | 1116 if (status != PIPELINE_OK) { |
1115 SetError(status); | 1117 SetError(status); |
1116 return; | 1118 return; |
1117 } | 1119 } |
1118 | 1120 |
1119 CHECK(demuxer_) << "Null demuxer encountered despite PIPELINE_OK."; | |
1120 demuxer_->set_host(this); | |
1121 | |
1122 { | 1121 { |
1123 base::AutoLock auto_lock(lock_); | 1122 base::AutoLock auto_lock(lock_); |
1124 // We do not want to start the clock running. We only want to set the base | 1123 // We do not want to start the clock running. We only want to set the base |
1125 // media time so our timestamp calculations will be correct. | 1124 // media time so our timestamp calculations will be correct. |
1126 clock_->SetTime(demuxer_->GetStartTime(), demuxer_->GetStartTime()); | 1125 clock_->SetTime(demuxer_->GetStartTime(), demuxer_->GetStartTime()); |
1127 } | 1126 } |
1128 | 1127 |
1129 OnFilterInitialize(PIPELINE_OK); | 1128 OnFilterInitialize(PIPELINE_OK); |
1130 } | 1129 } |
1131 | 1130 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { | 1384 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { |
1386 lock_.AssertAcquired(); | 1385 lock_.AssertAcquired(); |
1387 if (!waiting_for_clock_update_) | 1386 if (!waiting_for_clock_update_) |
1388 return; | 1387 return; |
1389 | 1388 |
1390 waiting_for_clock_update_ = false; | 1389 waiting_for_clock_update_ = false; |
1391 clock_->Play(); | 1390 clock_->Play(); |
1392 } | 1391 } |
1393 | 1392 |
1394 } // namespace media | 1393 } // namespace media |
OLD | NEW |