Commit f705e6e4 authored by Andreas Oberritter's avatar Andreas Oberritter Committed by Linus Torvalds

V4L/DVB (3438): Optical cleanup for dmxdev.c

Used Lindent, manually changed some line breaks. Removed invalid email
addresses, useless casts and useless initialization of return values.
Signed-off-by: default avatarAndreas Oberritter <obi@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent bbad7dc5
/* /*
* dmxdev.c - DVB demultiplexer device * dmxdev.c - DVB demultiplexer device
* *
* Copyright (C) 2000 Ralph Metzler <ralph@convergence.de> * Copyright (C) 2000 Ralph Metzler & Marcus Metzler
* & Marcus Metzler <marcus@convergence.de> * for convergence integrated media GmbH
for convergence integrated media GmbH
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License * modify it under the terms of the GNU Lesser General Public License
...@@ -32,7 +31,6 @@ ...@@ -32,7 +31,6 @@
#include <linux/wait.h> #include <linux/wait.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/system.h> #include <asm/system.h>
#include "dmxdev.h" #include "dmxdev.h"
static int debug; static int debug;
...@@ -44,15 +42,16 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); ...@@ -44,15 +42,16 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
static inline void dvb_dmxdev_buffer_init(struct dmxdev_buffer *buffer) static inline void dvb_dmxdev_buffer_init(struct dmxdev_buffer *buffer)
{ {
buffer->data=NULL; buffer->data = NULL;
buffer->size=8192; buffer->size = 8192;
buffer->pread=0; buffer->pread = 0;
buffer->pwrite=0; buffer->pwrite = 0;
buffer->error=0; buffer->error = 0;
init_waitqueue_head(&buffer->queue); init_waitqueue_head(&buffer->queue);
} }
static inline int dvb_dmxdev_buffer_write(struct dmxdev_buffer *buf, const u8 *src, int len) static inline int dvb_dmxdev_buffer_write(struct dmxdev_buffer *buf,
const u8 *src, int len)
{ {
int split; int split;
int free; int free;
...@@ -63,98 +62,99 @@ static inline int dvb_dmxdev_buffer_write(struct dmxdev_buffer *buf, const u8 *s ...@@ -63,98 +62,99 @@ static inline int dvb_dmxdev_buffer_write(struct dmxdev_buffer *buf, const u8 *s
if (!buf->data) if (!buf->data)
return 0; return 0;
free=buf->pread-buf->pwrite; free = buf->pread - buf->pwrite;
split=0; split = 0;
if (free<=0) { if (free <= 0) {
free+=buf->size; free += buf->size;
split=buf->size-buf->pwrite; split = buf->size - buf->pwrite;
} }
if (len>=free) { if (len >= free) {
dprintk("dmxdev: buffer overflow\n"); dprintk("dmxdev: buffer overflow\n");
return -1; return -1;
} }
if (split>=len) if (split >= len)
split=0; split = 0;
todo=len; todo = len;
if (split) { if (split) {
memcpy(buf->data + buf->pwrite, src, split); memcpy(buf->data + buf->pwrite, src, split);
todo-=split; todo -= split;
buf->pwrite=0; buf->pwrite = 0;
} }
memcpy(buf->data + buf->pwrite, src+split, todo); memcpy(buf->data + buf->pwrite, src + split, todo);
buf->pwrite=(buf->pwrite+todo)%buf->size; buf->pwrite = (buf->pwrite + todo) % buf->size;
return len; return len;
} }
static ssize_t dvb_dmxdev_buffer_read(struct dmxdev_buffer *src, static ssize_t dvb_dmxdev_buffer_read(struct dmxdev_buffer *src,
int non_blocking, char __user *buf, size_t count, loff_t *ppos) int non_blocking, char __user *buf,
size_t count, loff_t *ppos)
{ {
unsigned long todo=count; unsigned long todo = count;
int split, avail, error; int split, avail, error;
if (!src->data) if (!src->data)
return 0; return 0;
if ((error=src->error)) { if ((error = src->error)) {
src->pwrite=src->pread; src->pwrite = src->pread;
src->error=0; src->error = 0;
return error; return error;
} }
if (non_blocking && (src->pwrite==src->pread)) if (non_blocking && (src->pwrite == src->pread))
return -EWOULDBLOCK; return -EWOULDBLOCK;
while (todo>0) { while (todo > 0) {
if (non_blocking && (src->pwrite==src->pread)) if (non_blocking && (src->pwrite == src->pread))
return (count-todo) ? (count-todo) : -EWOULDBLOCK; return (count - todo) ? (count - todo) : -EWOULDBLOCK;
if (wait_event_interruptible(src->queue, if (wait_event_interruptible(src->queue,
(src->pread!=src->pwrite) || (src->pread != src->pwrite) ||
(src->error))<0) (src->error)) < 0)
return count-todo; return count - todo;
if ((error=src->error)) { if ((error = src->error)) {
src->pwrite=src->pread; src->pwrite = src->pread;
src->error=0; src->error = 0;
return error; return error;
} }
split=src->size; split = src->size;
avail=src->pwrite - src->pread; avail = src->pwrite - src->pread;
if (avail<0) { if (avail < 0) {
avail+=src->size; avail += src->size;
split=src->size - src->pread; split = src->size - src->pread;
} }
if (avail>todo) if (avail > todo)
avail=todo; avail = todo;
if (split<avail) { if (split < avail) {
if (copy_to_user(buf, src->data+src->pread, split)) if (copy_to_user(buf, src->data + src->pread, split))
return -EFAULT; return -EFAULT;
buf+=split; buf += split;
src->pread=0; src->pread = 0;
todo-=split; todo -= split;
avail-=split; avail -= split;
} }
if (avail) { if (avail) {
if (copy_to_user(buf, src->data+src->pread, avail)) if (copy_to_user(buf, src->data + src->pread, avail))
return -EFAULT; return -EFAULT;
src->pread = (src->pread + avail) % src->size; src->pread = (src->pread + avail) % src->size;
todo-=avail; todo -= avail;
buf+=avail; buf += avail;
} }
} }
return count; return count;
} }
static struct dmx_frontend * get_fe(struct dmx_demux *demux, int type) static struct dmx_frontend *get_fe(struct dmx_demux *demux, int type)
{ {
struct list_head *head, *pos; struct list_head *head, *pos;
head=demux->get_frontends(demux); head = demux->get_frontends(demux);
if (!head) if (!head)
return NULL; return NULL;
list_for_each(pos, head) list_for_each(pos, head)
if (DMX_FE_ENTRY(pos)->source==type) if (DMX_FE_ENTRY(pos)->source == type)
return DMX_FE_ENTRY(pos); return DMX_FE_ENTRY(pos);
return NULL; return NULL;
...@@ -166,37 +166,37 @@ static int dvb_dvr_open(struct inode *inode, struct file *file) ...@@ -166,37 +166,37 @@ static int dvb_dvr_open(struct inode *inode, struct file *file)
struct dmxdev *dmxdev = dvbdev->priv; struct dmxdev *dmxdev = dvbdev->priv;
struct dmx_frontend *front; struct dmx_frontend *front;
dprintk ("function : %s\n", __FUNCTION__); dprintk("function : %s\n", __FUNCTION__);
if (mutex_lock_interruptible(&dmxdev->mutex)) if (mutex_lock_interruptible(&dmxdev->mutex))
return -ERESTARTSYS; return -ERESTARTSYS;
if ((file->f_flags&O_ACCMODE)==O_RDWR) { if ((file->f_flags & O_ACCMODE) == O_RDWR) {
if (!(dmxdev->capabilities&DMXDEV_CAP_DUPLEX)) { if (!(dmxdev->capabilities & DMXDEV_CAP_DUPLEX)) {
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
} }
if ((file->f_flags&O_ACCMODE)==O_RDONLY) { if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer); dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer);
dmxdev->dvr_buffer.size=DVR_BUFFER_SIZE; dmxdev->dvr_buffer.size = DVR_BUFFER_SIZE;
dmxdev->dvr_buffer.data=vmalloc(DVR_BUFFER_SIZE); dmxdev->dvr_buffer.data = vmalloc(DVR_BUFFER_SIZE);
if (!dmxdev->dvr_buffer.data) { if (!dmxdev->dvr_buffer.data) {
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return -ENOMEM; return -ENOMEM;
} }
} }
if ((file->f_flags&O_ACCMODE)==O_WRONLY) { if ((file->f_flags & O_ACCMODE) == O_WRONLY) {
dmxdev->dvr_orig_fe=dmxdev->demux->frontend; dmxdev->dvr_orig_fe = dmxdev->demux->frontend;
if (!dmxdev->demux->write) { if (!dmxdev->demux->write) {
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
front=get_fe(dmxdev->demux, DMX_MEMORY_FE); front = get_fe(dmxdev->demux, DMX_MEMORY_FE);
if (!front) { if (!front) {
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
...@@ -217,17 +217,17 @@ static int dvb_dvr_release(struct inode *inode, struct file *file) ...@@ -217,17 +217,17 @@ static int dvb_dvr_release(struct inode *inode, struct file *file)
if (mutex_lock_interruptible(&dmxdev->mutex)) if (mutex_lock_interruptible(&dmxdev->mutex))
return -ERESTARTSYS; return -ERESTARTSYS;
if ((file->f_flags&O_ACCMODE)==O_WRONLY) { if ((file->f_flags & O_ACCMODE) == O_WRONLY) {
dmxdev->demux->disconnect_frontend(dmxdev->demux); dmxdev->demux->disconnect_frontend(dmxdev->demux);
dmxdev->demux->connect_frontend(dmxdev->demux, dmxdev->demux->connect_frontend(dmxdev->demux,
dmxdev->dvr_orig_fe); dmxdev->dvr_orig_fe);
} }
if ((file->f_flags&O_ACCMODE)==O_RDONLY) { if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
if (dmxdev->dvr_buffer.data) { if (dmxdev->dvr_buffer.data) {
void *mem=dmxdev->dvr_buffer.data; void *mem = dmxdev->dvr_buffer.data;
mb(); mb();
spin_lock_irq(&dmxdev->lock); spin_lock_irq(&dmxdev->lock);
dmxdev->dvr_buffer.data=NULL; dmxdev->dvr_buffer.data = NULL;
spin_unlock_irq(&dmxdev->lock); spin_unlock_irq(&dmxdev->lock);
vfree(mem); vfree(mem);
} }
...@@ -245,11 +245,11 @@ static ssize_t dvb_dvr_write(struct file *file, const char __user *buf, ...@@ -245,11 +245,11 @@ static ssize_t dvb_dvr_write(struct file *file, const char __user *buf,
if (!dmxdev->demux->write) if (!dmxdev->demux->write)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if ((file->f_flags&O_ACCMODE)!=O_WRONLY) if ((file->f_flags & O_ACCMODE) != O_WRONLY)
return -EINVAL; return -EINVAL;
if (mutex_lock_interruptible(&dmxdev->mutex)) if (mutex_lock_interruptible(&dmxdev->mutex))
return -ERESTARTSYS; return -ERESTARTSYS;
ret=dmxdev->demux->write(dmxdev->demux, buf, count); ret = dmxdev->demux->write(dmxdev->demux, buf, count);
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return ret; return ret;
} }
...@@ -262,43 +262,45 @@ static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count, ...@@ -262,43 +262,45 @@ static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count,
int ret; int ret;
//mutex_lock(&dmxdev->mutex); //mutex_lock(&dmxdev->mutex);
ret= dvb_dmxdev_buffer_read(&dmxdev->dvr_buffer, ret = dvb_dmxdev_buffer_read(&dmxdev->dvr_buffer,
file->f_flags&O_NONBLOCK, file->f_flags & O_NONBLOCK,
buf, count, ppos); buf, count, ppos);
//mutex_unlock(&dmxdev->mutex); //mutex_unlock(&dmxdev->mutex);
return ret; return ret;
} }
static inline void dvb_dmxdev_filter_state_set(struct dmxdev_filter *dmxdevfilter, int state) static inline void dvb_dmxdev_filter_state_set(struct dmxdev_filter
*dmxdevfilter, int state)
{ {
spin_lock_irq(&dmxdevfilter->dev->lock); spin_lock_irq(&dmxdevfilter->dev->lock);
dmxdevfilter->state=state; dmxdevfilter->state = state;
spin_unlock_irq(&dmxdevfilter->dev->lock); spin_unlock_irq(&dmxdevfilter->dev->lock);
} }
static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter, unsigned long size) static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter,
unsigned long size)
{ {
struct dmxdev_buffer *buf=&dmxdevfilter->buffer; struct dmxdev_buffer *buf = &dmxdevfilter->buffer;
void *mem; void *mem;
if (buf->size==size) if (buf->size == size)
return 0; return 0;
if (dmxdevfilter->state>=DMXDEV_STATE_GO) if (dmxdevfilter->state >= DMXDEV_STATE_GO)
return -EBUSY; return -EBUSY;
spin_lock_irq(&dmxdevfilter->dev->lock); spin_lock_irq(&dmxdevfilter->dev->lock);
mem=buf->data; mem = buf->data;
buf->data=NULL; buf->data = NULL;
buf->size=size; buf->size = size;
buf->pwrite=buf->pread=0; buf->pwrite = buf->pread = 0;
spin_unlock_irq(&dmxdevfilter->dev->lock); spin_unlock_irq(&dmxdevfilter->dev->lock);
vfree(mem); vfree(mem);
if (buf->size) { if (buf->size) {
mem=vmalloc(dmxdevfilter->buffer.size); mem = vmalloc(dmxdevfilter->buffer.size);
if (!mem) if (!mem)
return -ENOMEM; return -ENOMEM;
spin_lock_irq(&dmxdevfilter->dev->lock); spin_lock_irq(&dmxdevfilter->dev->lock);
buf->data=mem; buf->data = mem;
spin_unlock_irq(&dmxdevfilter->dev->lock); spin_unlock_irq(&dmxdevfilter->dev->lock);
} }
return 0; return 0;
...@@ -306,31 +308,33 @@ static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter, unsign ...@@ -306,31 +308,33 @@ static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter, unsign
static void dvb_dmxdev_filter_timeout(unsigned long data) static void dvb_dmxdev_filter_timeout(unsigned long data)
{ {
struct dmxdev_filter *dmxdevfilter=(struct dmxdev_filter *)data; struct dmxdev_filter *dmxdevfilter = (struct dmxdev_filter *)data;
dmxdevfilter->buffer.error=-ETIMEDOUT; dmxdevfilter->buffer.error = -ETIMEDOUT;
spin_lock_irq(&dmxdevfilter->dev->lock); spin_lock_irq(&dmxdevfilter->dev->lock);
dmxdevfilter->state=DMXDEV_STATE_TIMEDOUT; dmxdevfilter->state = DMXDEV_STATE_TIMEDOUT;
spin_unlock_irq(&dmxdevfilter->dev->lock); spin_unlock_irq(&dmxdevfilter->dev->lock);
wake_up(&dmxdevfilter->buffer.queue); wake_up(&dmxdevfilter->buffer.queue);
} }
static void dvb_dmxdev_filter_timer(struct dmxdev_filter *dmxdevfilter) static void dvb_dmxdev_filter_timer(struct dmxdev_filter *dmxdevfilter)
{ {
struct dmx_sct_filter_params *para=&dmxdevfilter->params.sec; struct dmx_sct_filter_params *para = &dmxdevfilter->params.sec;
del_timer(&dmxdevfilter->timer); del_timer(&dmxdevfilter->timer);
if (para->timeout) { if (para->timeout) {
dmxdevfilter->timer.function=dvb_dmxdev_filter_timeout; dmxdevfilter->timer.function = dvb_dmxdev_filter_timeout;
dmxdevfilter->timer.data=(unsigned long) dmxdevfilter; dmxdevfilter->timer.data = (unsigned long)dmxdevfilter;
dmxdevfilter->timer.expires=jiffies+1+(HZ/2+HZ*para->timeout)/1000; dmxdevfilter->timer.expires =
jiffies + 1 + (HZ / 2 + HZ * para->timeout) / 1000;
add_timer(&dmxdevfilter->timer); add_timer(&dmxdevfilter->timer);
} }
} }
static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len, static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
const u8 *buffer2, size_t buffer2_len, const u8 *buffer2, size_t buffer2_len,
struct dmx_section_filter *filter, enum dmx_success success) struct dmx_section_filter *filter,
enum dmx_success success)
{ {
struct dmxdev_filter *dmxdevfilter = filter->priv; struct dmxdev_filter *dmxdevfilter = filter->priv;
int ret; int ret;
...@@ -340,25 +344,26 @@ static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len, ...@@ -340,25 +344,26 @@ static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
return 0; return 0;
} }
spin_lock(&dmxdevfilter->dev->lock); spin_lock(&dmxdevfilter->dev->lock);
if (dmxdevfilter->state!=DMXDEV_STATE_GO) { if (dmxdevfilter->state != DMXDEV_STATE_GO) {
spin_unlock(&dmxdevfilter->dev->lock); spin_unlock(&dmxdevfilter->dev->lock);
return 0; return 0;
} }
del_timer(&dmxdevfilter->timer); del_timer(&dmxdevfilter->timer);
dprintk("dmxdev: section callback %02x %02x %02x %02x %02x %02x\n", dprintk("dmxdev: section callback %02x %02x %02x %02x %02x %02x\n",
buffer1[0], buffer1[1], buffer1[0], buffer1[1],
buffer1[2], buffer1[3], buffer1[2], buffer1[3], buffer1[4], buffer1[5]);
buffer1[4], buffer1[5]); ret = dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer1,
ret=dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer1, buffer1_len); buffer1_len);
if (ret==buffer1_len) { if (ret == buffer1_len) {
ret=dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer2, buffer2_len); ret = dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer2,
buffer2_len);
} }
if (ret<0) { if (ret < 0) {
dmxdevfilter->buffer.pwrite=dmxdevfilter->buffer.pread; dmxdevfilter->buffer.pwrite = dmxdevfilter->buffer.pread;
dmxdevfilter->buffer.error=-EOVERFLOW; dmxdevfilter->buffer.error = -EOVERFLOW;
} }
if (dmxdevfilter->params.sec.flags&DMX_ONESHOT) if (dmxdevfilter->params.sec.flags & DMX_ONESHOT)
dmxdevfilter->state=DMXDEV_STATE_DONE; dmxdevfilter->state = DMXDEV_STATE_DONE;
spin_unlock(&dmxdevfilter->dev->lock); spin_unlock(&dmxdevfilter->dev->lock);
wake_up(&dmxdevfilter->buffer.queue); wake_up(&dmxdevfilter->buffer.queue);
return 0; return 0;
...@@ -366,42 +371,41 @@ static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len, ...@@ -366,42 +371,41 @@ static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len, static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len,
const u8 *buffer2, size_t buffer2_len, const u8 *buffer2, size_t buffer2_len,
struct dmx_ts_feed *feed, enum dmx_success success) struct dmx_ts_feed *feed,
enum dmx_success success)
{ {
struct dmxdev_filter *dmxdevfilter = feed->priv; struct dmxdev_filter *dmxdevfilter = feed->priv;
struct dmxdev_buffer *buffer; struct dmxdev_buffer *buffer;
int ret; int ret;
spin_lock(&dmxdevfilter->dev->lock); spin_lock(&dmxdevfilter->dev->lock);
if (dmxdevfilter->params.pes.output==DMX_OUT_DECODER) { if (dmxdevfilter->params.pes.output == DMX_OUT_DECODER) {
spin_unlock(&dmxdevfilter->dev->lock); spin_unlock(&dmxdevfilter->dev->lock);
return 0; return 0;
} }
if (dmxdevfilter->params.pes.output==DMX_OUT_TAP) if (dmxdevfilter->params.pes.output == DMX_OUT_TAP)
buffer=&dmxdevfilter->buffer; buffer = &dmxdevfilter->buffer;
else else
buffer=&dmxdevfilter->dev->dvr_buffer; buffer = &dmxdevfilter->dev->dvr_buffer;
if (buffer->error) { if (buffer->error) {
spin_unlock(&dmxdevfilter->dev->lock); spin_unlock(&dmxdevfilter->dev->lock);
wake_up(&buffer->queue); wake_up(&buffer->queue);
return 0; return 0;
} }
ret=dvb_dmxdev_buffer_write(buffer, buffer1, buffer1_len); ret = dvb_dmxdev_buffer_write(buffer, buffer1, buffer1_len);
if (ret==buffer1_len) if (ret == buffer1_len)
ret=dvb_dmxdev_buffer_write(buffer, buffer2, buffer2_len); ret = dvb_dmxdev_buffer_write(buffer, buffer2, buffer2_len);
if (ret<0) { if (ret < 0) {
buffer->pwrite=buffer->pread; buffer->pwrite = buffer->pread;
buffer->error=-EOVERFLOW; buffer->error = -EOVERFLOW;
} }
spin_unlock(&dmxdevfilter->dev->lock); spin_unlock(&dmxdevfilter->dev->lock);
wake_up(&buffer->queue); wake_up(&buffer->queue);
return 0; return 0;
} }
/* stop feed but only mark the specified filter as stopped (state set) */ /* stop feed but only mark the specified filter as stopped (state set) */
static int dvb_dmxdev_feed_stop(struct dmxdev_filter *dmxdevfilter) static int dvb_dmxdev_feed_stop(struct dmxdev_filter *dmxdevfilter)
{ {
dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET); dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET);
...@@ -420,20 +424,16 @@ static int dvb_dmxdev_feed_stop(struct dmxdev_filter *dmxdevfilter) ...@@ -420,20 +424,16 @@ static int dvb_dmxdev_feed_stop(struct dmxdev_filter *dmxdevfilter)
return 0; return 0;
} }
/* start feed associated with the specified filter */ /* start feed associated with the specified filter */
static int dvb_dmxdev_feed_start(struct dmxdev_filter *filter) static int dvb_dmxdev_feed_start(struct dmxdev_filter *filter)
{ {
dvb_dmxdev_filter_state_set (filter, DMXDEV_STATE_GO); dvb_dmxdev_filter_state_set(filter, DMXDEV_STATE_GO);
switch (filter->type) { switch (filter->type) {
case DMXDEV_TYPE_SEC: case DMXDEV_TYPE_SEC:
return filter->feed.sec->start_filtering(filter->feed.sec); return filter->feed.sec->start_filtering(filter->feed.sec);
break;
case DMXDEV_TYPE_PES: case DMXDEV_TYPE_PES:
return filter->feed.ts->start_filtering(filter->feed.ts); return filter->feed.ts->start_filtering(filter->feed.ts);
break;
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -441,32 +441,31 @@ static int dvb_dmxdev_feed_start(struct dmxdev_filter *filter) ...@@ -441,32 +441,31 @@ static int dvb_dmxdev_feed_start(struct dmxdev_filter *filter)
return 0; return 0;
} }
/* restart section feed if it has filters left associated with it, /* restart section feed if it has filters left associated with it,
otherwise release the feed */ otherwise release the feed */
static int dvb_dmxdev_feed_restart(struct dmxdev_filter *filter) static int dvb_dmxdev_feed_restart(struct dmxdev_filter *filter)
{ {
int i; int i;
struct dmxdev *dmxdev = filter->dev; struct dmxdev *dmxdev = filter->dev;
u16 pid = filter->params.sec.pid; u16 pid = filter->params.sec.pid;
for (i=0; i<dmxdev->filternum; i++) for (i = 0; i < dmxdev->filternum; i++)
if (dmxdev->filter[i].state>=DMXDEV_STATE_GO && if (dmxdev->filter[i].state >= DMXDEV_STATE_GO &&
dmxdev->filter[i].type==DMXDEV_TYPE_SEC && dmxdev->filter[i].type == DMXDEV_TYPE_SEC &&
dmxdev->filter[i].params.sec.pid==pid) { dmxdev->filter[i].params.sec.pid == pid) {
dvb_dmxdev_feed_start(&dmxdev->filter[i]); dvb_dmxdev_feed_start(&dmxdev->filter[i]);
return 0; return 0;
} }
filter->dev->demux->release_section_feed(dmxdev->demux, filter->feed.sec); filter->dev->demux->release_section_feed(dmxdev->demux,
filter->feed.sec);
return 0; return 0;
} }
static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter) static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter)
{ {
if (dmxdevfilter->state<DMXDEV_STATE_GO) if (dmxdevfilter->state < DMXDEV_STATE_GO)
return 0; return 0;
switch (dmxdevfilter->type) { switch (dmxdevfilter->type) {
...@@ -479,7 +478,7 @@ static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter) ...@@ -479,7 +478,7 @@ static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter)
release_filter(dmxdevfilter->feed.sec, release_filter(dmxdevfilter->feed.sec,
dmxdevfilter->filter.sec); dmxdevfilter->filter.sec);
dvb_dmxdev_feed_restart(dmxdevfilter); dvb_dmxdev_feed_restart(dmxdevfilter);
dmxdevfilter->feed.sec=NULL; dmxdevfilter->feed.sec = NULL;
break; break;
case DMXDEV_TYPE_PES: case DMXDEV_TYPE_PES:
if (!dmxdevfilter->feed.ts) if (!dmxdevfilter->feed.ts)
...@@ -488,23 +487,23 @@ static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter) ...@@ -488,23 +487,23 @@ static int dvb_dmxdev_filter_stop(struct dmxdev_filter *dmxdevfilter)
dmxdevfilter->dev->demux-> dmxdevfilter->dev->demux->
release_ts_feed(dmxdevfilter->dev->demux, release_ts_feed(dmxdevfilter->dev->demux,
dmxdevfilter->feed.ts); dmxdevfilter->feed.ts);
dmxdevfilter->feed.ts=NULL; dmxdevfilter->feed.ts = NULL;
break; break;
default: default:
if (dmxdevfilter->state==DMXDEV_STATE_ALLOCATED) if (dmxdevfilter->state == DMXDEV_STATE_ALLOCATED)
return 0; return 0;
return -EINVAL; return -EINVAL;
} }
dmxdevfilter->buffer.pwrite=dmxdevfilter->buffer.pread=0; dmxdevfilter->buffer.pwrite = dmxdevfilter->buffer.pread = 0;
return 0; return 0;
} }
static inline int dvb_dmxdev_filter_reset(struct dmxdev_filter *dmxdevfilter) static inline int dvb_dmxdev_filter_reset(struct dmxdev_filter *dmxdevfilter)
{ {
if (dmxdevfilter->state<DMXDEV_STATE_SET) if (dmxdevfilter->state < DMXDEV_STATE_SET)
return 0; return 0;
dmxdevfilter->type=DMXDEV_TYPE_NONE; dmxdevfilter->type = DMXDEV_TYPE_NONE;
dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED); dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED);
return 0; return 0;
} }
...@@ -524,7 +523,7 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter) ...@@ -524,7 +523,7 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
if (!(mem = filter->buffer.data)) { if (!(mem = filter->buffer.data)) {
mem = vmalloc(filter->buffer.size); mem = vmalloc(filter->buffer.size);
spin_lock_irq(&filter->dev->lock); spin_lock_irq(&filter->dev->lock);
filter->buffer.data=mem; filter->buffer.data = mem;
spin_unlock_irq(&filter->dev->lock); spin_unlock_irq(&filter->dev->lock);
if (!filter->buffer.data) if (!filter->buffer.data)
return -ENOMEM; return -ENOMEM;
...@@ -535,15 +534,16 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter) ...@@ -535,15 +534,16 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
switch (filter->type) { switch (filter->type) {
case DMXDEV_TYPE_SEC: case DMXDEV_TYPE_SEC:
{ {
struct dmx_sct_filter_params *para=&filter->params.sec; struct dmx_sct_filter_params *para = &filter->params.sec;
struct dmx_section_filter **secfilter=&filter->filter.sec; struct dmx_section_filter **secfilter = &filter->filter.sec;
struct dmx_section_feed **secfeed=&filter->feed.sec; struct dmx_section_feed **secfeed = &filter->feed.sec;
*secfilter = NULL;
*secfeed = NULL;
*secfilter=NULL;
*secfeed=NULL;
/* find active filter/feed with same PID */ /* find active filter/feed with same PID */
for (i=0; i<dmxdev->filternum; i++) { for (i = 0; i < dmxdev->filternum; i++) {
if (dmxdev->filter[i].state >= DMXDEV_STATE_GO && if (dmxdev->filter[i].state >= DMXDEV_STATE_GO &&
dmxdev->filter[i].type == DMXDEV_TYPE_SEC && dmxdev->filter[i].type == DMXDEV_TYPE_SEC &&
dmxdev->filter[i].params.sec.pid == para->pid) { dmxdev->filter[i].params.sec.pid == para->pid) {
...@@ -554,20 +554,19 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter) ...@@ -554,20 +554,19 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
/* if no feed found, try to allocate new one */ /* if no feed found, try to allocate new one */
if (!*secfeed) { if (!*secfeed) {
ret=dmxdev->demux->allocate_section_feed(dmxdev->demux, ret = dmxdev->demux->allocate_section_feed(dmxdev->demux,
secfeed, secfeed,
dvb_dmxdev_section_callback); dvb_dmxdev_section_callback);
if (ret<0) { if (ret < 0) {
printk ("DVB (%s): could not alloc feed\n", printk("DVB (%s): could not alloc feed\n",
__FUNCTION__); __FUNCTION__);
return ret; return ret;
} }
ret=(*secfeed)->set(*secfeed, para->pid, 32768, ret = (*secfeed)->set(*secfeed, para->pid, 32768,
(para->flags & DMX_CHECK_CRC) ? 1 : 0); (para->flags & DMX_CHECK_CRC) ? 1 : 0);
if (ret < 0) {
if (ret<0) { printk("DVB (%s): could not set feed\n",
printk ("DVB (%s): could not set feed\n",
__FUNCTION__); __FUNCTION__);
dvb_dmxdev_feed_restart(filter); dvb_dmxdev_feed_restart(filter);
return ret; return ret;
...@@ -576,41 +575,38 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter) ...@@ -576,41 +575,38 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
dvb_dmxdev_feed_stop(filter); dvb_dmxdev_feed_stop(filter);
} }
ret=(*secfeed)->allocate_filter(*secfeed, secfilter); ret = (*secfeed)->allocate_filter(*secfeed, secfilter);
if (ret < 0) { if (ret < 0) {
dvb_dmxdev_feed_restart(filter); dvb_dmxdev_feed_restart(filter);
filter->feed.sec->start_filtering(*secfeed); filter->feed.sec->start_filtering(*secfeed);
dprintk ("could not get filter\n"); dprintk("could not get filter\n");
return ret; return ret;
} }
(*secfilter)->priv = filter; (*secfilter)->priv = filter;
memcpy(&((*secfilter)->filter_value[3]), memcpy(&((*secfilter)->filter_value[3]),
&(para->filter.filter[1]), DMX_FILTER_SIZE-1); &(para->filter.filter[1]), DMX_FILTER_SIZE - 1);
memcpy(&(*secfilter)->filter_mask[3], memcpy(&(*secfilter)->filter_mask[3],
&para->filter.mask[1], DMX_FILTER_SIZE-1); &para->filter.mask[1], DMX_FILTER_SIZE - 1);
memcpy(&(*secfilter)->filter_mode[3], memcpy(&(*secfilter)->filter_mode[3],
&para->filter.mode[1], DMX_FILTER_SIZE-1); &para->filter.mode[1], DMX_FILTER_SIZE - 1);
(*secfilter)->filter_value[0]=para->filter.filter[0]; (*secfilter)->filter_value[0] = para->filter.filter[0];
(*secfilter)->filter_mask[0]=para->filter.mask[0]; (*secfilter)->filter_mask[0] = para->filter.mask[0];
(*secfilter)->filter_mode[0]=para->filter.mode[0]; (*secfilter)->filter_mode[0] = para->filter.mode[0];
(*secfilter)->filter_mask[1]=0; (*secfilter)->filter_mask[1] = 0;
(*secfilter)->filter_mask[2]=0; (*secfilter)->filter_mask[2] = 0;
filter->todo = 0; filter->todo = 0;
ret = filter->feed.sec->start_filtering (filter->feed.sec); ret = filter->feed.sec->start_filtering(filter->feed.sec);
if (ret < 0) if (ret < 0)
return ret; return ret;
dvb_dmxdev_filter_timer(filter); dvb_dmxdev_filter_timer(filter);
break; break;
} }
case DMXDEV_TYPE_PES: case DMXDEV_TYPE_PES:
{ {
struct timespec timeout = { 0 }; struct timespec timeout = { 0 };
...@@ -622,41 +618,41 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter) ...@@ -622,41 +618,41 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
struct dmx_ts_feed **tsfeed = &filter->feed.ts; struct dmx_ts_feed **tsfeed = &filter->feed.ts;
filter->feed.ts = NULL; filter->feed.ts = NULL;
otype=para->output; otype = para->output;
ts_pes=(enum dmx_ts_pes) para->pes_type; ts_pes = (enum dmx_ts_pes)para->pes_type;
if (ts_pes<DMX_PES_OTHER) if (ts_pes < DMX_PES_OTHER)
ts_type=TS_DECODER; ts_type = TS_DECODER;
else else
ts_type=0; ts_type = 0;
if (otype == DMX_OUT_TS_TAP) if (otype == DMX_OUT_TS_TAP)
ts_type |= TS_PACKET; ts_type |= TS_PACKET;
if (otype == DMX_OUT_TAP) if (otype == DMX_OUT_TAP)
ts_type |= TS_PAYLOAD_ONLY|TS_PACKET; ts_type |= TS_PAYLOAD_ONLY | TS_PACKET;
ret=dmxdev->demux->allocate_ts_feed(dmxdev->demux, ret = dmxdev->demux->allocate_ts_feed(dmxdev->demux,
tsfeed, tsfeed,
dvb_dmxdev_ts_callback); dvb_dmxdev_ts_callback);
if (ret<0) if (ret < 0)
return ret; return ret;
(*tsfeed)->priv = (void *) filter; (*tsfeed)->priv = filter;
ret = (*tsfeed)->set(*tsfeed, para->pid, ts_type, ts_pes, ret = (*tsfeed)->set(*tsfeed, para->pid, ts_type, ts_pes,
32768, timeout); 32768, timeout);
if (ret < 0) { if (ret < 0) {
dmxdev->demux->release_ts_feed(dmxdev->demux, *tsfeed); dmxdev->demux->release_ts_feed(dmxdev->demux,
*tsfeed);
return ret; return ret;
} }
ret = filter->feed.ts->start_filtering(filter->feed.ts); ret = filter->feed.ts->start_filtering(filter->feed.ts);
if (ret < 0) { if (ret < 0) {
dmxdev->demux->release_ts_feed(dmxdev->demux, *tsfeed); dmxdev->demux->release_ts_feed(dmxdev->demux,
*tsfeed);
return ret; return ret;
} }
...@@ -683,31 +679,31 @@ static int dvb_demux_open(struct inode *inode, struct file *file) ...@@ -683,31 +679,31 @@ static int dvb_demux_open(struct inode *inode, struct file *file)
if (mutex_lock_interruptible(&dmxdev->mutex)) if (mutex_lock_interruptible(&dmxdev->mutex))
return -ERESTARTSYS; return -ERESTARTSYS;
for (i=0; i<dmxdev->filternum; i++) for (i = 0; i < dmxdev->filternum; i++)
if (dmxdev->filter[i].state==DMXDEV_STATE_FREE) if (dmxdev->filter[i].state == DMXDEV_STATE_FREE)
break; break;
if (i==dmxdev->filternum) { if (i == dmxdev->filternum) {
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return -EMFILE; return -EMFILE;
} }
dmxdevfilter=&dmxdev->filter[i]; dmxdevfilter = &dmxdev->filter[i];
mutex_init(&dmxdevfilter->mutex); mutex_init(&dmxdevfilter->mutex);
file->private_data=dmxdevfilter; file->private_data = dmxdevfilter;
dvb_dmxdev_buffer_init(&dmxdevfilter->buffer); dvb_dmxdev_buffer_init(&dmxdevfilter->buffer);
dmxdevfilter->type=DMXDEV_TYPE_NONE; dmxdevfilter->type = DMXDEV_TYPE_NONE;
dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED); dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_ALLOCATED);
dmxdevfilter->feed.ts=NULL; dmxdevfilter->feed.ts = NULL;
init_timer(&dmxdevfilter->timer); init_timer(&dmxdevfilter->timer);
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return 0; return 0;
} }
static int dvb_dmxdev_filter_free(struct dmxdev *dmxdev,
static int dvb_dmxdev_filter_free(struct dmxdev *dmxdev, struct dmxdev_filter *dmxdevfilter) struct dmxdev_filter *dmxdevfilter)
{ {
if (mutex_lock_interruptible(&dmxdev->mutex)) if (mutex_lock_interruptible(&dmxdev->mutex))
return -ERESTARTSYS; return -ERESTARTSYS;
...@@ -721,10 +717,10 @@ static int dvb_dmxdev_filter_free(struct dmxdev *dmxdev, struct dmxdev_filter *d ...@@ -721,10 +717,10 @@ static int dvb_dmxdev_filter_free(struct dmxdev *dmxdev, struct dmxdev_filter *d
dvb_dmxdev_filter_reset(dmxdevfilter); dvb_dmxdev_filter_reset(dmxdevfilter);
if (dmxdevfilter->buffer.data) { if (dmxdevfilter->buffer.data) {
void *mem=dmxdevfilter->buffer.data; void *mem = dmxdevfilter->buffer.data;
spin_lock_irq(&dmxdev->lock); spin_lock_irq(&dmxdev->lock);
dmxdevfilter->buffer.data=NULL; dmxdevfilter->buffer.data = NULL;
spin_unlock_irq(&dmxdev->lock); spin_unlock_irq(&dmxdev->lock);
vfree(mem); vfree(mem);
} }
...@@ -740,26 +736,25 @@ static inline void invert_mode(dmx_filter_t *filter) ...@@ -740,26 +736,25 @@ static inline void invert_mode(dmx_filter_t *filter)
{ {
int i; int i;
for (i=0; i<DMX_FILTER_SIZE; i++) for (i = 0; i < DMX_FILTER_SIZE; i++)
filter->mode[i]^=0xff; filter->mode[i] ^= 0xff;
} }
static int dvb_dmxdev_filter_set(struct dmxdev *dmxdev, static int dvb_dmxdev_filter_set(struct dmxdev *dmxdev,
struct dmxdev_filter *dmxdevfilter, struct dmxdev_filter *dmxdevfilter,
struct dmx_sct_filter_params *params) struct dmx_sct_filter_params *params)
{ {
dprintk ("function : %s\n", __FUNCTION__); dprintk("function : %s\n", __FUNCTION__);
dvb_dmxdev_filter_stop(dmxdevfilter); dvb_dmxdev_filter_stop(dmxdevfilter);
dmxdevfilter->type=DMXDEV_TYPE_SEC; dmxdevfilter->type = DMXDEV_TYPE_SEC;
memcpy(&dmxdevfilter->params.sec, memcpy(&dmxdevfilter->params.sec,
params, sizeof(struct dmx_sct_filter_params)); params, sizeof(struct dmx_sct_filter_params));
invert_mode(&dmxdevfilter->params.sec.filter); invert_mode(&dmxdevfilter->params.sec.filter);
dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET); dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET);
if (params->flags&DMX_IMMEDIATE_START) if (params->flags & DMX_IMMEDIATE_START)
return dvb_dmxdev_filter_start(dmxdevfilter); return dvb_dmxdev_filter_start(dmxdevfilter);
return 0; return 0;
...@@ -771,87 +766,90 @@ static int dvb_dmxdev_pes_filter_set(struct dmxdev *dmxdev, ...@@ -771,87 +766,90 @@ static int dvb_dmxdev_pes_filter_set(struct dmxdev *dmxdev,
{ {
dvb_dmxdev_filter_stop(dmxdevfilter); dvb_dmxdev_filter_stop(dmxdevfilter);
if (params->pes_type>DMX_PES_OTHER || params->pes_type<0) if (params->pes_type > DMX_PES_OTHER || params->pes_type < 0)
return -EINVAL; return -EINVAL;
dmxdevfilter->type=DMXDEV_TYPE_PES; dmxdevfilter->type = DMXDEV_TYPE_PES;
memcpy(&dmxdevfilter->params, params, sizeof(struct dmx_pes_filter_params)); memcpy(&dmxdevfilter->params, params,
sizeof(struct dmx_pes_filter_params));
dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET); dvb_dmxdev_filter_state_set(dmxdevfilter, DMXDEV_STATE_SET);
if (params->flags&DMX_IMMEDIATE_START) if (params->flags & DMX_IMMEDIATE_START)
return dvb_dmxdev_filter_start(dmxdevfilter); return dvb_dmxdev_filter_start(dmxdevfilter);
return 0; return 0;
} }
static ssize_t dvb_dmxdev_read_sec(struct dmxdev_filter *dfil, static ssize_t dvb_dmxdev_read_sec(struct dmxdev_filter *dfil,
struct file *file, char __user *buf, size_t count, loff_t *ppos) struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{ {
int result, hcount; int result, hcount;
int done=0; int done = 0;
if (dfil->todo<=0) { if (dfil->todo <= 0) {
hcount=3+dfil->todo; hcount = 3 + dfil->todo;
if (hcount>count) if (hcount > count)
hcount=count; hcount = count;
result=dvb_dmxdev_buffer_read(&dfil->buffer, file->f_flags&O_NONBLOCK, result = dvb_dmxdev_buffer_read(&dfil->buffer,
file->f_flags & O_NONBLOCK,
buf, hcount, ppos); buf, hcount, ppos);
if (result<0) { if (result < 0) {
dfil->todo=0; dfil->todo = 0;
return result; return result;
} }
if (copy_from_user(dfil->secheader-dfil->todo, buf, result)) if (copy_from_user(dfil->secheader - dfil->todo, buf, result))
return -EFAULT; return -EFAULT;
buf+=result; buf += result;
done=result; done = result;
count-=result; count -= result;
dfil->todo-=result; dfil->todo -= result;
if (dfil->todo>-3) if (dfil->todo > -3)
return done; return done;
dfil->todo=((dfil->secheader[1]<<8)|dfil->secheader[2])&0xfff; dfil->todo = ((dfil->secheader[1] << 8) | dfil->secheader[2]) & 0xfff;
if (!count) if (!count)
return done; return done;
} }
if (count>dfil->todo) if (count > dfil->todo)
count=dfil->todo; count = dfil->todo;
result=dvb_dmxdev_buffer_read(&dfil->buffer, file->f_flags&O_NONBLOCK, result = dvb_dmxdev_buffer_read(&dfil->buffer,
file->f_flags & O_NONBLOCK,
buf, count, ppos); buf, count, ppos);
if (result<0) if (result < 0)
return result; return result;
dfil->todo-=result; dfil->todo -= result;
return (result+done); return (result + done);
} }
static ssize_t static ssize_t
dvb_demux_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) dvb_demux_read(struct file *file, char __user *buf, size_t count,
loff_t *ppos)
{ {
struct dmxdev_filter *dmxdevfilter= file->private_data; struct dmxdev_filter *dmxdevfilter = file->private_data;
int ret=0; int ret;
if (mutex_lock_interruptible(&dmxdevfilter->mutex)) if (mutex_lock_interruptible(&dmxdevfilter->mutex))
return -ERESTARTSYS; return -ERESTARTSYS;
if (dmxdevfilter->type==DMXDEV_TYPE_SEC) if (dmxdevfilter->type == DMXDEV_TYPE_SEC)
ret=dvb_dmxdev_read_sec(dmxdevfilter, file, buf, count, ppos); ret = dvb_dmxdev_read_sec(dmxdevfilter, file, buf, count, ppos);
else else
ret=dvb_dmxdev_buffer_read(&dmxdevfilter->buffer, ret = dvb_dmxdev_buffer_read(&dmxdevfilter->buffer,
file->f_flags&O_NONBLOCK, file->f_flags & O_NONBLOCK,
buf, count, ppos); buf, count, ppos);
mutex_unlock(&dmxdevfilter->mutex); mutex_unlock(&dmxdevfilter->mutex);
return ret; return ret;
} }
static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, void *parg) unsigned int cmd, void *parg)
{ {
struct dmxdev_filter *dmxdevfilter = file->private_data; struct dmxdev_filter *dmxdevfilter = file->private_data;
struct dmxdev *dmxdev=dmxdevfilter->dev; struct dmxdev *dmxdev = dmxdevfilter->dev;
unsigned long arg=(unsigned long) parg; unsigned long arg = (unsigned long)parg;
int ret=0; int ret = 0;
if (mutex_lock_interruptible(&dmxdev->mutex)) if (mutex_lock_interruptible(&dmxdev->mutex))
return -ERESTARTSYS; return -ERESTARTSYS;
...@@ -862,7 +860,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, ...@@ -862,7 +860,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return -ERESTARTSYS; return -ERESTARTSYS;
} }
if (dmxdevfilter->state<DMXDEV_STATE_SET) if (dmxdevfilter->state < DMXDEV_STATE_SET)
ret = -EINVAL; ret = -EINVAL;
else else
ret = dvb_dmxdev_filter_start(dmxdevfilter); ret = dvb_dmxdev_filter_start(dmxdevfilter);
...@@ -874,7 +872,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, ...@@ -874,7 +872,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return -ERESTARTSYS; return -ERESTARTSYS;
} }
ret=dvb_dmxdev_filter_stop(dmxdevfilter); ret = dvb_dmxdev_filter_stop(dmxdevfilter);
mutex_unlock(&dmxdevfilter->mutex); mutex_unlock(&dmxdevfilter->mutex);
break; break;
...@@ -883,8 +881,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, ...@@ -883,8 +881,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return -ERESTARTSYS; return -ERESTARTSYS;
} }
ret = dvb_dmxdev_filter_set(dmxdev, dmxdevfilter, ret = dvb_dmxdev_filter_set(dmxdev, dmxdevfilter, parg);
(struct dmx_sct_filter_params *)parg);
mutex_unlock(&dmxdevfilter->mutex); mutex_unlock(&dmxdevfilter->mutex);
break; break;
...@@ -893,8 +890,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, ...@@ -893,8 +890,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return -ERESTARTSYS; return -ERESTARTSYS;
} }
ret=dvb_dmxdev_pes_filter_set(dmxdev, dmxdevfilter, ret = dvb_dmxdev_pes_filter_set(dmxdev, dmxdevfilter, parg);
(struct dmx_pes_filter_params *)parg);
mutex_unlock(&dmxdevfilter->mutex); mutex_unlock(&dmxdevfilter->mutex);
break; break;
...@@ -903,7 +899,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, ...@@ -903,7 +899,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return -ERESTARTSYS; return -ERESTARTSYS;
} }
ret=dvb_dmxdev_set_buffer_size(dmxdevfilter, arg); ret = dvb_dmxdev_set_buffer_size(dmxdevfilter, arg);
mutex_unlock(&dmxdevfilter->mutex); mutex_unlock(&dmxdevfilter->mutex);
break; break;
...@@ -912,10 +908,10 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, ...@@ -912,10 +908,10 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
case DMX_GET_PES_PIDS: case DMX_GET_PES_PIDS:
if (!dmxdev->demux->get_pes_pids) { if (!dmxdev->demux->get_pes_pids) {
ret=-EINVAL; ret = -EINVAL;
break; break;
} }
dmxdev->demux->get_pes_pids(dmxdev->demux, (u16 *)parg); dmxdev->demux->get_pes_pids(dmxdev->demux, parg);
break; break;
case DMX_GET_CAPS: case DMX_GET_CAPS:
...@@ -936,7 +932,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, ...@@ -936,7 +932,7 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
case DMX_GET_STC: case DMX_GET_STC:
if (!dmxdev->demux->get_stc) { if (!dmxdev->demux->get_stc) {
ret=-EINVAL; ret = -EINVAL;
break; break;
} }
ret = dmxdev->demux->get_stc(dmxdev->demux, ret = dmxdev->demux->get_stc(dmxdev->demux,
...@@ -946,7 +942,8 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file, ...@@ -946,7 +942,8 @@ static int dvb_demux_do_ioctl(struct inode *inode, struct file *file,
break; break;
default: default:
ret=-EINVAL; ret = -EINVAL;
break;
} }
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return ret; return ret;
...@@ -958,8 +955,7 @@ static int dvb_demux_ioctl(struct inode *inode, struct file *file, ...@@ -958,8 +955,7 @@ static int dvb_demux_ioctl(struct inode *inode, struct file *file,
return dvb_usercopy(inode, file, cmd, arg, dvb_demux_do_ioctl); return dvb_usercopy(inode, file, cmd, arg, dvb_demux_do_ioctl);
} }
static unsigned int dvb_demux_poll(struct file *file, poll_table *wait)
static unsigned int dvb_demux_poll (struct file *file, poll_table *wait)
{ {
struct dmxdev_filter *dmxdevfilter = file->private_data; struct dmxdev_filter *dmxdevfilter = file->private_data;
unsigned int mask = 0; unsigned int mask = 0;
...@@ -983,7 +979,6 @@ static unsigned int dvb_demux_poll (struct file *file, poll_table *wait) ...@@ -983,7 +979,6 @@ static unsigned int dvb_demux_poll (struct file *file, poll_table *wait)
return mask; return mask;
} }
static int dvb_demux_release(struct inode *inode, struct file *file) static int dvb_demux_release(struct inode *inode, struct file *file)
{ {
struct dmxdev_filter *dmxdevfilter = file->private_data; struct dmxdev_filter *dmxdevfilter = file->private_data;
...@@ -992,7 +987,6 @@ static int dvb_demux_release(struct inode *inode, struct file *file) ...@@ -992,7 +987,6 @@ static int dvb_demux_release(struct inode *inode, struct file *file)
return dvb_dmxdev_filter_free(dmxdev, dmxdevfilter); return dvb_dmxdev_filter_free(dmxdev, dmxdevfilter);
} }
static struct file_operations dvb_demux_fops = { static struct file_operations dvb_demux_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.read = dvb_demux_read, .read = dvb_demux_read,
...@@ -1002,7 +996,6 @@ static struct file_operations dvb_demux_fops = { ...@@ -1002,7 +996,6 @@ static struct file_operations dvb_demux_fops = {
.poll = dvb_demux_poll, .poll = dvb_demux_poll,
}; };
static struct dvb_device dvbdev_demux = { static struct dvb_device dvbdev_demux = {
.priv = NULL, .priv = NULL,
.users = 1, .users = 1,
...@@ -1010,14 +1003,12 @@ static struct dvb_device dvbdev_demux = { ...@@ -1010,14 +1003,12 @@ static struct dvb_device dvbdev_demux = {
.fops = &dvb_demux_fops .fops = &dvb_demux_fops
}; };
static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file, static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, void *parg) unsigned int cmd, void *parg)
{ {
struct dvb_device *dvbdev = file->private_data; struct dvb_device *dvbdev = file->private_data;
struct dmxdev *dmxdev = dvbdev->priv; struct dmxdev *dmxdev = dvbdev->priv;
int ret;
int ret=0;
if (mutex_lock_interruptible(&dmxdev->mutex)) if (mutex_lock_interruptible(&dmxdev->mutex))
return -ERESTARTSYS; return -ERESTARTSYS;
...@@ -1025,39 +1016,38 @@ static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file, ...@@ -1025,39 +1016,38 @@ static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file,
switch (cmd) { switch (cmd) {
case DMX_SET_BUFFER_SIZE: case DMX_SET_BUFFER_SIZE:
// FIXME: implement // FIXME: implement
ret=0; ret = 0;
break; break;
default: default:
ret=-EINVAL; ret = -EINVAL;
break;
} }
mutex_unlock(&dmxdev->mutex); mutex_unlock(&dmxdev->mutex);
return ret; return ret;
} }
static int dvb_dvr_ioctl(struct inode *inode, struct file *file, static int dvb_dvr_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
return dvb_usercopy(inode, file, cmd, arg, dvb_dvr_do_ioctl); return dvb_usercopy(inode, file, cmd, arg, dvb_dvr_do_ioctl);
} }
static unsigned int dvb_dvr_poll(struct file *file, poll_table *wait)
static unsigned int dvb_dvr_poll (struct file *file, poll_table *wait)
{ {
struct dvb_device *dvbdev = file->private_data; struct dvb_device *dvbdev = file->private_data;
struct dmxdev *dmxdev = dvbdev->priv; struct dmxdev *dmxdev = dvbdev->priv;
unsigned int mask = 0; unsigned int mask = 0;
dprintk ("function : %s\n", __FUNCTION__); dprintk("function : %s\n", __FUNCTION__);
poll_wait(file, &dmxdev->dvr_buffer.queue, wait); poll_wait(file, &dmxdev->dvr_buffer.queue, wait);
if ((file->f_flags&O_ACCMODE) == O_RDONLY) { if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
if (dmxdev->dvr_buffer.error) if (dmxdev->dvr_buffer.error)
mask |= (POLLIN | POLLRDNORM | POLLPRI | POLLERR); mask |= (POLLIN | POLLRDNORM | POLLPRI | POLLERR);
if (dmxdev->dvr_buffer.pread!=dmxdev->dvr_buffer.pwrite) if (dmxdev->dvr_buffer.pread != dmxdev->dvr_buffer.pwrite)
mask |= (POLLIN | POLLRDNORM | POLLPRI); mask |= (POLLIN | POLLRDNORM | POLLPRI);
} else } else
mask |= (POLLOUT | POLLWRNORM | POLLPRI); mask |= (POLLOUT | POLLWRNORM | POLLPRI);
...@@ -1065,7 +1055,6 @@ static unsigned int dvb_dvr_poll (struct file *file, poll_table *wait) ...@@ -1065,7 +1055,6 @@ static unsigned int dvb_dvr_poll (struct file *file, poll_table *wait)
return mask; return mask;
} }
static struct file_operations dvb_dvr_fops = { static struct file_operations dvb_dvr_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.read = dvb_dvr_read, .read = dvb_dvr_read,
...@@ -1083,43 +1072,46 @@ static struct dvb_device dvbdev_dvr = { ...@@ -1083,43 +1072,46 @@ static struct dvb_device dvbdev_dvr = {
.fops = &dvb_dvr_fops .fops = &dvb_dvr_fops
}; };
int int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
{ {
int i; int i;
if (dmxdev->demux->open(dmxdev->demux) < 0) if (dmxdev->demux->open(dmxdev->demux) < 0)
return -EUSERS; return -EUSERS;
dmxdev->filter = vmalloc(dmxdev->filternum*sizeof(struct dmxdev_filter)); dmxdev->filter = vmalloc(dmxdev->filternum * sizeof(struct dmxdev_filter));
if (!dmxdev->filter) if (!dmxdev->filter)
return -ENOMEM; return -ENOMEM;
mutex_init(&dmxdev->mutex); mutex_init(&dmxdev->mutex);
spin_lock_init(&dmxdev->lock); spin_lock_init(&dmxdev->lock);
for (i=0; i<dmxdev->filternum; i++) { for (i = 0; i < dmxdev->filternum; i++) {
dmxdev->filter[i].dev=dmxdev; dmxdev->filter[i].dev = dmxdev;
dmxdev->filter[i].buffer.data=NULL; dmxdev->filter[i].buffer.data = NULL;
dvb_dmxdev_filter_state_set(&dmxdev->filter[i], DMXDEV_STATE_FREE); dvb_dmxdev_filter_state_set(&dmxdev->filter[i],
DMXDEV_STATE_FREE);
} }
dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev, DVB_DEVICE_DEMUX); dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev,
dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr, dmxdev, DVB_DEVICE_DVR); DVB_DEVICE_DEMUX);
dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr,
dmxdev, DVB_DEVICE_DVR);
dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer); dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer);
return 0; return 0;
} }
EXPORT_SYMBOL(dvb_dmxdev_init); EXPORT_SYMBOL(dvb_dmxdev_init);
void void dvb_dmxdev_release(struct dmxdev *dmxdev)
dvb_dmxdev_release(struct dmxdev *dmxdev)
{ {
dvb_unregister_device(dmxdev->dvbdev); dvb_unregister_device(dmxdev->dvbdev);
dvb_unregister_device(dmxdev->dvr_dvbdev); dvb_unregister_device(dmxdev->dvr_dvbdev);
vfree(dmxdev->filter); vfree(dmxdev->filter);
dmxdev->filter=NULL; dmxdev->filter = NULL;
dmxdev->demux->close(dmxdev->demux); dmxdev->demux->close(dmxdev->demux);
} }
EXPORT_SYMBOL(dvb_dmxdev_release); EXPORT_SYMBOL(dvb_dmxdev_release);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment