OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_AUDIO_BUFFER_H_ | 5 #ifndef MEDIA_BASE_AUDIO_BUFFER_H_ |
6 #define MEDIA_BASE_AUDIO_BUFFER_H_ | 6 #define MEDIA_BASE_AUDIO_BUFFER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // Alignment of each channel's data; this must match what ffmpeg expects | 27 // Alignment of each channel's data; this must match what ffmpeg expects |
28 // (which may be 0, 16, or 32, depending on the processor). Selecting 32 in | 28 // (which may be 0, 16, or 32, depending on the processor). Selecting 32 in |
29 // order to work on all processors. | 29 // order to work on all processors. |
30 enum { kChannelAlignment = 32 }; | 30 enum { kChannelAlignment = 32 }; |
31 | 31 |
32 // Create an AudioBuffer whose channel data is copied from |data|. For | 32 // Create an AudioBuffer whose channel data is copied from |data|. For |
33 // interleaved data, only the first buffer is used. For planar data, the | 33 // interleaved data, only the first buffer is used. For planar data, the |
34 // number of buffers must be equal to |channel_count|. |frame_count| is the | 34 // number of buffers must be equal to |channel_count|. |frame_count| is the |
35 // number of frames in each buffer. |data| must not be null and |frame_count| | 35 // number of frames in each buffer. |data| must not be null and |frame_count| |
36 // must be >= 0. | 36 // must be >= 0. |
| 37 // |
| 38 // TODO(jrummell): Compute duration rather than pass it in. |
37 static scoped_refptr<AudioBuffer> CopyFrom(SampleFormat sample_format, | 39 static scoped_refptr<AudioBuffer> CopyFrom(SampleFormat sample_format, |
38 ChannelLayout channel_layout, | 40 ChannelLayout channel_layout, |
39 int channel_count, | 41 int channel_count, |
40 int sample_rate, | 42 int sample_rate, |
41 int frame_count, | 43 int frame_count, |
42 const uint8* const* data, | 44 const uint8* const* data, |
43 const base::TimeDelta timestamp); | 45 const base::TimeDelta timestamp, |
| 46 const base::TimeDelta duration); |
44 | 47 |
45 // Create an AudioBuffer with |frame_count| frames. Buffer is allocated, but | 48 // Create an AudioBuffer with |frame_count| frames. Buffer is allocated, but |
46 // not initialized. Timestamp and duration are set to kNoTimestamp(). | 49 // not initialized. Timestamp and duration are set to kNoTimestamp(). |
47 static scoped_refptr<AudioBuffer> CreateBuffer(SampleFormat sample_format, | 50 static scoped_refptr<AudioBuffer> CreateBuffer(SampleFormat sample_format, |
48 ChannelLayout channel_layout, | 51 ChannelLayout channel_layout, |
49 int channel_count, | 52 int channel_count, |
50 int sample_rate, | 53 int sample_rate, |
51 int frame_count); | 54 int frame_count); |
52 | 55 |
53 // Create an empty AudioBuffer with |frame_count| frames. | 56 // Create an empty AudioBuffer with |frame_count| frames. |
54 static scoped_refptr<AudioBuffer> CreateEmptyBuffer( | 57 static scoped_refptr<AudioBuffer> CreateEmptyBuffer( |
55 ChannelLayout channel_layout, | 58 ChannelLayout channel_layout, |
56 int channel_count, | 59 int channel_count, |
57 int sample_rate, | 60 int sample_rate, |
58 int frame_count, | 61 int frame_count, |
59 const base::TimeDelta timestamp); | 62 const base::TimeDelta timestamp, |
| 63 const base::TimeDelta duration); |
60 | 64 |
61 // Create a AudioBuffer indicating we've reached end of stream. | 65 // Create a AudioBuffer indicating we've reached end of stream. |
62 // Calling any method other than end_of_stream() on the resulting buffer | 66 // Calling any method other than end_of_stream() on the resulting buffer |
63 // is disallowed. | 67 // is disallowed. |
64 static scoped_refptr<AudioBuffer> CreateEOSBuffer(); | 68 static scoped_refptr<AudioBuffer> CreateEOSBuffer(); |
65 | 69 |
66 // Copy frames into |dest|. |frames_to_copy| is the number of frames to copy. | 70 // Copy frames into |dest|. |frames_to_copy| is the number of frames to copy. |
67 // |source_frame_offset| specifies how many frames in the buffer to skip | 71 // |source_frame_offset| specifies how many frames in the buffer to skip |
68 // first. |dest_frame_offset| is the frame offset in |dest|. The frames are | 72 // first. |dest_frame_offset| is the frame offset in |dest|. The frames are |
69 // converted from their source format into planar float32 data (which is all | 73 // converted from their source format into planar float32 data (which is all |
(...skipping 21 matching lines...) Expand all Loading... |
91 | 95 |
92 // Return the sample rate. | 96 // Return the sample rate. |
93 int sample_rate() const { return sample_rate_; } | 97 int sample_rate() const { return sample_rate_; } |
94 | 98 |
95 // Return the channel layout. | 99 // Return the channel layout. |
96 ChannelLayout channel_layout() const { return channel_layout_; } | 100 ChannelLayout channel_layout() const { return channel_layout_; } |
97 | 101 |
98 base::TimeDelta timestamp() const { return timestamp_; } | 102 base::TimeDelta timestamp() const { return timestamp_; } |
99 base::TimeDelta duration() const { return duration_; } | 103 base::TimeDelta duration() const { return duration_; } |
100 void set_timestamp(base::TimeDelta timestamp) { timestamp_ = timestamp; } | 104 void set_timestamp(base::TimeDelta timestamp) { timestamp_ = timestamp; } |
| 105 void set_duration(base::TimeDelta duration) { duration_ = duration; } |
101 | 106 |
102 // If there's no data in this buffer, it represents end of stream. | 107 // If there's no data in this buffer, it represents end of stream. |
103 bool end_of_stream() const { return end_of_stream_; } | 108 bool end_of_stream() const { return end_of_stream_; } |
104 | 109 |
105 // Access to the raw buffer for ffmpeg to write directly to. Data for planar | 110 // Access to the raw buffer for ffmpeg to write directly to. Data for planar |
106 // data is grouped by channel. There is only 1 entry for interleaved formats. | 111 // data is grouped by channel. There is only 1 entry for interleaved formats. |
107 const std::vector<uint8*>& channel_data() const { return channel_data_; } | 112 const std::vector<uint8*>& channel_data() const { return channel_data_; } |
108 | 113 |
109 private: | 114 private: |
110 friend class base::RefCountedThreadSafe<AudioBuffer>; | 115 friend class base::RefCountedThreadSafe<AudioBuffer>; |
111 | 116 |
112 // Allocates aligned contiguous buffer to hold all channel data (1 block for | 117 // Allocates aligned contiguous buffer to hold all channel data (1 block for |
113 // interleaved data, |channel_count| blocks for planar data), copies | 118 // interleaved data, |channel_count| blocks for planar data), copies |
114 // [data,data+data_size) to the allocated buffer(s). If |data| is null, no | 119 // [data,data+data_size) to the allocated buffer(s). If |data| is null, no |
115 // data is copied. If |create_buffer| is false, no data buffer is created (or | 120 // data is copied. If |create_buffer| is false, no data buffer is created (or |
116 // copied to). | 121 // copied to). |
117 AudioBuffer(SampleFormat sample_format, | 122 AudioBuffer(SampleFormat sample_format, |
118 ChannelLayout channel_layout, | 123 ChannelLayout channel_layout, |
119 int channel_count, | 124 int channel_count, |
120 int sample_rate, | 125 int sample_rate, |
121 int frame_count, | 126 int frame_count, |
122 bool create_buffer, | 127 bool create_buffer, |
123 const uint8* const* data, | 128 const uint8* const* data, |
124 const base::TimeDelta timestamp); | 129 const base::TimeDelta timestamp, |
| 130 const base::TimeDelta duration); |
125 | 131 |
126 virtual ~AudioBuffer(); | 132 virtual ~AudioBuffer(); |
127 | 133 |
128 const SampleFormat sample_format_; | 134 const SampleFormat sample_format_; |
129 const ChannelLayout channel_layout_; | 135 const ChannelLayout channel_layout_; |
130 const int channel_count_; | 136 const int channel_count_; |
131 const int sample_rate_; | 137 const int sample_rate_; |
132 int adjusted_frame_count_; | 138 int adjusted_frame_count_; |
133 int trim_start_; | 139 int trim_start_; |
134 const bool end_of_stream_; | 140 const bool end_of_stream_; |
135 base::TimeDelta timestamp_; | 141 base::TimeDelta timestamp_; |
136 base::TimeDelta duration_; | 142 base::TimeDelta duration_; |
137 | 143 |
138 // Contiguous block of channel data. | 144 // Contiguous block of channel data. |
139 scoped_ptr<uint8, base::AlignedFreeDeleter> data_; | 145 scoped_ptr<uint8, base::AlignedFreeDeleter> data_; |
140 | 146 |
141 // For planar data, points to each channels data. | 147 // For planar data, points to each channels data. |
142 std::vector<uint8*> channel_data_; | 148 std::vector<uint8*> channel_data_; |
143 | 149 |
144 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioBuffer); | 150 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioBuffer); |
145 }; | 151 }; |
146 | 152 |
147 } // namespace media | 153 } // namespace media |
148 | 154 |
149 #endif // MEDIA_BASE_AUDIO_BUFFER_H_ | 155 #endif // MEDIA_BASE_AUDIO_BUFFER_H_ |
OLD | NEW |