mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-30 08:51:10 +02:00
driver/genpsi.cpp: replace old code with class
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
/*
|
||||
$Id: genpsi.c,v 1.2 2006/01/16 12:45:54 sat_man Exp $
|
||||
|
||||
Copyright (c) 2004 gmo18t, Germany. All rights reserved.
|
||||
|
||||
aktuelle Versionen gibt es hier:
|
||||
$Source: /cvs/tuxbox/apps/tuxbox/neutrino/src/driver/genpsi.c,v $
|
||||
Copyright (C) 2012 CoolStream International Ltd
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
@@ -22,7 +18,7 @@ $Id: genpsi.c,v 1.2 2006/01/16 12:45:54 sat_man Exp $
|
||||
|
||||
Mit diesem Programm koennen Neutrino TS Streams für das Abspielen unter Enigma gepatched werden
|
||||
*/
|
||||
//#include <mpegtools/transform.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <driver/genpsi.h>
|
||||
@@ -40,17 +36,6 @@ $Id: genpsi.c,v 1.2 2006/01/16 12:45:54 sat_man Exp $
|
||||
#define ES_TYPE_MPA 0x03
|
||||
#define ES_TYPE_AC3 0x81
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short nba;
|
||||
uint16_t vpid;
|
||||
uint8_t vtype;
|
||||
uint16_t apid[10];
|
||||
short isAC3[10];
|
||||
} T_AV_PIDS;
|
||||
|
||||
T_AV_PIDS avPids;
|
||||
|
||||
static const uint32_t crc_table[256] = {
|
||||
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
|
||||
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
|
||||
@@ -97,49 +82,6 @@ static const uint32_t crc_table[256] = {
|
||||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
|
||||
};
|
||||
|
||||
uint32_t calc_crc32psi(uint8_t *dst, const uint8_t *src, uint32_t len)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t crc = 0xffffffff;
|
||||
|
||||
for (i=0; i<len; i++)
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 24) ^ *src++) & 0xff];
|
||||
|
||||
if (dst)
|
||||
{
|
||||
dst[0] = (crc >> 24) & 0xff;
|
||||
dst[1] = (crc >> 16) & 0xff;
|
||||
dst[2] = (crc >> 8) & 0xff;
|
||||
dst[3] = (crc) & 0xff;
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
void transfer_pids(uint16_t pid,uint16_t pidart,short isAC3)
|
||||
{
|
||||
switch(pidart)
|
||||
{
|
||||
case EN_TYPE_VIDEO:
|
||||
avPids.vpid=pid;
|
||||
avPids.vtype = ES_TYPE_MPEG12;
|
||||
break;
|
||||
case EN_TYPE_AVC:
|
||||
avPids.vpid=pid;
|
||||
avPids.vtype = ES_TYPE_AVC;
|
||||
break;
|
||||
case EN_TYPE_AUDIO:
|
||||
avPids.apid[avPids.nba]=pid;
|
||||
avPids.isAC3[avPids.nba]=isAC3;
|
||||
avPids.nba++;
|
||||
break;
|
||||
case EN_TYPE_TELTEX:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
//-- special enigma stream description packet for --
|
||||
//-- at least 1 video, 1 audo and 1 PCR-Pid stream --
|
||||
//------------------------------------------------------------------------------------
|
||||
@@ -177,13 +119,65 @@ static uint8_t pkt_pmt[] =
|
||||
0x03, 0xE0, 0x00, 0xF0, 0x00 // (audio stream 1)
|
||||
};
|
||||
|
||||
CGenPsi::CGenPsi()
|
||||
{
|
||||
nba = 0;
|
||||
vpid = 0;
|
||||
vtype = 0;
|
||||
memset(apid, 0, sizeof(apid));
|
||||
memset(atypes, 0, sizeof(atypes));
|
||||
}
|
||||
|
||||
uint32_t CGenPsi::calc_crc32psi(uint8_t *dst, const uint8_t *src, uint32_t len)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t crc = 0xffffffff;
|
||||
|
||||
for (i=0; i<len; i++)
|
||||
crc = (crc << 8) ^ crc_table[((crc >> 24) ^ *src++) & 0xff];
|
||||
|
||||
if (dst)
|
||||
{
|
||||
dst[0] = (crc >> 24) & 0xff;
|
||||
dst[1] = (crc >> 16) & 0xff;
|
||||
dst[2] = (crc >> 8) & 0xff;
|
||||
dst[3] = (crc) & 0xff;
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
void CGenPsi::addPid(uint16_t pid, uint16_t pidtype, short isAC3)
|
||||
{
|
||||
switch(pidtype)
|
||||
{
|
||||
case EN_TYPE_VIDEO:
|
||||
vpid=pid;
|
||||
vtype = ES_TYPE_MPEG12;
|
||||
break;
|
||||
case EN_TYPE_AVC:
|
||||
vpid=pid;
|
||||
vtype = ES_TYPE_AVC;
|
||||
break;
|
||||
case EN_TYPE_AUDIO:
|
||||
apid[nba]=pid;
|
||||
atypes[nba]=isAC3;
|
||||
nba++;
|
||||
break;
|
||||
case EN_TYPE_TELTEX:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//== setup a new TS packet with format ==
|
||||
//== predefined with a template ==
|
||||
//=======================================
|
||||
#define COPY_TEMPLATE(dst, src) copy_template(dst, src, sizeof(src))
|
||||
|
||||
static int copy_template(uint8_t *dst, uint8_t *src, int len)
|
||||
int CGenPsi::copy_template(uint8_t *dst, uint8_t *src, int len)
|
||||
{
|
||||
//-- reset buffer --
|
||||
memset(dst, 0xFF, SIZE_TS_PKT);
|
||||
@@ -192,92 +186,93 @@ static int copy_template(uint8_t *dst, uint8_t *src, int len)
|
||||
|
||||
return len;
|
||||
}
|
||||
int genpsi(int fd2)
|
||||
|
||||
int CGenPsi::genpsi(int fd)
|
||||
{
|
||||
// int bytes = 0;
|
||||
uint8_t pkt[SIZE_TS_PKT];
|
||||
int i, data_len, patch_len, ofs;
|
||||
|
||||
//-- copy "Enigma"-template --
|
||||
//-- copy "Enigma"-template --
|
||||
data_len = COPY_TEMPLATE(pkt, pkt_enigma);
|
||||
|
||||
//-- adjust len dependent to number of audio streams --
|
||||
data_len += ((SIZE_ENIGMA_TAB_ROW+1) * (avPids.nba-1));
|
||||
//-- adjust len dependent to number of audio streams --
|
||||
data_len += ((SIZE_ENIGMA_TAB_ROW+1) * (nba-1));
|
||||
|
||||
patch_len = data_len - OFS_HDR_2 + 1;
|
||||
pkt[OFS_HDR_2+1] |= (patch_len>>8);
|
||||
pkt[OFS_HDR_2+2] = (patch_len & 0xFF);
|
||||
//-- write row with desc. for video stream --
|
||||
//-- write row with desc. for video stream --
|
||||
ofs = OFS_ENIGMA_TAB;
|
||||
pkt[ofs] = EN_TYPE_VIDEO;
|
||||
pkt[ofs+1] = 0x02;
|
||||
pkt[ofs+2] = (avPids.vpid>>8);
|
||||
pkt[ofs+3] = (avPids.vpid & 0xFF);
|
||||
//-- for each audio stream, write row with desc. --
|
||||
pkt[ofs+2] = (vpid>>8);
|
||||
pkt[ofs+3] = (vpid & 0xFF);
|
||||
//-- for each audio stream, write row with desc. --
|
||||
ofs += SIZE_ENIGMA_TAB_ROW;
|
||||
for (i=0; i<avPids.nba; i++)
|
||||
for (i=0; i<nba; i++)
|
||||
{
|
||||
pkt[ofs] = EN_TYPE_AUDIO;
|
||||
pkt[ofs+1] = 0x03;
|
||||
pkt[ofs+2] = (avPids.apid[i]>>8);
|
||||
pkt[ofs+3] = (avPids.apid[i] & 0xFF);
|
||||
pkt[ofs+4] = (avPids.isAC3[i]==1)? 0x01 : 0x00;
|
||||
pkt[ofs+2] = (apid[i]>>8);
|
||||
pkt[ofs+3] = (apid[i] & 0xFF);
|
||||
pkt[ofs+4] = (atypes[i]==1)? 0x01 : 0x00;
|
||||
|
||||
ofs += (SIZE_ENIGMA_TAB_ROW + 1);
|
||||
}
|
||||
//-- write row with desc. for pcr stream (eq. video) --
|
||||
//-- write row with desc. for pcr stream (eq. video) --
|
||||
pkt[ofs] = EN_TYPE_PCR;
|
||||
pkt[ofs+1] = 0x02;
|
||||
pkt[ofs+2] = (avPids.vpid>>8);
|
||||
pkt[ofs+3] = (avPids.vpid & 0xFF);
|
||||
pkt[ofs+2] = (vpid>>8);
|
||||
pkt[ofs+3] = (vpid & 0xFF);
|
||||
|
||||
//-- calculate CRC --
|
||||
//-- calculate CRC --
|
||||
calc_crc32psi(&pkt[data_len], &pkt[OFS_HDR_2], data_len-OFS_HDR_2 );
|
||||
//-- write TS packet --
|
||||
/*bytes +=*/ write(fd2, pkt, SIZE_TS_PKT);
|
||||
//-- (II) build PAT --
|
||||
//-- write TS packet --
|
||||
write(fd, pkt, SIZE_TS_PKT);
|
||||
|
||||
//-- (II) build PAT --
|
||||
data_len = COPY_TEMPLATE(pkt, pkt_pat);
|
||||
//-- calculate CRC --
|
||||
//-- calculate CRC --
|
||||
calc_crc32psi(&pkt[data_len], &pkt[OFS_HDR_2], data_len-OFS_HDR_2 );
|
||||
//-- write TS packet --
|
||||
/*bytes +=*/ write(fd2, pkt, SIZE_TS_PKT);
|
||||
//-- write TS packet --
|
||||
write(fd, pkt, SIZE_TS_PKT);
|
||||
|
||||
//-- (III) build PMT --
|
||||
//-- (III) build PMT --
|
||||
data_len = COPY_TEMPLATE(pkt, pkt_pmt);
|
||||
//-- adjust len dependent to count of audio streams --
|
||||
data_len += (SIZE_STREAM_TAB_ROW * (avPids.nba-1));
|
||||
//-- adjust len dependent to count of audio streams --
|
||||
data_len += (SIZE_STREAM_TAB_ROW * (nba-1));
|
||||
patch_len = data_len - OFS_HDR_2 + 1;
|
||||
pkt[OFS_HDR_2+1] |= (patch_len>>8);
|
||||
pkt[OFS_HDR_2+2] = (patch_len & 0xFF);
|
||||
//-- patch pcr PID --
|
||||
//-- patch pcr PID --
|
||||
ofs = OFS_PMT_DATA;
|
||||
pkt[ofs] |= (avPids.vpid>>8);
|
||||
pkt[ofs+1] = (avPids.vpid & 0xFF);
|
||||
//-- write row with desc. for ES video stream --
|
||||
pkt[ofs] |= (vpid>>8);
|
||||
pkt[ofs+1] = (vpid & 0xFF);
|
||||
//-- write row with desc. for ES video stream --
|
||||
ofs = OFS_STREAM_TAB;
|
||||
pkt[ofs] = avPids.vtype;
|
||||
pkt[ofs+1] = 0xE0 | (avPids.vpid>>8);
|
||||
pkt[ofs+2] = (avPids.vpid & 0xFF);
|
||||
pkt[ofs] = vtype;
|
||||
pkt[ofs+1] = 0xE0 | (vpid>>8);
|
||||
pkt[ofs+2] = (vpid & 0xFF);
|
||||
pkt[ofs+3] = 0xF0;
|
||||
pkt[ofs+4] = 0x00;
|
||||
|
||||
//-- for each ES audio stream, write row with desc. --
|
||||
for (i=0; i<avPids.nba; i++)
|
||||
//-- for each ES audio stream, write row with desc. --
|
||||
for (i=0; i<nba; i++)
|
||||
{
|
||||
ofs += SIZE_STREAM_TAB_ROW;
|
||||
pkt[ofs] = (avPids.isAC3[i]==1)? ES_TYPE_AC3 : ES_TYPE_MPA;
|
||||
pkt[ofs+1] = 0xE0 | (avPids.apid[i]>>8);
|
||||
pkt[ofs+2] = (avPids.apid[i] & 0xFF);
|
||||
pkt[ofs] = (atypes[i]==1)? ES_TYPE_AC3 : ES_TYPE_MPA;
|
||||
pkt[ofs+1] = 0xE0 | (apid[i]>>8);
|
||||
pkt[ofs+2] = (apid[i] & 0xFF);
|
||||
pkt[ofs+3] = 0xF0;
|
||||
pkt[ofs+4] = 0x00;
|
||||
}
|
||||
//-- calculate CRC --
|
||||
//-- calculate CRC --
|
||||
calc_crc32psi(&pkt[data_len], &pkt[OFS_HDR_2], data_len-OFS_HDR_2 );
|
||||
//-- write TS packet --
|
||||
/*bytes +=*/ write(fd2, pkt, SIZE_TS_PKT);
|
||||
//-- finish --
|
||||
avPids.vpid=0;
|
||||
avPids.nba=0;
|
||||
fdatasync(fd2);
|
||||
//-- write TS packet --
|
||||
write(fd, pkt, SIZE_TS_PKT);
|
||||
//-- finish --
|
||||
vpid=0;
|
||||
nba=0;
|
||||
fdatasync(fd);
|
||||
return 1;
|
||||
}
|
@@ -1,10 +1,7 @@
|
||||
/*
|
||||
$Id: genpsi.h,v 1.1 2005/08/15 14:47:52 metallica Exp $
|
||||
|
||||
Copyright (c) 2004 gmo18t, Germany. All rights reserved.
|
||||
|
||||
aktuelle Versionen gibt es hier:
|
||||
$Source: /cvs/tuxbox/apps/tuxbox/neutrino/src/driver/genpsi.h,v $
|
||||
Copyright (C) 2012 CoolStream International Ltd
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
@@ -26,13 +23,26 @@ $Id: genpsi.h,v 1.1 2005/08/15 14:47:52 metallica Exp $
|
||||
#define __genpsi_h__
|
||||
#include <inttypes.h>
|
||||
|
||||
int genpsi(int fd2);
|
||||
void transfer_pids(uint16_t pid,uint16_t pidart,short isAC3);
|
||||
|
||||
#define EN_TYPE_VIDEO 0x00
|
||||
#define EN_TYPE_AUDIO 0x01
|
||||
#define EN_TYPE_TELTEX 0x02
|
||||
#define EN_TYPE_PCR 0x03
|
||||
#define EN_TYPE_AVC 0x04
|
||||
|
||||
class CGenPsi
|
||||
{
|
||||
private:
|
||||
short nba;
|
||||
uint16_t vpid;
|
||||
uint8_t vtype;
|
||||
uint16_t apid[10];
|
||||
short atypes[10];
|
||||
static int copy_template(uint8_t *dst, uint8_t *src, int len);
|
||||
uint32_t calc_crc32psi(uint8_t *dst, const uint8_t *src, uint32_t len);
|
||||
|
||||
public:
|
||||
CGenPsi();
|
||||
void addPid(uint16_t pid,uint16_t pidtype, short isAC3);
|
||||
int genpsi(int fd);
|
||||
};
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user