Пример #1
0
        /// <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;
        }
Пример #2
0
        /// <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);
            }
        }