Callback trouble!!
From: Erik Brännlund (erik.brannlund_nospam__at_epl.ericsson.se)
Date: 06/22/04
- Next message: Maarten Wiltink: "Re: Question on Free and Nil"
- Previous message: Joachim Marder marder a jam - software.com.remove: "IMalloc.Alloc() not working in Delphi 8"
- Next in thread: Billw: "Re: Callback trouble!!"
- Reply: Billw: "Re: Callback trouble!!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 22 Jun 2004 14:27:55 GMT
Hi!
I have made an application showing TV from my DVB card. I also try to extract
the subtitling. I do this by making a callback function and telling th
directshow filter what PID I want and the callback function.
Callback function
Procedure Test(pTsp : PByteArray);safecall;
begin
Form1.ProcessSubtitle(pTsp);
Form1.Panel1.Caption := 'End';
end;
Specifiyng callback
m_pfSource.DvbSource.AddPidFilter(@Test, 1015);
Class to extract bits from stream
Constructor TBitExtractor.Create;
begin
BitPos := 0;
end;
Function TBitExtractor.GetBits(I : Integer; Data : PByteArray):LongWord;
var
Byp, Bip : Integer;
begin
Result := 0;
While I > 0 do
begin
Result := Result shl 1;
Byp := BitPos div 8;
Bip := BitPos mod 8;
Result := Result or ((Data^[Byp] shr (7 - Bip)) and 1);
BitPos := BitPos + 1;
Dec(I);
end;
end;
Function TBitExtractor.CheckBits(I : Integer; Data : PByteArray):LongWord;
var
Byp, Bip : Integer;
TmpPos : LongInt;
begin
TmpPos := BitPos;
Result := 0;
While I < 0 do
begin
Result := Result shl 1;
Byp := TmpPos div 8;
Bip := TmpPos mod 8;
Result := Result or (Data^[Byp] shr (7 - Bip));
TmpPos := TmpPos + 1;
end;
end;
Subtitle extraction code or at least the beginning of it
Procedure TForm1.ProcessSubtitle(pTsp : PByteArray);
var
I : Integer;
Be : TBitExtractor;
ts : TSPacket;
begin
Be := TBitExtractor.Create;
Form1.Panel1.Caption := 'Called 1'; // This updates the Panel
ts.Sync := Be.GetBits(8, pTsp);
Form1.Panel1.Caption := 'Called 2'; //This doesn't eupdate the panel
ts.trans_error_ind := Be.GetBits(1, pTsp);
ts.payload_start := Be.GetBits(1, pTsp);
ts.transportprio := Be.GetBits(1, pTsp);
ts.PID := Be.GetBits(13, pTsp);
ts.ts_scramble_control := Be.GetBits(2, pTsp);
ts.adaption_control := Be.GetBits(2, pTsp);
ts.cont_count := Be.GetBits(4, pTsp);
Be.Free;
end;
I declared the functions as (var pTsp : Array of Byte) and the stream was
decoded but the prg crashed upon exit from "Test". Now the application don't
crash, at least not immediately, but the strem dont get decoded.
Any suggestions?
P.S
As long as I skip this subtitle stream the "TV" works just fine.
D.S
/Erik
- Next message: Maarten Wiltink: "Re: Question on Free and Nil"
- Previous message: Joachim Marder marder a jam - software.com.remove: "IMalloc.Alloc() not working in Delphi 8"
- Next in thread: Billw: "Re: Callback trouble!!"
- Reply: Billw: "Re: Callback trouble!!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]