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

Side by Side Diff: media/filters/chunk_demuxer.cc

Issue 10800041: Update media duration if data is appended after the previous duration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
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/filters/chunk_demuxer.h" 5 #include "media/filters/chunk_demuxer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 735
736 if (audio_ && !video_) { 736 if (audio_ && !video_) {
737 ranges = audio_->GetBufferedRanges(); 737 ranges = audio_->GetBufferedRanges();
738 } else if (!audio_ && video_) { 738 } else if (!audio_ && video_) {
739 ranges = video_->GetBufferedRanges(); 739 ranges = video_->GetBufferedRanges();
740 } else { 740 } else {
741 ranges = ComputeIntersection(); 741 ranges = ComputeIntersection();
742 } 742 }
743 } 743 }
744 744
745 if (ranges.size() > 0) {
746 base::TimeDelta last_timestamp_buffered = ranges.end(ranges.size() - 1);
747 if (last_timestamp_buffered > duration_) {
748 duration_ = last_timestamp_buffered;
749 host_->SetDuration(last_timestamp_buffered);
750 }
751 }
752
745 for (size_t i = 0; i < ranges.size(); ++i) 753 for (size_t i = 0; i < ranges.size(); ++i)
746 host_->AddBufferedTimeRange(ranges.start(i), ranges.end(i)); 754 host_->AddBufferedTimeRange(ranges.start(i), ranges.end(i));
747 755
748 if (!cb.is_null()) 756 if (!cb.is_null())
749 cb.Run(PIPELINE_OK); 757 cb.Run(PIPELINE_OK);
750 758
751 return true; 759 return true;
752 } 760 }
753 761
754 void ChunkDemuxer::Abort(const std::string& id) { 762 void ChunkDemuxer::Abort(const std::string& id) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 } 924 }
917 925
918 if (duration > duration_) 926 if (duration > duration_)
919 duration_ = duration; 927 duration_ = duration;
920 928
921 // Wait until all streams have initialized. 929 // Wait until all streams have initialized.
922 if ((!source_id_audio_.empty() && !audio_) || 930 if ((!source_id_audio_.empty() && !audio_) ||
923 (!source_id_video_.empty() && !video_)) 931 (!source_id_video_.empty() && !video_))
924 return; 932 return;
925 933
926 host_->SetDuration(duration_);
927
928 ChangeState_Locked(WAITING_FOR_START_TIME); 934 ChangeState_Locked(WAITING_FOR_START_TIME);
929 } 935 }
930 936
931 bool ChunkDemuxer::OnNewConfigs(bool has_audio, bool has_video, 937 bool ChunkDemuxer::OnNewConfigs(bool has_audio, bool has_video,
932 const AudioDecoderConfig& audio_config, 938 const AudioDecoderConfig& audio_config,
933 const VideoDecoderConfig& video_config) { 939 const VideoDecoderConfig& video_config) {
934 DVLOG(1) << "OnNewConfigs(" << has_audio << ", " << has_video 940 DVLOG(1) << "OnNewConfigs(" << has_audio << ", " << has_video
935 << ", " << audio_config.IsValidConfig() 941 << ", " << audio_config.IsValidConfig()
936 << ", " << video_config.IsValidConfig() << ")"; 942 << ", " << video_config.IsValidConfig() << ")";
937 CHECK(audio_config.IsValidConfig() || video_config.IsValidConfig()); 943 CHECK(audio_config.IsValidConfig() || video_config.IsValidConfig());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 1027
1022 if (audio_) { 1028 if (audio_) {
1023 audio_->SetStartTime(start_time_); 1029 audio_->SetStartTime(start_time_);
1024 audio_->Seek(start_time_); 1030 audio_->Seek(start_time_);
1025 } 1031 }
1026 if (video_) { 1032 if (video_) {
1027 video_->SetStartTime(start_time_); 1033 video_->SetStartTime(start_time_);
1028 video_->Seek(start_time_); 1034 video_->Seek(start_time_);
1029 } 1035 }
1030 1036
1037 duration_ = std::max(duration_, start_time_);
1038 host_->SetDuration(duration_);
1039
1031 // The demuxer is now initialized after the |start_timestamp_| was set. 1040 // The demuxer is now initialized after the |start_timestamp_| was set.
1032 ChangeState_Locked(INITIALIZED); 1041 ChangeState_Locked(INITIALIZED);
1033 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); 1042 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK);
1034 } 1043 }
1035 1044
1036 } // namespace media 1045 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698