Skip to content

Commit

Permalink
The cookie is actually usually in ~/.config/pulse/cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmarc committed Dec 29, 2023
1 parent fc540fe commit 01401a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
4 changes: 2 additions & 2 deletions examples/list-sinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut sock = std::io::BufReader::new(UnixStream::connect(&socket_path)?);

// PulseAudio usually puts an authentication "cookie" in ~/.pulse-cookie.
// PulseAudio usually puts an authentication "cookie" in ~/.config/pulse/cookie.
let home = std::env::var("HOME")?;
let cookie_path = Path::new(&home).join(".pulse-cookie");
let cookie_path = Path::new(&home).join(".config/pulse/cookie");
let auth = if cookie_path.exists() {
let cookie = std::fs::read(&cookie_path)?;
protocol::AuthParams {
Expand Down
33 changes: 13 additions & 20 deletions examples/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
time,
};

use anyhow::bail;
use anyhow::{bail, Context};
use pulseaudio::protocol::{self, LatencyParams};

fn main() -> anyhow::Result<()> {
Expand All @@ -20,8 +20,7 @@ fn main() -> anyhow::Result<()> {
return Ok(());
}

let mut sock = connect_and_init()?;
let sink = default_sink_name(&mut sock)?;
let mut sock = connect_and_init().context("failed to initialize client")?;

let mut file = File::open(Path::new(&args[1]))?;
let mut wav_reader = hound::WavReader::new(&mut file)?;
Expand Down Expand Up @@ -64,13 +63,16 @@ fn main() -> anyhow::Result<()> {
sample_rate: spec.sample_rate,
},
channel_map,
sink_name: Some(sink),
cvolume: Some(protocol::ChannelVolume::norm(2)),
sink_name: Some(CString::new("@DEFAULT_SINK@")?),
..Default::default()
}),
)?;
)
.context("failed to send create_playback_stream")?;

let (seq, stream_info) =
protocol::read_reply_message::<protocol::CreatePlaybackStreamReply>(&mut sock)?;
protocol::read_reply_message::<protocol::CreatePlaybackStreamReply>(&mut sock)
.context("create_playback_stream failed")?;
assert_eq!(seq, 99);

// Create a buffer for sending data to the server.
Expand All @@ -85,7 +87,8 @@ fn main() -> anyhow::Result<()> {
)?;

// Send initial bytes to the server.
protocol::write_memblock(sock.get_mut(), stream_info.channel, &buf[..size], 0)?;
protocol::write_memblock(sock.get_mut(), stream_info.channel, &buf[..size], 0)
.context("write_memblock failed")?;

loop {
let (_, msg) = protocol::read_command_message(&mut sock)?;
Expand All @@ -103,7 +106,8 @@ fn main() -> anyhow::Result<()> {
break;
}

protocol::write_memblock(sock.get_mut(), stream_info.channel, &buf[..size], 0)?;
protocol::write_memblock(sock.get_mut(), stream_info.channel, &buf[..size], 0)
.context("write_memblock failed")?;

// Fetch the current timing information for the stream.
let timing_info = get_timing_info(&mut sock, stream_info.channel)?;
Expand Down Expand Up @@ -180,9 +184,8 @@ fn connect_and_init() -> anyhow::Result<BufReader<UnixStream>> {

let mut sock = std::io::BufReader::new(UnixStream::connect(&socket_path)?);

// PulseAudio usually puts an authentication "cookie" in ~/.pulse-cookie.
let home = std::env::var("HOME")?;
let cookie_path = Path::new(&home).join(".pulse-cookie");
let cookie_path = Path::new(&home).join(".config/pulse/cookie");
let auth = if cookie_path.exists() {
let cookie = std::fs::read(&cookie_path)?;
protocol::AuthParams {
Expand Down Expand Up @@ -211,16 +214,6 @@ fn connect_and_init() -> anyhow::Result<BufReader<UnixStream>> {
Ok(sock)
}

fn default_sink_name(sock: &mut BufReader<UnixStream>) -> anyhow::Result<CString> {
protocol::write_command_message(sock.get_mut(), 2, protocol::Command::GetServerInfo)?;
let (_, info) = protocol::read_reply_message::<protocol::ServerInfo>(sock)?;

match info.default_sink_name {
Some(name) => Ok(name),
None => bail!("no default sink"),
}
}

fn get_timing_info(
sock: &mut BufReader<UnixStream>,
channel: u32,
Expand Down
4 changes: 2 additions & 2 deletions examples/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut sock = std::io::BufReader::new(UnixStream::connect(&socket_path)?);

// PulseAudio usually puts an authentication "cookie" in ~/.pulse-cookie.
// PulseAudio usually puts an authentication "cookie" in ~/.config/pulse/cookie.
let home = std::env::var("HOME")?;
let cookie_path = Path::new(&home).join(".pulse-cookie");
let cookie_path = Path::new(&home).join(".config/pulse/cookie");
let auth = if cookie_path.exists() {
let cookie = std::fs::read(&cookie_path)?;
protocol::AuthParams {
Expand Down

0 comments on commit 01401a4

Please sign in to comment.