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_DATA_BUFFER_H_ | 5 #ifndef MEDIA_BASE_DATA_BUFFER_H_ |
6 #define MEDIA_BASE_DATA_BUFFER_H_ | 6 #define MEDIA_BASE_DATA_BUFFER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
| 11 |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "media/base/media_export.h" | 16 #include "media/base/media_export.h" |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 | 19 |
19 // A simple buffer that takes ownership of the given data pointer or allocates | 20 // A simple buffer that takes ownership of the given data pointer or allocates |
20 // as necessary. | 21 // as necessary. |
21 // | 22 // |
22 // Unlike DecoderBuffer, allocations are assumed to be allocated with the | 23 // Unlike DecoderBuffer, allocations are assumed to be allocated with the |
23 // default memory allocator (i.e., new uint8_t[]). | 24 // default memory allocator (i.e., new uint8_t[]). |
24 // | 25 // |
25 // NOTE: It is illegal to call any method when end_of_stream() is true. | 26 // NOTE: It is illegal to call any method when end_of_stream() is true. |
26 class MEDIA_EXPORT DataBuffer : public base::RefCountedThreadSafe<DataBuffer> { | 27 class MEDIA_EXPORT DataBuffer : public base::RefCountedThreadSafe<DataBuffer> { |
27 public: | 28 public: |
28 // Allocates buffer of size |buffer_size| >= 0. | 29 // Allocates buffer of size |buffer_size| >= 0. |
29 explicit DataBuffer(int buffer_size); | 30 explicit DataBuffer(int buffer_size); |
30 | 31 |
31 // Assumes valid data of size |buffer_size|. | 32 // Assumes valid data of size |buffer_size|. |
32 DataBuffer(scoped_ptr<uint8_t[]> buffer, int buffer_size); | 33 DataBuffer(std::unique_ptr<uint8_t[]> buffer, int buffer_size); |
33 | 34 |
34 // Create a DataBuffer whose |data_| is copied from |data|. | 35 // Create a DataBuffer whose |data_| is copied from |data|. |
35 // | 36 // |
36 // |data| must not be null and |size| must be >= 0. | 37 // |data| must not be null and |size| must be >= 0. |
37 static scoped_refptr<DataBuffer> CopyFrom(const uint8_t* data, int size); | 38 static scoped_refptr<DataBuffer> CopyFrom(const uint8_t* data, int size); |
38 | 39 |
39 // Create a DataBuffer indicating we've reached end of stream. | 40 // Create a DataBuffer indicating we've reached end of stream. |
40 // | 41 // |
41 // Calling any method other than end_of_stream() on the resulting buffer | 42 // Calling any method other than end_of_stream() on the resulting buffer |
42 // is disallowed. | 43 // is disallowed. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // | 98 // |
98 // If |data| is null an end of stream buffer is created. | 99 // If |data| is null an end of stream buffer is created. |
99 DataBuffer(const uint8_t* data, int data_size); | 100 DataBuffer(const uint8_t* data, int data_size); |
100 | 101 |
101 virtual ~DataBuffer(); | 102 virtual ~DataBuffer(); |
102 | 103 |
103 private: | 104 private: |
104 base::TimeDelta timestamp_; | 105 base::TimeDelta timestamp_; |
105 base::TimeDelta duration_; | 106 base::TimeDelta duration_; |
106 | 107 |
107 scoped_ptr<uint8_t[]> data_; | 108 std::unique_ptr<uint8_t[]> data_; |
108 int buffer_size_; | 109 int buffer_size_; |
109 int data_size_; | 110 int data_size_; |
110 | 111 |
111 DISALLOW_COPY_AND_ASSIGN(DataBuffer); | 112 DISALLOW_COPY_AND_ASSIGN(DataBuffer); |
112 }; | 113 }; |
113 | 114 |
114 } // namespace media | 115 } // namespace media |
115 | 116 |
116 #endif // MEDIA_BASE_DATA_BUFFER_H_ | 117 #endif // MEDIA_BASE_DATA_BUFFER_H_ |
OLD | NEW |