tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Audio device mmap and kevents
At Tue, 29 Jan 2019 16:06:40 +0900,
Tetsuya Isaki wrote:
> > looks good to me. Can you test recording?
>
> I will try it. (I need to setup)
I confirmed that GETISPACE at least looks correct with attached
sample code (by watching and calulating it manually :)
And I also confirmed that mplayer+pulseaudio on netbsd-8 worked
even with the patch. (Although, I'm not sure why pulseaudio
recording operation affects playback, too.)
Anyway, I'll commit GETISPACE part.
Thank you for comments.
---
Tetsuya Isaki <isaki%pastel-flower.jp@localhost / isaki%NetBSD.org@localhost>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/audioio.h>
#include <soundcard.h>
#include <unistd.h>
int main(int ac, char *av[])
{
struct audio_info ai;
struct audio_buf_info bufinfo;
int r;
int afd = open("/dev/audio0", O_RDONLY);
if (afd == -1)
err(1, "open audio");
r = ioctl(afd, AUDIO_GETBUFINFO, &ai);
if (r == -1)
err(1, "AUDIO_GETBUFINFO");
printf("ai.record.buffer_size=%d\n", ai.record.buffer_size);
printf("ai.blocksize=%d\n", ai.blocksize);
printf("ai.hiwat=%d\n", ai.hiwat);
char buf[3000]; // read and discard
while (1) {
r = read(afd, buf, sizeof(buf));
printf("read(%d bytes)\n", r);
if (r != sizeof(buf))
err(1, "read");
r = ioctl(afd, AUDIO_GETBUFINFO, &ai);
if (r == -1)
err(1, "GETBUFINFO");
r = ioctl(afd, SNDCTL_DSP_GETISPACE, &bufinfo);
if (r == -1)
err(1, "GETISPACE");
printf("record.seek=%d : ", ai.record.seek);
printf("fragments=%d fragstotal=%d fragsize=%d bytes=%d\n",
bufinfo.fragments, bufinfo.fragstotal,
bufinfo.fragsize, bufinfo.bytes);
if (bufinfo.bytes < sizeof(buf)) {
printf("sleep\n");
sleep(1);
continue;
}
}
/* NOTREACHED */
close(afd);
return 0;
}
Home |
Main Index |
Thread Index |
Old Index