这两天用使用海思的库hi_h264dec_w.dll(版本v2.2.2.0.2)解码时,在直接拷贝时出现"Invalid floating point operation.”的错误;
目前根据网络资料,屏蔽FPU错误,由于功能正常,因此具体原因还没有去分析,代码如下:
function TVideoDecoder.DecodeVideoFrame(var frame: H264_frame): boolean;
var
fOutFrame: H264_DEC_FRAME_S; //解码帧
iy, iuv: integer; //yuv长度,u的长度
Saved8087CW: Word;//Default 8087 control word. FPU control register is set to this value.
begin
Saved8087CW := Get8087CW; //保存当前
try
Set8087CW($133F); { Disable all fpu exceptions. }
result := DecodeVideoFrame(fOutFrame);
if not result then exit;
frame.FrameNo := fDecFrameCount;
frame.Width := foutframe.uWidth;
frame.Height := foutframe.uHeight;
frame.FrameRate := 25; //默认
frame.PicType := fDecAttr.uPictureFormat;
//拷贝 I420的yuv数据
iy := foutframe.uHeight * foutframe.uYStride;
iuv := foutframe.uHeight * foutframe.uUVStride div 2;
frame.datalen := iy + 2 * iuv;
getmem(frame.data, frame.datalen + 10);
copymemory(frame.data, foutframe.pY, iy);//不设置FPU,那么这句会报错
copymemory(frame.data + iy, foutframe.pu, iuv);
copymemory(frame.data + iy + iuv, foutframe.pv, iuv);
{$IFDEF __SaveH264}
if result then
fYuvStream.Write(frame.data[0], frame.datalen);
{$ENDIF}
finally
Set8087CW(Saved8087CW); //恢复
end;
end;
关于FPU的设置,有几个建议:
1)It is recommend that you disable all floating-point exceptions when using OpenGL to render 3D graphics;
2)如果在程序中使用了SceneControl.LoadSxFile载入了3D文档,那么必须在程序退出时,在Set8087CW之前调用IScene的ClearLayers方法清除图层,否则程序在退出时会出现异常。参考代码为:SceneControl1.Scene.ClearLayers;
参考文档(非常感谢以下文章):
1) http://www.langjisky.com/netdown/?type=detail&id=99
2) http://www.cnblogs.com/neugls/archive/2011/04/21/2023097.html