summaryrefslogtreecommitdiff
path: root/chromium/media/audio/alsa
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/media/audio/alsa')
-rw-r--r--chromium/media/audio/alsa/alsa_input.cc20
-rw-r--r--chromium/media/audio/alsa/alsa_output.cc54
-rw-r--r--chromium/media/audio/alsa/alsa_output.h2
-rw-r--r--chromium/media/audio/alsa/alsa_output_unittest.cc24
4 files changed, 51 insertions, 49 deletions
diff --git a/chromium/media/audio/alsa/alsa_input.cc b/chromium/media/audio/alsa/alsa_input.cc
index a70748274ae..ee7c5d0305d 100644
--- a/chromium/media/audio/alsa/alsa_input.cc
+++ b/chromium/media/audio/alsa/alsa_input.cc
@@ -41,10 +41,10 @@ AlsaPcmInputStream::AlsaPcmInputStream(AudioManagerBase* audio_manager,
buffer_duration_(base::TimeDelta::FromMicroseconds(
params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond /
static_cast<float>(params.sample_rate()))),
- callback_(NULL),
- device_handle_(NULL),
- mixer_handle_(NULL),
- mixer_element_handle_(NULL),
+ callback_(nullptr),
+ device_handle_(nullptr),
+ mixer_handle_(nullptr),
+ mixer_element_handle_(nullptr),
read_callback_behind_schedule_(false),
audio_bus_(AudioBus::Create(params)),
capture_thread_("AlsaInput"),
@@ -91,7 +91,7 @@ bool AlsaPcmInputStream::Open() {
}
}
- return device_handle_ != NULL;
+ return device_handle_ != nullptr;
}
void AlsaPcmInputStream::Start(AudioInputCallback* callback) {
@@ -108,7 +108,7 @@ void AlsaPcmInputStream::Start(AudioInputCallback* callback) {
}
if (error < 0) {
- callback_ = NULL;
+ callback_ = nullptr;
} else {
base::Thread::Options options;
options.priority = base::ThreadPriority::REALTIME_AUDIO;
@@ -268,7 +268,7 @@ void AlsaPcmInputStream::Stop() {
if (error < 0)
HandleError("PcmDrop", error);
- callback_ = NULL;
+ callback_ = nullptr;
}
void AlsaPcmInputStream::Close() {
@@ -282,9 +282,9 @@ void AlsaPcmInputStream::Close() {
alsa_util::CloseMixer(wrapper_, mixer_handle_, device_name_);
audio_buffer_.reset();
- device_handle_ = NULL;
- mixer_handle_ = NULL;
- mixer_element_handle_ = NULL;
+ device_handle_ = nullptr;
+ mixer_handle_ = nullptr;
+ mixer_element_handle_ = nullptr;
}
audio_manager_->ReleaseInputStream(this);
diff --git a/chromium/media/audio/alsa/alsa_output.cc b/chromium/media/audio/alsa/alsa_output.cc
index 74ea72b610c..c2cc61d1d8c 100644
--- a/chromium/media/audio/alsa/alsa_output.cc
+++ b/chromium/media/audio/alsa/alsa_output.cc
@@ -75,7 +75,7 @@ static const ChannelLayout kDefaultOutputChannelLayout = CHANNEL_LAYOUT_STEREO;
// http://0pointer.de/blog/projects/guide-to-sound-apis.html
//
// This function makes a best guess at the specific > 2 channel device name
-// based on the number of channels requested. NULL is returned if no device
+// based on the number of channels requested. nullptr is returned if no device
// can be found to match the channel numbers. In this case, using
// kDefaultDevice is probably the best bet.
//
@@ -103,7 +103,7 @@ static const char* GuessSpecificDeviceName(uint32_t channels) {
return "surround40";
default:
- return NULL;
+ return nullptr;
}
}
@@ -165,11 +165,11 @@ AlsaPcmOutputStream::AlsaPcmOutputStream(const std::string& device_name,
wrapper_(wrapper),
manager_(manager),
task_runner_(base::ThreadTaskRunnerHandle::Get()),
- playback_handle_(NULL),
+ playback_handle_(nullptr),
frames_per_packet_(packet_size_ / bytes_per_frame_),
state_(kCreated),
volume_(1.0f),
- source_callback_(NULL),
+ source_callback_(nullptr),
audio_bus_(AudioBus::Create(params)),
tick_clock_(base::DefaultTickClock::GetInstance()) {
DCHECK(manager_->GetTaskRunner()->BelongsToCurrentThread());
@@ -221,7 +221,7 @@ bool AlsaPcmOutputStream::Open() {
}
// Finish initializing the stream if the device was opened successfully.
- if (playback_handle_ == NULL) {
+ if (playback_handle_ == nullptr) {
stop_stream_ = true;
TransitionTo(kInError);
return false;
@@ -260,7 +260,7 @@ void AlsaPcmOutputStream::Close() {
if (alsa_util::CloseDevice(wrapper_, playback_handle_) < 0) {
LOG(WARNING) << "Unable to close audio device. Leaking handle.";
}
- playback_handle_ = NULL;
+ playback_handle_ = nullptr;
// Release the buffer.
buffer_.reset();
@@ -330,7 +330,7 @@ void AlsaPcmOutputStream::Stop() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Reset the callback, so that it is not called anymore.
- set_source_callback(NULL);
+ set_source_callback(nullptr);
weak_factory_.InvalidateWeakPtrs();
TransitionTo(kIsStopped);
@@ -559,19 +559,19 @@ std::string AlsaPcmOutputStream::FindDeviceForChannels(uint32_t channels) {
return std::string();
std::string guessed_device;
- void** hints = NULL;
+ void** hints = nullptr;
int error = wrapper_->DeviceNameHint(kGetAllDevices,
kPcmInterfaceName,
&hints);
if (error == 0) {
// NOTE: Do not early return from inside this if statement. The
// hints above need to be freed.
- for (void** hint_iter = hints; *hint_iter != NULL; hint_iter++) {
+ for (void** hint_iter = hints; *hint_iter != nullptr; hint_iter++) {
// Only examine devices that are output capable.. Valid values are
- // "Input", "Output", and NULL which means both input and output.
+ // "Input", "Output", and nullptr which means both input and output.
std::unique_ptr<char, base::FreeDeleter> io(
wrapper_->DeviceNameGetHint(*hint_iter, kIoHintName));
- if (io != NULL && strcmp(io.get(), "Input") == 0)
+ if (io != nullptr && strcmp(io.get(), "Input") == 0)
continue;
// Attempt to select the closest device for number of channels.
@@ -585,7 +585,7 @@ std::string AlsaPcmOutputStream::FindDeviceForChannels(uint32_t channels) {
// Destroy the hint now that we're done with it.
wrapper_->DeviceNameFreeHint(hints);
- hints = NULL;
+ hints = nullptr;
} else {
LOG(ERROR) << "Unable to get hints for devices: "
<< wrapper_->StrError(error);
@@ -673,24 +673,22 @@ snd_pcm_t* AlsaPcmOutputStream::AutoSelectDevice(unsigned int latency) {
// 4) Fallback to kDefaultDevice.
// 5) If that fails too, try the "plug:" version of kDefaultDevice.
// 6) Give up.
- snd_pcm_t* handle = NULL;
+ snd_pcm_t* handle = nullptr;
device_name_ = FindDeviceForChannels(channels_);
// Step 1.
if (!device_name_.empty()) {
- if ((handle = alsa_util::OpenPlaybackDevice(wrapper_, device_name_.c_str(),
- channels_, sample_rate_,
- pcm_format_,
- latency)) != NULL) {
+ if ((handle = alsa_util::OpenPlaybackDevice(
+ wrapper_, device_name_.c_str(), channels_, sample_rate_,
+ pcm_format_, latency)) != nullptr) {
return handle;
}
// Step 2.
device_name_ = kPlugPrefix + device_name_;
- if ((handle = alsa_util::OpenPlaybackDevice(wrapper_, device_name_.c_str(),
- channels_, sample_rate_,
- pcm_format_,
- latency)) != NULL) {
+ if ((handle = alsa_util::OpenPlaybackDevice(
+ wrapper_, device_name_.c_str(), channels_, sample_rate_,
+ pcm_format_, latency)) != nullptr) {
return handle;
}
@@ -700,7 +698,7 @@ snd_pcm_t* AlsaPcmOutputStream::AutoSelectDevice(unsigned int latency) {
device_name_ = kPlugPrefix + device_name_;
if ((handle = alsa_util::OpenPlaybackDevice(
wrapper_, device_name_.c_str(), channels_, sample_rate_,
- pcm_format_, latency)) != NULL) {
+ pcm_format_, latency)) != nullptr) {
return handle;
}
}
@@ -722,22 +720,22 @@ snd_pcm_t* AlsaPcmOutputStream::AutoSelectDevice(unsigned int latency) {
// Step 4.
device_name_ = kDefaultDevice;
if ((handle = alsa_util::OpenPlaybackDevice(
- wrapper_, device_name_.c_str(), default_channels, sample_rate_,
- pcm_format_, latency)) != NULL) {
+ wrapper_, device_name_.c_str(), default_channels, sample_rate_,
+ pcm_format_, latency)) != nullptr) {
return handle;
}
// Step 5.
device_name_ = kPlugPrefix + device_name_;
if ((handle = alsa_util::OpenPlaybackDevice(
- wrapper_, device_name_.c_str(), default_channels, sample_rate_,
- pcm_format_, latency)) != NULL) {
+ wrapper_, device_name_.c_str(), default_channels, sample_rate_,
+ pcm_format_, latency)) != nullptr) {
return handle;
}
// Unable to open any device.
device_name_.clear();
- return NULL;
+ return nullptr;
}
bool AlsaPcmOutputStream::CanTransitionTo(InternalState to) {
@@ -800,7 +798,7 @@ void AlsaPcmOutputStream::RunErrorCallback(int code) {
source_callback_->OnError(AudioSourceCallback::ErrorType::kUnknown);
}
-// Changes the AudioSourceCallback to proxy calls to. Pass in NULL to
+// Changes the AudioSourceCallback to proxy calls to. Pass in nullptr to
// release ownership of the currently registered callback.
void AlsaPcmOutputStream::set_source_callback(AudioSourceCallback* callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
diff --git a/chromium/media/audio/alsa/alsa_output.h b/chromium/media/audio/alsa/alsa_output.h
index 6070361a032..9922eae8763 100644
--- a/chromium/media/audio/alsa/alsa_output.h
+++ b/chromium/media/audio/alsa/alsa_output.h
@@ -159,7 +159,7 @@ class MEDIA_EXPORT AlsaPcmOutputStream : public AudioOutputStream {
AudioBus* audio_bus);
void RunErrorCallback(int code);
- // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to
+ // Changes the AudioSourceCallback to proxy calls to. Pass in nullptr to
// release ownership of the currently registered callback.
void set_source_callback(AudioSourceCallback* callback);
diff --git a/chromium/media/audio/alsa/alsa_output_unittest.cc b/chromium/media/audio/alsa/alsa_output_unittest.cc
index bca316b71d4..9183721af1b 100644
--- a/chromium/media/audio/alsa/alsa_output_unittest.cc
+++ b/chromium/media/audio/alsa/alsa_output_unittest.cc
@@ -5,6 +5,7 @@
#include <stdint.h>
#include <memory>
+#include "base/logging.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
@@ -177,7 +178,7 @@ char AlsaPcmOutputStreamTest::kSurround70[] = "surround70:CARD=foo,DEV=0";
char AlsaPcmOutputStreamTest::kSurround71[] = "surround71:CARD=foo,DEV=0";
void* AlsaPcmOutputStreamTest::kFakeHints[] = {
kSurround40, kSurround41, kSurround50, kSurround51,
- kSurround70, kSurround71, NULL };
+ kSurround70, kSurround71, nullptr};
char AlsaPcmOutputStreamTest::kGenericSurround50[] = "surround50";
// Custom action to clear a memory buffer.
@@ -315,7 +316,7 @@ TEST_F(AlsaPcmOutputStreamTest, PcmOpenFailed) {
// Ensure internal state is set for a no-op stream if PcmOpen() failes.
EXPECT_TRUE(test_stream->stop_stream_);
- EXPECT_TRUE(test_stream->playback_handle_ == NULL);
+ EXPECT_FALSE(test_stream->playback_handle_);
EXPECT_FALSE(test_stream->buffer_.get());
// Close the stream since we opened it to make destruction happy.
@@ -342,7 +343,7 @@ TEST_F(AlsaPcmOutputStreamTest, PcmSetParamsFailed) {
// Ensure internal state is set for a no-op stream if PcmSetParams() failes.
EXPECT_TRUE(test_stream->stop_stream_);
- EXPECT_TRUE(test_stream->playback_handle_ == NULL);
+ EXPECT_FALSE(test_stream->playback_handle_);
EXPECT_FALSE(test_stream->buffer_.get());
// Close the stream since we opened it to make destruction happy.
@@ -636,13 +637,16 @@ TEST_F(AlsaPcmOutputStreamTest, AutoSelectDevice_DeviceSelect) {
//
// Note that the loop starts at "1", so the first parameter is ignored in
// these arrays.
- const char* kExpectedDeviceName[] = { NULL,
- AlsaPcmOutputStream::kDefaultDevice,
- AlsaPcmOutputStream::kDefaultDevice,
- AlsaPcmOutputStream::kDefaultDevice,
- kSurround40, kSurround50, kSurround51,
- kSurround70, kSurround71,
- AlsaPcmOutputStream::kDefaultDevice };
+ const char* kExpectedDeviceName[] = {nullptr,
+ AlsaPcmOutputStream::kDefaultDevice,
+ AlsaPcmOutputStream::kDefaultDevice,
+ AlsaPcmOutputStream::kDefaultDevice,
+ kSurround40,
+ kSurround50,
+ kSurround51,
+ kSurround70,
+ kSurround71,
+ AlsaPcmOutputStream::kDefaultDevice};
bool kExpectedDownmix[] = { false, false, false, false, false, true,
false, false, false, false };
ChannelLayout kExpectedLayouts[] = { CHANNEL_LAYOUT_NONE,