Пример #1
0
 public FlowStream(ulong id, string signature, Peer peer, BaseRtmfpProtocol handler, Session band,FlowWriter localFlow)
     : base(id, signature, _Name, peer, handler, band, localFlow)
 {
     if (handler.StreamsManager?.StreamsByType.ContainsKey(StreamTypes.ST_IN_NET_RTMFP)??false)
     _publisher = handler.StreamsManager.StreamsByType[StreamTypes.ST_IN_NET_RTMFP].Select(x => x.Value as InNetRtmfpStream).SingleOrDefault(x=>x.PublisherId==StreamId);
     //_publication = handler.Publications.Values.SingleOrDefault(x => x.PublisherId == _index);
 }
Пример #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;
            }
        }
Пример #3
0
 public override InNetRtmfpStream PublishStream(Peer peer, uint id, string name, string type, FlowWriter writer)
 {
     var session = writer.Band as Session;
     if (!session.Application.StreamsManager.StreamNameAvailable(name))
     {
         WARN(
             "Stream name {0} already occupied and application doesn't allow duplicated inbound network streams",
             name);
         writer.WriteStatusResponse("Publish.BadName", name + "is not available");
         return null;
     }
     var pInNetRtmpStream = new InNetRtmfpStream(session, session.Application.StreamsManager, name);
     session.Application.OnPublish(this, pInNetRtmpStream, type);
     pInNetRtmpStream.Start(peer, id, writer);
     return pInNetRtmpStream;
 }