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/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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 return new mp4::MP4StreamParser(); | 68 return new mp4::MP4StreamParser(); |
69 } | 69 } |
70 | 70 |
71 static const SupportedTypeInfo kSupportedTypeInfo[] = { | 71 static const SupportedTypeInfo kSupportedTypeInfo[] = { |
72 { "video/webm", &BuildWebMParser, kVideoWebMCodecs }, | 72 { "video/webm", &BuildWebMParser, kVideoWebMCodecs }, |
73 { "audio/webm", &BuildWebMParser, kAudioWebMCodecs }, | 73 { "audio/webm", &BuildWebMParser, kAudioWebMCodecs }, |
74 { "video/mp4", &BuildMP4Parser, kVideoMP4Codecs }, | 74 { "video/mp4", &BuildMP4Parser, kVideoMP4Codecs }, |
75 { "audio/mp4", &BuildMP4Parser, kAudioMP4Codecs }, | 75 { "audio/mp4", &BuildMP4Parser, kAudioMP4Codecs }, |
76 }; | 76 }; |
77 | 77 |
78 | |
79 // The fake total size we use for converting times to bytes | |
80 // for AddBufferedByteRange() calls. | |
81 // TODO(acolwell): Remove this once Pipeline accepts buffered times | |
82 // instead of only buffered bytes. | |
83 enum { kFakeTotalBytes = 1000000 }; | |
scherkus (not reviewing)
2012/06/21 21:57:04
\m/,
| |
84 | |
85 // Checks to see if the specified |type| and |codecs| list are supported. | 78 // Checks to see if the specified |type| and |codecs| list are supported. |
86 // Returns true if |type| and all codecs listed in |codecs| are supported. | 79 // Returns true if |type| and all codecs listed in |codecs| are supported. |
87 // |factory_function| contains a function that can build a StreamParser | 80 // |factory_function| contains a function that can build a StreamParser |
88 // for this type. | 81 // for this type. |
89 // |has_audio| is true if an audio codec was specified. | 82 // |has_audio| is true if an audio codec was specified. |
90 // |has_video| is true if a video codec was specified. | 83 // |has_video| is true if a video codec was specified. |
91 // Returns false otherwise. The values of |factory_function|, |has_audio|, | 84 // Returns false otherwise. The values of |factory_function|, |has_audio|, |
92 // and |has_video| are undefined. | 85 // and |has_video| are undefined. |
93 static bool IsSupported(const std::string& type, | 86 static bool IsSupported(const std::string& type, |
94 std::vector<std::string>& codecs, | 87 std::vector<std::string>& codecs, |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 if (audio_ && !video_) { | 733 if (audio_ && !video_) { |
741 ranges = audio_->GetBufferedTime(); | 734 ranges = audio_->GetBufferedTime(); |
742 } else if (!audio_ && video_) { | 735 } else if (!audio_ && video_) { |
743 ranges = video_->GetBufferedTime(); | 736 ranges = video_->GetBufferedTime(); |
744 } else { | 737 } else { |
745 ranges = ComputeIntersection(); | 738 ranges = ComputeIntersection(); |
746 } | 739 } |
747 } | 740 } |
748 } | 741 } |
749 | 742 |
750 DCHECK(!ranges.size() || duration_ > TimeDelta()); | 743 for (size_t i = 0; i < ranges.size(); ++i) |
751 for (size_t i = 0; i < ranges.size(); ++i) { | 744 host_->AddBufferedTimeRange(ranges.start(i), ranges.end(i)); |
752 // Notify the host of 'network activity' because we got data. | |
753 int64 start = | |
754 kFakeTotalBytes * ranges.start(i).InSecondsF() / duration_.InSecondsF(); | |
755 int64 end = | |
756 kFakeTotalBytes * ranges.end(i).InSecondsF() / duration_.InSecondsF(); | |
757 host_->AddBufferedByteRange(start, end); | |
758 } | |
759 | 745 |
760 if (!cb.is_null()) | 746 if (!cb.is_null()) |
761 cb.Run(PIPELINE_OK); | 747 cb.Run(PIPELINE_OK); |
762 | 748 |
763 return true; | 749 return true; |
764 } | 750 } |
765 | 751 |
766 void ChunkDemuxer::Abort(const std::string& id) { | 752 void ChunkDemuxer::Abort(const std::string& id) { |
767 DVLOG(1) << "Abort(" << id << ")"; | 753 DVLOG(1) << "Abort(" << id << ")"; |
768 DCHECK(!id.empty()); | 754 DCHECK(!id.empty()); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
916 } | 902 } |
917 | 903 |
918 if (duration > duration_) | 904 if (duration > duration_) |
919 duration_ = duration; | 905 duration_ = duration; |
920 | 906 |
921 // Wait until all streams have initialized. | 907 // Wait until all streams have initialized. |
922 if ((!source_id_audio_.empty() && !audio_) || | 908 if ((!source_id_audio_.empty() && !audio_) || |
923 (!source_id_video_.empty() && !video_)) | 909 (!source_id_video_.empty() && !video_)) |
924 return; | 910 return; |
925 | 911 |
926 if (duration_ > TimeDelta() && duration_ != kInfiniteDuration()) | |
927 host_->SetTotalBytes(kFakeTotalBytes); | |
928 host_->SetDuration(duration_); | 912 host_->SetDuration(duration_); |
929 | 913 |
930 ChangeState_Locked(INITIALIZED); | 914 ChangeState_Locked(INITIALIZED); |
931 PipelineStatusCB cb; | 915 PipelineStatusCB cb; |
932 std::swap(cb, init_cb_); | 916 std::swap(cb, init_cb_); |
933 cb.Run(PIPELINE_OK); | 917 cb.Run(PIPELINE_OK); |
934 } | 918 } |
935 | 919 |
936 bool ChunkDemuxer::OnNewConfigs(bool has_audio, bool has_video, | 920 bool ChunkDemuxer::OnNewConfigs(bool has_audio, bool has_video, |
937 const AudioDecoderConfig& audio_config, | 921 const AudioDecoderConfig& audio_config, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1006 // TODO(vrk): There should be a special case for the first appends where all | 990 // TODO(vrk): There should be a special case for the first appends where all |
1007 // streams (for both demuxed and muxed case) begin at the earliest stream | 991 // streams (for both demuxed and muxed case) begin at the earliest stream |
1008 // timestamp. (crbug.com/132815) | 992 // timestamp. (crbug.com/132815) |
1009 if (audio_ && source_id == source_id_audio_) | 993 if (audio_ && source_id == source_id_audio_) |
1010 audio_->OnNewMediaSegment(start_timestamp); | 994 audio_->OnNewMediaSegment(start_timestamp); |
1011 if (video_ && source_id == source_id_video_) | 995 if (video_ && source_id == source_id_video_) |
1012 video_->OnNewMediaSegment(start_timestamp); | 996 video_->OnNewMediaSegment(start_timestamp); |
1013 } | 997 } |
1014 | 998 |
1015 } // namespace media | 999 } // namespace media |
OLD | NEW |