ref: fdbf31f12cf811f66a123fa5abcd87b68ec771b7
parent: d074aa0d3c51d95dc943a50cf82623f680c99c16
author: Sigrid Haflínudóttir <[email protected]>
date: Tue Jun 9 12:23:24 EDT 2020
remove all /dev/audio reopening logic
--- a/zuke.c
+++ b/zuke.c
@@ -42,6 +42,7 @@
int mainstacksize = 32768;
+static int audio;
static Meta *pl;
static int plnum;
static char *plraw;
@@ -421,17 +422,6 @@
return -1;
}
-static int
-openaudio(int audio)
-{
- while(audio < 0 && (audio = open("/dev/audio", OWRITE)) < 0){
- fprint(2, "audio busy\n");
- sleep(1000);
- }
-
- return audio;
-}
-
static void
playerthread(void *player_)
{
@@ -442,7 +432,6 @@
ulong c;
int p[2], fd, pid, n, got, noinit, trycoverload;
u64int bytesfrom, bf;
- int audio;
Meta *cur;
threadsetname("player");
@@ -454,7 +443,6 @@
trycoverload = 1;
io = nil;
pid = -1;
- audio = -1;
restart:
cur = getmeta(player->pcur);
@@ -504,7 +492,6 @@
c = recvul(player->ctl);
if(c != Cstart)
goto freeplayer;
- audio = openaudio(audio);
iowrite(io, audio, buf, got);
byteswritten = got;
bytesfrom = 0;
@@ -536,12 +523,9 @@
if(c == Cstop || c == -1)
goto stop;
if(c == Ctoggle){
- close(audio);
- audio = -1;
c = recvul(player->ctl);
if(c == Cstop)
goto stop;
- audio = openaudio(audio);
}else if(c == Cforward){
bytesfrom = bf + Seekbytes;
}else if(c == Cforwardfast){
@@ -560,7 +544,6 @@
if(bytesfrom <= byteswritten){
if(bytesfrom == byteswritten)
bytesfrom = 0;
- audio = openaudio(audio);
if(iowrite(io, audio, buf, n) != n){
fprint(2, "failed to write %d bytes: %r\n", n);
break;
@@ -584,14 +567,10 @@
start(playercurr);
goto stop;
}
- close(audio);
- audio = -1;
goto restart;
}
stop:
- if(audio >= 0)
- close(audio);
if(player->img != nil)
freeimage(recvp(player->img));
freeplayer:
@@ -909,6 +888,9 @@
fprint(2, "empty playlist\n");
sysfatal("empty");
}
+
+ if((audio = open("/dev/audio", OWRITE)) < 0)
+ sysfatal("audio: %r");
if(initdraw(nil, nil, "zuke") < 0)
sysfatal("initdraw: %r");