Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: media/base/data_buffer.h

Issue 17315021: Refactored DataBuffer to use unix_hacker style methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Inlined getters and setters on DataBuffer Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/audio_splicer_unittest.cc ('k') | media/base/data_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h"
8 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "base/time.h" 11 #include "base/time.h"
11 #include "media/base/media_export.h" 12 #include "media/base/media_export.h"
12 13
13 namespace media { 14 namespace media {
14 15
15 // A simple buffer that takes ownership of the given data pointer or allocates 16 // A simple buffer that takes ownership of the given data pointer or allocates
16 // as necessary. 17 // as necessary.
17 // 18 //
18 // Unlike DecoderBuffer, allocations are assumed to be allocated with the 19 // Unlike DecoderBuffer, allocations are assumed to be allocated with the
19 // default memory allocator (i.e., new uint8[]). 20 // default memory allocator (i.e., new uint8[]).
20 // 21 //
21 // NOTE: It is illegal to call any method when IsEndOfStream() is true. 22 // NOTE: It is illegal to call any method when end_of_stream() is true.
22 class MEDIA_EXPORT DataBuffer : public base::RefCountedThreadSafe<DataBuffer> { 23 class MEDIA_EXPORT DataBuffer : public base::RefCountedThreadSafe<DataBuffer> {
23 public: 24 public:
24 // Allocates buffer of size |buffer_size| >= 0. 25 // Allocates buffer of size |buffer_size| >= 0.
25 explicit DataBuffer(int buffer_size); 26 explicit DataBuffer(int buffer_size);
26 27
27 // Assumes valid data of size |buffer_size|. 28 // Assumes valid data of size |buffer_size|.
28 DataBuffer(scoped_ptr<uint8[]> buffer, int buffer_size); 29 DataBuffer(scoped_ptr<uint8[]> buffer, int buffer_size);
29 30
30 // Create a DataBuffer whose |data_| is copied from |data|. 31 // Create a DataBuffer whose |data_| is copied from |data|.
31 // 32 //
32 // |data| must not be null and |size| must be >= 0. 33 // |data| must not be null and |size| must be >= 0.
33 static scoped_refptr<DataBuffer> CopyFrom(const uint8* data, int size); 34 static scoped_refptr<DataBuffer> CopyFrom(const uint8* data, int size);
34 35
35 // Create a DataBuffer indicating we've reached end of stream. 36 // Create a DataBuffer indicating we've reached end of stream.
36 // 37 //
37 // Calling any method other than IsEndOfStream() on the resulting buffer 38 // Calling any method other than end_of_stream() on the resulting buffer
38 // is disallowed. 39 // is disallowed.
39 static scoped_refptr<DataBuffer> CreateEOSBuffer(); 40 static scoped_refptr<DataBuffer> CreateEOSBuffer();
40 41
41 base::TimeDelta GetTimestamp() const; 42 base::TimeDelta timestamp() const {
42 void SetTimestamp(const base::TimeDelta& timestamp); 43 DCHECK(!end_of_stream());
44 return timestamp_;
45 }
43 46
44 base::TimeDelta GetDuration() const; 47 void set_timestamp(const base::TimeDelta& timestamp) {
45 void SetDuration(const base::TimeDelta& duration); 48 DCHECK(!end_of_stream());
49 timestamp_ = timestamp;
50 }
46 51
47 const uint8* GetData() const; 52 base::TimeDelta duration() const {
48 uint8* GetWritableData(); 53 DCHECK(!end_of_stream());
54 return duration_;
55 }
56
57 void set_duration(const base::TimeDelta& duration) {
58 DCHECK(!end_of_stream());
59 duration_ = duration;
60 }
61
62 const uint8* data() const {
63 DCHECK(!end_of_stream());
64 return data_.get();
65 }
66
67 uint8* writable_data() {
68 DCHECK(!end_of_stream());
69 return data_.get();
70 }
49 71
50 // The size of valid data in bytes. 72 // The size of valid data in bytes.
51 // 73 //
52 // Setting this value beyond the buffer size is disallowed. 74 // Setting this value beyond the buffer size is disallowed.
53 int GetDataSize() const; 75 int data_size() const {
54 void SetDataSize(int data_size); 76 DCHECK(!end_of_stream());
77 return data_size_;
78 }
79
80 void set_data_size(int data_size) {
81 DCHECK(!end_of_stream());
82 CHECK_LE(data_size, buffer_size_);
83 data_size_ = data_size;
84 }
55 85
56 // If there's no data in this buffer, it represents end of stream. 86 // If there's no data in this buffer, it represents end of stream.
57 bool IsEndOfStream() const; 87 bool end_of_stream() const { return data_ == NULL; }
58 88
59 protected: 89 protected:
60 friend class base::RefCountedThreadSafe<DataBuffer>; 90 friend class base::RefCountedThreadSafe<DataBuffer>;
61 91
62 // Allocates buffer of size |data_size|, copies [data,data+data_size) to 92 // Allocates buffer of size |data_size|, copies [data,data+data_size) to
63 // the allocated buffer and sets data size to |data_size|. 93 // the allocated buffer and sets data size to |data_size|.
64 // 94 //
65 // If |data| is null an end of stream buffer is created. 95 // If |data| is null an end of stream buffer is created.
66 DataBuffer(const uint8* data, int data_size); 96 DataBuffer(const uint8* data, int data_size);
67 97
68 virtual ~DataBuffer(); 98 virtual ~DataBuffer();
69 99
70 private: 100 private:
71 base::TimeDelta timestamp_; 101 base::TimeDelta timestamp_;
72 base::TimeDelta duration_; 102 base::TimeDelta duration_;
73 103
74 scoped_ptr<uint8[]> data_; 104 scoped_ptr<uint8[]> data_;
75 int buffer_size_; 105 int buffer_size_;
76 int data_size_; 106 int data_size_;
77 107
78 DISALLOW_COPY_AND_ASSIGN(DataBuffer); 108 DISALLOW_COPY_AND_ASSIGN(DataBuffer);
79 }; 109 };
80 110
81 } // namespace media 111 } // namespace media
82 112
83 #endif // MEDIA_BASE_DATA_BUFFER_H_ 113 #endif // MEDIA_BASE_DATA_BUFFER_H_
OLDNEW
« no previous file with comments | « media/base/audio_splicer_unittest.cc ('k') | media/base/data_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698