public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Cc: Takashi Yano <takashi.yano@nifty.ne.jp>
Subject: [PATCH] Cygwin: dsp: Fix SNDCTL_DSP_GET[IO]SPACE before read()/write().
Date: Tue, 14 Feb 2023 23:35:55 +0900	[thread overview]
Message-ID: <20230214143555.42161-1-takashi.yano@nifty.ne.jp> (raw)

Even with the commit 3a4c740f59c0, SNDCTL_DSP_GET[IO]SPACE ioctl()
does not return the fragment set by SNDCTL_DSP_SETFRAGMENT if it
is issued before read()/write(). This patch fixes the issue.

Fixes: 3a4c740f59c0 ("Cygwin: dsp: Implement SNDCTL_DSP_SETFRAGMENT ioctl().")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
---
 winsup/cygwin/fhandler/dsp.cc | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/winsup/cygwin/fhandler/dsp.cc b/winsup/cygwin/fhandler/dsp.cc
index dd1aac8e2..16db6bb29 100644
--- a/winsup/cygwin/fhandler/dsp.cc
+++ b/winsup/cygwin/fhandler/dsp.cc
@@ -1369,11 +1369,17 @@ fhandler_dev_dsp::_ioctl (unsigned int cmd, void *buf)
 	    return -1;
 	  }
 	audio_buf_info *p = (audio_buf_info *) buf;
-        if (audio_out_) {
-            audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
-        } else {
-            Audio_out::default_buf_info(p, audiofreq_, audiobits_, audiochannels_);
-        }
+	if (audio_out_)
+	  audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
+	else if (fragment_has_been_set)
+	  {
+	    p->bytes = fragsize_ * fragstotal_;
+	    p->fragsize = fragsize_;
+	    p->fragstotal = fragstotal_;
+	    p->fragments = fragstotal_;
+	  }
+	else
+	  Audio_out::default_buf_info(p, audiofreq_, audiobits_, audiochannels_);
         debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d",
                       buf, p->fragments, p->fragsize, p->bytes);
 	return 0;
@@ -1387,11 +1393,17 @@ fhandler_dev_dsp::_ioctl (unsigned int cmd, void *buf)
 	    return -1;
 	  }
 	audio_buf_info *p = (audio_buf_info *) buf;
-        if (audio_in_) {
-            audio_in_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
-        } else {
-            Audio_in::default_buf_info(p, audiofreq_, audiobits_, audiochannels_);
-        }
+	if (audio_in_)
+	  audio_in_->buf_info (p, audiofreq_, audiobits_, audiochannels_);
+	else if (fragment_has_been_set)
+	  {
+	    p->bytes = 0;
+	    p->fragsize = fragsize_;
+	    p->fragstotal = fragstotal_;
+	    p->fragments = 0;
+	  }
+	else
+	  Audio_in::default_buf_info(p, audiofreq_, audiobits_, audiochannels_);
         debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d",
                       buf, p->fragments, p->fragsize, p->bytes);
 	return 0;
-- 
2.39.0


                 reply	other threads:[~2023-02-14 14:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230214143555.42161-1-takashi.yano@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin-patches@cygwin.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).