Beispiel #1
0
        public override void Dispose()
        {
            switch (_state)
            {
            case State.Publishing:
                _publisher.Dispose();
                //Handler.UnpublishStream(Peer,_index,Name);
                break;

            case State.Playing:
                _listener.Dispose();
                //Handler.UnsubscribeStream(Peer, _index, Name);
                break;
            }
            _listener = null;
            _state    = State.Idle;
        }
Beispiel #2
0
        protected override void MessageHandler(string action, Variant param)
        {
            this.Log().Info("{0},{1}", Id, action);
            switch (action)
            {
            case "play":
                Dispose();
                Name = param[1];
                double start  = param[2] ?? -2000;
                double length = param[3] ?? -1000;
                try
                {
                    _listener = Handler.SubScribeStream(Peer, StreamId, Name, Writer, start, length);
                    _state    = State.Playing;
                }
                catch (Exception ex)
                {
                    Logger.ASSERT("{0}", ex);
                }
                var raw = Writer.WriterRawMessage();
                raw.Write((ushort)0);
                raw.Write(3);
                raw.Write(34);
                Writer.Flush(true);
                break;

            case "closeStream":
                Dispose();
                break;

            case "publish":
                Dispose();
                Name = param[1];
                var type = param[2] ?? "live";
                //if (message.Available)
                //{
                //    type = message.Read<string>();
                //}
                _publisher = Handler.PublishStream(Peer, StreamId, Name, type, Writer);
                if (_publisher != null)
                {
                    _state = State.Publishing;
                }
                break;

            case "receiveAudio":
                if (_listener != null)
                {
                    _listener.ReceiveAudio = param[1];
                }
                break;

            case "receiveVideo":
                if (_listener != null)
                {
                    _listener.ReceiveVideo = param[1];
                }
                break;

            case "onStatus":
                var obj = param[1];
                this.Log().Info(obj["code"]);
                OnStatus?.Invoke(param);
                break;

            default:

                if (_state == State.Publishing)
                {
                    //var streamMessage = Variant.Get();
                    //var pos = message.BaseStream.Position;
                    //streamMessage[Defines.RM_FLEXSTREAMSEND, Defines.RM_FLEXSTREAMSEND_UNKNOWNBYTE] = 0;
                    //streamMessage[Defines.RM_FLEXSTREAMSEND, Defines.RM_FLEXSTREAMSEND_PARAMS] = Variant.Get();
                    //streamMessage[Defines.RM_FLEXSTREAMSEND, Defines.RM_FLEXSTREAMSEND_PARAMS].Add(action);
                    //while (message.Available)
                    //{
                    //    streamMessage[Defines.RM_FLEXSTREAMSEND, Defines.RM_FLEXSTREAMSEND_PARAMS].Add(message.ReadVariant());
                    //}
                    using (var tempms = Utils.Rms.GetStream()) {
                        tempms.WriteByte(0);
                        tempms.WriteByte(AMF0Serializer.AMF0_SHORT_STRING);
                        var buffer = Encoding.UTF8.GetBytes(action);
                        tempms.Write((ushort)buffer.Length);
                        tempms.Write(buffer, 0, buffer.Length);
                        //message.BaseStream.Position = pos;
                        //////////message.BaseStream.CopyTo(tempms);
                        tempms.Position = 0;
                        _publisher.SendStreamMessage(new BufferWithOffset(tempms));
                        //Handler.SendStreamMessage();
                    }
                }
                else
                {
                    base.MessageHandler(action, param);
                }
                break;
            }
        }
Beispiel #3
0
        public override OutNetRtmfpStream SubScribeStream(Peer peer, uint id, string name, FlowWriter writer, double start, double length)
        {
            var session           = writer.Band as Session;
            var outNetRtmfpStream = new OutNetRtmfpStream(session, session.Application.StreamsManager, id, name)
            {
                Writer = writer, Unbuffered = start == -3000
            };

            outNetRtmfpStream.Init();
            var inBoundStream = session.Application.StreamsManager.FindByTypeByName(StreamTypes.ST_IN_NET, name, true, false).Select(x => x.Value).OfType <IInStream>().FirstOrDefault();

            switch ((int)start)
            {
            case -2000:
                if (inBoundStream != null)
                {
                    inBoundStream.Link(outNetRtmfpStream);
                }
                else
                {
                    goto default;
                }
                break;

            case -1000:
                if (inBoundStream != null)
                {
                    inBoundStream.Link(outNetRtmfpStream);
                }
                else
                {
                    goto case -999;
                }
                break;

            case -999:
                if (ClientApplicationManager.ClusterApplication != null)
                {
                    ClientApplicationManager.ClusterApplication.GetProtocolHandler <BaseClusterAppProtocolHandler>().PlayStream(session.Application.Id, name);
                }
                break;

            default:
                var metadata          = session.Application.StreamsManager.GetMetaData(name, true, session.Application.Configuration);
                var pRtmpInFileStream = InFileRTMPStream.GetInstance(session, session.Application.StreamsManager, metadata);
                if (pRtmpInFileStream == null)
                {
                    WARN("Unable to get file stream. Metadata:\n{0}", metadata.ToString());
                    goto case -999;
                }
                if (!pRtmpInFileStream.Initialize(metadata[Defines.CONF_APPLICATION_CLIENTSIDEBUFFER]))
                {
                    WARN("Unable to initialize file inbound stream");
                    pRtmpInFileStream.Dispose();
                    goto case -999;
                }
                if (!pRtmpInFileStream.Link(outNetRtmfpStream))
                {
                    goto case -999;
                }
                if (!pRtmpInFileStream.Play(start, length))
                {
                    FATAL("Unable to start the playback");
                    goto case -999;
                }
                break;
            }
            return(outNetRtmfpStream);
        }