| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 88 } | 88 } | 
| 89 | 89 | 
| 90 int32_t FilePlayerImpl::AudioCodec(CodecInst& audioCodec) const | 90 int32_t FilePlayerImpl::AudioCodec(CodecInst& audioCodec) const | 
| 91 { | 91 { | 
| 92     audioCodec = _codec; | 92     audioCodec = _codec; | 
| 93     return 0; | 93     return 0; | 
| 94 } | 94 } | 
| 95 | 95 | 
| 96 int32_t FilePlayerImpl::Get10msAudioFromFile( | 96 int32_t FilePlayerImpl::Get10msAudioFromFile( | 
| 97     int16_t* outBuffer, | 97     int16_t* outBuffer, | 
| 98     int& lengthInSamples, | 98     size_t& lengthInSamples, | 
| 99     int frequencyInHz) | 99     int frequencyInHz) | 
| 100 { | 100 { | 
| 101     if(_codec.plfreq == 0) | 101     if(_codec.plfreq == 0) | 
| 102     { | 102     { | 
| 103         LOG(LS_WARNING) << "Get10msAudioFromFile() playing not started!" | 103         LOG(LS_WARNING) << "Get10msAudioFromFile() playing not started!" | 
| 104                         << " codec freq = " << _codec.plfreq | 104                         << " codec freq = " << _codec.plfreq | 
| 105                         << ", wanted freq = " << frequencyInHz; | 105                         << ", wanted freq = " << frequencyInHz; | 
| 106         return -1; | 106         return -1; | 
| 107     } | 107     } | 
| 108 | 108 | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 120         { | 120         { | 
| 121             // End of file reached. | 121             // End of file reached. | 
| 122             return -1; | 122             return -1; | 
| 123         } | 123         } | 
| 124         if(lengthInBytes == 0) | 124         if(lengthInBytes == 0) | 
| 125         { | 125         { | 
| 126             lengthInSamples = 0; | 126             lengthInSamples = 0; | 
| 127             return 0; | 127             return 0; | 
| 128         } | 128         } | 
| 129         // One sample is two bytes. | 129         // One sample is two bytes. | 
| 130         unresampledAudioFrame.samples_per_channel_ = | 130         unresampledAudioFrame.samples_per_channel_ = lengthInBytes >> 1; | 
| 131             (uint16_t)lengthInBytes >> 1; |  | 
| 132 | 131 | 
| 133     } else { | 132     } else { | 
| 134         // Decode will generate 10 ms of audio data. PlayoutAudioData(..) | 133         // Decode will generate 10 ms of audio data. PlayoutAudioData(..) | 
| 135         // expects a full frame. If the frame size is larger than 10 ms, | 134         // expects a full frame. If the frame size is larger than 10 ms, | 
| 136         // PlayoutAudioData(..) data should be called proportionally less often. | 135         // PlayoutAudioData(..) data should be called proportionally less often. | 
| 137         int16_t encodedBuffer[MAX_AUDIO_BUFFER_IN_SAMPLES]; | 136         int16_t encodedBuffer[MAX_AUDIO_BUFFER_IN_SAMPLES]; | 
| 138         size_t encodedLengthInBytes = 0; | 137         size_t encodedLengthInBytes = 0; | 
| 139         if(++_numberOf10MsInDecoder >= _numberOf10MsPerFrame) | 138         if(++_numberOf10MsInDecoder >= _numberOf10MsPerFrame) | 
| 140         { | 139         { | 
| 141             _numberOf10MsInDecoder = 0; | 140             _numberOf10MsInDecoder = 0; | 
| 142             size_t bytesFromFile = sizeof(encodedBuffer); | 141             size_t bytesFromFile = sizeof(encodedBuffer); | 
| 143             if (_fileModule.PlayoutAudioData((int8_t*)encodedBuffer, | 142             if (_fileModule.PlayoutAudioData((int8_t*)encodedBuffer, | 
| 144                                              bytesFromFile) == -1) | 143                                              bytesFromFile) == -1) | 
| 145             { | 144             { | 
| 146                 // End of file reached. | 145                 // End of file reached. | 
| 147                 return -1; | 146                 return -1; | 
| 148             } | 147             } | 
| 149             encodedLengthInBytes = bytesFromFile; | 148             encodedLengthInBytes = bytesFromFile; | 
| 150         } | 149         } | 
| 151         if(_audioDecoder.Decode(unresampledAudioFrame,frequencyInHz, | 150         if(_audioDecoder.Decode(unresampledAudioFrame,frequencyInHz, | 
| 152                                 (int8_t*)encodedBuffer, | 151                                 (int8_t*)encodedBuffer, | 
| 153                                 encodedLengthInBytes) == -1) | 152                                 encodedLengthInBytes) == -1) | 
| 154         { | 153         { | 
| 155             return -1; | 154             return -1; | 
| 156         } | 155         } | 
| 157     } | 156     } | 
| 158 | 157 | 
| 159     int outLen = 0; | 158     size_t outLen = 0; | 
| 160     if(_resampler.ResetIfNeeded(unresampledAudioFrame.sample_rate_hz_, | 159     if(_resampler.ResetIfNeeded(unresampledAudioFrame.sample_rate_hz_, | 
| 161                                 frequencyInHz, 1)) | 160                                 frequencyInHz, 1)) | 
| 162     { | 161     { | 
| 163         LOG(LS_WARNING) << "Get10msAudioFromFile() unexpected codec."; | 162         LOG(LS_WARNING) << "Get10msAudioFromFile() unexpected codec."; | 
| 164 | 163 | 
| 165         // New sampling frequency. Update state. | 164         // New sampling frequency. Update state. | 
| 166         outLen = frequencyInHz / 100; | 165         outLen = static_cast<size_t>(frequencyInHz / 100); | 
| 167         memset(outBuffer, 0, outLen * sizeof(int16_t)); | 166         memset(outBuffer, 0, outLen * sizeof(int16_t)); | 
| 168         return 0; | 167         return 0; | 
| 169     } | 168     } | 
| 170     _resampler.Push(unresampledAudioFrame.data_, | 169     _resampler.Push(unresampledAudioFrame.data_, | 
| 171                     unresampledAudioFrame.samples_per_channel_, | 170                     unresampledAudioFrame.samples_per_channel_, | 
| 172                     outBuffer, | 171                     outBuffer, | 
| 173                     MAX_AUDIO_BUFFER_IN_SAMPLES, | 172                     MAX_AUDIO_BUFFER_IN_SAMPLES, | 
| 174                     outLen); | 173                     outLen); | 
| 175 | 174 | 
| 176     lengthInSamples = outLen; | 175     lengthInSamples = outLen; | 
| 177 | 176 | 
| 178     if(_scaling != 1.0) | 177     if(_scaling != 1.0) | 
| 179     { | 178     { | 
| 180         for (int i = 0;i < outLen; i++) | 179         for (size_t i = 0;i < outLen; i++) | 
| 181         { | 180         { | 
| 182             outBuffer[i] = (int16_t)(outBuffer[i] * _scaling); | 181             outBuffer[i] = (int16_t)(outBuffer[i] * _scaling); | 
| 183         } | 182         } | 
| 184     } | 183     } | 
| 185     _decodedLengthInMS += 10; | 184     _decodedLengthInMS += 10; | 
| 186     return 0; | 185     return 0; | 
| 187 } | 186 } | 
| 188 | 187 | 
| 189 int32_t FilePlayerImpl::RegisterModuleFileCallback(FileCallback* callback) | 188 int32_t FilePlayerImpl::RegisterModuleFileCallback(FileCallback* callback) | 
| 190 { | 189 { | 
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 394     { | 393     { | 
| 395         LOG(LS_WARNING) << "SetUpAudioDecoder() codec " << _codec.plname | 394         LOG(LS_WARNING) << "SetUpAudioDecoder() codec " << _codec.plname | 
| 396                         << " not supported."; | 395                         << " not supported."; | 
| 397         return -1; | 396         return -1; | 
| 398     } | 397     } | 
| 399     _numberOf10MsPerFrame = _codec.pacsize / (_codec.plfreq / 100); | 398     _numberOf10MsPerFrame = _codec.pacsize / (_codec.plfreq / 100); | 
| 400     _numberOf10MsInDecoder = 0; | 399     _numberOf10MsInDecoder = 0; | 
| 401     return 0; | 400     return 0; | 
| 402 } | 401 } | 
| 403 }  // namespace webrtc | 402 }  // namespace webrtc | 
| OLD | NEW | 
|---|