Ejemplo n.º 1
0
 public static extern int HW_SetDisplayPara(IntPtr hChannel, ref DISPLAY_PARA pPara);
        public void g_SynGroupRealDataCallBack_V30(int lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr pUser)
        {
            bool iRet = false;
            bool temp;
            int iRtn = -1;
            IntPtr CurrentCardHandle = IntPtr.Zero;
            try
            {

                switch (dwDataType)
                {
                    case 1: //NET_DVR_SYSHEAD:

                        if (ListPorts.Count == 0)
                        {
                            if (_cameraInfo.ListOutputTarget != null)
                            {
                                foreach (DisplayHandlePair item in _cameraInfo.ListOutputTarget)
                                {

                                    #region soft decode
                                    HikPlayer.PlayM4_GetPort(ref m_lPort);
                                    if (dwBufSize > 0)
                                    {
                                        temp = HikPlayer.PlayM4_SetStreamOpenMode(m_lPort, 0);
                                        temp = HikPlayer.PlayM4_OpenStream(m_lPort, pBuffer, dwBufSize, 1024 * 1024);
                                        temp = HikPlayer.PlayM4_Play(m_lPort, item.Handle);
                                        temp = HikPlayer.PlayM4_SetDisplayBuf(m_lPort, 15);
                                        temp = HikPlayer.PlayM4_SetOverlayMode(m_lPort, false, 0);
                                        ListPorts.Add(m_lPort, item.Handle);
                                    }
                                    #endregion

                                    #region card decode output to TV
                                    DecodeChannel decodeChannel = FindOneFreeDecodeChannel();
                                    if (decodeChannel != null)
                                    {
                                        UsedDisplayChannelInfo udci=IsDisplayScreenNoOccupied(item.DisplayChannelId, item.DisplaySplitScreenNo);
                                        if ( udci!= null)
                                        {
                                            ReleaseUsedScreen(udci);
                                        }
                                        iRtn = HikVisionSDK.SetDecoderVideoExtOutput(decodeChannel.Id, 0, true, item.DisplayChannelId, item.DisplaySplitScreenNo, 0);
                                        if (iRtn != 0)
                                        {
                                            log.Error(string.Format("HW_SetDisplayPara {0}", iRtn));
                                            continue;
                                        }
                                        iRtn = HikVisionSDK.HW_InitDirectDraw(_cameraInfo.Handle, 0x00000010);
                                        iRtn = HikVisionSDK.HW_ChannelOpen(decodeChannel.Id, ref CurrentCardHandle);
                                        decodeChannel.Handle = CurrentCardHandle;
                                        if (iRtn != 0)
                                        {
                                            log.Error(string.Format("HW_ChannelOpen err[%x]", iRtn));
                                            ListPorts[m_lPort] = IntPtr.Zero;
                                            continue;
                                        }
                                        iRtn = HikVisionSDK.HW_SetStreamOpenMode(CurrentCardHandle, 2);
                                        if (iRtn != 0)
                                        {
                                            log.Error(string.Format("HW_SetStreamOpenMode {0}", iRtn));
                                            ListPorts[m_lPort] = IntPtr.Zero;
                                            continue;
                                        }
                                        DISPLAY_PARA struCardPlayInfo = new DISPLAY_PARA();
                                        struCardPlayInfo.nLeft = 0;
                                        struCardPlayInfo.nTop = 0;
                                        struCardPlayInfo.nWidth = 704;
                                        struCardPlayInfo.nHeight = 576;
                                        struCardPlayInfo.bToScreen = 0;
                                        struCardPlayInfo.bToVideoOut = 1;
                                        iRtn = HikVisionSDK.HW_SetDisplayPara(CurrentCardHandle, ref struCardPlayInfo);
                                        if (iRtn != 0)
                                        {
                                            log.Error(string.Format("HW_SetDisplayPara {0}", iRtn));

                                            ListPorts[m_lPort] = IntPtr.Zero;
                                            continue;
                                        }

                                        iRtn = HikVisionSDK.HW_OpenStream(CurrentCardHandle, pBuffer, dwBufSize);
                                        if (iRtn != 0)
                                        {
                                            log.Error(string.Format("HW_OpenStream err {0}", iRtn));

                                            ListPorts[m_lPort] = IntPtr.Zero;
                                            continue;
                                        }
                                        iRtn = HikVisionSDK.HW_Play(CurrentCardHandle);

                                        CardInitiOK = true;
                                        if (iRtn != 0)
                                        {
                                            log.Error(string.Format("HW_Play err {0}", iRtn));

                                            ListPorts[m_lPort] = IntPtr.Zero;
                                            continue;

                                        }
                                        decodeChannel.CurrentCardOutId = CurrentCardOutId;
                                        decodeChannel.CurrentCardOutType = CurrentCardOutType;
                                        _listDecodeChannel.Remove(decodeChannel.Id);
                                        _listDecodeChannel.Add(decodeChannel.Id, decodeChannel);
                                        AlUsedDisplayChannelInfo.Add(new UsedDisplayChannelInfo { DisplayChannelId = item.DisplayChannelId, DisplaySplitScreenNo = item.DisplaySplitScreenNo, SynGroupId = CurrentCardOutId, Handle = CurrentCardHandle });

                                    }
                                }
                            }
                        }
                        #endregion

                        break;

                    case 4://NET_DVR_STD_VIDEODATA:
                    case 5://NET_DVR_STD_AUDIODATA:
                    case 2://NET_DVR_STREAMDATA:

                        #region soft decode
                        if (dwBufSize > 0 && ListPorts.Count > 0)
                        {
                            foreach (KeyValuePair<int, IntPtr> item in ListPorts)
                            {

                                int curPort = item.Key;
                                bool success = HikPlayer.PlayM4_InputData(curPort, pBuffer, dwBufSize);
                                if (!success)
                                {
                                    // Trace.WriteLine(DateTime.Now + "\t:HikPlayer.PlayM4_InputData failed!");
                                    log.Error(string.Format("HikPlayer.PlayM4_InputData failed!"));
                                }
                            }
                        }
                        #endregion

                        #region card decode output to TV
                        if (dwBufSize > 0)
                        {
                            foreach (var item in _listDecodeChannel)
                            {
                                if ((CardInitiOK) && item.Value.IsUsed())
                                {
                                    iRtn = HikVisionSDK.HW_InputData(item.Value.Handle, pBuffer, dwBufSize);
                                    if (iRtn <= 0)
                                    {
                                        log.Error(string.Format("HW_InputData err {0}", iRtn));

                                    }
                                }
                            }
                        }

                        #endregion

                        break;
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.ToString());
            }
        }
        public void g_RealDataCallBack_V30(int lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr pUser)
        {
            bool iRet = false;
            bool temp;
            int iRtn = -1;
            IntPtr CurrentCardHandle = IntPtr.Zero;
            try
            {

                switch (dwDataType)
                {
                    case 1: //NET_DVR_SYSHEAD:

                        #region soft decode
                        HikPlayer.PlayM4_GetPort(ref m_lPort);
                        if (dwBufSize > 0)
                        {
                            temp = HikPlayer.PlayM4_SetStreamOpenMode(m_lPort, 0);
                            temp = HikPlayer.PlayM4_OpenStream(m_lPort, pBuffer, dwBufSize, 1024 * 1024);
                            temp = HikPlayer.PlayM4_Play(m_lPort, _cameraInfo.Handle);
                            temp = HikPlayer.PlayM4_SetDisplayBuf(m_lPort, 15);
                            temp = HikPlayer.PlayM4_SetOverlayMode(m_lPort, false, 0);
                            ListPorts.Add(m_lPort, _cameraInfo.Handle);
                        }
                        #endregion

                        #region card decode output to TV

                        foreach (var defaultCardOut in ListDefaultCardOut)
                        {
                            if (defaultCardOut.Value.CameraId == _cameraInfo.CameraId)
                            {
                                DecodeChannel decodeChannel = FindOneFreeDecodeChannel();

                                if (decodeChannel != null)
                                {
                                    // iRtn =  HikVisionSDK.HW_InitDirectDraw(item.Value, 0x00000010);
                                    iRtn = HikVisionSDK.SetDecoderVideoExtOutput(decodeChannel.Id, 0, true, defaultCardOut.Value.DisplayChannelId, defaultCardOut.Value.DisplaySplitScreenNo, 0);
                                    if (iRtn != 0)
                                    {
                                        log.Error(string.Format("HW_SetDisplayPara {0}", iRtn));
                                        ListPorts[m_lPort] = IntPtr.Zero;
                                        return;
                                    }
                                    iRtn = HikVisionSDK.HW_InitDirectDraw(_cameraInfo.Handle, 0x00000010);
                                    iRtn = HikVisionSDK.HW_ChannelOpen(decodeChannel.Id, ref CurrentCardHandle);
                                    decodeChannel.Handle = CurrentCardHandle;
                                    if (iRtn != 0)
                                    {
                                        log.Error(string.Format("HW_ChannelOpen err[%x]", iRtn));
                                        ListPorts[m_lPort] = IntPtr.Zero;
                                        return;
                                    }

                                    iRtn = HikVisionSDK.HW_SetStreamOpenMode(CurrentCardHandle, 2);
                                    if (iRtn != 0)
                                    {
                                        log.Error(string.Format("HW_SetStreamOpenMode {0}", iRtn));
                                        ListPorts[m_lPort] = IntPtr.Zero;
                                        return;

                                    }

                                    DISPLAY_PARA struCardPlayInfo = new DISPLAY_PARA();

                                    struCardPlayInfo.nLeft = 0;
                                    struCardPlayInfo.nTop = 0;
                                    struCardPlayInfo.nWidth = 704;
                                    struCardPlayInfo.nHeight = 576;
                                    struCardPlayInfo.bToScreen = 0;
                                    struCardPlayInfo.bToVideoOut = 1;
                                    iRtn = HikVisionSDK.HW_SetDisplayPara(CurrentCardHandle, ref struCardPlayInfo);
                                    if (iRtn != 0)
                                    {
                                        log.Error(string.Format("HW_SetDisplayPara {0}", iRtn));
                                        ListPorts[m_lPort] = IntPtr.Zero;
                                        return;
                                    }

                                    iRtn = HikVisionSDK.HW_OpenStream(CurrentCardHandle, pBuffer, dwBufSize);
                                    if (iRtn != 0)
                                    {
                                        log.Error(string.Format("HW_OpenStream err {0}", iRtn));
                                        ListPorts[m_lPort] = IntPtr.Zero;
                                        return;

                                    }
                                    iRtn = HikVisionSDK.HW_Play(CurrentCardHandle);
                                    //start to play
                                    CardInitiOK = true;
                                    if (iRtn != 0)
                                    {
                                        log.Error(string.Format("HW_Play err {0}", iRtn));

                                        ListPorts[m_lPort] = IntPtr.Zero;
                                        return;

                                    }

                                    decodeChannel.CurrentCardOutType = CurrentCardOutType;
                                    decodeChannel.CurrentCardOutId = CurrentCardOutId;
                                    _listDecodeChannel.Remove(decodeChannel.Id);
                                    _listDecodeChannel.Add(decodeChannel.Id, decodeChannel);

                                }
                            }
                        }

                        #endregion
                        break;

                    case 4://NET_DVR_STD_VIDEODATA:
                    case 5://NET_DVR_STD_AUDIODATA:
                    case 2://NET_DVR_STREAMDATA:

                        #region ltyong暂时注释
                        //if (dwBufSize > 0 && ListPorts.Count>0)
                        //{
                        //    foreach (KeyValuePair<int,IntPtr> item in ListPorts)
                        //    {
                        //        #region soft decode
                        //        m_lPort = item.Key;
                        //        if (!HikPlayer.PlayM4_InputData(m_lPort, pBuffer, dwBufSize))
                        //        {
                        //        }
                        //        #endregion
                        //        #region card decode output to TV
                        //        hCardHandle = item.Value;
                        //        if (hCardHandle != IntPtr.Zero)
                        //        {
                        //            iRtn = HikVisionSDK.HW_InputData(hCardHandle, pBuffer, dwBufSize);
                        //            if (iRtn <= 0)
                        //            {
                        //                log.Error(string.Format("HW_InputData err {0}", iRtn));

                        //            }
                        //        }
                        //        #endregion

                        //    }

                        //}
                        #endregion

                        #region soft decode
                        if (dwBufSize > 0 && ListPorts.Count > 0)
                        {
                            foreach (KeyValuePair<int, IntPtr> item in ListPorts)
                            {

                                m_lPort = item.Key;
                                bool success = HikPlayer.PlayM4_InputData(m_lPort, pBuffer, dwBufSize);
                                if (!success)
                                {
                                    // Trace.WriteLine(DateTime.Now + "\t:HikPlayer.PlayM4_InputData failed!");
                                    log.Error(string.Format("HikPlayer.PlayM4_InputData failed!"));
                                }
                            }
                        }
                        #endregion

                        #region card decode output to TV
                        if (dwBufSize > 0)
                        {
                            foreach (var item in _listDecodeChannel)
                            {
                                if ((CardInitiOK) && item.Value.IsUsed())
                                {
                                    iRtn = HikVisionSDK.HW_InputData(item.Value.Handle, pBuffer, dwBufSize);
                                    //Trace.WriteLine(DateTime.Now + "\t:HikVisionSDK.HW_InputData 返回值:" + iRtn);
                                    if (iRtn <= 0)
                                    {
                                        log.Error(string.Format("HW_InputData err {0}", iRtn));

                                    }
                                }
                            }
                        }

                        #endregion

                        break;
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.ToString());
            }
        }
        public static REGION_PARAM[] GetStruDisplayRegion(DISPLAY_PARA struCardPlayInfo, int regionNumber)
        {
            REGION_PARAM[] struDisplayRegion = new REGION_PARAM[regionNumber];
            int i;
            int row = (int)(Math.Sqrt(regionNumber));
            var tempDisplayRegion = new REGION_PARAM[row, row];
            int step = 64 / regionNumber;

            int nwidth = struCardPlayInfo.nWidth / row;
            int nheight = struCardPlayInfo.nHeight / row;
            for (int j = 0; j < row; j++)
            {
                for (int k = 0; k < row; k++)
                {
                    tempDisplayRegion[j, k].top = (uint)(nheight * k);
                    tempDisplayRegion[j, k].left = (uint)(nwidth * j);
                    tempDisplayRegion[j, k].width = (uint)(nwidth);
                    tempDisplayRegion[j, k].height = (uint)(nheight);
                }
            }
            for (i = 0; i < regionNumber; i++)
            {
                struDisplayRegion[i] = new REGION_PARAM();
                struDisplayRegion[i] = tempDisplayRegion[i % row, i / row];
                struDisplayRegion[i].color = (uint)(Color.FromArgb(128, i * step, 0, 0).ToArgb());
            }
            return struDisplayRegion;
        }
Ejemplo n.º 5
0
 private void InitDisplayRegion(int displayChannelInfoId)
 {
     DISPLAY_PARA struCardPlayInfo = new DISPLAY_PARA();
     struCardPlayInfo.nLeft = 0;
     struCardPlayInfo.nTop = 0;
     struCardPlayInfo.nWidth = 704;
     struCardPlayInfo.nHeight = 576;
     struCardPlayInfo.bToScreen = 0;
     struCardPlayInfo.bToVideoOut = 1;
     int iRtn = HikVisionSDK.SetDisplayStandard(displayChannelInfoId, VideoStandard_t.StandardPAL);
     REGION_PARAM[] struDisplayRegion = HikVideoServerCameraDriver.GetStruDisplayRegion(struCardPlayInfo, _listDisplayChannelInfo[displayChannelInfoId].SplitScreenNo);
     iRtn = HikVisionSDK.SetDisplayRegion(displayChannelInfoId, _listDisplayChannelInfo[displayChannelInfoId].SplitScreenNo, ref struDisplayRegion[0], 0);
 }
Ejemplo n.º 6
0
 private void InitDisplayRegion()
 {
     DISPLAY_PARA struCardPlayInfo = new DISPLAY_PARA();
     struCardPlayInfo.nLeft = 0;
     struCardPlayInfo.nTop = 0;
     struCardPlayInfo.nWidth = 704;
     struCardPlayInfo.nHeight = 576;
     struCardPlayInfo.bToScreen = 0;
     struCardPlayInfo.bToVideoOut = 1;
     if (_listDisplayChannelInfo==null) return;
     foreach (var displayChannelInfo in _listDisplayChannelInfo)
     {
         InitDisplayRegion(displayChannelInfo.Key);
     }
 }