Ejemplo n.º 1
0
        /// <summary>
        /// body 为 xml 格式
        ///  <zonekey app="record_livingcast_service">
        ///     <cmd command="livingcast_start">
        ///         <uuid>xxxxx</uuid>   与录像一致
        ///         <subject>xxxx</subject> 与录像一致
        ///         <streams>
        ///             <stream>
        ///                 <aid>xx</aid>   音频
        ///                 <vid>xxx</vid> 视频
        ///             </stream>
        ///         </streams>
        ///     </cmd>
        ///     <mcu>
        ///         <jid>xxx</jid>
        ///         <cid>xxx</cid>
        ///     </mcu>
        ///  </zonekey>
        ///
        /// </summary>
        /// <param name="req"></param>
        /// <param name="res"></param>
        public static void Start(HttpListenerRequest req, HttpListenerResponse res)
        {
            string     command, mcu_jid;
            int        mcu_cid;
            XmlElement node;

            string body_b64 = Utility.BodyFromStream.read(req.InputStream, req.ContentLength64, Encoding.ASCII);
            string body     = Encoding.UTF8.GetString(Convert.FromBase64String(body_b64));

            if (body == null)
            {
                Console.WriteLine("Record.Start: Net broken!");
                return;
            }

            Log.log("Livingcast_Start: xml=" + body);

            if (Utility.BodyParser.parse(body, out command, out node, out mcu_jid, out mcu_cid))
            {
                if (command != "livingcast_start")
                {
                    format_error(res);
                    return;
                }
                LivingcastStartParam start_param = parse_cmd_node(node, mcu_jid, mcu_cid);
                if (start_param == null)
                {
                    format_error(res);
                    return;
                }

                // 这里启动 ....
                lock (LivingcastTasks) {
                    if (LivingcastTasks.ContainsKey(mcu_cid))
                    {
                        livingcast_exist(res);
                        return;
                    }
                }

                LivingcastTask task = new LivingcastTask(start_param);
                lock (LivingcastTasks) {
                    LivingcastTasks.Add(mcu_cid, task);
                }

                done(res, "ok");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// body 为 xml 格式
        ///  <zonekey app="record_livingcast_service">
        ///     <cmd command="livingcast_start">
        ///         <uuid>xxxxx</uuid>   与录像一致
        ///         <subject>xxxx</subject> 与录像一致
        ///         <streams>
        ///             <stream>
        ///                 <aid>xx</aid>   音频
        ///                 <vid>xxx</vid> 视频
        ///             </stream>
        ///         </streams>
        ///     </cmd>
        ///     <mcu>
        ///         <jid>xxx</jid>
        ///         <cid>xxx</cid>
        ///     </mcu>
        ///  </zonekey>
        ///  
        /// </summary>
        /// <param name="req"></param>
        /// <param name="res"></param>
        public static void Start(HttpListenerRequest req, HttpListenerResponse res)
        {
            string command, mcu_jid;
            int mcu_cid;
            XmlElement node;

            string body_b64 = Utility.BodyFromStream.read(req.InputStream, req.ContentLength64, Encoding.ASCII);
            string body = Encoding.UTF8.GetString(Convert.FromBase64String(body_b64));
            if (body == null)
            {
                Console.WriteLine("Record.Start: Net broken!");
                return;
            }

            Log.log("Livingcast_Start: xml=" + body);

            if (Utility.BodyParser.parse(body, out command, out node, out mcu_jid, out mcu_cid)) {
                if (command != "livingcast_start") {
                    format_error(res);
                    return;
                }
                LivingcastStartParam start_param = parse_cmd_node(node, mcu_jid, mcu_cid);
                if (start_param == null) {
                    format_error(res);
                    return;
                }

                // 这里启动 ....
                lock (LivingcastTasks) {
                    if (LivingcastTasks.ContainsKey(mcu_cid)) {
                        livingcast_exist(res);
                        return;
                    }
                }

                LivingcastTask task = new LivingcastTask(start_param);
                lock (LivingcastTasks) {
                    LivingcastTasks.Add(mcu_cid, task);
                }

                done(res, "ok");
            }
        }
Ejemplo n.º 3
0
        public static void Stop(HttpListenerRequest req, HttpListenerResponse res)
        {
            string     command, mcu_jid;
            int        mcu_cid;
            XmlElement node;

            string body_b64 = Utility.BodyFromStream.read(req.InputStream, req.ContentLength64, Encoding.ASCII);
            string body     = Encoding.UTF8.GetString(Convert.FromBase64String(body_b64));

            if (body == null)
            {
                Console.WriteLine("Record.Start: Net broken!");
                return;
            }

            Log.log("Livingcast_Stop: xml=" + body);

            if (Utility.BodyParser.parse(body, out command, out node, out mcu_jid, out mcu_cid))
            {
                if (command != "livingcast_stop")
                {
                    format_error(res);
                    return;
                }

                // 结束对应的直播任务
                lock (LivingcastTasks) {
                    if (LivingcastTasks.ContainsKey(mcu_cid))
                    {
                        LivingcastTask task = LivingcastTasks[mcu_cid];
                        task.Close();
                        LivingcastTasks.Remove(mcu_cid);
                    }
                }

                done(res, "ok");
            }
        }