all: clean up cDemux headers

This commit is contained in:
max_10
2018-03-21 01:53:22 +01:00
committed by Thilo Graf
parent f4ad480fc0
commit 6a3abc86d8
85 changed files with 759 additions and 1285 deletions

View File

@@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libtriple.la
AM_CPPFLAGS = \
-I$(top_srcdir)/common \
-I$(top_srcdir)/include \
@DIRECTFB_CFLAGS@
AM_CXXFLAGS = -fno-rtti -fno-exceptions -fno-strict-aliasing

View File

@@ -4,7 +4,7 @@
#define _AUDIO_TD_H_
#include <hardware/aud/aud_inf.h>
#include "../common/cs_types.h"
#include "cs_types.h"
typedef enum
{

View File

@@ -1,67 +0,0 @@
/* compatibility header for tripledragon. I'm lazy, so I just left it
as "cs_api.h" so that I don't need too many ifdefs in the code */
#ifndef __CS_API_H_
#define __CS_API_H_
#include "init_td.h"
typedef void (*cs_messenger) (unsigned int msg, unsigned int data);
#if 0
enum CS_LOG_MODULE {
CS_LOG_CI = 0,
CS_LOG_HDMI_CEC,
CS_LOG_HDMI,
CS_LOG_VIDEO,
CS_LOG_VIDEO_DRM,
CS_LOG_AUDIO,
CS_LOG_DEMUX,
CS_LOG_DENC,
CS_LOG_PVR_RECORD,
CS_LOG_PVR_PLAY,
CS_LOG_POWER_CTRL,
CS_LOG_POWER_CLK,
CS_LOG_MEM,
CS_LOG_API,
};
#endif
inline void cs_api_init()
{
init_td_api();
};
inline void cs_api_exit()
{
shutdown_td_api();
};
#define cs_malloc_uncached malloc
#define cs_free_uncached free
// Callback function helpers
static inline void cs_register_messenger(cs_messenger) { return; };
static inline void cs_deregister_messenger(void) { return; };
//cs_messenger cs_get_messenger(void);
#if 0
// Logging functions
void cs_log_enable(void);
void cs_log_disable(void);
void cs_log_message(const char *prefix, const char *fmt, ...);
void cs_log_module_enable(enum CS_LOG_MODULE module);
void cs_log_module_disable(enum CS_LOG_MODULE module);
void cs_log_module_message(enum CS_LOG_MODULE module, const char *fmt, ...);
// TS Routing
unsigned int cs_get_ts_output(void);
int cs_set_ts_output(unsigned int port);
// Serial nr and revision accessors
unsigned long long cs_get_serial(void);
#endif
/* compat... HD1 seems to be version 6. everything newer ist > 6... */
static inline unsigned int cs_get_revision(void) { return 1; };
static inline unsigned int cs_get_chip_type(void) { return 0; };
extern int cnxt_debug;
#endif //__CS_API_H_

View File

@@ -1 +0,0 @@
#include "dmx_td.h"

View File

@@ -17,18 +17,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <poll.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <inttypes.h>
#include <unistd.h>
#include <cstring>
#include <cstdio>
#include <string>
#include <hardware/tddevices.h>
#include "dmx_td.h"
#include "dmx_hal.h"
#include "lt_debug.h"
/* Ugh... see comment in destructor for details... */
@@ -39,14 +42,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 +72,15 @@ 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;
bool running;
} dmx_pdata;
#define P ((dmx_pdata *)pdata)
cDemux::cDemux(int n)
{
if (n < 0 || n > 2)
@@ -85,32 +91,24 @@ cDemux::cDemux(int n)
else
num = n;
fd = -1;
measure = false;
last_measure = 0;
last_data = 0;
pdata = calloc(1, sizeof(dmx_pdata));
P->measure = false;
P->last_measure = 0;
P->last_data = 0;
P->running = false;
}
cDemux::~cDemux()
{
lt_debug("%s #%d fd: %d\n", __FUNCTION__, num, fd);
Close();
/* in zapit.cpp, videoDemux is deleted after videoDecoder
* in the video watchdog, we access videoDecoder
* the thread still runs after videoDecoder has been deleted
* => set videoDecoder to NULL here to make the check in the
* watchdog thread pick this up.
* This is ugly, but it saves me from changing neutrino
*
* if the delete order in neutrino will ever be changed, this
* will blow up badly :-(
*/
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 +118,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 +135,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 +157,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 +199,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)
{
@@ -229,6 +227,7 @@ bool cDemux::Start(bool)
perror("DEMUX_START");
}
ioctl(fd, DEMUX_START);
P->running = true;
return true;
}
@@ -246,6 +245,7 @@ bool cDemux::Stop(void)
perror("DEMUX_STOP");
}
ioctl(fd, DEMUX_STOP);
P->running = false;
return true;
}
@@ -262,7 +262,15 @@ int cDemux::Read(unsigned char *buff, int len, int timeout)
ufds.events = POLLIN;
ufds.revents = 0;
if (measure)
if (dmx_type == DMX_INVALID) /* happens, if too many DMX_TP are requested, because */
{ /* nobody checks the return value of Open or Start... */
lt_debug("%s #%d: DMX_INVALID\n", __func__, num);
usleep(timeout * 1000); /* rate-limit the debug message */
errno = EINVAL;
return -1;
}
if (P->measure)
{
if (timeout)
usleep(timeout * 1000);
@@ -271,7 +279,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 +303,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 +358,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 +374,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];
@@ -467,11 +477,15 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte
if (ioctl(fd, DEMUX_FILTER_SET, &s_flt) < 0)
return false;
P->running = true;
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 +497,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);
@@ -533,6 +547,8 @@ void cDemux::SetSyncMode(AVSYNC_TYPE /*mode*/)
void *cDemux::getBuffer()
{
lt_debug("%s #%d\n", __FUNCTION__, num);
if (P->running)
return (void *)1;
return NULL;
}
@@ -552,14 +568,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);

View File

@@ -1,78 +0,0 @@
#ifndef __DEMUX_TD_H
#define __DEMUX_TD_H
#include <cstdlib>
#include <vector>
extern "C" {
#include <inttypes.h>
#include <sys/ioctl.h>
#include <hardware/xp/xp_osd_user.h>
}
#include "../common/cs_types.h"
#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<pes_pids> 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<pes_pids> getPesPids(void) { return pesfds; };
//
cDemux(int num = 0);
~cDemux();
};
#endif //__DEMUX_H

View File

@@ -1,2 +0,0 @@
#warning using init_cs.h from libtriple
#include "init_td.h"

View File

@@ -36,7 +36,7 @@ int gfxfd = -1;
#define DFBCHECK(x...) \
err = x; \
if (err != DFB_OK) { \
fprintf(stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
fprintf(stderr, "init_td.cpp:%d:\n\t", __LINE__); \
DirectFBErrorFatal(#x, err ); \
}

View File

@@ -1,5 +0,0 @@
#ifndef __INIT_TD_H
#define __INIT_TD_H
void init_td_api();
void shutdown_td_api();
#endif

View File

@@ -58,7 +58,7 @@ extern cVideo *videoDecoder;
#define DFBCHECK(x...) \
err = x; \
if (err != DFB_OK) { \
fprintf(stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
fprintf(stderr, "lt_dfbinput.cpp:%d:\n\t", __LINE__); \
DirectFBErrorFatal(#x, err ); \
}

View File

@@ -1,13 +1,18 @@
#include <config.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <cstring>
#include <map>
#include "playback_td.h"
#include "dmx_td.h"
#include "dmx_hal.h"
#include "audio_td.h"
#include "video_td.h"
#include "lt_debug.h"

View File

@@ -6,7 +6,11 @@
#include <inttypes.h>
#include <cstdio>
#include <cstring>
#include <pthread.h>
#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 +125,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<pes_pids>::const_iterator i = pids.begin() + 1; i != pids.end(); ++i) {
found = false;
@@ -157,7 +161,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<pes_pids>::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? */

View File

@@ -2,7 +2,7 @@
#define __RECORD_TD_H
#include <pthread.h>
#include "dmx_td.h"
#include "dmx_hal.h"
#define REC_STATUS_OK 0
#define REC_STATUS_SLOW 1

View File

@@ -4,7 +4,7 @@
#include <hardware/vid/vid_inf.h>
#define video_format_t vidDispSize_t
//#define video_displayformat_t vidDispMode_t
#include "../common/cs_types.h"
#include "cs_types.h"
#include "dmx_td.h"
#define STB_HAL_VIDEO_HAS_GETSCREENIMAGE 1