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_DECODER_BUFFER_H_ | 5 #ifndef MEDIA_BASE_DECODER_BUFFER_H_ |
6 #define MEDIA_BASE_DECODER_BUFFER_H_ | 6 #define MEDIA_BASE_DECODER_BUFFER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 #endif | 41 #endif |
42 }; | 42 }; |
43 | 43 |
44 // Allocates buffer with |size| >= 0. Buffer will be padded and aligned | 44 // Allocates buffer with |size| >= 0. Buffer will be padded and aligned |
45 // as necessary, and |is_key_frame_| will default to false. | 45 // as necessary, and |is_key_frame_| will default to false. |
46 explicit DecoderBuffer(int size); | 46 explicit DecoderBuffer(int size); |
47 | 47 |
48 // Create a DecoderBuffer whose |data_| is copied from |data|. Buffer will be | 48 // Create a DecoderBuffer whose |data_| is copied from |data|. Buffer will be |
49 // padded and aligned as necessary. |data| must not be NULL and |size| >= 0. | 49 // padded and aligned as necessary. |data| must not be NULL and |size| >= 0. |
50 // The buffer's |is_key_frame_| will default to false. | 50 // The buffer's |is_key_frame_| will default to false. |
51 static scoped_refptr<DecoderBuffer> CopyFrom(const uint8* data, int size); | 51 static scoped_refptr<DecoderBuffer> CopyFrom(const uint8_t* data, int size); |
52 | 52 |
53 // Create a DecoderBuffer whose |data_| is copied from |data| and |side_data_| | 53 // Create a DecoderBuffer whose |data_| is copied from |data| and |side_data_| |
54 // is copied from |side_data|. Buffers will be padded and aligned as necessary | 54 // is copied from |side_data|. Buffers will be padded and aligned as necessary |
55 // Data pointers must not be NULL and sizes must be >= 0. The buffer's | 55 // Data pointers must not be NULL and sizes must be >= 0. The buffer's |
56 // |is_key_frame_| will default to false. | 56 // |is_key_frame_| will default to false. |
57 static scoped_refptr<DecoderBuffer> CopyFrom(const uint8* data, int size, | 57 static scoped_refptr<DecoderBuffer> CopyFrom(const uint8_t* data, |
58 const uint8* side_data, | 58 int size, |
| 59 const uint8_t* side_data, |
59 int side_data_size); | 60 int side_data_size); |
60 | 61 |
61 // Create a DecoderBuffer indicating we've reached end of stream. | 62 // Create a DecoderBuffer indicating we've reached end of stream. |
62 // | 63 // |
63 // Calling any method other than end_of_stream() on the resulting buffer | 64 // Calling any method other than end_of_stream() on the resulting buffer |
64 // is disallowed. | 65 // is disallowed. |
65 static scoped_refptr<DecoderBuffer> CreateEOSBuffer(); | 66 static scoped_refptr<DecoderBuffer> CreateEOSBuffer(); |
66 | 67 |
67 base::TimeDelta timestamp() const { | 68 base::TimeDelta timestamp() const { |
68 DCHECK(!end_of_stream()); | 69 DCHECK(!end_of_stream()); |
(...skipping 10 matching lines...) Expand all Loading... |
79 } | 80 } |
80 | 81 |
81 void set_duration(base::TimeDelta duration) { | 82 void set_duration(base::TimeDelta duration) { |
82 DCHECK(!end_of_stream()); | 83 DCHECK(!end_of_stream()); |
83 DCHECK(duration == kNoTimestamp() || | 84 DCHECK(duration == kNoTimestamp() || |
84 (duration >= base::TimeDelta() && duration != kInfiniteDuration())) | 85 (duration >= base::TimeDelta() && duration != kInfiniteDuration())) |
85 << duration.InSecondsF(); | 86 << duration.InSecondsF(); |
86 duration_ = duration; | 87 duration_ = duration; |
87 } | 88 } |
88 | 89 |
89 const uint8* data() const { | 90 const uint8_t* data() const { |
90 DCHECK(!end_of_stream()); | 91 DCHECK(!end_of_stream()); |
91 return data_.get(); | 92 return data_.get(); |
92 } | 93 } |
93 | 94 |
94 uint8* writable_data() const { | 95 uint8_t* writable_data() const { |
95 DCHECK(!end_of_stream()); | 96 DCHECK(!end_of_stream()); |
96 return data_.get(); | 97 return data_.get(); |
97 } | 98 } |
98 | 99 |
99 // TODO(servolk): data_size should return size_t instead of int | 100 // TODO(servolk): data_size should return size_t instead of int |
100 int data_size() const { | 101 int data_size() const { |
101 DCHECK(!end_of_stream()); | 102 DCHECK(!end_of_stream()); |
102 return size_; | 103 return size_; |
103 } | 104 } |
104 | 105 |
105 const uint8* side_data() const { | 106 const uint8_t* side_data() const { |
106 DCHECK(!end_of_stream()); | 107 DCHECK(!end_of_stream()); |
107 return side_data_.get(); | 108 return side_data_.get(); |
108 } | 109 } |
109 | 110 |
110 // TODO(servolk): side_data_size should return size_t instead of int | 111 // TODO(servolk): side_data_size should return size_t instead of int |
111 int side_data_size() const { | 112 int side_data_size() const { |
112 DCHECK(!end_of_stream()); | 113 DCHECK(!end_of_stream()); |
113 return side_data_size_; | 114 return side_data_size_; |
114 } | 115 } |
115 | 116 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 166 |
166 void set_is_key_frame(bool is_key_frame) { | 167 void set_is_key_frame(bool is_key_frame) { |
167 DCHECK(!end_of_stream()); | 168 DCHECK(!end_of_stream()); |
168 is_key_frame_ = is_key_frame; | 169 is_key_frame_ = is_key_frame; |
169 } | 170 } |
170 | 171 |
171 // Returns a human-readable string describing |*this|. | 172 // Returns a human-readable string describing |*this|. |
172 std::string AsHumanReadableString(); | 173 std::string AsHumanReadableString(); |
173 | 174 |
174 // Replaces any existing side data with data copied from |side_data|. | 175 // Replaces any existing side data with data copied from |side_data|. |
175 void CopySideDataFrom(const uint8* side_data, int side_data_size); | 176 void CopySideDataFrom(const uint8_t* side_data, int side_data_size); |
176 | 177 |
177 protected: | 178 protected: |
178 friend class base::RefCountedThreadSafe<DecoderBuffer>; | 179 friend class base::RefCountedThreadSafe<DecoderBuffer>; |
179 | 180 |
180 // Allocates a buffer of size |size| >= 0 and copies |data| into it. Buffer | 181 // Allocates a buffer of size |size| >= 0 and copies |data| into it. Buffer |
181 // will be padded and aligned as necessary. If |data| is NULL then |data_| is | 182 // will be padded and aligned as necessary. If |data| is NULL then |data_| is |
182 // set to NULL and |buffer_size_| to 0. |is_key_frame_| will default to | 183 // set to NULL and |buffer_size_| to 0. |is_key_frame_| will default to |
183 // false. | 184 // false. |
184 DecoderBuffer(const uint8* data, int size, | 185 DecoderBuffer(const uint8_t* data, |
185 const uint8* side_data, int side_data_size); | 186 int size, |
| 187 const uint8_t* side_data, |
| 188 int side_data_size); |
186 virtual ~DecoderBuffer(); | 189 virtual ~DecoderBuffer(); |
187 | 190 |
188 private: | 191 private: |
189 base::TimeDelta timestamp_; | 192 base::TimeDelta timestamp_; |
190 base::TimeDelta duration_; | 193 base::TimeDelta duration_; |
191 | 194 |
192 // TODO(servolk): Consider changing size_/side_data_size_ types to size_t. | 195 // TODO(servolk): Consider changing size_/side_data_size_ types to size_t. |
193 int size_; | 196 int size_; |
194 scoped_ptr<uint8, base::AlignedFreeDeleter> data_; | 197 scoped_ptr<uint8_t, base::AlignedFreeDeleter> data_; |
195 int side_data_size_; | 198 int side_data_size_; |
196 scoped_ptr<uint8, base::AlignedFreeDeleter> side_data_; | 199 scoped_ptr<uint8_t, base::AlignedFreeDeleter> side_data_; |
197 scoped_ptr<DecryptConfig> decrypt_config_; | 200 scoped_ptr<DecryptConfig> decrypt_config_; |
198 DiscardPadding discard_padding_; | 201 DiscardPadding discard_padding_; |
199 base::TimeDelta splice_timestamp_; | 202 base::TimeDelta splice_timestamp_; |
200 bool is_key_frame_; | 203 bool is_key_frame_; |
201 | 204 |
202 // Constructor helper method for memory allocations. | 205 // Constructor helper method for memory allocations. |
203 void Initialize(); | 206 void Initialize(); |
204 | 207 |
205 DISALLOW_COPY_AND_ASSIGN(DecoderBuffer); | 208 DISALLOW_COPY_AND_ASSIGN(DecoderBuffer); |
206 }; | 209 }; |
207 | 210 |
208 } // namespace media | 211 } // namespace media |
209 | 212 |
210 #endif // MEDIA_BASE_DECODER_BUFFER_H_ | 213 #endif // MEDIA_BASE_DECODER_BUFFER_H_ |
OLD | NEW |