| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 #include "webrtc/base/logging.h" | 10 #include "webrtc/base/logging.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 _recordingBufferSizeIn10MS(0), | 35 _recordingBufferSizeIn10MS(0), |
| 36 _recordingFramesIn10MS(0), | 36 _recordingFramesIn10MS(0), |
| 37 _playoutFramesIn10MS(0), | 37 _playoutFramesIn10MS(0), |
| 38 _playing(false), | 38 _playing(false), |
| 39 _recording(false), | 39 _recording(false), |
| 40 _lastCallPlayoutMillis(0), | 40 _lastCallPlayoutMillis(0), |
| 41 _lastCallRecordMillis(0), | 41 _lastCallRecordMillis(0), |
| 42 _outputFile(*FileWrapper::Create()), | 42 _outputFile(*FileWrapper::Create()), |
| 43 _inputFile(*FileWrapper::Create()), | 43 _inputFile(*FileWrapper::Create()), |
| 44 _outputFilename(outputFilename), | 44 _outputFilename(outputFilename), |
| 45 _inputFilename(inputFilename), | 45 _inputFilename(inputFilename) { |
| 46 _clock(Clock::GetRealTimeClock()) { | |
| 47 } | 46 } |
| 48 | 47 |
| 49 FileAudioDevice::~FileAudioDevice() { | 48 FileAudioDevice::~FileAudioDevice() { |
| 50 delete &_outputFile; | 49 delete &_outputFile; |
| 51 delete &_inputFile; | 50 delete &_inputFile; |
| 52 } | 51 } |
| 53 | 52 |
| 54 int32_t FileAudioDevice::ActiveAudioLayer( | 53 int32_t FileAudioDevice::ActiveAudioLayer( |
| 55 AudioDeviceModule::AudioLayer& audioLayer) const { | 54 AudioDeviceModule::AudioLayer& audioLayer) const { |
| 56 return -1; | 55 return -1; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 return (static_cast<FileAudioDevice*>(pThis)->PlayThreadProcess()); | 472 return (static_cast<FileAudioDevice*>(pThis)->PlayThreadProcess()); |
| 474 } | 473 } |
| 475 | 474 |
| 476 bool FileAudioDevice::RecThreadFunc(void* pThis) | 475 bool FileAudioDevice::RecThreadFunc(void* pThis) |
| 477 { | 476 { |
| 478 return (static_cast<FileAudioDevice*>(pThis)->RecThreadProcess()); | 477 return (static_cast<FileAudioDevice*>(pThis)->RecThreadProcess()); |
| 479 } | 478 } |
| 480 | 479 |
| 481 bool FileAudioDevice::PlayThreadProcess() | 480 bool FileAudioDevice::PlayThreadProcess() |
| 482 { | 481 { |
| 483 if(!_playing) { | 482 if (!_playing) { |
| 484 return false; | 483 return false; |
| 485 } | 484 } |
| 486 uint64_t currentTime = _clock->CurrentNtpInMilliseconds(); | 485 int64_t currentTime = rtc::TimeMillis(); |
| 487 _critSect.Enter(); | 486 _critSect.Enter(); |
| 488 | 487 |
| 489 if (_lastCallPlayoutMillis == 0 || | 488 if (_lastCallPlayoutMillis == 0 || |
| 490 currentTime - _lastCallPlayoutMillis >= 10) { | 489 currentTime - _lastCallPlayoutMillis >= 10) { |
| 491 _critSect.Leave(); | 490 _critSect.Leave(); |
| 492 _ptrAudioBuffer->RequestPlayoutData(_playoutFramesIn10MS); | 491 _ptrAudioBuffer->RequestPlayoutData(_playoutFramesIn10MS); |
| 493 _critSect.Enter(); | 492 _critSect.Enter(); |
| 494 | 493 |
| 495 _playoutFramesLeft = _ptrAudioBuffer->GetPlayoutData(_playoutBuffer); | 494 _playoutFramesLeft = _ptrAudioBuffer->GetPlayoutData(_playoutBuffer); |
| 496 assert(_playoutFramesLeft == _playoutFramesIn10MS); | 495 assert(_playoutFramesLeft == _playoutFramesIn10MS); |
| 497 if (_outputFile.is_open()) { | 496 if (_outputFile.is_open()) { |
| 498 _outputFile.Write(_playoutBuffer, kPlayoutBufferSize); | 497 _outputFile.Write(_playoutBuffer, kPlayoutBufferSize); |
| 499 } | 498 } |
| 500 _lastCallPlayoutMillis = currentTime; | 499 _lastCallPlayoutMillis = currentTime; |
| 501 } | 500 } |
| 502 _playoutFramesLeft = 0; | 501 _playoutFramesLeft = 0; |
| 503 _critSect.Leave(); | 502 _critSect.Leave(); |
| 504 | 503 |
| 505 uint64_t deltaTimeMillis = _clock->CurrentNtpInMilliseconds() - currentTime; | 504 int64_t deltaTimeMillis = rtc::TimeMillis() - currentTime; |
| 506 if(deltaTimeMillis < 10) { | 505 if (deltaTimeMillis < 10) { |
| 507 SleepMs(10 - deltaTimeMillis); | 506 SleepMs(10 - deltaTimeMillis); |
| 508 } | 507 } |
| 509 | 508 |
| 510 return true; | 509 return true; |
| 511 } | 510 } |
| 512 | 511 |
| 513 bool FileAudioDevice::RecThreadProcess() | 512 bool FileAudioDevice::RecThreadProcess() |
| 514 { | 513 { |
| 515 if (!_recording) { | 514 if (!_recording) { |
| 516 return false; | 515 return false; |
| 517 } | 516 } |
| 518 | 517 |
| 519 uint64_t currentTime = _clock->CurrentNtpInMilliseconds(); | 518 int64_t currentTime = rtc::TimeMillis(); |
| 520 _critSect.Enter(); | 519 _critSect.Enter(); |
| 521 | 520 |
| 522 if (_lastCallRecordMillis == 0 || | 521 if (_lastCallRecordMillis == 0 || |
| 523 currentTime - _lastCallRecordMillis >= 10) { | 522 currentTime - _lastCallRecordMillis >= 10) { |
| 524 if (_inputFile.is_open()) { | 523 if (_inputFile.is_open()) { |
| 525 if (_inputFile.Read(_recordingBuffer, kRecordingBufferSize) > 0) { | 524 if (_inputFile.Read(_recordingBuffer, kRecordingBufferSize) > 0) { |
| 526 _ptrAudioBuffer->SetRecordedBuffer(_recordingBuffer, | 525 _ptrAudioBuffer->SetRecordedBuffer(_recordingBuffer, |
| 527 _recordingFramesIn10MS); | 526 _recordingFramesIn10MS); |
| 528 } else { | 527 } else { |
| 529 _inputFile.Rewind(); | 528 _inputFile.Rewind(); |
| 530 } | 529 } |
| 531 _lastCallRecordMillis = currentTime; | 530 _lastCallRecordMillis = currentTime; |
| 532 _critSect.Leave(); | 531 _critSect.Leave(); |
| 533 _ptrAudioBuffer->DeliverRecordedData(); | 532 _ptrAudioBuffer->DeliverRecordedData(); |
| 534 _critSect.Enter(); | 533 _critSect.Enter(); |
| 535 } | 534 } |
| 536 } | 535 } |
| 537 | 536 |
| 538 _critSect.Leave(); | 537 _critSect.Leave(); |
| 539 | 538 |
| 540 uint64_t deltaTimeMillis = _clock->CurrentNtpInMilliseconds() - currentTime; | 539 int64_t deltaTimeMillis = rtc::TimeMillis() - currentTime; |
| 541 if(deltaTimeMillis < 10) { | 540 if (deltaTimeMillis < 10) { |
| 542 SleepMs(10 - deltaTimeMillis); | 541 SleepMs(10 - deltaTimeMillis); |
| 543 } | 542 } |
| 544 | 543 |
| 545 return true; | 544 return true; |
| 546 } | 545 } |
| 547 | 546 |
| 548 } // namespace webrtc | 547 } // namespace webrtc |
| OLD | NEW |