public ChannelControlMessage(ChannelControlType type) { Header = new RtpHeader() { PayloadType = NanoPayloadType.ChannelControl }; Type = type; }
private static ISerializableLE CreateFromControlType(ChannelControlType controlType) { var type = ChannelControlTypeAttribute.GetTypeForMessageType(controlType); if (type == null) { return(null); } return((ISerializableLE)Activator.CreateInstance(type)); }
private static INanoPacket CreateFromChannelControlType(ChannelControlType controlType) { switch (controlType) { case ChannelControlType.Create: return(new ChannelCreate()); case ChannelControlType.Open: return(new ChannelOpen()); case ChannelControlType.Close: return(new ChannelClose()); default: throw new NanoPackingException($"Invalid ChannelControlType: {controlType}"); } }
private Result ChannelEndCallback(IntPtr channelraw, ChannelControlType controltype, ChannelControlCallbackType type, IntPtr commanddata1, IntPtr commanddata2) { if (type == ChannelControlCallbackType.Syncpoint) { _fmodSound?.GetSyncPointInfo(_last15SyncPoint, new StringBuilder("songabouttoend"), 0, out _last15Offset, TimeUnit.Ms); uint last5Offset = 0; _fmodSound?.GetSyncPointInfo(_last5SyncPoint, new StringBuilder("fade"), 0, out last5Offset, TimeUnit.Ms); if (_position >= _fmodSound?.LengthInMilliseconds) { MediaEnded?.Invoke(this, new MediaEndedEventArgs(PlayerState.Ended)); } else if (_position >= last5Offset) { _fmodChannel.SetFadePoint(_fmodChannel.Volume, 0f, _fmodChannel.GetTotalSamplesLeft(_fmodSound)); } else if (_position >= _last15Offset && _position < last5Offset) { MediaAboutToEnd?.Invoke(this, new MediaAboutToEndEventArgs(CurrentlyPlayingFile)); } } return(Result.Ok); }
public ChannelControlTypeAttribute(ChannelControlType messageType) { MessageType = messageType; }
public static Type GetTypeForMessageType(ChannelControlType messageType) { return(_typeMapping.GetTypeForKey(messageType)); }
public ChannelControl(ChannelControlType type, ISerializableLE data) { Type = type; Data = data; }
public void Deserialize(EndianReader reader) { Type = (ChannelControlType)reader.ReadUInt32LE(); DeserializeData(reader); }
public void Deserialize(BinaryReader reader) { Type = (ChannelControlType)reader.ReadUInt32(); DeserializeData(reader); }
/// <summary> /// 同步通道会议信息 /// </summary> /// <param name="channelNo">通道号码</param> /// <param name="confNo">会议号</param> private SmcErr SyncChannelConfAccessCode(string channelLabel, string confAccessCode, ChannelControlType controlType) { SmcErr err = new SmcErr(); NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); string oldConfAccessCode = string.Empty; logEx.Trace("SyncChannelConfAccessCode Start. input channelLabel:{0}, ConfAccessCode:{1}, ControlType:{2}.", channelLabel, confAccessCode, controlType); if ((this.monitorChannelRelationDic.ContainsKey(channelLabel) && controlType == ChannelControlType.Add) || (!this.monitorChannelRelationDic.ContainsKey(channelLabel) && controlType != ChannelControlType.Add)) { err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_INPUT_ERROR); logEx.Trace("SyncChannelConfAccessCode input error channelLabel:{0}, ConfAccessCode:{1}, ControlType:{2}.", channelLabel, confAccessCode, controlType); return err; } // 判断是否需要添加通道 if (ChannelControlType.Add == controlType) { // 通道关系字典添加一个通道 this.monitorChannelRelationDic.Add(channelLabel, new MonitorChannelRelation(channelLabel)); // 通道字典添加一个新通道 this.monitorChannelManager.AddChannel(channelLabel); // 判断需要切换的会议号是否为空 if (!string.IsNullOrEmpty(confAccessCode)) { // 添加通道到软终端 this.monitorChannelManager.AddSotChannel(channelLabel, confAccessCode); this.monitorChannelRelationDic[channelLabel].ConfAccessCode = confAccessCode; } logEx.Trace("SyncChannelConfAccessCode add channel:{0} successfully.", channelLabel); } else if (ChannelControlType.None == controlType) { oldConfAccessCode = this.monitorChannelRelationDic[channelLabel].ConfAccessCode; if (string.IsNullOrEmpty(oldConfAccessCode)) // 判断本地通道号码是否入会 { // 判断需要切换的会议号是否为空 if (!string.IsNullOrEmpty(confAccessCode)) { // 添加通道到软终端 this.monitorChannelManager.AddSotChannel(channelLabel, confAccessCode); this.monitorChannelRelationDic[channelLabel].ConfAccessCode = confAccessCode; } } else { // 判断需要切换的会议号是否为空 if (!string.IsNullOrEmpty(confAccessCode)) { if (confAccessCode == oldConfAccessCode) { logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] is same.", oldConfAccessCode, confAccessCode); return err; } // 关闭视频码流 //err = this.SwitchChannelVideo(channelLabel, string.Empty); err = this.StopCameraRtpAudio(channelLabel); if (!err.IsSuccess()) { logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] stoprtp failed.", oldConfAccessCode, confAccessCode); return err; } // 软终端删除该通道 this.monitorChannelManager.RemoveSotChannel(channelLabel); // 软终端重新添加该通道 this.monitorChannelManager.AddSotChannel(channelLabel, confAccessCode); } else { // 关闭视频码流 //err = this.SwitchChannelVideo(channelLabel, string.Empty); err = this.StopCameraRtpAudio(channelLabel); if (!err.IsSuccess()) { logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] stoprtp failed.", oldConfAccessCode, confAccessCode); return err; } // 软终端删除该通道 this.monitorChannelManager.RemoveSotChannel(channelLabel); } this.monitorChannelRelationDic[channelLabel].ConfAccessCode = confAccessCode; } } else { oldConfAccessCode = this.monitorChannelRelationDic[channelLabel].ConfAccessCode; if (!string.IsNullOrEmpty(oldConfAccessCode)) { // 关闭视频码流 //err = this.SwitchChannelVideo(channelLabel, string.Empty); err = this.StopCameraRtpAudio(channelLabel); if (!err.IsSuccess()) { logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] stoprtp failed.", oldConfAccessCode, confAccessCode); return err; } // 软终端删除该通道 this.monitorChannelManager.RemoveSotChannel(channelLabel); this.monitorChannelRelationDic[channelLabel].ConfAccessCode = string.Empty; } // 通道关系字典删除该通道 if (this.monitorChannelRelationDic.ContainsKey(channelLabel)) { this.monitorChannelRelationDic.Remove(channelLabel); } // 通道字典删除该通道 this.monitorChannelManager.RemoveChannel(channelLabel); logEx.Trace("SyncChannelConfAccessCode remove channel:{0} successfully.", channelLabel); } logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] successfully.", oldConfAccessCode, confAccessCode); return err; }
public static INanoPacket ParsePacket(byte[] data, NanoChannelContext context) { EndianReader packetReader = new EndianReader(data); RtpHeader header = new RtpHeader(); header.Deserialize(packetReader); NanoPayloadType payloadType = header.PayloadType; // It might be NanoChannel.Unknown at this point, if ChannelCreate // packet was not processed yet // It gets processed at the end of the function NanoChannel channel = context.GetChannel(header.ChannelId); INanoPacket packet = null; long payloadOffset = packetReader.Position; switch (payloadType) { // FIXME: Create from Attribute is broken case NanoPayloadType.UDPHandshake: packet = new UdpHandshake(); break; case NanoPayloadType.ControlHandshake: packet = new ControlHandshake(); break; case NanoPayloadType.ChannelControl: // Read type to pinpoint exact payload ChannelControlType cct = (ChannelControlType)packetReader.ReadUInt32LE(); packet = CreateFromChannelControlType(cct); break; case NanoPayloadType.Streamer: packet = CreateFromStreamerHeader(packetReader, channel); break; default: throw new NanoPackingException( $"Unknown packet type received: {payloadType}"); } if (packet == null) { throw new NanoPackingException("Failed to find matching body for packet"); } packetReader.Seek(payloadOffset, SeekOrigin.Begin); packet.Deserialize(packetReader); packet.Header = header; if (packet as ChannelCreate != null) { string channelName = ((ChannelCreate)packet).Name; channel = NanoChannelClass.GetIdByClassName(channelName); } if (channel == NanoChannel.Unknown) { throw new NanoPackingException("ParsePacket: INanoPacket.Channel is UNKNOWN"); } packet.Channel = channel; return(packet); }