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

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

Issue 17408005: Refactored DecoderBuffer to use unix_hacker_style naming. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@localrefactor
Patch Set: 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/android/media_source_player_unittest.cc ('k') | media/base/decoder_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_DECODER_BUFFER_H_ 5 #ifndef MEDIA_BASE_DECODER_BUFFER_H_
6 #define MEDIA_BASE_DECODER_BUFFER_H_ 6 #define MEDIA_BASE_DECODER_BUFFER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h"
10 #include "base/memory/aligned_memory.h" 11 #include "base/memory/aligned_memory.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "media/base/decrypt_config.h"
15 #include "media/base/media_export.h" 17 #include "media/base/media_export.h"
16 18
17 namespace media { 19 namespace media {
18 20
19 class DecryptConfig;
20
21 // A specialized buffer for interfacing with audio / video decoders. 21 // A specialized buffer for interfacing with audio / video decoders.
22 // 22 //
23 // Specifically ensures that data is aligned and padded as necessary by the 23 // Specifically ensures that data is aligned and padded as necessary by the
24 // underlying decoding framework. On desktop platforms this means memory is 24 // underlying decoding framework. On desktop platforms this means memory is
25 // allocated using FFmpeg with particular alignment and padding requirements. 25 // allocated using FFmpeg with particular alignment and padding requirements.
26 // 26 //
27 // Also includes decoder specific functionality for decryption. 27 // Also includes decoder specific functionality for decryption.
28 // 28 //
29 // NOTE: It is illegal to call any method when IsEndOfStream() is true. 29 // NOTE: It is illegal to call any method when end_of_stream() is true.
30 class MEDIA_EXPORT DecoderBuffer 30 class MEDIA_EXPORT DecoderBuffer
31 : public base::RefCountedThreadSafe<DecoderBuffer> { 31 : public base::RefCountedThreadSafe<DecoderBuffer> {
32 public: 32 public:
33 enum { 33 enum {
34 kPaddingSize = 16, 34 kPaddingSize = 16,
35 #if defined(ARCH_CPU_ARM_FAMILY) 35 #if defined(ARCH_CPU_ARM_FAMILY)
36 kAlignmentSize = 16 36 kAlignmentSize = 16
37 #else 37 #else
38 kAlignmentSize = 32 38 kAlignmentSize = 32
39 #endif 39 #endif
40 }; 40 };
41 41
42 // Allocates buffer with |size| >= 0. Buffer will be padded and aligned 42 // Allocates buffer with |size| >= 0. Buffer will be padded and aligned
43 // as necessary. 43 // as necessary.
44 explicit DecoderBuffer(int size); 44 explicit DecoderBuffer(int size);
45 45
46 // Create a DecoderBuffer whose |data_| is copied from |data|. Buffer will be 46 // Create a DecoderBuffer whose |data_| is copied from |data|. Buffer will be
47 // padded and aligned as necessary. |data| must not be NULL and |size| >= 0. 47 // padded and aligned as necessary. |data| must not be NULL and |size| >= 0.
48 static scoped_refptr<DecoderBuffer> CopyFrom(const uint8* data, int size); 48 static scoped_refptr<DecoderBuffer> CopyFrom(const uint8* data, int size);
49 49
50 // Create a DecoderBuffer whose |data_| is copied from |data| and |side_data_| 50 // Create a DecoderBuffer whose |data_| is copied from |data| and |side_data_|
51 // is copied from |side_data|. Buffers will be padded and aligned as necessary 51 // is copied from |side_data|. Buffers will be padded and aligned as necessary
52 // Data pointers must not be NULL and sizes must be >= 0. 52 // Data pointers must not be NULL and sizes must be >= 0.
53 static scoped_refptr<DecoderBuffer> CopyFrom(const uint8* data, int size, 53 static scoped_refptr<DecoderBuffer> CopyFrom(const uint8* data, int size,
54 const uint8* side_data, 54 const uint8* side_data,
55 int side_data_size); 55 int side_data_size);
56 56
57 // Create a DecoderBuffer indicating we've reached end of stream. 57 // Create a DecoderBuffer indicating we've reached end of stream.
58 // 58 //
59 // Calling any method other than IsEndOfStream() on the resulting buffer 59 // Calling any method other than end_of_stream() on the resulting buffer
60 // is disallowed. 60 // is disallowed.
61 static scoped_refptr<DecoderBuffer> CreateEOSBuffer(); 61 static scoped_refptr<DecoderBuffer> CreateEOSBuffer();
62 62
63 base::TimeDelta GetTimestamp() const; 63 base::TimeDelta timestamp() const {
64 void SetTimestamp(const base::TimeDelta& timestamp); 64 DCHECK(!end_of_stream());
65 return timestamp_;
66 }
65 67
66 base::TimeDelta GetDuration() const; 68 void set_timestamp(const base::TimeDelta& timestamp) {
67 void SetDuration(const base::TimeDelta& duration); 69 DCHECK(!end_of_stream());
70 timestamp_ = timestamp;
71 }
68 72
69 const uint8* GetData() const; 73 base::TimeDelta duration() const {
70 uint8* GetWritableData() const; 74 DCHECK(!end_of_stream());
75 return duration_;
76 }
71 77
72 int GetDataSize() const; 78 void set_duration(const base::TimeDelta& duration) {
79 DCHECK(!end_of_stream());
80 duration_ = duration;
81 }
73 82
74 const uint8* GetSideData() const; 83 const uint8* data() const {
75 int GetSideDataSize() const; 84 DCHECK(!end_of_stream());
85 return data_.get();
86 }
76 87
77 const DecryptConfig* GetDecryptConfig() const; 88 uint8* writable_data() const {
78 void SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config); 89 DCHECK(!end_of_stream());
90 return data_.get();
91 }
92
93 int data_size() const {
94 DCHECK(!end_of_stream());
95 return size_;
96 }
97
98 const uint8* side_data() const {
99 DCHECK(!end_of_stream());
100 return side_data_.get();
101 }
102
103 int side_data_size() const {
104 DCHECK(!end_of_stream());
105 return side_data_size_;
106 }
107
108 const DecryptConfig* decrypt_config() const {
109 DCHECK(!end_of_stream());
110 return decrypt_config_.get();
111 }
112
113 void set_decrypt_config(scoped_ptr<DecryptConfig> decrypt_config) {
114 DCHECK(!end_of_stream());
115 decrypt_config_ = decrypt_config.Pass();
116 }
79 117
80 // If there's no data in this buffer, it represents end of stream. 118 // If there's no data in this buffer, it represents end of stream.
81 bool IsEndOfStream() const; 119 bool end_of_stream() const {
120 return data_ == NULL;
121 }
82 122
83 // Returns a human-readable string describing |*this|. 123 // Returns a human-readable string describing |*this|.
84 std::string AsHumanReadableString(); 124 std::string AsHumanReadableString();
85 125
86 protected: 126 protected:
87 friend class base::RefCountedThreadSafe<DecoderBuffer>; 127 friend class base::RefCountedThreadSafe<DecoderBuffer>;
88 128
89 // Allocates a buffer of size |size| >= 0 and copies |data| into it. Buffer 129 // Allocates a buffer of size |size| >= 0 and copies |data| into it. Buffer
90 // will be padded and aligned as necessary. If |data| is NULL then |data_| is 130 // will be padded and aligned as necessary. If |data| is NULL then |data_| is
91 // set to NULL and |buffer_size_| to 0. 131 // set to NULL and |buffer_size_| to 0.
(...skipping 13 matching lines...) Expand all
105 145
106 // Constructor helper method for memory allocations. 146 // Constructor helper method for memory allocations.
107 void Initialize(); 147 void Initialize();
108 148
109 DISALLOW_COPY_AND_ASSIGN(DecoderBuffer); 149 DISALLOW_COPY_AND_ASSIGN(DecoderBuffer);
110 }; 150 };
111 151
112 } // namespace media 152 } // namespace media
113 153
114 #endif // MEDIA_BASE_DECODER_BUFFER_H_ 154 #endif // MEDIA_BASE_DECODER_BUFFER_H_
OLDNEW
« no previous file with comments | « media/base/android/media_source_player_unittest.cc ('k') | media/base/decoder_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698