我想实现网传功能,客户端通过局域网接收服务端的视频。但是我的程序只能接收到帧,就是没图像。代码如下:在formshow里初始化
var
PRVRECT:TRECT;
begin
PRVRECT.Top :=0;
PRVRECT.Left :=0;
PRVRECT.Right :=panel1.Width ;
PRVRECT.Bottom :=panel1.Height ;
MTALoadLibrary(9000,1);//初始化
MTACreateVideoDevice(form1.Panel1.Handle,form1.Handle,PRVRECT,320,240,2,false);//视频输出
MTASetMpeg4Version(MPEG4_V3);///设置MPEG4版本,可选值有MPEG4_V1 MPEG4_V2 MPEG4_V3 MPEG4_XVID
end;连接服务器
var
ServerIP:string;
CallID:integer;
begin
ServerIP:=trim(sevip.Text);
CallID:=MTANewCall(pchar(sevIP.text),strtoint(serverport.text),0);//开始一个新的呼叫,并返回呼叫路数
CallIdNO:=CallID;
if CallID=-1 then
begin
showmessage('MTANewCall error');
exit;
end else
begin
MTASetVideoOut(CallID,0,0);//将视频输出到连接的线路上
MTAMakeCall(CallID,REQ_VI_STREAM,false,nil,0,0,ConnectingProc);//请求媒体服务传输 ConnectingProc为回调函数
ConnectOK:=True;
end;
end;//回调函数
procedure ConnectingProc(nCallId:longword;biCmd:char;nResult:longword;pRetData:pbyte);stdcall ;
var
lSize:longword;
begin
lSize := sizeof(VIDINFO);
pVideoInfo := @VideoInfo;
move(pRetData^, pVideoInfo^, lSize);
CallIdNO:=nCallId;
Postmessage(form1.Handle,My_Message,0,0);
end;procedure TForm1.MyMessage(var MyMsg:TMessage);
var
lIndexl:longword;
bRetVideo:bool;
begin
bRetVideo := true;
pVideoInfo.nCompressor := MPEG4_V3;//MPEG4压缩
lIndexl := MTAGetIndexByCallID(CallIdNO);//得到显示在客户端的区域
bRetVideo:=MTASetVideoOut(CallIdNO,lIndexl,@VideoInfo);//在客户端相应的区域上输出视频
if bRetVideo=false then
begin
showmessage('MTASetVideoOut false');
MTAClearCall(CallIdNO, false);///清楚该请求
end else
begin
//timer1.Enabled:=true;
end;
end;
var
PRVRECT:TRECT;
begin
PRVRECT.Top :=0;
PRVRECT.Left :=0;
PRVRECT.Right :=panel1.Width ;
PRVRECT.Bottom :=panel1.Height ;
MTALoadLibrary(9000,1);//初始化
MTACreateVideoDevice(form1.Panel1.Handle,form1.Handle,PRVRECT,320,240,2,false);//视频输出
MTASetMpeg4Version(MPEG4_V3);///设置MPEG4版本,可选值有MPEG4_V1 MPEG4_V2 MPEG4_V3 MPEG4_XVID
end;连接服务器
var
ServerIP:string;
CallID:integer;
begin
ServerIP:=trim(sevip.Text);
CallID:=MTANewCall(pchar(sevIP.text),strtoint(serverport.text),0);//开始一个新的呼叫,并返回呼叫路数
CallIdNO:=CallID;
if CallID=-1 then
begin
showmessage('MTANewCall error');
exit;
end else
begin
MTASetVideoOut(CallID,0,0);//将视频输出到连接的线路上
MTAMakeCall(CallID,REQ_VI_STREAM,false,nil,0,0,ConnectingProc);//请求媒体服务传输 ConnectingProc为回调函数
ConnectOK:=True;
end;
end;//回调函数
procedure ConnectingProc(nCallId:longword;biCmd:char;nResult:longword;pRetData:pbyte);stdcall ;
var
lSize:longword;
begin
lSize := sizeof(VIDINFO);
pVideoInfo := @VideoInfo;
move(pRetData^, pVideoInfo^, lSize);
CallIdNO:=nCallId;
Postmessage(form1.Handle,My_Message,0,0);
end;procedure TForm1.MyMessage(var MyMsg:TMessage);
var
lIndexl:longword;
bRetVideo:bool;
begin
bRetVideo := true;
pVideoInfo.nCompressor := MPEG4_V3;//MPEG4压缩
lIndexl := MTAGetIndexByCallID(CallIdNO);//得到显示在客户端的区域
bRetVideo:=MTASetVideoOut(CallIdNO,lIndexl,@VideoInfo);//在客户端相应的区域上输出视频
if bRetVideo=false then
begin
showmessage('MTASetVideoOut false');
MTAClearCall(CallIdNO, false);///清楚该请求
end else
begin
//timer1.Enabled:=true;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货