| 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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "media/base/media_export.h" | 11 #include "media/base/media_export.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 | 14 |
| 15 // A simple buffer that takes ownership of the given data pointer or allocates | 15 // A simple buffer that takes ownership of the given data pointer or allocates |
| 16 // as necessary. | 16 // as necessary. |
| 17 // | 17 // |
| 18 // Unlike DecoderBuffer, allocations are assumed to be allocated with the | 18 // Unlike DecoderBuffer, allocations are assumed to be allocated with the |
| 19 // default memory allocator (i.e., new uint8[]). | 19 // default memory allocator (i.e., new uint8[]). |
| 20 // | 20 // |
| 21 // NOTE: It is illegal to call any method when IsEndOfStream() is true. | 21 // NOTE: It is illegal to call any method when end_of_stream() is true. |
| 22 class MEDIA_EXPORT DataBuffer : public base::RefCountedThreadSafe<DataBuffer> { | 22 class MEDIA_EXPORT DataBuffer : public base::RefCountedThreadSafe<DataBuffer> { |
| 23 public: | 23 public: |
| 24 // Allocates buffer of size |buffer_size| >= 0. | 24 // Allocates buffer of size |buffer_size| >= 0. |
| 25 explicit DataBuffer(int buffer_size); | 25 explicit DataBuffer(int buffer_size); |
| 26 | 26 |
| 27 // Assumes valid data of size |buffer_size|. | 27 // Assumes valid data of size |buffer_size|. |
| 28 DataBuffer(scoped_ptr<uint8[]> buffer, int buffer_size); | 28 DataBuffer(scoped_ptr<uint8[]> buffer, int buffer_size); |
| 29 | 29 |
| 30 // Create a DataBuffer whose |data_| is copied from |data|. | 30 // Create a DataBuffer whose |data_| is copied from |data|. |
| 31 // | 31 // |
| 32 // |data| must not be null and |size| must be >= 0. | 32 // |data| must not be null and |size| must be >= 0. |
| 33 static scoped_refptr<DataBuffer> CopyFrom(const uint8* data, int size); | 33 static scoped_refptr<DataBuffer> CopyFrom(const uint8* data, int size); |
| 34 | 34 |
| 35 // Create a DataBuffer indicating we've reached end of stream. | 35 // Create a DataBuffer indicating we've reached end of stream. |
| 36 // | 36 // |
| 37 // Calling any method other than IsEndOfStream() on the resulting buffer | 37 // Calling any method other than end_of_stream() on the resulting buffer |
| 38 // is disallowed. | 38 // is disallowed. |
| 39 static scoped_refptr<DataBuffer> CreateEOSBuffer(); | 39 static scoped_refptr<DataBuffer> CreateEOSBuffer(); |
| 40 | 40 |
| 41 base::TimeDelta GetTimestamp() const; | 41 base::TimeDelta timestamp() const; |
| 42 void SetTimestamp(const base::TimeDelta& timestamp); | 42 void set_timestamp(const base::TimeDelta& timestamp); |
| 43 | 43 |
| 44 base::TimeDelta GetDuration() const; | 44 base::TimeDelta duration() const; |
| 45 void SetDuration(const base::TimeDelta& duration); | 45 void set_duration(const base::TimeDelta& duration); |
| 46 | 46 |
| 47 const uint8* GetData() const; | 47 const uint8* data() const; |
| 48 uint8* GetWritableData(); | 48 uint8* writable_data(); |
| 49 | 49 |
| 50 // The size of valid data in bytes. | 50 // The size of valid data in bytes. |
| 51 // | 51 // |
| 52 // Setting this value beyond the buffer size is disallowed. | 52 // Setting this value beyond the buffer size is disallowed. |
| 53 int GetDataSize() const; | 53 int data_size() const; |
| 54 void SetDataSize(int data_size); | 54 void set_data_size(int data_size); |
| 55 | 55 |
| 56 // If there's no data in this buffer, it represents end of stream. | 56 // If there's no data in this buffer, it represents end of stream. |
| 57 bool IsEndOfStream() const; | 57 bool end_of_stream() const; |
| 58 | 58 |
| 59 protected: | 59 protected: |
| 60 friend class base::RefCountedThreadSafe<DataBuffer>; | 60 friend class base::RefCountedThreadSafe<DataBuffer>; |
| 61 | 61 |
| 62 // Allocates buffer of size |data_size|, copies [data,data+data_size) to | 62 // Allocates buffer of size |data_size|, copies [data,data+data_size) to |
| 63 // the allocated buffer and sets data size to |data_size|. | 63 // the allocated buffer and sets data size to |data_size|. |
| 64 // | 64 // |
| 65 // If |data| is null an end of stream buffer is created. | 65 // If |data| is null an end of stream buffer is created. |
| 66 DataBuffer(const uint8* data, int data_size); | 66 DataBuffer(const uint8* data, int data_size); |
| 67 | 67 |
| 68 virtual ~DataBuffer(); | 68 virtual ~DataBuffer(); |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 base::TimeDelta timestamp_; | 71 base::TimeDelta timestamp_; |
| 72 base::TimeDelta duration_; | 72 base::TimeDelta duration_; |
| 73 | 73 |
| 74 scoped_ptr<uint8[]> data_; | 74 scoped_ptr<uint8[]> data_; |
| 75 int buffer_size_; | 75 int buffer_size_; |
| 76 int data_size_; | 76 int data_size_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(DataBuffer); | 78 DISALLOW_COPY_AND_ASSIGN(DataBuffer); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 } // namespace media | 81 } // namespace media |
| 82 | 82 |
| 83 #endif // MEDIA_BASE_DATA_BUFFER_H_ | 83 #endif // MEDIA_BASE_DATA_BUFFER_H_ |
| OLD | NEW |