/*1* dvb_demux.h: DVB kernel demux API2*3* Copyright (C) 2000-2001 Marcus Metzler & Ralph Metzler4* for convergence integrated media GmbH5*6* This program is free software; you can redistribute it and/or7* modify it under the terms of the GNU Lesser General Public License8* as published by the Free Software Foundation; either version 2.19* of the License, or (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16*/1718#ifndef _DVB_DEMUX_H_19#define _DVB_DEMUX_H_2021#include <linux/time.h>22#include <linux/timer.h>23#include <linux/spinlock.h>24#include <linux/mutex.h>2526#include <media/demux.h>2728/**29* enum dvb_dmx_filter_type - type of demux feed.30*31* @DMX_TYPE_TS: feed is in TS mode.32* @DMX_TYPE_SEC: feed is in Section mode.33*/34enum dvb_dmx_filter_type {35DMX_TYPE_TS,36DMX_TYPE_SEC,37};3839/**40* enum dvb_dmx_state - state machine for a demux filter.41*42* @DMX_STATE_FREE: indicates that the filter is freed.43* @DMX_STATE_ALLOCATED: indicates that the filter was allocated44* to be used.45* @DMX_STATE_READY: indicates that the filter is ready46* to be used.47* @DMX_STATE_GO: indicates that the filter is running.48*/49enum dvb_dmx_state {50DMX_STATE_FREE,51DMX_STATE_ALLOCATED,52DMX_STATE_READY,53DMX_STATE_GO,54};5556#define DVB_DEMUX_MASK_MAX 185758#define MAX_PID 0x1fff5960#define SPEED_PKTS_INTERVAL 500006162/**63* struct dvb_demux_filter - Describes a DVB demux section filter.64*65* @filter: Section filter as defined by &struct dmx_section_filter.66* @maskandmode: logical ``and`` bit mask.67* @maskandnotmode: logical ``and not`` bit mask.68* @doneq: flag that indicates when a filter is ready.69* @next: pointer to the next section filter.70* @feed: &struct dvb_demux_feed pointer.71* @index: index of the used demux filter.72* @state: state of the filter as described by &enum dvb_dmx_state.73* @type: type of the filter as described74* by &enum dvb_dmx_filter_type.75*/7677struct dvb_demux_filter {78struct dmx_section_filter filter;79u8 maskandmode[DMX_MAX_FILTER_SIZE];80u8 maskandnotmode[DMX_MAX_FILTER_SIZE];81bool doneq;8283struct dvb_demux_filter *next;84struct dvb_demux_feed *feed;85int index;86enum dvb_dmx_state state;87enum dvb_dmx_filter_type type;8889/* private: used only by av7110 */90u16 hw_handle;91};9293/**94* struct dvb_demux_feed - describes a DVB field95*96* @feed: a union describing a digital TV feed.97* Depending on the feed type, it can be either98* @feed.ts or @feed.sec.99* @feed.ts: a &struct dmx_ts_feed pointer.100* For TS feed only.101* @feed.sec: a &struct dmx_section_feed pointer.102* For section feed only.103* @cb: a union describing digital TV callbacks.104* Depending on the feed type, it can be either105* @cb.ts or @cb.sec.106* @cb.ts: a dmx_ts_cb() calback function pointer.107* For TS feed only.108* @cb.sec: a dmx_section_cb() callback function pointer.109* For section feed only.110* @demux: pointer to &struct dvb_demux.111* @priv: private data that can optionally be used by a DVB driver.112* @type: type of the filter, as defined by &enum dvb_dmx_filter_type.113* @state: state of the filter as defined by &enum dvb_dmx_state.114* @pid: PID to be filtered.115* @timeout: feed timeout.116* @filter: pointer to &struct dvb_demux_filter.117* @buffer_flags: Buffer flags used to report discontinuity users via DVB118* memory mapped API, as defined by &enum dmx_buffer_flags.119* @ts_type: type of TS, as defined by &enum ts_filter_type.120* @pes_type: type of PES, as defined by &enum dmx_ts_pes.121* @cc: MPEG-TS packet continuity counter122* @pusi_seen: if true, indicates that a discontinuity was detected.123* it is used to prevent feeding of garbage from previous section.124* @peslen: length of the PES (Packet Elementary Stream).125* @list_head: head for the list of digital TV demux feeds.126* @index: a unique index for each feed. Can be used as hardware127* pid filter index.128*/129struct dvb_demux_feed {130union {131struct dmx_ts_feed ts;132struct dmx_section_feed sec;133} feed;134135union {136dmx_ts_cb ts;137dmx_section_cb sec;138} cb;139140struct dvb_demux *demux;141void *priv;142enum dvb_dmx_filter_type type;143enum dvb_dmx_state state;144u16 pid;145146ktime_t timeout;147struct dvb_demux_filter *filter;148149u32 buffer_flags;150151enum ts_filter_type ts_type;152enum dmx_ts_pes pes_type;153154int cc;155bool pusi_seen;156157u16 peslen;158159struct list_head list_head;160unsigned int index;161};162163/**164* struct dvb_demux - represents a digital TV demux165* @dmx: embedded &struct dmx_demux with demux capabilities166* and callbacks.167* @priv: private data that can optionally be used by168* a DVB driver.169* @filternum: maximum amount of DVB filters.170* @feednum: maximum amount of DVB feeds.171* @start_feed: callback routine to be called in order to start172* a DVB feed.173* @stop_feed: callback routine to be called in order to stop174* a DVB feed.175* @write_to_decoder: callback routine to be called if the feed is TS and176* it is routed to an A/V decoder, when a new TS packet177* is received.178* Used only on av7110-av.c.179* @check_crc32: callback routine to check CRC. If not initialized,180* dvb_demux will use an internal one.181* @memcopy: callback routine to memcopy received data.182* If not initialized, dvb_demux will default to memcpy().183* @users: counter for the number of demux opened file descriptors.184* Currently, it is limited to 10 users.185* @filter: pointer to &struct dvb_demux_filter.186* @feed: pointer to &struct dvb_demux_feed.187* @frontend_list: &struct list_head with frontends used by the demux.188* @pesfilter: array of &struct dvb_demux_feed with the PES types189* that will be filtered.190* @pids: list of filtered program IDs.191* @feed_list: &struct list_head with feeds.192* @tsbuf: temporary buffer used internally to store TS packets.193* @tsbufp: temporary buffer index used internally.194* @mutex: pointer to &struct mutex used to protect feed set195* logic.196* @lock: pointer to &spinlock_t, used to protect buffer handling.197* @cnt_storage: buffer used for TS/TEI continuity check.198* @speed_last_time: &ktime_t used for TS speed check.199* @speed_pkts_cnt: packets count used for TS speed check.200*/201struct dvb_demux {202struct dmx_demux dmx;203void *priv;204int filternum;205int feednum;206int (*start_feed)(struct dvb_demux_feed *feed);207int (*stop_feed)(struct dvb_demux_feed *feed);208int (*write_to_decoder)(struct dvb_demux_feed *feed,209const u8 *buf, size_t len);210u32 (*check_crc32)(struct dvb_demux_feed *feed,211const u8 *buf, size_t len);212void (*memcopy)(struct dvb_demux_feed *feed, u8 *dst,213const u8 *src, size_t len);214215int users;216#define MAX_DVB_DEMUX_USERS 10217struct dvb_demux_filter *filter;218struct dvb_demux_feed *feed;219220struct list_head frontend_list;221222struct dvb_demux_feed *pesfilter[DMX_PES_OTHER];223u16 pids[DMX_PES_OTHER];224225#define DMX_MAX_PID 0x2000226struct list_head feed_list;227u8 tsbuf[204];228int tsbufp;229230struct mutex mutex;231spinlock_t lock;232233uint8_t *cnt_storage; /* for TS continuity check */234235ktime_t speed_last_time; /* for TS speed check */236uint32_t speed_pkts_cnt; /* for TS speed check */237238/* private: used only on av7110 */239int playing;240int recording;241};242243/**244* dvb_dmx_init - initialize a digital TV demux struct.245*246* @demux: &struct dvb_demux to be initialized.247*248* Before being able to register a digital TV demux struct, drivers249* should call this routine. On its typical usage, some fields should250* be initialized at the driver before calling it.251*252* A typical usecase is::253*254* dvb->demux.dmx.capabilities =255* DMX_TS_FILTERING | DMX_SECTION_FILTERING |256* DMX_MEMORY_BASED_FILTERING;257* dvb->demux.priv = dvb;258* dvb->demux.filternum = 256;259* dvb->demux.feednum = 256;260* dvb->demux.start_feed = driver_start_feed;261* dvb->demux.stop_feed = driver_stop_feed;262* ret = dvb_dmx_init(&dvb->demux);263* if (ret < 0)264* return ret;265*/266int dvb_dmx_init(struct dvb_demux *demux);267268/**269* dvb_dmx_release - releases a digital TV demux internal buffers.270*271* @demux: &struct dvb_demux to be released.272*273* The DVB core internally allocates data at @demux. This routine274* releases those data. Please notice that the struct itelf is not275* released, as it can be embedded on other structs.276*/277void dvb_dmx_release(struct dvb_demux *demux);278279/**280* dvb_dmx_swfilter_packets - use dvb software filter for a buffer with281* multiple MPEG-TS packets with 188 bytes each.282*283* @demux: pointer to &struct dvb_demux284* @buf: buffer with data to be filtered285* @count: number of MPEG-TS packets with size of 188.286*287* The routine will discard a DVB packet that don't start with 0x47.288*289* Use this routine if the DVB demux fills MPEG-TS buffers that are290* already aligned.291*292* NOTE: The @buf size should have size equal to ``count * 188``.293*/294void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,295size_t count);296297/**298* dvb_dmx_swfilter - use dvb software filter for a buffer with299* multiple MPEG-TS packets with 188 bytes each.300*301* @demux: pointer to &struct dvb_demux302* @buf: buffer with data to be filtered303* @count: number of MPEG-TS packets with size of 188.304*305* If a DVB packet doesn't start with 0x47, it will seek for the first306* byte that starts with 0x47.307*308* Use this routine if the DVB demux fill buffers that may not start with309* a packet start mark (0x47).310*311* NOTE: The @buf size should have size equal to ``count * 188``.312*/313void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count);314315/**316* dvb_dmx_swfilter_204 - use dvb software filter for a buffer with317* multiple MPEG-TS packets with 204 bytes each.318*319* @demux: pointer to &struct dvb_demux320* @buf: buffer with data to be filtered321* @count: number of MPEG-TS packets with size of 204.322*323* If a DVB packet doesn't start with 0x47, it will seek for the first324* byte that starts with 0x47.325*326* Use this routine if the DVB demux fill buffers that may not start with327* a packet start mark (0x47).328*329* NOTE: The @buf size should have size equal to ``count * 204``.330*/331void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf,332size_t count);333334/**335* dvb_dmx_swfilter_raw - make the raw data available to userspace without336* filtering337*338* @demux: pointer to &struct dvb_demux339* @buf: buffer with data340* @count: number of packets to be passed. The actual size of each packet341* depends on the &dvb_demux->feed->cb.ts logic.342*343* Use it if the driver needs to deliver the raw payload to userspace without344* passing through the kernel demux. That is meant to support some345* delivery systems that aren't based on MPEG-TS.346*347* This function relies on &dvb_demux->feed->cb.ts to actually handle the348* buffer.349*/350void dvb_dmx_swfilter_raw(struct dvb_demux *demux, const u8 *buf,351size_t count);352353#endif /* _DVB_DEMUX_H_ */354355356