libaribb25_Linuxと統合
LinuxとWindowsの両方でコンパイルが可能
This commit is contained in:
parent
a488fe5044
commit
2c1f031642
8
Makefile
Normal file
8
Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
all:
|
||||
cd aribb25; make all
|
||||
|
||||
clean:
|
||||
cd aribb25; make clean
|
||||
|
||||
install:
|
||||
cd aribb25; make install
|
@ -143,7 +143,7 @@
|
||||
<Link>
|
||||
<AdditionalDependencies>winscard.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)b25.exe</OutputFile>
|
||||
<GenerateDebugInformation>No</GenerateDebugInformation>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
@ -171,7 +171,7 @@
|
||||
<Link>
|
||||
<AdditionalDependencies>winscard.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)b25.exe</OutputFile>
|
||||
<GenerateDebugInformation>No</GenerateDebugInformation>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
|
@ -9,6 +9,9 @@ int B25Decoder::multi2_round = 4;
|
||||
|
||||
B25Decoder::B25Decoder() : _bcas(nullptr), _b25(nullptr), _data(nullptr)
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
pthread_mutex_init(&_mtx, nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
B25Decoder::~B25Decoder()
|
||||
@ -16,7 +19,11 @@ B25Decoder::~B25Decoder()
|
||||
if (_data)
|
||||
::free(_data);
|
||||
|
||||
std::lock_guard<std::mutex> lock(_mtx);
|
||||
#if defined(_WIN32)
|
||||
_mtx.lock();
|
||||
#else
|
||||
pthread_mutex_lock(&_mtx);
|
||||
#endif
|
||||
|
||||
if (_b25)
|
||||
_b25->release(_b25);
|
||||
@ -24,31 +31,40 @@ B25Decoder::~B25Decoder()
|
||||
if (_bcas)
|
||||
_bcas->release(_bcas);
|
||||
|
||||
char log[64];
|
||||
::wsprintfA(log, "B25Decoder::dtor() : end");
|
||||
::OutputDebugStringA(log);
|
||||
#if defined(_WIN32)
|
||||
_mtx.unlock();
|
||||
#else
|
||||
pthread_mutex_unlock(&_mtx);
|
||||
pthread_mutex_destroy(&_mtx);
|
||||
#endif
|
||||
}
|
||||
|
||||
int B25Decoder::init()
|
||||
{
|
||||
int rc;
|
||||
|
||||
std::lock_guard<std::mutex> lock(_mtx);
|
||||
#if defined(_WIN32)
|
||||
_mtx.lock();;
|
||||
#else
|
||||
pthread_mutex_lock(&_mtx);
|
||||
#endif
|
||||
|
||||
if (_b25)
|
||||
return -2;
|
||||
|
||||
char log[64];
|
||||
{
|
||||
rc = -2;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
_bcas = create_b_cas_card();
|
||||
if (!_bcas)
|
||||
return -3;
|
||||
{
|
||||
rc = -3;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
rc = _bcas->init(_bcas);
|
||||
if (rc < 0)
|
||||
{
|
||||
::wsprintfA(log, "B25Decoder::init() : bcas init error / rc(%d)", rc);
|
||||
::OutputDebugStringA(log);
|
||||
rc = -4;
|
||||
goto err;
|
||||
}
|
||||
@ -66,15 +82,16 @@ int B25Decoder::init()
|
||||
goto err;
|
||||
}
|
||||
|
||||
// success
|
||||
_b25->set_strip(_b25, strip);
|
||||
_b25->set_emm_proc(_b25, emm_proc);
|
||||
_b25->set_multi2_round(_b25, multi2_round);
|
||||
|
||||
::wsprintfA(log, "B25Decoder::init() : success");
|
||||
::OutputDebugStringA(log);
|
||||
return 0; // success
|
||||
rc = 0;
|
||||
goto unlock;
|
||||
|
||||
err:
|
||||
// error
|
||||
if (_b25)
|
||||
{
|
||||
_b25->release(_b25);
|
||||
@ -87,10 +104,19 @@ err:
|
||||
_bcas = nullptr;
|
||||
}
|
||||
|
||||
::wsprintfA(log, "B25Decoder::init() : error / rc(%d)", rc);
|
||||
::OutputDebugStringA(log);
|
||||
#if defined(_WIN32)
|
||||
_errtime = ::GetTickCount();
|
||||
return rc; // error
|
||||
#else
|
||||
clock_gettime(CLOCK_MONOTONIC_COARSE, &_errtime);
|
||||
#endif
|
||||
|
||||
unlock:
|
||||
#if defined(_WIN32)
|
||||
_mtx.unlock();
|
||||
#else
|
||||
pthread_mutex_unlock(&_mtx);
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
|
||||
void B25Decoder::setemm(bool flag)
|
||||
@ -103,8 +129,15 @@ void B25Decoder::decode(BYTE *pSrc, DWORD dwSrcSize, BYTE **ppDst, DWORD *pdwDst
|
||||
{
|
||||
if (!_b25)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
DWORD now = ::GetTickCount();
|
||||
if ((now - _errtime) > RETRY_INTERVAL)
|
||||
DWORD interval = (now - _errtime) / 1000;
|
||||
#else
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC_COARSE, &now);
|
||||
time_t interval = now.tv_sec - _errtime.tv_sec;
|
||||
#endif
|
||||
if (interval > RETRY_INTERVAL)
|
||||
{
|
||||
if (init() < 0)
|
||||
_errtime = now;
|
||||
@ -127,8 +160,6 @@ void B25Decoder::decode(BYTE *pSrc, DWORD dwSrcSize, BYTE **ppDst, DWORD *pdwDst
|
||||
_data = nullptr;
|
||||
}
|
||||
|
||||
char log[64];
|
||||
|
||||
ARIB_STD_B25_BUFFER buf;
|
||||
buf.data = pSrc;
|
||||
buf.size = dwSrcSize;
|
||||
@ -153,11 +184,7 @@ void B25Decoder::decode(BYTE *pSrc, DWORD dwSrcSize, BYTE **ppDst, DWORD *pdwDst
|
||||
BYTE *p = nullptr;
|
||||
_b25->withdraw(_b25, &buf); // withdraw src buffer
|
||||
if (buf.size > 0)
|
||||
{
|
||||
::wsprintfA(log, "B25Decoder::decode() : error / withdraw size(%u)", buf.size);
|
||||
::OutputDebugStringA(log);
|
||||
p = (BYTE *)::malloc(buf.size + dwSrcSize);
|
||||
}
|
||||
|
||||
if (p)
|
||||
{
|
||||
@ -185,9 +212,11 @@ void B25Decoder::decode(BYTE *pSrc, DWORD dwSrcSize, BYTE **ppDst, DWORD *pdwDst
|
||||
_bcas = nullptr;
|
||||
}
|
||||
}
|
||||
::wsprintfA(log, "B25Decoder::decode() : error / rc(%d)", rc);
|
||||
::OutputDebugStringA(log);
|
||||
#if defined(_WIN32)
|
||||
_errtime = ::GetTickCount();
|
||||
#else
|
||||
clock_gettime(CLOCK_MONOTONIC_COARSE, &_errtime);
|
||||
#endif
|
||||
return; // error
|
||||
}
|
||||
_b25->get(_b25, &buf);
|
||||
|
@ -3,12 +3,22 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef __B25DECODER_H__
|
||||
#define __B25DECODER_H__
|
||||
#include <windows.h>
|
||||
#include <mutex>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#include <mutex>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include "portable.h"
|
||||
#include "arib_std_b25.h"
|
||||
#include "arib_std_b25_error_code.h"
|
||||
|
||||
#define RETRY_INTERVAL 10000 // 10sec interval
|
||||
#define RETRY_INTERVAL 10 // 10sec interval
|
||||
|
||||
class B25Decoder
|
||||
{
|
||||
@ -31,11 +41,19 @@ public:
|
||||
static int multi2_round;
|
||||
|
||||
private:
|
||||
#if defined(_WIN32)
|
||||
std::mutex _mtx;
|
||||
#else
|
||||
pthread_mutex_t _mtx;
|
||||
#endif
|
||||
B_CAS_CARD *_bcas;
|
||||
ARIB_STD_B25 *_b25;
|
||||
BYTE *_data;
|
||||
#if defined(_WIN32)
|
||||
DWORD _errtime;
|
||||
#else
|
||||
struct timespec _errtime;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // __B25DECODER_H__
|
||||
|
53
aribb25/Makefile
Normal file
53
aribb25/Makefile
Normal file
@ -0,0 +1,53 @@
|
||||
PREFIX = /usr/local
|
||||
MAJOR = 0
|
||||
MINOR = 2
|
||||
REVISION = 5
|
||||
VER = $(MAJOR).$(MINOR).$(REVISION)
|
||||
|
||||
DEST_HEADER = $(PREFIX)/include/aribb25
|
||||
|
||||
# PC/SC Lite libraries and headers.
|
||||
PCSC_CFLAGS ?= `pkg-config libpcsclite --cflags`
|
||||
PCSC_LDLIBS ?= `pkg-config libpcsclite --libs`
|
||||
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
CFLAGS = -O2 -g -fPIC -Wall $(PCSC_CFLAGS) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
|
||||
|
||||
LIBS = $(PCSC_LDLIBS) -lm
|
||||
LDFLAGS =
|
||||
|
||||
OBJS = arib_std_b25.o b_cas_card.o multi2.o ts_section_parser.o
|
||||
HEADERS = arib_std_b25.h arib_std_b25_error_code.h b_cas_card.h portable.h
|
||||
TARGET_APP = b25
|
||||
TARGET_LIB = libaribb25.so
|
||||
TARGETS = $(TARGET_APP) $(TARGET_LIB)
|
||||
DEPEND = Makefile.dep
|
||||
SONAME = $(TARGET_LIB).$(MAJOR)
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) td.o $(TARGETS) $(DEPEND)
|
||||
|
||||
$(TARGET_APP): $(OBJS) td.o
|
||||
$(CXX) $(LDFLAGS) -o $(TARGET_APP) $(OBJS) td.o $(LIBS)
|
||||
|
||||
$(TARGET_LIB): $(OBJS)
|
||||
$(CXX) $(LDFLAGS) -shared -o $(TARGET_LIB) $(OBJS) $(LIBS) -Wl,-soname,$(SONAME)
|
||||
|
||||
$(DEPEND):
|
||||
$(CC) -fPIC -MM $(OBJS:.o=.c) td.c > $@
|
||||
|
||||
install: $(TARGET) install-headers
|
||||
install -m755 b25 $(PREFIX)/bin
|
||||
install -m755 $(TARGET_LIB) $(PREFIX)/lib/$(TARGET_LIB).$(VER)
|
||||
ln -sf $(PREFIX)/lib/$(TARGET_LIB).$(VER) $(PREFIX)/lib/$(TARGET_LIB).$(MAJOR)
|
||||
ln -sf $(PREFIX)/lib/$(TARGET_LIB).$(MAJOR) $(PREFIX)/lib/$(TARGET_LIB)
|
||||
ldconfig
|
||||
|
||||
install-headers:
|
||||
mkdir -p $(DEST_HEADER)
|
||||
install -m644 $(HEADERS) $(DEST_HEADER)
|
||||
|
||||
-include $(DEPEND)
|
@ -2005,24 +2005,6 @@ static int proc_ecm(DECRYPTOR_ELEM *dec, B_CAS_CARD *bcas, int32_t multi2_round)
|
||||
|
||||
dec->m2->set_scramble_key(dec->m2, res.scramble_key);
|
||||
|
||||
#if 0
|
||||
if (0){
|
||||
int i;
|
||||
fprintf(stdout, "----\n");
|
||||
fprintf(stdout, "odd: ");
|
||||
for(i=0;i<8;i++){
|
||||
fprintf(stdout, " %02x", res.scramble_key[i]);
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
fprintf(stdout, "even:");
|
||||
for(i=8;i<16;i++){
|
||||
fprintf(stdout, " %02x", res.scramble_key[i]);
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
LAST:
|
||||
if(sect.raw != NULL){
|
||||
n = dec->ecm->ret(dec->ecm, §);
|
||||
@ -2034,44 +2016,6 @@ LAST:
|
||||
return r;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void dump_pts(uint8_t *src, int32_t crypt)
|
||||
{
|
||||
int32_t pts_dts_flag;
|
||||
int64_t pts,dts;
|
||||
|
||||
src += 4; // TS header
|
||||
src += 4; // start_code_prefix + stream_id
|
||||
src += 2; // packet_length
|
||||
|
||||
pts_dts_flag = (src[1] >> 6) & 3;
|
||||
|
||||
src += 3;
|
||||
if(pts_dts_flag & 2){
|
||||
// PTS
|
||||
pts = (src[0] >> 1) & 0x07;
|
||||
pts <<= 15;
|
||||
pts += ((src[1] << 8) + src[2]) >> 1;
|
||||
pts <<= 15;
|
||||
pts += ((src[3] << 8) + src[4]) >> 1;
|
||||
src += 5;
|
||||
}
|
||||
if(pts_dts_flag & 1){
|
||||
// DTS
|
||||
dts = (src[0] >> 1) & 0x07;
|
||||
dts <<= 15;
|
||||
dts += ((src[1] << 8) + src[2]) >> 1;
|
||||
dts <<= 15;
|
||||
dts += ((src[3] << 8) + src[4]) >> 1;
|
||||
}
|
||||
|
||||
if(pts_dts_flag == 2){
|
||||
fprintf(stdout, " key=%d, pts=%"PRId64"\n", crypt, pts/90);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv)
|
||||
{
|
||||
int r;
|
||||
@ -2176,11 +2120,7 @@ static int proc_arib_std_b25(ARIB_STD_B25_PRIVATE_DATA *prv)
|
||||
}else{
|
||||
prv->map[pid].normal_packet += 1;
|
||||
}
|
||||
#if 0
|
||||
if( (hdr.payload_unit_start_indicator != 0) && (pid == 0x111) ){
|
||||
dump_pts(curr, crypt);
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!append_work_buffer(&(prv->dbuf), curr, unit)){
|
||||
return ARIB_STD_B25_ERROR_NO_ENOUGH_MEMORY;
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
#include "b_cas_card.h"
|
||||
#include "b_cas_card_error_code.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <winscard.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
inner structures
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
@ -263,17 +262,7 @@ static int get_id_b_cas_card(void *bcas, B_CAS_ID *dst)
|
||||
return B_CAS_CARD_ERROR_TRANSMIT_FAILED;
|
||||
}
|
||||
|
||||
{
|
||||
int maker_id;
|
||||
int version;
|
||||
int check_code;
|
||||
|
||||
maker_id = p[0];
|
||||
version = p[1];
|
||||
prv->id.data[i] = load_be_uint48(p+2);
|
||||
check_code = load_be_uint16(p+8);
|
||||
}
|
||||
|
||||
prv->id.data[i] = load_be_uint48(p+2);
|
||||
p += 10;
|
||||
}
|
||||
|
||||
|
@ -3,4 +3,33 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#define _open open
|
||||
#define _close close
|
||||
#define _read read
|
||||
#define _write write
|
||||
#define _lseeki64 lseek
|
||||
#define _telli64(fd) (lseek(fd,0,SEEK_CUR))
|
||||
#define _O_BINARY (0)
|
||||
#define _O_RDONLY (O_RDONLY)
|
||||
#define _O_WRONLY (O_WRONLY)
|
||||
#define _O_SEQUENTIAL (0)
|
||||
#define _O_CREAT (O_CREAT)
|
||||
#define _O_TRUNC (O_TRUNC)
|
||||
#define _S_IREAD (S_IRUSR|S_IRGRP|S_IROTH)
|
||||
#define _S_IWRITE (S_IWUSR|S_IWGRP|S_IWOTH)
|
||||
#define _S_IWRITE (S_IWUSR|S_IWGRP|S_IWOTH)
|
||||
#define _tcslen strlen
|
||||
#define __inline inline
|
||||
#define __forceinline inline
|
||||
typedef unsigned long DWORD;
|
||||
typedef char TCHAR;
|
||||
typedef char *LPTSTR;
|
||||
typedef const char *LPCTSTR;
|
||||
#endif
|
||||
|
||||
#if !defined(nullptr)
|
||||
#define nullptr NULL
|
||||
#endif
|
||||
|
||||
#endif /* PORTABLE_H */
|
||||
|
23
aribb25/td.c
23
aribb25/td.c
@ -1,16 +1,15 @@
|
||||
#if defined(WIN32)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#if defined(_WIN32)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#include <crtdbg.h>
|
||||
@ -42,7 +41,7 @@ int main(int argc, char **argv)
|
||||
int n;
|
||||
OPTION opt;
|
||||
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
|
||||
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
|
||||
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
|
||||
@ -62,7 +61,7 @@ int main(int argc, char **argv)
|
||||
test_arib_std_b25(argv[n+0], argv[n+1], &opt);
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
_CrtDumpMemoryLeaks();
|
||||
#endif
|
||||
|
||||
@ -159,9 +158,9 @@ static void test_arib_std_b25(const char *src, const char *dst, OPTION *opt)
|
||||
int code,i,n,m;
|
||||
int sfd,dfd;
|
||||
|
||||
uint32_t offset;
|
||||
int64_t total;
|
||||
int64_t offset;
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
unsigned long tick,tock;
|
||||
#else
|
||||
struct timeval tick,tock;
|
||||
@ -243,7 +242,7 @@ static void test_arib_std_b25(const char *src, const char *dst, OPTION *opt)
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
tock = GetTickCount();
|
||||
#else
|
||||
gettimeofday(&tock, NULL);
|
||||
@ -276,7 +275,7 @@ static void test_arib_std_b25(const char *src, const char *dst, OPTION *opt)
|
||||
if(opt->verbose != 0){
|
||||
m = (int)(10000*offset/total);
|
||||
mbps = 0.0;
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
tick = GetTickCount();
|
||||
if (tick-tock > 100) {
|
||||
mbps = offset;
|
||||
@ -319,7 +318,7 @@ static void test_arib_std_b25(const char *src, const char *dst, OPTION *opt)
|
||||
|
||||
if(opt->verbose != 0){
|
||||
mbps = 0.0;
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
tick = GetTickCount();
|
||||
if (tick-tock > 100) {
|
||||
mbps = offset;
|
||||
@ -357,7 +356,7 @@ static void test_arib_std_b25(const char *src, const char *dst, OPTION *opt)
|
||||
fprintf(stderr, " channel: %d\n", pgrm.program_number);
|
||||
fprintf(stderr, " unpurchased ECM count: %d\n", pgrm.ecm_unpurchased_count);
|
||||
fprintf(stderr, " last ECM error code: %04x\n", pgrm.last_ecm_error_code);
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
fprintf(stderr, " undecrypted TS packet: %I64d\n", pgrm.undecrypted_packet_count);
|
||||
fprintf(stderr, " total TS packet: %I64d\n", pgrm.total_packet_count);
|
||||
#else
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef TS_SECTION_PARSER_ERROR_CODE_H
|
||||
#define TS_SECTION_PARESR_ERROR_CODE_H
|
||||
#define TS_SECTION_PARSER_ERROR_CODE_H
|
||||
|
||||
#define TS_SECTION_PARSER_ERROR_INVALID_PARAM -1
|
||||
#define TS_SECTION_PARSER_ERROR_NO_ENOUGH_MEMORY -2
|
||||
|
Loading…
x
Reference in New Issue
Block a user