操作系统:WIN 7
语言:C#
功能:C#中多线程的参数传递
代码:
传递参数类:
public class PlayVideoParameter
{
public int NPortId { set; get; }
public int LRealHandle { set; get; }
public int DwDataType { set; get; }
public IntPtr PBuffer { set; get; }
public int DwBufSize { set; get; }
public NETSDKDLL_DOTNET.FRAME_EXTDATA PExtData { set; get; }
}
应用示例:
public int OnRealDataCallBack(int lRealHandle, int dwDataType, IntPtr pBuffer, int dwBufSize, ref FRAME_EXTDATA pExtData)
{
//根据lRealHandle设置NPortId
//创建多线程显示视频
PlayVideoParameter pvp = new PlayVideoParameter();
pvp.NPortId = 1;
pvp.LRealHandle = lRealHandle;
pvp.DwDataType = dwDataType;
pvp.PBuffer = pBuffer;
pvp.DwBufSize = dwBufSize;
pvp.PExtData = pExtData;
System.Threading.Thread playThread = new Thread(new ParameterizedThreadStart(ThreadMethod));
playThread.Start(pvp);
return 0;
}
private void ThreadMethod(object parameter)
{
PlayVideoParameter pvp = (PlayVideoParameter)parameter;
IntPtr pWnd =pvp.PExtData.pUserData;
if (pvp.DwDataType == 0)
{
PLAYERDLL.IP_TPS_InputVideoData(pvp.NPortId,pvp.PBuffer,pvp.DwBufSize,pvp.PExtData.bIsKey, (int)pvp.PExtData.timestamp);
}
else if (pvp.DwDataType == 1)
{
}
else if (pvp.DwDataType == 2)
{
STREAM_AV_PARAM avParam = new STREAM_AV_PARAM();
avParam = (STREAM_AV_PARAM)Marshal.PtrToStructure(pvp.PBuffer, avParam.GetType());
int size = Marshal.SizeOf(typeof(VIDEO_PARAM));
IntPtr pVideoParam = Marshal.AllocHGlobal(10240);
Marshal.StructureToPtr(avParam.videoParam, pVideoParam, false);
NETSDKDLL_DOTNET.PLAYERDLL.IP_TPS_OpenStream(pvp.NPortId, pVideoParam, size, 0, 40);
Marshal.FreeHGlobal(pVideoParam);
if (avParam.bHaveAudio != 0)
{//说明有音频
int haveaudio = 1;
}
NETSDKDLL_DOTNET.PLAYERDLL.IP_TPS_Play(pvp.NPortId, pWnd);
}
}