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

Side by Side Diff: media/filters/source_buffer_stream.h

Issue 1008463002: Fix MSE GC, make it less aggressive, more spec-compliant (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added overflow check to sanity checks and use CHECK instead of DCHECK Created 5 years, 4 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
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 // SourceBufferStream is a data structure that stores media Buffers in ranges. 5 // SourceBufferStream is a data structure that stores media Buffers in ranges.
6 // Buffers can be appended out of presentation order. Buffers are retrieved by 6 // Buffers can be appended out of presentation order. Buffers are retrieved by
7 // seeking to the desired start point and calling GetNextBuffer(). Buffers are 7 // seeking to the desired start point and calling GetNextBuffer(). Buffers are
8 // returned in sequential presentation order. 8 // returned in sequential presentation order.
9 9
10 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ 10 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Removes buffers between |start| and |end| according to the steps 83 // Removes buffers between |start| and |end| according to the steps
84 // in the "Coded Frame Removal Algorithm" in the Media Source 84 // in the "Coded Frame Removal Algorithm" in the Media Source
85 // Extensions Spec. 85 // Extensions Spec.
86 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc e.html#sourcebuffer-coded-frame-removal 86 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc e.html#sourcebuffer-coded-frame-removal
87 // 87 //
88 // |duration| is the current duration of the presentation. It is 88 // |duration| is the current duration of the presentation. It is
89 // required by the computation outlined in the spec. 89 // required by the computation outlined in the spec.
90 void Remove(base::TimeDelta start, base::TimeDelta end, 90 void Remove(base::TimeDelta start, base::TimeDelta end,
91 base::TimeDelta duration); 91 base::TimeDelta duration);
92 92
93 // Frees up space if the SourceBufferStream is taking up too much memory.
94 // |media_time| is current playback position.
95 bool GarbageCollectIfNeeded(DecodeTimestamp media_time,
96 size_t newDataSize);
97
93 // Changes the SourceBufferStream's state so that it will start returning 98 // Changes the SourceBufferStream's state so that it will start returning
94 // buffers starting from the closest keyframe before |timestamp|. 99 // buffers starting from the closest keyframe before |timestamp|.
95 void Seek(base::TimeDelta timestamp); 100 void Seek(base::TimeDelta timestamp);
96 101
97 // Returns true if the SourceBufferStream has seeked to a time without 102 // Returns true if the SourceBufferStream has seeked to a time without
98 // buffered data and is waiting for more data to be appended. 103 // buffered data and is waiting for more data to be appended.
99 bool IsSeekPending() const; 104 bool IsSeekPending() const;
100 105
101 // Notifies the SourceBufferStream that the media duration has been changed to 106 // Notifies the SourceBufferStream that the media duration has been changed to
102 // |duration| so it should drop any data past that point. 107 // |duration| so it should drop any data past that point.
(...skipping 10 matching lines...) Expand all
113 Status GetNextBuffer(scoped_refptr<StreamParserBuffer>* out_buffer); 118 Status GetNextBuffer(scoped_refptr<StreamParserBuffer>* out_buffer);
114 119
115 // Returns a list of the buffered time ranges. 120 // Returns a list of the buffered time ranges.
116 Ranges<base::TimeDelta> GetBufferedTime() const; 121 Ranges<base::TimeDelta> GetBufferedTime() const;
117 122
118 // Returns the duration of the buffered ranges, which is equivalent 123 // Returns the duration of the buffered ranges, which is equivalent
119 // to the end timestamp of the last buffered range. If no data is buffered 124 // to the end timestamp of the last buffered range. If no data is buffered
120 // then base::TimeDelta() is returned. 125 // then base::TimeDelta() is returned.
121 base::TimeDelta GetBufferedDuration() const; 126 base::TimeDelta GetBufferedDuration() const;
122 127
128 // Returns the size of the buffered data in bytes.
129 size_t GetBufferedSize() const;
130
123 // Notifies this object that end of stream has been signalled. 131 // Notifies this object that end of stream has been signalled.
124 void MarkEndOfStream(); 132 void MarkEndOfStream();
125 133
126 // Clear the end of stream state set by MarkEndOfStream(). 134 // Clear the end of stream state set by MarkEndOfStream().
127 void UnmarkEndOfStream(); 135 void UnmarkEndOfStream();
128 136
129 const AudioDecoderConfig& GetCurrentAudioDecoderConfig(); 137 const AudioDecoderConfig& GetCurrentAudioDecoderConfig();
130 const VideoDecoderConfig& GetCurrentVideoDecoderConfig(); 138 const VideoDecoderConfig& GetCurrentVideoDecoderConfig();
131 const TextTrackConfig& GetCurrentTextTrackConfig(); 139 const TextTrackConfig& GetCurrentTextTrackConfig();
132 140
(...skipping 10 matching lines...) Expand all
143 // yet. 151 // yet.
144 base::TimeDelta GetMaxInterbufferDistance() const; 152 base::TimeDelta GetMaxInterbufferDistance() const;
145 153
146 void set_memory_limit(size_t memory_limit) { 154 void set_memory_limit(size_t memory_limit) {
147 memory_limit_ = memory_limit; 155 memory_limit_ = memory_limit;
148 } 156 }
149 157
150 private: 158 private:
151 friend class SourceBufferStreamTest; 159 friend class SourceBufferStreamTest;
152 160
153 // Frees up space if the SourceBufferStream is taking up too much memory.
154 void GarbageCollectIfNeeded();
155
156 // Attempts to delete approximately |total_bytes_to_free| amount of data 161 // Attempts to delete approximately |total_bytes_to_free| amount of data
157 // |ranges_|, starting at the front of |ranges_| and moving linearly forward 162 // |ranges_|, starting at the front of |ranges_| and moving linearly forward
158 // through the buffers. Deletes starting from the back if |reverse_direction| 163 // through the buffers. Deletes starting from the back if |reverse_direction|
159 // is true. Returns the number of bytes freed. 164 // is true. |media_time| is current playback position.
160 size_t FreeBuffers(size_t total_bytes_to_free, bool reverse_direction); 165 // Returns the number of bytes freed.
166 size_t FreeBuffers(size_t total_bytes_to_free,
167 DecodeTimestamp media_time,
168 bool reverse_direction);
161 169
162 // Attempts to delete approximately |total_bytes_to_free| amount of data from 170 // Attempts to delete approximately |total_bytes_to_free| amount of data from
163 // |ranges_|, starting after the last appended buffer before the current 171 // |ranges_|, starting after the last appended buffer before the current
164 // playback position. 172 // playback position |media_time|.
165 size_t FreeBuffersAfterLastAppended(size_t total_bytes_to_free); 173 size_t FreeBuffersAfterLastAppended(size_t total_bytes_to_free,
174 DecodeTimestamp media_time);
166 175
167 // Gets the removal range to secure |byte_to_free| from 176 // Gets the removal range to secure |byte_to_free| from
168 // [|start_timestamp|, |end_timestamp|). 177 // [|start_timestamp|, |end_timestamp|).
169 // Returns the size of buffers to secure if future 178 // Returns the size of buffers to secure if future
170 // Remove(|start_timestamp|, |removal_end_timestamp|, duration) is called. 179 // Remove(|start_timestamp|, |removal_end_timestamp|, duration) is called.
171 // Will not update |removal_end_timestamp| if the returned size is 0. 180 // Will not update |removal_end_timestamp| if the returned size is 0.
172 size_t GetRemovalRange(DecodeTimestamp start_timestamp, 181 size_t GetRemovalRange(DecodeTimestamp start_timestamp,
173 DecodeTimestamp end_timestamp, size_t byte_to_free, 182 DecodeTimestamp end_timestamp, size_t byte_to_free,
174 DecodeTimestamp* removal_end_timestamp); 183 DecodeTimestamp* removal_end_timestamp);
175 184
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 int num_splice_generation_warning_logs_ = 0; 445 int num_splice_generation_warning_logs_ = 0;
437 int num_splice_generation_success_logs_ = 0; 446 int num_splice_generation_success_logs_ = 0;
438 int num_track_buffer_gap_warning_logs_ = 0; 447 int num_track_buffer_gap_warning_logs_ = 0;
439 448
440 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); 449 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream);
441 }; 450 };
442 451
443 } // namespace media 452 } // namespace media
444 453
445 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ 454 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698