Ejemplo n.º 1
0
        public override void Start()
        {
            lock (this.SyncRoot)
            {
                IConsumerService consumerManager = this.Scope.GetService(typeof(IConsumerService)) as IConsumerService;
                try
                {
                    //_videoCodecFactory = new VideoCodecFactory();
                    _videoCodecFactory = this.Scope.GetService(typeof(VideoCodecFactory)) as VideoCodecFactory;
                    _checkVideoCodec   = true;
                }
                catch (Exception ex)
                {
                    log.Warn("No video codec factory available.", ex);
                }
                _firstPacketTime = _audioTime = _videoTime = _dataTime = -1;
                _connMsgOut      = consumerManager.GetConsumerOutput(this);
                _connMsgOut.Subscribe(this, null);
                _recordPipe = new InMemoryPushPushPipe();
#if !(NET_1_1)
                Dictionary <string, object> recordParameterMap = new Dictionary <string, object>();
#else
                Hashtable recordParameterMap = new Hashtable();
#endif
                // Clear record flag
                recordParameterMap.Add("record", null);
                _recordPipe.Subscribe(this as IProvider, recordParameterMap);
                _recording         = false;
                _recordingFilename = null;
                this.CodecInfo     = new StreamCodecInfo();
                _closed            = false;
                _bytesReceived     = 0;
                _creationTime      = System.Environment.TickCount;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the server-side stream.
        /// </summary>
        public override void Start()
        {
            if (_state != State.UNINIT)
            {
                throw new NotSupportedException("State " + _state + " not valid to start");
            }
            if (_items.Count == 0)
            {
                throw new NotSupportedException("At least one item should be specified to start");
            }
            if (_publishedName == null)
            {
                throw new NotSupportedException("A published name is needed to start");
            }
            // publish this server-side stream

            IProviderService providerService = this.Scope.GetService(typeof(IProviderService)) as IProviderService;

            providerService.RegisterBroadcastStream(this.Scope, _publishedName, this);
            _recordPipe = new InMemoryPushPushPipe();
#if !(NET_1_1)
            Dictionary <string, object> recordParamMap = new Dictionary <string, object>();
#else
            Hashtable recordParamMap = new Hashtable();
#endif
            recordParamMap.Add("record", null);
            _recordPipe.Subscribe((IProvider)this, recordParamMap);
            _recordingFilename = null;
            _schedulingService = this.Scope.GetService(typeof(ISchedulingService)) as ISchedulingService;
            _state             = State.STOPPED;
            _currentItemIndex  = -1;
            NextItem();
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        public override void Start()
        {
            lock (this.SyncRoot)
            {
                IConsumerService consumerManager = this.Scope.GetService(typeof(IConsumerService)) as IConsumerService;
                try
                {
                    //_videoCodecFactory = new VideoCodecFactory();
                    _videoCodecFactory = this.Scope.GetService(typeof(VideoCodecFactory)) as VideoCodecFactory;
                    _checkVideoCodec = true;
                }
                catch (Exception ex)
                {
                    log.Warn("No video codec factory available.", ex);
                }
                _firstPacketTime = _audioTime = _videoTime = _dataTime = -1;
                _connMsgOut = consumerManager.GetConsumerOutput(this);
                _connMsgOut.Subscribe(this, null);
                _recordPipe = new InMemoryPushPushPipe();
#if !(NET_1_1)
                Dictionary<string, object> recordParameterMap = new Dictionary<string, object>();
#else
                Hashtable recordParameterMap = new Hashtable();
#endif
                // Clear record flag
                recordParameterMap.Add("record", null);
                _recordPipe.Subscribe(this as IProvider, recordParameterMap);
                _recording = false;
                _recordingFilename = null;
                this.CodecInfo = new StreamCodecInfo();
                _closed = false;
                _bytesReceived = 0;
                _creationTime = System.Environment.TickCount;
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Starts the server-side stream.
        /// </summary>
        public override void Start()
        {
            if (_state != State.UNINIT)
                throw new NotSupportedException("State " + _state + " not valid to start");
            if (_items.Count == 0)
                throw new NotSupportedException("At least one item should be specified to start");
            if (_publishedName == null)
                throw new NotSupportedException("A published name is needed to start");
            // publish this server-side stream

            IProviderService providerService = this.Scope.GetService(typeof(IProviderService)) as IProviderService;
            providerService.RegisterBroadcastStream(this.Scope, _publishedName, this);
            _recordPipe = new InMemoryPushPushPipe();
#if !(NET_1_1)
            Dictionary<string, object> recordParamMap = new Dictionary<string, object>();
#else
            Hashtable recordParamMap = new Hashtable();
#endif
            recordParamMap.Add("record", null);
            _recordPipe.Subscribe((IProvider)this, recordParamMap);
            _recordingFilename = null;
            _schedulingService = this.Scope.GetService(typeof(ISchedulingService)) as ISchedulingService;
            _state = State.STOPPED;
            _currentItemIndex = -1;
            NextItem();
        }