| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // Create an AudioBuffer whose channel data is copied from |data|. For | 43 // Create an AudioBuffer whose channel data is copied from |data|. For |
| 44 // interleaved data, only the first buffer is used. For planar data, the | 44 // interleaved data, only the first buffer is used. For planar data, the |
| 45 // number of buffers must be equal to |channel_count|. |frame_count| is the | 45 // number of buffers must be equal to |channel_count|. |frame_count| is the |
| 46 // number of frames in each buffer. |data| must not be null and |frame_count| | 46 // number of frames in each buffer. |data| must not be null and |frame_count| |
| 47 // must be >= 0. | 47 // must be >= 0. |
| 48 static scoped_refptr<AudioBuffer> CopyFrom(SampleFormat sample_format, | 48 static scoped_refptr<AudioBuffer> CopyFrom(SampleFormat sample_format, |
| 49 ChannelLayout channel_layout, | 49 ChannelLayout channel_layout, |
| 50 int channel_count, | 50 int channel_count, |
| 51 int sample_rate, | 51 int sample_rate, |
| 52 int frame_count, | 52 int frame_count, |
| 53 const uint8* const* data, | 53 const uint8_t* const* data, |
| 54 const base::TimeDelta timestamp); | 54 const base::TimeDelta timestamp); |
| 55 | 55 |
| 56 // Create an AudioBuffer with |frame_count| frames. Buffer is allocated, but | 56 // Create an AudioBuffer with |frame_count| frames. Buffer is allocated, but |
| 57 // not initialized. Timestamp and duration are set to kNoTimestamp(). | 57 // not initialized. Timestamp and duration are set to kNoTimestamp(). |
| 58 static scoped_refptr<AudioBuffer> CreateBuffer(SampleFormat sample_format, | 58 static scoped_refptr<AudioBuffer> CreateBuffer(SampleFormat sample_format, |
| 59 ChannelLayout channel_layout, | 59 ChannelLayout channel_layout, |
| 60 int channel_count, | 60 int channel_count, |
| 61 int sample_rate, | 61 int sample_rate, |
| 62 int frame_count); | 62 int frame_count); |
| 63 | 63 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 79 // first. |dest_frame_offset| is the frame offset in |dest|. The frames are | 79 // first. |dest_frame_offset| is the frame offset in |dest|. The frames are |
| 80 // converted from their source format into planar float32 data (which is all | 80 // converted from their source format into planar float32 data (which is all |
| 81 // that AudioBus handles). | 81 // that AudioBus handles). |
| 82 void ReadFrames(int frames_to_copy, | 82 void ReadFrames(int frames_to_copy, |
| 83 int source_frame_offset, | 83 int source_frame_offset, |
| 84 int dest_frame_offset, | 84 int dest_frame_offset, |
| 85 AudioBus* dest); | 85 AudioBus* dest); |
| 86 | 86 |
| 87 // Copy |frames_to_copy| frames into |dest|, |frames_to_copy| is the number of | 87 // Copy |frames_to_copy| frames into |dest|, |frames_to_copy| is the number of |
| 88 // frames to copy. The frames are converted from their source format into | 88 // frames to copy. The frames are converted from their source format into |
| 89 // interleaved int32. | 89 // interleaved int32_t. |
| 90 void ReadFramesInterleavedS32(int frames_to_copy, int32* dest); | 90 void ReadFramesInterleavedS32(int frames_to_copy, int32_t* dest); |
| 91 | 91 |
| 92 // Copy |frames_to_copy| frames into |dest|, |frames_to_copy| is the number of | 92 // Copy |frames_to_copy| frames into |dest|, |frames_to_copy| is the number of |
| 93 // frames to copy. The frames are converted from their source format into | 93 // frames to copy. The frames are converted from their source format into |
| 94 // interleaved int16. | 94 // interleaved int16_t. |
| 95 void ReadFramesInterleavedS16(int frames_to_copy, int16* dest); | 95 void ReadFramesInterleavedS16(int frames_to_copy, int16_t* dest); |
| 96 | 96 |
| 97 // Trim an AudioBuffer by removing |frames_to_trim| frames from the start. | 97 // Trim an AudioBuffer by removing |frames_to_trim| frames from the start. |
| 98 // Timestamp and duration are adjusted to reflect the fewer frames. | 98 // Timestamp and duration are adjusted to reflect the fewer frames. |
| 99 // Note that repeated calls to TrimStart() may result in timestamp() and | 99 // Note that repeated calls to TrimStart() may result in timestamp() and |
| 100 // duration() being off by a few microseconds due to rounding issues. | 100 // duration() being off by a few microseconds due to rounding issues. |
| 101 void TrimStart(int frames_to_trim); | 101 void TrimStart(int frames_to_trim); |
| 102 | 102 |
| 103 // Trim an AudioBuffer by removing |frames_to_trim| frames from the end. | 103 // Trim an AudioBuffer by removing |frames_to_trim| frames from the end. |
| 104 // Duration is adjusted to reflect the fewer frames. | 104 // Duration is adjusted to reflect the fewer frames. |
| 105 void TrimEnd(int frames_to_trim); | 105 void TrimEnd(int frames_to_trim); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 122 | 122 |
| 123 base::TimeDelta timestamp() const { return timestamp_; } | 123 base::TimeDelta timestamp() const { return timestamp_; } |
| 124 base::TimeDelta duration() const { return duration_; } | 124 base::TimeDelta duration() const { return duration_; } |
| 125 void set_timestamp(base::TimeDelta timestamp) { timestamp_ = timestamp; } | 125 void set_timestamp(base::TimeDelta timestamp) { timestamp_ = timestamp; } |
| 126 | 126 |
| 127 // If there's no data in this buffer, it represents end of stream. | 127 // If there's no data in this buffer, it represents end of stream. |
| 128 bool end_of_stream() const { return end_of_stream_; } | 128 bool end_of_stream() const { return end_of_stream_; } |
| 129 | 129 |
| 130 // Access to the raw buffer for ffmpeg to write directly to. Data for planar | 130 // Access to the raw buffer for ffmpeg to write directly to. Data for planar |
| 131 // data is grouped by channel. There is only 1 entry for interleaved formats. | 131 // data is grouped by channel. There is only 1 entry for interleaved formats. |
| 132 const std::vector<uint8*>& channel_data() const { return channel_data_; } | 132 const std::vector<uint8_t*>& channel_data() const { return channel_data_; } |
| 133 | 133 |
| 134 private: | 134 private: |
| 135 friend class base::RefCountedThreadSafe<AudioBuffer>; | 135 friend class base::RefCountedThreadSafe<AudioBuffer>; |
| 136 | 136 |
| 137 // mojo::TypeConverter added as a friend so that AudioBuffer can be | 137 // mojo::TypeConverter added as a friend so that AudioBuffer can be |
| 138 // transferred across a mojo connection. | 138 // transferred across a mojo connection. |
| 139 friend struct mojo::TypeConverter<mojo::StructPtr<interfaces::AudioBuffer>, | 139 friend struct mojo::TypeConverter<mojo::StructPtr<interfaces::AudioBuffer>, |
| 140 scoped_refptr<AudioBuffer>>; | 140 scoped_refptr<AudioBuffer>>; |
| 141 | 141 |
| 142 // Allocates aligned contiguous buffer to hold all channel data (1 block for | 142 // Allocates aligned contiguous buffer to hold all channel data (1 block for |
| 143 // interleaved data, |channel_count| blocks for planar data), copies | 143 // interleaved data, |channel_count| blocks for planar data), copies |
| 144 // [data,data+data_size) to the allocated buffer(s). If |data| is null, no | 144 // [data,data+data_size) to the allocated buffer(s). If |data| is null, no |
| 145 // data is copied. If |create_buffer| is false, no data buffer is created (or | 145 // data is copied. If |create_buffer| is false, no data buffer is created (or |
| 146 // copied to). | 146 // copied to). |
| 147 AudioBuffer(SampleFormat sample_format, | 147 AudioBuffer(SampleFormat sample_format, |
| 148 ChannelLayout channel_layout, | 148 ChannelLayout channel_layout, |
| 149 int channel_count, | 149 int channel_count, |
| 150 int sample_rate, | 150 int sample_rate, |
| 151 int frame_count, | 151 int frame_count, |
| 152 bool create_buffer, | 152 bool create_buffer, |
| 153 const uint8* const* data, | 153 const uint8_t* const* data, |
| 154 const base::TimeDelta timestamp); | 154 const base::TimeDelta timestamp); |
| 155 | 155 |
| 156 virtual ~AudioBuffer(); | 156 virtual ~AudioBuffer(); |
| 157 | 157 |
| 158 const SampleFormat sample_format_; | 158 const SampleFormat sample_format_; |
| 159 const ChannelLayout channel_layout_; | 159 const ChannelLayout channel_layout_; |
| 160 const int channel_count_; | 160 const int channel_count_; |
| 161 const int sample_rate_; | 161 const int sample_rate_; |
| 162 int adjusted_frame_count_; | 162 int adjusted_frame_count_; |
| 163 int trim_start_; | 163 int trim_start_; |
| 164 const bool end_of_stream_; | 164 const bool end_of_stream_; |
| 165 base::TimeDelta timestamp_; | 165 base::TimeDelta timestamp_; |
| 166 base::TimeDelta duration_; | 166 base::TimeDelta duration_; |
| 167 | 167 |
| 168 // Contiguous block of channel data. | 168 // Contiguous block of channel data. |
| 169 scoped_ptr<uint8, base::AlignedFreeDeleter> data_; | 169 scoped_ptr<uint8_t, base::AlignedFreeDeleter> data_; |
| 170 size_t data_size_; | 170 size_t data_size_; |
| 171 | 171 |
| 172 // For planar data, points to each channels data. | 172 // For planar data, points to each channels data. |
| 173 std::vector<uint8*> channel_data_; | 173 std::vector<uint8_t*> channel_data_; |
| 174 | 174 |
| 175 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioBuffer); | 175 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioBuffer); |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 } // namespace media | 178 } // namespace media |
| 179 | 179 |
| 180 #endif // MEDIA_BASE_AUDIO_BUFFER_H_ | 180 #endif // MEDIA_BASE_AUDIO_BUFFER_H_ |
| OLD | NEW |