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

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

Issue 1692403002: MSE - Fix crash caused by incorrect GC of GOP with next buffer position (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Increased hardening + more code comments per chat w/chcunningham@ Created 4 years, 10 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
« no previous file with comments | « media/filters/source_buffer_range.h ('k') | media/filters/source_buffer_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/source_buffer_range.h" 5 #include "media/filters/source_buffer_range.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "media/base/timestamp_constants.h" 9 #include "media/base/timestamp_constants.h"
10 10
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 bool SourceBufferRange::TruncateAt( 224 bool SourceBufferRange::TruncateAt(
225 DecodeTimestamp timestamp, BufferQueue* removed_buffers, 225 DecodeTimestamp timestamp, BufferQueue* removed_buffers,
226 bool is_exclusive) { 226 bool is_exclusive) {
227 // Find the place in |buffers_| where we will begin deleting data. 227 // Find the place in |buffers_| where we will begin deleting data.
228 BufferQueue::iterator starting_point = 228 BufferQueue::iterator starting_point =
229 GetBufferItrAt(timestamp, is_exclusive); 229 GetBufferItrAt(timestamp, is_exclusive);
230 return TruncateAt(starting_point, removed_buffers); 230 return TruncateAt(starting_point, removed_buffers);
231 } 231 }
232 232
233 size_t SourceBufferRange::DeleteGOPFromFront(BufferQueue* deleted_buffers) { 233 size_t SourceBufferRange::DeleteGOPFromFront(BufferQueue* deleted_buffers) {
234 DCHECK(!buffers_.empty());
234 DCHECK(!FirstGOPContainsNextBufferPosition()); 235 DCHECK(!FirstGOPContainsNextBufferPosition());
235 DCHECK(deleted_buffers); 236 DCHECK(deleted_buffers);
236 237
237 int buffers_deleted = 0; 238 int buffers_deleted = 0;
238 size_t total_bytes_deleted = 0; 239 size_t total_bytes_deleted = 0;
239 240
240 KeyframeMap::iterator front = keyframe_map_.begin(); 241 KeyframeMap::iterator front = keyframe_map_.begin();
241 DCHECK(front != keyframe_map_.end()); 242 DCHECK(front != keyframe_map_.end());
242 243
243 // Delete the keyframe at the start of |keyframe_map_|. 244 // Delete the keyframe at the start of |keyframe_map_|.
(...skipping 28 matching lines...) Expand all
272 273
273 // Invalidate media segment start time if we've deleted the first buffer of 274 // Invalidate media segment start time if we've deleted the first buffer of
274 // the range. 275 // the range.
275 if (buffers_deleted > 0) 276 if (buffers_deleted > 0)
276 media_segment_start_time_ = kNoDecodeTimestamp(); 277 media_segment_start_time_ = kNoDecodeTimestamp();
277 278
278 return total_bytes_deleted; 279 return total_bytes_deleted;
279 } 280 }
280 281
281 size_t SourceBufferRange::DeleteGOPFromBack(BufferQueue* deleted_buffers) { 282 size_t SourceBufferRange::DeleteGOPFromBack(BufferQueue* deleted_buffers) {
283 DCHECK(!buffers_.empty());
282 DCHECK(!LastGOPContainsNextBufferPosition()); 284 DCHECK(!LastGOPContainsNextBufferPosition());
283 DCHECK(deleted_buffers); 285 DCHECK(deleted_buffers);
284 286
285 // Remove the last GOP's keyframe from the |keyframe_map_|. 287 // Remove the last GOP's keyframe from the |keyframe_map_|.
286 KeyframeMap::iterator back = keyframe_map_.end(); 288 KeyframeMap::iterator back = keyframe_map_.end();
287 DCHECK_GT(keyframe_map_.size(), 0u); 289 DCHECK_GT(keyframe_map_.size(), 0u);
288 --back; 290 --back;
289 291
290 // The index of the first buffer in the last GOP is equal to the new size of 292 // The index of the first buffer in the last GOP is equal to the new size of
291 // |buffers_| after that GOP is deleted. 293 // |buffers_| after that GOP is deleted.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 if (bytes_removed > 0) { 346 if (bytes_removed > 0) {
345 *removal_end_timestamp = gop_itr == keyframe_map_.end() ? 347 *removal_end_timestamp = gop_itr == keyframe_map_.end() ?
346 GetBufferedEndTimestamp() : gop_itr->first; 348 GetBufferedEndTimestamp() : gop_itr->first;
347 } 349 }
348 return bytes_removed; 350 return bytes_removed;
349 } 351 }
350 352
351 bool SourceBufferRange::FirstGOPEarlierThanMediaTime( 353 bool SourceBufferRange::FirstGOPEarlierThanMediaTime(
352 DecodeTimestamp media_time) const { 354 DecodeTimestamp media_time) const {
353 if (keyframe_map_.size() == 1u) 355 if (keyframe_map_.size() == 1u)
354 return (GetEndTimestamp() < media_time); 356 return (GetBufferedEndTimestamp() <= media_time);
355 357
356 KeyframeMap::const_iterator second_gop = keyframe_map_.begin(); 358 KeyframeMap::const_iterator second_gop = keyframe_map_.begin();
357 ++second_gop; 359 ++second_gop;
358 return second_gop->first <= media_time; 360 return second_gop->first <= media_time;
359 } 361 }
360 362
361 bool SourceBufferRange::FirstGOPContainsNextBufferPosition() const { 363 bool SourceBufferRange::FirstGOPContainsNextBufferPosition() const {
362 if (!HasNextBufferPosition()) 364 if (!HasNextBufferPosition())
363 return false; 365 return false;
364 366
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 } 628 }
627 629
628 if (buffer->timestamp() + buffer->duration() <= start.ToPresentationTime()) 630 if (buffer->timestamp() + buffer->duration() <= start.ToPresentationTime())
629 continue; 631 continue;
630 buffers->push_back(buffer); 632 buffers->push_back(buffer);
631 } 633 }
632 return previous_size < buffers->size(); 634 return previous_size < buffers->size();
633 } 635 }
634 636
635 } // namespace media 637 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/source_buffer_range.h ('k') | media/filters/source_buffer_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698