diff options
Diffstat (limited to 'linux')
-rw-r--r-- | linux/drivers/media/dvb/dvb-core/dmxdev.c | 57 | ||||
-rw-r--r-- | linux/drivers/media/dvb/dvb-core/dvb_demux.c | 416 |
2 files changed, 269 insertions, 204 deletions
diff --git a/linux/drivers/media/dvb/dvb-core/dmxdev.c b/linux/drivers/media/dvb/dvb-core/dmxdev.c index 770b7ce61..73e357d05 100644 --- a/linux/drivers/media/dvb/dvb-core/dmxdev.c +++ b/linux/drivers/media/dvb/dvb-core/dmxdev.c @@ -1025,7 +1025,9 @@ int dvb_demux_release(struct inode *inode, struct file *file) return dvb_dmxdev_filter_free(dmxdev, dmxdevfilter); } -static struct file_operations dvb_demux_fops = { + +static +struct file_operations dvb_demux_fops = { .owner = THIS_MODULE, .read = dvb_demux_read, .ioctl = dvb_demux_ioctl, @@ -1034,15 +1036,19 @@ static struct file_operations dvb_demux_fops = { .poll = dvb_demux_poll, }; -static struct dvb_device dvbdev_demux = { + +static +struct dvb_device dvbdev_demux = { .priv = 0, .users = 1, .writers = 1, .fops = &dvb_demux_fops }; -static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file, - unsigned int cmd, void *parg) + +static +int dvb_dvr_do_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, void *parg) { struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; dmxdev_t *dmxdev=(dmxdev_t *) dvbdev->priv; @@ -1065,8 +1071,10 @@ static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file, return ret; } -static int dvb_dvr_ioctl(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg) + +static +int dvb_dvr_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) { return dvb_usercopy(inode, file, cmd, arg, dvb_dvr_do_ioctl); } @@ -1117,39 +1125,47 @@ static struct dvb_device dvbdev_dvr = { int dvb_dmxdev_init(dmxdev_t *dmxdev, struct dvb_adapter *dvb_adapter) { - int i; + int i, err; - if (dmxdev->demux->open(dmxdev->demux)<0) - return -EUSERS; + if ((err = dmxdev->demux->open(dmxdev->demux)) < 0) + return err; - dmxdev->filter=vmalloc(dmxdev->filternum*sizeof(dmxdev_filter_t)); + dmxdev->filter = vmalloc(dmxdev->filternum*sizeof(dmxdev_filter_t)); if (!dmxdev->filter) return -ENOMEM; - dmxdev->dvr=vmalloc(dmxdev->filternum*sizeof(dmxdev_dvr_t)); + dmxdev->dvr = vmalloc(dmxdev->filternum*sizeof(dmxdev_dvr_t)); + if (!dmxdev->dvr) { vfree(dmxdev->filter); - dmxdev->filter=0; + dmxdev->filter = NULL; return -ENOMEM; } + sema_init(&dmxdev->mutex, 1); spin_lock_init(&dmxdev->lock); + for (i=0; i<dmxdev->filternum; i++) { dmxdev->filter[i].dev=dmxdev; dmxdev->filter[i].buffer.data=0; - dvb_dmxdev_filter_state_set(&dmxdev->filter[i], DMXDEV_STATE_FREE); + dvb_dmxdev_filter_state_set(&dmxdev->filter[i], + DMXDEV_STATE_FREE); dmxdev->dvr[i].dev=dmxdev; dmxdev->dvr[i].buffer.data=0; - dvb_dmxdev_filter_state_set(&dmxdev->filter[i], DMXDEV_STATE_FREE); + dvb_dmxdev_filter_state_set(&dmxdev->filter[i], + DMXDEV_STATE_FREE); dvb_dmxdev_dvr_state_set(&dmxdev->dvr[i], DMXDEV_STATE_FREE); } - dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev, DVB_DEVICE_DEMUX); - dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr, dmxdev, DVB_DEVICE_DVR); + + dvb_register_device(dvb_adapter, &dmxdev->dvbdev, + &dvbdev_demux, dmxdev, DVB_DEVICE_DEMUX); + + dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, + &dvbdev_dvr, dmxdev, DVB_DEVICE_DVR); dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer); - /* fixme: is this correct? */ - try_module_get(THIS_MODULE); + return 0; } @@ -1158,17 +1174,18 @@ dvb_dmxdev_release(dmxdev_t *dmxdev) { dvb_unregister_device(dmxdev->dvbdev); dvb_unregister_device(dmxdev->dvr_dvbdev); + if (dmxdev->filter) { vfree(dmxdev->filter); dmxdev->filter=0; } + if (dmxdev->dvr) { vfree(dmxdev->dvr); dmxdev->dvr=0; } + dmxdev->demux->close(dmxdev->demux); - /* fixme: is this correct? */ - module_put(THIS_MODULE); } diff --git a/linux/drivers/media/dvb/dvb-core/dvb_demux.c b/linux/drivers/media/dvb/dvb-core/dvb_demux.c index 4c4a2dea8..baf292198 100644 --- a/linux/drivers/media/dvb/dvb-core/dvb_demux.c +++ b/linux/drivers/media/dvb/dvb-core/dvb_demux.c @@ -51,23 +51,20 @@ int dmx_register_demux(dmx_demux_t *demux) demux->users = 0; list_add(&demux->reg_list, &dmx_muxs); - /* fixme: is this correct? */ - try_module_get(THIS_MODULE); return 0; } + int dmx_unregister_demux(dmx_demux_t* demux) { - struct list_head *pos, *n, *head=&dmx_muxs; + struct list_head *pos, *n; - list_for_each_safe (pos, n, head) { + list_for_each_safe (pos, n, &dmx_muxs) { if (DMX_DIR_ENTRY(pos) == demux) { if (demux->users>0) return -EINVAL; list_del(pos); - /* fixme: is this correct? */ - module_put(THIS_MODULE); return 0; } } @@ -106,14 +103,16 @@ u16 ts_pid(const u8 *buf) static inline int payload(const u8 *tsp) { - if (!(tsp[3]&0x10)) // no payload? + if (!(tsp[3] & 0x10)) // no payload? return 0; - if (tsp[3]&0x20) { // adaptation field? - if (tsp[4]>183) // corrupted data? + + if (tsp[3] & 0x20) { // adaptation field? + if (tsp[4] > 183) // corrupted data? return 0; else return 184-1-tsp[4]; } + return 184; } @@ -397,10 +396,10 @@ void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, const u8 *buf) void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf) { struct dvb_demux_feed *feed; - struct list_head *pos, *head=&demux->feed_list; + struct list_head *pos; u16 pid = ts_pid(buf); - list_for_each(pos, head) { + list_for_each(pos, &demux->feed_list) { feed = list_entry(pos, struct dvb_demux_feed, list_head); if (feed->pid == pid) dvb_dmx_swfilter_packet_type (feed, buf); @@ -495,7 +494,7 @@ static int dmx_pid_set (u16 pid, struct dvb_demux_feed *feed) { struct dvb_demux *demux = feed->demux; - struct list_head *pos, *n, *head=&demux->feed_list; + struct list_head *pos, *n; if (pid > DMX_MAX_PID) return -EINVAL; @@ -503,14 +502,16 @@ int dmx_pid_set (u16 pid, struct dvb_demux_feed *feed) if (pid == feed->pid) return 0; - if (feed->pid <= DMX_MAX_PID) - list_for_each_safe(pos, n, head) + if (feed->pid <= DMX_MAX_PID) { + list_for_each_safe(pos, n, &demux->feed_list) { if (DMX_FEED_ENTRY(pos)->pid == feed->pid) { list_del(pos); break; } + } + } - list_add(&feed->list_head, head); + list_add(&feed->list_head, &demux->feed_list); feed->pid = pid; return 0; @@ -637,7 +638,7 @@ int dmx_ts_feed_stop_filtering(struct dmx_ts_feed_s* ts_feed) if (down_interruptible (&demux->mutex)) return -ERESTARTSYS; - if (feed->state<DMX_STATE_GO) { + if (feed->state < DMX_STATE_GO) { up(&demux->mutex); return -EINVAL; } @@ -681,12 +682,12 @@ int dvbdmx_allocate_ts_feed (dmx_demux_t *dmx, dmx_ts_feed_t **ts_feed, feed->buffer = 0; (*ts_feed) = &feed->feed.ts; - (*ts_feed)->is_filtering = 0; (*ts_feed)->parent = dmx; (*ts_feed)->priv = 0; - (*ts_feed)->set = dmx_ts_feed_set; + (*ts_feed)->is_filtering = 0; (*ts_feed)->start_filtering = dmx_ts_feed_start_filtering; (*ts_feed)->stop_filtering = dmx_ts_feed_stop_filtering; + (*ts_feed)->set = dmx_ts_feed_set; if (!(feed->filter = dvb_dmx_filter_alloc(demux))) { @@ -750,72 +751,78 @@ int dvbdmx_release_ts_feed(dmx_demux_t *dmx, dmx_ts_feed_t *ts_feed) * dmx_section_feed API calls ******************************************************************************/ -static int -dmx_section_feed_allocate_filter(struct dmx_section_feed_s* feed, - dmx_section_filter_t** filter) +static +int dmx_section_feed_allocate_filter(struct dmx_section_feed_s* feed, + dmx_section_filter_t** filter) { - struct dvb_demux_feed *dvbdmxfeed=(struct dvb_demux_feed *) feed; - struct dvb_demux *dvbdemux=dvbdmxfeed->demux; + struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; + struct dvb_demux *dvbdemux = dvbdmxfeed->demux; struct dvb_demux_filter *dvbdmxfilter; if (down_interruptible (&dvbdemux->mutex)) return -ERESTARTSYS; - dvbdmxfilter=dvb_dmx_filter_alloc(dvbdemux); + dvbdmxfilter = dvb_dmx_filter_alloc(dvbdemux); if (!dvbdmxfilter) { up(&dvbdemux->mutex); - return -ENOSPC; + return -EBUSY; } + spin_lock_irq(&dvbdemux->lock); - *filter=&dvbdmxfilter->filter; - (*filter)->parent=feed; - (*filter)->priv=0; - dvbdmxfilter->feed=dvbdmxfeed; - dvbdmxfilter->type=DMX_TYPE_SEC; - dvbdmxfilter->state=DMX_STATE_READY; - - dvbdmxfilter->next=dvbdmxfeed->filter; - dvbdmxfeed->filter=dvbdmxfilter; + *filter = &dvbdmxfilter->filter; + (*filter)->parent = feed; + (*filter)->priv = 0; + dvbdmxfilter->feed = dvbdmxfeed; + dvbdmxfilter->type = DMX_TYPE_SEC; + dvbdmxfilter->state = DMX_STATE_READY; + dvbdmxfilter->next = dvbdmxfeed->filter; + dvbdmxfeed->filter = dvbdmxfilter; spin_unlock_irq(&dvbdemux->lock); + up(&dvbdemux->mutex); return 0; } -static int -dmx_section_feed_set(struct dmx_section_feed_s* feed, - u16 pid, size_t circular_buffer_size, - int descramble, int check_crc) + +static +int dmx_section_feed_set(struct dmx_section_feed_s* feed, + u16 pid, size_t circular_buffer_size, + int descramble, int check_crc) { - struct dvb_demux_feed *dvbdmxfeed=(struct dvb_demux_feed *) feed; - struct dvb_demux *dvbdmx=dvbdmxfeed->demux; - struct list_head *pos, *n, *head=&dvbdmx->feed_list; + struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; + struct dvb_demux *dvbdmx = dvbdmxfeed->demux; + struct list_head *pos, *n; - if (pid>0x1fff) + if (pid > 0x1fff) return -EINVAL; if (down_interruptible (&dvbdmx->mutex)) return -ERESTARTSYS; - if (dvbdmxfeed->pid <= DMX_MAX_PID) - list_for_each_safe(pos, n, head) + if (dvbdmxfeed->pid <= DMX_MAX_PID) { + list_for_each_safe(pos, n, &dvbdmx->feed_list) { if (DMX_FEED_ENTRY(pos)->pid == dvbdmxfeed->pid) { list_del(pos); break; } + } + } + + list_add(&dvbdmxfeed->list_head, &dvbdmx->feed_list); - list_add(&dvbdmxfeed->list_head, head); - dvbdmxfeed->pid=pid; + dvbdmxfeed->pid = pid; + dvbdmxfeed->buffer_size = circular_buffer_size; + dvbdmxfeed->descramble = descramble; - dvbdmxfeed->buffer_size=circular_buffer_size; - dvbdmxfeed->descramble=descramble; if (dvbdmxfeed->descramble) { up(&dvbdmx->mutex); return -ENOSYS; } - dvbdmxfeed->feed.sec.check_crc=check_crc; + dvbdmxfeed->feed.sec.check_crc = check_crc; + #ifdef NOBUFS - dvbdmxfeed->buffer=0; + dvbdmxfeed->buffer = 0; #else dvbdmxfeed->buffer=vmalloc(dvbdmxfeed->buffer_size); if (!dvbdmxfeed->buffer) { @@ -823,39 +830,43 @@ dmx_section_feed_set(struct dmx_section_feed_s* feed, return -ENOMEM; } #endif - dvbdmxfeed->state=DMX_STATE_READY; + + dvbdmxfeed->state = DMX_STATE_READY; up(&dvbdmx->mutex); return 0; } -static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed) + +static +void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed) { - int i; + struct dvb_demux_filter *f = dvbdmxfeed->filter; dmx_section_filter_t *sf; - struct dvb_demux_filter *f; u8 mask, mode, doneq; - - if (!(f=dvbdmxfeed->filter)) + int i; + + if (!f) return; + do { - sf=&f->filter; - doneq=0; + sf = &f->filter; + doneq = 0; for (i=0; i<DVB_DEMUX_MASK_MAX; i++) { - mode=sf->filter_mode[i]; - mask=sf->filter_mask[i]; - f->maskandmode[i]=mask&mode; - doneq|=f->maskandnotmode[i]=mask&~mode; + mode = sf->filter_mode[i]; + mask = sf->filter_mask[i]; + f->maskandmode[i] = mask & mode; + doneq |= f->maskandnotmode[i] = mask & ~mode; } - f->doneq=doneq ? 1 : 0; - } while ((f=f->next)); + f->doneq = doneq ? 1 : 0; + } while ((f = f->next)); } static int dmx_section_feed_start_filtering(dmx_section_feed_t *feed) { - struct dvb_demux_feed *dvbdmxfeed=(struct dvb_demux_feed *) feed; - struct dvb_demux *dvbdmx=dvbdmxfeed->demux; + struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; + struct dvb_demux *dvbdmx = dvbdmxfeed->demux; int ret; if (down_interruptible (&dvbdmx->mutex)) @@ -865,12 +876,14 @@ dmx_section_feed_start_filtering(dmx_section_feed_t *feed) up(&dvbdmx->mutex); return -EBUSY; } + if (!dvbdmxfeed->filter) { up(&dvbdmx->mutex); return -EINVAL; } - dvbdmxfeed->feed.sec.secbufp=0; - dvbdmxfeed->feed.sec.seclen=0; + + dvbdmxfeed->feed.sec.secbufp = 0; + dvbdmxfeed->feed.sec.seclen = 0; if (!dvbdmx->start_feed) { up(&dvbdmx->mutex); @@ -885,18 +898,20 @@ dmx_section_feed_start_filtering(dmx_section_feed_t *feed) } spin_lock_irq(&dvbdmx->lock); - feed->is_filtering=1; - dvbdmxfeed->state=DMX_STATE_GO; + feed->is_filtering = 1; + dvbdmxfeed->state = DMX_STATE_GO; spin_unlock_irq(&dvbdmx->lock); + up(&dvbdmx->mutex); return 0; } -static int -dmx_section_feed_stop_filtering(struct dmx_section_feed_s* feed) + +static +int dmx_section_feed_stop_filtering(struct dmx_section_feed_s* feed) { - struct dvb_demux_feed *dvbdmxfeed=(struct dvb_demux_feed *) feed; - struct dvb_demux *dvbdmx=dvbdmxfeed->demux; + struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; + struct dvb_demux *dvbdmx = dvbdmxfeed->demux; int ret; if (down_interruptible (&dvbdmx->mutex)) @@ -906,43 +921,51 @@ dmx_section_feed_stop_filtering(struct dmx_section_feed_s* feed) up(&dvbdmx->mutex); return -ENODEV; } - ret=dvbdmx->stop_feed(dvbdmxfeed); + + ret = dvbdmx->stop_feed(dvbdmxfeed); + spin_lock_irq(&dvbdmx->lock); - dvbdmxfeed->state=DMX_STATE_READY; - feed->is_filtering=0; + dvbdmxfeed->state = DMX_STATE_READY; + feed->is_filtering = 0; spin_unlock_irq(&dvbdmx->lock); + up(&dvbdmx->mutex); return ret; } + static int dmx_section_feed_release_filter(dmx_section_feed_t *feed, dmx_section_filter_t* filter) { - struct dvb_demux_filter *dvbdmxfilter=(struct dvb_demux_filter *) filter, *f; - struct dvb_demux_feed *dvbdmxfeed=(struct dvb_demux_feed *) feed; - struct dvb_demux *dvbdmx=dvbdmxfeed->demux; + struct dvb_demux_filter *dvbdmxfilter = (struct dvb_demux_filter *) filter; + struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; + struct dvb_demux *dvbdmx = dvbdmxfeed->demux; + struct dvb_demux_filter *f; if (down_interruptible (&dvbdmx->mutex)) return -ERESTARTSYS; - if (dvbdmxfilter->feed!=dvbdmxfeed) { + if (dvbdmxfilter->feed != dvbdmxfeed) { up(&dvbdmx->mutex); return -EINVAL; } + if (feed->is_filtering) feed->stop_filtering(feed); spin_lock_irq(&dvbdmx->lock); - f=dvbdmxfeed->filter; - if (f==dvbdmxfilter) - dvbdmxfeed->filter=dvbdmxfilter->next; - else { - while(f->next!=dvbdmxfilter) - f=f->next; - f->next=f->next->next; + f = dvbdmxfeed->filter; + + if (f == dvbdmxfilter) { + dvbdmxfeed->filter = dvbdmxfilter->next; + } else { + while(f->next != dvbdmxfilter) + f = f->next; + f->next = f->next->next; } - dvbdmxfilter->state=DMX_STATE_FREE; + + dvbdmxfilter->state = DMX_STATE_FREE; spin_unlock_irq(&dvbdmx->lock); up(&dvbdmx->mutex); return 0; @@ -952,33 +975,35 @@ static int dvbdmx_allocate_section_feed(dmx_demux_t *demux, dmx_section_feed_t **feed, dmx_section_cb callback) { - struct dvb_demux *dvbdmx=(struct dvb_demux *) demux; + struct dvb_demux *dvbdmx = (struct dvb_demux *) demux; struct dvb_demux_feed *dvbdmxfeed; if (down_interruptible (&dvbdmx->mutex)) return -ERESTARTSYS; - if (!(dvbdmxfeed=dvb_dmx_feed_alloc(dvbdmx))) { + if (!(dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx))) { up(&dvbdmx->mutex); return -EBUSY; } - dvbdmxfeed->type=DMX_TYPE_SEC; - dvbdmxfeed->cb.sec=callback; - dvbdmxfeed->demux=dvbdmx; - dvbdmxfeed->pid=0xffff; - dvbdmxfeed->feed.sec.secbufp=0; - dvbdmxfeed->filter=0; - dvbdmxfeed->buffer=0; + + dvbdmxfeed->type = DMX_TYPE_SEC; + dvbdmxfeed->cb.sec = callback; + dvbdmxfeed->demux = dvbdmx; + dvbdmxfeed->pid = 0xffff; + dvbdmxfeed->feed.sec.secbufp = 0; + dvbdmxfeed->filter = 0; + dvbdmxfeed->buffer = 0; (*feed)=&dvbdmxfeed->feed.sec; - (*feed)->is_filtering=0; - (*feed)->parent=demux; - (*feed)->priv=0; - (*feed)->set=dmx_section_feed_set; - (*feed)->allocate_filter=dmx_section_feed_allocate_filter; - (*feed)->release_filter=dmx_section_feed_release_filter; - (*feed)->start_filtering=dmx_section_feed_start_filtering; - (*feed)->stop_filtering=dmx_section_feed_stop_filtering; + (*feed)->is_filtering = 0; + (*feed)->parent = demux; + (*feed)->priv = NULL; + + (*feed)->set = dmx_section_feed_set; + (*feed)->allocate_filter = dmx_section_feed_allocate_filter; + (*feed)->start_filtering = dmx_section_feed_start_filtering; + (*feed)->stop_filtering = dmx_section_feed_stop_filtering; + (*feed)->release_filter = dmx_section_feed_release_filter; up(&dvbdmx->mutex); return 0; @@ -987,9 +1012,9 @@ static int dvbdmx_allocate_section_feed(dmx_demux_t *demux, static int dvbdmx_release_section_feed(dmx_demux_t *demux, dmx_section_feed_t *feed) { - struct dvb_demux_feed *dvbdmxfeed=(struct dvb_demux_feed *) feed; - struct dvb_demux *dvbdmx=(struct dvb_demux *) demux; - struct list_head *pos, *n, *head=&dvbdmx->feed_list; + struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; + struct dvb_demux *dvbdmx = (struct dvb_demux *) demux; + struct list_head *pos, *n; if (down_interruptible (&dvbdmx->mutex)) return -ERESTARTSYS; @@ -1007,11 +1032,12 @@ static int dvbdmx_release_section_feed(dmx_demux_t *demux, dvbdmxfeed->state=DMX_STATE_FREE; if (dvbdmxfeed->pid <= DMX_MAX_PID) { - list_for_each_safe(pos, n, head) + list_for_each_safe(pos, n, &dvbdmx->feed_list) { if (DMX_FEED_ENTRY(pos)->pid == dvbdmxfeed->pid) { list_del(pos); break; } + } dvbdmxfeed->pid = 0xffff; } @@ -1024,54 +1050,61 @@ static int dvbdmx_release_section_feed(dmx_demux_t *demux, * dvb_demux kernel data API calls ******************************************************************************/ -static int dvbdmx_open(dmx_demux_t *demux) +static +int dvbdmx_open(dmx_demux_t *demux) { - struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; + struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; - if (dvbdemux->users>=MAX_DVB_DEMUX_USERS) + if (dvbdemux->users >= MAX_DVB_DEMUX_USERS) return -EUSERS; + dvbdemux->users++; return 0; } -static int dvbdmx_close(struct dmx_demux_s *demux) + +static +int dvbdmx_close(struct dmx_demux_s *demux) { - struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; + struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; - if (dvbdemux->users==0) + if (dvbdemux->users == 0) return -ENODEV; + dvbdemux->users--; //FIXME: release any unneeded resources if users==0 return 0; } -static int dvbdmx_write(dmx_demux_t *demux, const char *buf, size_t count) + +static +int dvbdmx_write(dmx_demux_t *demux, const char *buf, size_t count) { struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; - if ((!demux->frontend) || - (demux->frontend->source!=DMX_MEMORY_FE)) + if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE)) return -EINVAL; if (down_interruptible (&dvbdemux->mutex)) return -ERESTARTSYS; dvb_dmx_swfilter(dvbdemux, buf, count); + up(&dvbdemux->mutex); return count; } -static int dvbdmx_add_frontend(dmx_demux_t *demux, - dmx_frontend_t *frontend) +static +int dvbdmx_add_frontend(dmx_demux_t *demux, dmx_frontend_t *frontend) { - struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; - struct list_head *pos, *head=&dvbdemux->frontend_list; + struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; + struct list_head *pos, *head = &dvbdemux->frontend_list; if (!(frontend->id && frontend->vendor && frontend->model)) return -EINVAL; - list_for_each(pos, head) - { + + list_for_each(pos, head) { if (!strcmp(DMX_FE_ENTRY(pos)->id, frontend->id)) return -EEXIST; } @@ -1080,38 +1113,40 @@ static int dvbdmx_add_frontend(dmx_demux_t *demux, return 0; } -static int -dvbdmx_remove_frontend(dmx_demux_t *demux, - dmx_frontend_t *frontend) + +static +int dvbdmx_remove_frontend(dmx_demux_t *demux, dmx_frontend_t *frontend) { - struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; - struct list_head *pos, *n, *head=&dvbdemux->frontend_list; + struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; + struct list_head *pos, *n, *head = &dvbdemux->frontend_list; - list_for_each_safe (pos, n, head) - { - if (DMX_FE_ENTRY(pos)==frontend) - { + list_for_each_safe (pos, n, head) { + if (DMX_FE_ENTRY(pos) == frontend) { list_del(pos); return 0; } } + return -ENODEV; } -static struct list_head * -dvbdmx_get_frontends(dmx_demux_t *demux) + +static +struct list_head* dvbdmx_get_frontends(dmx_demux_t *demux) { - struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; + struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; if (list_empty(&dvbdemux->frontend_list)) return NULL; + return &dvbdemux->frontend_list; } + static int dvbdmx_connect_frontend(dmx_demux_t *demux, dmx_frontend_t *frontend) { - struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; + struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; if (demux->frontend) return -EINVAL; @@ -1119,64 +1154,75 @@ static int dvbdmx_connect_frontend(dmx_demux_t *demux, if (down_interruptible (&dvbdemux->mutex)) return -ERESTARTSYS; - demux->frontend=frontend; + demux->frontend = frontend; up(&dvbdemux->mutex); return 0; } -static int dvbdmx_disconnect_frontend(dmx_demux_t *demux) +static +int dvbdmx_disconnect_frontend(dmx_demux_t *demux) { - struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; + struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; if (down_interruptible (&dvbdemux->mutex)) return -ERESTARTSYS; - demux->frontend=NULL; + demux->frontend = NULL; + up(&dvbdemux->mutex); return 0; } -static int dvbdmx_get_pes_pids(dmx_demux_t *demux, u16 *pids) + +static +int dvbdmx_get_pes_pids(dmx_demux_t *demux, u16 *pids) { - struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; + struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; memcpy(pids, dvbdemux->pids, 5*sizeof(u16)); return 0; } -int -dvb_dmx_init(struct dvb_demux *dvbdemux) + +int dvb_dmx_init(struct dvb_demux *dvbdemux) { - int i; - dmx_demux_t *dmx=&dvbdemux->dmx; + dmx_demux_t *dmx = &dvbdemux->dmx; + int i, err; - dvbdemux->users=0; - dvbdemux->filter=vmalloc(dvbdemux->filternum*sizeof(struct dvb_demux_filter)); + dvbdemux->users = 0; + dvbdemux->filter = vmalloc(dvbdemux->filternum*sizeof(struct dvb_demux_filter)); if (!dvbdemux->filter) return -ENOMEM; - dvbdemux->feed=vmalloc(dvbdemux->feednum*sizeof(struct dvb_demux_feed)); + dvbdemux->feed = vmalloc(dvbdemux->feednum*sizeof(struct dvb_demux_feed)); + if (!dvbdemux->feed) { vfree(dvbdemux->filter); return -ENOMEM; } + for (i=0; i<dvbdemux->filternum; i++) { - dvbdemux->filter[i].state=DMX_STATE_FREE; - dvbdemux->filter[i].index=i; + dvbdemux->filter[i].state = DMX_STATE_FREE; + dvbdemux->filter[i].index = i; } + for (i=0; i<dvbdemux->feednum; i++) - dvbdemux->feed[i].state=DMX_STATE_FREE; - dvbdemux->frontend_list.next= - dvbdemux->frontend_list.prev= - &dvbdemux->frontend_list; + dvbdemux->feed[i].state = DMX_STATE_FREE; + + dvbdemux->frontend_list.next = &dvbdemux->frontend_list; + dvbdemux->frontend_list.prev = &dvbdemux->frontend_list; + for (i=0; i<DMX_TS_PES_OTHER; i++) { - dvbdemux->pesfilter[i]=NULL; - dvbdemux->pids[i]=0xffff; + dvbdemux->pesfilter[i] = NULL; + dvbdemux->pids[i] = 0xffff; } - dvbdemux->playing=dvbdemux->recording=0; + INIT_LIST_HEAD(&dvbdemux->feed_list); - dvbdemux->tsbufp=0; + + dvbdemux->playing = 0; + dvbdemux->recording = 0; + dvbdemux->tsbufp = 0; if (!dvbdemux->check_crc32) dvbdemux->check_crc32 = dvb_dmx_crc32; @@ -1184,40 +1230,42 @@ dvb_dmx_init(struct dvb_demux *dvbdemux) if (!dvbdemux->memcopy) dvbdemux->memcopy = dvb_dmx_memcopy; - dmx->frontend=0; - dmx->reg_list.next=dmx->reg_list.prev=&dmx->reg_list; - dmx->priv=(void *) dvbdemux; - //dmx->users=0; // reset in dmx_register_demux() - dmx->open=dvbdmx_open; - dmx->close=dvbdmx_close; - dmx->write=dvbdmx_write; - dmx->allocate_ts_feed=dvbdmx_allocate_ts_feed; - dmx->release_ts_feed=dvbdmx_release_ts_feed; - dmx->allocate_section_feed=dvbdmx_allocate_section_feed; - dmx->release_section_feed=dvbdmx_release_section_feed; - - dmx->descramble_mac_address=NULL; - dmx->descramble_section_payload=NULL; + dmx->frontend = 0; + dmx->reg_list.prev = &dmx->reg_list; + dmx->reg_list.next = &dmx->reg_list; + dmx->priv = (void *) dvbdemux; + dmx->open = dvbdmx_open; + dmx->close = dvbdmx_close; + dmx->write = dvbdmx_write; + dmx->allocate_ts_feed = dvbdmx_allocate_ts_feed; + dmx->release_ts_feed = dvbdmx_release_ts_feed; + dmx->allocate_section_feed = dvbdmx_allocate_section_feed; + dmx->release_section_feed = dvbdmx_release_section_feed; + + dmx->descramble_mac_address = NULL; + dmx->descramble_section_payload = NULL; - dmx->add_frontend=dvbdmx_add_frontend; - dmx->remove_frontend=dvbdmx_remove_frontend; - dmx->get_frontends=dvbdmx_get_frontends; - dmx->connect_frontend=dvbdmx_connect_frontend; - dmx->disconnect_frontend=dvbdmx_disconnect_frontend; - dmx->get_pes_pids=dvbdmx_get_pes_pids; + dmx->add_frontend = dvbdmx_add_frontend; + dmx->remove_frontend = dvbdmx_remove_frontend; + dmx->get_frontends = dvbdmx_get_frontends; + dmx->connect_frontend = dvbdmx_connect_frontend; + dmx->disconnect_frontend = dvbdmx_disconnect_frontend; + dmx->get_pes_pids = dvbdmx_get_pes_pids; + sema_init(&dvbdemux->mutex, 1); spin_lock_init(&dvbdemux->lock); - if (dmx_register_demux(dmx)<0) - return -1; + if ((err = dmx_register_demux(dmx)) < 0) + return err; return 0; } + int dvb_dmx_release(struct dvb_demux *dvbdemux) { - dmx_demux_t *dmx=&dvbdemux->dmx; + dmx_demux_t *dmx = &dvbdemux->dmx; dmx_unregister_demux(dmx); if (dvbdemux->filter) |