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_impl.h" | 5 #include "media/base/pipeline_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 void Suspend(); | 50 void Suspend(); |
51 void Resume(std::unique_ptr<Renderer> renderer, base::TimeDelta time); | 51 void Resume(std::unique_ptr<Renderer> renderer, base::TimeDelta time); |
52 void SetPlaybackRate(double playback_rate); | 52 void SetPlaybackRate(double playback_rate); |
53 void SetVolume(float volume); | 53 void SetVolume(float volume); |
54 base::TimeDelta GetMediaTime() const; | 54 base::TimeDelta GetMediaTime() const; |
55 Ranges<base::TimeDelta> GetBufferedTimeRanges() const; | 55 Ranges<base::TimeDelta> GetBufferedTimeRanges() const; |
56 bool DidLoadingProgress(); | 56 bool DidLoadingProgress(); |
57 PipelineStatistics GetStatistics() const; | 57 PipelineStatistics GetStatistics() const; |
58 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb); | 58 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb); |
59 | 59 |
| 60 // |enabledTrackIds| contains track ids of enabled audio tracks. |
| 61 void OnEnabledAudioTracksChanged( |
| 62 const std::vector<MediaTrack::Id>& enabledTrackIds); |
| 63 |
| 64 // |trackId| either empty, which means no video track is selected, or contain |
| 65 // one element - the selected video track id. |
| 66 void OnSelectedVideoTrackChanged( |
| 67 const std::vector<MediaTrack::Id>& selectedTrackId); |
| 68 |
60 private: | 69 private: |
61 // Contains state shared between main and media thread. | 70 // Contains state shared between main and media thread. |
62 // Main thread can only read. Media thread can both - read and write. | 71 // Main thread can only read. Media thread can both - read and write. |
63 // So it is not necessary to lock when reading from the media thread. | 72 // So it is not necessary to lock when reading from the media thread. |
64 // This struct should only contain state that is not immediately needed by | 73 // This struct should only contain state that is not immediately needed by |
65 // PipelineClient and can be cached on the media thread until queried. | 74 // PipelineClient and can be cached on the media thread until queried. |
66 // Alternatively we could cache it on the main thread by posting the | 75 // Alternatively we could cache it on the main thread by posting the |
67 // notification to the main thread. But some of the state change notifications | 76 // notification to the main thread. But some of the state change notifications |
68 // (OnStatisticsUpdate and OnBufferedTimeRangesChanged) arrive much more | 77 // (OnStatisticsUpdate and OnBufferedTimeRangesChanged) arrive much more |
69 // frequently than needed. Posting all those notifications to the main thread | 78 // frequently than needed. Posting all those notifications to the main thread |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::ENDED)); | 492 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::ENDED)); |
484 | 493 |
485 if (state_ != kPlaying) | 494 if (state_ != kPlaying) |
486 return; | 495 return; |
487 | 496 |
488 DCHECK(!renderer_ended_); | 497 DCHECK(!renderer_ended_); |
489 renderer_ended_ = true; | 498 renderer_ended_ = true; |
490 CheckPlaybackEnded(); | 499 CheckPlaybackEnded(); |
491 } | 500 } |
492 | 501 |
| 502 void PipelineImpl::OnEnabledAudioTracksChanged( |
| 503 const std::vector<MediaTrack::Id>& enabledTrackIds) { |
| 504 DCHECK(thread_checker_.CalledOnValidThread()); |
| 505 media_task_runner_->PostTask( |
| 506 FROM_HERE, |
| 507 base::Bind(&RendererWrapper::OnEnabledAudioTracksChanged, |
| 508 base::Unretained(renderer_wrapper_.get()), enabledTrackIds)); |
| 509 } |
| 510 |
| 511 void PipelineImpl::OnSelectedVideoTrackChanged( |
| 512 const std::vector<MediaTrack::Id>& selectedTrackId) { |
| 513 DCHECK(thread_checker_.CalledOnValidThread()); |
| 514 media_task_runner_->PostTask( |
| 515 FROM_HERE, |
| 516 base::Bind(&RendererWrapper::OnSelectedVideoTrackChanged, |
| 517 base::Unretained(renderer_wrapper_.get()), selectedTrackId)); |
| 518 } |
| 519 |
| 520 void PipelineImpl::RendererWrapper::OnEnabledAudioTracksChanged( |
| 521 const std::vector<MediaTrack::Id>& enabledTrackIds) { |
| 522 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 523 |
| 524 // This might happen at the very beginning of the media playback, when the |
| 525 // first video track gets selected by default before the playback has been |
| 526 // started, so we don't need to react to this. |
| 527 if (!demuxer_ || !shared_state_.renderer) { |
| 528 return; |
| 529 } |
| 530 |
| 531 base::TimeDelta currTime = (state_ == kPlaying) |
| 532 ? shared_state_.renderer->GetMediaTime() |
| 533 : start_timestamp_; |
| 534 demuxer_->OnEnabledAudioTracksChanged(enabledTrackIds, currTime); |
| 535 } |
| 536 |
| 537 void PipelineImpl::RendererWrapper::OnSelectedVideoTrackChanged( |
| 538 const std::vector<MediaTrack::Id>& selectedTrackId) { |
| 539 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 540 |
| 541 // This might happen at the very beginning of the media playback, when the |
| 542 // first video track gets selected by default before the playback has been |
| 543 // started, so we don't need to react to this. |
| 544 if (!demuxer_ || !shared_state_.renderer) { |
| 545 return; |
| 546 } |
| 547 |
| 548 base::TimeDelta currTime = (state_ == kPlaying) |
| 549 ? shared_state_.renderer->GetMediaTime() |
| 550 : start_timestamp_; |
| 551 demuxer_->OnSelectedVideoTrackChanged(selectedTrackId, currTime); |
| 552 } |
| 553 |
493 void PipelineImpl::RendererWrapper::OnStatisticsUpdate( | 554 void PipelineImpl::RendererWrapper::OnStatisticsUpdate( |
494 const PipelineStatistics& stats) { | 555 const PipelineStatistics& stats) { |
495 DVLOG(3) << __FUNCTION__; | 556 DVLOG(3) << __FUNCTION__; |
496 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 557 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
497 | 558 |
498 base::AutoLock auto_lock(shared_state_lock_); | 559 base::AutoLock auto_lock(shared_state_lock_); |
499 shared_state_.statistics.audio_bytes_decoded += stats.audio_bytes_decoded; | 560 shared_state_.statistics.audio_bytes_decoded += stats.audio_bytes_decoded; |
500 shared_state_.statistics.video_bytes_decoded += stats.video_bytes_decoded; | 561 shared_state_.statistics.video_bytes_decoded += stats.video_bytes_decoded; |
501 shared_state_.statistics.video_frames_decoded += stats.video_frames_decoded; | 562 shared_state_.statistics.video_frames_decoded += stats.video_frames_decoded; |
502 shared_state_.statistics.video_frames_dropped += stats.video_frames_dropped; | 563 shared_state_.statistics.video_frames_dropped += stats.video_frames_dropped; |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 void PipelineImpl::OnSuspendDone(base::TimeDelta suspend_time) { | 1291 void PipelineImpl::OnSuspendDone(base::TimeDelta suspend_time) { |
1231 DVLOG(3) << __FUNCTION__ << "(" << suspend_time.InMicroseconds() << ")"; | 1292 DVLOG(3) << __FUNCTION__ << "(" << suspend_time.InMicroseconds() << ")"; |
1232 DCHECK(thread_checker_.CalledOnValidThread()); | 1293 DCHECK(thread_checker_.CalledOnValidThread()); |
1233 DCHECK(IsRunning()); | 1294 DCHECK(IsRunning()); |
1234 | 1295 |
1235 DCHECK(!suspend_cb_.is_null()); | 1296 DCHECK(!suspend_cb_.is_null()); |
1236 base::ResetAndReturn(&suspend_cb_).Run(PIPELINE_OK); | 1297 base::ResetAndReturn(&suspend_cb_).Run(PIPELINE_OK); |
1237 } | 1298 } |
1238 | 1299 |
1239 } // namespace media | 1300 } // namespace media |
OLD | NEW |