aboutsummaryrefslogtreecommitdiff
path: root/src/volume-control-pulse.vala
diff options
context:
space:
mode:
authorXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-10-21 15:16:58 +0200
committerXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-10-21 15:16:58 +0200
commit4dbdcf30a0ed10019d3350293c4ac52040393640 (patch)
treefa01e697dee299506a91d1d9f41c2a61f429fcc9 /src/volume-control-pulse.vala
parent6ee23e401d3847e609f1ef50e1736f69e6253608 (diff)
parent86c449a7125f3ff90dcac353c8a4ad5a8c2cc46e (diff)
downloadayatana-indicator-sound-4dbdcf30a0ed10019d3350293c4ac52040393640.tar.gz
ayatana-indicator-sound-4dbdcf30a0ed10019d3350293c4ac52040393640.tar.bz2
ayatana-indicator-sound-4dbdcf30a0ed10019d3350293c4ac52040393640.zip
Fixed conflict. Updated changelog to be in sync with trunk
Diffstat (limited to 'src/volume-control-pulse.vala')
-rw-r--r--src/volume-control-pulse.vala83
1 files changed, 69 insertions, 14 deletions
diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala
index 87af258..8122f26 100644
--- a/src/volume-control-pulse.vala
+++ b/src/volume-control-pulse.vala
@@ -87,6 +87,7 @@ public class VolumeControlPulse : VolumeControl
private bool _send_next_local_volume = false;
private double _account_service_volume = 0.0;
private bool _active_port_headphone = false;
+ private VolumeControl.ActiveOutput _active_output = VolumeControl.ActiveOutput.SPEAKERS;
/** true when connected to the pulse server */
public override bool ready { get; private set; }
@@ -135,6 +136,49 @@ public class VolumeControlPulse : VolumeControl
stop_high_volume_approved_timer();
}
+ private VolumeControl.ActiveOutput calculate_active_output (SinkInfo? sink) {
+
+ VolumeControl.ActiveOutput ret_output = VolumeControl.ActiveOutput.SPEAKERS;
+ /* Check if the current active port is headset/headphone */
+ /* There is not easy way to check if the port is a headset/headphone besides
+ * checking for the port name. On touch (with the pulseaudio droid element)
+ * the headset/headphone port is called 'output-headset' and 'output-headphone'.
+ * On the desktop this is usually called 'analog-output-headphones' */
+ // look if it's a headset/headphones
+ if (sink.name == "indicator_sound_test_headphones" ||
+ (sink.active_port != null &&
+ (sink.active_port.name.contains("headset") ||
+ sink.active_port.name.contains("headphone")))) {
+ _active_port_headphone = true;
+ // check if it's a bluetooth device
+ var device_bus = sink.proplist.gets ("device.bus");
+ if (device_bus != null && device_bus == "bluetooth") {
+ ret_output = VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES;
+ } else if (device_bus != null && device_bus == "usb") {
+ ret_output = VolumeControl.ActiveOutput.USB_HEADPHONES;
+ } else if (device_bus != null && device_bus == "hdmi") {
+ ret_output = VolumeControl.ActiveOutput.HDMI_HEADPHONES;
+ } else {
+ ret_output = VolumeControl.ActiveOutput.HEADPHONES;
+ }
+ } else {
+ // speaker
+ _active_port_headphone = false;
+ var device_bus = sink.proplist.gets ("device.bus");
+ if (device_bus != null && device_bus == "bluetooth") {
+ ret_output = VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER;
+ } else if (device_bus != null && device_bus == "usb") {
+ ret_output = VolumeControl.ActiveOutput.USB_SPEAKER;
+ } else if (device_bus != null && device_bus == "hdmi") {
+ ret_output = VolumeControl.ActiveOutput.HDMI_SPEAKER;
+ } else {
+ ret_output = VolumeControl.ActiveOutput.SPEAKERS;
+ }
+ }
+
+ return ret_output;
+ }
+
/* PulseAudio logic*/
private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index)
{
@@ -201,18 +245,20 @@ public class VolumeControlPulse : VolumeControl
this.notify_property ("is-playing");
}
- /* Check if the current active port is headset/headphone */
- /* There is not easy way to check if the port is a headset/headphone besides
- * checking for the port name. On touch (with the pulseaudio droid element)
- * the headset/headphone port is called 'output-headset' and 'output-headphone'.
- * On the desktop this is usually called 'analog-output-headphones' */
- if (i.active_port != null &&
- (i.active_port.name == "output-wired_headset" ||
- i.active_port.name == "output-wired_headphone" ||
- i.active_port.name == "analog-output-headphones")) {
- _active_port_headphone = true;
- } else {
- _active_port_headphone = false;
+ // store the current status of the active output
+ VolumeControl.ActiveOutput active_output_before = active_output;
+
+ // calculate the output
+ _active_output = calculate_active_output (i);
+
+ // check if the output has changed, if so... emit a signal
+ VolumeControl.ActiveOutput active_output_now = active_output;
+ if (active_output_now != active_output_before) {
+ this.active_output_changed (active_output_now);
+ if (active_output_now == VolumeControl.ActiveOutput.SPEAKERS) {
+ _high_volume_approved = false;
+ }
+ update_high_volume();
}
if (_pulse_use_stream_restore == false &&
@@ -478,7 +524,8 @@ public class VolumeControlPulse : VolumeControl
this.context = new PulseAudio.Context (loop.get_api(), null, props);
this.context.set_state_callback (context_state_callback);
- if (context.connect(null, Context.Flags.NOFAIL, null) < 0)
+ var server_string = Environment.get_variable("PULSE_SERVER");
+ if (context.connect(server_string, Context.Flags.NOFAIL, null) < 0)
warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(context.errno()));
}
@@ -535,6 +582,14 @@ public class VolumeControlPulse : VolumeControl
}
}
+ public override VolumeControl.ActiveOutput active_output
+ {
+ get
+ {
+ return _active_output;
+ }
+ }
+
/* Volume operations */
private static PulseAudio.Volume double_to_volume (double vol)
{
@@ -710,7 +765,7 @@ public class VolumeControlPulse : VolumeControl
private bool calculate_high_volume_from_volume(double volume) {
return _active_port_headphone
&& _warning_volume_enabled
- && volume >= _warning_volume_norms
+ && volume > _warning_volume_norms
&& (stream == "multimedia");
}