Chromium Code Reviews| 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" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/synchronization/condition_variable.h" | 17 #include "base/synchronization/condition_variable.h" |
| 18 #include "media/base/audio_decoder.h" | 18 #include "media/base/audio_decoder.h" |
| 19 #include "media/base/audio_renderer.h" | 19 #include "media/base/audio_renderer.h" |
| 20 #include "media/base/callback_util.h" | |
| 21 #include "media/base/clock.h" | 20 #include "media/base/clock.h" |
| 22 #include "media/base/filter_collection.h" | 21 #include "media/base/filter_collection.h" |
| 23 #include "media/base/media_log.h" | 22 #include "media/base/media_log.h" |
| 24 #include "media/base/video_decoder.h" | 23 #include "media/base/video_decoder.h" |
| 25 #include "media/base/video_renderer.h" | 24 #include "media/base/video_renderer.h" |
| 26 | 25 |
| 27 using base::TimeDelta; | 26 using base::TimeDelta; |
| 28 | 27 |
| 29 namespace media { | 28 namespace media { |
| 30 | 29 |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 // Since the byte->time calculation is approximate, fudge the beginning & | 443 // Since the byte->time calculation is approximate, fudge the beginning & |
| 445 // ending areas to look better. | 444 // ending areas to look better. |
| 446 TimeDelta epsilon = clock_->Duration() / 100; | 445 TimeDelta epsilon = clock_->Duration() / 100; |
| 447 if (time_offset < epsilon) | 446 if (time_offset < epsilon) |
| 448 return TimeDelta(); | 447 return TimeDelta(); |
| 449 if (time_offset + epsilon > clock_->Duration()) | 448 if (time_offset + epsilon > clock_->Duration()) |
| 450 return clock_->Duration(); | 449 return clock_->Duration(); |
| 451 return time_offset; | 450 return time_offset; |
| 452 } | 451 } |
| 453 | 452 |
| 454 void Pipeline::DoPause(const base::Closure& done_cb) { | 453 void Pipeline::DoPause(const PipelineStatusCB& done_cb) { |
| 455 DCHECK(message_loop_->BelongsToCurrentThread()); | 454 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 456 scoped_ptr<std::queue<ClosureFunc> > closures(new std::queue<ClosureFunc>); | 455 DCHECK(!pending_callbacks_.get()); |
| 456 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs( | |
| 457 new std::queue<PipelineStatusCBFunc>()); | |
| 457 | 458 |
| 458 if (audio_renderer_) | 459 if (audio_renderer_) |
|
Ami GONE FROM CHROMIUM
2012/08/03 04:49:57
Not reviewing this carefully yet b/c I have hopes
scherkus (not reviewing)
2012/08/03 18:08:50
Done.
| |
| 459 closures->push(base::Bind(&AudioRenderer::Pause, audio_renderer_)); | 460 status_cbs->push(base::Bind( |
| 461 &RunClosureFunc, base::Bind(&AudioRenderer::Pause, audio_renderer_))); | |
|
scherkus (not reviewing)
2012/08/02 22:17:04
I thought of having CallbackSeries::Run() that acc
| |
| 460 | 462 |
| 461 if (video_renderer_) | 463 if (video_renderer_) |
| 462 closures->push(base::Bind(&VideoRenderer::Pause, video_renderer_)); | 464 status_cbs->push(base::Bind( |
| 465 &RunClosureFunc, base::Bind(&VideoRenderer::Pause, video_renderer_))); | |
| 463 | 466 |
| 464 RunInSeries(closures.Pass(), done_cb); | 467 pending_callbacks_ = CallbackSeries::Run(status_cbs.Pass(), done_cb); |
| 465 } | 468 } |
| 466 | 469 |
| 467 void Pipeline::DoFlush(const base::Closure& done_cb) { | 470 void Pipeline::DoFlush(const PipelineStatusCB& done_cb) { |
| 468 DCHECK(message_loop_->BelongsToCurrentThread()); | 471 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 469 scoped_ptr<std::queue<ClosureFunc> > closures(new std::queue<ClosureFunc>); | 472 DCHECK(!pending_callbacks_.get()); |
| 473 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs( | |
| 474 new std::queue<PipelineStatusCBFunc>()); | |
| 470 | 475 |
| 471 if (audio_renderer_) | 476 if (audio_renderer_) |
| 472 closures->push(base::Bind(&AudioRenderer::Flush, audio_renderer_)); | 477 status_cbs->push(base::Bind( |
| 478 &RunClosureFunc, base::Bind(&AudioRenderer::Flush, audio_renderer_))); | |
| 473 | 479 |
| 474 if (video_renderer_) | 480 if (video_renderer_) |
| 475 closures->push(base::Bind(&VideoRenderer::Flush, video_renderer_)); | 481 status_cbs->push(base::Bind( |
| 482 &RunClosureFunc, base::Bind(&VideoRenderer::Flush, video_renderer_))); | |
| 476 | 483 |
| 477 RunInParallel(closures.Pass(), done_cb); | 484 pending_callbacks_ = CallbackSeries::Run(status_cbs.Pass(), done_cb); |
| 478 } | 485 } |
| 479 | 486 |
| 480 void Pipeline::DoPlay(const base::Closure& done_cb) { | 487 void Pipeline::DoPlay(const PipelineStatusCB& done_cb) { |
| 481 DCHECK(message_loop_->BelongsToCurrentThread()); | 488 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 482 scoped_ptr<std::queue<ClosureFunc> > closures(new std::queue<ClosureFunc>); | 489 DCHECK(!pending_callbacks_.get()); |
| 490 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs( | |
| 491 new std::queue<PipelineStatusCBFunc>()); | |
| 483 | 492 |
| 484 if (audio_renderer_) | 493 if (audio_renderer_) |
| 485 closures->push(base::Bind(&AudioRenderer::Play, audio_renderer_)); | 494 status_cbs->push(base::Bind( |
| 495 &RunClosureFunc, base::Bind(&AudioRenderer::Play, audio_renderer_))); | |
| 486 | 496 |
| 487 if (video_renderer_) | 497 if (video_renderer_) |
| 488 closures->push(base::Bind(&VideoRenderer::Play, video_renderer_)); | 498 status_cbs->push(base::Bind( |
| 499 &RunClosureFunc, base::Bind(&VideoRenderer::Play, video_renderer_))); | |
| 489 | 500 |
| 490 RunInSeries(closures.Pass(), done_cb); | 501 pending_callbacks_ = CallbackSeries::Run(status_cbs.Pass(), done_cb); |
| 491 } | 502 } |
| 492 | 503 |
| 493 void Pipeline::DoStop(const base::Closure& done_cb) { | 504 void Pipeline::DoStop(const PipelineStatusCB& done_cb) { |
| 494 DCHECK(message_loop_->BelongsToCurrentThread()); | 505 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 495 scoped_ptr<std::queue<ClosureFunc> > closures(new std::queue<ClosureFunc>); | 506 DCHECK(!pending_callbacks_.get()); |
| 507 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs( | |
| 508 new std::queue<PipelineStatusCBFunc>()); | |
| 496 | 509 |
| 497 if (demuxer_) | 510 if (demuxer_) |
| 498 closures->push(base::Bind(&Demuxer::Stop, demuxer_)); | 511 status_cbs->push(base::Bind( |
| 512 &RunClosureFunc, base::Bind(&Demuxer::Stop, demuxer_))); | |
| 499 | 513 |
| 500 if (audio_renderer_) | 514 if (audio_renderer_) |
| 501 closures->push(base::Bind(&AudioRenderer::Stop, audio_renderer_)); | 515 status_cbs->push(base::Bind( |
| 516 &RunClosureFunc, base::Bind(&AudioRenderer::Stop, audio_renderer_))); | |
| 502 | 517 |
| 503 if (video_renderer_) | 518 if (video_renderer_) |
| 504 closures->push(base::Bind(&VideoRenderer::Stop, video_renderer_)); | 519 status_cbs->push(base::Bind( |
| 520 &RunClosureFunc, base::Bind(&VideoRenderer::Stop, video_renderer_))); | |
| 505 | 521 |
| 506 RunInSeries(closures.Pass(), done_cb); | 522 pending_callbacks_ = CallbackSeries::Run(status_cbs.Pass(), done_cb); |
| 507 } | 523 } |
| 508 | 524 |
| 509 void Pipeline::AddBufferedByteRange(int64 start, int64 end) { | 525 void Pipeline::AddBufferedByteRange(int64 start, int64 end) { |
| 510 DCHECK(IsRunning()); | 526 DCHECK(IsRunning()); |
| 511 base::AutoLock auto_lock(lock_); | 527 base::AutoLock auto_lock(lock_); |
| 512 buffered_byte_ranges_.Add(start, end); | 528 buffered_byte_ranges_.Add(start, end); |
| 513 did_loading_progress_ = true; | 529 did_loading_progress_ = true; |
| 514 } | 530 } |
| 515 | 531 |
| 516 void Pipeline::AddBufferedTimeRange(base::TimeDelta start, | 532 void Pipeline::AddBufferedTimeRange(base::TimeDelta start, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 538 } | 554 } |
| 539 | 555 |
| 540 // Called from any thread. | 556 // Called from any thread. |
| 541 void Pipeline::OnFilterInitialize(PipelineStatus status) { | 557 void Pipeline::OnFilterInitialize(PipelineStatus status) { |
| 542 // Continue the initialize task by proceeding to the next stage. | 558 // Continue the initialize task by proceeding to the next stage. |
| 543 message_loop_->PostTask(FROM_HERE, base::Bind( | 559 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 544 &Pipeline::InitializeTask, this, status)); | 560 &Pipeline::InitializeTask, this, status)); |
| 545 } | 561 } |
| 546 | 562 |
| 547 // Called from any thread. | 563 // Called from any thread. |
| 548 void Pipeline::OnFilterStateTransition() { | |
| 549 message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 550 &Pipeline::FilterStateTransitionTask, this)); | |
| 551 } | |
| 552 | |
| 553 // Called from any thread. | |
| 554 // This method makes the PipelineStatusCB behave like a Closure. It | 564 // This method makes the PipelineStatusCB behave like a Closure. It |
| 555 // makes it look like a host()->SetError() call followed by a call to | 565 // makes it look like a host()->SetError() call followed by a call to |
| 556 // OnFilterStateTransition() when errors occur. | 566 // OnFilterStateTransition() when errors occur. |
| 557 // | 567 // |
| 558 // TODO: Revisit this code when SetError() is removed from FilterHost and | 568 // TODO: Revisit this code when SetError() is removed from FilterHost and |
| 559 // all the Closures are converted to PipelineStatusCB. | 569 // all the Closures are converted to PipelineStatusCB. |
| 560 void Pipeline::OnFilterStateTransitionWithStatus(PipelineStatus status) { | 570 void Pipeline::OnFilterStateTransition(PipelineStatus status) { |
| 561 if (status != PIPELINE_OK) | 571 if (status != PIPELINE_OK) |
| 562 SetError(status); | 572 SetError(status); |
| 563 OnFilterStateTransition(); | 573 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 574 &Pipeline::FilterStateTransitionTask, this)); | |
| 564 } | 575 } |
| 565 | 576 |
| 566 void Pipeline::OnTeardownStateTransition() { | 577 void Pipeline::OnTeardownStateTransition(PipelineStatus status) { |
| 578 // Ignore any errors during teardown. | |
| 567 message_loop_->PostTask(FROM_HERE, base::Bind( | 579 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 568 &Pipeline::TeardownStateTransitionTask, this)); | 580 &Pipeline::TeardownStateTransitionTask, this)); |
| 569 } | 581 } |
| 570 | 582 |
| 571 // Called from any thread. | 583 // Called from any thread. |
| 572 void Pipeline::OnUpdateStatistics(const PipelineStatistics& stats) { | 584 void Pipeline::OnUpdateStatistics(const PipelineStatistics& stats) { |
| 573 base::AutoLock auto_lock(lock_); | 585 base::AutoLock auto_lock(lock_); |
| 574 statistics_.audio_bytes_decoded += stats.audio_bytes_decoded; | 586 statistics_.audio_bytes_decoded += stats.audio_bytes_decoded; |
| 575 statistics_.video_bytes_decoded += stats.video_bytes_decoded; | 587 statistics_.video_bytes_decoded += stats.video_bytes_decoded; |
| 576 statistics_.video_frames_decoded += stats.video_frames_decoded; | 588 statistics_.video_frames_decoded += stats.video_frames_decoded; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 // to set the initial playback rate and volume. | 699 // to set the initial playback rate and volume. |
| 688 PlaybackRateChangedTask(GetPlaybackRate()); | 700 PlaybackRateChangedTask(GetPlaybackRate()); |
| 689 VolumeChangedTask(GetVolume()); | 701 VolumeChangedTask(GetVolume()); |
| 690 | 702 |
| 691 // Fire a seek request to get the renderers to preroll. We can skip a seek | 703 // Fire a seek request to get the renderers to preroll. We can skip a seek |
| 692 // here as the demuxer should be at the start of the stream. | 704 // here as the demuxer should be at the start of the stream. |
| 693 seek_pending_ = true; | 705 seek_pending_ = true; |
| 694 SetState(kSeeking); | 706 SetState(kSeeking); |
| 695 seek_timestamp_ = demuxer_->GetStartTime(); | 707 seek_timestamp_ = demuxer_->GetStartTime(); |
| 696 DoSeek(seek_timestamp_, true, | 708 DoSeek(seek_timestamp_, true, |
| 697 base::Bind(&Pipeline::OnFilterStateTransitionWithStatus, this)); | 709 base::Bind(&Pipeline::OnFilterStateTransition, this)); |
| 698 } | 710 } |
| 699 } | 711 } |
| 700 | 712 |
| 701 // This method is called as a result of the client calling Pipeline::Stop() or | 713 // This method is called as a result of the client calling Pipeline::Stop() or |
| 702 // as the result of an error condition. | 714 // as the result of an error condition. |
| 703 // We stop the filters in the reverse order. | 715 // We stop the filters in the reverse order. |
| 704 // | 716 // |
| 705 // TODO(scherkus): beware! this can get posted multiple times since we post | 717 // TODO(scherkus): beware! this can get posted multiple times since we post |
| 706 // Stop() tasks even if we've already stopped. Perhaps this should no-op for | 718 // Stop() tasks even if we've already stopped. Perhaps this should no-op for |
| 707 // additional calls, however most of this logic will be changing. | 719 // additional calls, however most of this logic will be changing. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 demuxer_->OnAudioRendererDisabled(); | 894 demuxer_->OnAudioRendererDisabled(); |
| 883 | 895 |
| 884 // Start clock since there is no more audio to | 896 // Start clock since there is no more audio to |
| 885 // trigger clock updates. | 897 // trigger clock updates. |
| 886 clock_->SetMaxTime(clock_->Duration()); | 898 clock_->SetMaxTime(clock_->Duration()); |
| 887 StartClockIfWaitingForTimeUpdate_Locked(); | 899 StartClockIfWaitingForTimeUpdate_Locked(); |
| 888 } | 900 } |
| 889 | 901 |
| 890 void Pipeline::FilterStateTransitionTask() { | 902 void Pipeline::FilterStateTransitionTask() { |
| 891 DCHECK(message_loop_->BelongsToCurrentThread()); | 903 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 904 DCHECK(pending_callbacks_.get()) | |
| 905 << "Filter state transitions must be completed via pending_callbacks_"; | |
| 906 pending_callbacks_.reset(); | |
| 892 | 907 |
| 893 // No reason transitioning if we've errored or have stopped. | 908 // No reason transitioning if we've errored or have stopped. |
| 894 if (IsPipelineStopped()) { | 909 if (IsPipelineStopped()) { |
| 895 return; | 910 return; |
| 896 } | 911 } |
| 897 | 912 |
| 898 // If we are tearing down, don't allow any state changes. Teardown | 913 // If we are tearing down, don't allow any state changes. Teardown |
| 899 // state changes will come in via TeardownStateTransitionTask(). | 914 // state changes will come in via TeardownStateTransitionTask(). |
| 900 if (IsPipelineTearingDown()) { | 915 if (IsPipelineTearingDown()) { |
| 901 return; | 916 return; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 916 } | 931 } |
| 917 | 932 |
| 918 // Carry out the action for the current state. | 933 // Carry out the action for the current state. |
| 919 if (TransientState(state_)) { | 934 if (TransientState(state_)) { |
| 920 if (state_ == kPausing) { | 935 if (state_ == kPausing) { |
| 921 DoPause(base::Bind(&Pipeline::OnFilterStateTransition, this)); | 936 DoPause(base::Bind(&Pipeline::OnFilterStateTransition, this)); |
| 922 } else if (state_ == kFlushing) { | 937 } else if (state_ == kFlushing) { |
| 923 DoFlush(base::Bind(&Pipeline::OnFilterStateTransition, this)); | 938 DoFlush(base::Bind(&Pipeline::OnFilterStateTransition, this)); |
| 924 } else if (state_ == kSeeking) { | 939 } else if (state_ == kSeeking) { |
| 925 DoSeek(seek_timestamp_, false, | 940 DoSeek(seek_timestamp_, false, |
| 926 base::Bind(&Pipeline::OnFilterStateTransitionWithStatus, this)); | 941 base::Bind(&Pipeline::OnFilterStateTransition, this)); |
| 927 } else if (state_ == kStarting) { | 942 } else if (state_ == kStarting) { |
| 928 DoPlay(base::Bind(&Pipeline::OnFilterStateTransition, this)); | 943 DoPlay(base::Bind(&Pipeline::OnFilterStateTransition, this)); |
| 929 } else if (state_ == kStopping) { | 944 } else if (state_ == kStopping) { |
| 930 DoStop(base::Bind(&Pipeline::OnFilterStateTransition, this)); | 945 DoStop(base::Bind(&Pipeline::OnFilterStateTransition, this)); |
| 931 } else { | 946 } else { |
| 932 NOTREACHED() << "Unexpected state: " << state_; | 947 NOTREACHED() << "Unexpected state: " << state_; |
| 933 } | 948 } |
| 934 } else if (state_ == kStarted) { | 949 } else if (state_ == kStarted) { |
| 935 FinishInitialization(); | 950 FinishInitialization(); |
| 936 | 951 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 957 // We had a pending stop request need to be honored right now. | 972 // We had a pending stop request need to be honored right now. |
| 958 TearDownPipeline(); | 973 TearDownPipeline(); |
| 959 } | 974 } |
| 960 } else { | 975 } else { |
| 961 NOTREACHED() << "Unexpected state: " << state_; | 976 NOTREACHED() << "Unexpected state: " << state_; |
| 962 } | 977 } |
| 963 } | 978 } |
| 964 | 979 |
| 965 void Pipeline::TeardownStateTransitionTask() { | 980 void Pipeline::TeardownStateTransitionTask() { |
| 966 DCHECK(IsPipelineTearingDown()); | 981 DCHECK(IsPipelineTearingDown()); |
| 982 DCHECK(pending_callbacks_.get()) | |
| 983 << "Teardown state transitions must be completed via pending_callbacks_"; | |
| 984 pending_callbacks_.reset(); | |
| 985 | |
| 967 switch (state_) { | 986 switch (state_) { |
| 968 case kStopping: | 987 case kStopping: |
| 969 SetState(error_caused_teardown_ ? kError : kStopped); | 988 SetState(error_caused_teardown_ ? kError : kStopped); |
| 970 FinishDestroyingFiltersTask(); | 989 FinishDestroyingFiltersTask(); |
| 971 break; | 990 break; |
| 972 case kPausing: | 991 case kPausing: |
| 973 SetState(kFlushing); | 992 SetState(kFlushing); |
| 974 DoFlush(base::Bind(&Pipeline::OnTeardownStateTransition, this)); | 993 DoFlush(base::Bind(&Pipeline::OnTeardownStateTransition, this)); |
| 975 break; | 994 break; |
| 976 case kFlushing: | 995 case kFlushing: |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1164 DCHECK(message_loop_->BelongsToCurrentThread()); | 1183 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 1165 DCHECK_NE(kStopped, state_); | 1184 DCHECK_NE(kStopped, state_); |
| 1166 | 1185 |
| 1167 DCHECK(!tearing_down_ || // Teardown on Stop(). | 1186 DCHECK(!tearing_down_ || // Teardown on Stop(). |
| 1168 (tearing_down_ && error_caused_teardown_) || // Teardown on error. | 1187 (tearing_down_ && error_caused_teardown_) || // Teardown on error. |
| 1169 (tearing_down_ && stop_pending_)); // Stop during teardown by error. | 1188 (tearing_down_ && stop_pending_)); // Stop during teardown by error. |
| 1170 | 1189 |
| 1171 // Mark that we already start tearing down operation. | 1190 // Mark that we already start tearing down operation. |
| 1172 tearing_down_ = true; | 1191 tearing_down_ = true; |
| 1173 | 1192 |
| 1193 // Cancel any pending operation so we can proceed with teardown. | |
| 1194 pending_callbacks_.reset(); | |
|
scherkus (not reviewing)
2012/08/02 22:17:04
AFAIK this is the fix -- previously we may have ha
| |
| 1195 | |
| 1174 switch (state_) { | 1196 switch (state_) { |
| 1175 case kCreated: | 1197 case kCreated: |
| 1176 case kError: | 1198 case kError: |
| 1177 SetState(kStopped); | 1199 SetState(kStopped); |
| 1178 // Need to put this in the message loop to make sure that it comes | 1200 // Need to put this in the message loop to make sure that it comes |
| 1179 // after any pending callback tasks that are already queued. | 1201 // after any pending callback tasks that are already queued. |
| 1180 message_loop_->PostTask(FROM_HERE, base::Bind( | 1202 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 1181 &Pipeline::FinishDestroyingFiltersTask, this)); | 1203 &Pipeline::FinishDestroyingFiltersTask, this)); |
| 1182 break; | 1204 break; |
| 1183 | 1205 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1222 break; | 1244 break; |
| 1223 // default: intentionally left out to force new states to cause compiler | 1245 // default: intentionally left out to force new states to cause compiler |
| 1224 // errors. | 1246 // errors. |
| 1225 }; | 1247 }; |
| 1226 } | 1248 } |
| 1227 | 1249 |
| 1228 void Pipeline::DoSeek(base::TimeDelta seek_timestamp, | 1250 void Pipeline::DoSeek(base::TimeDelta seek_timestamp, |
| 1229 bool skip_demuxer_seek, | 1251 bool skip_demuxer_seek, |
| 1230 const PipelineStatusCB& done_cb) { | 1252 const PipelineStatusCB& done_cb) { |
| 1231 DCHECK(message_loop_->BelongsToCurrentThread()); | 1253 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 1254 DCHECK(!pending_callbacks_.get()); | |
| 1232 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs( | 1255 scoped_ptr<std::queue<PipelineStatusCBFunc> > status_cbs( |
| 1233 new std::queue<PipelineStatusCBFunc>()); | 1256 new std::queue<PipelineStatusCBFunc>()); |
| 1234 | 1257 |
| 1235 if (!skip_demuxer_seek) | 1258 if (!skip_demuxer_seek) |
| 1236 status_cbs->push(base::Bind(&Demuxer::Seek, demuxer_, seek_timestamp)); | 1259 status_cbs->push(base::Bind( |
| 1260 &Demuxer::Seek, demuxer_, seek_timestamp)); | |
| 1237 | 1261 |
| 1238 if (audio_renderer_) | 1262 if (audio_renderer_) |
| 1239 status_cbs->push(base::Bind( | 1263 status_cbs->push(base::Bind( |
| 1240 &AudioRenderer::Preroll, audio_renderer_, seek_timestamp)); | 1264 &AudioRenderer::Preroll, audio_renderer_, seek_timestamp)); |
| 1241 | 1265 |
| 1242 if (video_renderer_) | 1266 if (video_renderer_) |
| 1243 status_cbs->push(base::Bind( | 1267 status_cbs->push(base::Bind( |
| 1244 &VideoRenderer::Preroll, video_renderer_, seek_timestamp)); | 1268 &VideoRenderer::Preroll, video_renderer_, seek_timestamp)); |
| 1245 | 1269 |
| 1246 RunInSeriesWithStatus(status_cbs.Pass(), base::Bind( | 1270 pending_callbacks_ = CallbackSeries::Run(status_cbs.Pass(), done_cb); |
| 1247 &Pipeline::ReportStatus, this, done_cb)); | |
| 1248 } | 1271 } |
| 1249 | 1272 |
| 1250 void Pipeline::OnAudioUnderflow() { | 1273 void Pipeline::OnAudioUnderflow() { |
| 1251 if (!message_loop_->BelongsToCurrentThread()) { | 1274 if (!message_loop_->BelongsToCurrentThread()) { |
| 1252 message_loop_->PostTask(FROM_HERE, base::Bind( | 1275 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 1253 &Pipeline::OnAudioUnderflow, this)); | 1276 &Pipeline::OnAudioUnderflow, this)); |
| 1254 return; | 1277 return; |
| 1255 } | 1278 } |
| 1256 | 1279 |
| 1257 if (state_ != kStarted) | 1280 if (state_ != kStarted) |
| 1258 return; | 1281 return; |
| 1259 | 1282 |
| 1260 if (audio_renderer_) | 1283 if (audio_renderer_) |
| 1261 audio_renderer_->ResumeAfterUnderflow(true); | 1284 audio_renderer_->ResumeAfterUnderflow(true); |
| 1262 } | 1285 } |
| 1263 | 1286 |
| 1264 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { | 1287 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { |
| 1265 lock_.AssertAcquired(); | 1288 lock_.AssertAcquired(); |
| 1266 if (!waiting_for_clock_update_) | 1289 if (!waiting_for_clock_update_) |
| 1267 return; | 1290 return; |
| 1268 | 1291 |
| 1269 waiting_for_clock_update_ = false; | 1292 waiting_for_clock_update_ = false; |
| 1270 clock_->Play(); | 1293 clock_->Play(); |
| 1271 } | 1294 } |
| 1272 | 1295 |
| 1273 } // namespace media | 1296 } // namespace media |
| OLD | NEW |