Ejemplo n.º 1
0
        /// <summary>
        /// Gets a stream for the resource which is described by this file handle if the stream is already open or opens a new stream for it.
        /// </summary>
        /// <returns>
        /// This method returns the same stream for the same thread; it returns a new stream for a new thread.
        /// </returns>
        public Stream GetOrOpenStream()
        {
            Thread currentThread = Thread.CurrentThread;
            Stream stream;

            lock (_syncObj)
                if (_threadStreams.TryGetValue(currentThread, out stream))
                {
                    return(stream);
                }

            IResourceAccessor resourceAccessor = _resource.ResourceAccessor;

            try
            {
                if (resourceAccessor != null)
                {
                    resourceAccessor.PrepareStreamAccess();
                    lock (_syncObj)
                        return(_threadStreams[currentThread] = resourceAccessor.OpenRead());
                }
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn("Dokan FileHandle: Error creating stream for resource '{0}'", e, resourceAccessor);
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an <see cref="IInputSource"/> object for a given mediaitem.
        /// </summary>
        /// <param name="resourceLocator">Locator instance to the media item to create the input source for.</param>
        /// <param name="mimeType">Mime type of the media item, if present. May be <c>null</c>.</param>
        /// <returns>Input source object for the given <paramref name="resourceLocator"/> or <c>null</c>, if no input source
        /// could be created.</returns>
        public IInputSource CreateInputSource(IResourceLocator resourceLocator, string mimeType)
        {
            if (!CanPlay(resourceLocator, mimeType))
            {
                return(null);
            }
            IResourceAccessor       accessor = resourceLocator.CreateAccessor();
            IInputSource            result;
            AudioCDResourceAccessor acdra = accessor as AudioCDResourceAccessor;

            if (acdra != null)
            {
                result = BassCDTrackInputSource.Create(acdra.Drive, acdra.TrackNo);
            }
            else
            {
                string filePath = accessor.ResourcePathName;
                if (URLUtils.IsCDDA(filePath))
                {
                    ILocalFsResourceAccessor lfra = accessor as ILocalFsResourceAccessor;
                    if (lfra == null)
                    {
                        return(null);
                    }
                    result = BassFsCDTrackInputSource.Create(lfra.LocalFileSystemPath);
                }
                else if (URLUtils.IsMODFile(filePath))
                {
                    result = BassMODFileInputSource.Create(accessor);
                }
                else
                {
                    result = BassAudioFileInputSource.Create(accessor);
                }
                // TODO: Handle web streams when we have resource accessors for web URLs: BassWebStreamInputSource.Create(...);
            }

            accessor.PrepareStreamAccess();

            Log.Debug("InputSourceFactory: Creating input source for media resource '{0}' of type '{1}'", accessor, result.GetType());
            return(result);
        }