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

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

Issue 1670033002: Reland: MSE: Relax the 'media segment must begin with keyframe' requirement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Undid patch set 9's test change, since FrameProcessor *can* produce that output 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/media_source_state.cc ('k') | media/filters/source_buffer_range.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 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ 5 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_
6 #define MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ 6 #define MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 19 matching lines...) Expand all
30 30
31 // Policy for handling large gaps between buffers. Continuous media like 31 // Policy for handling large gaps between buffers. Continuous media like
32 // audio & video should use NO_GAPS_ALLOWED. Discontinuous media like 32 // audio & video should use NO_GAPS_ALLOWED. Discontinuous media like
33 // timed text should use ALLOW_GAPS because large differences in timestamps 33 // timed text should use ALLOW_GAPS because large differences in timestamps
34 // are common and acceptable. 34 // are common and acceptable.
35 enum GapPolicy { 35 enum GapPolicy {
36 NO_GAPS_ALLOWED, 36 NO_GAPS_ALLOWED,
37 ALLOW_GAPS 37 ALLOW_GAPS
38 }; 38 };
39 39
40 // Buffers with the same timestamp are only allowed under certain conditions. 40 // Sequential buffers with the same decode timestamp make sense under certain
41 // More precisely, it is allowed in all situations except when the previous 41 // conditions, typically when the first buffer is a keyframe. Due to some
42 // frame is not a key frame and the current is a key frame. 42 // atypical media append behaviors where a new keyframe might have the same
43 // Examples of situations where DTS of two consecutive frames can be equal: 43 // timestamp as a previous non-keyframe, the playback of the sequence might
44 // involve some throwaway decode work. This method supports detecting this
45 // situation so that callers can log warnings (it returns true in this case
46 // only).
47 // For all other cases, including more typical same-DTS sequences, this method
48 // returns false. Examples of typical situations where DTS of two consecutive
49 // frames can be equal:
44 // - Video: VP8 Alt-Ref frames. 50 // - Video: VP8 Alt-Ref frames.
45 // - Video: IPBPBP...: DTS for I frame and for P frame can be equal. 51 // - Video: IPBPBP...: DTS for I frame and for P frame can be equal.
46 // - Text track cues that start at same time. 52 // - Text track cues that start at same time.
47 // Returns true if |prev_is_keyframe| and |current_is_keyframe| indicate a 53 // Returns true if |prev_is_keyframe| and |current_is_keyframe| indicate a
48 // same timestamp situation that is allowed. False is returned otherwise. 54 // same timestamp situation that is atypical. False is returned otherwise.
49 static bool AllowSameTimestamp(bool prev_is_keyframe, 55 static bool IsUncommonSameTimestampSequence(bool prev_is_keyframe,
50 bool current_is_keyframe); 56 bool current_is_keyframe);
51 57
52 // Creates a source buffer range with |new_buffers|. |new_buffers| cannot be 58 // Creates a source buffer range with |new_buffers|. |new_buffers| cannot be
53 // empty and the front of |new_buffers| must be a keyframe. 59 // empty and the front of |new_buffers| must be a keyframe.
54 // |media_segment_start_time| refers to the starting timestamp for the media 60 // |range_start_time| refers to the starting timestamp for the coded frame
55 // segment to which these buffers belong. 61 // group to which these buffers belong.
56 SourceBufferRange(GapPolicy gap_policy, 62 SourceBufferRange(GapPolicy gap_policy,
57 const BufferQueue& new_buffers, 63 const BufferQueue& new_buffers,
58 DecodeTimestamp media_segment_start_time, 64 DecodeTimestamp range_start_time,
59 const InterbufferDistanceCB& interbuffer_distance_cb); 65 const InterbufferDistanceCB& interbuffer_distance_cb);
60 66
61 ~SourceBufferRange(); 67 ~SourceBufferRange();
62 68
63 // Appends |buffers| to the end of the range and updates |keyframe_map_| as 69 // Appends |buffers| to the end of the range and updates |keyframe_map_| as
64 // it encounters new keyframes. Assumes |buffers| belongs at the end of the 70 // it encounters new keyframes.
65 // range. 71 // If |new_buffers_group_start_timestamp| is kNoDecodeTimestamp(), then the
66 void AppendBuffersToEnd(const BufferQueue& buffers); 72 // first buffer in |buffers| must come directly after the last buffer in this
67 bool CanAppendBuffersToEnd(const BufferQueue& buffers) const; 73 // range (within the fudge room).
74 // If |new_buffers_group_start_timestamp| is set otherwise, then that time
75 // must come directly after the last buffer in this range (within the fudge
76 // room). The latter scenario is required when a muxed coded frame group has
77 // such a large jagged start across tracks that its first buffer is not within
78 // the fudge room, yet its group start was.
79 void AppendBuffersToEnd(const BufferQueue& buffers,
80 DecodeTimestamp new_buffers_group_start_timestamp);
81 bool CanAppendBuffersToEnd(
82 const BufferQueue& buffers,
83 DecodeTimestamp new_buffers_group_start_timestamp) const;
68 84
69 // Appends the buffers from |range| into this range. 85 // Appends the buffers from |range| into this range.
70 // The first buffer in |range| must come directly after the last buffer 86 // The first buffer in |range| must come directly after the last buffer
71 // in this range. 87 // in this range.
72 // If |transfer_current_position| is true, |range|'s |next_buffer_index_| 88 // If |transfer_current_position| is true, |range|'s |next_buffer_index_|
73 // is transfered to this SourceBufferRange. 89 // is transfered to this SourceBufferRange.
90 // Note: Use these only to merge existing ranges. |range|'s first buffer
91 // timestamp must be adjacent to this range. No group start timestamp
92 // adjacency is involved in these methods.
74 void AppendRangeToEnd(const SourceBufferRange& range, 93 void AppendRangeToEnd(const SourceBufferRange& range,
75 bool transfer_current_position); 94 bool transfer_current_position);
76 bool CanAppendRangeToEnd(const SourceBufferRange& range) const; 95 bool CanAppendRangeToEnd(const SourceBufferRange& range) const;
77 96
78 // Updates |next_buffer_index_| to point to the Buffer containing |timestamp|. 97 // Updates |next_buffer_index_| to point to the Buffer containing |timestamp|.
79 // Assumes |timestamp| is valid and in this range. 98 // Assumes |timestamp| is valid and in this range.
80 void Seek(DecodeTimestamp timestamp); 99 void Seek(DecodeTimestamp timestamp);
81 100
82 // Updates |next_buffer_index_| to point to next keyframe after or equal to 101 // Updates |next_buffer_index_| to point to next keyframe after or equal to
83 // |timestamp|. 102 // |timestamp|.
84 void SeekAheadTo(DecodeTimestamp timestamp); 103 void SeekAheadTo(DecodeTimestamp timestamp);
85 104
86 // Updates |next_buffer_index_| to point to next keyframe strictly after 105 // Updates |next_buffer_index_| to point to next keyframe strictly after
87 // |timestamp|. 106 // |timestamp|.
88 void SeekAheadPast(DecodeTimestamp timestamp); 107 void SeekAheadPast(DecodeTimestamp timestamp);
89 108
90 // Seeks to the beginning of the range. 109 // Seeks to the beginning of the range.
91 void SeekToStart(); 110 void SeekToStart();
92 111
93 // Finds the next keyframe from |buffers_| starting at or after |timestamp| 112 // Finds the next keyframe from |buffers_| starting at or after |timestamp|
94 // and creates and returns a new SourceBufferRange with the buffers from that 113 // and creates and returns a new SourceBufferRange with the buffers from that
95 // keyframe onward. The buffers in the new SourceBufferRange are moved out of 114 // keyframe onward. The buffers in the new SourceBufferRange are moved out of
96 // this range. If there is no keyframe at or after |timestamp|, SplitRange() 115 // this range. If there is no keyframe at or after |timestamp|, SplitRange()
97 // returns null and this range is unmodified. 116 // returns null and this range is unmodified. This range can become empty if
117 // |timestamp| <= the DTS of the first buffer in this range.
98 SourceBufferRange* SplitRange(DecodeTimestamp timestamp); 118 SourceBufferRange* SplitRange(DecodeTimestamp timestamp);
99 119
100 // Deletes the buffers from this range starting at |timestamp|, exclusive if 120 // Deletes the buffers from this range starting at |timestamp|, exclusive if
101 // |is_exclusive| is true, inclusive otherwise. 121 // |is_exclusive| is true, inclusive otherwise.
102 // Resets |next_buffer_index_| if the buffer at |next_buffer_index_| was 122 // Resets |next_buffer_index_| if the buffer at |next_buffer_index_| was
103 // deleted, and deletes the |keyframe_map_| entries for the buffers that 123 // deleted, and deletes the |keyframe_map_| entries for the buffers that
104 // were removed. 124 // were removed.
105 // |deleted_buffers| contains the buffers that were deleted from this range, 125 // |deleted_buffers| contains the buffers that were deleted from this range,
106 // starting at the buffer that had been at |next_buffer_index_|. 126 // starting at the buffer that had been at |next_buffer_index_|.
107 // Returns true if everything in the range was deleted. Otherwise 127 // Returns true if everything in the range was deleted. Otherwise
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // Returns true if this range's buffered timespan completely overlaps the 216 // Returns true if this range's buffered timespan completely overlaps the
197 // buffered timespan of |range|. 217 // buffered timespan of |range|.
198 bool CompletelyOverlaps(const SourceBufferRange& range) const; 218 bool CompletelyOverlaps(const SourceBufferRange& range) const;
199 219
200 // Returns true if the end of this range contains buffers that overlaps with 220 // Returns true if the end of this range contains buffers that overlaps with
201 // the beginning of |range|. 221 // the beginning of |range|.
202 bool EndOverlaps(const SourceBufferRange& range) const; 222 bool EndOverlaps(const SourceBufferRange& range) const;
203 223
204 // Returns true if |timestamp| is the timestamp of the next buffer in 224 // Returns true if |timestamp| is the timestamp of the next buffer in
205 // sequence after |buffers_.back()|, false otherwise. 225 // sequence after |buffers_.back()|, false otherwise.
206 bool IsNextInSequence(DecodeTimestamp timestamp, bool is_key_frame) const; 226 bool IsNextInSequence(DecodeTimestamp timestamp) const;
207 227
208 // Adds all buffers which overlap [start, end) to the end of |buffers|. If 228 // Adds all buffers which overlap [start, end) to the end of |buffers|. If
209 // no buffers exist in the range returns false, true otherwise. 229 // no buffers exist in the range returns false, true otherwise.
210 bool GetBuffersInRange(DecodeTimestamp start, DecodeTimestamp end, 230 bool GetBuffersInRange(DecodeTimestamp start, DecodeTimestamp end,
211 BufferQueue* buffers); 231 BufferQueue* buffers);
212 232
213 size_t size_in_bytes() const { return size_in_bytes_; } 233 size_t size_in_bytes() const { return size_in_bytes_; }
214 234
215 private: 235 private:
216 typedef std::map<DecodeTimestamp, int> KeyframeMap; 236 typedef std::map<DecodeTimestamp, int> KeyframeMap;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 292
273 // Index base of all positions in |keyframe_map_|. In other words, the 293 // Index base of all positions in |keyframe_map_|. In other words, the
274 // real position of entry |k| of |keyframe_map_| in the range is: 294 // real position of entry |k| of |keyframe_map_| in the range is:
275 // keyframe_map_[k] - keyframe_map_index_base_ 295 // keyframe_map_[k] - keyframe_map_index_base_
276 int keyframe_map_index_base_; 296 int keyframe_map_index_base_;
277 297
278 // Index into |buffers_| for the next buffer to be returned by 298 // Index into |buffers_| for the next buffer to be returned by
279 // GetNextBuffer(), set to -1 before Seek(). 299 // GetNextBuffer(), set to -1 before Seek().
280 int next_buffer_index_; 300 int next_buffer_index_;
281 301
282 // If the first buffer in this range is the beginning of a media segment, 302 // If the first buffer in this range is the beginning of a coded frame group,
283 // |media_segment_start_time_| is the time when the media segment begins. 303 // |range_start_time_| is the time when the coded frame group begins. This is
284 // |media_segment_start_time_| may be <= the timestamp of the first buffer in 304 // especially important in muxed media where the first coded frames for each
285 // |buffers_|. |media_segment_start_time_| is kNoTimestamp() if this range 305 // track do not necessarily begin at the same time.
286 // does not start at the beginning of a media segment, which can only happen 306 // |range_start_time_| may be <= the timestamp of the first buffer in
287 // garbage collection or after an end overlap that results in a split range 307 // |buffers_|. |range_start_time_| is kNoDecodeTimestamp() if this range does
288 // (we don't have a way of knowing the media segment timestamp for the new 308 // not start at the beginning of a coded frame group, which can happen by
289 // range). 309 // range removal or split when we don't have a way of knowing, across
290 DecodeTimestamp media_segment_start_time_; 310 // potentially multiple muxed streams, the coded frame group start timestamp
311 // for the new range.
312 DecodeTimestamp range_start_time_;
291 313
292 // Called to get the largest interbuffer distance seen so far in the stream. 314 // Called to get the largest interbuffer distance seen so far in the stream.
293 InterbufferDistanceCB interbuffer_distance_cb_; 315 InterbufferDistanceCB interbuffer_distance_cb_;
294 316
295 // Stores the amount of memory taken up by the data in |buffers_|. 317 // Stores the amount of memory taken up by the data in |buffers_|.
296 size_t size_in_bytes_; 318 size_t size_in_bytes_;
297 319
298 DISALLOW_COPY_AND_ASSIGN(SourceBufferRange); 320 DISALLOW_COPY_AND_ASSIGN(SourceBufferRange);
299 }; 321 };
300 322
301 } // namespace media 323 } // namespace media
302 324
303 #endif // MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ 325 #endif // MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_
OLDNEW
« no previous file with comments | « media/filters/media_source_state.cc ('k') | media/filters/source_buffer_range.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698