Beispiel #1
0
 protected BaseOutStream(T pProtocol, StreamsManager pStreamsManager, string name) : base(pProtocol, pStreamsManager, name)
 {
     if (!Type.TagKindOf(StreamTypes.ST_OUT))
     {
         Logger.ASSERT("Incorrect stream type. Wanted a stream type in class {0} and got {1}", StreamTypes.ST_OUT.TagToString(), Type.TagToString());
     }
 }
 public bool EnqueueForTimeEvent(uint seconds)
 {
     if (_pTimer != null)
     {
         return(_pTimer.EnqueueForTimeEvent(seconds));
     }
     Logger.ASSERT("BaseTimerProtocol has no timer");
     return(false);
 }
 public static void RegisterIOHandler(this IOHandler pIoHandler)
 {
     if (ActiveIoHandler.ContainsKey(pIoHandler.Id))
     {
         Logger.ASSERT("IOHandler already registered");
     }
     ActiveIoHandler[pIoHandler.Id] = pIoHandler;
     Logger.Debug("Handlers count changed: {0}->{1}", ActiveIoHandler.Keys.Count - 1, ActiveIoHandler.Keys.Count);
 }
 public void RegisterAppProtocolHandler(ulong protocolType, BaseAppProtocolHandler pAppProtocolHandler)
 {
     if (_protocolsHandlers.ContainsKey(protocolType))
     {
         Logger.ASSERT("Invalid protocol handler type. Already registered");
     }
     _protocolsHandlers[protocolType] = pAppProtocolHandler;
     pAppProtocolHandler.Application  = this;
 }
 protected BaseInFileStream(BaseProtocol pProtocol, StreamsManager pStreamsManager, string name)
     : base(pProtocol, pStreamsManager, name)
 {
     if (!Type.TagKindOf(StreamTypes.ST_IN_FILE))
     {
         Logger.ASSERT("Incorrect stream type. Wanted a stream type in class {0} and got {1}", StreamTypes.ST_IN_FILE.TagToString(), Type.TagToString());
     }
     Paused = true;
     _audioVideoCodecsSent = false;
     Capabilities.Clear();
     _playLimit = -1;
 }
 virtual public void RegisterProtocol(BaseProtocol pProtocol)
 {
     if (!_protocolsHandlers.ContainsKey(pProtocol.Type))
     {
         Logger.ASSERT("Protocol handler not activated for protocol type {0} in application {1}",
                       pProtocol.Type, Name);
     }
     else
     {
         _protocolsHandlers[pProtocol.Type].RegisterProtocol(pProtocol);
     }
 }
 virtual public void UnRegisterProtocol(BaseProtocol pProtocol)
 {
     SOManager.UnRegisterProtocol(pProtocol);
     StreamsManager.UnRegisterStreams(pProtocol.Id);
     if (!_protocolsHandlers.ContainsKey(pProtocol.Type))
     {
         Logger.ASSERT("Protocol handler not activated for protocol type {0} in application {1}",
                       pProtocol.Type, Name);
     }
     else
     {
         _protocolsHandlers[pProtocol.Type].UnRegisterProtocol(pProtocol);
     }
     //INFO(typeid(_protocolsHandlers[pProtocol.Type]).name());
     this.Log().Info("Protocol {0} unregistered from application: {1}", pProtocol.ToString(), Name);
 }
Beispiel #8
0
        private Variant ToPrimitives(List <DirtyInfo> info)
        {
            var vm = GlobalPool <VariantMap> .GetObject();

            var result = Variant.Get(vm);

            vm.IsArray     = true;
            vm.ArrayLength = info.Count;
            for (var i = 0; i < vm.ArrayLength; i++)
            {
                var primitive = Variant.GetMap(new VariantMapHelper {
                    { Defines.RM_SHAREDOBJECTPRIMITIVE_TYPE, info[i].Type }
                });
                switch (info[i].Type)
                {
                case Defines.SOT_SC_UPDATE_DATA_ACK:

                case Defines.SOT_SC_DELETE_DATA:
                    primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_PAYLOAD] = Variant.GetList(info[i].PropertyName);
                    break;

                case Defines.SOT_SC_UPDATE_DATA:
                    primitive[Defines.RM_SHAREDOBJECTPRIMITIVE_PAYLOAD] = Variant.GetMap(new VariantMapHelper
                    {
                        { info[i].PropertyName, Payload[info[i].PropertyName].Clone() }
                    });
                    break;

                case Defines.SOT_SC_INITIAL_DATA:
                case Defines.SOT_SC_CLEAR_DATA:
                    break;

                default:
                    Logger.ASSERT("Unable to handle primitive type:{0}", info[i].Type);
                    break;
                }
                vm[VariantMap.GetIndexString(i)] = primitive;
            }
            return(result);
        }
Beispiel #9
0
 public virtual bool FeedData(Stream pData, uint dataLength, uint processedLength, uint totalLength,
                              uint absoluteTimestamp, bool isAudio)
 {
     Logger.ASSERT("Operation not supported");
     return(true);
 }
Beispiel #10
0
 public virtual bool Stop()
 {
     Logger.ASSERT("Operation not supported");
     return(true);
 }
Beispiel #11
0
 public virtual bool Seek(double absoluteTimestamp)
 {
     Logger.ASSERT("Operation not supported");
     return(true);
 }
Beispiel #12
0
 public virtual bool Play(double absoluteTimestamp, double length)
 {
     Logger.ASSERT("Operation not supported");
     return(true);
 }
Beispiel #13
0
 public virtual bool SignalResume()
 {
     Logger.ASSERT("Operation not supported");
     return(true);
 }
Beispiel #14
0
 public virtual void ReadyForSend()
 {
     Logger.ASSERT("Operation not supported");
 }
Beispiel #15
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;
            }
        }