From 5a563399258bfdb4937b808164590589db1bbaf2 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sat, 2 Nov 2013 16:44:39 +0100 Subject: [PATCH] all: clean up cDemux headers --- azbox/dmx.cpp | 24 ++++------ azbox/dmx_cs.h | 1 - azbox/dmx_lib.h | 70 ---------------------------- azbox/video_lib.h | 2 +- generic-pc/audio.cpp | 2 +- generic-pc/dmx.cpp | 26 +++++------ generic-pc/dmx_cs.h | 1 - generic-pc/dmx_lib.h | 70 ---------------------------- generic-pc/video.cpp | 2 +- include/dmx_cs.h | 2 +- include/dmx_hal.h | 96 +++++++++++++++++++++++++++++++++++++++ include/dmx_td.h | 18 +------- libspark/dmx.cpp | 59 +++++++++++++----------- libspark/dmx_cs.h | 1 - libspark/dmx_lib.h | 72 ----------------------------- libspark/record.cpp | 5 +- libspark/record_lib.h | 2 +- libspark/video_lib.h | 2 +- libtriple/dmx_cs.h | 1 - libtriple/dmx_td.cpp | 92 +++++++++++++++++++++++-------------- libtriple/dmx_td.h | 78 ------------------------------- libtriple/playback_td.cpp | 14 ++++-- libtriple/record_td.cpp | 5 +- libtriple/record_td.h | 2 +- libtriple/video_td.h | 2 +- raspi/audio.cpp | 2 +- raspi/avdec.cpp | 2 +- raspi/dmx.cpp | 26 +++++------ raspi/dmx_cs.h | 1 - raspi/dmx_lib.h | 70 ---------------------------- raspi/video.cpp | 2 +- raspi/video_lib.h | 2 +- 32 files changed, 246 insertions(+), 508 deletions(-) delete mode 100644 azbox/dmx_cs.h delete mode 100644 azbox/dmx_lib.h delete mode 100644 generic-pc/dmx_cs.h delete mode 100644 generic-pc/dmx_lib.h create mode 100644 include/dmx_hal.h delete mode 100644 libspark/dmx_cs.h delete mode 100644 libspark/dmx_lib.h delete mode 100644 libtriple/dmx_cs.h delete mode 100644 libtriple/dmx_td.h delete mode 100644 raspi/dmx_cs.h delete mode 100644 raspi/dmx_lib.h diff --git a/azbox/dmx.cpp b/azbox/dmx.cpp index cacd823..6749089 100644 --- a/azbox/dmx.cpp +++ b/azbox/dmx.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "dmx_lib.h" #include "lt_debug.h" @@ -42,14 +43,8 @@ extern cVideo *videoDecoder; #define lt_info_c(args...) _lt_info(TRIPLE_DEBUG_DEMUX, NULL, args) #define dmx_err(_errfmt, _errstr, _revents) do { \ - uint16_t _pid = (uint16_t)-1; uint16_t _f = 0;\ - if (dmx_type == DMX_PSI_CHANNEL) { \ - _pid = s_flt.pid; _f = s_flt.filter.filter[0]; \ - } else { \ - _pid = p_flt.pid; \ - }; \ lt_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ - __func__, _errstr, fd, _revents, DMX_T[dmx_type], _pid, _f); \ + __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ } while(0); cDemux *videoDemux = NULL; @@ -88,9 +83,6 @@ cDemux::cDemux(int n) else num = n; fd = -1; - measure = false; - last_measure = 0; - last_data = 0; } cDemux::~cDemux() @@ -165,8 +157,6 @@ void cDemux::Close(void) ioctl(fd, DMX_STOP); close(fd); fd = -1; - if (measure) - return; if (dmx_type == DMX_TP_CHANNEL) { dmx_tp_count--; @@ -273,11 +263,13 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return rc; } -bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filter, +bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter, const unsigned char * const mask, int len, int timeout, const unsigned char * const negmask) { + struct dmx_sct_filter_params s_flt; memset(&s_flt, 0, sizeof(s_flt)); + pid = _pid; if (len > DMX_FILTER_SIZE) { @@ -286,6 +278,7 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte } s_flt.pid = pid; s_flt.timeout = timeout; + flt = filter[0]; memcpy(s_flt.filter.filter, filter, len); memcpy(s_flt.filter.mask, mask, len); if (negmask != NULL) @@ -389,8 +382,11 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte return true; } -bool cDemux::pesFilter(const unsigned short pid) +bool cDemux::pesFilter(const unsigned short _pid) { + struct dmx_pes_filter_params p_flt; + pid = _pid; + flt = 0; /* allow PID 0 for web streaming e.g. * this check originally is from tuxbox cvs but I'm not sure * what it is good for... diff --git a/azbox/dmx_cs.h b/azbox/dmx_cs.h deleted file mode 100644 index 175d8cb..0000000 --- a/azbox/dmx_cs.h +++ /dev/null @@ -1 +0,0 @@ -#include "dmx_lib.h" diff --git a/azbox/dmx_lib.h b/azbox/dmx_lib.h deleted file mode 100644 index 440d92d..0000000 --- a/azbox/dmx_lib.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef __DEMUX_TD_H -#define __DEMUX_TD_H - -#include -#include -#include -#include -#include -#include - -#define MAX_DMX_UNITS 4 - -typedef enum -{ - DMX_INVALID = 0, - DMX_VIDEO_CHANNEL = 1, - DMX_AUDIO_CHANNEL, - DMX_PES_CHANNEL, - DMX_PSI_CHANNEL, - DMX_PIP_CHANNEL, - DMX_TP_CHANNEL, - DMX_PCR_ONLY_CHANNEL -} DMX_CHANNEL_TYPE; - -typedef struct -{ - int fd; - unsigned short pid; -} pes_pids; - -class cDemux -{ - private: - int num; - int fd; - int buffersize; - bool measure; - uint64_t last_measure, last_data; - DMX_CHANNEL_TYPE dmx_type; - std::vector pesfds; - struct dmx_sct_filter_params s_flt; - struct dmx_pes_filter_params p_flt; - public: - - bool Open(DMX_CHANNEL_TYPE pes_type, void * x = NULL, int y = 0); - void Close(void); - bool Start(bool record = false); - bool Stop(void); - int Read(unsigned char *buff, int len, int Timeout = 0); - bool sectionFilter(unsigned short pid, const unsigned char * const filter, const unsigned char * const mask, int len, int Timeout = 0, const unsigned char * const negmask = NULL); - bool pesFilter(const unsigned short pid); - void SetSyncMode(AVSYNC_TYPE mode); - void * getBuffer(); - void * getChannel(); - DMX_CHANNEL_TYPE getChannelType(void) { return dmx_type; }; - bool addPid(unsigned short pid); - void getSTC(int64_t * STC); - int getUnit(void); - static bool SetSource(int unit, int source); - static int GetSource(int unit); - // TD only functions - int getFD(void) { return fd; }; /* needed by cPlayback class */ - void removePid(unsigned short Pid); /* needed by cRecord class */ - std::vector getPesPids(void) { return pesfds; }; - // - cDemux(int num = 0); - ~cDemux(); -}; - -#endif //__DEMUX_H diff --git a/azbox/video_lib.h b/azbox/video_lib.h index 00e33d2..eff23a0 100644 --- a/azbox/video_lib.h +++ b/azbox/video_lib.h @@ -3,7 +3,6 @@ #include #include -#include "dmx_lib.h" typedef enum { ANALOG_SD_RGB_CINCH = 0x00, @@ -112,6 +111,7 @@ typedef enum VIDEO_CONTROL_MAX = VIDEO_CONTROL_SHARPNESS } VIDEO_CONTROL; +class cDemux; class cVideo { diff --git a/generic-pc/audio.cpp b/generic-pc/audio.cpp index 53ab656..c63a65f 100644 --- a/generic-pc/audio.cpp +++ b/generic-pc/audio.cpp @@ -24,7 +24,7 @@ #include "audio_lib.h" #include "audio_priv.h" -#include "dmx_lib.h" +#include "dmx_hal.h" #include "lt_debug.h" #define lt_debug(args...) _lt_debug(HAL_DEBUG_AUDIO, this, args) diff --git a/generic-pc/dmx.cpp b/generic-pc/dmx.cpp index 9c3d569..d87f0c5 100644 --- a/generic-pc/dmx.cpp +++ b/generic-pc/dmx.cpp @@ -32,7 +32,8 @@ #include #include #include -#include "dmx_lib.h" +#include +#include "dmx_hal.h" #include "lt_debug.h" /* needed for getSTC :-( */ @@ -44,14 +45,8 @@ extern VDec *vdec; #define lt_info_c(args...) _lt_info(TRIPLE_DEBUG_DEMUX, NULL, args) #define dmx_err(_errfmt, _errstr, _revents) do { \ - uint16_t _pid = (uint16_t)-1; uint16_t _f = 0;\ - if (dmx_type == DMX_PSI_CHANNEL) { \ - _pid = s_flt.pid; _f = s_flt.filter.filter[0]; \ - } else { \ - _pid = p_flt.pid; \ - }; \ lt_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ - __func__, _errstr, fd, _revents, DMX_T[dmx_type], _pid, _f); \ + __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ } while(0); cDemux *videoDemux = NULL; @@ -92,9 +87,6 @@ cDemux::cDemux(int n) else num = n; fd = -1; - measure = false; - last_measure = 0; - last_data = 0; } cDemux::~cDemux() @@ -160,8 +152,6 @@ void cDemux::Close(void) ioctl(fd, DMX_STOP); close(fd); fd = -1; - if (measure) - return; if (dmx_type == DMX_TP_CHANNEL) { dmx_tp_count--; @@ -253,11 +243,13 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return rc; } -bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filter, +bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter, const unsigned char * const mask, int len, int timeout, const unsigned char * const negmask) { + struct dmx_sct_filter_params s_flt; memset(&s_flt, 0, sizeof(s_flt)); + pid = _pid; if (len > DMX_FILTER_SIZE) { @@ -266,6 +258,7 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte } s_flt.pid = pid; s_flt.timeout = timeout; + flt = filter[0]; memcpy(s_flt.filter.filter, filter, len); memcpy(s_flt.filter.mask, mask, len); if (negmask != NULL) @@ -366,8 +359,11 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte return true; } -bool cDemux::pesFilter(const unsigned short pid) +bool cDemux::pesFilter(const unsigned short _pid) { + struct dmx_pes_filter_params p_flt; + pid = _pid; + flt = 0; /* allow PID 0 for web streaming e.g. * this check originally is from tuxbox cvs but I'm not sure * what it is good for... diff --git a/generic-pc/dmx_cs.h b/generic-pc/dmx_cs.h deleted file mode 100644 index 175d8cb..0000000 --- a/generic-pc/dmx_cs.h +++ /dev/null @@ -1 +0,0 @@ -#include "dmx_lib.h" diff --git a/generic-pc/dmx_lib.h b/generic-pc/dmx_lib.h deleted file mode 100644 index 440d92d..0000000 --- a/generic-pc/dmx_lib.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef __DEMUX_TD_H -#define __DEMUX_TD_H - -#include -#include -#include -#include -#include -#include - -#define MAX_DMX_UNITS 4 - -typedef enum -{ - DMX_INVALID = 0, - DMX_VIDEO_CHANNEL = 1, - DMX_AUDIO_CHANNEL, - DMX_PES_CHANNEL, - DMX_PSI_CHANNEL, - DMX_PIP_CHANNEL, - DMX_TP_CHANNEL, - DMX_PCR_ONLY_CHANNEL -} DMX_CHANNEL_TYPE; - -typedef struct -{ - int fd; - unsigned short pid; -} pes_pids; - -class cDemux -{ - private: - int num; - int fd; - int buffersize; - bool measure; - uint64_t last_measure, last_data; - DMX_CHANNEL_TYPE dmx_type; - std::vector pesfds; - struct dmx_sct_filter_params s_flt; - struct dmx_pes_filter_params p_flt; - public: - - bool Open(DMX_CHANNEL_TYPE pes_type, void * x = NULL, int y = 0); - void Close(void); - bool Start(bool record = false); - bool Stop(void); - int Read(unsigned char *buff, int len, int Timeout = 0); - bool sectionFilter(unsigned short pid, const unsigned char * const filter, const unsigned char * const mask, int len, int Timeout = 0, const unsigned char * const negmask = NULL); - bool pesFilter(const unsigned short pid); - void SetSyncMode(AVSYNC_TYPE mode); - void * getBuffer(); - void * getChannel(); - DMX_CHANNEL_TYPE getChannelType(void) { return dmx_type; }; - bool addPid(unsigned short pid); - void getSTC(int64_t * STC); - int getUnit(void); - static bool SetSource(int unit, int source); - static int GetSource(int unit); - // TD only functions - int getFD(void) { return fd; }; /* needed by cPlayback class */ - void removePid(unsigned short Pid); /* needed by cRecord class */ - std::vector getPesPids(void) { return pesfds; }; - // - cDemux(int num = 0); - ~cDemux(); -}; - -#endif //__DEMUX_H diff --git a/generic-pc/video.cpp b/generic-pc/video.cpp index 1d2c904..59f8717 100644 --- a/generic-pc/video.cpp +++ b/generic-pc/video.cpp @@ -39,7 +39,7 @@ extern "C" { #define DMX_BUF_SZ 0x20000 #include "video_lib.h" -#include "dmx_lib.h" +#include "dmx_hal.h" #include "glfb_priv.h" #include "video_priv.h" #include "lt_debug.h" diff --git a/include/dmx_cs.h b/include/dmx_cs.h index 4f0dbc1..7f86974 100644 --- a/include/dmx_cs.h +++ b/include/dmx_cs.h @@ -1 +1 @@ -#include "dmx_td.h" +#include "dmx_hal.h" diff --git a/include/dmx_hal.h b/include/dmx_hal.h new file mode 100644 index 0000000..9d021fe --- /dev/null +++ b/include/dmx_hal.h @@ -0,0 +1,96 @@ +/* + * (C) 2010-2013 Stefan Seyfried + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __dmx_hal__ +#define __dmx_hal__ + +#include +#include +#include +/* at least on td, config.h needs to be included before... */ +#ifndef HAVE_TRIPLEDRAGON +#include +#else /* TRIPLEDRAGON */ +extern "C" { +#include +} +#if defined DMX_FILTER_SIZE +#undef DMX_FILTER_SIZE +#endif +#define DMX_FILTER_SIZE FILTER_LENGTH +#endif /* TRIPLEDRAGON */ + +#include + +#define MAX_DMX_UNITS 4 + +typedef enum +{ + DMX_INVALID = 0, + DMX_VIDEO_CHANNEL = 1, + DMX_AUDIO_CHANNEL, + DMX_PES_CHANNEL, + DMX_PSI_CHANNEL, + DMX_PIP_CHANNEL, + DMX_TP_CHANNEL, + DMX_PCR_ONLY_CHANNEL +} DMX_CHANNEL_TYPE; + +typedef struct +{ + int fd; + unsigned short pid; +} pes_pids; + +class cRecord; +class cPlayback; +class cDemux +{ +friend class cRecord; +friend class cPlayback; +public: + bool Open(DMX_CHANNEL_TYPE pes_type, void * x = NULL, int y = 0); + void Close(void); + bool Start(bool record = false); + bool Stop(void); + int Read(unsigned char *buff, int len, int Timeout = 0); + bool sectionFilter(unsigned short pid, const unsigned char * const filter, const unsigned char * const mask, int len, int Timeout = 0, const unsigned char * const negmask = NULL); + bool pesFilter(const unsigned short pid); + void SetSyncMode(AVSYNC_TYPE mode); + void * getBuffer(); + void * getChannel(); + DMX_CHANNEL_TYPE getChannelType(void) { return dmx_type; }; + bool addPid(unsigned short pid); + void getSTC(int64_t * STC); + int getUnit(void); + static bool SetSource(int unit, int source); + static int GetSource(int unit); + cDemux(int num = 0); + ~cDemux(); +private: + void removePid(unsigned short Pid); /* needed by cRecord class */ + int num; + int fd; + int buffersize; + uint16_t pid; + uint8_t flt; + std::vector pesfds; + DMX_CHANNEL_TYPE dmx_type; + void *pdata; +}; + +#endif //__dmx_hal__ diff --git a/include/dmx_td.h b/include/dmx_td.h index b2b3751..bf6f379 100644 --- a/include/dmx_td.h +++ b/include/dmx_td.h @@ -1,16 +1,2 @@ -#include -#if HAVE_TRIPLEDRAGON -#include "../libtriple/dmx_td.h" -#elif HAVE_SPARK_HARDWARE -#include "../libspark/dmx_lib.h" -#elif HAVE_AZBOX_HARDWARE -#include "../azbox/dmx_lib.h" -#elif HAVE_GENERIC_HARDWARE -#if BOXMODEL_RASPI -#include "../raspi/dmx_lib.h" -#else -#include "../generic-pc/dmx_lib.h" -#endif -#else -#error neither HAVE_TRIPLEDRAGON nor HAVE_SPARK_HARDWARE defined -#endif +/* will be removed once all users are converted to dmx_hal */ +#include "dmx_hal.h" diff --git a/libspark/dmx.cpp b/libspark/dmx.cpp index 6c11749..78852c1 100644 --- a/libspark/dmx.cpp +++ b/libspark/dmx.cpp @@ -65,7 +65,8 @@ #include #include #include -#include "dmx_lib.h" +#include +#include "dmx_hal.h" #include "lt_debug.h" /* Ugh... see comment in destructor for details... */ @@ -75,16 +76,12 @@ extern cVideo *videoDecoder; #define lt_debug(args...) _lt_debug(TRIPLE_DEBUG_DEMUX, this, args) #define lt_info(args...) _lt_info(TRIPLE_DEBUG_DEMUX, this, args) #define lt_info_c(args...) _lt_info(TRIPLE_DEBUG_DEMUX, NULL, args) +#define lt_info_z(args...) _lt_info(TRIPLE_DEBUG_DEMUX, thiz, args) +#define lt_debug_z(args...) _lt_debug(TRIPLE_DEBUG_DEMUX, thiz, args) #define dmx_err(_errfmt, _errstr, _revents) do { \ - uint16_t _pid = (uint16_t)-1; uint16_t _f = 0;\ - if (dmx_type == DMX_PSI_CHANNEL) { \ - _pid = s_flt.pid; _f = s_flt.filter.filter[0]; \ - } else { \ - _pid = p_flt.pid; \ - }; \ lt_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ - __func__, _errstr, fd, _revents, DMX_T[dmx_type], _pid, _f); \ + __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ } while(0); cDemux *videoDemux = NULL; @@ -122,6 +119,11 @@ static bool init[NUM_DEMUXDEV] = { false, false, false }; static int dmx_tp_count = 0; #define MAX_TS_COUNT 1 +typedef struct dmx_pdata { + int last_source; +} dmx_pdata; +#define P ((dmx_pdata *)pdata) + cDemux::cDemux(int n) { if (n < 0 || n >= NUM_DEMUX) @@ -132,10 +134,8 @@ cDemux::cDemux(int n) else num = n; fd = -1; - measure = false; - last_measure = 0; - last_data = 0; - last_source = -1; + pdata = (void *)calloc(1, sizeof(dmx_pdata)); + P->last_source = -1; } cDemux::~cDemux() @@ -154,6 +154,8 @@ cDemux::~cDemux() */ if (dmx_type == DMX_VIDEO_CHANNEL) videoDecoder = NULL; + free(pdata); + pdata = NULL; } bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBufferSize) @@ -168,18 +170,18 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe return true; } -bool cDemux::_open(void) +static bool _open(cDemux *thiz, int num, int &fd, int &last_source, DMX_CHANNEL_TYPE dmx_type, int buffersize) { int flags = O_RDWR|O_CLOEXEC; int devnum = dmx_source[num]; if (last_source == devnum) { - lt_debug("%s #%d: source (%d) did not change\n", __func__, num, last_source); + lt_debug_z("%s #%d: source (%d) did not change\n", __func__, num, last_source); if (fd > -1) return true; } if (fd > -1) { /* we changed source -> close and reopen the fd */ - lt_debug("%s #%d: FD ALREADY OPENED fd = %d lastsource %d devnum %d\n", + lt_debug_z("%s #%d: FD ALREADY OPENED fd = %d lastsource %d devnum %d\n", __func__, num, fd, last_source, devnum); close(fd); } @@ -190,10 +192,10 @@ bool cDemux::_open(void) fd = open(devname[devnum], flags); if (fd < 0) { - lt_info("%s %s: %m\n", __FUNCTION__, devname[devnum]); + lt_info_z("%s %s: %m\n", __FUNCTION__, devname[devnum]); return false; } - lt_debug("%s #%d pes_type: %s(%d), uBufferSize: %d fd: %d\n", __func__, + lt_debug_z("%s #%d pes_type: %s(%d), uBufferSize: %d fd: %d\n", __func__, num, DMX_T[dmx_type], dmx_type, buffersize, fd); /* this would actually need locking, but the worst that weill happen is, that @@ -202,9 +204,9 @@ bool cDemux::_open(void) { /* this should not change anything... */ int n = DMX_SOURCE_FRONT0 + devnum; - lt_info("%s: setting %s to source %d\n", __func__, devname[devnum], n); + lt_info_z("%s: setting %s to source %d\n", __func__, devname[devnum], n); if (ioctl(fd, DMX_SET_SOURCE, &n) < 0) - lt_info("%s DMX_SET_SOURCE failed!\n", __func__); + lt_info_z("%s DMX_SET_SOURCE failed!\n", __func__); else init[devnum] = true; } @@ -212,7 +214,7 @@ bool cDemux::_open(void) { /* probably uBufferSize == 0 means "use default size". TODO: find a reasonable default */ if (ioctl(fd, DMX_SET_BUFFER_SIZE, buffersize) < 0) - lt_info("%s DMX_SET_BUFFER_SIZE failed (%m)\n", __func__); + lt_info_z("%s DMX_SET_BUFFER_SIZE failed (%m)\n", __func__); } last_source = devnum; @@ -232,8 +234,6 @@ void cDemux::Close(void) ioctl(fd, DMX_STOP); close(fd); fd = -1; - if (measure) - return; if (dmx_type == DMX_TP_CHANNEL) { dmx_tp_count--; @@ -342,13 +342,15 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return rc; } -bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filter, +bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter, const unsigned char * const mask, int len, int timeout, const unsigned char * const negmask) { + struct dmx_sct_filter_params s_flt; memset(&s_flt, 0, sizeof(s_flt)); + pid = _pid; - _open(); + _open(this, num, fd, P->last_source, dmx_type, buffersize); if (len > DMX_FILTER_SIZE) { @@ -459,8 +461,11 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte return true; } -bool cDemux::pesFilter(const unsigned short pid) +bool cDemux::pesFilter(const unsigned short _pid) { + struct dmx_pes_filter_params p_flt; + pid = _pid; + flt = 0; /* allow PID 0 for web streaming e.g. * this check originally is from tuxbox cvs but I'm not sure * what it is good for... @@ -472,7 +477,7 @@ bool cDemux::pesFilter(const unsigned short pid) lt_debug("%s #%d pid: 0x%04hx fd: %d type: %s\n", __FUNCTION__, num, pid, fd, DMX_T[dmx_type]); - _open(); + _open(this, num, fd, P->last_source, dmx_type, buffersize); memset(&p_flt, 0, sizeof(p_flt)); p_flt.pid = pid; @@ -535,7 +540,7 @@ bool cDemux::addPid(unsigned short Pid) lt_info("%s pes_type %s not implemented yet! pid=%hx\n", __FUNCTION__, DMX_T[dmx_type], Pid); return false; } - _open(); + _open(this, num, fd, P->last_source, dmx_type, buffersize); if (fd == -1) lt_info("%s bucketfd not yet opened? pid=%hx\n", __FUNCTION__, Pid); pfd.fd = fd; /* dummy */ diff --git a/libspark/dmx_cs.h b/libspark/dmx_cs.h deleted file mode 100644 index 175d8cb..0000000 --- a/libspark/dmx_cs.h +++ /dev/null @@ -1 +0,0 @@ -#include "dmx_lib.h" diff --git a/libspark/dmx_lib.h b/libspark/dmx_lib.h deleted file mode 100644 index 8826ff4..0000000 --- a/libspark/dmx_lib.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef __DEMUX_TD_H -#define __DEMUX_TD_H - -#include -#include -#include -#include -#include -#include - -#define MAX_DMX_UNITS 4 - -typedef enum -{ - DMX_INVALID = 0, - DMX_VIDEO_CHANNEL = 1, - DMX_AUDIO_CHANNEL, - DMX_PES_CHANNEL, - DMX_PSI_CHANNEL, - DMX_PIP_CHANNEL, - DMX_TP_CHANNEL, - DMX_PCR_ONLY_CHANNEL -} DMX_CHANNEL_TYPE; - -typedef struct -{ - int fd; - unsigned short pid; -} pes_pids; - -class cDemux -{ - private: - int num; - int fd; - int buffersize; - bool measure; - uint64_t last_measure, last_data; - DMX_CHANNEL_TYPE dmx_type; - std::vector pesfds; - struct dmx_sct_filter_params s_flt; - struct dmx_pes_filter_params p_flt; - int last_source; - bool _open(void); - public: - - bool Open(DMX_CHANNEL_TYPE pes_type, void * unused = NULL, int bufsize = 0); - void Close(void); - bool Start(bool record = false); - bool Stop(void); - int Read(unsigned char *buff, int len, int Timeout = 0); - bool sectionFilter(unsigned short pid, const unsigned char * const filter, const unsigned char * const mask, int len, int Timeout = 0, const unsigned char * const negmask = NULL); - bool pesFilter(const unsigned short pid); - void SetSyncMode(AVSYNC_TYPE mode); - void * getBuffer(); - void * getChannel(); - DMX_CHANNEL_TYPE getChannelType(void) { return dmx_type; }; - bool addPid(unsigned short pid); - void getSTC(int64_t * STC); - int getUnit(void); - static bool SetSource(int unit, int source); - static int GetSource(int unit); - // TD only functions - int getFD(void) { return fd; }; /* needed by cPlayback class */ - void removePid(unsigned short Pid); /* needed by cRecord class */ - std::vector getPesPids(void) { return pesfds; }; - // - cDemux(int num = 0); - ~cDemux(); -}; - -#endif //__DEMUX_H diff --git a/libspark/record.cpp b/libspark/record.cpp index 9ed6e36..ffc8df3 100644 --- a/libspark/record.cpp +++ b/libspark/record.cpp @@ -10,6 +10,7 @@ #include #include "record_lib.h" +#include "dmx_hal.h" #include "lt_debug.h" #define lt_debug(args...) _lt_debug(TRIPLE_DEBUG_RECORD, this, args) #define lt_info(args...) _lt_info(TRIPLE_DEBUG_RECORD, this, args) @@ -125,7 +126,7 @@ bool cRecord::ChangePids(unsigned short /*vpid*/, unsigned short *apids, int num lt_info("%s: DMX = NULL\n", __func__); return false; } - pids = dmx->getPesPids(); + pids = dmx->pesfds; /* the first PID is the video pid, so start with the second PID... */ for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) { found = false; @@ -161,7 +162,7 @@ bool cRecord::AddPid(unsigned short pid) lt_info("%s: DMX = NULL\n", __func__); return false; } - pids = dmx->getPesPids(); + pids = dmx->pesfds; for (std::vector::const_iterator i = pids.begin(); i != pids.end(); ++i) { if ((*i).pid == pid) return true; /* or is it an error to try to add the same PID twice? */ diff --git a/libspark/record_lib.h b/libspark/record_lib.h index 9d3d6b6..cab59a2 100644 --- a/libspark/record_lib.h +++ b/libspark/record_lib.h @@ -2,7 +2,6 @@ #define __RECORD_TD_H #include -#include "dmx_lib.h" #define REC_STATUS_OK 0 #define REC_STATUS_SLOW 1 @@ -17,6 +16,7 @@ typedef enum { RECORD_FAILED_MEMORY /* out of memory */ } record_state_t; +class cDemux; class cRecord { private: diff --git a/libspark/video_lib.h b/libspark/video_lib.h index dd8a109..670d461 100644 --- a/libspark/video_lib.h +++ b/libspark/video_lib.h @@ -3,7 +3,6 @@ #include #include -#include "dmx_lib.h" typedef enum { ANALOG_SD_RGB_CINCH = 0x00, @@ -112,6 +111,7 @@ typedef enum VIDEO_CONTROL_MAX = VIDEO_CONTROL_SHARPNESS } VIDEO_CONTROL; +class cDemux; class cVideo { diff --git a/libtriple/dmx_cs.h b/libtriple/dmx_cs.h deleted file mode 100644 index 4f0dbc1..0000000 --- a/libtriple/dmx_cs.h +++ /dev/null @@ -1 +0,0 @@ -#include "dmx_td.h" diff --git a/libtriple/dmx_td.cpp b/libtriple/dmx_td.cpp index 92242d3..100f1e4 100644 --- a/libtriple/dmx_td.cpp +++ b/libtriple/dmx_td.cpp @@ -17,10 +17,12 @@ * along with this program. If not, see . */ +#include #include #include #include #include +#include #include #include @@ -28,7 +30,7 @@ #include #include #include -#include "dmx_td.h" +#include "dmx_hal.h" #include "lt_debug.h" /* Ugh... see comment in destructor for details... */ @@ -39,14 +41,8 @@ extern cVideo *videoDecoder; #define lt_info(args...) _lt_info(TRIPLE_DEBUG_DEMUX, this, args) #define dmx_err(_errfmt, _errstr, _revents) do { \ - uint16_t _pid = (uint16_t)-1; uint16_t _f = 0;\ - if (dmx_type == DMX_PSI_CHANNEL) { \ - _pid = s_flt.pid; _f = s_flt.filter[0]; \ - } else { \ - _pid = p_flt.pid; \ - }; \ lt_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ - __func__, _errstr, fd, _revents, DMX_T[dmx_type], _pid, _f); \ + __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ } while(0); cDemux *videoDemux = NULL; @@ -75,6 +71,14 @@ static const char *devname[] = { static int dmx_tp_count = 0; #define MAX_TS_COUNT 1 +typedef struct dmx_pdata { + bool measure; + int last_measure; + int last_data; + int devnum; +} dmx_pdata; +#define P ((dmx_pdata *)pdata) + cDemux::cDemux(int n) { if (n < 0 || n > 2) @@ -85,9 +89,10 @@ cDemux::cDemux(int n) else num = n; fd = -1; - measure = false; - last_measure = 0; - last_data = 0; + pdata = calloc(1, sizeof(pdata)); + P->measure = false; + P->last_measure = 0; + P->last_data = 0; } cDemux::~cDemux() @@ -106,11 +111,13 @@ cDemux::~cDemux() */ if (dmx_type == DMX_VIDEO_CHANNEL) videoDecoder = NULL; + free(pdata); + pdata = NULL; } bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBufferSize) { - devnum = num; + P->devnum = num; int flags = O_RDWR; if (fd > -1) lt_info("%s FD ALREADY OPENED? fd = %d\n", __FUNCTION__, fd); @@ -120,10 +127,10 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe if (num == 0 && uBufferSize == 3 * 3008 * 62) /* streaminfo measurement, let's cheat... */ { lt_info("%s num=0 and DMX_TP_CHANNEL => measurement demux\n", __func__); - devnum = 2; /* demux 0 is used for live, demux 1 for recording */ - measure = true; - last_measure = 0; - last_data = 0; + P->devnum = 2; /* demux 0 is used for live, demux 1 for recording */ + P->measure = true; + P->last_measure = 0; + P->last_data = 0; flags |= O_NONBLOCK; } else @@ -137,18 +144,18 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe return false; } dmx_tp_count++; - devnum = dmx_tp_count; + P->devnum = dmx_tp_count; } } - fd = open(devname[devnum], flags); + fd = open(devname[P->devnum], flags); if (fd < 0) { - lt_info("%s %s: %m\n", __FUNCTION__, devname[devnum]); + lt_info("%s %s: %m\n", __FUNCTION__, devname[P->devnum]); return false; } fcntl(fd, F_SETFD, FD_CLOEXEC); lt_debug("%s #%d pes_type: %s(%d), uBufferSize: %d dev:%s fd: %d\n", __func__, - num, DMX_T[pes_type], pes_type, uBufferSize, devname[devnum] + strlen("/dev/stb/"), fd); + num, DMX_T[pes_type], pes_type, uBufferSize, devname[P->devnum] + strlen("/dev/stb/"), fd); dmx_type = pes_type; @@ -159,7 +166,7 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe } if (pes_type == DMX_TP_CHANNEL) { - if (measure) + if (P->measure) return true; struct demux_bucket_para bp; bp.unloader.unloader_type = UNLOADER_TYPE_TRANSPORT; @@ -201,7 +208,7 @@ void cDemux::Close(void) ioctl(fd, DEMUX_STOP); close(fd); fd = -1; - if (measure) + if (P->measure) return; if (dmx_type == DMX_TP_CHANNEL) { @@ -262,7 +269,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) ufds.events = POLLIN; ufds.revents = 0; - if (measure) + if (P->measure) { if (timeout) usleep(timeout * 1000); @@ -271,7 +278,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) clock_gettime(CLOCK_MONOTONIC, &t); now = t.tv_sec * 1000; now += t.tv_nsec / 1000000; - if (now - last_measure < 333) + if (now - P->last_measure < 333) return 0; unsigned char dummy[12]; unsigned long long bit_s = 0; @@ -295,17 +302,17 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) bit_s = (m.rx_bytes * 7816793ULL + (m.rx_time_us / 2ULL)) / m.rx_time_us; */ bit_s = (m.rx_bytes * 8000ULL + (m.rx_time_us / 2ULL)) / m.rx_time_us; - if (now - last_data < 5000) - rc = bit_s * (now - last_data) / 8ULL; + if (now - P->last_data < 5000) + rc = bit_s * (now - P->last_data) / 8ULL; else rc = 0; lt_debug("%s measure bit_s: %llu rc: %d timediff: %lld\n", - __func__, bit_s, rc, (now - last_data)); - last_data = now; + __func__, bit_s, rc, (now - P->last_data)); + P->last_data = now; } else rc = 0; } - last_measure = now; + P->last_measure = now; ioctl(fd, DEMUX_START); return rc; } @@ -350,13 +357,14 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return rc; } -bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filter, +bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter, const unsigned char * const mask, int len, int timeout, const unsigned char * const negmask) { int length; + struct demux_filter_para s_flt; memset(&s_flt, 0, sizeof(s_flt)); - + pid = _pid; if (len > FILTER_LENGTH - 2) lt_info("%s #%d: len too long: %d, FILTER_LENGTH: %d\n", __func__, num, len, FILTER_LENGTH); if (len < 1) /* memcpy below will be unhappy */ @@ -365,6 +373,7 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte length = (len + 2 + 1) & 0xfe; /* reportedly, the TD drivers don't handle odd filter */ if (length > FILTER_LENGTH) /* lengths well. So make sure the length is a multiple */ length = FILTER_LENGTH; /* of 2. The unused mask is zeroed anyway. */ + flt = filter[0]; s_flt.pid = pid; s_flt.filter_length = length; s_flt.filter[0] = filter[0]; @@ -470,8 +479,11 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte return true; } -bool cDemux::pesFilter(const unsigned short pid) +bool cDemux::pesFilter(const unsigned short _pid) { + demux_pes_para p_flt; + pid = _pid; + flt = 0; /* allow PID 0 for web streaming e.g. * this check originally is from tuxbox cvs but I'm not sure * what it is good for... @@ -483,7 +495,7 @@ bool cDemux::pesFilter(const unsigned short pid) lt_debug("%s #%d pid: 0x%04hx fd: %d type: %s\n", __FUNCTION__, num, pid, fd, DMX_T[dmx_type]); - if (dmx_type == DMX_TP_CHANNEL && !measure) + if (dmx_type == DMX_TP_CHANNEL && !P->measure) { unsigned int n = pesfds.size(); addPid(pid); @@ -552,14 +564,14 @@ bool cDemux::addPid(unsigned short Pid) lt_info("%s pes_type %s not implemented yet! pid=%hx\n", __FUNCTION__, DMX_T[dmx_type], Pid); return false; } - if (measure) + if (P->measure) { lt_info("%s measurement demux -> skipping\n", __func__); return true; } if (fd == -1) lt_info("%s bucketfd not yet opened? pid=%hx\n", __FUNCTION__, Pid); - pfd.fd = open(devname[devnum], O_RDWR); + pfd.fd = open(devname[P->devnum], O_RDWR); if (pfd.fd < 0) { lt_info("%s #%d Pid = %hx open failed (%m)\n", __FUNCTION__, num, Pid); @@ -636,3 +648,13 @@ int cDemux::getUnit(void) anyway */ return num; } + +bool cDemux::SetSource(int /*unit*/, int /*source*/) +{ + return true; +}; + +int cDemux::GetSource(int /*unit*/) +{ + return 0; +}; diff --git a/libtriple/dmx_td.h b/libtriple/dmx_td.h deleted file mode 100644 index 71f36dd..0000000 --- a/libtriple/dmx_td.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef __DEMUX_TD_H -#define __DEMUX_TD_H - -#include -#include -extern "C" { -#include -#include -#include -} -#include -#if defined DMX_FILTER_SIZE -#undef DMX_FILTER_SIZE -#endif -#define DMX_FILTER_SIZE FILTER_LENGTH - -#define MAX_DMX_UNITS 4 - -typedef enum -{ - DMX_INVALID = 0, - DMX_VIDEO_CHANNEL = 1, - DMX_AUDIO_CHANNEL, - DMX_PES_CHANNEL, - DMX_PSI_CHANNEL, - DMX_PIP_CHANNEL, - DMX_TP_CHANNEL, - DMX_PCR_ONLY_CHANNEL -} DMX_CHANNEL_TYPE; - -typedef struct -{ - int fd; - unsigned short pid; -} pes_pids; - -class cDemux -{ - private: - int num; - int devnum; - int fd; - int buffersize; - bool measure; - uint64_t last_measure, last_data; - DMX_CHANNEL_TYPE dmx_type; - std::vector pesfds; - struct demux_filter_para s_flt; - demux_pes_para p_flt; - public: - - bool Open(DMX_CHANNEL_TYPE pes_type, void * x = NULL, int y = 0); - void Close(void); - bool Start(bool record = false); - bool Stop(void); - int Read(unsigned char *buff, int len, int Timeout = 0); - bool sectionFilter(unsigned short pid, const unsigned char * const filter, const unsigned char * const mask, int len, int Timeout = 0, const unsigned char * const negmask = NULL); - bool pesFilter(const unsigned short pid); - void SetSyncMode(AVSYNC_TYPE mode); - void * getBuffer(); - void * getChannel(); - DMX_CHANNEL_TYPE getChannelType(void) { return dmx_type; }; - bool addPid(unsigned short pid); - void getSTC(int64_t * STC); - int getUnit(void); - /* tripledragon is unlikely to get a second tuner, so stub it out right here */ - static bool SetSource(int /*unit*/, int /*source*/) { return true; }; - static int GetSource(int /*unit*/) { return 0; }; - // TD only functions - int getFD(void) { return fd; }; /* needed by cPlayback class */ - void removePid(unsigned short Pid); /* needed by cRecord class */ - std::vector getPesPids(void) { return pesfds; }; - // - cDemux(int num = 0); - ~cDemux(); -}; - -#endif //__DEMUX_H diff --git a/libtriple/playback_td.cpp b/libtriple/playback_td.cpp index 6abcbac..60a55b4 100644 --- a/libtriple/playback_td.cpp +++ b/libtriple/playback_td.cpp @@ -1,13 +1,16 @@ +#include + #include #include #include #include #include +#include #include #include #include "playback_td.h" -#include "dmx_td.h" +#include "dmx_hal.h" #include "audio_td.h" #include "video_td.h" #include "lt_debug.h" @@ -266,9 +269,9 @@ void cPlayback::playthread(void) } fcntl(dvrfd, F_SETFD, FD_CLOEXEC); - pthread_cleanup_push(playthread_cleanup_handler, 0); + pthread_cleanup_push(playthread_cleanup_handler, (void *)audioDemux->fd); - ioctl(audioDemux->getFD(), DEMUX_SELECT_SOURCE, INPUT_FROM_PVR); + ioctl(audioDemux->fd, DEMUX_SELECT_SOURCE, INPUT_FROM_PVR); if (ac3) audioDecoder->SetStreamType(AUDIO_FMT_DOLBY_DIGITAL); else @@ -360,10 +363,11 @@ void cPlayback::playthread(void) pthread_exit(NULL); } -static void playthread_cleanup_handler(void *) +static void playthread_cleanup_handler(void *arg) { lt_info_c("%s\n", __FUNCTION__); - ioctl(audioDemux->getFD(), DEMUX_SELECT_SOURCE, INPUT_FROM_CHANNEL0); + int admx_fd = (int)arg; + ioctl(admx_fd, DEMUX_SELECT_SOURCE, INPUT_FROM_CHANNEL0); audioDemux->Stop(); videoDemux->Stop(); audioDecoder->Stop(); diff --git a/libtriple/record_td.cpp b/libtriple/record_td.cpp index 584aba7..67f7228 100644 --- a/libtriple/record_td.cpp +++ b/libtriple/record_td.cpp @@ -7,6 +7,7 @@ #include #include #include "record_td.h" +#include "dmx_hal.h" #include "lt_debug.h" #define lt_debug(args...) _lt_debug(TRIPLE_DEBUG_RECORD, this, args) #define lt_info(args...) _lt_info(TRIPLE_DEBUG_RECORD, this, args) @@ -121,7 +122,7 @@ bool cRecord::ChangePids(unsigned short /*vpid*/, unsigned short *apids, int num lt_info("%s: DMX = NULL\n", __func__); return false; } - pids = dmx->getPesPids(); + pids = dmx->pesfds; /* the first PID is the video pid, so start with the second PID... */ for (std::vector::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) { found = false; @@ -157,7 +158,7 @@ bool cRecord::AddPid(unsigned short pid) lt_info("%s: DMX = NULL\n", __func__); return false; } - pids = dmx->getPesPids(); + pids = dmx->pesfds; for (std::vector::const_iterator i = pids.begin(); i != pids.end(); ++i) { if ((*i).pid == pid) return true; /* or is it an error to try to add the same PID twice? */ diff --git a/libtriple/record_td.h b/libtriple/record_td.h index c2f60ea..b7addb6 100644 --- a/libtriple/record_td.h +++ b/libtriple/record_td.h @@ -2,7 +2,6 @@ #define __RECORD_TD_H #include -#include "dmx_td.h" #define REC_STATUS_OK 0 #define REC_STATUS_SLOW 1 @@ -17,6 +16,7 @@ typedef enum { RECORD_FAILED_MEMORY /* out of memory */ } record_state_t; +class cDemux; class cRecord { private: diff --git a/libtriple/video_td.h b/libtriple/video_td.h index d50aaa6..5774117 100644 --- a/libtriple/video_td.h +++ b/libtriple/video_td.h @@ -5,7 +5,6 @@ #define video_format_t vidDispSize_t //#define video_displayformat_t vidDispMode_t #include -#include "dmx_td.h" #define STB_HAL_VIDEO_HAS_GETSCREENIMAGE 1 @@ -110,6 +109,7 @@ typedef enum VIDEO_CONTROL_MAX = VIDEO_CONTROL_SHARPNESS } VIDEO_CONTROL; +class cDemux; class cVideo { diff --git a/raspi/audio.cpp b/raspi/audio.cpp index a0d45f6..14ce3a5 100644 --- a/raspi/audio.cpp +++ b/raspi/audio.cpp @@ -21,7 +21,7 @@ #include #include "audio_lib.h" -#include "dmx_lib.h" +#include "dmx_hal.h" #include "avdec.h" #include "lt_debug.h" diff --git a/raspi/avdec.cpp b/raspi/avdec.cpp index f851f7e..0090966 100644 --- a/raspi/avdec.cpp +++ b/raspi/avdec.cpp @@ -50,7 +50,7 @@ extern "C" { #endif #include "avdec.h" -#include "dmx_lib.h" +#include "dmx_hal.h" #include "lt_debug.h" #define lt_debug(args...) _lt_debug(HAL_DEBUG_AUDIO, this, args) diff --git a/raspi/dmx.cpp b/raspi/dmx.cpp index 3e967a9..520d722 100644 --- a/raspi/dmx.cpp +++ b/raspi/dmx.cpp @@ -32,7 +32,8 @@ #include #include #include -#include "dmx_lib.h" +#include +#include "dmx_hal.h" #include "lt_debug.h" /* needed for getSTC :-( */ @@ -44,14 +45,8 @@ extern cVideo *videoDecoder; #define lt_info_c(args...) _lt_info(TRIPLE_DEBUG_DEMUX, NULL, args) #define dmx_err(_errfmt, _errstr, _revents) do { \ - uint16_t _pid = (uint16_t)-1; uint16_t _f = 0;\ - if (dmx_type == DMX_PSI_CHANNEL) { \ - _pid = s_flt.pid; _f = s_flt.filter.filter[0]; \ - } else { \ - _pid = p_flt.pid; \ - }; \ lt_info("%s " _errfmt " fd:%d, ev:0x%x %s pid:0x%04hx flt:0x%02hx\n", \ - __func__, _errstr, fd, _revents, DMX_T[dmx_type], _pid, _f); \ + __func__, _errstr, fd, _revents, DMX_T[dmx_type], pid, flt); \ } while(0); cDemux *videoDemux = NULL; @@ -90,9 +85,6 @@ cDemux::cDemux(int n) else num = n; fd = -1; - measure = false; - last_measure = 0; - last_data = 0; } cDemux::~cDemux() @@ -158,8 +150,6 @@ void cDemux::Close(void) ioctl(fd, DMX_STOP); close(fd); fd = -1; - if (measure) - return; if (dmx_type == DMX_TP_CHANNEL) { dmx_tp_count--; @@ -251,11 +241,13 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return rc; } -bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filter, +bool cDemux::sectionFilter(unsigned short _pid, const unsigned char * const filter, const unsigned char * const mask, int len, int timeout, const unsigned char * const negmask) { + struct dmx_sct_filter_params s_flt; memset(&s_flt, 0, sizeof(s_flt)); + pid = _pid; if (len > DMX_FILTER_SIZE) { @@ -264,6 +256,7 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte } s_flt.pid = pid; s_flt.timeout = timeout; + flt = filter[0]; memcpy(s_flt.filter.filter, filter, len); memcpy(s_flt.filter.mask, mask, len); if (negmask != NULL) @@ -364,8 +357,11 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte return true; } -bool cDemux::pesFilter(const unsigned short pid) +bool cDemux::pesFilter(const unsigned short _pid) { + struct dmx_pes_filter_params p_flt; + pid = _pid; + flt = 0; /* allow PID 0 for web streaming e.g. * this check originally is from tuxbox cvs but I'm not sure * what it is good for... diff --git a/raspi/dmx_cs.h b/raspi/dmx_cs.h deleted file mode 100644 index 175d8cb..0000000 --- a/raspi/dmx_cs.h +++ /dev/null @@ -1 +0,0 @@ -#include "dmx_lib.h" diff --git a/raspi/dmx_lib.h b/raspi/dmx_lib.h deleted file mode 100644 index 440d92d..0000000 --- a/raspi/dmx_lib.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef __DEMUX_TD_H -#define __DEMUX_TD_H - -#include -#include -#include -#include -#include -#include - -#define MAX_DMX_UNITS 4 - -typedef enum -{ - DMX_INVALID = 0, - DMX_VIDEO_CHANNEL = 1, - DMX_AUDIO_CHANNEL, - DMX_PES_CHANNEL, - DMX_PSI_CHANNEL, - DMX_PIP_CHANNEL, - DMX_TP_CHANNEL, - DMX_PCR_ONLY_CHANNEL -} DMX_CHANNEL_TYPE; - -typedef struct -{ - int fd; - unsigned short pid; -} pes_pids; - -class cDemux -{ - private: - int num; - int fd; - int buffersize; - bool measure; - uint64_t last_measure, last_data; - DMX_CHANNEL_TYPE dmx_type; - std::vector pesfds; - struct dmx_sct_filter_params s_flt; - struct dmx_pes_filter_params p_flt; - public: - - bool Open(DMX_CHANNEL_TYPE pes_type, void * x = NULL, int y = 0); - void Close(void); - bool Start(bool record = false); - bool Stop(void); - int Read(unsigned char *buff, int len, int Timeout = 0); - bool sectionFilter(unsigned short pid, const unsigned char * const filter, const unsigned char * const mask, int len, int Timeout = 0, const unsigned char * const negmask = NULL); - bool pesFilter(const unsigned short pid); - void SetSyncMode(AVSYNC_TYPE mode); - void * getBuffer(); - void * getChannel(); - DMX_CHANNEL_TYPE getChannelType(void) { return dmx_type; }; - bool addPid(unsigned short pid); - void getSTC(int64_t * STC); - int getUnit(void); - static bool SetSource(int unit, int source); - static int GetSource(int unit); - // TD only functions - int getFD(void) { return fd; }; /* needed by cPlayback class */ - void removePid(unsigned short Pid); /* needed by cRecord class */ - std::vector getPesPids(void) { return pesfds; }; - // - cDemux(int num = 0); - ~cDemux(); -}; - -#endif //__DEMUX_H diff --git a/raspi/video.cpp b/raspi/video.cpp index f95317c..a11a8a9 100644 --- a/raspi/video.cpp +++ b/raspi/video.cpp @@ -24,7 +24,7 @@ #include #include "video_lib.h" -#include "dmx_lib.h" +#include "dmx_hal.h" #include "avdec.h" #include "lt_debug.h" #define lt_debug(args...) _lt_debug(TRIPLE_DEBUG_VIDEO, this, args) diff --git a/raspi/video_lib.h b/raspi/video_lib.h index 1cc953b..690bc3d 100644 --- a/raspi/video_lib.h +++ b/raspi/video_lib.h @@ -4,7 +4,6 @@ #include #include #include -#include "dmx_lib.h" extern "C" { #include } @@ -116,6 +115,7 @@ typedef enum VIDEO_CONTROL_MAX = VIDEO_CONTROL_SHARPNESS } VIDEO_CONTROL; +class cDemux; #define VDEC_MAXBUFS 0x30 class cVideo