Example #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            string strDPath = Application.StartupPath;

            string uid;
            string uidpassword;

            uid         = textBox1.Text.ToString();
            uidpassword = textBox2.Text.ToString();

            try { thread1.Abort(); }
            catch (Exception) { }
            IntPtr hwd    = panel1.Handle;
            video  video1 = new video(hwd, uid, uidpassword);

            thread1 = new Thread(new ThreadStart(video1.getvideo));
            thread1.Start();
        }
Example #2
0
        public string messagerecv(string recvstr)
        {
            string[] mss    = recvstr.Split(new char[] { ':', ':' });
            string   userID = mss[0];

            Console.WriteLine(userID);
            string pwd           = mss[1];
            string videoID       = mss[2];
            string videocmd      = mss[3];
            string servermessage = "无效操作";



            if (videocmd.Equals("open"))
            {
                int    camid;
                string uid;
                string uidpassword;

                string sqlstr = "SELECT    camid,uid,uidpassword  FROM cam WHERE     (userid ='" + userID + "')";

                DataSet ds = dataoperate.getDs(sqlstr, "cam");
                if (ds.Tables.Count > 0)
                {
                    Console.WriteLine(ds.Tables[0].Rows.Count);//获得数据库userid对应的 行数 及对应相机数
                    servermessage = null;
                    string  get_setting = "SELECT  path FROM setting ";
                    DataSet setting     = dataoperate.getDs(get_setting, "setting");
                    pathmain = setting.Tables[0].Rows[0][0].ToString();
                    for (int i = ds.Tables[0].Rows.Count - 1; i >= 0; i--)
                    {
                        camid = int.Parse(ds.Tables[0].Rows[i][0].ToString());

                        uid = ds.Tables[0].Rows[i][1].ToString();

                        uidpassword = ds.Tables[0].Rows[i][2].ToString();


                        string nowtime = DateTime.Now.ToString();

                        string timestr     = DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");
                        string filename    = videoID + "_" + camid.ToString() + "_" + timestr + ".h264";
                        string mp4filename = videoID + "_" + camid.ToString() + "_" + timestr + ".mp4";
                        string path        = pathmain + "\\" + userID + "\\" + mp4filename;
                        //路径检查
                        if (!System.IO.Directory.Exists(pathmain + "\\" + userID + "\\"))//判断文件夹存在
                        {
                            Console.WriteLine("路径不存在");
                            System.IO.Directory.CreateDirectory(pathmain + "\\" + userID + "\\");
                        }
                        string  sqlString = "insert into video(userid,videoname,begintime,path,camid) values ('" + userID + "','" + videoID + "','" + nowtime + "','" + path + "','" + camid.ToString() + "') ;";
                        DataSet ds1       = dataoperate.getDs(sqlString, "video");

                        video video1 = new video(uid, uidpassword, pathmain + "\\" + userID + "\\" + filename);

                        Thread thread = new Thread(new ThreadStart(video1.recordvideo));
                        thread.Name = userID + "#" + videoID + "#" + camid.ToString() + "#" + nowtime + "#" + camid.ToString() + "#" + uid;
                        listThread.Add(thread);
                        thread.IsBackground = true;

                        thread.Start();


                        if (servermessage == null)
                        {
                            servermessage = userID + "用户" + videoID + "摄像头" + camid.ToString() + "开始录制";
                        }
                        else
                        {
                            servermessage = servermessage + "\r\n" + userID + "用户" + videoID + "摄像头" + camid.ToString() + "开始录制";
                        }
                    }
                }
            }
            if (videocmd.Equals("close"))
            {
                servermessage = null;

                for (int i = 0; i < 4; i++)
                {
                    foreach (Thread tempThread in listThread)
                    {
                        if (tempThread.Name.Contains(userID + "#" + videoID + "#" + i))
                        {
                            string[] cut       = tempThread.Name.Split(new char[] { '#', '#' });
                            DateTime begintime = Convert.ToDateTime(cut[3]);
                            string   nowtime   = DateTime.Now.ToString();
                            //err[int.Parse(cut[4])] = false;
                            string  updatestr = "update video set endtime='" + nowtime + "' where userid='" + userID + "' and begintime=#" + begintime + "# ";
                            DataSet ds2       = dataoperate.getDs(updatestr, "video");
                            if (servermessage == null)
                            {
                                servermessage = userID + "用户" + videoID + "第" + i + "文件结束录制";
                            }
                            else
                            {
                                servermessage = servermessage + "\r\n" + userID + "用户" + videoID + "第" + i + "文件结束录制";
                            }


                            tempThread.Abort();
                            listThread.Remove(tempThread);
                            string begingtimestr = begintime.ToString("yyyy_MM_dd_hh_mm_ss");
                            string filename      = videoID + "_" + i.ToString() + "_" + begingtimestr + ".h264";

                            string   fullfilename = pathmain + "\\" + userID + "\\" + filename;
                            string[] s            = fullfilename.Split(new char[] { '.' });
                            mp4box(fullfilename, "10", s[0] + ".mp4");

                            break;
                        }
                    }
                }
            }

            if (videocmd.Equals("R&Q"))
            {
                string  strSql = "select * from login_db where loginname='" + userID + "' and pwd='" + pwd + "'";
                DataSet ds     = dataoperate.getDs(strSql, "login_db");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    servermessage = userID + "_login";
                }
                else
                {
                    servermessage = userID + "_end";
                }
            }
            return(servermessage);
        }