public PlayList(string name, Media.MediaTypes type) : base(new List <Media.Media>()) { this.Name = name; this.Type = LibraryType.PlayList; this.MediaType = type; }
public PlayList(string name, List <Media.Media> content) : base(content) { this.Name = name; this.Type = LibraryType.PlayList; this.MediaType = GetMediaType(content); /* * if (this.MediaType == Media.MediaTypes.Generic) * throw new PlayListMixedMediaTypesException(); */ }
private static Media.MediaTypes GetMediaType(List <Media.Media> medias) { Media.MediaTypes type = Media.MediaTypes.Generic; if (medias.Count > 0) { type = medias[0].Type; foreach (var media in medias) { if (type != media.Type) { Console.WriteLine("File skipped : " + media.Name); } //return Media.MediaTypes.Generic; } } return(type); }
public void SendRtpDataToConnection(Guid connectionId, byte[] data, Media.MediaTypes mediaType) { RTSPConnection targetConnection = null; lock (_rtspList) { foreach (RTSPConnection connection in _rtspList.ToArray()) { // Convert to Array to allow us to delete from rtsp_list if (connectionId == connection.Id) { targetConnection = connection; break; } } } if (targetConnection != null) { targetConnection.SendRtpData(data, mediaType); } }
public void SendRtpData(byte[] data, Media.MediaTypes mediaType) { DateTime now = DateTime.UtcNow; // RTSP Timeout (clients receiving RTP video over the RTSP session // do not need to send a keepalive (so we check for Socket write errors) Boolean sending_rtp_via_tcp = false; if (mediaType == Media.MediaTypes.audio) { if ((_audioClientTransport != null) && (_audioClientTransport.LowerTransport == Rtsp.Messages.RtspTransport.LowerTransportType.TCP)) { sending_rtp_via_tcp = true; } } else if (mediaType == Media.MediaTypes.video) { if ((_videoClientTransport != null) && (_videoClientTransport.LowerTransport == Rtsp.Messages.RtspTransport.LowerTransportType.TCP)) { sending_rtp_via_tcp = true; } } else { return; } if (sending_rtp_via_tcp == false && ((now - _timeSinceLastRtspKeepAlive).TotalSeconds > timeout_in_seconds) && ((now - _timeSinceLastRtcpKeepAlive).TotalSeconds > timeout_in_seconds) ) { _logger.Info($"{Id} Removing session " + _audioSessionId + " due to TIMEOUT"); CloseConnection("timeout"); return; } // Only process Sessions in Play Mode if (Play == false) { return; } RtspTransport clientTransport; RtspTransport transportReply; String sessionId; UDPSocket udpPair; ushort sequenceNumber; if (mediaType == Media.MediaTypes.audio) { clientTransport = _audioClientTransport; transportReply = _audioTransportReply; sessionId = _audioSessionId; udpPair = _audioUdpPair; sequenceNumber = _audioSequenceNumber; _audioSequenceNumber++; } else if (mediaType == Media.MediaTypes.video) { clientTransport = _videoClientTransport; transportReply = _videoTransportReply; sessionId = _videoSessionId; udpPair = _videoUdpPair; sequenceNumber = _videoSequenceNumber; _videoSequenceNumber++; } else { return; } if (clientTransport == null) { return; } String connection_type = ""; if (clientTransport.LowerTransport == Rtsp.Messages.RtspTransport.LowerTransportType.TCP) { connection_type = "TCP"; } if (clientTransport.LowerTransport == Rtsp.Messages.RtspTransport.LowerTransportType.UDP && clientTransport.IsMulticast == false) { connection_type = "UDP"; } if (clientTransport.LowerTransport == Rtsp.Messages.RtspTransport.LowerTransportType.UDP && clientTransport.IsMulticast == true) { connection_type = "Multicast"; } _logger.Trace($"{Id} Sending {mediaType} session " + sessionId + " " + connection_type + " Sequence=" + sequenceNumber); // There could be more than 1 RTP packet (if the data is fragmented) Boolean write_error = false; // Send as RTP over RTSP (Interleaved) if (transportReply.LowerTransport == Rtsp.Messages.RtspTransport.LowerTransportType.TCP) { int channel = transportReply.Interleaved.First; // second is for RTCP status messages) object state = new object(); try { // send the whole NAL. With RTP over RTSP we do not need to Fragment the NAL (as we do with UDP packets or Multicast) //session.listener.BeginSendData(video_channel, rtp_packet, new AsyncCallback(session.listener.EndSendData), state); _listener.SendData(channel, data); } catch { _logger.Error($"{Id} Error writing to listener " + _listener.RemoteAdress); write_error = true; return; } } // Send as RTP over UDP if (transportReply.LowerTransport == Rtsp.Messages.RtspTransport.LowerTransportType.UDP && transportReply.IsMulticast == false) { try { // send the whole NAL. ** We could fragment the RTP packet into smaller chuncks that fit within the MTU // Send to the IP address of the Client // Send to the UDP Port the Client gave us in the SETUP command udpPair.Write_To_Data_Port(data, _clientHostname, clientTransport.ClientPort.First); } catch (Exception e) { _logger.Error($"{Id} UDP Write Exception " + e.ToString()); _logger.Error($"{Id} Error writing to listener " + _listener.RemoteAdress); write_error = true; return; } } // TODO. Add Multicast if (false == _videoDataSendStartInformed && mediaType == Media.MediaTypes.video) { _videoDataSendStartInformed = true; _logger.Info($"Connection {Id} started to send video over {connection_type}"); } if (false == _audioDataSendStartInformed && mediaType == Media.MediaTypes.audio) { _audioDataSendStartInformed = true; _logger.Info($"Connection {Id} started to send audio over {connection_type}"); } if (write_error) { _logger.Info($"{Id} Removing session " + _audioSessionId + " due to write error"); CloseConnection("write error"); } }
public void KeepType(Media.MediaTypes type, List <Media.Media> list) { int lol = list.RemoveAll(med => med.Type != type); }