| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 169 |
| 170 // Return the number of ms that have been played so far. | 170 // Return the number of ms that have been played so far. |
| 171 uint32_t PlayoutPositionMs(); | 171 uint32_t PlayoutPositionMs(); |
| 172 | 172 |
| 173 // Update codecInst according to the current audio codec being used for | 173 // Update codecInst according to the current audio codec being used for |
| 174 // reading or writing. | 174 // reading or writing. |
| 175 int32_t codec_info(CodecInst& codecInst); | 175 int32_t codec_info(CodecInst& codecInst); |
| 176 | 176 |
| 177 private: | 177 private: |
| 178 // Biggest WAV frame supported is 10 ms at 48kHz of 2 channel, 16 bit audio. | 178 // Biggest WAV frame supported is 10 ms at 48kHz of 2 channel, 16 bit audio. |
| 179 enum{WAV_MAX_BUFFER_SIZE = 480*2*2}; | 179 static const size_t WAV_MAX_BUFFER_SIZE = 480 * 2 * 2; |
| 180 | 180 |
| 181 | 181 |
| 182 int32_t InitWavCodec(uint32_t samplesPerSec, | 182 int32_t InitWavCodec(uint32_t samplesPerSec, |
| 183 uint32_t channels, | 183 uint32_t channels, |
| 184 uint32_t bitsPerSample, | 184 uint32_t bitsPerSample, |
| 185 uint32_t formatTag); | 185 uint32_t formatTag); |
| 186 | 186 |
| 187 // Parse the WAV header in stream. | 187 // Parse the WAV header in stream. |
| 188 int32_t ReadWavHeader(InStream& stream); | 188 int32_t ReadWavHeader(InStream& stream); |
| 189 | 189 |
| 190 // Update the WAV header. freqInHz, bytesPerSample, channels, format, | 190 // Update the WAV header. freqInHz, bytesPerSample, channels, format, |
| 191 // lengthInBytes specify characterists of the audio data. | 191 // lengthInBytes specify characterists of the audio data. |
| 192 // freqInHz is the sampling frequency. bytesPerSample is the sample size in | 192 // freqInHz is the sampling frequency. bytesPerSample is the sample size in |
| 193 // bytes. channels is the number of channels, e.g. 1 is mono and 2 is | 193 // bytes. channels is the number of channels, e.g. 1 is mono and 2 is |
| 194 // stereo. format is the encode format (e.g. PCMU, PCMA, PCM etc). | 194 // stereo. format is the encode format (e.g. PCMU, PCMA, PCM etc). |
| 195 // lengthInBytes is the number of bytes the audio samples are using up. | 195 // lengthInBytes is the number of bytes the audio samples are using up. |
| 196 int32_t WriteWavHeader(OutStream& stream, | 196 int32_t WriteWavHeader(OutStream& stream, |
| 197 const uint32_t freqInHz, | 197 uint32_t freqInHz, |
| 198 const uint32_t bytesPerSample, | 198 size_t bytesPerSample, |
| 199 const uint32_t channels, | 199 uint32_t channels, |
| 200 const uint32_t format, | 200 uint32_t format, |
| 201 const uint32_t lengthInBytes); | 201 size_t lengthInBytes); |
| 202 | 202 |
| 203 // Put dataLengthInBytes of audio data from stream into the audioBuffer. | 203 // Put dataLengthInBytes of audio data from stream into the audioBuffer. |
| 204 // The return value is the number of bytes written to audioBuffer. | 204 // The return value is the number of bytes written to audioBuffer. |
| 205 int32_t ReadWavData(InStream& stream, uint8_t* audioBuffer, | 205 int32_t ReadWavData(InStream& stream, uint8_t* audioBuffer, |
| 206 const uint32_t dataLengthInBytes); | 206 size_t dataLengthInBytes); |
| 207 | 207 |
| 208 // Update the current audio codec being used for reading or writing | 208 // Update the current audio codec being used for reading or writing |
| 209 // according to codecInst. | 209 // according to codecInst. |
| 210 int32_t set_codec_info(const CodecInst& codecInst); | 210 int32_t set_codec_info(const CodecInst& codecInst); |
| 211 | 211 |
| 212 struct WAVE_FMTINFO_header | 212 struct WAVE_FMTINFO_header |
| 213 { | 213 { |
| 214 int16_t formatTag; | 214 int16_t formatTag; |
| 215 int16_t nChannels; | 215 int16_t nChannels; |
| 216 int32_t nSamplesPerSec; | 216 int32_t nSamplesPerSec; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 247 kCodecG726_32, | 247 kCodecG726_32, |
| 248 kCodecG726_24, | 248 kCodecG726_24, |
| 249 kCodecG726_16, | 249 kCodecG726_16, |
| 250 kCodecSpeex8Khz, | 250 kCodecSpeex8Khz, |
| 251 kCodecSpeex16Khz | 251 kCodecSpeex16Khz |
| 252 }; | 252 }; |
| 253 | 253 |
| 254 // TODO (hellner): why store multiple formats. Just store either codec_info_ | 254 // TODO (hellner): why store multiple formats. Just store either codec_info_ |
| 255 // or _wavFormatObj and supply conversion functions. | 255 // or _wavFormatObj and supply conversion functions. |
| 256 WAVE_FMTINFO_header _wavFormatObj; | 256 WAVE_FMTINFO_header _wavFormatObj; |
| 257 int32_t _dataSize; // Chunk size if reading a WAV file | 257 size_t _dataSize; // Chunk size if reading a WAV file |
| 258 // Number of bytes to read. I.e. frame size in bytes. May be multiple | 258 // Number of bytes to read. I.e. frame size in bytes. May be multiple |
| 259 // chunks if reading WAV. | 259 // chunks if reading WAV. |
| 260 int32_t _readSizeBytes; | 260 size_t _readSizeBytes; |
| 261 | 261 |
| 262 int32_t _id; | 262 int32_t _id; |
| 263 | 263 |
| 264 uint32_t _stopPointInMs; | 264 uint32_t _stopPointInMs; |
| 265 uint32_t _startPointInMs; | 265 uint32_t _startPointInMs; |
| 266 uint32_t _playoutPositionMs; | 266 uint32_t _playoutPositionMs; |
| 267 size_t _bytesWritten; | 267 size_t _bytesWritten; |
| 268 | 268 |
| 269 CodecInst codec_info_; | 269 CodecInst codec_info_; |
| 270 MediaFileUtility_CodecType _codecId; | 270 MediaFileUtility_CodecType _codecId; |
| 271 | 271 |
| 272 // The amount of bytes, on average, used for one audio sample. | 272 // The amount of bytes, on average, used for one audio sample. |
| 273 int32_t _bytesPerSample; | 273 size_t _bytesPerSample; |
| 274 int32_t _readPos; | 274 size_t _readPos; |
| 275 | 275 |
| 276 // Only reading or writing can be enabled, not both. | 276 // Only reading or writing can be enabled, not both. |
| 277 bool _reading; | 277 bool _reading; |
| 278 bool _writing; | 278 bool _writing; |
| 279 | 279 |
| 280 // Scratch buffer used for turning stereo audio to mono. | 280 // Scratch buffer used for turning stereo audio to mono. |
| 281 uint8_t _tempData[WAV_MAX_BUFFER_SIZE]; | 281 uint8_t _tempData[WAV_MAX_BUFFER_SIZE]; |
| 282 }; | 282 }; |
| 283 } // namespace webrtc | 283 } // namespace webrtc |
| 284 #endif // WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_UTILITY_H_ | 284 #endif // WEBRTC_MODULES_MEDIA_FILE_MEDIA_FILE_UTILITY_H_ |
| OLD | NEW |