C#中多线程的参数传递

操作系统: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);
            }
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值