public RTPSendConnection(IPEndPoint ipe) { this.m_Participant = new RtpParticipant(Guid.NewGuid().ToString(), "Classroom Playback"); this.m_Session = new RtpSession(ipe, this.m_Participant, true, false); this.m_Sender = this.m_Session.CreateRtpSenderFec("Classroom Presenter", PayloadType.dynamicPresentation, null, 0, 100); this.m_Queue = new SendingQueue(this); }
/// <summary> /// Hooks up the provided renderer to a pin of the provided media type on the file /// </summary> /// <param name="renderer">The filter to render data to</param> /// <param name="mediaType">The type of pin to connect to this renderer</param> /// <param name="rtpSender">RtpSender that will be used by the renderer</param> /// <param name="filterName">The name of the render filter in the graph</param> private void HookUpFilter(ref IBaseFilter renderer, Guid mediaType, RtpSender rtpSender, string filterName) { // Pin the Guid, so we can pass it as an IntPtr GCHandle hGuid = GCHandle.Alloc(mediaType, GCHandleType.Pinned); try { // Only create the filter once if (renderer == null) { // ConferenceXP's custom filter for sending data over network renderer = MDShow.RtpRendererClass.CreateInstance(); // Initialize the filter with an RtpSender to use ((IRtpRenderer)renderer).Initialize(rtpSender); // Add filter to graph iGB.AddFilter(renderer, filterName); } // The WM file may not have a pin of the desired category, so this may fail // e.g. Audio only file won't have video, video may not have audio, etc. iCGB2.RenderStream(IntPtr.Zero, hGuid.AddrOfPinnedObject(), wmASFReader, null, renderer); } catch (COMException ce) { Console.WriteLine(ce.ToString()); } finally { // Always unpin the Guid hGuid.Free(); } }
/// <summary> /// Creates the RtpSender for this stream asynchronously. This causes the 500ms Thread.Sleep that occurs in /// RtpSession.CreateRtpSender to not cause performance problems during playback. /// </summary> private void CreateSender(object stateVar) { // For multi-threading safety purposes, we create the sender before assigning the new sender to the class variable. RtpSender newSender = rtpSession.CreateRtpSender("Playback: " + cname + " : " + name, this.streamPayload, this.privExtns); this.rtpSender = newSender; }
/// <summary> /// Thread entry point for attempting to recreate the network connection /// </summary> private void ResetThread() { while (true) { using (Synchronizer.Lock(this)) { try { // Try to Reconnect ushort fec; short interpacketdelay; using (Synchronizer.Lock(this.m_Model.SyncRoot)) { using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) { fec = (ushort)this.m_Model.ViewerState.ForwardErrorCorrection; interpacketdelay = (short)this.m_Model.ViewerState.InterPacketDelay; } } if (fec == 0) { this.m_RtpSender = this.m_RtpSession.CreateRtpSender("Classroom Presenter", PayloadType.dynamicPresentation, null); } else { this.m_RtpSender = this.m_RtpSession.CreateRtpSenderFec("Classroom Presenter", PayloadType.dynamicPresentation, null, 0, fec); } this.m_RtpSender.DelayBetweenPackets = interpacketdelay; return; } catch (Exception) { System.Threading.Thread.Sleep(100); } } } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { m_Disposing = true; m_SendQueueWait.Set(); this.m_BeaconService.Dispose(); if (m_RtpSender != null) { m_RtpSender.Dispose(); m_RtpSender = null; } if (m_RtpSession != null) { try { m_RtpSession.Dispose(); } catch { } m_RtpSession = null; } m_RtpParticipant = null; if (m_SendThread != null) { if (!m_SendThread.Join(5000)) { m_SendThread.Abort(); } } } }
static void Main(string[] args) { RtpParticipant part = new RtpParticipant("*****@*****.**", "SENDER"); RtpSession session = new RtpSession(ip, part, true, true); session.PacketTransform = new EncryptionTransform("You are a big freak!"); //session.PacketTransform = new XorTransform(); RtpSender sender = session.CreateRtpSender("My sender", PayloadType.Test, null); Stream fs = File.OpenRead("data.txt"); int length = (int)fs.Length; Console.Out.WriteLine("Opening file of length: " + length); byte[] buffer = new byte[length]; int bytesRead = 0; while (bytesRead < length) { bytesRead += fs.Read(buffer, bytesRead, Math.Min(16384, (length - bytesRead))); } for (int i = 0; i < 5; i++) { Console.Out.WriteLine("Sending buffer to address: " + ip); sender.Send(buffer); Thread.Sleep(1000); } }
/// <summary> /// Creates the RtpSender for this stream asynchronously. This causes the 500ms Thread.Sleep that occurs in /// RtpSession.CreateRtpSender to not cause performance problems during playback. /// </summary> private void CreateSender(object stateVar) { // For multi-threading safety purposes, we create the sender before assigning the new sender to the class variable. RtpSender newSender = rtpSession.CreateRtpSender(string.Format(CultureInfo.CurrentCulture, Strings.Playback, cname, name), this.streamPayload, this.privExtns); this.rtpSender = newSender; }
protected override void CreateRtpSenders() { // // Don't call base.CreateRtpSenders, because we need to customize the // creation of our RtpSenders // videoSender = CreateRtpSender(videoProps); audioSender = CreateRtpSender(audioProps); }
// CF2 Create participant, join session // CF3 Retrieve RtpSender private void JoinRtpSession(string name) { try { rtpSession = new RtpSession(ep, new RtpParticipant(name, name), true, true); rtpSender = rtpSession.CreateRtpSenderFec(name, PayloadType.Chat, null, 0, 200); } catch (Exception ex) { MessageBox.Show("Please make sure that you are connceted with the network so " + ex.Message); } }
private void LeaveRtpSession() { if (rtpSession != null) { rtpSession.Dispose(); rtpSession = null; rtpSender = null; } }
private void LeaveRtpSession() { if (rtpSession != null) { // Clean up all outstanding objects owned by the RtpSession rtpSession.Dispose(); rtpSession = null; rtpSender = null; } }
public UnicastToMulticastBridge(PresenterModel model) { GetConfig(); //Prepare for RTP sending m_RtpParticipant = new RtpParticipant(m_Cname, m_Name); try { m_RtpSession = new RtpSession(m_MulticastEndpoint, m_RtpParticipant, true, false); } catch (Exception e) { Trace.WriteLine(e.ToString()); m_RtpSession = null; m_RtpParticipant = null; return; } try { /// Notes about FEC: There are two types supported by the MSR RTP stack: Frame-based and Packet-based. /// Setting cDataPx to zero forces frame-based. In this case cFecPx is a percentage. It must be greater than zero, but can be /// very large, eg. 1000. Frame-based FEC appears to be better for large frames (which the stack splits into multiple packets) /// possibly because the FEC packets for the frame are not interlaced in time sequence with the frame packets. /// If cDataPx is not zero, packet-based FEC is used. In this mode cDataPx and cFecPx are a ratio of data packets to fec packets. /// For single packet frames, 1:1 and 0:100 are identical. Single packet frames are frames smaller than /// the MTU which is normally 1500 bytes. Presenter's Chunk encoder creates frames up to 16kbytes. Many frames are smaller /// than this, but only a few are below the MTU. For this reason we will always use Frame-based FEC. Usful values are expected to /// be from around 10 up to around 100. More than 100 might be good in some cases, but might impact performance. /// More than 500 would probably never be advised. m_RtpSender = m_RtpSession.CreateRtpSenderFec("Classroom Presenter Unicast to Multicast Bridge", PayloadType.dynamicPresentation, null, 0, m_Fec); m_RtpSender.DelayBetweenPackets = m_InterpacketDelay; } catch (Exception e) { Trace.WriteLine(e.ToString()); try { m_RtpSession.Dispose(); } catch { } m_RtpParticipant = null; m_RtpSession = null; m_RtpSender = null; return; } //Prepare the beacon this.m_ChunkSequence = 0; this.m_Encoder = new Chunk.ChunkEncoder(); this.m_BeaconService = new Beacons.BridgeBeaconService(this, model); //Prepare the queue and sending thread m_Disposing = false; m_SendQueueWait = new EventWaitHandle(false, EventResetMode.AutoReset); m_SendQueue = new PriorityQueue <BridgeMessage>(); m_SendThread = new Thread(new ThreadStart(SendThread)); m_SendThread.Start(); }
private void DisposeSender() { // Pri2: Account for the case that the sender creation has been fired, but the sender hasn't yet been created. if (rtpSender != null) { this.rtpSender.Dispose(); this.rtpSender = null; } this.createSenderFired = false; }
// CF1 private void LeaveRtpSession() { UnhookRtpEvents(); if (rtpSession != null) { rtpSession.Dispose(); rtpSession = null; rtpSender = null; rtpStream = null; } }
void JoinSession() { // Add the channel for graphics commands fRtpSender = fSession.CreateRtpSender(fParticipantName, PayloadType.xApplication2, null); //fRtpSender = fSession.CreateRtpSenderFec(fParticipantName, PayloadType.xApplication2, null, 0, 200); fRtpSender.DelayBetweenPackets = 0; // Create the sending graph port fChunkEncoder = new GraphPortChunkEncoder(); fChunkEncoder.ChunkPackedEvent += new GraphPortChunkEncoder.ChunkPacked(GDIChunkPacked); AddGraphPort(fChunkEncoder); }
override public void Run() { RtpEvents.RtpStreamAdded += new MSR.LST.Net.Rtp.RtpEvents.RtpStreamAddedEventHandler(RtpStreamAdded); RtpEvents.RtpStreamRemoved += new MSR.LST.Net.Rtp.RtpEvents.RtpStreamRemovedEventHandler(RtpStreamRemoved); RtpSession session = new RtpSession(RtpSession.DefaultEndPoint, new RtpParticipant("RtpSenderCreation", "RtpSenderCreation"), true, true); // Plain old RtpSender rtpSender = session.CreateRtpSender("RtpSenderCreation", PayloadType.Test, null); Thread.Sleep(timeout); SendData(); SendData(); rtpSender.Dispose(); // Constant FEC sender rtpSender = session.CreateRtpSenderFec("RtpSenderCreation", PayloadType.Test, null, 1, 1); SendData(); SendData(); rtpSender.Dispose(); // Frame FEC sender rtpSender = session.CreateRtpSenderFec("RtpSenderCreation", PayloadType.Test, null, 0, 50); SendData(); SendData(); rtpSender.Dispose(); // RtpSenders with the fec private extensions already set Hashtable priExns = new Hashtable(); // Plain old RtpSender rtpSender = session.CreateRtpSender("RtpSenderCreation", PayloadType.Test, priExns); SendData(); SendData(); rtpSender.Dispose(); // Constant FEC sender priExns[Rtcp.PEP_FEC] = "1:1"; rtpSender = session.CreateRtpSender("RtpSenderCreation", PayloadType.Test, priExns); SendData(); SendData(); rtpSender.Dispose(); // Frame FEC sender priExns[Rtcp.PEP_FEC] = "0:50"; rtpSender = session.CreateRtpSender("RtpSenderCreation", PayloadType.Test, priExns); SendData(); SendData(); rtpSender.Dispose(); session.Dispose(); }
void AddChannels() { HookRtpEvents(); // Add the channel for commands fRtpSender = fSession.CreateRtpSender(fParticipantName, PayloadType.xApplication3, null); fRtpSender.DelayBetweenPackets = 0; // Create the sending graph port fChunkEncoder = new SpaceCommandEncoder(); fChunkEncoder.ChunkPackedEvent += new SpaceCommandEncoder.PackCommandEventHandler(SendCommand); AddSpaceController(fChunkEncoder); }
public RTPClient(IPEndPoint multiCastIP, Image image, String cname, String name) { UnhandledExceptionHandler.Register(); this.ipe = multiCastIP; this.image = image; this.vpList = null; rtpSession = new RtpSession(ipe, new RtpParticipant(cname, name), true, true); System.Diagnostics.Debug.WriteLine(rtpSession.MulticastInterface.ToString()); rtpSender = rtpSession.CreateRtpSenderFec(name, PayloadType.JPEG, null, 0, 1); waveWriters = new Dictionary <IPAddress, WaveFileWriter>(); EvetnBinding(); }
// DShowNET.IGraphBuilder graphBuilder; // IBasicAudio basicAudio; // IMediaControl mediaControl; // comType = Type.GetTypeFromCLSID(Clsid.FilterGraph); // if (comType == null) // throw new NotImplementedException(@"DirectShow FilterGraph not installed/registered!"); // comObj = Activator.CreateInstance(comType); // graphBuilder = (IGraphBuilder)comObj; comObj = null; graphBuilder.RenderFile(d_tb_sciezka.Text, null); // mediaControl = (IMediaControl)graphBuilder; // videoWindow = graphBuilder as IVideoWindow; // mediaEvt = (IMediaEventEx)graphBuilder; // basicAudio = graphBuilder as IBasicAudio; // comType = Type.GetTypeFromCLSID(Clsid.SampleGrabber); // if (comType == null) // throw new NotImplementedException(@"DirectShow SampleGrabber not installed/registered!"); // comObj = Activator.CreateInstance(comType); // sampGrabber = (ISampleGrabber)comObj; comObj = null; // mediaEvt = (IMediaEventEx)graphBuilder; // baseGrabFlt = (IBaseFilter)sampGrabber; // AMMediaType media = new AMMediaType(); // media.majorType = MediaType.Video; // media.subType = MediaSubType.RGB24; // media.formatType = FormatType.VideoInfo; // ??? // hr = sampGrabber.SetMediaType(media); // videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader)); // Marshal.FreeCoTaskMem(media.formatPtr); media.formatPtr = IntPtr.Zero; // videoWindow.put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN); // videoWindow.put_Owner(picPreview.Handle); // videoWindow.SetWindowPosition(0, 0, picPreview.Width, picPreview.Height); // mediaControl.Run(); // timer1.Enabled = true; // } // } // else // { // MessageBox.Show("Podaj plik do strumieniowania", "Brak ścieżki dostępu", MessageBoxButtons.OK, MessageBoxIcon.Information); // } //} private void SetRTPSession() { IPEndPoint ep; try { ep = new IPEndPoint(IPAddress.Parse(d_tb_multicastIP.Text), 3000); } catch { MessageBox.Show("Błędny adres grupy multicastowej"); return; } rtpSession = new RtpSession(ep, new RtpParticipant(Dns.GetHostName(), Dns.GetHostName()), true, true); rtpSender = rtpSession.CreateRtpSenderFec(Dns.GetHostName(), PayloadType.Chat, null, 0, 10); }
public virtual void JoinSession(RtpSession session, string participantName) { fSession = session; fParticipantName = participantName; // Must hook up events before creating sender so we know when the // ChannelType stream is added. HookRtpEvents(); // Add the channel for graphics commands fRtpSender = fSession.CreateRtpSender(fParticipantName, ChannelType, null); //fRtpSender = fSession.CreateRtpSenderFec(fParticipantName, PayloadType.xApplication2, null, 0, 200); //fRtpSender.DelayBetweenPackets = 0; }
private void SetRTPSession() { RtpSession rtpSession; IPEndPoint ep; try { ep = new IPEndPoint(ip, port); } catch { MessageBox.Show("Błędny adres grupy multicastowej"); return; } rtpSession = new RtpSession(ep, new RtpParticipant(Dns.GetHostName(), Dns.GetHostName()), true, true); rtpSender = rtpSession.CreateRtpSenderFec(Dns.GetHostName(), PayloadType.Chat, null, 0, 200); }
// CF2 Create participant, join session // CF3 Retrieve RtpSender private void JoinRtpSession(string name) { try { Hashtable payloadPara = new Hashtable(); payloadPara.Add("Width", Width); payloadPara.Add("Height", Height); payloadPara.Add("Quality", Quality); rtpSession = new RtpSession(ep, new RtpParticipant(name, name), true, true); rtpSender = rtpSession.CreateRtpSender(name, PayloadType.JPEG, null, payloadPara); } catch (Exception err) { logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace); } }
private void LeaveRtpSession() { try { if (rtpSession != null) { // Clean up all outstanding objects owned by the RtpSession rtpSession.Dispose(); rtpSession = null; rtpSender = null; } } catch (Exception err) { logger.Log(LogLevel.Error, err.Message + " " + err.Source + " " + err.StackTrace); } }
private void CleanUp() { logger.Debug("VideoStreamer::CleanUp()"); if (videoEncoder != null) { videoEncoder.DataEncoded -= VideoEncoder_DataEncoded; videoEncoder.Close(); videoEncoder = null; } videoSource.BufferUpdated -= ScreenSource_BufferUpdated; RtpSender?.Close(); state = StreamerState.Closed; }
// CF2 Create participant, join session // CF3 Retrieve RtpSender private void JoinRtpSession(string name) { try { Hashtable payloadPara = new Hashtable(); payloadPara.Add("Width", ImgWidth); payloadPara.Add("Height", ImgHeight); payloadPara.Add("Quality", Quality); rtpSession = new RtpSession(ep, new RtpParticipant(name, name), true, true); rtpSender = rtpSession.CreateRtpSender(name, PayloadType.JPEG, null, payloadPara); } catch (Exception ex) { Console.WriteLine(ex.Message); //MessageBox.Show("Please make sure that you are connceted with the network so " + ex.Message); } }
private void d_b_strumieniuj_Click(object sender, EventArgs e) { IPEndPoint ep; try { ep = new IPEndPoint(IPAddress.Parse(d_tb_multicastIP.Text), 3000); } catch { MessageBox.Show("Błędny adres grupy multicastowej"); return; } RtpEvents.RtpStreamAdded += new RtpEvents.RtpStreamAddedEventHandler(RtpStreamAdded); RtpEvents.RtpStreamRemoved += new RtpEvents.RtpStreamRemovedEventHandler(RtpStreamRemoved); rtpSession = new RtpSession(ep, new RtpParticipant(Dns.GetHostName(), Dns.GetHostName()), true, true); RtpSender rtpSender = rtpSession.CreateRtpSenderFec(Dns.GetHostName(), PayloadType.Chat, null, 0, 200); }
public void RenderNetwork(RtpSender rtpSender) { if (rtpSender == null) { string msg = Strings.NullRtpSenderError; Debug.Fail(msg); throw new ArgumentNullException(Strings.RtpSender, msg); } renderer = (Renderer)Filter.NetworkRenderer(); ((IRtpRenderer)renderer.BaseFilter).Initialize(rtpSender); iGB.AddFilter(renderer.BaseFilter, renderer.FriendlyName); renderer.AddedToGraph(fgm); // Connect last pin (device or compressor) to the network renderer iGB.Connect(compressor != null ? compressor.OutputPin : source.OutputPin, renderer.InputPin); }
// FileStream file = new FileStream(@"d:\test_enc3.h264", FileMode.Create); //private void MfEncoder_DataReady(byte[] buf) private void VideoEncoder_DataEncoded(byte[] buf, double _time) { //throw new NotImplementedException(); var time = MediaTimer.GetRelativeTime(); // var memo = new MemoryStream(buf); // memo.CopyTo(file); RtpSender.Push(buf, time); // rtpStreamer.Send(buf, time); var processingTime = sw.ElapsedMilliseconds; //logger.Debug(processingTime); //var ts = hwContext.sw.ElapsedMilliseconds; //Console.WriteLine("ElapsedMilliseconds " + ts); streamStats.Update(time, buf.Length, processingTime); }
// CF1, CF2 private void DShowNetworkFiltersForm_Load(object sender, System.EventArgs e) { HookRtpEvents(); // CF1 JoinRtpSession(); // CF1 if (presenter) { // CF2 Add devices to UI foreach (FilterInfo fi in VideoSource.Sources()) { cklbCameras.Items.Add(fi); } rtpSender = rtpSession.CreateRtpSender("Video", PayloadType.dynamicVideo, null); // CF1 } else { cklbCameras.Visible = false; } }
public void Close() { logger.Debug("AudioStreamer::Close()"); closing = true; if (RtpSender != null) { RtpSender.Close(); RtpSender = null; } if (audioSource != null) { audioSource.DataAvailable -= AudioSource_DataAvailable; } if (audioResampler != null) { audioResampler.Close(); audioResampler = null; } }
/// <summary> /// /// </summary> /// <param name="multiCastIP"></param> /// <param name="vpList"></param> /// <param name="cname"></param> /// <param name="name"></param> public RTPClient(IPEndPoint multiCastIP, Dictionary <IPAddress, VideoPreview> vpList, String cname, String name) { UnhandledExceptionHandler.Register(); this.ipe = multiCastIP; this.vpList = vpList; this.image = null; rtpSession = new RtpSession(ipe, new RtpParticipant(cname, name), true, true); System.Diagnostics.Debug.WriteLine(rtpSession.MulticastInterface.ToString()); rtpSender = rtpSession.CreateRtpSenderFec(name, PayloadType.JPEG, null, 0, 1); EvetnBinding(); //stream = new MemoryStream(); //sBuffer = new Dictionary<IPAddress, System.IO.MemoryStream>(); //rBuffer = new Dictionary<IPAddress, System.IO.MemoryStream>(); //listen_thread = new Thread(new ThreadStart(listener_proc)); //listen_thread.SetApartmentState(ApartmentState.STA); //port =(int)MainWindow.Ports.RTP; //rtpSendClient = new UdpClient(); //rtpReceClient = new UdpClient((int)MainWindow.Ports.RTP); }
//metoda odbierająca klatki internal void receive(PictureBox pb_picture) { this.pb_picture = pb_picture; RtpSession rtpSession; IPEndPoint ep; try { ep = new IPEndPoint(ip, port); } catch { MessageBox.Show("Błędny adres grupy multicastowej"); return; } //utworzenie zdarzenia nawiązania połączenia RtpEvents.RtpStreamAdded += new RtpEvents.RtpStreamAddedEventHandler(RtpStreamAdded); //RtpEvents.RtpStreamRemoved += new RtpEvents.RtpStreamRemovedEventHandler(RtpStreamRemoved); //parametryzajca rtpSession rtpSession = new RtpSession(ep, new RtpParticipant(Dns.GetHostName(), Dns.GetHostName()), true, true); //tworzenie rtpSender RtpSender rtpSender = rtpSession.CreateRtpSenderFec(Dns.GetHostName(), PayloadType.Chat, null, 0, 200); }
public void Dispose() { RtpEvents.RtpParticipantAdded -= RtpParticipantAdded; RtpEvents.RtpParticipantRemoved -= RtpParticipantRemoved; RtpEvents.RtpStreamAdded -= RtpEvents_RtpStreamAdded; RtpEvents.RtpStreamRemoved -= RtpEvents_RtpStreamRemoved; if (waveWriters != null) { foreach (var wave in waveWriters.Values) { wave.Close(); } } if (waveOut != null) { waveOut.Dispose(); } if (rtpSession != null) { rtpSession.Dispose(); rtpSession = null; rtpSender = null; } }
/// <summary> /// Finishes the creation of an RtpSender by adding it to local collections and announcing /// it to the remote sites via an Rtcp packet /// </summary> private void _CreateRtpSender(RtpSender rtpSender) { // Add it to the collection lock(rtpSenders) { rtpSenders.Add(rtpSender.SSRC, rtpSender); } // We would like to try and have the stream constructed at the remote sites before the // Rtp data starts arriving so that none of it is missed. To help with that, when an // RtpSender is constructed, it sets an Sdes private extension indicating its payload // type. Here we force an Rtcp compound packet to be sent and give it a little time. rtcpSender.SendRtcpDataNow(); Thread.Sleep(250); }
public virtual void CreateRtpSender(string participantName) { // Create the sender for the specified channel type fRtpSender = fSession.CreateRtpSender(participantName, ChannelType, null); //fRtpSender = fSession.CreateRtpSenderFec(participantName, ChannelType, null, 3, 1); //fRtpSender.DelayBetweenPackets = 0; }
public SpaceCommandEncoder(RtpSender sender) { fSender = sender; }