public void Connect() { Trace.WriteLine("RtspHandler::Connect()"); _rtspClient.Connect(); _rtspClient.SendOptions().Dispose(); _rtspClient.SendDescribe().Dispose(); var videoDesc = _rtspClient.SessionDescription.MediaDescriptions.First(d => d.MediaType == MediaType.video); var audioDesc = _rtspClient.SessionDescription.MediaDescriptions.First(d => d.MediaType == MediaType.audio); // a=fmtp:97 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z2QAH62EBUViuKxUdCAqKxXFYqOhAVFYrisVHQgKisVxWKjoQFRWK4rFR0ICorFcVio6ECSFITk8nyfk/k/J8nm5s00IEkKQnJ5Pk/J/J+T5PNzZprQCgC3I,aO48sA== _videoStreamInfo.Parameter = videoDesc.FmtpLine.Parts.ElementAt(1).Split(';').First(l => l.StartsWith(VideoParameterIdentifier)).Substring(VideoParameterIdentifier.Length); // a=fmtp:96 streamtype=5;profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1190 _audioStreamInfo.Parameter = audioDesc.FmtpLine.Parts.ElementAt(1).Split(';').First(l => l.StartsWith(AudioParameterIdentifier)).Substring(AudioParameterIdentifier.Length); // a=rtpmap:97 H264/90000 _videoStreamInfo.ClockRate = int.Parse(videoDesc.RtpMapLine.Parts.ElementAt(1).Split('/')[1]); // a=rtpmap:96 MPEG4-GENERIC/48000/2 _audioStreamInfo.ClockRate = int.Parse(audioDesc.RtpMapLine.Parts.ElementAt(1).Split('/')[1]); Trace.WriteLine($"RtspHandler::Connect(): Video ClockRate={_videoStreamInfo.ClockRate} / Config={_videoStreamInfo.Parameter}"); Trace.WriteLine($"RtspHandler::Connect(): Audio ClockRate={_audioStreamInfo.ClockRate} / Config={_audioStreamInfo.Parameter}"); _rtspClient.Client.Logger = _rtspClient.Logger; _rtspClient.Client.HandleFrameChanges = false; _rtspClient.Client.RtpPacketReceieved += OnRtpPacketReceieved; }
private void PlayButton_Click(object sender, EventArgs e) { if (ClientThreadProc != null) { if (m_rtspClient != null) { m_rtspClient.StopPlaying(); m_rtspClient = null; } Media.Common.Extensions.Thread.ThreadExtensions.TryAbortAndFree(ref ClientThreadProc); ClientThreadProc = null; GC.WaitForPendingFinalizers(); PlayButton.Text = "Start"; } else { m_rtspClient = new RtspClient(URLTextBox.Text, RtspClient.ClientProtocolType.Tcp); //Client.DisableKeepAliveRequest = checkBox1.Checked; m_rtspClient.OnConnect += RTSPClient_OnConnect; ClientThreadProc = new Thread(() => m_rtspClient.Connect()); ClientThreadProc.Start(); PlayButton.Text = "Stop"; } }
/// <summary> /// Beings streaming from the source /// </summary> public override void Start() { if (IsDisposed) { return; } if (false == RtspClient.IsConnected) { RtspClient.OnConnect += RtspClient_OnConnect; RtspClient.OnDisconnect += RtspClient_OnDisconnect; RtspClient.OnPlay += RtspClient_OnPlay; RtspClient.OnPause += RtspClient_OnPausing; RtspClient.OnStop += RtspClient_OnStop; try { RtspClient.Connect(); } catch { RtspClient.StopPlaying(); } //Stop stop } else if (false == RtspClient.IsPlaying) { try { //Start the playing again RtspClient.StartPlaying(MediaStartTime, MediaEndTime, SpecificMediaType); //Indicate when the stream was started. m_StartedTimeUtc = DateTime.UtcNow; //Call base to set started etc. base.Start(); } catch { RtspClient.StopPlaying(); } //Not stop } }
static void Main(string[] args) { //初始化 Init(); string rtspUrl = "rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov"; IRtspClient rtspClient = new RtspClient(RTSP.Enums.RTPTransport.TCP); rtspClient.Connect(rtspUrl); //等待循环结束 Cycling(); }
/// <summary> /// Beings streaming from the source /// </summary> public override void Start() { if (IsDisposed || State >= StreamState.StopRequested) { return; } //May have to re-create client. try { RtspClient.Connect(); } catch (Exception ex) { Common.ILoggingExtensions.LogException(RtspClient.Logger, ex); RtspClient.StopPlaying(); RtspClient.Disconnect(); } }