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); }
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); }
public void Register() { lock (base.SyncRoot) { if (!this._isRegistered) { IStreamFilenameGenerator generator = ObjectFactory.CreateInstance(this._appConfig.StreamFilenameGenerator.Type) as IStreamFilenameGenerator; base.AddService(typeof(IStreamFilenameGenerator), generator, false); generator.Start(this._appConfig.StreamFilenameGenerator); ISharedObjectService service = ObjectFactory.CreateInstance(this._appConfig.SharedObjectServiceConfiguration.Type) as ISharedObjectService; base.AddService(typeof(ISharedObjectService), service, false); service.Start(this._appConfig.SharedObjectServiceConfiguration); IProviderService service2 = ObjectFactory.CreateInstance(this._appConfig.ProviderServiceConfiguration.Type) as IProviderService; base.AddService(typeof(IProviderService), service2, false); service2.Start(this._appConfig.ProviderServiceConfiguration); IConsumerService service3 = ObjectFactory.CreateInstance(this._appConfig.ConsumerServiceConfiguration.Type) as IConsumerService; base.AddService(typeof(IConsumerService), service3, false); service3.Start(this._appConfig.ConsumerServiceConfiguration); IStreamService service4 = ObjectFactory.CreateInstance(this._appConfig.StreamService.Type) as IStreamService; base.AddService(typeof(IStreamService), service4, false); service4.Start(this._appConfig.StreamService); if (this._appConfig.SharedObjectSecurityService.Type != null) { ISharedObjectSecurityService service5 = ObjectFactory.CreateInstance(this._appConfig.SharedObjectSecurityService.Type) as ISharedObjectSecurityService; base.AddService(typeof(ISharedObjectSecurityService), service5, false); service5.Start(this._appConfig.SharedObjectSecurityService); } base.Init(); base._keepOnDisconnect = true; this._isRegistered = true; } } }
/// <summary> /// Saves broadcasted stream. /// </summary> /// <param name="name"></param> /// <param name="isAppend"></param> public void SaveAs(string name, bool isAppend) { if (log.IsDebugEnabled) { log.Debug("SaveAs - name: " + name + " append: " + isAppend); } // Get stream scope IStreamCapableConnection connection = this.Connection; if (connection == null) { // TODO: throw other exception here? throw new IOException("Stream is no longer connected"); } IScope scope = connection.Scope; // Get stream filename generator IStreamFilenameGenerator generator = ScopeUtils.GetScopeService(scope, typeof(IStreamFilenameGenerator)) as IStreamFilenameGenerator; // Generate filename string filename = generator.GenerateFilename(scope, name, ".flv", GenerationType.RECORD); // Get file for that filename FileInfo file; if (generator.ResolvesToAbsolutePath) { file = new FileInfo(filename); } else { file = scope.Context.GetResource(filename).File; } // If append mode is on... if (!isAppend) { if (file.Exists) { // Per livedoc of FCS/FMS: // When "live" or "record" is used, // any previously recorded stream with the same stream URI is deleted. file.Delete(); } } else { if (!file.Exists) { // Per livedoc of FCS/FMS: // If a recorded stream at the same URI does not already exist, // "append" creates the stream as though "record" was passed. isAppend = false; } } //Requery file = new FileInfo(file.FullName); if (!file.Exists) { // Make sure the destination directory exists string directory = Path.GetDirectoryName(file.FullName); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } } if (!file.Exists) { using (FileStream fs = file.Create()) { } } if (log.IsDebugEnabled) { log.Debug("Recording file: " + file.FullName); } _recordingFile = new FileConsumer(scope, file); #if !(NET_1_1) Dictionary <string, object> parameterMap = new Dictionary <string, object>(); #else Hashtable parameterMap = new Hashtable(); #endif if (isAppend) { parameterMap.Add("mode", "append"); } else { parameterMap.Add("mode", "record"); } _recordPipe.Subscribe(_recordingFile, parameterMap); _recording = true; _recordingFilename = filename; }
/// <summary> /// Saves the broadcast stream as a file. /// </summary> /// <param name="name">The path of the file relative to the scope.</param> /// <param name="isAppend">Whether to append to the end of file.</param> public void SaveAs(string name, bool isAppend) { try { IScope scope = this.Scope; IStreamFilenameGenerator generator = ScopeUtils.GetScopeService(scope, typeof(IStreamFilenameGenerator)) as IStreamFilenameGenerator; string filename = generator.GenerateFilename(scope, name, ".flv", GenerationType.RECORD); // Get file for that filename FileInfo file; if (generator.ResolvesToAbsolutePath) { file = new FileInfo(filename); } else { file = scope.Context.GetResource(filename).File; } if (!isAppend) { if (file.Exists) { // Per livedoc of FCS/FMS: // When "live" or "record" is used, // any previously recorded stream with the same stream URI is deleted. file.Delete(); } } else { if (!file.Exists) { // Per livedoc of FCS/FMS: // If a recorded stream at the same URI does not already exist, // "append" creates the stream as though "record" was passed. isAppend = false; } } if (!file.Exists) { // Make sure the destination directory exists string directory = Path.GetDirectoryName(file.FullName); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } } if (!file.Exists) { using (FileStream fs = file.Create()) { } } FileConsumer fc = new FileConsumer(scope, file); #if !(NET_1_1) Dictionary <string, object> parameterMap = new Dictionary <string, object>(); #else Hashtable parameterMap = new Hashtable(); #endif if (isAppend) { parameterMap.Add("mode", "append"); } else { parameterMap.Add("mode", "record"); } if (null == _recordPipe) { _recordPipe = new InMemoryPushPushPipe(); } _recordPipe.Subscribe(fc, parameterMap); _recordingFilename = filename; } catch (IOException ex) { log.Error("Save as exception", ex); } }
public void SaveAs(string name, bool isAppend) { FileInfo file; if (log.get_IsDebugEnabled()) { log.Debug(string.Concat(new object[] { "SaveAs - name: ", name, " append: ", isAppend })); } IStreamCapableConnection connection = base.Connection; if (connection == null) { throw new IOException("Stream is no longer connected"); } IScope scope = connection.Scope; IStreamFilenameGenerator scopeService = ScopeUtils.GetScopeService(scope, typeof(IStreamFilenameGenerator)) as IStreamFilenameGenerator; string fileName = scopeService.GenerateFilename(scope, name, ".flv", GenerationType.RECORD); if (scopeService.ResolvesToAbsolutePath) { file = new FileInfo(fileName); } else { file = scope.Context.GetResource(fileName).File; } if (!isAppend) { if (file.Exists) { file.Delete(); } } else if (!file.Exists) { isAppend = false; } file = new FileInfo(file.FullName); if (!file.Exists) { string directoryName = Path.GetDirectoryName(file.FullName); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } } if (!file.Exists) { using (file.Create()) { } } if (log.get_IsDebugEnabled()) { log.Debug("Recording file: " + file.FullName); } this._recordingFile = new FileConsumer(scope, file); Dictionary <string, object> parameterMap = new Dictionary <string, object>(); if (isAppend) { parameterMap.Add("mode", "append"); } else { parameterMap.Add("mode", "record"); } this._recordPipe.Subscribe(this._recordingFile, parameterMap); this._recording = true; this._recordingFilename = fileName; }