From: David Henningsson <david.henningsson@canonical.com>
To: Irfan Shaikh <irfan.shaikh@sasken.com>
Cc: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Subject: Re: SEGFAULT : snd_pcm_mmap_begin/commit
Date: Tue, 16 Nov 2010 09:59:09 +0100 [thread overview]
Message-ID: <4CE247DD.7010303@canonical.com> (raw)
In-Reply-To: <16F32A3F9AF4E441B752BCD79C151ACA5D9A2EE33F@EXGMBX01.sasken.com>
On 2010-11-16 09:44, Irfan Shaikh wrote:
> Hello All,
>
> I have been facing dificulty in using snd_pcm_mmap_begin and snd_pcm_mmap_commit.
> Shows Seg fault as pointed by comment in code below.
> Please tell me what wrong i am doing and how do i correct.
>
> /###################################################################################/
> unsigned int count = (alsaParams->frames/(((alsaParams->bit_per_sample)*(alsaParams->num_channel)) / 8));
> unsigned char *data = alsaParams->data;https://owa.sasken.com/owa/?ae=Item&t=IPM.Note&a=New#
> snd_pcm_sframes_t frames_available, frames_transmit;
> const snd_pcm_channel_area_t *area;
> snd_pcm_uframes_t offset;
> char *outbuffer;
> int result;
>
> /*available space in audio-buffer to write to*/
> frames_available = snd_pcm_avail_update(alsaParams->pcm_handle);
>
> /*
> * prepare the areas
> * and get back area, offset and frames_transmit
> * frames_transmit gives back the REAL value of available frames which could be written to in the mmaped-area
> * frames_transmit are less than frames_available
> */
> frames_transmit = frames_available;
>
> snd_pcm_mmap_begin(alsaParams->pcm_handle,&area,&offset,&frames_transmit);
>
> /*calculates the mmaped-buffer which could be written to*/
> outbuffer = ((char *) area->addr + (area->first + area->step * offset)/ 8); // ****** SEGFAULT *******
Well, the only pointer dereference is to area, so area has an invalid
pointer. Please check the return value of snd_pcm_mmap_begin to see why.
>
> /*gives back the virtually written (writable) frames which should be always == frames_transmit*/
> result = snd_pcm_mmap_commit(alsaParams->pcm_handle, offset, frames_transmit);
>
> memcpy(outbuffer, data, count); //data is actual data
Hmm, I've haven't used snd_pcm_mmap_* in a long time, but shouldn't the
memcpy be above snd_pcm_mmap_commit? Second, if you're using memcpy, why
don't settle with snd_pcm_writei in the first place?
--
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
next prev parent reply other threads:[~2010-11-16 8:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-16 8:44 SEGFAULT : snd_pcm_mmap_begin/commit Irfan Shaikh
2010-11-16 8:59 ` David Henningsson [this message]
2010-11-16 9:18 ` Irfan Shaikh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CE247DD.7010303@canonical.com \
--to=david.henningsson@canonical.com \
--cc=alsa-devel@alsa-project.org \
--cc=irfan.shaikh@sasken.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.