https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a9a17f5fe51498b182d4a11ac48207b8c7ffe8ec

commit a9a17f5fe51498b182d4a11ac48207b8c7ffe8ec
Author: Takashi Yano <[email protected]>
Date:   Tue Feb 14 22:55:10 2023 +0900

    Cygwin: dsp: Fix SNDCTL_DSP_GET[IO]SPACE before read()/write().
    
    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 <[email protected]>

Diff:
---
 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;

Reply via email to