public override bool Wrap(IBassStreamProvider provider, int channelHandle, IEnumerable <IBassStreamAdvice> advice, BassFlags flags, out IBassStream stream) { var offset = default(long); var length = default(long); if (this.Offset != TimeSpan.Zero) { offset = Bass.ChannelSeconds2Bytes(channelHandle, this.Offset.TotalSeconds); } if (this.Length != TimeSpan.Zero) { length = Bass.ChannelSeconds2Bytes(channelHandle, this.Length.TotalSeconds); } if (offset != 0 || length != 0) { if (length == 0) { length = Bass.ChannelGetLength(channelHandle, PositionFlags.Bytes) - offset; } stream = new BassStream( provider, BassSubstream.CreateStream(channelHandle, offset, length, flags), length, advice, flags ); return(true); } stream = null; return(false); }
public BassStream(IBassStreamProvider provider, int channelHandle, long length, IEnumerable <IBassStreamAdvice> advice, BassFlags flags) : this() { this.Provider = provider; this.ChannelHandle = channelHandle; this.Length = length; this.Advice = advice; this.Flags = flags; }
public IEnumerable <IBassStreamAdvice> GetAdvice(IBassStreamProvider provider, PlaylistItem playlistItem) { var advice = new List <IBassStreamAdvice>(); foreach (var advisor in this.Advisors) { advisor.Advise(provider, playlistItem, advice); } return(advice.ToArray()); }
protected virtual bool TryGetSilence(IBassStreamProvider provider, PlaylistItem playlistItem, IEnumerable <IBassStreamAdvice> advice, out TimeSpan leadIn, out TimeSpan leadOut) { if (this.TryGetMetaData(this.Behaviour, playlistItem, out leadIn, out leadOut)) { return(true); } if (!this.TryCalculateSilence(provider, playlistItem, advice, out leadIn, out leadOut)) { return(false); } //Have to copy as cannot pass out parameter to lambda expression. var _leadIn = leadIn; var _leadOut = leadOut; this.Dispatch(() => this.UpdateMetaData(playlistItem, _leadIn, _leadOut)); return(true); }
public override void Advise(IBassStreamProvider provider, PlaylistItem playlistItem, IList <IBassStreamAdvice> advice) { if (this.Behaviour == null || !this.Behaviour.Enabled) { return; } var leadIn = default(TimeSpan); var leadOut = default(TimeSpan); try { if (!this.TryGetSilence(provider, playlistItem, advice, out leadIn, out leadOut)) { return; } advice.Add(new BassSkipSilenceStreamAdvice(playlistItem.FileName, leadIn, leadOut)); } catch (Exception e) { Logger.Write(this, LogLevel.Warn, "Failed to create stream advice for file \"{0}\": {1}", playlistItem.FileName, e.Message); } }
public override void Advise(IBassStreamProvider provider, PlaylistItem playlistItem, IList <IBassStreamAdvice> advice) { if (this.Behaviour == null || !this.Behaviour.Enabled) { return; } var fileName = default(string); var offset = default(string); var length = default(string); try { if (!ParseUrl(playlistItem.FileName, out fileName, out offset, out length)) { return; } advice.Add(new BassCueStreamAdvice(fileName, offset, length)); } catch (Exception e) { Logger.Write(this, LogLevel.Warn, "Failed to create stream advice for file \"{0}\": {1}", playlistItem.FileName, e.Message); } }
public void Register(IBassStreamProvider provider) { this.Providers.Add(provider.Priority, provider); Logger.Write(this, LogLevel.Debug, "Registered bass stream provider with priority {0}: {1}", provider.Priority, provider.GetType().Name); }
public abstract bool Wrap(IBassStreamProvider provider, int channelHandle, IEnumerable <IBassStreamAdvice> advice, BassFlags flags, out IBassStream stream);
public BassStream(IBassStreamProvider provider, int channelHandle) : this() { this.Provider = provider; this.ChannelHandle = channelHandle; }
public abstract void Advise(IBassStreamProvider provider, PlaylistItem playlistItem, IList <IBassStreamAdvice> advice);
public void Register(IBassStreamProvider provider) { this.Providers.Add(provider); Logger.Write(this, LogLevel.Debug, "Registered bass stream provider \"{0}\".", provider.GetType().Name); }
public BassOutputStream(IBassOutput output, IBassStreamPipelineManager manager, IBassStreamProvider provider, PlaylistItem playlistItem, int channelHandle) : base(playlistItem) { this.Output = output; this.Manager = manager; this.Provider = provider; this.ChannelHandle = channelHandle; if (!ActiveStreams.TryAdd(playlistItem, this)) { //TODO: Warn. } }
protected virtual bool TryCalculateSilence(IBassStreamProvider provider, PlaylistItem playlistItem, IEnumerable <IBassStreamAdvice> advice, out TimeSpan leadIn, out TimeSpan leadOut) { if (provider.Flags.HasFlag(BassStreamProviderFlags.Serial)) { Logger.Write(this, LogLevel.Debug, "Cannot calculate lead in/out for file \"{0}\": The provider does not support this action.", playlistItem.FileName); leadIn = default(TimeSpan); leadOut = default(TimeSpan); return(false); } Logger.Write(this, LogLevel.Debug, "Attempting to calculate lead in/out for file \"{0}\".", playlistItem.FileName); var stream = provider.CreateBasicStream(playlistItem, advice, BassFlags.Decode | BassFlags.Byte); if (stream.IsEmpty) { Logger.Write(this, LogLevel.Warn, "Failed to create stream for file \"{0}\": {1}", playlistItem.FileName, Enum.GetName(typeof(Errors), Bass.LastError)); leadIn = default(TimeSpan); leadOut = default(TimeSpan); return(false); } try { var leadInBytes = this.GetLeadIn(stream, this.Behaviour.Threshold); if (leadInBytes == -1) { Logger.Write(this, LogLevel.Warn, "Failed to calculate lead in for file \"{0}\": Track was considered silent.", playlistItem.FileName); leadIn = default(TimeSpan); leadOut = default(TimeSpan); return(false); } var leadOutBytes = this.GetLeadOut(stream, this.Behaviour.Threshold); if (leadOutBytes == -1) { Logger.Write(this, LogLevel.Warn, "Failed to calculate lead out for file \"{0}\": Track was considered silent.", playlistItem.FileName); leadIn = default(TimeSpan); leadOut = default(TimeSpan); return(false); } leadIn = TimeSpan.FromSeconds( Bass.ChannelBytes2Seconds( stream.ChannelHandle, leadInBytes ) ); leadOut = TimeSpan.FromSeconds( Bass.ChannelBytes2Seconds( stream.ChannelHandle, leadOutBytes ) ); Logger.Write(this, LogLevel.Debug, "Successfully calculated lead in/out for file \"{0}\": {1}/{2}", playlistItem.FileName, leadIn, leadOut); return(true); } finally { provider.FreeStream(playlistItem, stream.ChannelHandle); } }