libaribb25.cppをB25Decoder.cppに合わせて変更

This commit is contained in:
epgdatacapbon 2018-03-29 02:38:56 +09:00
parent 38bae51c7f
commit da22adaf99
4 changed files with 46 additions and 68 deletions

View File

@ -5,7 +5,6 @@
#define __B25DECODER_H__
#include <ctime>
#include <cstring>
#include <mutex>
#if defined(_WIN32)
@ -13,7 +12,6 @@
#include "arib_std_b25.h"
#include "arib_std_b25_error_code.h"
#else
#include <stdlib.h>
#include <aribb25/arib_std_b25.h>
#include <aribb25/arib_std_b25_error_code.h>
#include "typedef.h"

View File

@ -1,7 +1,6 @@
// libaribb25.cpp: CB25Decoder クラスのインプリメンテーション
//
//////////////////////////////////////////////////////////////////////
#include "libaribb25.h"
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
@ -45,9 +44,9 @@ __declspec(dllexport) IB25Decoder2 * CreateB25Decoder2()
//////////////////////////////////////////////////////////////////////
// 静的メンバ初期化
CB25Decoder * CB25Decoder::m_pThis = NULL;
CB25Decoder * CB25Decoder::m_pThis = nullptr;
CB25Decoder::CB25Decoder(void) : _bcas(NULL), _b25(NULL), _data(NULL)
CB25Decoder::CB25Decoder(void) : _bcas(nullptr), _b25(nullptr), _data(nullptr)
{
m_pThis = this;
}
@ -57,7 +56,7 @@ CB25Decoder::~CB25Decoder(void)
if (_data)
::free(_data);
_mtx.lock();
std::lock_guard<std::mutex> lock(_mtx);
if (_b25)
_b25->release(_b25);
@ -65,9 +64,7 @@ CB25Decoder::~CB25Decoder(void)
if (_bcas)
_bcas->release(_bcas);
_mtx.unlock();
m_pThis = NULL;
m_pThis = nullptr;
}
void CB25Decoder::Release()
@ -78,16 +75,14 @@ void CB25Decoder::Release()
const BOOL CB25Decoder::Initialize(DWORD dwRound)
{
int ret = FALSE;
_mtx.lock();
std::lock_guard<std::mutex> lock(_mtx);
if (_b25)
goto unlock;
return Reset();
_bcas = create_b_cas_card();
if (!_bcas)
goto unlock;
return FALSE;
if (_bcas->init(_bcas) < 0)
goto err;
@ -99,43 +94,32 @@ const BOOL CB25Decoder::Initialize(DWORD dwRound)
if (_b25->set_b_cas_card(_b25, _bcas) < 0)
goto err;
// success
_b25->set_strip(_b25, 1);
_b25->set_emm_proc(_b25, 0);
_b25->set_multi2_round(_b25, dwRound);
ret = TRUE;
goto unlock;
return TRUE; // success
err:
// error
if (_b25)
{
if (_b25) {
_b25->release(_b25);
_b25 = NULL;
_b25 = nullptr;
}
if (_bcas)
{
if (_bcas) {
_bcas->release(_bcas);
_bcas = NULL;
_bcas = nullptr;
}
_errtime = ::GetTickCount();
unlock:
_mtx.unlock();
return ret;
_errtime = time(nullptr);
return FALSE; // error
}
const BOOL CB25Decoder::Decode(BYTE *pSrcBuf, const DWORD dwSrcSize, BYTE **ppDstBuf, DWORD *pdwDstSize)
{
if (!_b25)
{
DWORD now = ::GetTickCount();
DWORD interval = (now - _errtime) / 1000;
if (interval > RETRY_INTERVAL) {
if (!_b25) {
time_t now = time(nullptr);
if (difftime(now, _errtime) > RETRY_INTERVAL) {
if (Initialize() < 0)
_errtime = now;
}
@ -151,7 +135,7 @@ const BOOL CB25Decoder::Decode(BYTE *pSrcBuf, const DWORD dwSrcSize, BYTE **ppDs
if (_data) {
::free(_data);
_data = NULL;
_data = nullptr;
}
ARIB_STD_B25_BUFFER buf;
@ -162,15 +146,15 @@ const BOOL CB25Decoder::Decode(BYTE *pSrcBuf, const DWORD dwSrcSize, BYTE **ppDs
if (rc >= ARIB_STD_B25_ERROR_NO_ECM_IN_HEAD_32M) {
// pass through
_b25->release(_b25);
_b25 = NULL;
_b25 = nullptr;
_bcas->release(_bcas);
_bcas = NULL;
_bcas = nullptr;
if (*ppDstBuf != pSrcBuf) {
*ppDstBuf = pSrcBuf;
*pdwDstSize = dwSrcSize;
}
} else {
BYTE *p = NULL;
BYTE *p = nullptr;
_b25->withdraw(_b25, &buf); // withdraw src buffer
if (buf.size > 0)
p = (BYTE *)::malloc(buf.size + dwSrcSize);
@ -191,12 +175,12 @@ const BOOL CB25Decoder::Decode(BYTE *pSrcBuf, const DWORD dwSrcSize, BYTE **ppDs
if (rc == ARIB_STD_B25_ERROR_ECM_PROC_FAILURE) {
// pass through
_b25->release(_b25);
_b25 = NULL;
_b25 = nullptr;
_bcas->release(_bcas);
_bcas = NULL;
_bcas = nullptr;
}
}
_errtime = ::GetTickCount();
_errtime = time(nullptr);
return FALSE; // error
}
_b25->get(_b25, &buf);
@ -214,7 +198,7 @@ const BOOL CB25Decoder::Flush(BYTE **ppDstBuf, DWORD *pdwDstSize)
ret = (rc < 0) ? FALSE : TRUE;
}
*ppDstBuf = NULL;
*ppDstBuf = nullptr;
*pdwDstSize = 0;
return ret;

View File

@ -1,10 +1,10 @@
// libaribb25.h: CB25Decoder クラスのインターフェイス
//
//////////////////////////////////////////////////////////////////////
#pragma once
#include <windows.h>
#include <ctime>
#include <mutex>
#include "IB25Decoder.h"
@ -52,5 +52,5 @@ private:
B_CAS_CARD *_bcas;
ARIB_STD_B25 *_b25;
BYTE *_data;
DWORD _errtime;
time_t _errtime;
};

View File

@ -1,7 +1,25 @@
#ifndef PORTABLE_H
#define PORTABLE_H
#if (defined(WIN32) && defined(_MSC_VER) && _MSC_VER < 1800)
#include <stdint.h>
#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)
typedef unsigned char uint8_t;
typedef signed char int8_t;
@ -12,28 +30,6 @@ typedef signed int int32_t;
typedef unsigned __int64 uint64_t;
typedef signed __int64 int64_t;
#else
#include <stdint.h>
#include <inttypes.h>
#endif
#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)
#endif
#endif /* PORTABLE_H */