C++中的代码,这个是在主线程中创建的子线程,分数可能少了点,但已经是我所有的分数了,希望大家能帮忙!DWORD dw;
m_hThread=NULL;
m_hEventInput=NULL;
m_hEventKill=NULL;m_hThread= CreateThread(NULL,0, LPTHREAD_START_ROUTINE (InputData),this,0,&dw);
m_hEventInput= CreateEvent(NULL,TRUE,FALSE,NULL);
m_hEventKill= CreateEvent(NULL,FALSE,FALSE,NULL);////////////////////////////////////////////////////////#define BUF_SIZE 4096
DWORD WINAPI InputData(LPVOID lpParameter)
{
CPlayerDlg* pOwner=(CPlayerDlg*)lpParameter;
HANDLE hMulEvents[2];
hMulEvents[0]=pOwner->m_hEventKill;
hMulEvents[1]=pOwner->m_hEventInput;
BYTE pBuf[BUF_SIZE];
DWORD nRealRead;
BOOL bBufFull=FALSE;
while(WAIT_OBJECT_0!=WaitForMultipleObjects(2,hMulEvents,FALSE,INFINITE))
{
if(!bBufFull)
{
if(!(ReadFile(pOwner->m_hStreamFile,pBuf,BUF_SIZE,&nRealRead,NULL)&&nRealRead==BUF_SIZE))
{
bBufFull=FALSE;
ResetEvent(pOwner->m_hEventInput);
}
}
if(!InputData(PORT,pBuf,BUF_SIZE))//送数据到缓冲的一个函数
{
bBufFull=TRUE;
ResetEvent(pOwner->m_hEventInput);
}
else
bBufFull=FALSE;
}
return 1;
}以上代码我想转成delphi形式,因为代码较多,所以只把相关的主要部分提了出来,如果大家觉得不够,我可以再贴其他的上来
unit T_Play;
interface
uses
Windows, Classes, SysUtils, ExtCtrls, StdCtrls, Variants, U_MPG4_REPLAY_API;
type
TThreadPlay = class(TThread)
private
//Global
fOwner: TComponent;
fPort: integer;
fhFile: HWND;
fHeadSize: DWORD;
fbFileEnd: Boolean;
//Event
fhEventInPut: THandle;
fhEventKill : THandle;
public
constructor Create(AOwner: TComponent);
protected
procedure Execute; override;
end;
implementation
{ TThreadPlay }
constructor TThreadPlay.Create(AOwner: TComponent);
begin
inherited Create(True);
FOwner:= AOwner;
fhEventInPut:= CreateEvent(nil, True, False, nil);
fhEventKill := CreateEvent(nil, FALSE,FALSE, nil);
end;
//文件头在别的地方读取,读取没有问题,读取完毕后Resume线程
procedure TThreadPlay.Execute;
var
EventHandles: array of THandle;
EventCount: Integer;
Buf: array of Byte;
BufSize: Integer;
bBufFull: Boolean;
nRealRead: DWORD;
begin
if fbExit then Exit;
begin
EventCount:= 2;
SetLength(EventHandles, EventCount);
EventHandles[0]:= fhEventInPut;
EventHandles[1]:= fhEventKill;
BufSize:= 4096;
SetLength(Buf, BufSize);
bBufFull:= False;
nRealRead:= 0; while(WAIT_OBJECT_0 <> WaitForMultipleObjects(EventCount,@EventHandles[0],FALSE,INFINITE)) do
begin
if(not bBufFull)then
begin
if ReadFile(fhFile,Buf[0],BufSize,nRealRead,nil)then
if nRealRead <> BufSize then
begin//File end;
fbFileEnd:= TRUE;
bBufFull:= FALSE;
ResetEvent(fhEventInput);
end;
end;
if(not InputData(fPORT,Buf[0],BufSize))then
begin
bBufFull:= TRUE;
ResetEvent(fhEventInput);
end
else
bBufFull:= FALSE;
end;
end;
end;//我现在不能进行录像播放, 能不能帮忙看看问题出在哪
m_hThread=NULL;
m_hEventInput=NULL;
m_hEventKill=NULL;m_hThread= CreateThread(NULL,0, LPTHREAD_START_ROUTINE (InputData),this,0,&dw);
m_hEventInput= CreateEvent(NULL,TRUE,FALSE,NULL);
m_hEventKill= CreateEvent(NULL,FALSE,FALSE,NULL);////////////////////////////////////////////////////////#define BUF_SIZE 4096
DWORD WINAPI InputData(LPVOID lpParameter)
{
CPlayerDlg* pOwner=(CPlayerDlg*)lpParameter;
HANDLE hMulEvents[2];
hMulEvents[0]=pOwner->m_hEventKill;
hMulEvents[1]=pOwner->m_hEventInput;
BYTE pBuf[BUF_SIZE];
DWORD nRealRead;
BOOL bBufFull=FALSE;
while(WAIT_OBJECT_0!=WaitForMultipleObjects(2,hMulEvents,FALSE,INFINITE))
{
if(!bBufFull)
{
if(!(ReadFile(pOwner->m_hStreamFile,pBuf,BUF_SIZE,&nRealRead,NULL)&&nRealRead==BUF_SIZE))
{
bBufFull=FALSE;
ResetEvent(pOwner->m_hEventInput);
}
}
if(!InputData(PORT,pBuf,BUF_SIZE))//送数据到缓冲的一个函数
{
bBufFull=TRUE;
ResetEvent(pOwner->m_hEventInput);
}
else
bBufFull=FALSE;
}
return 1;
}以上代码我想转成delphi形式,因为代码较多,所以只把相关的主要部分提了出来,如果大家觉得不够,我可以再贴其他的上来
unit T_Play;
interface
uses
Windows, Classes, SysUtils, ExtCtrls, StdCtrls, Variants, U_MPG4_REPLAY_API;
type
TThreadPlay = class(TThread)
private
//Global
fOwner: TComponent;
fPort: integer;
fhFile: HWND;
fHeadSize: DWORD;
fbFileEnd: Boolean;
//Event
fhEventInPut: THandle;
fhEventKill : THandle;
public
constructor Create(AOwner: TComponent);
protected
procedure Execute; override;
end;
implementation
{ TThreadPlay }
constructor TThreadPlay.Create(AOwner: TComponent);
begin
inherited Create(True);
FOwner:= AOwner;
fhEventInPut:= CreateEvent(nil, True, False, nil);
fhEventKill := CreateEvent(nil, FALSE,FALSE, nil);
end;
//文件头在别的地方读取,读取没有问题,读取完毕后Resume线程
procedure TThreadPlay.Execute;
var
EventHandles: array of THandle;
EventCount: Integer;
Buf: array of Byte;
BufSize: Integer;
bBufFull: Boolean;
nRealRead: DWORD;
begin
if fbExit then Exit;
begin
EventCount:= 2;
SetLength(EventHandles, EventCount);
EventHandles[0]:= fhEventInPut;
EventHandles[1]:= fhEventKill;
BufSize:= 4096;
SetLength(Buf, BufSize);
bBufFull:= False;
nRealRead:= 0; while(WAIT_OBJECT_0 <> WaitForMultipleObjects(EventCount,@EventHandles[0],FALSE,INFINITE)) do
begin
if(not bBufFull)then
begin
if ReadFile(fhFile,Buf[0],BufSize,nRealRead,nil)then
if nRealRead <> BufSize then
begin//File end;
fbFileEnd:= TRUE;
bBufFull:= FALSE;
ResetEvent(fhEventInput);
end;
end;
if(not InputData(fPORT,Buf[0],BufSize))then
begin
bBufFull:= TRUE;
ResetEvent(fhEventInput);
end
else
bBufFull:= FALSE;
end;
end;
end;//我现在不能进行录像播放, 能不能帮忙看看问题出在哪
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货