15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SourceBufferStream is a data structure that stores media Buffers in ranges.
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Buffers can be appended out of presentation order. Buffers are retrieved by
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// seeking to the desired start point and calling GetNextBuffer(). Buffers are
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// returned in sequential presentation order.
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <deque>
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <list>
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <utility>
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "media/base/audio_decoder_config.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "media/base/media_export.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "media/base/media_log.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "media/base/ranges.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "media/base/stream_parser_buffer.h"
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "media/base/text_track_config.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "media/base/video_decoder_config.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace media {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SourceBufferRange;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// See file-level comment for complete description.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MEDIA_EXPORT SourceBufferStream {
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
35effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  typedef StreamParser::BufferQueue BufferQueue;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Status returned by GetNextBuffer().
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // kSuccess: Indicates that the next buffer was returned.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // kNeedBuffer: Indicates that we need more data before a buffer can be
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //              returned.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // kConfigChange: Indicates that the next buffer requires a config change.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum Status {
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kSuccess,
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kNeedBuffer,
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    kConfigChange,
467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    kEndOfStream
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  enum Type {
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    kAudio,
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    kVideo,
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    kText
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  };
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceBufferStream(const AudioDecoderConfig& audio_config,
56effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                     const LogCB& log_cb,
57effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                     bool splice_frames_enabled);
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SourceBufferStream(const VideoDecoderConfig& video_config,
59effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                     const LogCB& log_cb,
60effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                     bool splice_frames_enabled);
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SourceBufferStream(const TextTrackConfig& text_config,
62effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                     const LogCB& log_cb,
63effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                     bool splice_frames_enabled);
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~SourceBufferStream();
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Signals that the next buffers appended are part of a new media segment
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // starting at |media_segment_start_time|.
696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // TODO(acolwell/wolenetz): This should be changed to a presentation
706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // timestamp. See http://crbug.com/402502
716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void OnNewMediaSegment(DecodeTimestamp media_segment_start_time);
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add the |buffers| to the SourceBufferStream. Buffers within the queue are
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // expected to be in order, but multiple calls to Append() may add buffers out
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // of order or overlapping. Assumes all buffers within |buffers| are in
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // presentation order and are non-overlapping.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if Append() was successful, false if |buffers| are not added.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(vrk): Implement garbage collection. (crbug.com/125070)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Append(const BufferQueue& buffers);
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
81bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // Removes buffers between |start| and |end| according to the steps
82bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // in the "Coded Frame Removal Algorithm" in the Media Source
83bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // Extensions Spec.
84bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#sourcebuffer-coded-frame-removal
85bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  //
86bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // |duration| is the current duration of the presentation. It is
87bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // required by the computation outlined in the spec.
88bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  void Remove(base::TimeDelta start, base::TimeDelta end,
89bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch              base::TimeDelta duration);
90bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Changes the SourceBufferStream's state so that it will start returning
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // buffers starting from the closest keyframe before |timestamp|.
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Seek(base::TimeDelta timestamp);
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the SourceBufferStream has seeked to a time without
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // buffered data and is waiting for more data to be appended.
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsSeekPending() const;
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notifies the SourceBufferStream that the media duration has been changed to
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |duration| so it should drop any data past that point.
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnSetDuration(base::TimeDelta duration);
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Fills |out_buffer| with a new buffer. Buffers are presented in order from
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the last call to Seek(), or starting with the first buffer appended if
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Seek() has not been called yet.
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |out_buffer|'s timestamp may be earlier than the |timestamp| passed to
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the last Seek() call.
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns kSuccess if |out_buffer| is filled with a valid buffer, kNeedBuffer
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if there is not enough data buffered to fulfill the request, and
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // kConfigChange if the next buffer requires a config change.
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Status GetNextBuffer(scoped_refptr<StreamParserBuffer>* out_buffer);
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a list of the buffered time ranges.
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Ranges<base::TimeDelta> GetBufferedTime() const;
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns the duration of the buffered ranges, which is equivalent
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to the end timestamp of the last buffered range. If no data is buffered
1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // then base::TimeDelta() is returned.
1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::TimeDelta GetBufferedDuration() const;
1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Notifies this object that end of stream has been signalled.
122ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  void MarkEndOfStream();
1237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
124ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Clear the end of stream state set by MarkEndOfStream().
125ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  void UnmarkEndOfStream();
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const AudioDecoderConfig& GetCurrentAudioDecoderConfig();
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const VideoDecoderConfig& GetCurrentVideoDecoderConfig();
129f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  const TextTrackConfig& GetCurrentTextTrackConfig();
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notifies this object that the audio config has changed and buffers in
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // future Append() calls should be associated with this new config.
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool UpdateAudioConfig(const AudioDecoderConfig& config);
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notifies this object that the video config has changed and buffers in
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // future Append() calls should be associated with this new config.
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool UpdateVideoConfig(const VideoDecoderConfig& config);
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the largest distance between two adjacent buffers in this stream,
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // or an estimate if no two adjacent buffers have been appended to the stream
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // yet.
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeDelta GetMaxInterbufferDistance() const;
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void set_memory_limit(int memory_limit) {
145eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    memory_limit_ = memory_limit;
146eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
14968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  friend class SourceBufferStreamTest;
15068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef std::list<SourceBufferRange*> RangeList;
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Frees up space if the SourceBufferStream is taking up too much memory.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GarbageCollectIfNeeded();
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Attempts to delete approximately |total_bytes_to_free| amount of data
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |ranges_|, starting at the front of |ranges_| and moving linearly forward
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // through the buffers. Deletes starting from the back if |reverse_direction|
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is true. Returns the number of bytes freed.
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int FreeBuffers(int total_bytes_to_free, bool reverse_direction);
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Attempts to delete approximately |total_bytes_to_free| amount of data from
16368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // |ranges_|, starting after the last appended buffer before the current
16468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // playback position.
16568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  int FreeBuffersAfterLastAppended(int total_bytes_to_free);
16668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
16768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Gets the removal range to secure |byte_to_free| from
16868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // [|start_timestamp|, |end_timestamp|).
16968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Returns the size of buffers to secure if future
17068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Remove(|start_timestamp|, |removal_end_timestamp|, duration) is called.
17168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Will not update |removal_end_timestamp| if the returned size is 0.
1726e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  int GetRemovalRange(DecodeTimestamp start_timestamp,
1736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      DecodeTimestamp end_timestamp, int byte_to_free,
1746e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      DecodeTimestamp* removal_end_timestamp);
17568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
1761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Prepares |range_for_next_append_| so |new_buffers| can be appended.
1771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // This involves removing buffers between the end of the previous append
1781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // and any buffers covered by the time range in |new_buffers|.
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |deleted_buffers| is an output parameter containing candidates for
1801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // |track_buffer_| if this method ends up removing the current playback
1811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // position from the range.
1821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void PrepareRangesForNextAppend(const BufferQueue& new_buffers,
1831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                  BufferQueue* deleted_buffers);
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Removes buffers, from the |track_buffer_|, that come after |timestamp|.
1866e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void PruneTrackBuffer(const DecodeTimestamp timestamp);
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Checks to see if |range_with_new_buffers_itr| can be merged with the range
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // next to it, and merges them if so.
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void MergeWithAdjacentRangeIfNecessary(
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const RangeList::iterator& range_with_new_buffers_itr);
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if |second_timestamp| is the timestamp of the next buffer in
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // sequence after |first_timestamp|, false otherwise.
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool AreAdjacentInSequence(
1966e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      DecodeTimestamp first_timestamp, DecodeTimestamp second_timestamp) const;
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper method that returns the timestamp for the next buffer that
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |selected_range_| will return from GetNextBuffer() call, or kNoTimestamp()
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if in between seeking (i.e. |selected_range_| is null).
2016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  DecodeTimestamp GetNextBufferTimestamp();
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Finds the range that should contain a media segment that begins with
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |start_timestamp| and returns the iterator pointing to it. Returns
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |ranges_.end()| if there's no such existing range.
2066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  RangeList::iterator FindExistingRangeFor(DecodeTimestamp start_timestamp);
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Inserts |new_range| into |ranges_| preserving sorted order. Returns an
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // iterator in |ranges_| that points to |new_range|.
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RangeList::iterator AddToRanges(SourceBufferRange* new_range);
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns an iterator that points to the place in |ranges_| where
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |selected_range_| lives.
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RangeList::iterator GetSelectedRangeItr();
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the |selected_range_| to |range| and resets the next buffer position
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for the previous |selected_range_|.
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetSelectedRange(SourceBufferRange* range);
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Seeks |range| to |seek_timestamp| and then calls SetSelectedRange() with
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |range|.
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SeekAndSetSelectedRange(SourceBufferRange* range,
2236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                               DecodeTimestamp seek_timestamp);
2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Resets this stream back to an unseeked state.
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ResetSeekState();
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if |seek_timestamp| refers to the beginning of the first range
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in |ranges_|, false otherwise or if |ranges_| is empty.
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ShouldSeekToStartOfBuffered(base::TimeDelta seek_timestamp) const;
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the timestamps of |buffers| are monotonically increasing
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // since the previous append to the media segment, false otherwise.
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsMonotonicallyIncreasing(const BufferQueue& buffers) const;
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Returns true if |next_timestamp| and |next_is_keyframe| are valid for
2371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // the first buffer after the previous append.
2386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  bool IsNextTimestampValid(DecodeTimestamp next_timestamp,
2391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                            bool next_is_keyframe) const;
2401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if |selected_range_| is the only range in |ranges_| that
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HasNextBufferPosition().
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool OnlySelectedRangeIsSeeked() const;
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Measures the distances between buffer timestamps and tracks the max.
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void UpdateMaxInterbufferDistance(const BufferQueue& buffers);
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the config ID for each buffer to |append_config_index_|.
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetConfigIds(const BufferQueue& buffers);
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to complete a config change. Updates |current_config_index_| to
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // match the index of the next buffer. Calling this method causes
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // GetNextBuffer() to stop returning kConfigChange and start returning
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // kSuccess.
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CompleteConfigChange();
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets |selected_range_| and seeks to the nearest keyframe after
2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |timestamp| if necessary and possible. This method only attempts to
2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // set |selected_range_| if |seleted_range_| is null and |track_buffer_|
2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // is empty.
2616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void SetSelectedRangeIfNeeded(const DecodeTimestamp timestamp);
2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Find a keyframe timestamp that is >= |start_timestamp| and can be used to
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // find a new selected range.
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns kNoTimestamp() if an appropriate keyframe timestamp could not be
2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // found.
2676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  DecodeTimestamp FindNewSelectedRangeSeekTimestamp(
2686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      const DecodeTimestamp start_timestamp);
2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Searches |ranges_| for the first keyframe timestamp that is >= |timestamp|.
2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If |ranges_| doesn't contain a GOP that covers |timestamp| or doesn't
2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // have a keyframe after |timestamp| then kNoTimestamp() is returned.
2736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  DecodeTimestamp FindKeyframeAfterTimestamp(const DecodeTimestamp timestamp);
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns "VIDEO" for a video SourceBufferStream, "AUDIO" for an audio
2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // stream, and "TEXT" for a text stream.
2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string GetStreamTypeName() const;
2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Returns true if we don't have any ranges or the last range is selected
2807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // or there is a pending seek beyond any existing ranges.
2817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool IsEndSelected() const;
2827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Deletes the range pointed to by |*itr| and removes it from |ranges_|.
2848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // If |*itr| points to |selected_range_|, then |selected_range_| is set to
2858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // NULL. After the range is removed, |*itr| is to the range after the one that
2868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // was removed or to |ranges_.end()| if the last range was removed.
2878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void DeleteAndRemoveRange(RangeList::iterator* itr);
2888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Helper function used by Remove() and PrepareRangesForNextAppend() to
2901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // remove buffers and ranges between |start| and |end|.
2911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // |is_exclusive| - If set to true, buffers with timestamps that
2921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // match |start| are not removed. If set to false, buffers with
2931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // timestamps that match |start| will be removed.
2941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // |*deleted_buffers| - Filled with buffers for the current playback position
2951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // if the removal range included the current playback position. These buffers
2961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // can be used as candidates for placing in the |track_buffer_|.
2971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void RemoveInternal(
2986e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      DecodeTimestamp start, DecodeTimestamp end, bool is_exclusive,
2991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      BufferQueue* deleted_buffers);
3001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
3015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Type GetType() const;
3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
30346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // See GetNextBuffer() for additional details.  This method handles splice
30446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // frame processing.
30546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  Status HandleNextBufferWithSplice(
30646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      scoped_refptr<StreamParserBuffer>* out_buffer);
30746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
30846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // See GetNextBuffer() for additional details.  This method handles preroll
30946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // frame processing.
31046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  Status HandleNextBufferWithPreroll(
31146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      scoped_refptr<StreamParserBuffer>* out_buffer);
31246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // See GetNextBuffer() for additional details.  The internal method hands out
31446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // single buffers from the |track_buffer_| and |selected_range_| without
31546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // additional processing for splice frame or preroll buffers.
3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Status GetNextBufferInternal(scoped_refptr<StreamParserBuffer>* out_buffer);
3171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
318effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Called by PrepareRangesForNextAppend() before pruning overlapped buffers to
319effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // generate a splice frame with a small portion of the overlapped buffers.  If
320effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // a splice frame is generated, the first buffer in |new_buffers| will have
321effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // its timestamps, duration, and fade out preroll updated.
322effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  void GenerateSpliceFrame(const BufferQueue& new_buffers);
323effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
32446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // If |out_buffer| has splice buffers or preroll, sets |pending_buffer_|
32546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // appropriately and returns true.  Otherwise returns false.
32646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  bool SetPendingBuffer(scoped_refptr<StreamParserBuffer>* out_buffer);
32746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Callback used to report error strings that can help the web developer
3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // figure out what is wrong with the content.
3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  LogCB log_cb_;
3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // List of disjoint buffered ranges, ordered by start time.
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RangeList ranges_;
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates which decoder config is being used by the decoder.
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // GetNextBuffer() is only allows to return buffers that have a
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // config ID that matches this index. If there is a mismatch then
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // it must signal that a config change is needed.
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int current_config_index_;
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates which decoder config to associate with new buffers
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // being appended. Each new buffer appended has its config ID set
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to the value of this field.
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int append_config_index_;
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Holds the audio/video configs for this stream. |current_config_index_|
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and |append_config_index_| represent indexes into one of these vectors.
3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<AudioDecoderConfig> audio_configs_;
3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<VideoDecoderConfig> video_configs_;
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
351f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Holds the text config for this stream.
352f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  TextTrackConfig text_track_config_;
353f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // True if more data needs to be appended before the Seek() can complete,
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // false if no Seek() has been requested or the Seek() is completed.
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool seek_pending_;
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // True if the end of the stream has been signalled.
3597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool end_of_stream_;
3607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Timestamp of the last request to Seek().
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeDelta seek_buffer_timestamp_;
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Pointer to the seeked-to Range. This is the range from which
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // emptied.
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SourceBufferRange* selected_range_;
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Queue of the next buffers to be returned from calls to GetNextBuffer(). If
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |track_buffer_| is empty, return buffers from |selected_range_|.
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BufferQueue track_buffer_;
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The start time of the current media segment being appended.
3746e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  DecodeTimestamp media_segment_start_time_;
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Points to the range containing the current media segment being appended.
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RangeList::iterator range_for_next_append_;
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // True when the next call to Append() begins a new media segment.
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool new_media_segment_;
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The timestamp of the last buffer appended to the media segment, set to
3836e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // kNoDecodeTimestamp() if the beginning of the segment.
3846e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  DecodeTimestamp last_appended_buffer_timestamp_;
3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool last_appended_buffer_is_keyframe_;
3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The decode timestamp on the last buffer returned by the most recent
3882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // GetNextBuffer() call. Set to kNoTimestamp() if GetNextBuffer() hasn't been
3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // called yet or a seek has happened since the last GetNextBuffer() call.
3906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  DecodeTimestamp last_output_buffer_timestamp_;
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stores the largest distance between two adjacent buffers in this stream.
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeDelta max_interbuffer_distance_;
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The maximum amount of data in bytes the stream will keep in memory.
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int memory_limit_;
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates that a kConfigChanged status has been reported by GetNextBuffer()
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and GetCurrentXXXDecoderConfig() must be called to update the current
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // config. GetNextBuffer() must not be called again until
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // GetCurrentXXXDecoderConfig() has been called.
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool config_change_pending_;
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
40446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Used by HandleNextBufferWithSplice() or HandleNextBufferWithPreroll() when
40546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // a splice frame buffer or buffer with preroll is returned from
40646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // GetNextBufferInternal().
40746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  scoped_refptr<StreamParserBuffer> pending_buffer_;
408effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
409effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Indicates which of the splice buffers in |splice_buffer_| should be
410effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // handled out next.
411effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  size_t splice_buffers_index_;
4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
41346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Indicates that all buffers before |pending_buffer_| have been handed out.
41446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  bool pending_buffers_complete_;
4155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
416effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Indicates that splice frame generation is enabled.
417effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  const bool splice_frames_enabled_;
4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SourceBufferStream);
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace media
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_
425