private void CloseKmpeg() { logger.Trace("CloseKmpeg start"); this.InstallImageCallback3 -= new EventHandler <ImageEventArgs>(OnImageCallback3Recive); this.InstallTimeCodeExCallback -= new EventHandler <TimeCodeCallbackExEventArgs>(OnTimeCodeRecive); if (m_KMPEGHandle == IntPtr.Zero) { return; } try { KMPEG4.KStop(m_KMPEGHandle); KMPEG4.KStopStreaming(m_KMPEGHandle); KMPEG4.KDisconnect(m_KMPEGHandle); KMPEG4.KCloseInterface(m_KMPEGHandle); } catch (Exception ex) { logger.Error(ex.ToString()); } m_KMPEGHandle = IntPtr.Zero; _state = PlayerState.Ready; logger.Trace("CloseKmpeg done"); }
private void StartPlayback() { logger.Info("CPlayer::StartPlayback"); m_URLCommand.Play(); KMPEG4.KPlay(m_KMPEGHandle); //if (_mediaSession == null) //{ // _logger.Error("Media session reference missing"); // return; //} //int hr = _mediaSession.Start(Guid.Empty, new PropVariant()); //MFError.ThrowExceptionForHR(hr); }
public bool Pause() { logger.Info("Pause requested"); if (_state != PlayerState.Started) { logger.Error("Expected Started state, but was {0}", _state); } try { _state = PlayerState.PausePending; logger.Info("Pause pending"); m_URLCommand.Pause(); KMPEG4.KPause(m_KMPEGHandle); _state = PlayerState.Paused; return(true); } catch (Exception excp) { logger.Error(excp.ToString()); } return(false); }
private void OpenKmpeg(object info) { logger.Trace("OpenKmpeg start"); ConnectInfo connectInfo = (ConnectInfo)info; uint time = Convert.ToUInt32((connectInfo.StartTime - new DateTime(1970, 1, 1)).TotalSeconds); bool success = false; m_KMPEGHandle = KMPEG4.KOpenInterface(); KMPEG4.Media_Connect_Config4 mediaConfig = new KMPEG4.Media_Connect_Config4(); mediaConfig.ConnectTimeOut = 2; mediaConfig.ContactType = (int)KMPEG4.CONTACT_TYPE.CONTACT_TYPE_HTTP_WOC_PREVIEW; mediaConfig.HTTPPort = connectInfo.Port; mediaConfig.Password = connectInfo.Password; mediaConfig.UniCastIP = connectInfo.HostName; mediaConfig.UserID = connectInfo.UserID; mediaConfig.TCPVideoStreamID = 0; string session = "1234" + m_SelectID; mediaConfig.PlayFileName = time > 0 ? $"/Media/SyncPlayback?deviceid={connectInfo.SelectID}&syncsession={session}" : $"/Media/Streaming?deviceid={connectInfo.SelectID}&streamid={connectInfo.StreamId}"; logger.Debug($"Prepare play file:{mediaConfig.PlayFileName}"); success = KMPEG4.KSetMediaConfig4(m_KMPEGHandle, ref mediaConfig); SetImageCallback3(); SetTimeCodeExRecive(); if (KMPEG4.KConnect(m_KMPEGHandle)) { if (KMPEG4.KStartStreaming(m_KMPEGHandle)) { KMPEG4.KPlay(m_KMPEGHandle); m_URLCommand = new URLCommand(connectInfo.HostName, connectInfo.Port, connectInfo.UserID, connectInfo.Password, session); if (time > 0) { m_URLCommand.SetCurrentTime(time.ToString()); System.Threading.SpinWait.SpinUntil(() => false, 1000); m_URLCommand.SetPlayMode("1"); m_URLCommand.Play(); } else { } KMPEG4.KSetVolume(m_KMPEGHandle, 100, 100); KMPEG4.KSetMute(m_KMPEGHandle, false); } else { m_KMPEGConnectFail = true; } } else { m_KMPEGConnectFail = true; } logger.Trace("OpenKmpeg done"); }
public void TestK() { m_KMPEGHandle = KMPEG4.KOpenInterface(); }