rurkabl/lib.sh
2024-05-02 04:49:17 +02:00

92 lines
2 KiB
Bash

#!/bin/bash
# lib.sh - stuff you might wanna call
pa_auth() {
local c
local b
if [[ "$PULSE_COOKIE" != '' ]]; then
c="$(hex < "$PULSE_COOKIE")"
elif [[ -f ~/.config/pulse/cookie ]]; then
c="$(hex < ~/.config/pulse/cookie)"
elif [[ -f ~/.pulse-cookie ]]; then
c="$(hex < ~/.pulse-cookie)"
else # strict diet
:
fi
b="$(write_long "8")" # Auth
b+="$(write_long "$_PA_SEQ_NUM")" # sequence number
b+="4c0000000d" # 0000 - we don't support SHM/MEMFD; 0x0d - max version (used to be 0x23, but lower == easier)
b+="$(write_arbitrary "$c")"
pkt "$b"
pkt_read
parse "$res"
(( _PA_SEQ_NUM++ ))
}
pa_setclientname() {
local b
#set -x
b="$(write_long "9")" # SetClientName
b+="$(write_long "$_PA_SEQ_NUM")" # sequence number
b+="$(write_props "application.name" "$(hex meow)00" "meowmeow.meowmeow" "00")"
pkt "$b"
pkt_read
parse "$res"
(( _PA_SEQ_NUM++ ))
}
pa_getsinks() {
local b
b="$(write_long "22")" # GetSinkInfoList
b+="$(write_long "$_PA_SEQ_NUM")" # sequence number
pkt "$b"
pkt_read
parse "$res"
(( _PA_SEQ_NUM++ ))
}
pa_createplaybackstream() {
local b
b="$(write_long "3")"
b+="$(write_long "$_PA_SEQ_NUM")" # sequence number
b+="$(write_samplespec)" # TODO, hardcoded
b+="$(write_channelmap)" # ^
b+="$(write_long 540)" # sink index, TODO
b+="$(write_nullstring)" # sink name, TODO
b+="$(write_long 1024)" # buffer max length
b+="30" # start_corked (idk)
b+="$(write_long 1024)" # buffer target length (???)
b+="$(write_long 1024)" # pre_buffering
b+="$(write_long $((0xffffffff)))" # minimum_request_length (max ulong makes PA choose)
b+="$(write_long 0)" # sync_id (?????????)
b+="$(write_channelvolume 65535)" # channel volume, number out of my ass
b+="30" # no_remap_channels
b+="30" # no_remix_channels
b+="30" # fix_format
b+="30" # fix_rate
b+="30" # fix_channels
b+="30" # no_move
b+="31" # variable_rate
b+="30" # start_muted
b+="30" # adjust_latency
# props
b+="$(write_props "i.dont.know.how" "$(hex "to send an empty prop object")00")"
pkt "$b"
pkt_read
parse "$res"
(( _PA_SEQ_NUM++ ))
}