~ft/zuke

fdbf31f12cf811f66a123fa5abcd87b68ec771b7 — Sigrid Haflínudóttir 7 months ago d074aa0
remove all /dev/audio reopening logic
1 files changed, 4 insertions(+), 22 deletions(-)

M zuke.c
M zuke.c => zuke.c +4 -22
@@ 42,6 42,7 @@ struct Player

int mainstacksize = 32768;

static int audio;
static Meta *pl;
static int plnum;
static char *plraw;


@@ 421,17 422,6 @@ start(Player *player)
	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 @@ playerthread(void *player_)
	ulong c;
	int p[2], fd, pid, n, got, noinit, trycoverload;
	u64int bytesfrom, bf;
	int audio;
	Meta *cur;

	threadsetname("player");


@@ 454,7 443,6 @@ playerthread(void *player_)
	trycoverload = 1;
	io = nil;
	pid = -1;
	audio = -1;

restart:
	cur = getmeta(player->pcur);


@@ 504,7 492,6 @@ restart:
			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 @@ restart:
		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 @@ restart:
		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 @@ restart:
			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:


@@ 910,6 889,9 @@ threadmain(int argc, char **argv)
		sysfatal("empty");
	}

	if((audio = open("/dev/audio", OWRITE)) < 0)
		sysfatal("audio: %r");

	if(initdraw(nil, nil, "zuke") < 0)
		sysfatal("initdraw: %r");
	unlockdisplay(display);