private bool DoConnect(bool startTimer) { this.Server.LastError = StreamingServer.STREAMINGERROR.Ok; this.Server.LastErrorMessage = string.Empty; this._automaticMode = false; bool flag = false; object @lock = this._lock; lock (@lock) { flag = (!this.IsConnected || this.Disconnect()); if (flag) { flag = this.InternalConnect(startTimer); if (!flag) { this.StopEncoder(); this._status = BroadCast.BROADCASTSTATUS.NotConnected; } } else { this._status = BroadCast.BROADCASTSTATUS.NotConnected; } if (this.AutoReconnect) { if (this._retryTimer != null) { this._retryTimer.Change(-1, -1); this._retryTimer.Dispose(); this._retryTimer = null; } if (flag && this.Server.UseBASS) { if (this.Server is WMAcast) { ((EncoderWMA)this.Server.Encoder).WMA_Notify = this._myNotifyProc; } else { Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_ENCODE_CAST_TIMEOUT, (int)this._reconnectTimeout.TotalMilliseconds); BassEnc.BASS_Encode_SetNotify(this.Server.Encoder.EncoderHandle, this._myNotifyProc, IntPtr.Zero); } } else if (startTimer) { this._retryTimer = new Timer(this._retryTimerDelegate, null, this._reconnectTimeout, this._reconnectTimeout); } } } this._isStarted = flag; return(flag); }
private bool Disconnect(bool calledFromReconnectTry) { if (!calledFromReconnectTry) { this.Server.LastError = StreamingServer.STREAMINGERROR.Ok; this.Server.LastErrorMessage = string.Empty; } this._isStarted = calledFromReconnectTry; bool flag = false; object @lock = this._lock; lock (@lock) { flag = this.InternalDisconnect(); if (flag) { if (!calledFromReconnectTry) { this._killAutoReconnectTry = true; if (this._autoReconnectTryRunning) { while (this._autoReconnectTryRunning) { Thread.Sleep(3); } } } if (this._retryTimer != null) { this._retryTimer.Change(-1, -1); this._retryTimer.Dispose(); this._retryTimer = null; } if (this.Server.UseBASS) { if (this.Server is WMAcast) { ((EncoderWMA)this.Server.Encoder).WMA_Notify = null; } else { BassEnc.BASS_Encode_SetNotify(this.Server.Encoder.EncoderHandle, null, IntPtr.Zero); } } } } return(flag); }
public override bool Connect() { if (!base.Encoder.IsActive) { base.LastError = StreamingServer.STREAMINGERROR.Error_EncoderError; base.LastErrorMessage = "Encoder not active!"; return(false); } if (!base.UseBASS) { if (this._socket != null && this._socket.Connected) { this._socket.Close(); this._socket = null; } this._socket = this.CreateSocket(this.ServerAddress, this.ServerPort); return(this._socket != null && this._socket.Connected); } if (this._isConnected) { return(true); } string content = BassEnc.BASS_ENCODE_TYPE_OGG; if (base.Encoder.EncoderType == BASSChannelType.BASS_CTYPE_STREAM_MP3) { content = BassEnc.BASS_ENCODE_TYPE_MP3; } else if (base.Encoder.EncoderType == BASSChannelType.BASS_CTYPE_STREAM_AAC) { content = BassEnc.BASS_ENCODE_TYPE_AAC; } string pass = this.Password; if (!string.IsNullOrEmpty(this.Username) && this.Username.ToLower() != "source") { pass = this.Username + ":" + this.Password; } if (BassEnc.BASS_Encode_CastInit(base.Encoder.EncoderHandle, string.Format("{0}:{1}{2}", this.ServerAddress, this.ServerPort, this.MountPoint), pass, content, this.StreamName, this.StreamUrl, this.StreamGenre, this.StreamDescription, (this.Quality == null) ? null : string.Format("ice-bitrate: {0}\r\n", this.Quality), (this.Quality == null) ? base.Encoder.EffectiveBitrate : 0, this.PublicFlag)) { this._myNotifyProc = new ENCODENOTIFYPROC(this.EncoderNotifyProc); this._isConnected = BassEnc.BASS_Encode_SetNotify(base.Encoder.EncoderHandle, this._myNotifyProc, IntPtr.Zero); } else { base.LastError = StreamingServer.STREAMINGERROR.Error_EncoderError; base.LastErrorMessage = "Encoder not active or a connction to the server could not be established!"; BASSError basserror = Bass.BASS_ErrorGetCode(); if (basserror <= BASSError.BASS_ERROR_HANDLE) { if (basserror != BASSError.BASS_ERROR_UNKNOWN) { if (basserror != BASSError.BASS_ERROR_FILEOPEN) { if (basserror == BASSError.BASS_ERROR_HANDLE) { base.LastError = StreamingServer.STREAMINGERROR.Error_EncoderError; base.LastErrorMessage = "Encoder not active or invalif Encoder used!"; } } else { base.LastError = StreamingServer.STREAMINGERROR.Error_CreatingConnection; base.LastErrorMessage = "Couldn't connect to the server!"; } } else { base.LastError = StreamingServer.STREAMINGERROR.Error_CreatingConnection; base.LastErrorMessage = "An unknown error occurred!"; } } else if (basserror != BASSError.BASS_ERROR_ALREADY) { if (basserror != BASSError.BASS_ERROR_ILLPARAM) { if (basserror == BASSError.BASS_ERROR_CAST_DENIED) { base.LastError = StreamingServer.STREAMINGERROR.Error_Login; base.LastErrorMessage = "Username or Password incorrect!"; } } else { base.LastError = StreamingServer.STREAMINGERROR.Error_ResolvingServerAddress; base.LastErrorMessage = "Couldn't connect to the server or server doesn't include a port number!"; } } else { base.LastError = StreamingServer.STREAMINGERROR.Error_NotConnected; base.LastErrorMessage = "There is already a cast set on the encoder!"; } this._isConnected = false; } return(this._isConnected); }