Subject: kern/35171: AUDIO_WSEEK ioctl implementation conflicts with documentation
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <svs@ropnet.ru>
List: netbsd-bugs
Date: 12/02/2006 22:55:00
>Number:         35171
>Category:       kern
>Synopsis:       AUDIO_WSEEK ioctl implementation conflicts with documentation
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 02 22:55:00 +0000 2006
>Originator:     Sergey Svishchev
>Release:        3.0.2_PATCH
>Organization:
>Environment:
>Description:
man page:

AUDIO_WSEEK (int)
  This command fetches the count of samples that are queued ahead
  of the first sample in the most recent sample block written into
  its integer argument.

sys/dev/audio.c (both 3.0 and -current):

/*
 * How many bytes will elapse until mike hears the first
 * sample of what we write next?
 */
case AUDIO_WSEEK:
  *(u_long *)addr = audio_stream_get_used(sc->sc_rustream);

But isn't sc->sc_rustream the 'recording' stream, not the 'playing' one?..
>How-To-Repeat:
Run this code.  'wseek' is always 0, but should be equal to 'play.seek', I think.

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <err.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/audioio.h>

main() 
{
int fd, rc, wseek = -1;
struct audio_info ai;

  fd = open("/dev/audioctl", O_RDONLY);
  if (fd < 0) {
    perror("open /dev/audioctl");
    err(1, NULL);
  }

  rc = ioctl(fd, AUDIO_WSEEK, &wseek);
  if (rc < 0) {
    perror("ioctl AUDIO_WSEEK");
  }

  rc = ioctl(fd, AUDIO_GETINFO, &ai);
  if (rc < 0) {
    perror("ioctl AUDIO_GETINFO");
  }

  printf ("wseek %d play.seek %d play.samples %d\n", 
    wseek, ai.play.seek, ai.play.samples);
  return 0;
}

>Fix: