Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 181568
b: refs/heads/master
c: 60433e2
h: refs/heads/master
v: v3
  • Loading branch information
Devin Heitmueller authored and Mauro Carvalho Chehab committed Feb 26, 2010
1 parent 989827e commit e48ab05
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 81 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 71036ef26b0026742c8ab79a54937aac1439350d
refs/heads/master: 60433e2ab8391d1884ddef2269bd19ecdaaa2d72
156 changes: 76 additions & 80 deletions trunk/drivers/media/video/cx18/cx18-alsa-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ MODULE_PARM_DESC(pcm_debug, "enable debug messages for pcm");
__func__, ##arg); \
} while (0)

/* Forward Declaration */
void cx18_alsa_announce_pcm_data(struct snd_cx18_card *cxsc, u8 *pcm_data,
size_t num_bytes);

static struct snd_pcm_hardware snd_cx18_hw_capture = {
.info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP |
Expand All @@ -72,6 +68,82 @@ static struct snd_pcm_hardware snd_cx18_hw_capture = {
.periods_max = 98, /* 12544, */
};

void cx18_alsa_announce_pcm_data(struct snd_cx18_card *cxsc, u8 *pcm_data,
size_t num_bytes)
{
struct snd_pcm_substream *substream;
struct snd_pcm_runtime *runtime;
unsigned int oldptr;
unsigned int stride;
int period_elapsed = 0;
int length;

dprintk("cx18 alsa announce ptr=%p data=%p num_bytes=%d\n", cxsc,
pcm_data, num_bytes);

substream = cxsc->capture_pcm_substream;
if (substream == NULL) {
dprintk("substream was NULL\n");
return;
}

runtime = substream->runtime;
if (runtime == NULL) {
dprintk("runtime was NULL\n");
return;
}

stride = runtime->frame_bits >> 3;
if (stride == 0) {
dprintk("stride is zero\n");
return;
}

length = num_bytes / stride;
if (length == 0) {
dprintk("%s: length was zero\n", __func__);
return;
}

if (runtime->dma_area == NULL) {
dprintk("dma area was NULL - ignoring\n");
return;
}

oldptr = cxsc->hwptr_done_capture;
if (oldptr + length >= runtime->buffer_size) {
unsigned int cnt =
runtime->buffer_size - oldptr;
memcpy(runtime->dma_area + oldptr * stride, pcm_data,
cnt * stride);
memcpy(runtime->dma_area, pcm_data + cnt * stride,
length * stride - cnt * stride);
} else {
memcpy(runtime->dma_area + oldptr * stride, pcm_data,
length * stride);
}
snd_pcm_stream_lock(substream);

cxsc->hwptr_done_capture += length;
if (cxsc->hwptr_done_capture >=
runtime->buffer_size)
cxsc->hwptr_done_capture -=
runtime->buffer_size;

cxsc->capture_transfer_done += length;
if (cxsc->capture_transfer_done >=
runtime->period_size) {
cxsc->capture_transfer_done -=
runtime->period_size;
period_elapsed = 1;
}

snd_pcm_stream_unlock(substream);

if (period_elapsed)
snd_pcm_period_elapsed(substream);
}

static int snd_cx18_pcm_capture_open(struct snd_pcm_substream *substream)
{
struct snd_cx18_card *cxsc = snd_pcm_substream_chip(substream);
Expand Down Expand Up @@ -245,82 +317,6 @@ static struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
.page = snd_pcm_get_vmalloc_page,
};

void cx18_alsa_announce_pcm_data(struct snd_cx18_card *cxsc, u8 *pcm_data,
size_t num_bytes)
{
struct snd_pcm_substream *substream;
struct snd_pcm_runtime *runtime;
unsigned int oldptr;
unsigned int stride;
int period_elapsed = 0;
int length;

dprintk("cx18 alsa announce ptr=%p data=%p num_bytes=%d\n", cxsc,
pcm_data, num_bytes);

substream = cxsc->capture_pcm_substream;
if (substream == NULL) {
dprintk("substream was NULL\n");
return;
}

runtime = substream->runtime;
if (runtime == NULL) {
dprintk("runtime was NULL\n");
return;
}

stride = runtime->frame_bits >> 3;
if (stride == 0) {
dprintk("stride is zero\n");
return;
}

length = num_bytes / stride;
if (length == 0) {
dprintk("%s: length was zero\n", __func__);
return;
}

if (runtime->dma_area == NULL) {
dprintk("dma area was NULL - ignoring\n");
return;
}

oldptr = cxsc->hwptr_done_capture;
if (oldptr + length >= runtime->buffer_size) {
unsigned int cnt =
runtime->buffer_size - oldptr;
memcpy(runtime->dma_area + oldptr * stride, pcm_data,
cnt * stride);
memcpy(runtime->dma_area, pcm_data + cnt * stride,
length * stride - cnt * stride);
} else {
memcpy(runtime->dma_area + oldptr * stride, pcm_data,
length * stride);
}
snd_pcm_stream_lock(substream);

cxsc->hwptr_done_capture += length;
if (cxsc->hwptr_done_capture >=
runtime->buffer_size)
cxsc->hwptr_done_capture -=
runtime->buffer_size;

cxsc->capture_transfer_done += length;
if (cxsc->capture_transfer_done >=
runtime->period_size) {
cxsc->capture_transfer_done -=
runtime->period_size;
period_elapsed = 1;
}

snd_pcm_stream_unlock(substream);

if (period_elapsed)
snd_pcm_period_elapsed(substream);
}

int snd_cx18_pcm_create(struct snd_cx18_card *cxsc)
{
struct snd_pcm *sp;
Expand Down

0 comments on commit e48ab05

Please sign in to comment.