OLD | NEW |
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 #ifndef MEDIA_BASE_STREAM_PARSER_BUFFER_H_ | 5 #ifndef MEDIA_BASE_STREAM_PARSER_BUFFER_H_ |
6 #define MEDIA_BASE_STREAM_PARSER_BUFFER_H_ | 6 #define MEDIA_BASE_STREAM_PARSER_BUFFER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "media/base/decoder_buffer.h" | 10 #include "media/base/decoder_buffer.h" |
11 #include "media/base/demuxer_stream.h" | 11 #include "media/base/demuxer_stream.h" |
12 #include "media/base/media_export.h" | 12 #include "media/base/media_export.h" |
13 #include "media/base/stream_parser.h" | 13 #include "media/base/stream_parser.h" |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
| 17 // Simple wrapper around base::TimeDelta that represents a decode timestamp. |
| 18 // Making DecodeTimestamp a different type makes it easier to determine whether |
| 19 // code is operating on presentation or decode timestamps and makes conversions |
| 20 // between the two types explicit and easy to spot. |
| 21 class DecodeTimestamp { |
| 22 public: |
| 23 DecodeTimestamp() {} |
| 24 DecodeTimestamp(const DecodeTimestamp& rhs) : ts_(rhs.ts_) { } |
| 25 DecodeTimestamp& operator=(const DecodeTimestamp& rhs) { |
| 26 if (&rhs != this) |
| 27 ts_ = rhs.ts_; |
| 28 return *this; |
| 29 } |
| 30 |
| 31 // Only operators that are actually used by the code have been defined. |
| 32 // Reviewers should pay close attention to the addition of new operators. |
| 33 bool operator<(const DecodeTimestamp& rhs) const { return ts_ < rhs.ts_; } |
| 34 bool operator>(const DecodeTimestamp& rhs) const { return ts_ > rhs.ts_; } |
| 35 bool operator==(const DecodeTimestamp& rhs) const { return ts_ == rhs.ts_; } |
| 36 bool operator!=(const DecodeTimestamp& rhs) const { return ts_ != rhs.ts_; } |
| 37 bool operator>=(const DecodeTimestamp& rhs) const { return ts_ >= rhs.ts_; } |
| 38 bool operator<=(const DecodeTimestamp& rhs) const { return ts_ <= rhs.ts_; } |
| 39 |
| 40 base::TimeDelta operator-(const DecodeTimestamp& rhs) const { |
| 41 return ts_ - rhs.ts_; |
| 42 } |
| 43 |
| 44 DecodeTimestamp& operator+=(const base::TimeDelta& rhs) { |
| 45 ts_ += rhs; |
| 46 return *this; |
| 47 } |
| 48 |
| 49 DecodeTimestamp& operator-=(const base::TimeDelta& rhs) { |
| 50 ts_ -= rhs; |
| 51 return *this; |
| 52 } |
| 53 |
| 54 DecodeTimestamp operator+(const base::TimeDelta& rhs) const { |
| 55 return DecodeTimestamp(ts_ + rhs); |
| 56 } |
| 57 |
| 58 DecodeTimestamp operator-(const base::TimeDelta& rhs) const { |
| 59 return DecodeTimestamp(ts_ - rhs); |
| 60 } |
| 61 |
| 62 int64 operator/(const base::TimeDelta& rhs) const { |
| 63 return ts_ / rhs; |
| 64 } |
| 65 |
| 66 static DecodeTimestamp FromSecondsD(double seconds) { |
| 67 return DecodeTimestamp(base::TimeDelta::FromSecondsD(seconds)); |
| 68 } |
| 69 |
| 70 static DecodeTimestamp FromMilliseconds(int64 milliseconds) { |
| 71 return DecodeTimestamp(base::TimeDelta::FromMilliseconds(milliseconds)); |
| 72 } |
| 73 |
| 74 static DecodeTimestamp FromMicroseconds(int64 microseconds) { |
| 75 return DecodeTimestamp(base::TimeDelta::FromMicroseconds(microseconds)); |
| 76 } |
| 77 |
| 78 // This method is used to explicitly call out when presentation timestamps |
| 79 // are being converted to a decode timestamp. |
| 80 static DecodeTimestamp FromPresentationTime(base::TimeDelta timestamp) { |
| 81 return DecodeTimestamp(timestamp); |
| 82 } |
| 83 |
| 84 double InSecondsF() const { return ts_.InSecondsF(); } |
| 85 int64 InMilliseconds() const { return ts_.InMilliseconds(); } |
| 86 int64 InMicroseconds() const { return ts_.InMicroseconds(); } |
| 87 |
| 88 // TODO(acolwell): Remove once all the hacks are gone. This method is called |
| 89 // by hacks where a decode time is being used as a presentation time. |
| 90 base::TimeDelta ToPresentationTime() const { return ts_; } |
| 91 |
| 92 private: |
| 93 explicit DecodeTimestamp(base::TimeDelta timestamp) : ts_(timestamp) { } |
| 94 |
| 95 base::TimeDelta ts_; |
| 96 }; |
| 97 |
| 98 MEDIA_EXPORT extern inline DecodeTimestamp kNoDecodeTimestamp() { |
| 99 return DecodeTimestamp::FromPresentationTime(kNoTimestamp()); |
| 100 } |
| 101 |
17 class MEDIA_EXPORT StreamParserBuffer : public DecoderBuffer { | 102 class MEDIA_EXPORT StreamParserBuffer : public DecoderBuffer { |
18 public: | 103 public: |
19 // Value used to signal an invalid decoder config ID. | 104 // Value used to signal an invalid decoder config ID. |
20 enum { kInvalidConfigId = -1 }; | 105 enum { kInvalidConfigId = -1 }; |
21 | 106 |
22 typedef DemuxerStream::Type Type; | 107 typedef DemuxerStream::Type Type; |
23 typedef StreamParser::TrackId TrackId; | 108 typedef StreamParser::TrackId TrackId; |
24 | 109 |
25 static scoped_refptr<StreamParserBuffer> CreateEOSBuffer(); | 110 static scoped_refptr<StreamParserBuffer> CreateEOSBuffer(); |
26 | 111 |
27 static scoped_refptr<StreamParserBuffer> CopyFrom( | 112 static scoped_refptr<StreamParserBuffer> CopyFrom( |
28 const uint8* data, int data_size, bool is_keyframe, Type type, | 113 const uint8* data, int data_size, bool is_keyframe, Type type, |
29 TrackId track_id); | 114 TrackId track_id); |
30 static scoped_refptr<StreamParserBuffer> CopyFrom( | 115 static scoped_refptr<StreamParserBuffer> CopyFrom( |
31 const uint8* data, int data_size, | 116 const uint8* data, int data_size, |
32 const uint8* side_data, int side_data_size, bool is_keyframe, Type type, | 117 const uint8* side_data, int side_data_size, bool is_keyframe, Type type, |
33 TrackId track_id); | 118 TrackId track_id); |
34 bool IsKeyframe() const { return is_keyframe_; } | 119 bool IsKeyframe() const { return is_keyframe_; } |
35 | 120 |
36 // Decode timestamp. If not explicitly set, or set to kNoTimestamp(), the | 121 // Decode timestamp. If not explicitly set, or set to kNoTimestamp(), the |
37 // value will be taken from the normal timestamp. | 122 // value will be taken from the normal timestamp. |
38 base::TimeDelta GetDecodeTimestamp() const; | 123 DecodeTimestamp GetDecodeTimestamp() const; |
39 void SetDecodeTimestamp(base::TimeDelta timestamp); | 124 void SetDecodeTimestamp(DecodeTimestamp timestamp); |
40 | 125 |
41 // Gets/sets the ID of the decoder config associated with this buffer. | 126 // Gets/sets the ID of the decoder config associated with this buffer. |
42 int GetConfigId() const; | 127 int GetConfigId() const; |
43 void SetConfigId(int config_id); | 128 void SetConfigId(int config_id); |
44 | 129 |
45 // Gets the parser's media type associated with this buffer. Value is | 130 // Gets the parser's media type associated with this buffer. Value is |
46 // meaningless for EOS buffers. | 131 // meaningless for EOS buffers. |
47 Type type() const { return type_; } | 132 Type type() const { return type_; } |
48 | 133 |
49 // Gets the parser's track ID associated with this buffer. Value is | 134 // Gets the parser's track ID associated with this buffer. Value is |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 virtual void set_timestamp(base::TimeDelta timestamp) OVERRIDE; | 167 virtual void set_timestamp(base::TimeDelta timestamp) OVERRIDE; |
83 | 168 |
84 private: | 169 private: |
85 StreamParserBuffer(const uint8* data, int data_size, | 170 StreamParserBuffer(const uint8* data, int data_size, |
86 const uint8* side_data, int side_data_size, | 171 const uint8* side_data, int side_data_size, |
87 bool is_keyframe, Type type, | 172 bool is_keyframe, Type type, |
88 TrackId track_id); | 173 TrackId track_id); |
89 virtual ~StreamParserBuffer(); | 174 virtual ~StreamParserBuffer(); |
90 | 175 |
91 bool is_keyframe_; | 176 bool is_keyframe_; |
92 base::TimeDelta decode_timestamp_; | 177 DecodeTimestamp decode_timestamp_; |
93 int config_id_; | 178 int config_id_; |
94 Type type_; | 179 Type type_; |
95 TrackId track_id_; | 180 TrackId track_id_; |
96 BufferQueue splice_buffers_; | 181 BufferQueue splice_buffers_; |
97 scoped_refptr<StreamParserBuffer> preroll_buffer_; | 182 scoped_refptr<StreamParserBuffer> preroll_buffer_; |
98 | 183 |
99 DISALLOW_COPY_AND_ASSIGN(StreamParserBuffer); | 184 DISALLOW_COPY_AND_ASSIGN(StreamParserBuffer); |
100 }; | 185 }; |
101 | 186 |
102 } // namespace media | 187 } // namespace media |
103 | 188 |
104 #endif // MEDIA_BASE_STREAM_PARSER_BUFFER_H_ | 189 #endif // MEDIA_BASE_STREAM_PARSER_BUFFER_H_ |
OLD | NEW |