Home | History | Annotate | Download | only in base
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef MEDIA_BASE_STREAM_PARSER_BUFFER_H_
      6 #define MEDIA_BASE_STREAM_PARSER_BUFFER_H_
      7 
      8 #include <deque>
      9 
     10 #include "media/base/decoder_buffer.h"
     11 #include "media/base/demuxer_stream.h"
     12 #include "media/base/media_export.h"
     13 #include "media/base/stream_parser.h"
     14 
     15 namespace media {
     16 
     17 class MEDIA_EXPORT StreamParserBuffer : public DecoderBuffer {
     18  public:
     19   // Value used to signal an invalid decoder config ID.
     20   enum { kInvalidConfigId = -1 };
     21 
     22   typedef DemuxerStream::Type Type;
     23   typedef StreamParser::TrackId TrackId;
     24 
     25   static scoped_refptr<StreamParserBuffer> CreateEOSBuffer();
     26 
     27   static scoped_refptr<StreamParserBuffer> CopyFrom(
     28       const uint8* data, int data_size, bool is_keyframe, Type type,
     29       TrackId track_id);
     30   static scoped_refptr<StreamParserBuffer> CopyFrom(
     31       const uint8* data, int data_size,
     32       const uint8* side_data, int side_data_size, bool is_keyframe, Type type,
     33       TrackId track_id);
     34   bool IsKeyframe() const { return is_keyframe_; }
     35 
     36   // Decode timestamp. If not explicitly set, or set to kNoTimestamp(), the
     37   // value will be taken from the normal timestamp.
     38   base::TimeDelta GetDecodeTimestamp() const;
     39   void SetDecodeTimestamp(base::TimeDelta timestamp);
     40 
     41   // Gets/sets the ID of the decoder config associated with this buffer.
     42   int GetConfigId() const;
     43   void SetConfigId(int config_id);
     44 
     45   // Gets the parser's media type associated with this buffer. Value is
     46   // meaningless for EOS buffers.
     47   Type type() const { return type_; }
     48 
     49   // Gets the parser's track ID associated with this buffer. Value is
     50   // meaningless for EOS buffers.
     51   TrackId track_id() const { return track_id_; }
     52 
     53   // Converts this buffer to a splice buffer.  |pre_splice_buffers| must not
     54   // have any EOS buffers, must not have any splice buffers, nor must have any
     55   // buffer with preroll.
     56   //
     57   // |pre_splice_buffers| will be deep copied and each copy's splice_timestamp()
     58   // will be set to this buffer's splice_timestamp().  A copy of |this|, with a
     59   // splice_timestamp() of kNoTimestamp(), will be added to the end of
     60   // |splice_buffers_|.
     61   //
     62   // See the Audio Splice Frame Algorithm in the MSE specification for details.
     63   typedef StreamParser::BufferQueue BufferQueue;
     64   void ConvertToSpliceBuffer(const BufferQueue& pre_splice_buffers);
     65   const BufferQueue& splice_buffers() const { return splice_buffers_; }
     66 
     67   // Specifies a buffer which must be decoded prior to this one to ensure this
     68   // buffer can be accurately decoded.  The given buffer must be of the same
     69   // type, must not be a splice buffer, must not have any discard padding, and
     70   // must not be an end of stream buffer.  |preroll| is not copied.
     71   //
     72   // It's expected that this preroll buffer will be discarded entirely post
     73   // decoding.  As such it's discard_padding() will be set to kInfiniteDuration.
     74   //
     75   // All future timestamp, decode timestamp, config id, or track id changes to
     76   // this buffer will be applied to the preroll buffer as well.
     77   void SetPrerollBuffer(const scoped_refptr<StreamParserBuffer>& preroll);
     78   const scoped_refptr<StreamParserBuffer>& preroll_buffer() {
     79     return preroll_buffer_;
     80   }
     81 
     82   virtual void set_timestamp(base::TimeDelta timestamp) OVERRIDE;
     83 
     84  private:
     85   StreamParserBuffer(const uint8* data, int data_size,
     86                      const uint8* side_data, int side_data_size,
     87                      bool is_keyframe, Type type,
     88                      TrackId track_id);
     89   virtual ~StreamParserBuffer();
     90 
     91   bool is_keyframe_;
     92   base::TimeDelta decode_timestamp_;
     93   int config_id_;
     94   Type type_;
     95   TrackId track_id_;
     96   BufferQueue splice_buffers_;
     97   scoped_refptr<StreamParserBuffer> preroll_buffer_;
     98 
     99   DISALLOW_COPY_AND_ASSIGN(StreamParserBuffer);
    100 };
    101 
    102 }  // namespace media
    103 
    104 #endif  // MEDIA_BASE_STREAM_PARSER_BUFFER_H_
    105