Ejemplo n.º 1
0
        public void Publish([FromOptionalArgument] string publishingName, [FromOptionalArgument] string publishingType)
        {
            if (string.IsNullOrEmpty(publishingName))
            {
                throw new InvalidOperationException("empty publishing name");
            }
            if (!PublishingHelpers.IsTypeSupported(publishingType))
            {
                throw new InvalidOperationException($"not supported publishing type {publishingType}");
            }

            _publishingType = PublishingHelpers.PublishingTypes[publishingType];

            _publisherSessionService.RegisterPublisher(publishingName, this);

            RtmpSession.SendControlMessageAsync(new StreamBeginMessage()
            {
                StreamID = MessageStream.MessageStreamId
            });
            var onStatus = RtmpSession.CreateCommandMessage <OnStatusCommandMessage>();

            MessageStream.RegisterMessageHandler <DataMessage>(HandleDataMessage);
            MessageStream.RegisterMessageHandler <AudioMessage>(HandleAudioMessage);
            MessageStream.RegisterMessageHandler <VideoMessage>(HandleVideoMessage);
            onStatus.InfoObject = new AmfObject
            {
                { "level", "status" },
                { "code", "NetStream.Publish.Start" },
                { "description", "Stream is now published." },
                { "details", publishingName }
            };
            MessageStream.SendMessageAsync(ChunkStream, onStatus);
        }
Ejemplo n.º 2
0
        public async Task Publish([FromOptionalArgument] string streamName, [FromOptionalArgument] string publishingType)
        {
            if (string.IsNullOrEmpty(streamName))
            {
                throw new InvalidOperationException("empty publishing name");
            }
            if (!PublishingHelpers.IsTypeSupported(publishingType))
            {
                throw new InvalidOperationException($"not supported publishing type {publishingType}");
            }

            _publishingType = PublishingHelpers.PublishingTypes[publishingType];

            await RtmpSession.SendControlMessageAsync(new StreamIsRecordedMessage()
            {
                StreamID = MessageStream.MessageStreamId
            });

            await RtmpSession.SendControlMessageAsync(new StreamBeginMessage()
            {
                StreamID = MessageStream.MessageStreamId
            });

            var onStatus = RtmpSession.CreateCommandMessage <OnStatusCommandMessage>();

            MessageStream.RegisterMessageHandler <DataMessage>(HandleData);
            MessageStream.RegisterMessageHandler <AudioMessage>(HandleAudioMessage);
            MessageStream.RegisterMessageHandler <VideoMessage>(HandleVideoMessage);
            MessageStream.RegisterMessageHandler <UserControlMessage>(HandleUserControlMessage);
            onStatus.InfoObject = new AmfObject
            {
                { "level", "status" },
                { "code", "NetStream.Publish.Start" },
                { "description", "Stream is now published." },
                { "details", streamName }
            };
            await MessageStream.SendMessageAsync(ChunkStream, onStatus);

            _recordFileData = new FileStream(_recordService.GetRecordFilename(streamName) + ".data", FileMode.OpenOrCreate);
            _recordFileData.SetLength(0);
            _keyframes             = new AmfObject();
            _keyframeTimes         = new List <object>();
            _keyframeFilePositions = new List <object>();
            _keyframes.Add("times", _keyframeTimes);
            _keyframes.Add("filepositions", _keyframeFilePositions);
        }