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

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: Refactor DataBuffer Created 7 years, 6 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
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/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 is_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> copy_from(const uint8* data, int size);
scherkus (not reviewing) 2013/06/20 21:29:13 ditto w/ changing too much -- this should be rever
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 is_end_of_stream() on the resulting buffer
38 // is disallowed. 38 // is disallowed.
39 static scoped_refptr<DataBuffer> CreateEOSBuffer(); 39 static scoped_refptr<DataBuffer> create_eos_buffer();
scherkus (not reviewing) 2013/06/20 21:29:13 ditto
40 40
41 base::TimeDelta GetTimestamp() const; 41 base::TimeDelta get_timestamp() const;
scherkus (not reviewing) 2013/06/20 21:29:13 drop get_ prefixes from these setters
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 get_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* get_data() const;
48 uint8* GetWritableData(); 48 uint8* get_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 get_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 is_end_of_stream() const;
scherkus (not reviewing) 2013/06/20 21:29:13 drop is_ prefix
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698