Beispiel #1
0
        public override async Task <int> CreateStream(PlaylistItem playlistItem, BassFlags flags)
#endif
        {
            if (!flags.HasFlag(BassFlags.DSDRaw))
            {
#if NET40
                return(base.CreateStream(playlistItem, flags));
#else
                return(await base.CreateStream(playlistItem, flags).ConfigureAwait(false));
#endif
            }
#if NET40
            this.Semaphore.Wait();
#else
            await this.Semaphore.WaitAsync().ConfigureAwait(false);
#endif
            try
            {
                var channelHandle = default(int);
                if (this.Output != null && this.Output.PlayFromMemory)
                {
                    channelHandle = BassDsdInMemoryHandler.CreateStream(playlistItem.FileName, 0, 0, flags);
                    if (channelHandle == 0)
                    {
                        Logger.Write(this, LogLevel.Warn, "Failed to load file into memory: {0}", playlistItem.FileName);
                    }
                }
                else
                {
                    channelHandle = BassDsd.CreateStream(playlistItem.FileName, 0, 0, flags);
                }
                if (channelHandle != 0)
                {
                    var query    = this.BassStreamPipelineFactory.QueryPipeline();
                    var channels = BassUtils.GetChannelCount(channelHandle);
                    var rate     = BassUtils.GetChannelDsdRate(channelHandle);
                    if (query.OutputChannels < channels || !query.OutputRates.Contains(rate))
                    {
                        Logger.Write(this, LogLevel.Warn, "DSD format {0}:{1} is unsupported, the stream will be unloaded. This warning is expensive, please don't attempt to play unsupported DSD.", rate, channels);
                        this.FreeStream(playlistItem, channelHandle);
                        channelHandle = 0;
                    }
                }
#if NET40
                return(TaskEx.FromResult(channelHandle));
#else
                return(channelHandle);
#endif
            }
            finally
            {
                this.Semaphore.Release();
            }
        }
        protected virtual bool IsFormatSupported(PlaylistItem playlistItem, int channelHandle)
        {
            var query    = this.BassStreamPipelineFactory.QueryPipeline();
            var channels = BassUtils.GetChannelCount(channelHandle);
            var rate     = BassUtils.GetChannelDsdRate(channelHandle);

            if (query.OutputChannels < channels || !query.OutputRates.Contains(rate))
            {
                Logger.Write(this, LogLevel.Warn, "DSD format {0}:{1} is unsupported, the stream will be unloaded. This warning is expensive, please don't attempt to play unsupported DSD.", rate, channels);
                return(false);
            }
            return(true);
        }
        public override bool CheckFormat(BassOutputStream stream)
        {
            var rate     = default(int);
            var channels = default(int);

            if (BassUtils.GetChannelDsdRaw(stream.ChannelHandle))
            {
                rate     = BassUtils.GetChannelDsdRate(stream.ChannelHandle);
                channels = BassUtils.GetChannelCount(stream.ChannelHandle);
            }
            else
            {
                rate     = BassUtils.GetChannelPcmRate(stream.ChannelHandle);
                channels = BassUtils.GetChannelCount(stream.ChannelHandle);
            }
            return(this.Rate == rate && this.Channels == channels);
        }