Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write ioctl is not guaranteed to write requested number of frames #18

Open
djadala opened this issue Dec 21, 2020 · 1 comment
Open

Comments

@djadala
Copy link

djadala commented Dec 21, 2020

alsa/device.go

Line 256 in d079056

func (device *Device) Write(buf []byte, frames int) error {

Hi,
sometimes write method write less number of frames, here is how i fixed this:

func (device *Device) write1(buf []byte, frames int) (int, error) {
	x := pcm.XferI{
		Buf:    uintptr(unsafe.Pointer(&buf[0])),
		Frames: alsatype.Uframes(frames),
	}
	err := ioctl(device.fh.Fd(), ioctl_encode_ptr(cmdWrite, &x, cmdPCMWriteIFrames), &x)
        written := alsatype.Uframes(frames)
	if  err == syscall.EAGAIN {
		return written, nil
	} 
	return written, err
}


func (device *Device) Write(buf []byte, framesize int) error {

	for len(buf) > 0 {
		w, err := dev.write1(buf, len(buf)/framesize)
		if err != nil {
			return  err
		}
		buf = buf[w*framesize:]
	}
}

i not going to send PR, please update from this issue,

Regards

PS
May be Read can also read less that requested frames ?

@yobert
Copy link
Owner

yobert commented Jan 26, 2023

Great report! That makes sense. I was hoping it would block until it was able to write as many frames as requested. I'll make a PR for this sometime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants