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 // A simple implementation of Buffer that takes ownership of the given data | 5 // A simple implementation of Buffer that takes ownership of the given data |
6 // pointer. | 6 // pointer. |
7 // | 7 // |
8 // DataBuffer assumes that memory was allocated with new uint8[]. | 8 // DataBuffer assumes that memory was allocated with new uint8[]. |
9 | 9 |
10 #ifndef MEDIA_BASE_DATA_BUFFER_H_ | 10 #ifndef MEDIA_BASE_DATA_BUFFER_H_ |
11 #define MEDIA_BASE_DATA_BUFFER_H_ | 11 #define MEDIA_BASE_DATA_BUFFER_H_ |
12 | 12 |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "media/base/buffers.h" | 14 #include "media/base/buffers.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 class MEDIA_EXPORT DataBuffer : public Buffer { | 18 class MEDIA_EXPORT DataBuffer : public Buffer { |
19 public: | 19 public: |
20 // Assumes valid data of size |buffer_size|. | 20 // Assumes valid data of size |buffer_size|. |
21 DataBuffer(scoped_array<uint8> buffer, int buffer_size); | 21 DataBuffer(scoped_array<uint8> buffer, int buffer_size); |
22 | 22 |
23 // Allocates buffer of size |buffer_size|. If |buffer_size| is 0, |data_| is | 23 // Allocates buffer of size |buffer_size|. If |buffer_size| is 0, |data_| is |
24 // set to a NULL ptr. | 24 // set to a NULL ptr. |
25 explicit DataBuffer(int buffer_size); | 25 explicit DataBuffer(int buffer_size); |
26 | 26 |
27 // Create a DataBuffer whose |data_| is copied from |data|. | |
28 static scoped_refptr<DataBuffer> CopyFrom(const uint8* data, int size); | |
29 | |
30 // Buffer implementation. | 27 // Buffer implementation. |
31 virtual const uint8* GetData() const OVERRIDE; | 28 virtual const uint8* GetData() const OVERRIDE; |
32 virtual int GetDataSize() const OVERRIDE; | 29 virtual int GetDataSize() const OVERRIDE; |
33 | 30 |
34 // Returns a read-write pointer to the buffer data. | 31 // Returns a read-write pointer to the buffer data. |
35 virtual uint8* GetWritableData(); | 32 virtual uint8* GetWritableData(); |
36 | 33 |
37 // Updates the size of valid data in bytes, which must be less than or equal | 34 // Updates the size of valid data in bytes, which must be less than or equal |
38 // to GetBufferSize(). | 35 // to GetBufferSize(). |
39 virtual void SetDataSize(int data_size); | 36 virtual void SetDataSize(int data_size); |
(...skipping 13 matching lines...) Expand all Loading... |
53 scoped_array<uint8> data_; | 50 scoped_array<uint8> data_; |
54 int buffer_size_; | 51 int buffer_size_; |
55 int data_size_; | 52 int data_size_; |
56 | 53 |
57 DISALLOW_COPY_AND_ASSIGN(DataBuffer); | 54 DISALLOW_COPY_AND_ASSIGN(DataBuffer); |
58 }; | 55 }; |
59 | 56 |
60 } // namespace media | 57 } // namespace media |
61 | 58 |
62 #endif // MEDIA_BASE_DATA_BUFFER_H_ | 59 #endif // MEDIA_BASE_DATA_BUFFER_H_ |
OLD | NEW |