^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * dmxdev.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2000 Ralph Metzler & Marcus Metzler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * for convergence integrated media GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * modify it under the terms of the GNU Lesser General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * as published by the Free Software Foundation; either version 2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * of the License, or (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #ifndef _DMXDEV_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define _DMXDEV_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/dvb/dmx.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <media/dvbdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <media/demux.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <media/dvb_ringbuffer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <media/dvb_vb2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * enum dmxdev_type - type of demux filter type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * @DMXDEV_TYPE_NONE: no filter set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * @DMXDEV_TYPE_SEC: section filter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @DMXDEV_TYPE_PES: Program Elementary Stream (PES) filter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) enum dmxdev_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) DMXDEV_TYPE_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) DMXDEV_TYPE_SEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) DMXDEV_TYPE_PES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * enum dmxdev_state - state machine for the dmxdev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * @DMXDEV_STATE_FREE: indicates that the filter is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @DMXDEV_STATE_ALLOCATED: indicates that the filter was allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * to be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @DMXDEV_STATE_SET: indicates that the filter parameters are set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @DMXDEV_STATE_GO: indicates that the filter is running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @DMXDEV_STATE_DONE: indicates that a packet was already filtered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * and the filter is now disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Set only if %DMX_ONESHOT. See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * &dmx_sct_filter_params.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @DMXDEV_STATE_TIMEDOUT: Indicates a timeout condition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) enum dmxdev_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) DMXDEV_STATE_FREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) DMXDEV_STATE_ALLOCATED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) DMXDEV_STATE_SET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) DMXDEV_STATE_GO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) DMXDEV_STATE_DONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) DMXDEV_STATE_TIMEDOUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * struct dmxdev_feed - digital TV dmxdev feed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * @pid: Program ID to be filtered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * @ts: pointer to &struct dmx_ts_feed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * @next: &struct list_head pointing to the next feed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct dmxdev_feed {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) u16 pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct dmx_ts_feed *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct list_head next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * struct dmxdev_filter - digital TV dmxdev filter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * @filter: a union describing a dmxdev filter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Currently used only for section filters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * @filter.sec: a &struct dmx_section_filter pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * For section filter only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * @feed: a union describing a dmxdev feed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Depending on the filter type, it can be either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * @feed.ts or @feed.sec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * @feed.ts: a &struct list_head list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * For TS and PES feeds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * @feed.sec: a &struct dmx_section_feed pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * For section feed only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @params: a union describing dmxdev filter parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * Depending on the filter type, it can be either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * @params.sec or @params.pes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @params.sec: a &struct dmx_sct_filter_params embedded struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * For section filter only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * @params.pes: a &struct dmx_pes_filter_params embedded struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * For PES filter only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * @type: type of the dmxdev filter, as defined by &enum dmxdev_type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * @state: state of the dmxdev filter, as defined by &enum dmxdev_state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * @dev: pointer to &struct dmxdev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * @buffer: an embedded &struct dvb_ringbuffer buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * @vb2_ctx: control struct for VB2 handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * @mutex: protects the access to &struct dmxdev_filter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * @timer: &struct timer_list embedded timer, used to check for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * feed timeouts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * Only for section filter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * @todo: index for the @secheader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * Only for section filter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * @secheader: buffer cache to parse the section header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * Only for section filter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct dmxdev_filter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct dmx_section_filter *sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) } filter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* list of TS and PES feeds (struct dmxdev_feed) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct list_head ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct dmx_section_feed *sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) } feed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct dmx_sct_filter_params sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct dmx_pes_filter_params pes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) } params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) enum dmxdev_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) enum dmxdev_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct dmxdev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct dvb_ringbuffer buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct dvb_vb2_ctx vb2_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* only for sections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) u8 secheader[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * struct dmxdev - Describes a digital TV demux device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * @dvbdev: pointer to &struct dvb_device associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * the demux device node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * @dvr_dvbdev: pointer to &struct dvb_device associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * the dvr device node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * @filter: pointer to &struct dmxdev_filter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * @demux: pointer to &struct dmx_demux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * @filternum: number of filters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * @capabilities: demux capabilities as defined by &enum dmx_demux_caps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * @may_do_mmap: flag used to indicate if the device may do mmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * @exit: flag to indicate that the demux is being released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * @dvr_orig_fe: pointer to &struct dmx_frontend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * @dvr_buffer: embedded &struct dvb_ringbuffer for DVB output.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * @dvr_vb2_ctx: control struct for VB2 handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * @mutex: protects the usage of this structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * @lock: protects access to &dmxdev->filter->data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct dmxdev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct dvb_device *dvbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct dvb_device *dvr_dvbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct dmxdev_filter *filter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct dmx_demux *demux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int filternum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int capabilities;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) unsigned int may_do_mmap:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) unsigned int exit:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #define DMXDEV_CAP_DUPLEX 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct dmx_frontend *dvr_orig_fe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct dvb_ringbuffer dvr_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #define DVR_BUFFER_SIZE (10*188*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct dvb_vb2_ctx dvr_vb2_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * dvb_dmxdev_init - initializes a digital TV demux and registers both demux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * and DVR devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * @dmxdev: pointer to &struct dmxdev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * @adap: pointer to &struct dvb_adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * dvb_dmxdev_release - releases a digital TV demux and unregisters it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * @dmxdev: pointer to &struct dmxdev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) void dvb_dmxdev_release(struct dmxdev *dmxdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #endif /* _DMXDEV_H_ */