2014-06-11 14:12:04 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
2016-11-29 05:30:40 -08:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_device/dummy/file_audio_device.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
|
|
|
|
#include "rtc_base/platform_thread.h"
|
|
|
|
|
#include "system_wrappers/include/sleep.h"
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-11-23 12:44:01 +01:00
|
|
|
const int kRecordingFixedSampleRate = 48000;
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
const size_t kRecordingNumChannels = 2;
|
2015-11-23 12:44:01 +01:00
|
|
|
const int kPlayoutFixedSampleRate = 48000;
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
const size_t kPlayoutNumChannels = 2;
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
const size_t kPlayoutBufferSize =
|
|
|
|
|
kPlayoutFixedSampleRate / 100 * kPlayoutNumChannels * 2;
|
|
|
|
|
const size_t kRecordingBufferSize =
|
|
|
|
|
kRecordingFixedSampleRate / 100 * kRecordingNumChannels * 2;
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-10-11 15:14:51 +02:00
|
|
|
FileAudioDevice::FileAudioDevice(const char* inputFilename,
|
2017-11-09 09:33:23 +01:00
|
|
|
const char* outputFilename)
|
|
|
|
|
: _ptrAudioBuffer(NULL),
|
|
|
|
|
_recordingBuffer(NULL),
|
|
|
|
|
_playoutBuffer(NULL),
|
|
|
|
|
_recordingFramesLeft(0),
|
|
|
|
|
_playoutFramesLeft(0),
|
|
|
|
|
_recordingBufferSizeIn10MS(0),
|
|
|
|
|
_recordingFramesIn10MS(0),
|
|
|
|
|
_playoutFramesIn10MS(0),
|
|
|
|
|
_playing(false),
|
|
|
|
|
_recording(false),
|
|
|
|
|
_lastCallPlayoutMillis(0),
|
|
|
|
|
_lastCallRecordMillis(0),
|
|
|
|
|
_outputFile(*FileWrapper::Create()),
|
|
|
|
|
_inputFile(*FileWrapper::Create()),
|
|
|
|
|
_outputFilename(outputFilename),
|
|
|
|
|
_inputFilename(inputFilename) {}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2016-10-28 06:51:59 -07:00
|
|
|
FileAudioDevice::~FileAudioDevice() {
|
|
|
|
|
delete &_outputFile;
|
|
|
|
|
delete &_inputFile;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-11 14:12:04 +00:00
|
|
|
int32_t FileAudioDevice::ActiveAudioLayer(
|
|
|
|
|
AudioDeviceModule::AudioLayer& audioLayer) const {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-01 13:35:19 +02:00
|
|
|
AudioDeviceGeneric::InitStatus FileAudioDevice::Init() {
|
|
|
|
|
return InitStatus::OK;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::Terminate() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
bool FileAudioDevice::Initialized() const {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
int16_t FileAudioDevice::PlayoutDevices() {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int16_t FileAudioDevice::RecordingDevices() {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::PlayoutDeviceName(uint16_t index,
|
2017-11-09 09:33:23 +01:00
|
|
|
char name[kAdmMaxDeviceNameSize],
|
|
|
|
|
char guid[kAdmMaxGuidSize]) {
|
2014-06-11 14:12:04 +00:00
|
|
|
const char* kName = "dummy_device";
|
|
|
|
|
const char* kGuid = "dummy_device_unique_id";
|
|
|
|
|
if (index < 1) {
|
|
|
|
|
memset(name, 0, kAdmMaxDeviceNameSize);
|
|
|
|
|
memset(guid, 0, kAdmMaxGuidSize);
|
|
|
|
|
memcpy(name, kName, strlen(kName));
|
|
|
|
|
memcpy(guid, kGuid, strlen(guid));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::RecordingDeviceName(uint16_t index,
|
2017-11-09 09:33:23 +01:00
|
|
|
char name[kAdmMaxDeviceNameSize],
|
|
|
|
|
char guid[kAdmMaxGuidSize]) {
|
2014-06-11 14:12:04 +00:00
|
|
|
const char* kName = "dummy_device";
|
|
|
|
|
const char* kGuid = "dummy_device_unique_id";
|
|
|
|
|
if (index < 1) {
|
|
|
|
|
memset(name, 0, kAdmMaxDeviceNameSize);
|
|
|
|
|
memset(guid, 0, kAdmMaxGuidSize);
|
|
|
|
|
memcpy(name, kName, strlen(kName));
|
|
|
|
|
memcpy(guid, kGuid, strlen(guid));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::SetPlayoutDevice(uint16_t index) {
|
|
|
|
|
if (index == 0) {
|
|
|
|
|
_playout_index = index;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::SetPlayoutDevice(
|
|
|
|
|
AudioDeviceModule::WindowsDeviceType device) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::SetRecordingDevice(uint16_t index) {
|
|
|
|
|
if (index == 0) {
|
|
|
|
|
_record_index = index;
|
|
|
|
|
return _record_index;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::SetRecordingDevice(
|
|
|
|
|
AudioDeviceModule::WindowsDeviceType device) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::PlayoutIsAvailable(bool& available) {
|
|
|
|
|
if (_playout_index == 0) {
|
|
|
|
|
available = true;
|
|
|
|
|
return _playout_index;
|
|
|
|
|
}
|
|
|
|
|
available = false;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::InitPlayout() {
|
2015-03-12 10:27:52 +00:00
|
|
|
if (_ptrAudioBuffer) {
|
2017-11-09 09:33:23 +01:00
|
|
|
// Update webrtc audio buffer with the selected parameters
|
|
|
|
|
_ptrAudioBuffer->SetPlayoutSampleRate(kPlayoutFixedSampleRate);
|
|
|
|
|
_ptrAudioBuffer->SetPlayoutChannels(kPlayoutNumChannels);
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FileAudioDevice::PlayoutIsInitialized() const {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::RecordingIsAvailable(bool& available) {
|
|
|
|
|
if (_record_index == 0) {
|
|
|
|
|
available = true;
|
|
|
|
|
return _record_index;
|
|
|
|
|
}
|
|
|
|
|
available = false;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::InitRecording() {
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope lock(&_critSect);
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
if (_recording) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
_recordingFramesIn10MS = static_cast<size_t>(kRecordingFixedSampleRate / 100);
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
if (_ptrAudioBuffer) {
|
|
|
|
|
_ptrAudioBuffer->SetRecordingSampleRate(kRecordingFixedSampleRate);
|
|
|
|
|
_ptrAudioBuffer->SetRecordingChannels(kRecordingNumChannels);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FileAudioDevice::RecordingIsInitialized() const {
|
2016-07-15 10:03:54 -07:00
|
|
|
return _recordingFramesIn10MS != 0;
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::StartPlayout() {
|
2015-03-12 10:27:52 +00:00
|
|
|
if (_playing) {
|
2017-11-09 09:33:23 +01:00
|
|
|
return 0;
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
_playoutFramesIn10MS = static_cast<size_t>(kPlayoutFixedSampleRate / 100);
|
2014-06-11 14:12:04 +00:00
|
|
|
_playing = true;
|
|
|
|
|
_playoutFramesLeft = 0;
|
|
|
|
|
|
2015-03-12 10:27:52 +00:00
|
|
|
if (!_playoutBuffer) {
|
2017-11-09 09:33:23 +01:00
|
|
|
_playoutBuffer = new int8_t[kPlayoutBufferSize];
|
2015-03-12 10:27:52 +00:00
|
|
|
}
|
|
|
|
|
if (!_playoutBuffer) {
|
2014-06-11 14:12:04 +00:00
|
|
|
_playing = false;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PLAYOUT
|
2016-10-28 06:51:59 -07:00
|
|
|
if (!_outputFilename.empty() &&
|
|
|
|
|
!_outputFile.OpenFile(_outputFilename.c_str(), false)) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << "Failed to open playout file: " << _outputFilename;
|
2016-10-28 06:51:59 -07:00
|
|
|
_playing = false;
|
2017-11-09 09:33:23 +01:00
|
|
|
delete[] _playoutBuffer;
|
2016-10-28 06:51:59 -07:00
|
|
|
_playoutBuffer = NULL;
|
|
|
|
|
return -1;
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-26 17:45:47 +01:00
|
|
|
_ptrThreadPlay.reset(new rtc::PlatformThread(
|
|
|
|
|
PlayThreadFunc, this, "webrtc_audio_module_play_thread"));
|
|
|
|
|
_ptrThreadPlay->Start();
|
|
|
|
|
_ptrThreadPlay->SetPriority(rtc::kRealtimePriority);
|
2016-08-17 15:14:48 -07:00
|
|
|
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "Started playout capture to output file: "
|
|
|
|
|
<< _outputFilename;
|
2014-06-11 14:12:04 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::StopPlayout() {
|
|
|
|
|
{
|
2017-11-09 09:33:23 +01:00
|
|
|
rtc::CritScope lock(&_critSect);
|
|
|
|
|
_playing = false;
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stop playout thread first
|
2015-03-19 14:44:18 +00:00
|
|
|
if (_ptrThreadPlay) {
|
2017-11-09 09:33:23 +01:00
|
|
|
_ptrThreadPlay->Stop();
|
|
|
|
|
_ptrThreadPlay.reset();
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope lock(&_critSect);
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
_playoutFramesLeft = 0;
|
2017-11-09 09:33:23 +01:00
|
|
|
delete[] _playoutBuffer;
|
2014-06-11 14:12:04 +00:00
|
|
|
_playoutBuffer = NULL;
|
2016-10-28 06:51:59 -07:00
|
|
|
_outputFile.CloseFile();
|
2016-08-17 15:14:48 -07:00
|
|
|
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "Stopped playout capture to output file: "
|
|
|
|
|
<< _outputFilename;
|
FileWrapper[Impl] modifications and actually remove the "Impl" class.
This is a somewhat involved refactoring of this class. Here's an overview of the changes:
* FileWrapper can now be used as a regular class and instances allocated on the stack.
* The type now has support for move semantics and copy isn't allowed.
* New public ctor with FILE* that can be used instead of OpenFromFileHandle.
* New static Open() method. The intent of this is to allow opening a file and getting back a FileWrapper instance. Using this method instead of Create(), will allow us in the future to make the FILE* member pointer, to be const and simplify threading (get rid of the lock).
* Rename the Open() method to is_open() and make it inline.
* The FileWrapper interface is no longer a pure virtual interface. There's only one implementation so there's no need to go through a vtable for everything.
* Functionality offered by the class, is now reduced. No support for looping (not clear if that was actually useful to users of that flag), no need to implement the 'read_only_' functionality in the class, since file APIs implement that already, no support for *not* managing the file handle (this wasn't used). OpenFromFileHandle always "manages" the file.
* Delete the unused WriteText() method and don't support opening files in text mode. Text mode is only different on Windows and on Windows it translates \n to \r\n, which means that files such as log files, could have a slightly different format on Windows than other platforms. Besides, tools on Windows can handle UNIX line endings.
* Remove FileName(), change Trace code to manage its own path.
* Rename id_ member variable to file_.
* Removed the open_ member variable since the same functionality can be gotten from just checking the file pointer.
* Don't call CloseFile inside of Write. Write shouldn't be changing the state of the class beyond just attempting to write.
* Remove concept of looping from FileWrapper and never close inside of Read()
* Changed stream base classes to inherit from a common base class instead of both defining the Rewind method. Ultimately, Id' like to remove these interfaces and just have FileWrapper.
* Remove read_only param from OpenFromFileHandle
* Renamed size_in_bytes_ to position_, since it gets set to 0 when Rewind() is called (and the size actually does not change).
* Switch out rw lock for CriticalSection. The r/w lock was only used for reading when checking the open_ flag.
BUG=
Review-Url: https://codereview.webrtc.org/2054373002
Cr-Commit-Position: refs/heads/master@{#13155}
2016-06-15 10:30:14 -07:00
|
|
|
return 0;
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FileAudioDevice::Playing() const {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::StartRecording() {
|
|
|
|
|
_recording = true;
|
|
|
|
|
|
|
|
|
|
// Make sure we only create the buffer once.
|
2017-11-09 09:33:23 +01:00
|
|
|
_recordingBufferSizeIn10MS =
|
|
|
|
|
_recordingFramesIn10MS * kRecordingNumChannels * 2;
|
2014-06-11 14:12:04 +00:00
|
|
|
if (!_recordingBuffer) {
|
2017-11-09 09:33:23 +01:00
|
|
|
_recordingBuffer = new int8_t[_recordingBufferSizeIn10MS];
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-10-28 06:51:59 -07:00
|
|
|
if (!_inputFilename.empty() &&
|
|
|
|
|
!_inputFile.OpenFile(_inputFilename.c_str(), true)) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << "Failed to open audio input file: " << _inputFilename;
|
2016-10-28 06:51:59 -07:00
|
|
|
_recording = false;
|
|
|
|
|
delete[] _recordingBuffer;
|
|
|
|
|
_recordingBuffer = NULL;
|
|
|
|
|
return -1;
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-26 17:45:47 +01:00
|
|
|
_ptrThreadRec.reset(new rtc::PlatformThread(
|
|
|
|
|
RecThreadFunc, this, "webrtc_audio_module_capture_thread"));
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2015-11-26 17:45:47 +01:00
|
|
|
_ptrThreadRec->Start();
|
|
|
|
|
_ptrThreadRec->SetPriority(rtc::kRealtimePriority);
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "Started recording from input file: " << _inputFilename;
|
2016-08-17 15:14:48 -07:00
|
|
|
|
2014-06-11 14:12:04 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::StopRecording() {
|
|
|
|
|
{
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope lock(&_critSect);
|
2014-06-11 14:12:04 +00:00
|
|
|
_recording = false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-19 14:44:18 +00:00
|
|
|
if (_ptrThreadRec) {
|
2017-11-09 09:33:23 +01:00
|
|
|
_ptrThreadRec->Stop();
|
|
|
|
|
_ptrThreadRec.reset();
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope lock(&_critSect);
|
2014-06-11 14:12:04 +00:00
|
|
|
_recordingFramesLeft = 0;
|
2015-03-12 10:27:52 +00:00
|
|
|
if (_recordingBuffer) {
|
2017-11-09 09:33:23 +01:00
|
|
|
delete[] _recordingBuffer;
|
|
|
|
|
_recordingBuffer = NULL;
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
2016-10-28 06:51:59 -07:00
|
|
|
_inputFile.CloseFile();
|
2016-08-17 15:14:48 -07:00
|
|
|
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "Stopped recording from input file: " << _inputFilename;
|
2014-06-11 14:12:04 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FileAudioDevice::Recording() const {
|
|
|
|
|
return _recording;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::SetAGC(bool enable) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
bool FileAudioDevice::AGC() const {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::InitSpeaker() {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
bool FileAudioDevice::SpeakerIsInitialized() const {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::InitMicrophone() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
bool FileAudioDevice::MicrophoneIsInitialized() const {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::SpeakerVolumeIsAvailable(bool& available) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::SetSpeakerVolume(uint32_t volume) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::SpeakerVolume(uint32_t& volume) const {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::MaxSpeakerVolume(uint32_t& maxVolume) const {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::MinSpeakerVolume(uint32_t& minVolume) const {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::MicrophoneVolumeIsAvailable(bool& available) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::SetMicrophoneVolume(uint32_t volume) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::MicrophoneVolume(uint32_t& volume) const {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::MaxMicrophoneVolume(uint32_t& maxVolume) const {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::MinMicrophoneVolume(uint32_t& minVolume) const {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::SpeakerMuteIsAvailable(bool& available) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::SetSpeakerMute(bool enable) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::SpeakerMute(bool& enabled) const {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::MicrophoneMuteIsAvailable(bool& available) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::SetMicrophoneMute(bool enable) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int32_t FileAudioDevice::MicrophoneMute(bool& enabled) const {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::StereoPlayoutIsAvailable(bool& available) {
|
|
|
|
|
available = true;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
int32_t FileAudioDevice::SetStereoPlayout(bool enable) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::StereoPlayout(bool& enabled) const {
|
|
|
|
|
enabled = true;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::StereoRecordingIsAvailable(bool& available) {
|
|
|
|
|
available = true;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::SetStereoRecording(bool enable) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::StereoRecording(bool& enabled) const {
|
|
|
|
|
enabled = true;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t FileAudioDevice::PlayoutDelay(uint16_t& delayMS) const {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileAudioDevice::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope lock(&_critSect);
|
2014-06-11 14:12:04 +00:00
|
|
|
|
|
|
|
|
_ptrAudioBuffer = audioBuffer;
|
|
|
|
|
|
|
|
|
|
// Inform the AudioBuffer about default settings for this implementation.
|
|
|
|
|
// Set all values to zero here since the actual settings will be done by
|
|
|
|
|
// InitPlayout and InitRecording later.
|
|
|
|
|
_ptrAudioBuffer->SetRecordingSampleRate(0);
|
|
|
|
|
_ptrAudioBuffer->SetPlayoutSampleRate(0);
|
|
|
|
|
_ptrAudioBuffer->SetRecordingChannels(0);
|
|
|
|
|
_ptrAudioBuffer->SetPlayoutChannels(0);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
bool FileAudioDevice::PlayThreadFunc(void* pThis) {
|
|
|
|
|
return (static_cast<FileAudioDevice*>(pThis)->PlayThreadProcess());
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
bool FileAudioDevice::RecThreadFunc(void* pThis) {
|
|
|
|
|
return (static_cast<FileAudioDevice*>(pThis)->RecThreadProcess());
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
bool FileAudioDevice::PlayThreadProcess() {
|
|
|
|
|
if (!_playing) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
int64_t currentTime = rtc::TimeMillis();
|
|
|
|
|
_critSect.Enter();
|
2016-01-07 12:38:31 -08:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
if (_lastCallPlayoutMillis == 0 ||
|
|
|
|
|
currentTime - _lastCallPlayoutMillis >= 10) {
|
2016-10-28 06:51:59 -07:00
|
|
|
_critSect.Leave();
|
2017-11-09 09:33:23 +01:00
|
|
|
_ptrAudioBuffer->RequestPlayoutData(_playoutFramesIn10MS);
|
|
|
|
|
_critSect.Enter();
|
2016-01-07 12:38:31 -08:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
_playoutFramesLeft = _ptrAudioBuffer->GetPlayoutData(_playoutBuffer);
|
|
|
|
|
RTC_DCHECK_EQ(_playoutFramesIn10MS, _playoutFramesLeft);
|
|
|
|
|
if (_outputFile.is_open()) {
|
|
|
|
|
_outputFile.Write(_playoutBuffer, kPlayoutBufferSize);
|
2016-10-28 06:51:59 -07:00
|
|
|
}
|
2017-11-09 09:33:23 +01:00
|
|
|
_lastCallPlayoutMillis = currentTime;
|
|
|
|
|
}
|
|
|
|
|
_playoutFramesLeft = 0;
|
|
|
|
|
_critSect.Leave();
|
|
|
|
|
|
|
|
|
|
int64_t deltaTimeMillis = rtc::TimeMillis() - currentTime;
|
|
|
|
|
if (deltaTimeMillis < 10) {
|
|
|
|
|
SleepMs(10 - deltaTimeMillis);
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
return true;
|
2016-10-28 02:08:23 -07:00
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
bool FileAudioDevice::RecThreadProcess() {
|
|
|
|
|
if (!_recording) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int64_t currentTime = rtc::TimeMillis();
|
|
|
|
|
_critSect.Enter();
|
2016-10-28 06:51:59 -07:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
if (_lastCallRecordMillis == 0 || currentTime - _lastCallRecordMillis >= 10) {
|
|
|
|
|
if (_inputFile.is_open()) {
|
|
|
|
|
if (_inputFile.Read(_recordingBuffer, kRecordingBufferSize) > 0) {
|
|
|
|
|
_ptrAudioBuffer->SetRecordedBuffer(_recordingBuffer,
|
|
|
|
|
_recordingFramesIn10MS);
|
|
|
|
|
} else {
|
|
|
|
|
_inputFile.Rewind();
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
2017-11-09 09:33:23 +01:00
|
|
|
_lastCallRecordMillis = currentTime;
|
|
|
|
|
_critSect.Leave();
|
|
|
|
|
_ptrAudioBuffer->DeliverRecordedData();
|
|
|
|
|
_critSect.Enter();
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
2017-11-09 09:33:23 +01:00
|
|
|
}
|
2014-06-11 14:12:04 +00:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
_critSect.Leave();
|
2016-01-07 12:38:31 -08:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
int64_t deltaTimeMillis = rtc::TimeMillis() - currentTime;
|
|
|
|
|
if (deltaTimeMillis < 10) {
|
|
|
|
|
SleepMs(10 - deltaTimeMillis);
|
|
|
|
|
}
|
2016-01-07 12:38:31 -08:00
|
|
|
|
2017-11-09 09:33:23 +01:00
|
|
|
return true;
|
2014-06-11 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|