summaryrefslogtreecommitdiffstats
path: root/chromeos/audio
diff options
context:
space:
mode:
authorrkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-07 00:04:57 +0000
committerrkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-07 00:04:57 +0000
commit8e48da24b7a33f32f74158f631f9820f9834a243 (patch)
tree4ee862b6e4fa6296eb77c1d26fce6746d54e4617 /chromeos/audio
parent628c56b57bbc8749d695c8093cb44c9477f8a791 (diff)
downloadchromium_src-8e48da24b7a33f32f74158f631f9820f9834a243.zip
chromium_src-8e48da24b7a33f32f74158f631f9820f9834a243.tar.gz
chromium_src-8e48da24b7a33f32f74158f631f9820f9834a243.tar.bz2
Revert 198556 "Implement the rest of the audio API."
> Implement the rest of the audio API. > Picking up where https://codereview.chromium.org/13486004/ left off, implemented the setProperties and setActiveDevices calls; also fixed GetNodes to also return the volume of the devices. > > R=hshi@chromium.org, jennyz@chromium.org, mpcomplete@chromium.org > BUG=175798 > TEST=Wrote a test extension to set the volume on the active and inactive devices, to verify they were set correctly. Also wrote code to switch active devices to verify that the devices did switch. > > Review URL: https://codereview.chromium.org/14652027 TBR=rkc@chromium.org Review URL: https://codereview.chromium.org/14655010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198568 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/audio')
-rw-r--r--chromeos/audio/audio_devices_pref_handler.h20
-rw-r--r--chromeos/audio/cras_audio_handler.cc102
-rw-r--r--chromeos/audio/cras_audio_handler.h40
-rw-r--r--chromeos/audio/cras_audio_switch_handler.cc4
-rw-r--r--chromeos/audio/cras_audio_switch_handler.h2
5 files changed, 17 insertions, 151 deletions
diff --git a/chromeos/audio/audio_devices_pref_handler.h b/chromeos/audio/audio_devices_pref_handler.h
index f528d25..63e3ed7 100644
--- a/chromeos/audio/audio_devices_pref_handler.h
+++ b/chromeos/audio/audio_devices_pref_handler.h
@@ -20,17 +20,15 @@ namespace chromeos {
class CHROMEOS_EXPORT AudioDevicesPrefHandler
: public base::RefCountedThreadSafe<AudioDevicesPrefHandler> {
public:
- // Gets the audio output volume value from prefs for a device. Since we can
- // only have either a gain or a volume for a device (depending on whether it
- // is input or output), we don't really care which value it is.
- virtual double GetVolumeGainValue(uint64 device_id) = 0;
- // Sets the audio volume or gain value to prefs for a device.
- virtual void SetVolumeGainValue(uint64 device_id, double value) = 0;
-
- // Reads the audio mute value from prefs for a device.
- virtual bool GetMuteValue(uint64 device_id) = 0;
- // Sets the audio mute value to prefs for a device.
- virtual void SetMuteValue(uint64 device_id, bool mute_on) = 0;
+ // Gets the audio output volume value from prefs for the active device.
+ virtual double GetOutputVolumeValue() = 0;
+ // Reads the audio output mute value from prefs for the active device.
+ virtual bool GetOutputMuteValue() = 0;
+
+ // Sets the output audio volume value to prefs for the active device.
+ virtual void SetOutputVolumeValue(double volume_percent) = 0;
+ // Sets the audio output mute value to prefs for the active device.
+ virtual void SetOutputMuteValue(bool mute_on) = 0;
// Reads the audio capture allowed value from prefs.
virtual bool GetAudioCaptureAllowedValue() = 0;
diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc
index cfe5361..733fac9 100644
--- a/chromeos/audio/cras_audio_handler.cc
+++ b/chromeos/audio/cras_audio_handler.cc
@@ -11,7 +11,6 @@
#include "base/bind_helpers.h"
#include "base/logging.h"
#include "chromeos/audio/audio_devices_pref_handler.h"
-#include "chromeos/audio/cras_audio_switch_handler.h"
#include "chromeos/audio/mock_cras_audio_handler.h"
#include "chromeos/dbus/dbus_thread_manager.h"
@@ -42,9 +41,6 @@ CrasAudioHandler::AudioObserver::~AudioObserver() {
void CrasAudioHandler::AudioObserver::OnOutputVolumeChanged() {
}
-void CrasAudioHandler::AudioObserver::OnInputGainChanged() {
-}
-
void CrasAudioHandler::AudioObserver::OnOutputMuteChanged() {
}
@@ -112,24 +108,6 @@ int CrasAudioHandler::GetOutputVolumePercent() {
return output_volume_;
}
-int CrasAudioHandler::GetOutputVolumePercentForDevice(uint64 device_id) {
- if (device_id == active_output_node_id_)
- return output_volume_;
- else
- return (int) audio_pref_handler_->GetVolumeGainValue(device_id);
-}
-
-int CrasAudioHandler::GetInputGainPercent() {
- return input_gain_;
-}
-
-int CrasAudioHandler::GetInputGainPercentForDevice(uint64 device_id) {
- if (device_id == active_input_node_id_)
- return input_gain_;
- else
- return (int) audio_pref_handler_->GetVolumeGainValue(device_id);
-}
-
uint64 CrasAudioHandler::GetActiveOutputNode() const {
return active_output_node_id_;
}
@@ -172,17 +150,6 @@ void CrasAudioHandler::SetOutputVolumePercent(int volume_percent) {
SetOutputMute(true);
}
-void CrasAudioHandler::SetInputGainPercent(int gain_percent) {
- gain_percent = min(max(gain_percent, 0), 100);
- if (gain_percent <= kMuteThresholdPercent)
- gain_percent = 0;
- SetInputGainInternal(gain_percent);
- if (IsInputMuted() && gain_percent > 0)
- SetInputMute(false);
- if (!IsInputMuted() && gain_percent == 0)
- SetInputMute(true);
-}
-
void CrasAudioHandler::AdjustOutputVolumeByPercent(int adjust_by_percent) {
SetOutputVolumePercent(output_volume_ + adjust_by_percent);
}
@@ -221,23 +188,6 @@ void CrasAudioHandler::SetActiveInputNode(uint64 node_id) {
SetActiveInputNode(node_id);
}
-void CrasAudioHandler::SetVolumeGainPercentForDevice(uint64 device_id,
- int value) {
- if (device_id == active_output_node_id_) {
- SetOutputVolumePercent(value);
- return;
- } else if (device_id == active_input_node_id_) {
- SetInputGainPercent(value);
- return;
- }
-
- value = min(max(value, 0), 100);
- if (value <= kMuteThresholdPercent)
- value = 0;
-
- audio_pref_handler_->SetVolumeGainValue(device_id, value);
-}
-
CrasAudioHandler::CrasAudioHandler(
scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler)
: audio_pref_handler_(audio_pref_handler),
@@ -245,7 +195,6 @@ CrasAudioHandler::CrasAudioHandler(
output_mute_on_(false),
input_mute_on_(false),
output_volume_(0),
- input_gain_(0),
active_output_node_id_(0),
active_input_node_id_(0),
has_alternative_input_(false),
@@ -286,27 +235,16 @@ void CrasAudioHandler::OutputVolumeChanged(int volume) {
return;
output_volume_ = volume;
- audio_pref_handler_->SetVolumeGainValue(active_output_node_id_,
- output_volume_);
+ audio_pref_handler_->SetOutputVolumeValue(output_volume_);
FOR_EACH_OBSERVER(AudioObserver, observers_, OnOutputVolumeChanged());
}
-void CrasAudioHandler::InputGainChanged(int gain) {
- if (input_gain_ == gain)
- return;
-
- input_gain_ = gain;
- audio_pref_handler_->SetVolumeGainValue(active_input_node_id_, input_gain_);
- FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputGainChanged());
-}
-
void CrasAudioHandler::OutputMuteChanged(bool mute_on) {
if (output_mute_on_ == mute_on)
return;
output_mute_on_ = mute_on;
- audio_pref_handler_->SetMuteValue(active_output_node_id_,
- mute_on);
+ audio_pref_handler_->SetOutputMuteValue(mute_on);
FOR_EACH_OBSERVER(AudioObserver, observers_, OnOutputMuteChanged());
}
@@ -315,8 +253,6 @@ void CrasAudioHandler::InputMuteChanged(bool mute_on) {
return;
input_mute_on_ = mute_on;
- audio_pref_handler_->SetMuteValue(active_input_node_id_,
- mute_on);
FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputMuteChanged());
}
@@ -339,7 +275,6 @@ void CrasAudioHandler::ActiveInputNodeChanged(uint64 node_id) {
return;
active_input_node_id_ = node_id;
- SetupAudioState();
FOR_EACH_OBSERVER(AudioObserver, observers_, OnActiveInputNodeChanged());
}
@@ -351,30 +286,10 @@ void CrasAudioHandler::SetupAudioState() {
ApplyAudioPolicy();
// Set the initial audio state to the ones read from audio prefs.
- if (active_input_node_id_) {
- input_mute_on_ = audio_pref_handler_->GetMuteValue(active_input_node_id_);
- input_gain_ = audio_pref_handler_->GetVolumeGainValue(
- active_input_node_id_);
- SetInputMute(input_mute_on_);
- SetInputGainInternal(input_gain_);
- } else {
- SetInputMute(kPrefMuteOff);
- SetInputGainInternal(kDefaultVolumeGainPercent);
- }
-
- if (active_output_node_id_) {
- output_mute_on_ = audio_pref_handler_->GetMuteValue(active_output_node_id_);
- output_volume_ = audio_pref_handler_->GetVolumeGainValue(
- active_output_node_id_);
- SetOutputMute(output_mute_on_);
- SetOutputVolumeInternal(output_volume_);
- } else {
- SetOutputMute(kPrefMuteOff);
- SetOutputVolumeInternal(kDefaultVolumeGainPercent);
- }
-
- if (!active_output_node_id_ || !active_input_node_id_)
- CrasAudioSwitchHandler::Get()->UpdateActiveDevice();
+ output_mute_on_ = audio_pref_handler_->GetOutputMuteValue();
+ output_volume_ = audio_pref_handler_->GetOutputVolumeValue();
+ SetOutputVolumeInternal(output_volume_);
+ SetOutputMute(output_mute_on_);
}
void CrasAudioHandler::ApplyAudioPolicy() {
@@ -398,11 +313,6 @@ void CrasAudioHandler::SetOutputVolumeInternal(int volume) {
SetOutputVolume(volume);
}
-void CrasAudioHandler::SetInputGainInternal(int gain) {
- chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->
- SetInputGain(gain);
-}
-
void CrasAudioHandler::GetNodes() {
chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->GetNodes(
base::Bind(&CrasAudioHandler::HandleGetNodes,
diff --git a/chromeos/audio/cras_audio_handler.h b/chromeos/audio/cras_audio_handler.h
index da45268..fd9ac03 100644
--- a/chromeos/audio/cras_audio_handler.h
+++ b/chromeos/audio/cras_audio_handler.h
@@ -18,17 +18,6 @@
class PrefRegistrySimple;
class PrefService;
-namespace {
-
-// Default value for the volume pref, as a percent in the range [0.0, 100.0].
-const double kDefaultVolumeGainPercent = 75.0;
-
-// Values used for muted preference.
-const int kPrefMuteOff = 0;
-const int kPrefMuteOn = 1;
-
-} // namespace
-
namespace chromeos {
class AudioDevicesPrefHandler;
@@ -45,9 +34,6 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
virtual void OnOutputMuteChanged();
// Called when input mute state changed.
- virtual void OnInputGainChanged();
-
- // Called when input mute state changed.
virtual void OnInputMuteChanged();
// Called when audio nodes changed.
@@ -93,20 +79,9 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
// Returns true if audio input is muted.
virtual bool IsInputMuted();
- // Gets volume level in 0-100% range (0 being pure silence) for the current
- // active node.
+ // Gets volume level in 0-100% range, 0 being pure silence.
virtual int GetOutputVolumePercent();
- // Gets volume level in 0-100% range (0 being pure silence) for a device.
- virtual int GetOutputVolumePercentForDevice(uint64 device_id);
-
- // Gets gain level in 0-100% range (0 being pure silence) for the current
- // active node.
- virtual int GetInputGainPercent();
-
- // Gets volume level in 0-100% range (0 being pure silence) for a device.
- virtual int GetInputGainPercentForDevice(uint64 device_id);
-
// Returns node_id of the active output node.
virtual uint64 GetActiveOutputNode() const;
@@ -127,9 +102,6 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
// the threshold, then the sound is unmuted.
virtual void SetOutputVolumePercent(int volume_percent);
- // Sets gain level from 0-100%.
- virtual void SetInputGainPercent(int gain_percent);
-
// Adjusts volume up (positive percentage) or down (negative percentage).
virtual void AdjustOutputVolumeByPercent(int adjust_by_percent);
@@ -145,20 +117,16 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
// Sets the active audio input node to the node with |node_id|.
virtual void SetActiveInputNode(uint64 node_id);
- // Sets volume/gain level from a device.
- virtual void SetVolumeGainPercentForDevice(uint64 device_id, int value);
-
protected:
explicit CrasAudioHandler(
scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler);
virtual ~CrasAudioHandler();
private:
- // Overriden from CrasAudioClient::Observer.
+ // Overriden from CrasAudioHandler::Observer.
virtual void AudioClientRestarted() OVERRIDE;
virtual void OutputVolumeChanged(int volume) OVERRIDE;
virtual void OutputMuteChanged(bool mute_on) OVERRIDE;
- virtual void InputGainChanged(int gain) OVERRIDE;
virtual void InputMuteChanged(bool mute_on) OVERRIDE;
virtual void NodesChanged() OVERRIDE;
virtual void ActiveOutputNodeChanged(uint64 node_id) OVERRIDE;
@@ -178,9 +146,6 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
// Sets output volume to specified value and notifies observers.
void SetOutputVolumeInternal(int volume);
- // Sets output volume to specified value and notifies observers.
- void SetInputGainInternal(int gain);
-
// Calling dbus to get nodes data.
void GetNodes();
@@ -197,7 +162,6 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
bool output_mute_on_;
bool input_mute_on_;
int output_volume_;
- int input_gain_;
uint64 active_output_node_id_;
uint64 active_input_node_id_;
bool has_alternative_input_;
diff --git a/chromeos/audio/cras_audio_switch_handler.cc b/chromeos/audio/cras_audio_switch_handler.cc
index 2255cc4..4efb3a8 100644
--- a/chromeos/audio/cras_audio_switch_handler.cc
+++ b/chromeos/audio/cras_audio_switch_handler.cc
@@ -41,10 +41,6 @@ CrasAudioSwitchHandler* CrasAudioSwitchHandler::Get() {
return g_cras_audio_handler;
}
-void CrasAudioSwitchHandler::UpdateActiveDevice() {
- GetNodes();
-}
-
CrasAudioSwitchHandler::CrasAudioSwitchHandler()
: muted_device_id_(0),
weak_ptr_factory_(this) {
diff --git a/chromeos/audio/cras_audio_switch_handler.h b/chromeos/audio/cras_audio_switch_handler.h
index eb66f52..a31ddf3d 100644
--- a/chromeos/audio/cras_audio_switch_handler.h
+++ b/chromeos/audio/cras_audio_switch_handler.h
@@ -40,8 +40,6 @@ class CHROMEOS_EXPORT CrasAudioSwitchHandler
// Gets the global instance. Initialize must be called first.
static CrasAudioSwitchHandler* Get();
- void UpdateActiveDevice();
-
private:
explicit CrasAudioSwitchHandler();
virtual ~CrasAudioSwitchHandler();