[alsa-devel] snd_pcm_mmap_commit

Irfan Shaikh irfan.shaikh at sasken.com
Fri Nov 19 11:16:28 CET 2010


As per your valuable inputs modified code using snd_pcm_wait
/$$$$ My code waits indefinetly in snd_pcm_wait() $$$$$/
If i set some timer again frames available shows to be zero.

#ifdef DIRECT1
  snd_pcm_state_t state;
  int err, first = 1;
  snd_pcm_sframes_t frames_available, frames_transmit,commitres;
  snd_pcm_uframes_t size, offset;
  unsigned char *outbuffer;
  const snd_pcm_channel_area_t *area;
  static int irf=0;


  state = snd_pcm_state(alsaParams->pcm_handle);
  if (state == SND_PCM_STATE_XRUN)
  {
    err=xrun_recovery(alsaParams->pcm_handle, -EPIPE);
    if (err < 0) {
      printf("XRUN recovery failed: %s\n", snd_strerror(err));
      exit(EXIT_FAILURE);
    }
    first = 1;
  }
  else if (state == SND_PCM_STATE_SUSPENDED)
  {
    err = xrun_recovery(alsaParams->pcm_handle, -ESTRPIPE);
    if (err < 0) {
      printf("SUSPEND recovery failed: %s\n", snd_strerror(err));
      exit(EXIT_FAILURE);
    }
  }
   frames_available = snd_pcm_avail_update(alsaParams->pcm_handle);
  if (frames_available < 0) {
    err = xrun_recovery(alsaParams->pcm_handle, frames_available);
    if (err < 0) {
      printf("avail update failed: %s\n", snd_strerror(err));
      exit(EXIT_FAILURE);
    }
    first = 1;
    printf("RETURN : Should Be continued\n");
    return;
  }
  printf("Farames available : %d\n", frames_available);
  if(frames_available<=0)
  {
#if 1
      err = snd_pcm_wait(alsaParams->pcm_handle, -1);    /############ WAIT here indefinitely ##############/
      if (err < 0) {
        if ((err = xrun_recovery(alsaParams->pcm_handle, err)) < 0) {
          printf("snd_pcm_wait error: %s\n", snd_strerror(err));
          exit(EXIT_FAILURE);
        }
      }
#endif
      irf=1;
      return;
  }
  else if(irf==1)
  {
      err = snd_pcm_start(alsaParams->pcm_handle);
      if (err < 0) {
        printf("Start error: %s\n", snd_strerror(err));
        exit(EXIT_FAILURE);
      }
      irf=0;
  }
   size=frames_available;
  while (size > 0) {
    frames_transmit = size;
    err=snd_pcm_mmap_begin(alsaParams->pcm_handle, &area, &offset, &frames_transmit);
    if (err < 0) {
      if ((err = xrun_recovery(alsaParams->pcm_handle, err)) < 0) {
        printf("MMAP begin avail error: %s\n", snd_strerror(err));
        exit(EXIT_FAILURE);
      }
      first = 1;
    }
    printf(">>>>Begin result : %d\n", err);
    outbuffer = ((char *) area->addr + (area->first + area->step * offset)/ 8); //Copies Actual data

    commitres = snd_pcm_mmap_commit(alsaParams->pcm_handle, offset, frames_transmit);
    if (commitres < 0 || (snd_pcm_uframes_t)commitres != frames_transmit) {
      if ((err = xrun_recovery(alsaParams->pcm_handle, commitres >= 0 ? -EPIPE : commitres)) < 0) {
        printf("MMAP commit error: %s\n", snd_strerror(err));
        exit(EXIT_FAILURE);
      }
      first = 1;
    }
    printf(">>>>>>>>>>>>>>>>>>>>>>Comit result : %d\n", commitres);
    size -= frames_transmit;
  }
#endif



________________________________________
From: Jaroslav Kysela [perex at perex.cz]
Sent: Friday, November 19, 2010 12:41 PM
To: Irfan Shaikh
Cc: alsa-devel at alsa-project.org
Subject: Re: [alsa-devel] snd_pcm_mmap_commit

On Fri, 19 Nov 2010, Irfan Shaikh wrote:

> /*************************************************************/
> Code below O/p results runs in a while loop till end of PCM data.
> 1) First time O/p is
>          Farames available : 1024                                                /*Return VALUE of snd_pcm_avail_update*/
>          >>>>>>>>>>>>>>>>>>>>>>>>>Begin result : 0      /*Return VALUE of snd_pcm_mmap_begin*/
>          Address outbuffer : 0xcff88
>          >>>>>>>>>>>>>>>>>>>>>>Comit result : 1024       /*SUCESSFUL - Return VALUE of  snd_pcm_mmap_commi*/
>
> 2) Second time onwards ALWAYS O/p is
>          Farames available : 0                                                      /*Return VALUE of snd_pcm_avail_update*/
>          >>>>>>>>>>>>>>>>>>>>>>>>>Begin result : 0      /*Return VALUE of snd_pcm_mmap_begin*/
>          Address outbuffer : 0xcff88
>          >>>>>>>>>>>>>>>>>>>>>>Comit result : 0             /*FAILURE - Return VALUE of  snd_pcm_mmap_commit*/

You have to use poll()/select() or snd_pcm_wait() to wait for a room in
the playback buffer. The direct mmap I/O is always non-blocked.

                                                Jaroslav

-----
Jaroslav Kysela <perex at perex.cz>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.


SASKEN BUSINESS DISCLAIMER: This message may contain confidential, proprietary or legally privileged information. In case you are not the original intended Recipient of the message, you must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message and you are requested to delete it and inform the sender. Any views expressed in this message are those of the individual sender unless otherwise stated. Nothing contained in this message shall be construed as an offer or acceptance of any offer by Sasken Communication Technologies Limited ("Sasken") unless sent with that express intent and with due authority of Sasken. Sasken has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email.
Read Disclaimer at http://www.sasken.com/extras/mail_disclaimer.html


More information about the Alsa-devel mailing list