Exemple #1
0
        protected override void OnReceive(byte[] buffer, int idx, int len)
        {
            byte[] ReceiveBuffer = new byte[len];
            Array.Copy(buffer, idx, ReceiveBuffer, 0, len);

            var objs = RtmpProtocolDecoder.DecodeBuffer(remotecontext, new ByteBuffer(new MemoryStream(ReceiveBuffer)));

            if (objs != null)
            {
                foreach (var obj in objs)
                {
                    RtmpPacket packet = obj as RtmpPacket;
                    if (packet != null)
                    {
                        var result = packet.Message as Notify;
                        if (result != null)
                        {
                            CallResultWait callresult = null;
                            if (RtmpUtil.IsResult(result))
                            {
                                lock (WaitLock)
                                {
                                    int fidx = WaitInvokeList.FindIndex(crw => crw.Call.InvokeId == result.InvokeId);
                                    if (fidx != -1)
                                    {
                                        callresult = WaitInvokeList[fidx];
                                        WaitInvokeList.RemoveAt(fidx);
                                    }
                                }

                                if (callresult != null)
                                {
                                    callresult.Result = result;
                                    callresult.Wait.Set();

                                    if (!callresult.Blocking)
                                    {
                                        OnCall(callresult.Call, callresult.Result);
                                    }
                                }
                                else
                                {
                                    OnNotify(result);
                                }
                            }
                            else
                            {
                                OnNotify(result);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void CallView_SelectedIndexChanged(object sender, EventArgs e)
        {
            CallTree.Nodes.Clear();

            if (CallView.SelectedItems.Count < 1)
            {
                return;
            }

            var notifies = CallView.SelectedItems[0].Tag as List <Notify>;

            if (notifies == null)
            {
                return;
            }

            foreach (var notify in notifies)
            {
                var children = new List <TreeNode>();
                var bodies   = RtmpUtil.GetBodies(notify);
                foreach (var body in bodies)
                {
                    children.Add(GetNode(body.Item1) ?? new TreeNode(body.Item1 != null ? body.Item1.ToString() : ""));
                }

                CallTree.Nodes.Add(new TreeNode(!RtmpUtil.IsResult(notify) ? "Call" : "Return", children.ToArray()));
            }

            foreach (TreeNode node in CallTree.Nodes)
            {
                node.Expand();
                foreach (TreeNode node2 in node.Nodes)
                {
                    node2.Expand();
                }
            }
        }
Exemple #3
0
        protected override void OnReceive(byte[] buffer, int idx, int len)
        {
            StaticLogger.Trace(string.Format("Recv {0} bytes", len));

            if (logtofiles)
            {
                using (var fs = File.Open("realrecv.dmp", FileMode.Append, FileAccess.Write))
                {
                    fs.Write(buffer, idx, len);
                }
            }

            receivebuffer.Append(buffer, idx, len);

            var objs = RtmpProtocolDecoder.DecodeBuffer(remotecontext, receivebuffer);

            if (objs != null)
            {
                foreach (var obj in objs)
                {
                    var pck = obj as RtmpPacket;
                    if (pck != null)
                    {
                        var result = pck.Message as Notify;
                        if (result != null)
                        {
                            Notify inv = null;
                            if (RtmpUtil.IsResult(result))
                            {
                                lock (InvokeList)
                                {
                                    int fidx = InvokeList.FindIndex(i => i.InvokeId == result.InvokeId);
                                    if (fidx != -1)
                                    {
                                        inv = InvokeList[fidx];
                                        InvokeList.RemoveAt(fidx);
                                    }
                                }

                                if (inv != null)
                                {
                                    OnCall(inv, result);

                                    StaticLogger.Trace(
                                        string.Format(
                                            "Ret  ({0}) (Id:{1})",
                                            string.Join(", ", inv.ServiceCall.Arguments.Select(o => o.ToString())),
                                            pck.Header.ChannelId
                                            )
                                        );
                                }
                            }
                            else
                            {
                                OnNotify(result);
                            }
                        }
                        else
                        {
                            StaticLogger.Trace(string.Format("Recv {0} (Id:{1})", pck.Message, pck.Header.ChannelId));
                        }
                    }
                    else if (obj is ByteBuffer)
                    {
                        //Just handshakes, ignore
                    }
                    else
                    {
                        StaticLogger.Warning(string.Format("Unknown object {0}", obj.GetType()));
                    }

                    if (obj != null && encode)
                    {
                        if (pck != null && pck.Message is Notify)
                        {
                            InternalReceive((Notify)pck.Message);
                            remotecontext.ObjectEncoding = ObjectEncoding.AMF3;
                        }
                        else
                        {
                            var buf = RtmpProtocolEncoder.Encode(remotecontext, obj);
                            if (buf == null)
                            {
                                StaticLogger.Fatal("Unable to encode " + obj);
                            }
                            else
                            {
                                var buff = buf.ToArray();
                                if (logtofiles)
                                {
                                    using (var fs = File.Open("recv.dmp", FileMode.Append, FileAccess.Write))
                                    {
                                        fs.Write(buff, 0, buff.Length);
                                    }
                                }
                                if (encode)
                                {
                                    base.OnReceive(buff, 0, buff.Length);
                                }
                            }
                        }
                    }
                }
            }

            if (!encode)
            {
                base.OnReceive(buffer, idx, len);
            }
        }
Exemple #4
0
        /// <summary>
        /// Replaces the invokeid
        /// </summary>
        /// <param name="notify"></param>
        protected void InternalReceive(Notify notify)
        {
            if (RtmpUtil.IsResult(notify))
            {
                int ourid = notify.InvokeId;

                CallResultWait callresult = null;
                lock (WaitLock)
                {
                    if (WaitInvokeList != null)
                    {
                        int idx = WaitInvokeList.FindIndex(crw => crw.Call.InvokeId == ourid);
                        if (idx != -1)
                        {
                            callresult = WaitInvokeList[idx];
                            WaitInvokeList.RemoveAt(idx);
                        }
                    }
                }

                //InvokeId was found in the waitlist, that means its one of our calls.
                if (callresult != null)
                {
                    callresult.Result = notify;
                    callresult.Wait.Set();

                    //Not blocking, lets send it to the handler instead.
                    if (!callresult.Blocking)
                    {
                        OnCall(callresult.Call, callresult.Result);
                    }

                    return;                     //Return, we don't want LoL receiving the message.
                }

                int theirid;
                lock (InvokeIds)
                {
                    if (!InvokeIds.TryGetValue(ourid, out theirid))
                    {
                        StaticLogger.Error(string.Format("Call id not found for {0}", notify));
                        return;
                    }
                    InvokeIds.Remove(ourid);
                }
                notify.InvokeId = theirid;
            }

            var buf = RtmpProtocolEncoder.Encode(remotecontext, CreatePacket(notify));

            if (buf == null)
            {
                StaticLogger.Fatal("Unable to encode " + notify);
            }
            else
            {
                var buff = buf.ToArray();
                if (logtofiles)
                {
                    using (var fs = File.Open("recv.dmp", FileMode.Append, FileAccess.Write))
                    {
                        fs.Write(buff, 0, buff.Length);
                    }
                }
                if (encode)
                {
                    base.OnReceive(buff, 0, buff.Length);
                }
            }
        }