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

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

Issue 10581050: Ensure media's buffered ranges always have a range that includes currentTime. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 static const SupportedTypeInfo kSupportedTypeInfo[] = { 75 static const SupportedTypeInfo kSupportedTypeInfo[] = {
76 { "video/webm", &BuildWebMParser, kVideoWebMCodecs }, 76 { "video/webm", &BuildWebMParser, kVideoWebMCodecs },
77 { "audio/webm", &BuildWebMParser, kAudioWebMCodecs }, 77 { "audio/webm", &BuildWebMParser, kAudioWebMCodecs },
78 #if defined(USE_PROPRIETARY_CODECS) 78 #if defined(USE_PROPRIETARY_CODECS)
79 { "video/mp4", &BuildMP4Parser, kVideoMP4Codecs }, 79 { "video/mp4", &BuildMP4Parser, kVideoMP4Codecs },
80 { "audio/mp4", &BuildMP4Parser, kAudioMP4Codecs }, 80 { "audio/mp4", &BuildMP4Parser, kAudioMP4Codecs },
81 #endif 81 #endif
82 }; 82 };
83 83
84
85 // The fake total size we use for converting times to bytes
86 // for AddBufferedByteRange() calls.
87 // TODO(acolwell): Remove this once Pipeline accepts buffered times
88 // instead of only buffered bytes.
89 enum { kFakeTotalBytes = 1000000 };
90
91 // Checks to see if the specified |type| and |codecs| list are supported. 84 // Checks to see if the specified |type| and |codecs| list are supported.
92 // Returns true if |type| and all codecs listed in |codecs| are supported. 85 // Returns true if |type| and all codecs listed in |codecs| are supported.
93 // |factory_function| contains a function that can build a StreamParser 86 // |factory_function| contains a function that can build a StreamParser
94 // for this type. 87 // for this type.
95 // |has_audio| is true if an audio codec was specified. 88 // |has_audio| is true if an audio codec was specified.
96 // |has_video| is true if a video codec was specified. 89 // |has_video| is true if a video codec was specified.
97 // Returns false otherwise. The values of |factory_function|, |has_audio|, 90 // Returns false otherwise. The values of |factory_function|, |has_audio|,
98 // and |has_video| are undefined. 91 // and |has_video| are undefined.
99 static bool IsSupported(const std::string& type, 92 static bool IsSupported(const std::string& type,
100 std::vector<std::string>& codecs, 93 std::vector<std::string>& codecs,
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 if (audio_ && !video_) { 739 if (audio_ && !video_) {
747 ranges = audio_->GetBufferedTime(); 740 ranges = audio_->GetBufferedTime();
748 } else if (!audio_ && video_) { 741 } else if (!audio_ && video_) {
749 ranges = video_->GetBufferedTime(); 742 ranges = video_->GetBufferedTime();
750 } else { 743 } else {
751 ranges = ComputeIntersection(); 744 ranges = ComputeIntersection();
752 } 745 }
753 } 746 }
754 } 747 }
755 748
756 DCHECK(!ranges.size() || duration_ > TimeDelta()); 749 for (size_t i = 0; i < ranges.size(); ++i)
757 for (size_t i = 0; i < ranges.size(); ++i) { 750 host_->AddBufferedTimeRange(ranges.start(i), ranges.end(i));
758 // Notify the host of 'network activity' because we got data.
759 int64 start =
760 kFakeTotalBytes * ranges.start(i).InSecondsF() / duration_.InSecondsF();
761 int64 end =
762 kFakeTotalBytes * ranges.end(i).InSecondsF() / duration_.InSecondsF();
763 host_->AddBufferedByteRange(start, end);
764 }
765 751
766 if (!cb.is_null()) 752 if (!cb.is_null())
767 cb.Run(PIPELINE_OK); 753 cb.Run(PIPELINE_OK);
768 754
769 return true; 755 return true;
770 } 756 }
771 757
772 void ChunkDemuxer::Abort(const std::string& id) { 758 void ChunkDemuxer::Abort(const std::string& id) {
773 DVLOG(1) << "Abort(" << id << ")"; 759 DVLOG(1) << "Abort(" << id << ")";
774 DCHECK(!id.empty()); 760 DCHECK(!id.empty());
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 } 908 }
923 909
924 if (duration > duration_) 910 if (duration > duration_)
925 duration_ = duration; 911 duration_ = duration;
926 912
927 // Wait until all streams have initialized. 913 // Wait until all streams have initialized.
928 if ((!source_id_audio_.empty() && !audio_) || 914 if ((!source_id_audio_.empty() && !audio_) ||
929 (!source_id_video_.empty() && !video_)) 915 (!source_id_video_.empty() && !video_))
930 return; 916 return;
931 917
932 if (duration_ > TimeDelta() && duration_ != kInfiniteDuration())
933 host_->SetTotalBytes(kFakeTotalBytes);
934 host_->SetDuration(duration_); 918 host_->SetDuration(duration_);
935 919
936 ChangeState_Locked(INITIALIZED); 920 ChangeState_Locked(INITIALIZED);
937 PipelineStatusCB cb; 921 PipelineStatusCB cb;
938 std::swap(cb, init_cb_); 922 std::swap(cb, init_cb_);
939 cb.Run(PIPELINE_OK); 923 cb.Run(PIPELINE_OK);
940 } 924 }
941 925
942 bool ChunkDemuxer::OnNewConfigs(bool has_audio, bool has_video, 926 bool ChunkDemuxer::OnNewConfigs(bool has_audio, bool has_video,
943 const AudioDecoderConfig& audio_config, 927 const AudioDecoderConfig& audio_config,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 // TODO(vrk): There should be a special case for the first appends where all 996 // TODO(vrk): There should be a special case for the first appends where all
1013 // streams (for both demuxed and muxed case) begin at the earliest stream 997 // streams (for both demuxed and muxed case) begin at the earliest stream
1014 // timestamp. (crbug.com/132815) 998 // timestamp. (crbug.com/132815)
1015 if (audio_ && source_id == source_id_audio_) 999 if (audio_ && source_id == source_id_audio_)
1016 audio_->OnNewMediaSegment(start_timestamp); 1000 audio_->OnNewMediaSegment(start_timestamp);
1017 if (video_ && source_id == source_id_video_) 1001 if (video_ && source_id == source_id_video_)
1018 video_->OnNewMediaSegment(start_timestamp); 1002 video_->OnNewMediaSegment(start_timestamp);
1019 } 1003 }
1020 1004
1021 } // namespace media 1005 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698