예제 #1
0
        private FileInfo GetStreamFile(IScope scope, string name)
        {
            IStreamableFileFactory scopeService = ScopeUtils.GetScopeService(scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory;

            if ((name.IndexOf(':') == -1) && (name.IndexOf('.') == -1))
            {
                name = "flv:" + name;
            }
            log.Info(string.Concat(new object[] { "GetStreamFile factory: ", scopeService, " name: ", name }));
            foreach (IStreamableFileService service in scopeService.GetServices())
            {
                if (name.StartsWith(service.Prefix + ':'))
                {
                    name = service.PrepareFilename(name);
                    break;
                }
            }
            IStreamFilenameGenerator generator = ScopeUtils.GetScopeService(scope, typeof(IStreamFilenameGenerator)) as IStreamFilenameGenerator;
            string fileName = generator.GenerateFilename(scope, name, GenerationType.PLAYBACK);

            if (generator.ResolvesToAbsolutePath)
            {
                return(new FileInfo(fileName));
            }
            return(scope.Context.GetResource(fileName).File);
        }
예제 #2
0
        private FileInfo GetStreamFile(IScope scope, String name)
        {
            IStreamableFileFactory factory = ScopeUtils.GetScopeService(scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory;

            if (name.IndexOf(':') == -1 && name.IndexOf('.') == -1)
            {
                // Default to .flv files if no prefix and no extension is given.
                name = "flv:" + name;
            }
            log.Info("GetStreamFile factory: " + factory + " name: " + name);
            foreach (IStreamableFileService service in factory.GetServices())
            {
                if (name.StartsWith(service.Prefix + ':'))
                {
                    name = service.PrepareFilename(name);
                    break;
                }
            }
            IStreamFilenameGenerator filenameGenerator = ScopeUtils.GetScopeService(scope, typeof(IStreamFilenameGenerator)) as IStreamFilenameGenerator;
            string   filename = filenameGenerator.GenerateFilename(scope, name, GenerationType.PLAYBACK);
            FileInfo file;

            if (filenameGenerator.ResolvesToAbsolutePath)
            {
                file = new FileInfo(filename);
            }
            else
            {
                file = scope.Context.GetResource(filename).File;
            }
            return(file);
        }
예제 #3
0
        private void Init()
        {
            IStreamableFileFactory scopeService = ScopeUtils.GetScopeService(this._scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory;
            string directoryName = Path.GetDirectoryName(this._file.FullName);

            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }
            if (!this._file.Exists)
            {
                using (this._file.Create())
                {
                }
            }
            IStreamableFile streamableFile = scopeService.GetService(this._file).GetStreamableFile(this._file);

            if ((this._mode == null) || this._mode.Equals("record"))
            {
                this._writer = streamableFile.GetWriter();
            }
            else
            {
                if (!this._mode.Equals("append"))
                {
                    throw new NotSupportedException("Illegal mode type: " + this._mode);
                }
                this._writer = streamableFile.GetAppendWriter();
            }
        }
예제 #4
0
        public void Register()
        {
            IStreamableFileFactory factory = ObjectFactory.CreateInstance(FluorineConfiguration.Instance.FluorineSettings.StreamableFileFactory.Type) as IStreamableFileFactory;

            base.AddService(typeof(IStreamableFileFactory), factory, false);
            factory.Start(null);
            SchedulingService service = new SchedulingService();

            base.AddService(typeof(ISchedulingService), service, false);
            service.Start(null);
            IBWControlService service2 = ObjectFactory.CreateInstance(FluorineConfiguration.Instance.FluorineSettings.BWControlService.Type) as IBWControlService;

            base.AddService(typeof(IBWControlService), service2, false);
            service2.Start(null);
            base.Init();
        }
예제 #5
0
        /// <summary>
        /// Returns stream length. Method added to get flv player to work.
        /// </summary>
        /// <param name="name">Stream name.</param>
        /// <returns>Returns the length of a stream, in seconds.</returns>
        public double getStreamLength(string name)
        {
            double           duration = 0;
            IProviderService provider = ScopeUtils.GetScopeService(this.Scope, typeof(IProviderService)) as IProviderService;
            FileInfo         file     = provider.GetVODProviderFile(this.Scope, name);

            if (file != null)
            {
                IStreamableFileFactory factory = (IStreamableFileFactory)ScopeUtils.GetScopeService(this.Scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory;
                IStreamableFileService service = factory.GetService(file);
                if (service != null)
                {
                    ITagReader reader = null;
                    try
                    {
                        IStreamableFile streamFile = service.GetStreamableFile(file);
                        reader   = streamFile.GetReader();
                        duration = (double)reader.Duration / 1000;
                    }
                    catch (IOException ex)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error(string.Format("Error reading stream file {0}. {1}", file.FullName, ex.Message));
                        }
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                }
                else
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error(string.Format("No service found for {0}", file.FullName));
                    }
                }
                file = null;
            }
            return(duration);
        }
예제 #6
0
        /// <summary>
        /// Initializes file provider. Creates streamable file factory and service, seeks to start position.
        /// </summary>
        private void Init()
        {
            IStreamableFileFactory factory = (IStreamableFileFactory)ScopeUtils.GetScopeService(_scope, typeof(IStreamableFileFactory));
            IStreamableFileService service = factory.GetService(_file);

            if (service == null)
            {
                log.Error("No service found for " + _file.FullName);
                return;
            }
            IStreamableFile streamFile = service.GetStreamableFile(_file);

            _reader = streamFile.GetReader();
            if (_start > 0)
            {
                Seek(_start);
            }
        }
예제 #7
0
        private void Init()
        {
            IStreamableFileFactory factory = ScopeUtils.GetScopeService(_scope, typeof(IStreamableFileFactory)) as IStreamableFileFactory;
            string directory = Path.GetDirectoryName(_file.FullName);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            if (!_file.Exists)
            {
                // Maybe the (previously existing) file has been deleted
                using (FileStream fs = _file.Create()){}
            }

            /*
             * else if (_file.IsReadOnly)
             * {
             * throw new IOException("The file is read-only");
             * }
             */
            IStreamableFileService service = factory.GetService(_file);
            IStreamableFile        flv     = service.GetStreamableFile(_file);

            if (_mode == null || _mode.Equals(Constants.ClientStreamModeRecord))
            {
                _writer = flv.GetWriter();
            }
            else if (_mode.Equals(Constants.ClientStreamModeAppend))
            {
                _writer = flv.GetAppendWriter();
            }
            else
            {
                throw new NotSupportedException("Illegal mode type: " + _mode);
            }
        }