2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-02-20 09:17:41 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-07-11 13:24:38 +00:00
|
|
|
#include "webrtc/modules/audio_device/audio_device_buffer.h"
|
2013-09-13 00:02:13 +00:00
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
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
|
|
|
#include "webrtc/base/format_macros.h"
|
2013-07-11 13:24:38 +00:00
|
|
|
#include "webrtc/modules/audio_device/audio_device_config.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
|
|
|
|
#include "webrtc/system_wrappers/include/logging.h"
|
|
|
|
|
#include "webrtc/system_wrappers/include/trace.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2013-09-11 22:35:00 +00:00
|
|
|
static const int kHighDelayThresholdMs = 300;
|
|
|
|
|
static const int kLogHighDelayIntervalFrames = 500; // 5 seconds.
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// ctor
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
AudioDeviceBuffer::AudioDeviceBuffer() :
|
|
|
|
|
_id(-1),
|
|
|
|
|
_critSect(*CriticalSectionWrapper::CreateCriticalSection()),
|
|
|
|
|
_critSectCb(*CriticalSectionWrapper::CreateCriticalSection()),
|
|
|
|
|
_ptrCbAudioTransport(NULL),
|
|
|
|
|
_recSampleRate(0),
|
|
|
|
|
_playSampleRate(0),
|
|
|
|
|
_recChannels(0),
|
|
|
|
|
_playChannels(0),
|
|
|
|
|
_recChannel(AudioDeviceModule::kChannelBoth),
|
|
|
|
|
_recBytesPerSample(0),
|
|
|
|
|
_playBytesPerSample(0),
|
|
|
|
|
_recSamples(0),
|
|
|
|
|
_recSize(0),
|
2011-08-04 15:33:30 +00:00
|
|
|
_playSamples(0),
|
2011-07-07 08:21:25 +00:00
|
|
|
_playSize(0),
|
|
|
|
|
_recFile(*FileWrapper::Create()),
|
|
|
|
|
_playFile(*FileWrapper::Create()),
|
|
|
|
|
_currentMicLevel(0),
|
2011-08-04 15:33:30 +00:00
|
|
|
_newMicLevel(0),
|
2013-05-07 21:04:24 +00:00
|
|
|
_typingStatus(false),
|
2011-07-07 08:21:25 +00:00
|
|
|
_playDelayMS(0),
|
|
|
|
|
_recDelayMS(0),
|
2013-09-11 22:35:00 +00:00
|
|
|
_clockDrift(0),
|
|
|
|
|
// Set to the interval in order to log on the first occurrence.
|
|
|
|
|
high_delay_counter_(kLogHighDelayIntervalFrames) {
|
2011-07-07 08:21:25 +00:00
|
|
|
// valid ID will be set later by SetId, use -1 for now
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s created", __FUNCTION__);
|
2011-12-06 10:02:56 +00:00
|
|
|
memset(_recBuffer, 0, kMaxBufferSizeBytes);
|
|
|
|
|
memset(_playBuffer, 0, kMaxBufferSizeBytes);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// dtor
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
AudioDeviceBuffer::~AudioDeviceBuffer()
|
|
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__);
|
|
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
_recFile.Flush();
|
|
|
|
|
_recFile.CloseFile();
|
|
|
|
|
delete &_recFile;
|
|
|
|
|
|
|
|
|
|
_playFile.Flush();
|
|
|
|
|
_playFile.CloseFile();
|
|
|
|
|
delete &_playFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete &_critSect;
|
|
|
|
|
delete &_critSectCb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// SetId
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
void AudioDeviceBuffer::SetId(uint32_t id)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "AudioDeviceBuffer::SetId(id=%d)", id);
|
|
|
|
|
_id = id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// RegisterAudioCallback
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::RegisterAudioCallback(AudioTransport* audioCallback)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSectCb);
|
2011-07-07 08:21:25 +00:00
|
|
|
_ptrCbAudioTransport = audioCallback;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// InitPlayout
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::InitPlayout()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// InitRecording
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::InitRecording()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// SetRecordingSampleRate
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::SetRecordingSampleRate(uint32_t fsHz)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
_recSampleRate = fsHz;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// SetPlayoutSampleRate
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::SetPlayoutSampleRate(uint32_t fsHz)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
_playSampleRate = fsHz;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// RecordingSampleRate
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::RecordingSampleRate() const
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
return _recSampleRate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// PlayoutSampleRate
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::PlayoutSampleRate() const
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
return _playSampleRate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// SetRecordingChannels
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
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
|
|
|
int32_t AudioDeviceBuffer::SetRecordingChannels(size_t channels)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
_recChannels = channels;
|
|
|
|
|
_recBytesPerSample = 2*channels; // 16 bits per sample in mono, 32 bits in stereo
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// SetPlayoutChannels
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
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
|
|
|
int32_t AudioDeviceBuffer::SetPlayoutChannels(size_t channels)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
_playChannels = channels;
|
|
|
|
|
// 16 bits per sample in mono, 32 bits in stereo
|
|
|
|
|
_playBytesPerSample = 2*channels;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// SetRecordingChannel
|
|
|
|
|
//
|
|
|
|
|
// Select which channel to use while recording.
|
|
|
|
|
// This API requires that stereo is enabled.
|
|
|
|
|
//
|
|
|
|
|
// Note that, the nChannel parameter in RecordedDataIsAvailable will be
|
|
|
|
|
// set to 2 even for kChannelLeft and kChannelRight. However, nBytesPerSample
|
|
|
|
|
// will be 2 instead of 4 four these cases.
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::SetRecordingChannel(const AudioDeviceModule::ChannelType channel)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if (_recChannels == 1)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (channel == AudioDeviceModule::kChannelBoth)
|
|
|
|
|
{
|
|
|
|
|
// two bytes per channel
|
|
|
|
|
_recBytesPerSample = 4;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// only utilize one out of two possible channels (left or right)
|
|
|
|
|
_recBytesPerSample = 2;
|
|
|
|
|
}
|
|
|
|
|
_recChannel = channel;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// RecordingChannel
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::RecordingChannel(AudioDeviceModule::ChannelType& channel) const
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
channel = _recChannel;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// RecordingChannels
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
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
|
|
|
size_t AudioDeviceBuffer::RecordingChannels() const
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
return _recChannels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// PlayoutChannels
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
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
|
|
|
size_t AudioDeviceBuffer::PlayoutChannels() const
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
return _playChannels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// SetCurrentMicLevel
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::SetCurrentMicLevel(uint32_t level)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
_currentMicLevel = level;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-07 21:04:24 +00:00
|
|
|
int32_t AudioDeviceBuffer::SetTypingStatus(bool typingStatus)
|
|
|
|
|
{
|
|
|
|
|
_typingStatus = typingStatus;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// NewMicLevel
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
uint32_t AudioDeviceBuffer::NewMicLevel() const
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
return _newMicLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// SetVQEData
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-09-12 01:01:42 +00:00
|
|
|
void AudioDeviceBuffer::SetVQEData(int playDelayMs, int recDelayMs,
|
|
|
|
|
int clockDrift) {
|
2013-09-11 22:35:00 +00:00
|
|
|
if (high_delay_counter_ < kLogHighDelayIntervalFrames) {
|
|
|
|
|
++high_delay_counter_;
|
|
|
|
|
} else {
|
|
|
|
|
if (playDelayMs + recDelayMs > kHighDelayThresholdMs) {
|
|
|
|
|
high_delay_counter_ = 0;
|
|
|
|
|
LOG(LS_WARNING) << "High audio device delay reported (render="
|
|
|
|
|
<< playDelayMs << " ms, capture=" << recDelayMs << " ms)";
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-09-11 22:35:00 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-09-11 22:35:00 +00:00
|
|
|
_playDelayMS = playDelayMs;
|
|
|
|
|
_recDelayMS = recDelayMs;
|
|
|
|
|
_clockDrift = clockDrift;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// StartInputFileRecording
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::StartInputFileRecording(
|
2012-03-01 18:01:48 +00:00
|
|
|
const char fileName[kAdmMaxFileNameSize])
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__);
|
|
|
|
|
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
_recFile.Flush();
|
|
|
|
|
_recFile.CloseFile();
|
|
|
|
|
|
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 _recFile.OpenFile(fileName, false) ? 0 : -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// StopInputFileRecording
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::StopInputFileRecording()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__);
|
|
|
|
|
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
_recFile.Flush();
|
|
|
|
|
_recFile.CloseFile();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// StartOutputFileRecording
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::StartOutputFileRecording(
|
2012-03-01 18:01:48 +00:00
|
|
|
const char fileName[kAdmMaxFileNameSize])
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__);
|
|
|
|
|
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
_playFile.Flush();
|
|
|
|
|
_playFile.CloseFile();
|
|
|
|
|
|
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 _playFile.OpenFile(fileName, false) ? 0 : -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// StopOutputFileRecording
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::StopOutputFileRecording()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__);
|
|
|
|
|
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
_playFile.Flush();
|
|
|
|
|
_playFile.CloseFile();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// SetRecordedBuffer
|
|
|
|
|
//
|
|
|
|
|
// Store recorded audio buffer in local memory ready for the actual
|
|
|
|
|
// "delivery" using a callback.
|
|
|
|
|
//
|
|
|
|
|
// This method can also parse out left or right channel from a stereo
|
|
|
|
|
// input signal, i.e., emulate mono.
|
|
|
|
|
//
|
|
|
|
|
// Examples:
|
|
|
|
|
//
|
|
|
|
|
// 16-bit,48kHz mono, 10ms => nSamples=480 => _recSize=2*480=960 bytes
|
2011-11-25 02:45:39 +00:00
|
|
|
// 16-bit,48kHz stereo,10ms => nSamples=480 => _recSize=4*480=1920 bytes
|
2011-07-07 08:21:25 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::SetRecordedBuffer(const void* audioBuffer,
|
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
|
|
|
size_t nSamples)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if (_recBytesPerSample == 0)
|
|
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_recSamples = nSamples;
|
|
|
|
|
_recSize = _recBytesPerSample*nSamples; // {2,4}*nSamples
|
2011-11-25 02:45:39 +00:00
|
|
|
if (_recSize > kMaxBufferSizeBytes)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_recChannel == AudioDeviceModule::kChannelBoth)
|
|
|
|
|
{
|
|
|
|
|
// (default) copy the complete input buffer to the local buffer
|
|
|
|
|
memcpy(&_recBuffer[0], audioBuffer, _recSize);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-04-09 10:30:35 +00:00
|
|
|
int16_t* ptr16In = (int16_t*)audioBuffer;
|
|
|
|
|
int16_t* ptr16Out = (int16_t*)&_recBuffer[0];
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if (AudioDeviceModule::kChannelRight == _recChannel)
|
|
|
|
|
{
|
|
|
|
|
ptr16In++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// exctract left or right channel from input buffer to the local buffer
|
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
|
|
|
for (size_t i = 0; i < _recSamples; i++)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
*ptr16Out = *ptr16In;
|
|
|
|
|
ptr16Out++;
|
|
|
|
|
ptr16In++;
|
|
|
|
|
ptr16In++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
if (_recFile.is_open()) {
|
|
|
|
|
// write to binary file in mono or stereo (interleaved)
|
|
|
|
|
_recFile.Write(&_recBuffer[0], _recSize);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// DeliverRecordedData
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::DeliverRecordedData()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSectCb);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Ensure that user has initialized all essential members
|
|
|
|
|
if ((_recSampleRate == 0) ||
|
|
|
|
|
(_recSamples == 0) ||
|
|
|
|
|
(_recBytesPerSample == 0) ||
|
|
|
|
|
(_recChannels == 0))
|
|
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_ptrCbAudioTransport == NULL)
|
|
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "failed to deliver recorded data (AudioTransport does not exist)");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t res(0);
|
|
|
|
|
uint32_t newMicLevel(0);
|
|
|
|
|
uint32_t totalDelayMS = _playDelayMS +_recDelayMS;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
res = _ptrCbAudioTransport->RecordedDataIsAvailable(&_recBuffer[0],
|
|
|
|
|
_recSamples,
|
|
|
|
|
_recBytesPerSample,
|
|
|
|
|
_recChannels,
|
|
|
|
|
_recSampleRate,
|
|
|
|
|
totalDelayMS,
|
|
|
|
|
_clockDrift,
|
|
|
|
|
_currentMicLevel,
|
2013-05-07 21:04:24 +00:00
|
|
|
_typingStatus,
|
2011-07-07 08:21:25 +00:00
|
|
|
newMicLevel);
|
|
|
|
|
if (res != -1)
|
|
|
|
|
{
|
|
|
|
|
_newMicLevel = newMicLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// RequestPlayoutData
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
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
|
|
|
int32_t AudioDeviceBuffer::RequestPlayoutData(size_t nSamples)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2013-04-09 10:30:35 +00:00
|
|
|
uint32_t playSampleRate = 0;
|
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
|
|
|
size_t playBytesPerSample = 0;
|
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
|
|
|
size_t playChannels = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-05 14:34:57 +00:00
|
|
|
// Store copies under lock and use copies hereafter to avoid race with
|
|
|
|
|
// setter methods.
|
|
|
|
|
playSampleRate = _playSampleRate;
|
|
|
|
|
playBytesPerSample = _playBytesPerSample;
|
|
|
|
|
playChannels = _playChannels;
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// Ensure that user has initialized all essential members
|
2013-04-05 14:34:57 +00:00
|
|
|
if ((playBytesPerSample == 0) ||
|
|
|
|
|
(playChannels == 0) ||
|
|
|
|
|
(playSampleRate == 0))
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_playSamples = nSamples;
|
2013-04-05 14:34:57 +00:00
|
|
|
_playSize = playBytesPerSample * nSamples; // {2,4}*nSamples
|
2011-11-25 02:45:39 +00:00
|
|
|
if (_playSize > kMaxBufferSizeBytes)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nSamples != _playSamples)
|
|
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "invalid number of samples to be played out (%d)", nSamples);
|
|
|
|
|
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
|
|
|
size_t nSamplesOut(0);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSectCb);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if (_ptrCbAudioTransport == NULL)
|
|
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "failed to feed data to playout (AudioTransport does not exist)");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_ptrCbAudioTransport)
|
|
|
|
|
{
|
2013-04-09 10:30:35 +00:00
|
|
|
uint32_t res(0);
|
2014-06-05 20:34:08 +00:00
|
|
|
int64_t elapsed_time_ms = -1;
|
|
|
|
|
int64_t ntp_time_ms = -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
res = _ptrCbAudioTransport->NeedMorePlayData(_playSamples,
|
2013-04-05 14:34:57 +00:00
|
|
|
playBytesPerSample,
|
|
|
|
|
playChannels,
|
|
|
|
|
playSampleRate,
|
2011-07-07 08:21:25 +00:00
|
|
|
&_playBuffer[0],
|
2014-05-19 17:39:11 +00:00
|
|
|
nSamplesOut,
|
2014-06-05 20:34:08 +00:00
|
|
|
&elapsed_time_ms,
|
2014-05-19 17:39:11 +00:00
|
|
|
&ntp_time_ms);
|
2011-07-07 08:21:25 +00:00
|
|
|
if (res != 0)
|
|
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "NeedMorePlayData() failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
return static_cast<int32_t>(nSamplesOut);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// GetPlayoutData
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2013-04-09 10:30:35 +00:00
|
|
|
int32_t AudioDeviceBuffer::GetPlayoutData(void* audioBuffer)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-12 12:15:51 +00:00
|
|
|
CriticalSectionScoped lock(&_critSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-11-29 18:49:54 +00:00
|
|
|
if (_playSize > kMaxBufferSizeBytes)
|
|
|
|
|
{
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceUtility, _id,
|
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
|
|
|
"_playSize %" PRIuS " exceeds kMaxBufferSizeBytes in "
|
Reformat existing code. There should be no functional effects.
This includes changes like:
* Attempt to break lines at better positions
* Use "override" in more places, don't use "virtual" with it
* Use {} where the body is more than one line
* Make declaration and definition arg names match
* Eliminate unused code
* EXPECT_EQ(expected, actual) (but use (actual, expected) for e.g. _GT)
* Correct #include order
* Use anonymous namespaces in preference to "static" for file-scoping
* Eliminate unnecessary casts
* Update reference code in comments of ARM assembly sources to match actual current C code
* Fix indenting to be more style-guide compliant
* Use arraysize() in more places
* Use bool instead of int for "boolean" values (0/1)
* Shorten and simplify code
* Spaces around operators
* 80 column limit
* Use const more consistently
* Space goes after '*' in type name, not before
* Remove unnecessary return values
* Use "(var == const)", not "(const == var)"
* Spelling
* Prefer true, typed constants to "enum hack" constants
* Avoid "virtual" on non-overridden functions
* ASSERT(x == y) -> ASSERT_EQ(y, x)
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kjellander@webrtc.org, kwiberg@webrtc.org
Review URL: https://codereview.webrtc.org/1172163004
Cr-Commit-Position: refs/heads/master@{#9420}
2015-06-11 14:31:38 -07:00
|
|
|
"AudioDeviceBuffer::GetPlayoutData", _playSize);
|
2011-11-29 18:49:54 +00:00
|
|
|
assert(false);
|
2012-03-01 18:01:48 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2011-11-29 18:49:54 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
memcpy(audioBuffer, &_playBuffer[0], _playSize);
|
|
|
|
|
|
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
|
|
|
if (_playFile.is_open()) {
|
|
|
|
|
// write to binary file in mono or stereo (interleaved)
|
|
|
|
|
_playFile.Write(&_playBuffer[0], _playSize);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
return static_cast<int32_t>(_playSamples);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|