Пример #1
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("Record_Stop: xml=" + body);

            if (Utility.BodyParser.parse(body, out command, out node, out mcu_jid, out mcu_cid))
            {
                /** node 格式为:
                 *      <cmd command="record_stop">
                 *      </cmd>
                 */
                lock (RecordingTasks)
                {
                    if (RecordingTasks.ContainsKey(mcu_cid))
                    {
                        RecordingTasks[mcu_cid].Close();
                        RecordingTasks.Remove(mcu_cid);
                        done(res, "");
                    }
                    else
                    {
                        no_matched_recording(res, mcu_cid);
                    }
                }
            }
            else
            {
                format_error(res);
            }
        }
Пример #2
0
        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("Record_Start: xml=" + body);

            if (Utility.BodyParser.parse(body, out command, out node, out mcu_jid, out mcu_cid))
            {
                // 需要继续解析 node, 格式为:

                /*
                 *      <cmd command="record_start">
                 *          <uuid>xxxx-xxx...</uuid>        // 录像目录,上传时,将上传整个 uuid 的目录,这个 uuid 将与直播时的 uuid 一致
                 *          <subject>......</subject>       // 互动描述
                 *          <members>
                 *              <caller>...</caller>            // 主讲 ..
                 *              <callee>...</callee>            // 听讲,可能多个
                 *              <callee>...</callee>
                 *          </members>
                 *          <files>
                 *              <file>             // 描述一个录像文件
                 *                  <aid>xx</aid>   // 音频 id
                 *                  <vid>xx</vid>   // 视频 id
                 *                  <desc>....</desc>       // 录像描述
                 *                  <name> ...</name>       // 录像文件名字
                 *                  ....                    // ...
                 *              </file>
                 *              <file>
                 *              </file>
                 *              ....
                 *          </files>
                 *      </cmd>
                 */
                RecordStartParam param = parseRecordStartNode(node);
                if (param == null)
                {
                    format_error(res);
                    return;
                }

                param.mcu_cid = mcu_cid;
                param.mcu_jid = mcu_jid;

                // 检查录像是否已经启动
                lock (RecordingTasks)
                {
                    if (RecordingTasks.ContainsKey(mcu_cid))
                    {
                        already_recording_error(res, mcu_cid);
                        return;
                    }

                    // 启动录像任务
                    try
                    {
                        RecordingTasks.Add(mcu_cid, new RecordTask(param));
                        done(res, "");
                    }
                    catch
                    {
                        failure_error(res);
                    }
                }
            }
            else
            {
                format_error(res);
            }
        }