Home » Source Code » PMCAM2_2.50_Delphi_Source_Code » UTS184ToBitFilter.pas

UTS184ToBitFilter.pas ( File view )

  • By sathex 2016-03-20
  • View(s):0
  • Download(s):0
  • Point(s): 1
			unit UTS184ToBitFilter;

interface

Uses Windows,SysUtils,Unit_CRC32,Classes,uBitManager;

type eTS184ToBitFilterParseMode=(eTS184_DVB_184Packet,eTS184_DVB_188Packet,eTS184_DVB_BitFilter,eTS184_DVB_BitFilter_Text,eTS184_DVB_PES);

type TPESInformation=record
    StreamID: BYTE;
    PacketLen: DWORD;
    Scrambling: BYTE;
    Priority: Boolean;
    DataAlignementIndicator: Boolean;
    Copyright: Boolean;
    Original: Boolean;
    PTS_DTS_Flags: BYTE;
    ESCR_Present: Boolean;
    ES_Rate_Present: Boolean;
    DSM_Trick_Mode_Present: Boolean;
    Additional_CopyInfo_Present: Boolean;
    CRC_Present: Boolean;
    Extension_Present: Boolean;
    HeaderDataLength: BYTE;
    PTS: array [0..4] of BYTE;
    DTS: array [0..4] of BYTE;
    ESCR: array [0..5] of BYTE;
    ES_Rate: DWORD;
    DSM_TrickMode: BYTE;
    PayloadStart: WORD;
    PayloadSize: WORD;
end;

type PPESInformation=^TPESInformation;

type TTS184ToBitFilter=Class(TObject)
  Private
    function CalculateTS184TableSize(P: PBYTEARRAY;index: DWORD): DWORD;
    Function FillTableFromHere(P: PBYTEARRAY;var Index: DWORD): Boolean;
    Function FillTableFromHere_2(P: PBYTEARRAY;var Index: DWORD): Boolean;
    function GetProcessedData: DWORD;
    Function GetFFsEndToBegin(P: PBYTEARRAY;index: DWORD): DWORD;
  Protected
    mvarPESLastScanPoint: DWORD;
    mvarCRCTest: Boolean;
    mvarDataInBuffer: DWORD;
    mvarBufferSize: DWORD;
    mvarOffSet: DWORD;
    mvarBuffer: PBYTEARRAY;
    mvarProcessedData: DWORD;
    mvarBitFilterBuffer: array [0..4095] of byte;
    mvarBitFilterSize: DWORD;
    mvarValidTablesHelper: array [0..63] of byte;
    mvarValidTablesHelperCounter: integer;
    mvarBuffering: DWORD;
    mvarMODE: eTS184ToBitFilterParseMode;
    mvarMAXBufferSize: DWORD;
    mvarMAXTableSize: DWORD;
    mvarBufferMustBeResetted: Boolean;
    mvarStream: TStream;
    mvarPES: TPESInformation;
    mvarPESIsElementaryVideo: Boolean;
    mvarRecurseCheckDeep: DWORD;
    mvarLimitReachedInside: Boolean;
    function GetTableLen(P: PBYTEARRAY; Position: DWORD): DWORD;
    function CheckValidTable(P: PBYTEARRAY; i: DWORD): Boolean;
    function CheckContinuity(P: PBYTEARRAY; i: DWORD): Boolean;
    function CheckNextTable(P: PBYTEARRAY; i: DWORD): Boolean;
    function TestTable184(P: PBYTEARRAY; Position: DWORD;Limit: DWORD;Recurse: DWORD): Boolean;
    function FillNextBitFilter184(): Boolean;
    function FillNextBitFilter184_2(): Boolean; //Test only
    function FillNextBitFilter188(): Boolean;
    function FillNextBitFilterBitFilter(): Boolean;
    function FillNextBitFilterBitFilterText(): Boolean;
    function FillNextBitFilterPES(): Boolean;
    function getPESInformation(): PPESInformation;
    Function CheckElementaryStreamLoaded(StartOffSet: DWORD; Limit: DWORD): DWORD;
  Public
    property MAXTableSize: DWORD read mvarMAXTableSize write mvarMAXTableSize;
    property TotalProcessedData: DWORD read GetProcessedData;
    property CRCCheck: Boolean read mvarCRCTest write mvarCRCTest;
    property Buffering: DWORD read mvarBuffering write mvarBuffering;
    property CurrentDataInBuffer: DWORD read mvarDataInBuffer;
    property Mode: eTS184ToBitFilterParseMode read mvarMode write mvarMode;
    property PESInformation: PPESInformation read getPESInformation;

    function AddToBuffer(Buffer: Pointer;Len: DWORD): Boolean;
    function FillNextBitFilter(): Boolean;
    procedure GetBitFilter(var Buffer: Pointer; var Len: DWORD);
    procedure GetBitFilterPESPayloadOnly(var Buffer: Pointer; var Len: DWORD);
    procedure BufferReset;
    function MatchBitFilter(FilterData: PBYTEARRAY; FilterMask: PBYTEARRAY; Len: integer): Boolean;
    function CheckCRCTable(Table: Pointer;Len: DWORD): Boolean;
    procedure SetValidTablesHelper(ValidTables: Array of Byte; Len: integer);
    procedure ReadFromStream(Stream: TStream);
    function SubmitFromStream: Boolean;
    function PTS_DTS_To_Int64(PTS_DTS_Field: Pointer): int64;

    constructor Create;
    Destructor Destroy; override;
end;

implementation

{
 TTS184ToBitFilter 
}

var HexSet : Set of char = ['0'..'9','A'..'F','a'..'f'];

constructor TTS184ToBitFilter.Create;
begin
    mvarBuffer:=nil;
    mvarValidTablesHelperCounter:=0;
    mvarCRCTest:=true;
    mvarBuffering:=8192;
    Mode:=eTS184_DVB_184Packet; //default mode
    mvarMAXBufferSize:=$FFFFFFFF; //"unlimited"..
    mvarMAXTableSize:=4095;
    mvarStream:=nil;
    mvarRecurseCheckDeep:=2;
    mvarLimitReachedInside:=false;
    mvarPESIsElementaryVideo:=false;
    BufferReset;
end;

destructor TTS184ToBitFilter.Destroy;
begin
    if Assigned(mvarBuffer) Then begin
        FreeMem(mvarBuffer);
        mvarBuffer:=nil;
    end;
  inherited;
end;

function TTS184ToBitFilter.AddToBuffer(Buffer: Pointer;
  Len: DWORD): Boolean;
var
    NewPos: DWORD;
begin
    if ((mvarDataInBuffer+Len+184)> mvarMAXBufferSize) Then begin
        mvarBufferMustBeResetted:=true;
    end;
    if mvarBufferMustBeResetted Then begin
        Result:=false;
        Exit;
    end;
    if (mvarDataInBuffer+Len+184)>=mvarBufferSize Then begin
        //Try to make room
        if mvarDataInBuffer>368 Then begin
            if mvarMODE<>eTS184_DVB_PES Then begin
                NewPos:=mvarOffSet mod 184;
            end else begin
                NewPos:=0;
            end;
            move(Pointer(@mvarBuffer[mvarOffset])^,Pointer(@mvarBuffer[NewPos])^,mvarDataInBuffer-mvarOffSet);
            mvarDataInBuffer:=mvarDataInBuffer-mvarOffSet+NewPos;
            inc(mvarProcessedData,mvarOffSet-NewPos);
            mvarOffSet:=NewPos;
        end;
    end;
    if (mvarDataInBuffer+Len)>=mvarBufferSize Then begin
        //Try to make room reallocating buffer size
        ReallocMem(Pointer(mvarBuffer),mvarDataInBuffer+Len+184000);
        mvarBufferSize:=mvarDataInBuffer+Len+184000;
    end;
    move(Buffer^,Pointer(@mvarBuffer[mvarDataInBuffer])^,Len);
    inc(mvarDataInBuffer,Len);
    Result:=true;
end;

function TTS184ToBitFilter.FillNextBitFilter: Boolean;
begin
    case Mode of
        eTS184_DVB_184Packet: Result:=FillNextBitFilter184_2(); //Use old method...
        eTS184_DVB_188Packet: Result:=FillNextBitFilter188();
        eTS184_DVB_BitFilter: Result:=FillNextBitFilterBitFilter();
        eTS184_DVB_BitFilter_Text: Result:=FillNextBitFilterBitFilterText();
        eTS184_DVB_PES: Result:=FillNextBitFilterPES();
        else
            Assert(false,'Unsupported Mode');
            Result:=false;
    end;
end;

function TTS184ToBitFilter.GetTableLen(P: PBYTEARRAY; Position: DWORD): DWORD;
begin
    Result:=(((P[Position+1] and $0F) shl 8) or P[Position+2])+3;
end;

function TTS184ToBitFilter.TestTable184(P: PBYTEARRAY; Position: DWORD;Limit: DWORD; Recurse: DWORD): Boolean;
var
    TableOffSet: DWORD;
    TargetPos: DWORD;
    i: DWORD;
    Flag: Boolean;
    TestPos: DWORD;
begin
    if Recurse>mvarRecurseCheckDeep Then begin
        Result:=true;
        Exit;
    end;
    Result:=false; //Default value...
    if (Position Mod 184) = 0 Then begin
        //Process located at a 184 byte boundary. Check for
        //init table. First byte could be a table offset indicator.
        TableOffSet:=P[Position];
        TestPos:=Position+TableOffSet+1;
        if TestPos<Limit Then begin
            //Test against valid tables...
            if TestTable184(P,TestPos,Limit,Recurse) Then begin
                mvarOffset:=TestPos; //Forces object to parse from here
                Result:=true;
            end;
        end else begin
            If Recurse>0 Then begin
                mvarLimitReachedInside:=true;
                Exit;
            end;
        end;
    end else if P[Position]=$FF Then begin
        //Maybe a padding table :-? Check for skip repeated $FF up to the next
        //184 byte boundary...
        i:=Position mod 184;
        TargetPos:=Position+184-i; //Next 184 byte boundary.
        if TargetPos<=Limit Then begin
            Flag:=true;
            for i := Position to TargetPos-1 do begin
                if P[i]<>$FF Then begin
                    Flag:=False;
                    Break;
                end;
            end;
            if Flag Then begin
                Position:=i;
                Result:=TestTable184(P,Position,Limit,Recurse);
            end;
        end else begin
            If Recurse>0 Then begin
                mvarLimitReachedInside:=true;
                Exit;
            end;
        end;
    end else if mvarValidTablesHelperCounter>0 Then begin
        If CheckValidTable(P,Position) Then begin
            TestPos:=Position+CalculateTS184TableSize(P,Position);
            if TestPos<Limit Then begin //No transverse bounds.
                if TestTable184(P,TestPos,Limit,Recurse+1)=true Then begin
                    mvarOffSet:=Position;
                    Result:=true;
                end;
            end else begin
                If Recurse>0 Then begin
                    mvarLimitReachedInside:=true;
                    Exit;
                end;
            end;
        end;
    end else if mvarCRCTest Then begin
        i:=CalculateTS184TableSize(P,Position);
        TestPos:=Position+i;
        if TestPos<=Limit Then begin
            TestPos:=Position;
            FillTableFromHere_2(P,TestPos);
            if CheckCRCTable(mvarBuffer,mvarBitFilterSize) Then begin
                mvarOffSet:=Position;
                Result:=true;
            end else begin
                mvarBitFilterSize:=0;
            end;
        end else begin
            If Recurse>0 Then begin
                mvarLimitReachedInside:=true;
                Exit;
            end;
        end;
    end;
end;

function TTS184ToBitFilter.FillNextBitFilter184: Boolean;
var
    Limit: DWORD;
    Position: DWORD;
    P: PBYTEARRAY;
    TestPos: DWORD;
begin
    Limit:=mvarDataInBuffer;
    if Limit<mvarBuffering Then begin
        Result:=False;
        Exit;
    end;
    Position:=mvarOffSet;
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
About.rtf20.49 kB2005-03-15|17:16
changelog.txt4.26 kB2005-03-15|17:16
clean.bat92.00 B2005-01-05|02:35
DVBCore.pas31.98 kB2004-12-17|23:45
frmPPVInfo.dfm15.69 kB2004-12-19|19:54
frmPPVInfo.pas6.17 kB2005-03-03|01:02
01.96 kB
About.bmp3.05 kB2004-12-17|23:52
About.ico2.40 kB2004-12-17|23:52
Add.bmp1.30 kB2004-12-17|23:52
bluenote.ico7.23 kB2004-12-17|23:52
bug.jpg6.04 kB2005-01-05|02:35
CAM.ico2.40 kB2004-12-17|23:52
Close.bmp3.05 kB2004-12-17|23:52
EPG.bmp1.05 kB2005-01-05|21:10
EPG.ico1.37 kB2004-12-17|23:52
EPGOFF.bmp1.62 kB2004-12-17|23:52
EPGON.bmp1.62 kB2004-12-17|23:52
EPG_Gliph.bmp3.43 kB2004-12-17|23:52
Event.ico1.37 kB2004-12-17|23:52
jetons.ico1.37 kB2004-12-17|23:52
leftLogo.bmp9.96 kB2004-12-17|23:52
logger.ico1.68 kB2004-12-17|23:52
MagicWand.bmp1.30 kB2004-12-17|23:52
MagicWand.ico1.37 kB2004-12-17|23:52
MAS.ico1.37 kB2004-12-17|23:52
MENOS.ico1.37 kB2004-12-17|23:52
nemesis.ico4.19 kB2004-12-17|23:52
Phoenix.ico1.72 kB2004-12-17|23:52
Provider.ico1.37 kB2004-12-17|23:52
Remove.bmp1.30 kB2004-12-17|23:52
Reset.bmp3.05 kB2004-12-17|23:52
Restart.bmp1.30 kB2004-12-17|23:52
Save.bmp2.05 kB2004-12-17|23:52
scriptengine.ico7.23 kB2004-12-17|23:52
ScriptsEngine.bmp6.80 kB2004-12-17|23:52
Tools.bmp246.00 B2004-12-17|23:52
tuxprogramming.jpg4.15 kB2005-01-13|19:01
V9Card.jpg11.00 kB2005-03-03|01:02
IFSI_IniFiles.pas10.45 kB2004-12-19|19:54
MpgLib.DLL141.50 kB2004-12-24|17:03
PMCAM0.00 B2005-03-15|17:18
PMCAM4.67 kB2005-01-05|17:24
PMCAM4.69 kB2005-01-05|17:24
PMCAM4.52 kB2005-01-05|17:24
PMCAM.rc3.60 kB2004-12-17|23:47
PMCAM2.dpr6.30 kB2005-03-11|20:15
PMCAM2.res1.70 kB2005-03-15|17:16
PMCAM2StandAlone.dpr1.19 kB2005-03-03|01:02
PMCAM2StandAlone.res4.95 kB2005-03-11|20:15
PMCAMMenu.rc259.00 B2004-12-26|20:10
PMCAMMenu.RES162.25 kB2005-03-15|17:16
rUPClickSplitter.res740.00 B2004-12-19|19:54
santa_rock.jpg5.65 kB2004-12-24|17:59
UBitManager.pas4.18 kB2004-12-17|23:45
uDecode123.pas4.01 kB2004-12-29|01:33
UDVBConditionalAccessSystemNames.pas1.49 kB2004-12-17|23:45
UDVBCoreToMD.pas4.59 kB2004-12-17|23:45
UDVBPIDNames.pas1.23 kB2004-12-17|23:45
UDVBTablesHolder.pas2.68 kB2004-12-28|02:17
UEPGEntry.pas3.29 kB2004-12-17|23:45
UEPGMHW.dfm7.72 kB2005-01-11|02:38
UEPGMHW.pas40.85 kB2005-01-11|02:38
UfrmAddFilter.dfm6.86 kB2004-12-17|23:46
UfrmAddFilter.pas3.68 kB2004-12-17|23:45
UfrmCAM.dfm217.00 kB2005-03-15|03:22
UfrmCAM.pas159.37 kB2005-03-15|17:16
ufrmDLLForm.dfm420.00 B2004-12-19|19:54
ufrmDLLForm.pas1.87 kB2004-12-26|20:10
UfrmEMM.dfm1.28 kB2004-12-17|23:46
UfrmEMM.pas1.47 kB2004-12-17|23:45
UfrmEPGAdvanced.dfm7.01 kB2005-01-05|21:10
UfrmEPGAdvanced.pas2.56 kB2005-01-05|21:10
UfrmMHWEPGEntries.dfm3.81 kB2004-12-17|23:46
UfrmMHWEPGEntries.pas4.33 kB2004-12-17|23:45
ufrmMHWRadio.dfm35.85 kB2005-01-21|18:53
ufrmMHWRadio.pas37.84 kB2005-01-21|18:53
UfrmPMTDetails.dfm2.31 kB2005-01-21|18:53
UfrmPMTDetails.pas2.74 kB2005-01-21|18:53
UfrmWarningOnExit.dfm15.64 kB2005-01-05|21:10
UfrmWarningOnExit.pas1.44 kB2005-01-05|21:10
ULogEngine.pas15.89 kB2005-03-12|17:11
UMDDefs.pas4.07 kB2005-03-03|01:02
UMD_Impl.pas11.26 kB2005-03-03|01:02
United32.pas14.20 kB2004-12-17|23:45
UnitISO639_3.pas10.04 kB2005-03-03|01:02
UnitMDInterface.pas28.92 kB2005-03-15|03:22
UnitTimer.pas1.39 kB2004-12-17|23:45
Unit_CRC32.pas3.62 kB2004-12-17|23:45
uPESToTS.pas6.11 kB2005-03-03|01:02
UScriptFunctions.pas2.97 kB2005-01-03|16:45
UScriptsEditor.dfm58.10 kB2005-01-21|18:53
UScriptsEditor.pas22.02 kB2005-03-03|01:02
USECAManager.pas18.26 kB2005-03-03|01:02
USECATableStore.pas12.92 kB2004-12-17|23:45
USECA_EMM.pas7.74 kB2005-03-12|03:36
USmartCardISO.pas14.45 kB2004-12-17|23:45
UTfrmMultiDec.dfm407.00 B2005-01-21|18:53
UTfrmMultiDec.pas4.38 kB2005-01-21|18:53
UTranslate.pas6.49 kB2004-12-24|17:03
UTS184ToBitFilter.pas36.28 kB2005-03-11|20:15
uUPClickSplitter.dcr488.00 B2004-12-19|19:54
uUPClickSplitter.dcu18.09 kB2005-03-03|01:02
uUPClickSplitter.pas20.43 kB2004-12-26|20:10
PMCAM2_2.50.zip870.87 kB2016-03-19|22:08
...
Sponsored links

UTS184ToBitFilter.pas (1.30 MB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D