9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Eli Cohen <echoline@gmail.com>
To: 9front@9front.org
Subject: [9front] Re: drawterm patches
Date: Thu, 27 Jan 2022 16:24:09 -0800	[thread overview]
Message-ID: <CAHwi9byuxj6LE5g2B7C8GBKc8s0f02yUORHDXNm+og17pTBYJg@mail.gmail.com> (raw)
In-Reply-To: <CAHwi9bzvSP7S0CBHiCjV9f=-Guc0sZ90Fg-bzjpwn72+9k9KLA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 820 bytes --]

this one seems to work better, at least on my system

On Thu, Jan 27, 2022 at 4:08 PM Eli Cohen <echoline@gmail.com> wrote:
>
> sorry, wait... I don't think the alsa patch is quite right after further testing
>
> On Thu, Jan 27, 2022 at 3:59 PM Eli Cohen <echoline@gmail.com> wrote:
> >
> > I have attached a couple more drawterm patches that may be of
> > interest, and a Make.alsa configuration file
> >
> > the alsa patches change devaudio.c a little bit to add audiodevread
> > support which (only) devaudio-alsa.c uses
> >
> > the bindflags patch adds -R and -C options to not bind /mnt/term/root
> > and /mnt/term/cmd respectively for a slightly more secure drawterm
> > session. I tried to do the same for -I with /mnt/term/net to disallow
> > using drawterm's networking but then it just wouldn't connect at all

[-- Attachment #2: drawterm.alsa.patch --]
[-- Type: text/x-patch, Size: 2350 bytes --]

diff --git a/kern/devaudio-alsa.c b/kern/devaudio-alsa.c
index 30dfd60..2042139 100644
--- a/kern/devaudio-alsa.c
+++ b/kern/devaudio-alsa.c
@@ -76,17 +76,20 @@ int
 audiodevwrite(void *v, int n)
 {
 	snd_pcm_sframes_t frames;
-	int tot, m;
+	int tot, m, fr;
 
 	for(tot = 0; tot < n; tot += m){
+		fr = (n-tot)/4;
 		do {
-			frames = snd_pcm_writei(playback, v+tot, (n-tot)/4);
-		} while(frames == -EAGAIN);
+			frames = snd_pcm_writei(playback, v+tot, fr);
+			if (frames < 0 && snd_pcm_recover(playback, frames, 0) == 0)
+				frames = fr;
+			if (frames < 0)
+				break;
+		} while(frames != fr);
 		if (frames < 0)
-			frames = snd_pcm_recover(playback, frames, 0);
-		if (frames < 0)
-			error((char*)snd_strerror(frames));
-		m = frames*4;
+			error("snd_pcm_writei");
+		m = n-tot;
 	}
 
 	return tot;
@@ -100,9 +103,11 @@ audiodevread(void *v, int n)
 	do {
 		frames = snd_pcm_readi(capture, v, n/4);
 	} while(frames == -EAGAIN);
-
+	if (frames < 0 && snd_pcm_recover(capture, frames, 0) == 0)
+		frames = n/4;
 	if (frames < 0)
-		error((char*)snd_strerror(frames));
+		error("snd_pcm_readi");
 
 	return frames*4;
 }
+
diff --git a/kern/devaudio.c b/kern/devaudio.c
index 1655262..0009994 100644
--- a/kern/devaudio.c
+++ b/kern/devaudio.c
@@ -14,6 +14,7 @@ enum
 	Aclosed		= 0,
 	Aread,
 	Awrite,
+	Ardwr,
 
 	Speed		= 44100,
 	Ncmd		= 50,		/* max volume command words */
@@ -31,7 +32,7 @@ static	struct
 {
 	QLock	lk;
 	Rendez	vous;
-	int	amode;		/* Aclosed/Aread/Awrite for /audio */
+	int	amode;		/* Aclosed/Aread/Awrite/Ardwr for /audio */
 } audio;
 
 #define aqlock(a) qlock(&(a)->lk)
@@ -114,6 +115,8 @@ audioopen(Chan *c, int omode)
 		amode = Awrite;
 		if((omode&7) == OREAD)
 			amode = Aread;
+		else if((omode&7) == ORDWR)
+			amode = Ardwr;
 		aqlock(&audio);
 		if(waserror()){
 			aqunlock(&audio);
@@ -178,7 +181,7 @@ audioread(Chan *c, void *v, long n, vlong off)
 		return devdirread(c, a, n, audiodir, nelem(audiodir), devgen);
 
 	case Qaudio:
-		if(audio.amode != Aread)
+		if(audio.amode != Aread && audio.amode != Ardwr)
 			error(Emode);
 		aqlock(&audio);
 		if(waserror()){
@@ -324,7 +327,7 @@ audiowrite(Chan *c, void *vp, long n, vlong off)
 		break;
 
 	case Qaudio:
-		if(audio.amode != Awrite)
+		if(audio.amode != Awrite && audio.amode != Ardwr)
 			error(Emode);
 		aqlock(&audio);
 		if(waserror()){

  reply	other threads:[~2022-01-28 19:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-27 23:59 [9front] " Eli Cohen
2022-01-28  0:08 ` [9front] " Eli Cohen
2022-01-28  0:24   ` Eli Cohen [this message]
2022-01-28  0:44     ` Eli Cohen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHwi9byuxj6LE5g2B7C8GBKc8s0f02yUORHDXNm+og17pTBYJg@mail.gmail.com \
    --to=echoline@gmail.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).