| 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 20 matching lines...) Expand all Loading... |
| 31 { | 31 { |
| 32 int8_t ckID[4]; | 32 int8_t ckID[4]; |
| 33 int32_t ckSize; | 33 int32_t ckSize; |
| 34 int8_t wave_ckID[4]; | 34 int8_t wave_ckID[4]; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 // First 8 byte of the format chunk. fmt_ckID should be "fmt ". fmt_ckSize is | 37 // First 8 byte of the format chunk. fmt_ckID should be "fmt ". fmt_ckSize is |
| 38 // the chunk size (16, 18 or 40 byte) | 38 // the chunk size (16, 18 or 40 byte) |
| 39 struct WAVE_CHUNK_header | 39 struct WAVE_CHUNK_header |
| 40 { | 40 { |
| 41 int8_t fmt_ckID[4]; | 41 int8_t fmt_ckID[4]; |
| 42 int32_t fmt_ckSize; | 42 uint32_t fmt_ckSize; |
| 43 }; | 43 }; |
| 44 } // unnamed namespace | 44 } // unnamed namespace |
| 45 | 45 |
| 46 namespace webrtc { | 46 namespace webrtc { |
| 47 ModuleFileUtility::ModuleFileUtility(const int32_t id) | 47 ModuleFileUtility::ModuleFileUtility(const int32_t id) |
| 48 : _wavFormatObj(), | 48 : _wavFormatObj(), |
| 49 _dataSize(0), | 49 _dataSize(0), |
| 50 _readSizeBytes(0), | 50 _readSizeBytes(0), |
| 51 _id(id), | 51 _id(id), |
| 52 _stopPointInMs(0), | 52 _stopPointInMs(0), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 "ModuleFileUtility::~ModuleFileUtility()"); | 72 "ModuleFileUtility::~ModuleFileUtility()"); |
| 73 } | 73 } |
| 74 | 74 |
| 75 int32_t ModuleFileUtility::ReadWavHeader(InStream& wav) | 75 int32_t ModuleFileUtility::ReadWavHeader(InStream& wav) |
| 76 { | 76 { |
| 77 WAVE_RIFF_header RIFFheaderObj; | 77 WAVE_RIFF_header RIFFheaderObj; |
| 78 WAVE_CHUNK_header CHUNKheaderObj; | 78 WAVE_CHUNK_header CHUNKheaderObj; |
| 79 // TODO (hellner): tmpStr and tmpStr2 seems unnecessary here. | 79 // TODO (hellner): tmpStr and tmpStr2 seems unnecessary here. |
| 80 char tmpStr[6] = "FOUR"; | 80 char tmpStr[6] = "FOUR"; |
| 81 unsigned char tmpStr2[4]; | 81 unsigned char tmpStr2[4]; |
| 82 int32_t i, len; | 82 size_t i; |
| 83 bool dataFound = false; | 83 bool dataFound = false; |
| 84 bool fmtFound = false; | 84 bool fmtFound = false; |
| 85 int8_t dummyRead; | 85 int8_t dummyRead; |
| 86 | 86 |
| 87 | 87 |
| 88 _dataSize = 0; | 88 _dataSize = 0; |
| 89 len = wav.Read(&RIFFheaderObj, sizeof(WAVE_RIFF_header)); | 89 int len = wav.Read(&RIFFheaderObj, sizeof(WAVE_RIFF_header)); |
| 90 if(len != sizeof(WAVE_RIFF_header)) | 90 if (len != static_cast<int>(sizeof(WAVE_RIFF_header))) |
| 91 { | 91 { |
| 92 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 92 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 93 "Not a wave file (too short)"); | 93 "Not a wave file (too short)"); |
| 94 return -1; | 94 return -1; |
| 95 } | 95 } |
| 96 | 96 |
| 97 for (i = 0; i < 4; i++) | 97 for (i = 0; i < 4; i++) |
| 98 { | 98 { |
| 99 tmpStr[i] = RIFFheaderObj.ckID[i]; | 99 tmpStr[i] = RIFFheaderObj.ckID[i]; |
| 100 } | 100 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 len = wav.Read(&CHUNKheaderObj, sizeof(WAVE_CHUNK_header)); | 118 len = wav.Read(&CHUNKheaderObj, sizeof(WAVE_CHUNK_header)); |
| 119 | 119 |
| 120 // WAVE files are stored in little endian byte order. Make sure that the | 120 // WAVE files are stored in little endian byte order. Make sure that the |
| 121 // data can be read on big endian as well. | 121 // data can be read on big endian as well. |
| 122 // TODO (hellner): little endian to system byte order should be done in | 122 // TODO (hellner): little endian to system byte order should be done in |
| 123 // in a subroutine. | 123 // in a subroutine. |
| 124 memcpy(tmpStr2, &CHUNKheaderObj.fmt_ckSize, 4); | 124 memcpy(tmpStr2, &CHUNKheaderObj.fmt_ckSize, 4); |
| 125 CHUNKheaderObj.fmt_ckSize = | 125 CHUNKheaderObj.fmt_ckSize = |
| 126 (int32_t) ((uint32_t) tmpStr2[0] + | 126 (uint32_t)tmpStr2[0] + (((uint32_t)tmpStr2[1]) << 8) + |
| 127 (((uint32_t)tmpStr2[1])<<8) + | 127 (((uint32_t)tmpStr2[2]) << 16) + (((uint32_t)tmpStr2[3]) << 24); |
| 128 (((uint32_t)tmpStr2[2])<<16) + | |
| 129 (((uint32_t)tmpStr2[3])<<24)); | |
| 130 | 128 |
| 131 memcpy(tmpStr, CHUNKheaderObj.fmt_ckID, 4); | 129 memcpy(tmpStr, CHUNKheaderObj.fmt_ckID, 4); |
| 132 | 130 |
| 133 while ((len == sizeof(WAVE_CHUNK_header)) && (!fmtFound || !dataFound)) | 131 while ((len == static_cast<int>(sizeof(WAVE_CHUNK_header))) && |
| 132 (!fmtFound || !dataFound)) |
| 134 { | 133 { |
| 135 if(strcmp(tmpStr, "fmt ") == 0) | 134 if(strcmp(tmpStr, "fmt ") == 0) |
| 136 { | 135 { |
| 137 len = wav.Read(&_wavFormatObj, sizeof(WAVE_FMTINFO_header)); | 136 len = wav.Read(&_wavFormatObj, sizeof(WAVE_FMTINFO_header)); |
| 138 | 137 |
| 139 memcpy(tmpStr2, &_wavFormatObj.formatTag, 2); | 138 memcpy(tmpStr2, &_wavFormatObj.formatTag, 2); |
| 140 _wavFormatObj.formatTag = | 139 _wavFormatObj.formatTag = |
| 141 (uint32_t)tmpStr2[0] + (((uint32_t)tmpStr2[1])<<8); | 140 (uint32_t)tmpStr2[0] + (((uint32_t)tmpStr2[1])<<8); |
| 142 memcpy(tmpStr2, &_wavFormatObj.nChannels, 2); | 141 memcpy(tmpStr2, &_wavFormatObj.nChannels, 2); |
| 143 _wavFormatObj.nChannels = | 142 _wavFormatObj.nChannels = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 157 (((uint32_t)tmpStr2[3])<<24)); | 156 (((uint32_t)tmpStr2[3])<<24)); |
| 158 memcpy(tmpStr2, &_wavFormatObj.nBlockAlign, 2); | 157 memcpy(tmpStr2, &_wavFormatObj.nBlockAlign, 2); |
| 159 _wavFormatObj.nBlockAlign = | 158 _wavFormatObj.nBlockAlign = |
| 160 (int16_t) ((uint32_t)tmpStr2[0] + | 159 (int16_t) ((uint32_t)tmpStr2[0] + |
| 161 (((uint32_t)tmpStr2[1])<<8)); | 160 (((uint32_t)tmpStr2[1])<<8)); |
| 162 memcpy(tmpStr2, &_wavFormatObj.nBitsPerSample, 2); | 161 memcpy(tmpStr2, &_wavFormatObj.nBitsPerSample, 2); |
| 163 _wavFormatObj.nBitsPerSample = | 162 _wavFormatObj.nBitsPerSample = |
| 164 (int16_t) ((uint32_t)tmpStr2[0] + | 163 (int16_t) ((uint32_t)tmpStr2[0] + |
| 165 (((uint32_t)tmpStr2[1])<<8)); | 164 (((uint32_t)tmpStr2[1])<<8)); |
| 166 | 165 |
| 166 if (CHUNKheaderObj.fmt_ckSize < sizeof(WAVE_FMTINFO_header)) |
| 167 { |
| 168 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 169 "Chunk size is too small"); |
| 170 return -1; |
| 171 } |
| 167 for (i = 0; | 172 for (i = 0; |
| 168 i < (CHUNKheaderObj.fmt_ckSize - | 173 i < CHUNKheaderObj.fmt_ckSize - sizeof(WAVE_FMTINFO_header); |
| 169 (int32_t)sizeof(WAVE_FMTINFO_header)); | |
| 170 i++) | 174 i++) |
| 171 { | 175 { |
| 172 len = wav.Read(&dummyRead, 1); | 176 len = wav.Read(&dummyRead, 1); |
| 173 if(len != 1) | 177 if(len != 1) |
| 174 { | 178 { |
| 175 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 179 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 176 "File corrupted, reached EOF (reading fmt)"); | 180 "File corrupted, reached EOF (reading fmt)"); |
| 177 return -1; | 181 return -1; |
| 178 } | 182 } |
| 179 } | 183 } |
| 180 fmtFound = true; | 184 fmtFound = true; |
| 181 } | 185 } |
| 182 else if(strcmp(tmpStr, "data") == 0) | 186 else if(strcmp(tmpStr, "data") == 0) |
| 183 { | 187 { |
| 184 _dataSize = CHUNKheaderObj.fmt_ckSize; | 188 _dataSize = CHUNKheaderObj.fmt_ckSize; |
| 185 dataFound = true; | 189 dataFound = true; |
| 186 break; | 190 break; |
| 187 } | 191 } |
| 188 else | 192 else |
| 189 { | 193 { |
| 190 for (i = 0; i < (CHUNKheaderObj.fmt_ckSize); i++) | 194 for (i = 0; i < CHUNKheaderObj.fmt_ckSize; i++) |
| 191 { | 195 { |
| 192 len = wav.Read(&dummyRead, 1); | 196 len = wav.Read(&dummyRead, 1); |
| 193 if(len != 1) | 197 if(len != 1) |
| 194 { | 198 { |
| 195 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 199 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 196 "File corrupted, reached EOF (reading other)"); | 200 "File corrupted, reached EOF (reading other)"); |
| 197 return -1; | 201 return -1; |
| 198 } | 202 } |
| 199 } | 203 } |
| 200 } | 204 } |
| 201 | 205 |
| 202 len = wav.Read(&CHUNKheaderObj, sizeof(WAVE_CHUNK_header)); | 206 len = wav.Read(&CHUNKheaderObj, sizeof(WAVE_CHUNK_header)); |
| 203 | 207 |
| 204 memcpy(tmpStr2, &CHUNKheaderObj.fmt_ckSize, 4); | 208 memcpy(tmpStr2, &CHUNKheaderObj.fmt_ckSize, 4); |
| 205 CHUNKheaderObj.fmt_ckSize = | 209 CHUNKheaderObj.fmt_ckSize = |
| 206 (int32_t) ((uint32_t)tmpStr2[0] + | 210 (uint32_t)tmpStr2[0] + (((uint32_t)tmpStr2[1]) << 8) + |
| 207 (((uint32_t)tmpStr2[1])<<8) + | 211 (((uint32_t)tmpStr2[2]) << 16) + (((uint32_t)tmpStr2[3]) << 24); |
| 208 (((uint32_t)tmpStr2[2])<<16) + | |
| 209 (((uint32_t)tmpStr2[3])<<24)); | |
| 210 | 212 |
| 211 memcpy(tmpStr, CHUNKheaderObj.fmt_ckID, 4); | 213 memcpy(tmpStr, CHUNKheaderObj.fmt_ckID, 4); |
| 212 } | 214 } |
| 213 | 215 |
| 214 // Either a proper format chunk has been read or a data chunk was come | 216 // Either a proper format chunk has been read or a data chunk was come |
| 215 // across. | 217 // across. |
| 216 if( (_wavFormatObj.formatTag != kWavFormatPcm) && | 218 if( (_wavFormatObj.formatTag != kWavFormatPcm) && |
| 217 (_wavFormatObj.formatTag != kWavFormatALaw) && | 219 (_wavFormatObj.formatTag != kWavFormatALaw) && |
| 218 (_wavFormatObj.formatTag != kWavFormatMuLaw)) | 220 (_wavFormatObj.formatTag != kWavFormatMuLaw)) |
| 219 { | 221 { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 234 if((_wavFormatObj.nBitsPerSample != 8) && | 236 if((_wavFormatObj.nBitsPerSample != 8) && |
| 235 (_wavFormatObj.nBitsPerSample != 16)) | 237 (_wavFormatObj.nBitsPerSample != 16)) |
| 236 { | 238 { |
| 237 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 239 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 238 "nBitsPerSample value=%d not supported!", | 240 "nBitsPerSample value=%d not supported!", |
| 239 _wavFormatObj.nBitsPerSample); | 241 _wavFormatObj.nBitsPerSample); |
| 240 return -1; | 242 return -1; |
| 241 } | 243 } |
| 242 | 244 |
| 243 // Calculate the number of bytes that 10 ms of audio data correspond to. | 245 // Calculate the number of bytes that 10 ms of audio data correspond to. |
| 244 if(_wavFormatObj.formatTag == kWavFormatPcm) | 246 size_t samples_per_10ms = |
| 245 { | 247 ((_wavFormatObj.formatTag == kWavFormatPcm) && |
| 246 // TODO (hellner): integer division for 22050 and 11025 would yield | 248 (_wavFormatObj.nSamplesPerSec == 44100)) ? |
| 247 // the same result as the else statement. Remove those | 249 440 : static_cast<size_t>(_wavFormatObj.nSamplesPerSec / 100); |
| 248 // special cases? | 250 _readSizeBytes = samples_per_10ms * _wavFormatObj.nChannels * |
| 249 if(_wavFormatObj.nSamplesPerSec == 44100) | 251 (_wavFormatObj.nBitsPerSample / 8); |
| 250 { | |
| 251 _readSizeBytes = 440 * _wavFormatObj.nChannels * | |
| 252 (_wavFormatObj.nBitsPerSample / 8); | |
| 253 } else if(_wavFormatObj.nSamplesPerSec == 22050) { | |
| 254 _readSizeBytes = 220 * _wavFormatObj.nChannels * | |
| 255 (_wavFormatObj.nBitsPerSample / 8); | |
| 256 } else if(_wavFormatObj.nSamplesPerSec == 11025) { | |
| 257 _readSizeBytes = 110 * _wavFormatObj.nChannels * | |
| 258 (_wavFormatObj.nBitsPerSample / 8); | |
| 259 } else { | |
| 260 _readSizeBytes = (_wavFormatObj.nSamplesPerSec/100) * | |
| 261 _wavFormatObj.nChannels * (_wavFormatObj.nBitsPerSample / 8); | |
| 262 } | |
| 263 | |
| 264 } else { | |
| 265 _readSizeBytes = (_wavFormatObj.nSamplesPerSec/100) * | |
| 266 _wavFormatObj.nChannels * (_wavFormatObj.nBitsPerSample / 8); | |
| 267 } | |
| 268 return 0; | 252 return 0; |
| 269 } | 253 } |
| 270 | 254 |
| 271 int32_t ModuleFileUtility::InitWavCodec(uint32_t samplesPerSec, | 255 int32_t ModuleFileUtility::InitWavCodec(uint32_t samplesPerSec, |
| 272 uint32_t channels, | 256 uint32_t channels, |
| 273 uint32_t bitsPerSample, | 257 uint32_t bitsPerSample, |
| 274 uint32_t formatTag) | 258 uint32_t formatTag) |
| 275 { | 259 { |
| 276 codec_info_.pltype = -1; | 260 codec_info_.pltype = -1; |
| 277 codec_info_.plfreq = samplesPerSec; | 261 codec_info_.plfreq = samplesPerSec; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 "failed to read WAV header!"); | 353 "failed to read WAV header!"); |
| 370 return -1; | 354 return -1; |
| 371 } | 355 } |
| 372 | 356 |
| 373 _playoutPositionMs = 0; | 357 _playoutPositionMs = 0; |
| 374 _readPos = 0; | 358 _readPos = 0; |
| 375 | 359 |
| 376 if(start > 0) | 360 if(start > 0) |
| 377 { | 361 { |
| 378 uint8_t dummy[WAV_MAX_BUFFER_SIZE]; | 362 uint8_t dummy[WAV_MAX_BUFFER_SIZE]; |
| 379 int32_t readLength; | 363 int readLength; |
| 380 if(_readSizeBytes <= WAV_MAX_BUFFER_SIZE) | 364 if(_readSizeBytes <= WAV_MAX_BUFFER_SIZE) |
| 381 { | 365 { |
| 382 while (_playoutPositionMs < start) | 366 while (_playoutPositionMs < start) |
| 383 { | 367 { |
| 384 readLength = wav.Read(dummy, _readSizeBytes); | 368 readLength = wav.Read(dummy, _readSizeBytes); |
| 385 if(readLength == _readSizeBytes) | 369 if(readLength == static_cast<int>(_readSizeBytes)) |
| 386 { | 370 { |
| 387 _readPos += readLength; | 371 _readPos += _readSizeBytes; |
| 388 _playoutPositionMs += 10; | 372 _playoutPositionMs += 10; |
| 389 } | 373 } |
| 390 else // Must have reached EOF before start position! | 374 else // Must have reached EOF before start position! |
| 391 { | 375 { |
| 392 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 376 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 393 "InitWavReading(), EOF before start position"); | 377 "InitWavReading(), EOF before start position"); |
| 394 return -1; | 378 return -1; |
| 395 } | 379 } |
| 396 } | 380 } |
| 397 } | 381 } |
| 398 else | 382 else |
| 399 { | 383 { |
| 400 return -1; | 384 return -1; |
| 401 } | 385 } |
| 402 } | 386 } |
| 403 if( InitWavCodec(_wavFormatObj.nSamplesPerSec, _wavFormatObj.nChannels, | 387 if( InitWavCodec(_wavFormatObj.nSamplesPerSec, _wavFormatObj.nChannels, |
| 404 _wavFormatObj.nBitsPerSample, | 388 _wavFormatObj.nBitsPerSample, |
| 405 _wavFormatObj.formatTag) != 0) | 389 _wavFormatObj.formatTag) != 0) |
| 406 { | 390 { |
| 407 return -1; | 391 return -1; |
| 408 } | 392 } |
| 409 _bytesPerSample = _wavFormatObj.nBitsPerSample / 8; | 393 _bytesPerSample = static_cast<size_t>(_wavFormatObj.nBitsPerSample / 8); |
| 410 | 394 |
| 411 | 395 |
| 412 _startPointInMs = start; | 396 _startPointInMs = start; |
| 413 _stopPointInMs = stop; | 397 _stopPointInMs = stop; |
| 414 _reading = true; | 398 _reading = true; |
| 415 return 0; | 399 return 0; |
| 416 } | 400 } |
| 417 | 401 |
| 418 int32_t ModuleFileUtility::ReadWavDataAsMono( | 402 int32_t ModuleFileUtility::ReadWavDataAsMono( |
| 419 InStream& wav, | 403 InStream& wav, |
| 420 int8_t* outData, | 404 int8_t* outData, |
| 421 const size_t bufferSize) | 405 const size_t bufferSize) |
| 422 { | 406 { |
| 423 WEBRTC_TRACE( | 407 WEBRTC_TRACE( |
| 424 kTraceStream, | 408 kTraceStream, |
| 425 kTraceFile, | 409 kTraceFile, |
| 426 _id, | 410 _id, |
| 427 "ModuleFileUtility::ReadWavDataAsMono(wav= 0x%x, outData= 0x%d, " | 411 "ModuleFileUtility::ReadWavDataAsMono(wav= 0x%x, outData= 0x%d, " |
| 428 "bufSize= %" PRIuS ")", | 412 "bufSize= %" PRIuS ")", |
| 429 &wav, | 413 &wav, |
| 430 outData, | 414 outData, |
| 431 bufferSize); | 415 bufferSize); |
| 432 | 416 |
| 433 // The number of bytes that should be read from file. | 417 // The number of bytes that should be read from file. |
| 434 const uint32_t totalBytesNeeded = _readSizeBytes; | 418 const size_t totalBytesNeeded = _readSizeBytes; |
| 435 // The number of bytes that will be written to outData. | 419 // The number of bytes that will be written to outData. |
| 436 const uint32_t bytesRequested = (codec_info_.channels == 2) ? | 420 const size_t bytesRequested = (codec_info_.channels == 2) ? |
| 437 totalBytesNeeded >> 1 : totalBytesNeeded; | 421 totalBytesNeeded >> 1 : totalBytesNeeded; |
| 438 if(bufferSize < bytesRequested) | 422 if(bufferSize < bytesRequested) |
| 439 { | 423 { |
| 440 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 424 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 441 "ReadWavDataAsMono: output buffer is too short!"); | 425 "ReadWavDataAsMono: output buffer is too short!"); |
| 442 return -1; | 426 return -1; |
| 443 } | 427 } |
| 444 if(outData == NULL) | 428 if(outData == NULL) |
| 445 { | 429 { |
| 446 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 430 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 465 } | 449 } |
| 466 if(bytesRead < 0) | 450 if(bytesRead < 0) |
| 467 { | 451 { |
| 468 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 452 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 469 "ReadWavDataAsMono: failed to read data from WAV file."); | 453 "ReadWavDataAsMono: failed to read data from WAV file."); |
| 470 return -1; | 454 return -1; |
| 471 } | 455 } |
| 472 // Output data is should be mono. | 456 // Output data is should be mono. |
| 473 if(codec_info_.channels == 2) | 457 if(codec_info_.channels == 2) |
| 474 { | 458 { |
| 475 for (uint32_t i = 0; i < bytesRequested / _bytesPerSample; i++) | 459 for (size_t i = 0; i < bytesRequested / _bytesPerSample; i++) |
| 476 { | 460 { |
| 477 // Sample value is the average of left and right buffer rounded to | 461 // Sample value is the average of left and right buffer rounded to |
| 478 // closest integer value. Note samples can be either 1 or 2 byte. | 462 // closest integer value. Note samples can be either 1 or 2 byte. |
| 479 if(_bytesPerSample == 1) | 463 if(_bytesPerSample == 1) |
| 480 { | 464 { |
| 481 _tempData[i] = ((_tempData[2 * i] + _tempData[(2 * i) + 1] + | 465 _tempData[i] = ((_tempData[2 * i] + _tempData[(2 * i) + 1] + |
| 482 1) >> 1); | 466 1) >> 1); |
| 483 } | 467 } |
| 484 else | 468 else |
| 485 { | 469 { |
| 486 int16_t* sampleData = (int16_t*) _tempData; | 470 int16_t* sampleData = (int16_t*) _tempData; |
| 487 sampleData[i] = ((sampleData[2 * i] + sampleData[(2 * i) + 1] + | 471 sampleData[i] = ((sampleData[2 * i] + sampleData[(2 * i) + 1] + |
| 488 1) >> 1); | 472 1) >> 1); |
| 489 } | 473 } |
| 490 } | 474 } |
| 491 memcpy(outData, _tempData, bytesRequested); | 475 memcpy(outData, _tempData, bytesRequested); |
| 492 } | 476 } |
| 493 return bytesRequested; | 477 return static_cast<int32_t>(bytesRequested); |
| 494 } | 478 } |
| 495 | 479 |
| 496 int32_t ModuleFileUtility::ReadWavDataAsStereo( | 480 int32_t ModuleFileUtility::ReadWavDataAsStereo( |
| 497 InStream& wav, | 481 InStream& wav, |
| 498 int8_t* outDataLeft, | 482 int8_t* outDataLeft, |
| 499 int8_t* outDataRight, | 483 int8_t* outDataRight, |
| 500 const size_t bufferSize) | 484 const size_t bufferSize) |
| 501 { | 485 { |
| 502 WEBRTC_TRACE( | 486 WEBRTC_TRACE( |
| 503 kTraceStream, | 487 kTraceStream, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 527 return -1; | 511 return -1; |
| 528 } | 512 } |
| 529 if(! _reading) | 513 if(! _reading) |
| 530 { | 514 { |
| 531 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 515 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 532 "ReadWavDataAsStereo: no longer reading file."); | 516 "ReadWavDataAsStereo: no longer reading file."); |
| 533 return -1; | 517 return -1; |
| 534 } | 518 } |
| 535 | 519 |
| 536 // The number of bytes that should be read from file. | 520 // The number of bytes that should be read from file. |
| 537 const uint32_t totalBytesNeeded = _readSizeBytes; | 521 const size_t totalBytesNeeded = _readSizeBytes; |
| 538 // The number of bytes that will be written to the left and the right | 522 // The number of bytes that will be written to the left and the right |
| 539 // buffers. | 523 // buffers. |
| 540 const uint32_t bytesRequested = totalBytesNeeded >> 1; | 524 const size_t bytesRequested = totalBytesNeeded >> 1; |
| 541 if(bufferSize < bytesRequested) | 525 if(bufferSize < bytesRequested) |
| 542 { | 526 { |
| 543 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 527 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 544 "ReadWavData: Output buffers are too short!"); | 528 "ReadWavData: Output buffers are too short!"); |
| 545 assert(false); | 529 assert(false); |
| 546 return -1; | 530 return -1; |
| 547 } | 531 } |
| 548 | 532 |
| 549 int32_t bytesRead = ReadWavData(wav, _tempData, totalBytesNeeded); | 533 int32_t bytesRead = ReadWavData(wav, _tempData, totalBytesNeeded); |
| 550 if(bytesRead <= 0) | 534 if(bytesRead <= 0) |
| 551 { | 535 { |
| 552 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 536 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 553 "ReadWavDataAsStereo: failed to read data from WAV file."); | 537 "ReadWavDataAsStereo: failed to read data from WAV file."); |
| 554 return -1; | 538 return -1; |
| 555 } | 539 } |
| 556 | 540 |
| 557 // Turn interleaved audio to left and right buffer. Note samples can be | 541 // Turn interleaved audio to left and right buffer. Note samples can be |
| 558 // either 1 or 2 bytes | 542 // either 1 or 2 bytes |
| 559 if(_bytesPerSample == 1) | 543 if(_bytesPerSample == 1) |
| 560 { | 544 { |
| 561 for (uint32_t i = 0; i < bytesRequested; i++) | 545 for (size_t i = 0; i < bytesRequested; i++) |
| 562 { | 546 { |
| 563 outDataLeft[i] = _tempData[2 * i]; | 547 outDataLeft[i] = _tempData[2 * i]; |
| 564 outDataRight[i] = _tempData[(2 * i) + 1]; | 548 outDataRight[i] = _tempData[(2 * i) + 1]; |
| 565 } | 549 } |
| 566 } | 550 } |
| 567 else if(_bytesPerSample == 2) | 551 else if(_bytesPerSample == 2) |
| 568 { | 552 { |
| 569 int16_t* sampleData = reinterpret_cast<int16_t*>(_tempData); | 553 int16_t* sampleData = reinterpret_cast<int16_t*>(_tempData); |
| 570 int16_t* outLeft = reinterpret_cast<int16_t*>(outDataLeft); | 554 int16_t* outLeft = reinterpret_cast<int16_t*>(outDataLeft); |
| 571 int16_t* outRight = reinterpret_cast<int16_t*>( | 555 int16_t* outRight = reinterpret_cast<int16_t*>( |
| 572 outDataRight); | 556 outDataRight); |
| 573 | 557 |
| 574 // Bytes requested to samples requested. | 558 // Bytes requested to samples requested. |
| 575 uint32_t sampleCount = bytesRequested >> 1; | 559 size_t sampleCount = bytesRequested >> 1; |
| 576 for (uint32_t i = 0; i < sampleCount; i++) | 560 for (size_t i = 0; i < sampleCount; i++) |
| 577 { | 561 { |
| 578 outLeft[i] = sampleData[2 * i]; | 562 outLeft[i] = sampleData[2 * i]; |
| 579 outRight[i] = sampleData[(2 * i) + 1]; | 563 outRight[i] = sampleData[(2 * i) + 1]; |
| 580 } | 564 } |
| 581 } else { | 565 } else { |
| 582 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 566 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 583 "ReadWavStereoData: unsupported sample size %d!", | 567 "ReadWavStereoData: unsupported sample size %" PRIuS "!", |
| 584 _bytesPerSample); | 568 _bytesPerSample); |
| 585 assert(false); | 569 assert(false); |
| 586 return -1; | 570 return -1; |
| 587 } | 571 } |
| 588 return bytesRequested; | 572 return static_cast<int32_t>(bytesRequested); |
| 589 } | 573 } |
| 590 | 574 |
| 591 int32_t ModuleFileUtility::ReadWavData( | 575 int32_t ModuleFileUtility::ReadWavData(InStream& wav, |
| 592 InStream& wav, | 576 uint8_t* buffer, |
| 593 uint8_t* buffer, | 577 size_t dataLengthInBytes) |
| 594 const uint32_t dataLengthInBytes) | |
| 595 { | 578 { |
| 596 WEBRTC_TRACE( | 579 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
| 597 kTraceStream, | 580 "ModuleFileUtility::ReadWavData(wav= 0x%x, buffer= 0x%x, " |
| 598 kTraceFile, | 581 "dataLen= %" PRIuS ")", &wav, buffer, dataLengthInBytes); |
| 599 _id, | |
| 600 "ModuleFileUtility::ReadWavData(wav= 0x%x, buffer= 0x%x, dataLen= %ld)", | |
| 601 &wav, | |
| 602 buffer, | |
| 603 dataLengthInBytes); | |
| 604 | 582 |
| 605 | 583 |
| 606 if(buffer == NULL) | 584 if(buffer == NULL) |
| 607 { | 585 { |
| 608 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 586 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 609 "ReadWavDataAsMono: output buffer NULL!"); | 587 "ReadWavDataAsMono: output buffer NULL!"); |
| 610 return -1; | 588 return -1; |
| 611 } | 589 } |
| 612 | 590 |
| 613 // Make sure that a read won't return too few samples. | 591 // Make sure that a read won't return too few samples. |
| 614 // TODO (hellner): why not read the remaining bytes needed from the start | 592 // TODO (hellner): why not read the remaining bytes needed from the start |
| 615 // of the file? | 593 // of the file? |
| 616 if((_dataSize - _readPos) < (int32_t)dataLengthInBytes) | 594 if(_dataSize < (_readPos + dataLengthInBytes)) |
| 617 { | 595 { |
| 618 // Rewind() being -1 may be due to the file not supposed to be looped. | 596 // Rewind() being -1 may be due to the file not supposed to be looped. |
| 619 if(wav.Rewind() == -1) | 597 if(wav.Rewind() == -1) |
| 620 { | 598 { |
| 621 _reading = false; | 599 _reading = false; |
| 622 return 0; | 600 return 0; |
| 623 } | 601 } |
| 624 if(InitWavReading(wav, _startPointInMs, _stopPointInMs) == -1) | 602 if(InitWavReading(wav, _startPointInMs, _stopPointInMs) == -1) |
| 625 { | 603 { |
| 626 _reading = false; | 604 _reading = false; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 1 : codecInst.channels; | 667 1 : codecInst.channels; |
| 690 | 668 |
| 691 if(STR_CASE_CMP(codecInst.plname, "PCMU") == 0) | 669 if(STR_CASE_CMP(codecInst.plname, "PCMU") == 0) |
| 692 { | 670 { |
| 693 _bytesPerSample = 1; | 671 _bytesPerSample = 1; |
| 694 if(WriteWavHeader(wav, 8000, _bytesPerSample, channels, | 672 if(WriteWavHeader(wav, 8000, _bytesPerSample, channels, |
| 695 kWavFormatMuLaw, 0) == -1) | 673 kWavFormatMuLaw, 0) == -1) |
| 696 { | 674 { |
| 697 return -1; | 675 return -1; |
| 698 } | 676 } |
| 699 }else if(STR_CASE_CMP(codecInst.plname, "PCMA") == 0) | 677 } |
| 678 else if(STR_CASE_CMP(codecInst.plname, "PCMA") == 0) |
| 700 { | 679 { |
| 701 _bytesPerSample = 1; | 680 _bytesPerSample = 1; |
| 702 if(WriteWavHeader(wav, 8000, _bytesPerSample, channels, kWavFormatALaw, | 681 if(WriteWavHeader(wav, 8000, _bytesPerSample, channels, kWavFormatALaw, |
| 703 0) == -1) | 682 0) == -1) |
| 704 { | 683 { |
| 705 return -1; | 684 return -1; |
| 706 } | 685 } |
| 707 } | 686 } |
| 708 else if(STR_CASE_CMP(codecInst.plname, "L16") == 0) | 687 else if(STR_CASE_CMP(codecInst.plname, "L16") == 0) |
| 709 { | 688 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 722 } | 701 } |
| 723 _writing = true; | 702 _writing = true; |
| 724 _bytesWritten = 0; | 703 _bytesWritten = 0; |
| 725 return 0; | 704 return 0; |
| 726 } | 705 } |
| 727 | 706 |
| 728 int32_t ModuleFileUtility::WriteWavData(OutStream& out, | 707 int32_t ModuleFileUtility::WriteWavData(OutStream& out, |
| 729 const int8_t* buffer, | 708 const int8_t* buffer, |
| 730 const size_t dataLength) | 709 const size_t dataLength) |
| 731 { | 710 { |
| 732 WEBRTC_TRACE( | 711 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
| 733 kTraceStream, | 712 "ModuleFileUtility::WriteWavData(out= 0x%x, buf= 0x%x, " |
| 734 kTraceFile, | 713 "dataLen= %" PRIuS ")", &out, buffer, dataLength); |
| 735 _id, | |
| 736 "ModuleFileUtility::WriteWavData(out= 0x%x, buf= 0x%x, dataLen= %" PRIuS | |
| 737 ")", | |
| 738 &out, | |
| 739 buffer, | |
| 740 dataLength); | |
| 741 | 714 |
| 742 if(buffer == NULL) | 715 if(buffer == NULL) |
| 743 { | 716 { |
| 744 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 717 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 745 "WriteWavData: input buffer NULL!"); | 718 "WriteWavData: input buffer NULL!"); |
| 746 return -1; | 719 return -1; |
| 747 } | 720 } |
| 748 | 721 |
| 749 if(!out.Write(buffer, dataLength)) | 722 if(!out.Write(buffer, dataLength)) |
| 750 { | 723 { |
| 751 return -1; | 724 return -1; |
| 752 } | 725 } |
| 753 _bytesWritten += dataLength; | 726 _bytesWritten += dataLength; |
| 754 return static_cast<int32_t>(dataLength); | 727 return static_cast<int32_t>(dataLength); |
| 755 } | 728 } |
| 756 | 729 |
| 757 | 730 |
| 758 int32_t ModuleFileUtility::WriteWavHeader( | 731 int32_t ModuleFileUtility::WriteWavHeader( |
| 759 OutStream& wav, | 732 OutStream& wav, |
| 760 const uint32_t freq, | 733 uint32_t freq, |
| 761 const uint32_t bytesPerSample, | 734 size_t bytesPerSample, |
| 762 const uint32_t channels, | 735 uint32_t channels, |
| 763 const uint32_t format, | 736 uint32_t format, |
| 764 const uint32_t lengthInBytes) | 737 size_t lengthInBytes) |
| 765 { | 738 { |
| 766 // Frame size in bytes for 10 ms of audio. | 739 // Frame size in bytes for 10 ms of audio. |
| 767 // TODO (hellner): 44.1 kHz has 440 samples frame size. Doesn't seem to | 740 // TODO (hellner): 44.1 kHz has 440 samples frame size. Doesn't seem to |
| 768 // be taken into consideration here! | 741 // be taken into consideration here! |
| 769 const int32_t frameSize = (freq / 100) * channels; | 742 const size_t frameSize = (freq / 100) * channels; |
| 770 | 743 |
| 771 // Calculate the number of full frames that the wave file contain. | 744 // Calculate the number of full frames that the wave file contain. |
| 772 const int32_t dataLengthInBytes = frameSize * (lengthInBytes / frameSize); | 745 const size_t dataLengthInBytes = frameSize * (lengthInBytes / frameSize); |
| 773 | 746 |
| 774 uint8_t buf[kWavHeaderSize]; | 747 uint8_t buf[kWavHeaderSize]; |
| 775 webrtc::WriteWavHeader(buf, channels, freq, static_cast<WavFormat>(format), | 748 webrtc::WriteWavHeader(buf, channels, freq, static_cast<WavFormat>(format), |
| 776 bytesPerSample, dataLengthInBytes / bytesPerSample); | 749 bytesPerSample, dataLengthInBytes / bytesPerSample); |
| 777 wav.Write(buf, kWavHeaderSize); | 750 wav.Write(buf, kWavHeaderSize); |
| 778 return 0; | 751 return 0; |
| 779 } | 752 } |
| 780 | 753 |
| 781 int32_t ModuleFileUtility::UpdateWavHeader(OutStream& wav) | 754 int32_t ModuleFileUtility::UpdateWavHeader(OutStream& wav) |
| 782 { | 755 { |
| 783 int32_t res = -1; | 756 int32_t res = -1; |
| 784 if(wav.Rewind() == -1) | 757 if(wav.Rewind() == -1) |
| 785 { | 758 { |
| 786 return -1; | 759 return -1; |
| 787 } | 760 } |
| 788 uint32_t channels = (codec_info_.channels == 0) ? | 761 uint32_t channels = (codec_info_.channels == 0) ? 1 : codec_info_.channels; |
| 789 1 : codec_info_.channels; | |
| 790 | 762 |
| 791 if(STR_CASE_CMP(codec_info_.plname, "L16") == 0) | 763 if(STR_CASE_CMP(codec_info_.plname, "L16") == 0) |
| 792 { | 764 { |
| 793 res = WriteWavHeader(wav, codec_info_.plfreq, 2, channels, | 765 res = WriteWavHeader(wav, codec_info_.plfreq, 2, channels, |
| 794 kWavFormatPcm, _bytesWritten); | 766 kWavFormatPcm, _bytesWritten); |
| 795 } else if(STR_CASE_CMP(codec_info_.plname, "PCMU") == 0) { | 767 } else if(STR_CASE_CMP(codec_info_.plname, "PCMU") == 0) { |
| 796 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatMuLaw, | 768 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatMuLaw, |
| 797 _bytesWritten); | 769 _bytesWritten); |
| 798 } else if(STR_CASE_CMP(codec_info_.plname, "PCMA") == 0) { | 770 } else if(STR_CASE_CMP(codec_info_.plname, "PCMA") == 0) { |
| 799 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatALaw, | 771 res = WriteWavHeader(wav, 8000, 1, channels, kWavFormatALaw, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 memcpy(&codec_info_,&cinst,sizeof(CodecInst)); | 804 memcpy(&codec_info_,&cinst,sizeof(CodecInst)); |
| 833 _reading = true; | 805 _reading = true; |
| 834 return 0; | 806 return 0; |
| 835 } | 807 } |
| 836 | 808 |
| 837 int32_t ModuleFileUtility::ReadPreEncodedData( | 809 int32_t ModuleFileUtility::ReadPreEncodedData( |
| 838 InStream& in, | 810 InStream& in, |
| 839 int8_t* outData, | 811 int8_t* outData, |
| 840 const size_t bufferSize) | 812 const size_t bufferSize) |
| 841 { | 813 { |
| 842 WEBRTC_TRACE( | 814 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
| 843 kTraceStream, | 815 "ModuleFileUtility::ReadPreEncodedData(in= 0x%x, " |
| 844 kTraceFile, | 816 "outData= 0x%x, bufferSize= %" PRIuS ")", &in, outData, |
| 845 _id, | 817 bufferSize); |
| 846 "ModuleFileUtility::ReadPreEncodedData(in= 0x%x, outData= 0x%x, " | |
| 847 "bufferSize= %" PRIuS ")", | |
| 848 &in, | |
| 849 outData, | |
| 850 bufferSize); | |
| 851 | 818 |
| 852 if(outData == NULL) | 819 if(outData == NULL) |
| 853 { | 820 { |
| 854 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "output buffer NULL"); | 821 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "output buffer NULL"); |
| 855 } | 822 } |
| 856 | 823 |
| 857 uint32_t frameLen; | 824 size_t frameLen; |
| 858 uint8_t buf[64]; | 825 uint8_t buf[64]; |
| 859 // Each frame has a two byte header containing the frame length. | 826 // Each frame has a two byte header containing the frame length. |
| 860 int32_t res = in.Read(buf, 2); | 827 int32_t res = in.Read(buf, 2); |
| 861 if(res != 2) | 828 if(res != 2) |
| 862 { | 829 { |
| 863 if(!in.Rewind()) | 830 if(!in.Rewind()) |
| 864 { | 831 { |
| 865 // The first byte is the codec identifier. | 832 // The first byte is the codec identifier. |
| 866 in.Read(buf, 1); | 833 in.Read(buf, 1); |
| 867 res = in.Read(buf, 2); | 834 res = in.Read(buf, 2); |
| 868 } | 835 } |
| 869 else | 836 else |
| 870 { | 837 { |
| 871 return -1; | 838 return -1; |
| 872 } | 839 } |
| 873 } | 840 } |
| 874 frameLen = buf[0] + buf[1] * 256; | 841 frameLen = buf[0] + buf[1] * 256; |
| 875 if(bufferSize < frameLen) | 842 if(bufferSize < frameLen) |
| 876 { | 843 { |
| 877 WEBRTC_TRACE( | 844 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 878 kTraceError, | 845 "buffer not large enough to read %" PRIuS " bytes of " |
| 879 kTraceFile, | 846 "pre-encoded data!", frameLen); |
| 880 _id, | |
| 881 "buffer not large enough to read %d bytes of pre-encoded data!", | |
| 882 frameLen); | |
| 883 return -1; | 847 return -1; |
| 884 } | 848 } |
| 885 return in.Read(outData, frameLen); | 849 return in.Read(outData, frameLen); |
| 886 } | 850 } |
| 887 | 851 |
| 888 int32_t ModuleFileUtility::InitPreEncodedWriting( | 852 int32_t ModuleFileUtility::InitPreEncodedWriting( |
| 889 OutStream& out, | 853 OutStream& out, |
| 890 const CodecInst& codecInst) | 854 const CodecInst& codecInst) |
| 891 { | 855 { |
| 892 | 856 |
| 893 if(set_codec_info(codecInst) != 0) | 857 if(set_codec_info(codecInst) != 0) |
| 894 { | 858 { |
| 895 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "CodecInst not recognized!"); | 859 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "CodecInst not recognized!"); |
| 896 return -1; | 860 return -1; |
| 897 } | 861 } |
| 898 _writing = true; | 862 _writing = true; |
| 899 _bytesWritten = 1; | 863 _bytesWritten = 1; |
| 900 out.Write(&_codecId, 1); | 864 out.Write(&_codecId, 1); |
| 901 return 0; | 865 return 0; |
| 902 } | 866 } |
| 903 | 867 |
| 904 int32_t ModuleFileUtility::WritePreEncodedData( | 868 int32_t ModuleFileUtility::WritePreEncodedData( |
| 905 OutStream& out, | 869 OutStream& out, |
| 906 const int8_t* buffer, | 870 const int8_t* buffer, |
| 907 const size_t dataLength) | 871 const size_t dataLength) |
| 908 { | 872 { |
| 909 WEBRTC_TRACE( | 873 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
| 910 kTraceStream, | 874 "ModuleFileUtility::WritePreEncodedData(out= 0x%x, " |
| 911 kTraceFile, | 875 "inData= 0x%x, dataLen= %" PRIuS ")", &out, buffer, |
| 912 _id, | 876 dataLength); |
| 913 "ModuleFileUtility::WritePreEncodedData(out= 0x%x, inData= 0x%x, " | |
| 914 "dataLen= %" PRIuS ")", | |
| 915 &out, | |
| 916 buffer, | |
| 917 dataLength); | |
| 918 | 877 |
| 919 if(buffer == NULL) | 878 if(buffer == NULL) |
| 920 { | 879 { |
| 921 WEBRTC_TRACE(kTraceError, kTraceFile, _id,"buffer NULL"); | 880 WEBRTC_TRACE(kTraceError, kTraceFile, _id,"buffer NULL"); |
| 922 } | 881 } |
| 923 | 882 |
| 924 size_t bytesWritten = 0; | 883 size_t bytesWritten = 0; |
| 925 // The first two bytes is the size of the frame. | 884 // The first two bytes is the size of the frame. |
| 926 int16_t lengthBuf; | 885 int16_t lengthBuf; |
| 927 lengthBuf = (int16_t)dataLength; | 886 lengthBuf = (int16_t)dataLength; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 938 } | 897 } |
| 939 bytesWritten += dataLength; | 898 bytesWritten += dataLength; |
| 940 return static_cast<int32_t>(bytesWritten); | 899 return static_cast<int32_t>(bytesWritten); |
| 941 } | 900 } |
| 942 | 901 |
| 943 int32_t ModuleFileUtility::InitCompressedReading( | 902 int32_t ModuleFileUtility::InitCompressedReading( |
| 944 InStream& in, | 903 InStream& in, |
| 945 const uint32_t start, | 904 const uint32_t start, |
| 946 const uint32_t stop) | 905 const uint32_t stop) |
| 947 { | 906 { |
| 948 WEBRTC_TRACE( | 907 WEBRTC_TRACE(kTraceDebug, kTraceFile, _id, |
| 949 kTraceDebug, | 908 "ModuleFileUtility::InitCompressedReading(in= 0x%x, " |
| 950 kTraceFile, | 909 "start= %d, stop= %d)", &in, start, stop); |
| 951 _id, | |
| 952 "ModuleFileUtility::InitCompressedReading(in= 0x%x, start= %d,\ | |
| 953 stop= %d)", | |
| 954 &in, | |
| 955 start, | |
| 956 stop); | |
| 957 | 910 |
| 958 #if defined(WEBRTC_CODEC_ILBC) | 911 #if defined(WEBRTC_CODEC_ILBC) |
| 959 int16_t read_len = 0; | 912 int16_t read_len = 0; |
| 960 #endif | 913 #endif |
| 961 _codecId = kCodecNoCodec; | 914 _codecId = kCodecNoCodec; |
| 962 _playoutPositionMs = 0; | 915 _playoutPositionMs = 0; |
| 963 _reading = false; | 916 _reading = false; |
| 964 | 917 |
| 965 _startPointInMs = start; | 918 _startPointInMs = start; |
| 966 _stopPointInMs = stop; | 919 _stopPointInMs = stop; |
| 967 | 920 |
| 968 // Read the codec name | 921 // Read the codec name |
| 969 int32_t cnt = 0; | 922 int32_t cnt = 0; |
| 970 char buf[64]; | 923 char buf[64]; |
| 971 do | 924 do |
| 972 { | 925 { |
| 973 in.Read(&buf[cnt++], 1); | 926 in.Read(&buf[cnt++], 1); |
| 974 } while ((buf[cnt-1] != '\n') && (64 > cnt)); | 927 } while ((buf[cnt-1] != '\n') && (64 > cnt)); |
| 975 | 928 |
| 976 if(cnt==64) | 929 if(cnt==64) |
| 977 { | 930 { |
| 978 return -1; | 931 return -1; |
| 979 } else { | |
| 980 buf[cnt]=0; | |
| 981 } | 932 } |
| 933 buf[cnt]=0; |
| 982 | 934 |
| 983 #ifdef WEBRTC_CODEC_ILBC | 935 #ifdef WEBRTC_CODEC_ILBC |
| 984 if(!strcmp("#!iLBC20\n", buf)) | 936 if(!strcmp("#!iLBC20\n", buf)) |
| 985 { | 937 { |
| 986 codec_info_.pltype = 102; | 938 codec_info_.pltype = 102; |
| 987 strcpy(codec_info_.plname, "ilbc"); | 939 strcpy(codec_info_.plname, "ilbc"); |
| 988 codec_info_.plfreq = 8000; | 940 codec_info_.plfreq = 8000; |
| 989 codec_info_.pacsize = 160; | 941 codec_info_.pacsize = 160; |
| 990 codec_info_.channels = 1; | 942 codec_info_.channels = 1; |
| 991 codec_info_.rate = 13300; | 943 codec_info_.rate = 13300; |
| 992 _codecId = kCodecIlbc20Ms; | 944 _codecId = kCodecIlbc20Ms; |
| 993 | 945 |
| 994 if(_startPointInMs > 0) | 946 if(_startPointInMs > 0) |
| 995 { | 947 { |
| 996 while (_playoutPositionMs <= _startPointInMs) | 948 while (_playoutPositionMs <= _startPointInMs) |
| 997 { | 949 { |
| 998 read_len = in.Read(buf, 38); | 950 read_len = in.Read(buf, 38); |
| 999 if(read_len == 38) | 951 if(read_len != 38) |
| 1000 { | |
| 1001 _playoutPositionMs += 20; | |
| 1002 } | |
| 1003 else | |
| 1004 { | 952 { |
| 1005 return -1; | 953 return -1; |
| 1006 } | 954 } |
| 955 _playoutPositionMs += 20; |
| 1007 } | 956 } |
| 1008 } | 957 } |
| 1009 } | 958 } |
| 1010 | 959 |
| 1011 if(!strcmp("#!iLBC30\n", buf)) | 960 if(!strcmp("#!iLBC30\n", buf)) |
| 1012 { | 961 { |
| 1013 codec_info_.pltype = 102; | 962 codec_info_.pltype = 102; |
| 1014 strcpy(codec_info_.plname, "ilbc"); | 963 strcpy(codec_info_.plname, "ilbc"); |
| 1015 codec_info_.plfreq = 8000; | 964 codec_info_.plfreq = 8000; |
| 1016 codec_info_.pacsize = 240; | 965 codec_info_.pacsize = 240; |
| 1017 codec_info_.channels = 1; | 966 codec_info_.channels = 1; |
| 1018 codec_info_.rate = 13300; | 967 codec_info_.rate = 13300; |
| 1019 _codecId = kCodecIlbc30Ms; | 968 _codecId = kCodecIlbc30Ms; |
| 1020 | 969 |
| 1021 if(_startPointInMs > 0) | 970 if(_startPointInMs > 0) |
| 1022 { | 971 { |
| 1023 while (_playoutPositionMs <= _startPointInMs) | 972 while (_playoutPositionMs <= _startPointInMs) |
| 1024 { | 973 { |
| 1025 read_len = in.Read(buf, 50); | 974 read_len = in.Read(buf, 50); |
| 1026 if(read_len == 50) | 975 if(read_len != 50) |
| 1027 { | |
| 1028 _playoutPositionMs += 20; | |
| 1029 } | |
| 1030 else | |
| 1031 { | 976 { |
| 1032 return -1; | 977 return -1; |
| 1033 } | 978 } |
| 979 _playoutPositionMs += 20; |
| 1034 } | 980 } |
| 1035 } | 981 } |
| 1036 } | 982 } |
| 1037 #endif | 983 #endif |
| 1038 if(_codecId == kCodecNoCodec) | 984 if(_codecId == kCodecNoCodec) |
| 1039 { | 985 { |
| 1040 return -1; | 986 return -1; |
| 1041 } | 987 } |
| 1042 _reading = true; | 988 _reading = true; |
| 1043 return 0; | 989 return 0; |
| 1044 } | 990 } |
| 1045 | 991 |
| 1046 int32_t ModuleFileUtility::ReadCompressedData(InStream& in, | 992 int32_t ModuleFileUtility::ReadCompressedData(InStream& in, |
| 1047 int8_t* outData, | 993 int8_t* outData, |
| 1048 size_t bufferSize) | 994 size_t bufferSize) |
| 1049 { | 995 { |
| 1050 WEBRTC_TRACE( | 996 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
| 1051 kTraceStream, | 997 "ModuleFileUtility::ReadCompressedData(in=0x%x, outData=0x%x, " |
| 1052 kTraceFile, | 998 "bytes=%" PRIuS ")", &in, outData, bufferSize); |
| 1053 _id, | |
| 1054 "ModuleFileUtility::ReadCompressedData(in=0x%x, outData=0x%x, bytes=%" | |
| 1055 PRIuS ")", | |
| 1056 &in, | |
| 1057 outData, | |
| 1058 bufferSize); | |
| 1059 | 999 |
| 1060 uint32_t bytesRead = 0; | 1000 int bytesRead = 0; |
| 1061 | 1001 |
| 1062 if(! _reading) | 1002 if(! _reading) |
| 1063 { | 1003 { |
| 1064 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "not currently reading!"); | 1004 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "not currently reading!"); |
| 1065 return -1; | 1005 return -1; |
| 1066 } | 1006 } |
| 1067 | 1007 |
| 1068 #ifdef WEBRTC_CODEC_ILBC | 1008 #ifdef WEBRTC_CODEC_ILBC |
| 1069 if((_codecId == kCodecIlbc20Ms) || | 1009 if((_codecId == kCodecIlbc20Ms) || |
| 1070 (_codecId == kCodecIlbc30Ms)) | 1010 (_codecId == kCodecIlbc30Ms)) |
| 1071 { | 1011 { |
| 1072 uint32_t byteSize = 0; | 1012 size_t byteSize = 0; |
| 1073 if(_codecId == kCodecIlbc30Ms) | 1013 if(_codecId == kCodecIlbc30Ms) |
| 1074 { | 1014 { |
| 1075 byteSize = 50; | 1015 byteSize = 50; |
| 1076 } | 1016 } |
| 1077 if(_codecId == kCodecIlbc20Ms) | 1017 if(_codecId == kCodecIlbc20Ms) |
| 1078 { | 1018 { |
| 1079 byteSize = 38; | 1019 byteSize = 38; |
| 1080 } | 1020 } |
| 1081 if(bufferSize < byteSize) | 1021 if(bufferSize < byteSize) |
| 1082 { | 1022 { |
| 1083 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 1023 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 1084 "output buffer is too short to read ILBC compressed\ | 1024 "output buffer is too short to read ILBC compressed " |
| 1085 data."); | 1025 "data."); |
| 1086 assert(false); | 1026 assert(false); |
| 1087 return -1; | 1027 return -1; |
| 1088 } | 1028 } |
| 1089 | 1029 |
| 1090 bytesRead = in.Read(outData, byteSize); | 1030 bytesRead = in.Read(outData, byteSize); |
| 1091 if(bytesRead != byteSize) | 1031 if(bytesRead != static_cast<int>(byteSize)) |
| 1092 { | 1032 { |
| 1093 if(!in.Rewind()) | 1033 if(!in.Rewind()) |
| 1094 { | 1034 { |
| 1095 InitCompressedReading(in, _startPointInMs, _stopPointInMs); | 1035 InitCompressedReading(in, _startPointInMs, _stopPointInMs); |
| 1096 bytesRead = in.Read(outData, byteSize); | 1036 bytesRead = in.Read(outData, byteSize); |
| 1097 if(bytesRead != byteSize) | 1037 if(bytesRead != static_cast<int>(byteSize)) |
| 1098 { | 1038 { |
| 1099 _reading = false; | 1039 _reading = false; |
| 1100 return -1; | 1040 return -1; |
| 1101 } | 1041 } |
| 1102 } | 1042 } |
| 1103 else | 1043 else |
| 1104 { | 1044 { |
| 1105 _reading = false; | 1045 _reading = false; |
| 1106 return -1; | 1046 return -1; |
| 1107 } | 1047 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1129 } | 1069 } |
| 1130 } | 1070 } |
| 1131 return bytesRead; | 1071 return bytesRead; |
| 1132 } | 1072 } |
| 1133 | 1073 |
| 1134 int32_t ModuleFileUtility::InitCompressedWriting( | 1074 int32_t ModuleFileUtility::InitCompressedWriting( |
| 1135 OutStream& out, | 1075 OutStream& out, |
| 1136 const CodecInst& codecInst) | 1076 const CodecInst& codecInst) |
| 1137 { | 1077 { |
| 1138 WEBRTC_TRACE(kTraceDebug, kTraceFile, _id, | 1078 WEBRTC_TRACE(kTraceDebug, kTraceFile, _id, |
| 1139 "ModuleFileUtility::InitCompressedWriting(out= 0x%x,\ | 1079 "ModuleFileUtility::InitCompressedWriting(out= 0x%x, " |
| 1140 codecName= %s)", | 1080 "codecName= %s)", &out, codecInst.plname); |
| 1141 &out, codecInst.plname); | |
| 1142 | 1081 |
| 1143 _writing = false; | 1082 _writing = false; |
| 1144 | 1083 |
| 1145 #ifdef WEBRTC_CODEC_ILBC | 1084 #ifdef WEBRTC_CODEC_ILBC |
| 1146 if(STR_CASE_CMP(codecInst.plname, "ilbc") == 0) | 1085 if(STR_CASE_CMP(codecInst.plname, "ilbc") == 0) |
| 1147 { | 1086 { |
| 1148 if(codecInst.pacsize == 160) | 1087 if(codecInst.pacsize == 160) |
| 1149 { | 1088 { |
| 1150 _codecId = kCodecIlbc20Ms; | 1089 _codecId = kCodecIlbc20Ms; |
| 1151 out.Write("#!iLBC20\n",9); | 1090 out.Write("#!iLBC20\n",9); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1170 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 1109 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 1171 "codecInst defines unsupported compression codec!"); | 1110 "codecInst defines unsupported compression codec!"); |
| 1172 return -1; | 1111 return -1; |
| 1173 } | 1112 } |
| 1174 | 1113 |
| 1175 int32_t ModuleFileUtility::WriteCompressedData( | 1114 int32_t ModuleFileUtility::WriteCompressedData( |
| 1176 OutStream& out, | 1115 OutStream& out, |
| 1177 const int8_t* buffer, | 1116 const int8_t* buffer, |
| 1178 const size_t dataLength) | 1117 const size_t dataLength) |
| 1179 { | 1118 { |
| 1180 WEBRTC_TRACE( | 1119 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
| 1181 kTraceStream, | 1120 "ModuleFileUtility::WriteCompressedData(out= 0x%x, buf= 0x%x, " |
| 1182 kTraceFile, | 1121 "dataLen= %" PRIuS ")", &out, buffer, dataLength); |
| 1183 _id, | |
| 1184 "ModuleFileUtility::WriteCompressedData(out= 0x%x, buf= 0x%x, " | |
| 1185 "dataLen= %" PRIuS ")", | |
| 1186 &out, | |
| 1187 buffer, | |
| 1188 dataLength); | |
| 1189 | 1122 |
| 1190 if(buffer == NULL) | 1123 if(buffer == NULL) |
| 1191 { | 1124 { |
| 1192 WEBRTC_TRACE(kTraceError, kTraceFile, _id,"buffer NULL"); | 1125 WEBRTC_TRACE(kTraceError, kTraceFile, _id,"buffer NULL"); |
| 1193 } | 1126 } |
| 1194 | 1127 |
| 1195 if(!out.Write(buffer, dataLength)) | 1128 if(!out.Write(buffer, dataLength)) |
| 1196 { | 1129 { |
| 1197 return -1; | 1130 return -1; |
| 1198 } | 1131 } |
| 1199 return static_cast<int32_t>(dataLength); | 1132 return static_cast<int32_t>(dataLength); |
| 1200 } | 1133 } |
| 1201 | 1134 |
| 1202 int32_t ModuleFileUtility::InitPCMReading(InStream& pcm, | 1135 int32_t ModuleFileUtility::InitPCMReading(InStream& pcm, |
| 1203 const uint32_t start, | 1136 const uint32_t start, |
| 1204 const uint32_t stop, | 1137 const uint32_t stop, |
| 1205 uint32_t freq) | 1138 uint32_t freq) |
| 1206 { | 1139 { |
| 1207 WEBRTC_TRACE( | 1140 WEBRTC_TRACE(kTraceInfo, kTraceFile, _id, |
| 1208 kTraceInfo, | 1141 "ModuleFileUtility::InitPCMReading(pcm= 0x%x, start=%d, " |
| 1209 kTraceFile, | 1142 "stop=%d, freq=%d)", &pcm, start, stop, freq); |
| 1210 _id, | |
| 1211 "ModuleFileUtility::InitPCMReading(pcm= 0x%x, start=%d, stop=%d,\ | |
| 1212 freq=%d)", | |
| 1213 &pcm, | |
| 1214 start, | |
| 1215 stop, | |
| 1216 freq); | |
| 1217 | 1143 |
| 1218 int8_t dummy[320]; | 1144 int8_t dummy[320]; |
| 1219 int32_t read_len; | 1145 int read_len; |
| 1220 | 1146 |
| 1221 _playoutPositionMs = 0; | 1147 _playoutPositionMs = 0; |
| 1222 _startPointInMs = start; | 1148 _startPointInMs = start; |
| 1223 _stopPointInMs = stop; | 1149 _stopPointInMs = stop; |
| 1224 _reading = false; | 1150 _reading = false; |
| 1225 | 1151 |
| 1226 if(freq == 8000) | 1152 if(freq == 8000) |
| 1227 { | 1153 { |
| 1228 strcpy(codec_info_.plname, "L16"); | 1154 strcpy(codec_info_.plname, "L16"); |
| 1229 codec_info_.pltype = -1; | 1155 codec_info_.pltype = -1; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1254 _codecId = kCodecL16_32Khz; | 1180 _codecId = kCodecL16_32Khz; |
| 1255 } | 1181 } |
| 1256 | 1182 |
| 1257 // Readsize for 10ms of audio data (2 bytes per sample). | 1183 // Readsize for 10ms of audio data (2 bytes per sample). |
| 1258 _readSizeBytes = 2 * codec_info_. plfreq / 100; | 1184 _readSizeBytes = 2 * codec_info_. plfreq / 100; |
| 1259 if(_startPointInMs > 0) | 1185 if(_startPointInMs > 0) |
| 1260 { | 1186 { |
| 1261 while (_playoutPositionMs < _startPointInMs) | 1187 while (_playoutPositionMs < _startPointInMs) |
| 1262 { | 1188 { |
| 1263 read_len = pcm.Read(dummy, _readSizeBytes); | 1189 read_len = pcm.Read(dummy, _readSizeBytes); |
| 1264 if(read_len == _readSizeBytes) | 1190 if(read_len != static_cast<int>(_readSizeBytes)) |
| 1265 { | 1191 { |
| 1266 _playoutPositionMs += 10; | 1192 return -1; // Must have reached EOF before start position! |
| 1267 } | 1193 } |
| 1268 else // Must have reached EOF before start position! | 1194 _playoutPositionMs += 10; |
| 1269 { | |
| 1270 return -1; | |
| 1271 } | |
| 1272 } | 1195 } |
| 1273 } | 1196 } |
| 1274 _reading = true; | 1197 _reading = true; |
| 1275 return 0; | 1198 return 0; |
| 1276 } | 1199 } |
| 1277 | 1200 |
| 1278 int32_t ModuleFileUtility::ReadPCMData(InStream& pcm, | 1201 int32_t ModuleFileUtility::ReadPCMData(InStream& pcm, |
| 1279 int8_t* outData, | 1202 int8_t* outData, |
| 1280 size_t bufferSize) | 1203 size_t bufferSize) |
| 1281 { | 1204 { |
| 1282 WEBRTC_TRACE( | 1205 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
| 1283 kTraceStream, | 1206 "ModuleFileUtility::ReadPCMData(pcm= 0x%x, outData= 0x%x, " |
| 1284 kTraceFile, | 1207 "bufSize= %" PRIuS ")", &pcm, outData, bufferSize); |
| 1285 _id, | |
| 1286 "ModuleFileUtility::ReadPCMData(pcm= 0x%x, outData= 0x%x, bufSize= %" | |
| 1287 PRIuS ")", | |
| 1288 &pcm, | |
| 1289 outData, | |
| 1290 bufferSize); | |
| 1291 | 1208 |
| 1292 if(outData == NULL) | 1209 if(outData == NULL) |
| 1293 { | 1210 { |
| 1294 WEBRTC_TRACE(kTraceError, kTraceFile, _id,"buffer NULL"); | 1211 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "buffer NULL"); |
| 1295 } | 1212 } |
| 1296 | 1213 |
| 1297 // Readsize for 10ms of audio data (2 bytes per sample). | 1214 // Readsize for 10ms of audio data (2 bytes per sample). |
| 1298 uint32_t bytesRequested = 2 * codec_info_.plfreq / 100; | 1215 size_t bytesRequested = static_cast<size_t>(2 * codec_info_.plfreq / 100); |
| 1299 if(bufferSize < bytesRequested) | 1216 if(bufferSize < bytesRequested) |
| 1300 { | 1217 { |
| 1301 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 1218 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 1302 "ReadPCMData: buffer not long enough for a 10ms frame."); | 1219 "ReadPCMData: buffer not long enough for a 10ms frame."); |
| 1303 assert(false); | 1220 assert(false); |
| 1304 return -1; | 1221 return -1; |
| 1305 } | 1222 } |
| 1306 | 1223 |
| 1307 uint32_t bytesRead = pcm.Read(outData, bytesRequested); | 1224 int bytesRead = pcm.Read(outData, bytesRequested); |
| 1308 if(bytesRead < bytesRequested) | 1225 if(bytesRead < static_cast<int>(bytesRequested)) |
| 1309 { | 1226 { |
| 1310 if(pcm.Rewind() == -1) | 1227 if(pcm.Rewind() == -1) |
| 1311 { | 1228 { |
| 1312 _reading = false; | 1229 _reading = false; |
| 1313 } | 1230 } |
| 1314 else | 1231 else |
| 1315 { | 1232 { |
| 1316 if(InitPCMReading(pcm, _startPointInMs, _stopPointInMs, | 1233 if(InitPCMReading(pcm, _startPointInMs, _stopPointInMs, |
| 1317 codec_info_.plfreq) == -1) | 1234 codec_info_.plfreq) == -1) |
| 1318 { | 1235 { |
| 1319 _reading = false; | 1236 _reading = false; |
| 1320 } | 1237 } |
| 1321 else | 1238 else |
| 1322 { | 1239 { |
| 1323 int32_t rest = bytesRequested - bytesRead; | 1240 size_t rest = bytesRequested - bytesRead; |
| 1324 int32_t len = pcm.Read(&(outData[bytesRead]), rest); | 1241 int len = pcm.Read(&(outData[bytesRead]), rest); |
| 1325 if(len == rest) | 1242 if(len == static_cast<int>(rest)) |
| 1326 { | 1243 { |
| 1327 bytesRead += len; | 1244 bytesRead += len; |
| 1328 } | 1245 } |
| 1329 else | 1246 else |
| 1330 { | 1247 { |
| 1331 _reading = false; | 1248 _reading = false; |
| 1332 } | 1249 } |
| 1333 } | 1250 } |
| 1334 if(bytesRead <= 0) | 1251 if(bytesRead <= 0) |
| 1335 { | 1252 { |
| 1336 WEBRTC_TRACE(kTraceError, kTraceFile, _id, | 1253 WEBRTC_TRACE(kTraceError, kTraceFile, _id, |
| 1337 "ReadPCMData: Failed to rewind audio file."); | 1254 "ReadPCMData: Failed to rewind audio file."); |
| 1338 return -1; | 1255 return -1; |
| 1339 } | 1256 } |
| 1340 } | 1257 } |
| 1341 } | 1258 } |
| 1342 | 1259 |
| 1343 if(bytesRead <= 0) | 1260 if(bytesRead <= 0) |
| 1344 { | 1261 { |
| 1345 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, | 1262 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
| 1346 "ReadPCMData: end of file"); | 1263 "ReadPCMData: end of file"); |
| 1347 return -1; | 1264 return -1; |
| 1348 } | 1265 } |
| 1349 _playoutPositionMs += 10; | 1266 _playoutPositionMs += 10; |
| 1350 if(_stopPointInMs && _playoutPositionMs >= _stopPointInMs) | 1267 if(_stopPointInMs && _playoutPositionMs >= _stopPointInMs) |
| 1351 { | 1268 { |
| 1352 if(!pcm.Rewind()) | 1269 if(!pcm.Rewind()) |
| 1353 { | 1270 { |
| 1354 if(InitPCMReading(pcm, _startPointInMs, _stopPointInMs, | 1271 if(InitPCMReading(pcm, _startPointInMs, _stopPointInMs, |
| 1355 codec_info_.plfreq) == -1) | 1272 codec_info_.plfreq) == -1) |
| 1356 { | 1273 { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 } | 1324 } |
| 1408 _writing = true; | 1325 _writing = true; |
| 1409 _bytesWritten = 0; | 1326 _bytesWritten = 0; |
| 1410 return 0; | 1327 return 0; |
| 1411 } | 1328 } |
| 1412 | 1329 |
| 1413 int32_t ModuleFileUtility::WritePCMData(OutStream& out, | 1330 int32_t ModuleFileUtility::WritePCMData(OutStream& out, |
| 1414 const int8_t* buffer, | 1331 const int8_t* buffer, |
| 1415 const size_t dataLength) | 1332 const size_t dataLength) |
| 1416 { | 1333 { |
| 1417 WEBRTC_TRACE( | 1334 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
| 1418 kTraceStream, | 1335 "ModuleFileUtility::WritePCMData(out= 0x%x, buf= 0x%x, " |
| 1419 kTraceFile, | 1336 "dataLen= %" PRIuS ")", &out, buffer, dataLength); |
| 1420 _id, | |
| 1421 "ModuleFileUtility::WritePCMData(out= 0x%x, buf= 0x%x, dataLen= %" PRIuS | |
| 1422 ")", | |
| 1423 &out, | |
| 1424 buffer, | |
| 1425 dataLength); | |
| 1426 | 1337 |
| 1427 if(buffer == NULL) | 1338 if(buffer == NULL) |
| 1428 { | 1339 { |
| 1429 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "buffer NULL"); | 1340 WEBRTC_TRACE(kTraceError, kTraceFile, _id, "buffer NULL"); |
| 1430 } | 1341 } |
| 1431 | 1342 |
| 1432 if(!out.Write(buffer, dataLength)) | 1343 if(!out.Write(buffer, dataLength)) |
| 1433 { | 1344 { |
| 1434 return -1; | 1345 return -1; |
| 1435 } | 1346 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 case kFileFormatPcm8kHzFile: | 1489 case kFileFormatPcm8kHzFile: |
| 1579 { | 1490 { |
| 1580 // 8 samples per ms. 2 bytes per sample. | 1491 // 8 samples per ms. 2 bytes per sample. |
| 1581 int32_t denominator = 8*2; | 1492 int32_t denominator = 8*2; |
| 1582 time_in_ms = (file_size.st_size)/denominator; | 1493 time_in_ms = (file_size.st_size)/denominator; |
| 1583 break; | 1494 break; |
| 1584 } | 1495 } |
| 1585 case kFileFormatCompressedFile: | 1496 case kFileFormatCompressedFile: |
| 1586 { | 1497 { |
| 1587 int32_t cnt = 0; | 1498 int32_t cnt = 0; |
| 1588 int32_t read_len = 0; | 1499 int read_len = 0; |
| 1589 char buf[64]; | 1500 char buf[64]; |
| 1590 do | 1501 do |
| 1591 { | 1502 { |
| 1592 read_len = inStreamObj->Read(&buf[cnt++], 1); | 1503 read_len = inStreamObj->Read(&buf[cnt++], 1); |
| 1593 if(read_len != 1) | 1504 if(read_len != 1) |
| 1594 { | 1505 { |
| 1595 return -1; | 1506 return -1; |
| 1596 } | 1507 } |
| 1597 } while ((buf[cnt-1] != '\n') && (64 > cnt)); | 1508 } while ((buf[cnt-1] != '\n') && (64 > cnt)); |
| 1598 | 1509 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1635 break; | 1546 break; |
| 1636 } | 1547 } |
| 1637 inStreamObj->CloseFile(); | 1548 inStreamObj->CloseFile(); |
| 1638 delete inStreamObj; | 1549 delete inStreamObj; |
| 1639 return time_in_ms; | 1550 return time_in_ms; |
| 1640 } | 1551 } |
| 1641 | 1552 |
| 1642 uint32_t ModuleFileUtility::PlayoutPositionMs() | 1553 uint32_t ModuleFileUtility::PlayoutPositionMs() |
| 1643 { | 1554 { |
| 1644 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, | 1555 WEBRTC_TRACE(kTraceStream, kTraceFile, _id, |
| 1645 "ModuleFileUtility::PlayoutPosition()"); | 1556 "ModuleFileUtility::PlayoutPosition()"); |
| 1646 | 1557 |
| 1647 if(_reading) | 1558 return _reading ? _playoutPositionMs : 0; |
| 1648 { | |
| 1649 return _playoutPositionMs; | |
| 1650 } | |
| 1651 else | |
| 1652 { | |
| 1653 return 0; | |
| 1654 } | |
| 1655 } | 1559 } |
| 1656 } // namespace webrtc | 1560 } // namespace webrtc |
| OLD | NEW |