private void Stream_HeaderEvent(IHeaderPacket obj) { switch (_vType) { case VideoDeviceType.Hikv: { HikHeaderPacket hhp = obj as HikHeaderPacket; if (hhp != null) { CurrentHeader = new HikvStreamHeader(hhp.Buffer); OnStreamHeaderRecieved(CurrentHeader); } } break; case VideoDeviceType.Ffmpeg: { FfmpegHeaderPacket fhp = obj as FfmpegHeaderPacket; if (fhp != null) { CurrentHeader = new FfmpegStreamHeader(fhp.CodecID, fhp.Buffer); OnStreamHeaderRecieved(CurrentHeader); } } break; default: break; } }
private void _client_ReceiveCompleted(object sender, ReceiveEventArgs args) { try { if (args.ByteLenght >= 4) { int code = BitConverter.ToInt32(args.ReceivedBytes, 0); switch (code) { case StreamEntityCode.FfmpegHeader: { CurrentHeader = FfmpegStreamHeader.DeserializeTo(args.ReceivedBytes); OnStreamHeaderRecieved(CurrentHeader); } break; case StreamEntityCode.HikvHeader: { CurrentHeader = HikvStreamHeader.DeserializeTo(args.ReceivedBytes); OnStreamHeaderRecieved(CurrentHeader); } break; case StreamEntityCode.StreamData: { OnStreamDataReceived(StreamData.DeserializeTo(args.ReceivedBytes)); } break; case StreamEntityCode.RemoteError: { RemoteError re = RemoteError.DeserializeTo(args.ReceivedBytes); OnErrorOccurred(new ErrorEventArgs(re.ErrorMessage, ErrorTypes.Receive)); } break; } } } catch (Exception e) { OnErrorOccurred(new ErrorEventArgs($"从远程流媒体服务器获取到异常数据:{e.Message}", ErrorTypes.Receive)); } }