Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc
diff --git a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc
index f7315de2afc7177dabe041a4fe59cdcf572c4f35..492b66463de09b089a238dc0a78b370a4cfc10e9 100644
--- a/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc
+++ b/webrtc/modules/audio_device/linux/audio_device_alsa_linux.cc
@@ -60,52 +60,50 @@ static const unsigned int ALSA_CAPTURE_WAIT_TIMEOUT = 5; // in ms
#define FUNC_GET_DEVICE_NAME 1
#define FUNC_GET_DEVICE_NAME_FOR_AN_ENUM 2
-AudioDeviceLinuxALSA::AudioDeviceLinuxALSA(const int32_t id) :
- _ptrAudioBuffer(NULL),
- _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
- _id(id),
- _mixerManager(id),
- _inputDeviceIndex(0),
- _outputDeviceIndex(0),
- _inputDeviceIsSpecified(false),
- _outputDeviceIsSpecified(false),
- _handleRecord(NULL),
- _handlePlayout(NULL),
- _recordingBuffersizeInFrame(0),
- _recordingPeriodSizeInFrame(0),
- _playoutBufferSizeInFrame(0),
- _playoutPeriodSizeInFrame(0),
- _recordingBufferSizeIn10MS(0),
- _playoutBufferSizeIn10MS(0),
- _recordingFramesIn10MS(0),
- _playoutFramesIn10MS(0),
- _recordingFreq(ALSA_CAPTURE_FREQ),
- _playoutFreq(ALSA_PLAYOUT_FREQ),
- _recChannels(ALSA_CAPTURE_CH),
- _playChannels(ALSA_PLAYOUT_CH),
- _recordingBuffer(NULL),
- _playoutBuffer(NULL),
- _recordingFramesLeft(0),
- _playoutFramesLeft(0),
- _playBufType(AudioDeviceModule::kFixedBufferSize),
- _initialized(false),
- _recording(false),
- _playing(false),
- _recIsInitialized(false),
- _playIsInitialized(false),
- _AGC(false),
- _recordingDelay(0),
- _playoutDelay(0),
- _playWarning(0),
- _playError(0),
- _recWarning(0),
- _recError(0),
- _playBufDelay(80),
- _playBufDelayFixed(80)
-{
- memset(_oldKeyState, 0, sizeof(_oldKeyState));
- WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id,
- "%s created", __FUNCTION__);
+AudioDeviceLinuxALSA::AudioDeviceLinuxALSA(const int32_t id)
+ : _ptrAudioBuffer(nullptr),
+ _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
+ _id(id),
+ _mixerManager(id),
+ _inputDeviceIndex(0),
+ _outputDeviceIndex(0),
+ _inputDeviceIsSpecified(false),
+ _outputDeviceIsSpecified(false),
+ _handleRecord(nullptr),
+ _handlePlayout(nullptr),
+ _recordingBuffersizeInFrame(0),
+ _recordingPeriodSizeInFrame(0),
+ _playoutBufferSizeInFrame(0),
+ _playoutPeriodSizeInFrame(0),
+ _recordingBufferSizeIn10MS(0),
+ _playoutBufferSizeIn10MS(0),
+ _recordingFramesIn10MS(0),
+ _playoutFramesIn10MS(0),
+ _recordingFreq(ALSA_CAPTURE_FREQ),
+ _playoutFreq(ALSA_PLAYOUT_FREQ),
+ _recChannels(ALSA_CAPTURE_CH),
+ _playChannels(ALSA_PLAYOUT_CH),
+ _recordingBuffer(nullptr),
+ _playoutBuffer(nullptr),
+ _recordingFramesLeft(0),
+ _playoutFramesLeft(0),
+ _playBufType(AudioDeviceModule::kFixedBufferSize),
+ _initialized(false),
+ _recording(false),
+ _playing(false),
+ _recIsInitialized(false),
+ _playIsInitialized(false),
+ _AGC(false),
+ _recordingDelay(0),
+ _playoutDelay(0),
+ _playWarning(0),
+ _playError(0),
+ _recWarning(0),
+ _recError(0),
+ _playBufDelay(80),
+ _playBufDelayFixed(80) {
+ memset(_oldKeyState, 0, sizeof(_oldKeyState));
+ WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created", __FUNCTION__);
}
// ----------------------------------------------------------------------------
@@ -123,12 +121,12 @@ AudioDeviceLinuxALSA::~AudioDeviceLinuxALSA()
if (_recordingBuffer)
{
delete [] _recordingBuffer;
- _recordingBuffer = NULL;
+ _recordingBuffer = nullptr;
}
if (_playoutBuffer)
{
delete [] _playoutBuffer;
- _playoutBuffer = NULL;
+ _playoutBuffer = nullptr;
}
delete &_critSect;
}
@@ -171,10 +169,10 @@ AudioDeviceGeneric::InitStatus AudioDeviceLinuxALSA::Init() {
}
#if defined(USE_X11)
//Get X display handle for typing detection
- _XDisplay = XOpenDisplay(NULL);
- if (!_XDisplay) {
- LOG(LS_WARNING)
- << "failed to open X display, typing detection will not work";
+ _XDisplay = XOpenDisplay(nullptr);
+ if (!_XDisplay) {
+ LOG(LS_WARNING)
+ << "failed to open X display, typing detection will not work";
}
#endif
_playWarning = 0;
@@ -225,7 +223,7 @@ int32_t AudioDeviceLinuxALSA::Terminate()
if (_XDisplay)
{
XCloseDisplay(_XDisplay);
- _XDisplay = NULL;
+ _XDisplay = nullptr;
}
#endif
_initialized = false;
@@ -861,16 +859,14 @@ int32_t AudioDeviceLinuxALSA::PlayoutDeviceName(
const uint16_t nDevices(PlayoutDevices());
- if ((index > (nDevices-1)) || (name == NULL))
- {
- return -1;
+ if ((index > (nDevices - 1)) || (name == nullptr)) {
+ return -1;
}
memset(name, 0, kAdmMaxDeviceNameSize);
- if (guid != NULL)
- {
- memset(guid, 0, kAdmMaxGuidSize);
+ if (guid != nullptr) {
+ memset(guid, 0, kAdmMaxGuidSize);
}
return GetDevicesInfo(1, true, index, name, kAdmMaxDeviceNameSize);
@@ -884,16 +880,14 @@ int32_t AudioDeviceLinuxALSA::RecordingDeviceName(
const uint16_t nDevices(RecordingDevices());
- if ((index > (nDevices-1)) || (name == NULL))
- {
- return -1;
+ if ((index > (nDevices - 1)) || (name == nullptr)) {
+ return -1;
}
memset(name, 0, kAdmMaxDeviceNameSize);
- if (guid != NULL)
- {
- memset(guid, 0, kAdmMaxGuidSize);
+ if (guid != nullptr) {
+ memset(guid, 0, kAdmMaxGuidSize);
}
return GetDevicesInfo(1, false, index, name, kAdmMaxDeviceNameSize);
@@ -1033,17 +1027,16 @@ int32_t AudioDeviceLinuxALSA::InitPlayout()
// Start by closing any existing wave-output devices
//
- if (_handlePlayout != NULL)
- {
- LATE(snd_pcm_close)(_handlePlayout);
- _handlePlayout = NULL;
- _playIsInitialized = false;
- if (errVal < 0)
- {
- WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
- " Error closing current playout sound device, error:"
- " %s", LATE(snd_strerror)(errVal));
- }
+ if (_handlePlayout != nullptr) {
+ LATE(snd_pcm_close)(_handlePlayout);
+ _handlePlayout = nullptr;
+ _playIsInitialized = false;
+ if (errVal < 0) {
+ WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
+ " Error closing current playout sound device, error:"
+ " %s",
+ LATE(snd_strerror)(errVal));
+ }
}
// Open PCM device for playout
@@ -1082,7 +1075,7 @@ int32_t AudioDeviceLinuxALSA::InitPlayout()
" unable to open playback device: %s (%d)",
LATE(snd_strerror)(errVal),
errVal);
- _handlePlayout = NULL;
+ _handlePlayout = nullptr;
return -1;
}
@@ -1107,7 +1100,7 @@ int32_t AudioDeviceLinuxALSA::InitPlayout()
errVal);
ErrorRecovery(errVal, _handlePlayout);
errVal = LATE(snd_pcm_close)(_handlePlayout);
- _handlePlayout = NULL;
+ _handlePlayout = nullptr;
return -1;
}
@@ -1144,10 +1137,9 @@ int32_t AudioDeviceLinuxALSA::InitPlayout()
_playWarning = 0;
_playError = 0;
- if (_handlePlayout != NULL)
- {
- _playIsInitialized = true;
- return 0;
+ if (_handlePlayout != nullptr) {
+ _playIsInitialized = true;
+ return 0;
}
else
{
@@ -1188,18 +1180,16 @@ int32_t AudioDeviceLinuxALSA::InitRecording()
// Start by closing any existing pcm-input devices
//
- if (_handleRecord != NULL)
- {
- int errVal = LATE(snd_pcm_close)(_handleRecord);
- _handleRecord = NULL;
- _recIsInitialized = false;
- if (errVal < 0)
- {
- WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
- " Error closing current recording sound device,"
- " error: %s",
- LATE(snd_strerror)(errVal));
- }
+ if (_handleRecord != nullptr) {
+ int errVal = LATE(snd_pcm_close)(_handleRecord);
+ _handleRecord = nullptr;
+ _recIsInitialized = false;
+ if (errVal < 0) {
+ WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
+ " Error closing current recording sound device,"
+ " error: %s",
+ LATE(snd_strerror)(errVal));
+ }
}
// Open PCM device for recording
@@ -1238,7 +1228,7 @@ int32_t AudioDeviceLinuxALSA::InitRecording()
WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
" unable to open record device: %s",
LATE(snd_strerror)(errVal));
- _handleRecord = NULL;
+ _handleRecord = nullptr;
return -1;
}
@@ -1281,7 +1271,7 @@ int32_t AudioDeviceLinuxALSA::InitRecording()
LATE(snd_strerror)(errVal), errVal);
ErrorRecovery(errVal, _handleRecord);
errVal = LATE(snd_pcm_close)(_handleRecord);
- _handleRecord = NULL;
+ _handleRecord = nullptr;
return -1;
}
}
@@ -1314,11 +1304,10 @@ int32_t AudioDeviceLinuxALSA::InitRecording()
_recordingBufferSizeIn10MS = LATE(snd_pcm_frames_to_bytes)(
_handleRecord, _recordingFramesIn10MS);
- if (_handleRecord != NULL)
- {
- // Mark recording side as initialized
- _recIsInitialized = true;
- return 0;
+ if (_handleRecord != nullptr) {
+ // Mark recording side as initialized
+ _recIsInitialized = true;
+ return 0;
}
else
{
@@ -1404,9 +1393,8 @@ int32_t AudioDeviceLinuxALSA::StopRecording()
return 0;
}
- if (_handleRecord == NULL)
- {
- return -1;
+ if (_handleRecord == nullptr) {
+ return -1;
}
// Make sure we don't start recording (it's asynchronous).
@@ -1425,7 +1413,7 @@ int32_t AudioDeviceLinuxALSA::StopRecording()
if (_recordingBuffer)
{
delete [] _recordingBuffer;
- _recordingBuffer = NULL;
+ _recordingBuffer = nullptr;
}
// Stop and close pcm recording device.
@@ -1455,8 +1443,8 @@ int32_t AudioDeviceLinuxALSA::StopRecording()
SetMicrophoneMute(false);
}
- // set the pcm input handle to NULL
- _handleRecord = NULL;
+ // set the pcm input handle to null
+ _handleRecord = nullptr;
return 0;
}
@@ -1530,9 +1518,8 @@ int32_t AudioDeviceLinuxALSA::StopPlayout()
return 0;
}
- if (_handlePlayout == NULL)
- {
- return -1;
+ if (_handlePlayout == nullptr) {
+ return -1;
}
_playing = false;
@@ -1549,7 +1536,7 @@ int32_t AudioDeviceLinuxALSA::StopPlayout()
_playoutFramesLeft = 0;
delete [] _playoutBuffer;
- _playoutBuffer = NULL;
+ _playoutBuffer = nullptr;
// stop and close pcm playout device
int errVal = LATE(snd_pcm_drop)(_handlePlayout);
@@ -1566,11 +1553,11 @@ int32_t AudioDeviceLinuxALSA::StopPlayout()
" Error closing playout sound device, error: %s",
LATE(snd_strerror)(errVal));
- // set the pcm input handle to NULL
+ // set the pcm input handle to null
_playIsInitialized = false;
- _handlePlayout = NULL;
+ _handlePlayout = nullptr;
WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
- " handle_playout is now set to NULL");
+ " handle_playout is now set to null");
return 0;
}
@@ -1741,82 +1728,71 @@ int32_t AudioDeviceLinuxALSA::GetDevicesInfo(
return 0;
}
- for (void **list = hints; *list != NULL; ++list)
- {
- char *actualType = LATE(snd_device_name_get_hint)(*list, "IOID");
- if (actualType)
- { // NULL means it's both.
- bool wrongType = (strcmp(actualType, type) != 0);
- free(actualType);
- if (wrongType)
- {
- // Wrong type of device (i.e., input vs. output).
- continue;
- }
+ for (void** list = hints; *list != nullptr; ++list) {
+ char* actualType = LATE(snd_device_name_get_hint)(*list, "IOID");
+ if (actualType) { // nullptr means it's both.
+ bool wrongType = (strcmp(actualType, type) != 0);
+ free(actualType);
+ if (wrongType) {
+ // Wrong type of device (i.e., input vs. output).
+ continue;
}
+ }
- char *name = LATE(snd_device_name_get_hint)(*list, "NAME");
- if (!name)
- {
- WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
- "Device has no name");
- // Skip it.
- continue;
+ char* name = LATE(snd_device_name_get_hint)(*list, "NAME");
+ if (!name) {
+ WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
+ "Device has no name");
+ // Skip it.
+ continue;
+ }
+
+ // Now check if we actually want to show this device.
+ if (strcmp(name, "default") != 0 && strcmp(name, "null") != 0 &&
+ strcmp(name, "pulse") != 0 &&
+ strncmp(name, ignorePrefix, strlen(ignorePrefix)) != 0) {
+ // Yes, we do.
+ char* desc = LATE(snd_device_name_get_hint)(*list, "DESC");
+ if (!desc) {
+ // Virtual devices don't necessarily have descriptions.
+ // Use their names instead.
+ desc = name;
}
- // Now check if we actually want to show this device.
- if (strcmp(name, "default") != 0 &&
- strcmp(name, "null") != 0 &&
- strcmp(name, "pulse") != 0 &&
- strncmp(name, ignorePrefix, strlen(ignorePrefix)) != 0)
- {
- // Yes, we do.
- char *desc = LATE(snd_device_name_get_hint)(*list, "DESC");
- if (!desc)
- {
- // Virtual devices don't necessarily have descriptions.
- // Use their names instead.
- desc = name;
- }
-
- if (FUNC_GET_NUM_OF_DEVICE == function)
- {
- WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
- " Enum device %d - %s", enumCount, name);
-
- }
- if ((FUNC_GET_DEVICE_NAME == function) &&
- (enumDeviceNo == enumCount))
- {
- // We have found the enum device, copy the name to buffer.
- strncpy(enumDeviceName, desc, ednLen);
- enumDeviceName[ednLen-1] = '\0';
- keepSearching = false;
- // Replace '\n' with '-'.
- char * pret = strchr(enumDeviceName, '\n'/*0xa*/); //LF
- if (pret)
- *pret = '-';
- }
- if ((FUNC_GET_DEVICE_NAME_FOR_AN_ENUM == function) &&
- (enumDeviceNo == enumCount))
- {
- // We have found the enum device, copy the name to buffer.
- strncpy(enumDeviceName, name, ednLen);
- enumDeviceName[ednLen-1] = '\0';
- keepSearching = false;
- }
+ if (FUNC_GET_NUM_OF_DEVICE == function) {
+ WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id,
+ " Enum device %d - %s", enumCount, name);
+ }
+ if ((FUNC_GET_DEVICE_NAME == function) &&
+ (enumDeviceNo == enumCount)) {
+ // We have found the enum device, copy the name to buffer.
+ strncpy(enumDeviceName, desc, ednLen);
+ enumDeviceName[ednLen - 1] = '\0';
+ keepSearching = false;
+ // Replace '\n' with '-'.
+ char* pret = strchr(enumDeviceName, '\n' /*0xa*/); // LF
+ if (pret)
+ *pret = '-';
+ }
+ if ((FUNC_GET_DEVICE_NAME_FOR_AN_ENUM == function) &&
+ (enumDeviceNo == enumCount)) {
+ // We have found the enum device, copy the name to buffer.
+ strncpy(enumDeviceName, name, ednLen);
+ enumDeviceName[ednLen - 1] = '\0';
+ keepSearching = false;
+ }
- if (keepSearching)
- ++enumCount;
+ if (keepSearching)
+ ++enumCount;
- if (desc != name)
- free(desc);
- }
+ if (desc != name)
+ free(desc);
+ }
- free(name);
+ free(name);
- if (!keepSearching)
- break;
+ if (!keepSearching)
+ break;
}
err = LATE(snd_device_name_free_hint)(hints);
@@ -1850,22 +1826,20 @@ int32_t AudioDeviceLinuxALSA::GetDevicesInfo(
int32_t AudioDeviceLinuxALSA::InputSanityCheckAfterUnlockedPeriod() const
{
- if (_handleRecord == NULL)
- {
- WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
- " input state has been modified during unlocked period");
- return -1;
+ if (_handleRecord == nullptr) {
+ WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
+ " input state has been modified during unlocked period");
+ return -1;
}
return 0;
}
int32_t AudioDeviceLinuxALSA::OutputSanityCheckAfterUnlockedPeriod() const
{
- if (_handlePlayout == NULL)
- {
- WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
- " output state has been modified during unlocked period");
- return -1;
+ if (_handlePlayout == nullptr) {
+ WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id,
+ " output state has been modified during unlocked period");
+ return -1;
}
return 0;
}

Powered by Google App Engine
This is Rietveld 408576698