private void button_startmove_Click(object sender, EventArgs e) { long start_time; // initiating a new move along with a new timestamp as identifier if (!new_move) { live_video_click_count = 0; // Enable the Spielzug/Move property buttons button_kill.Enabled = true; button_smash.Enabled = true; button_drop.Enabled = true; button_bigPoint.Enabled = true; button_timeout.Enabled = true; radioButton_playerupright.Enabled = true; radioButton_playerupleft.Enabled = true; radioButton_playerdownleft.Enabled = true; radioButton_playerdownright.Enabled = true; radioButton_playerupright.Checked = false; radioButton_playerupleft.Checked = false; radioButton_playerdownleft.Checked = false; radioButton_playerdownright.Checked = false; start_time = getCurrentTime(); // get current time as identifier while (List_timestamps.Contains(start_time)) start_time = getCurrentTime(); List_timestamps.Add(start_time); // add timestamp to the list we use for the screenshots // Create a new Rally Game.Current_rally = new Rally(configuration.Teama.Player1.Current_position, configuration.Teama.Player2.Current_position, configuration.Teamb.Player1.Current_position, configuration.Teamb.Player2.Current_position, start_time, Game.Sets.Count); // Clear the BirdView pictureBox_birdview.Invalidate(); rallyframes = new List<Image<Bgr, byte>>(); String move_identifier = start_time.ToString(); String videopath = Program.getConfiguration().Mediafolderpath + @"\" + move_identifier + ".mpg"; if (capture_device_index != -1) this.videoWriter = new VideoWriter(videopath, Emgu.CV.CvInvoke.CV_FOURCC('P', 'I', 'M', '1'), fps, 640, 480, true); // start a new video capture from video if (capture_device_index == -1) { Capture tempcapture = new Capture(loaded_videopath); int tempfps = (int)tempcapture.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS); //this.videoWriter = new VideoWriter(videopath, Emgu.CV.CvInvoke.CV_FOURCC('P', 'I', 'M', '1'), tempfps, 640, 480, true); startmilisecond = axWindowsMediaPlayer_live.Ctlcontrols.currentPosition; axWindowsMediaPlayer_live.Ctlcontrols.play(); tempcapture.Dispose(); } button_startmove.Text = "End of rally"; button_startmove.ForeColor = System.Drawing.Color.Red; new_move = true; } else { live_video_click_count = 0; // Disable the Spielzug/Move property buttons button_kill.Enabled = false; button_smash.Enabled = false; button_drop.Enabled = false; button_bigPoint.Enabled = false; button_timeout.Enabled = false; radioButton_playerupright.Enabled = false; radioButton_playerupleft.Enabled = false; radioButton_playerdownleft.Enabled = false; radioButton_playerdownright.Enabled = false; radioButton_playerupright.Checked = false; radioButton_playerupleft.Checked = false; radioButton_playerdownleft.Checked = false; radioButton_playerdownright.Checked = false; // AUTO handling of score // Save into the list and add to xml output if (Game.Current_rally != null) { Set current_set = Game.Sets[Game.Sets.Count - 1]; current_set.Rallies.Add(Game.Current_rally); // Set End Time Game.Current_rally.EndRally_time = getCurrentTime(); Game.Current_rally.Duration_ticks = Game.Current_rally.EndRally_time - Game.Current_rally.Start_time; // calculate the point for the successful team Game.Current_rally.setNewScore(Game, configuration.TeamAup); xmlDoc.addRally(Game.Current_rally); if (Game.Current_rally.Kill) button_kill.Text = "KILL"; else button_kill.Text = "NO KILL"; if (configuration.TeamAup) { textBox_scoreteamup.Text = current_set.TeamAScore.ToString(); textBox_scoreteamdown.Text = current_set.TeamBScore.ToString(); } else { textBox_scoreteamup.Text = current_set.TeamBScore.ToString(); textBox_scoreteamdown.Text = current_set.TeamAScore.ToString(); } // set color setScoreColor(current_set); Team winner = current_set.getSetWinner(Game); if (winner != null) { teamXhasWon(); } } // stop the capturing and write video if (capture_device_index != -1) // camera capture { start_time = Game.Current_rally.Start_time; WriteRallyVideoThread writevideoobject = new WriteRallyVideoThread(buffer, videoWriter, start_time); writevideoobject.donewritingrallyvideo += new DoneWritingRallyVideoEventHandler(writevideothread_donewritingvideo); writeRallyVideoFromBuffer(writevideoobject); } else // loaded video { endmilisecond = axWindowsMediaPlayer_live.Ctlcontrols.currentPosition; start_time = Game.Current_rally.Start_time; WriteRallyVideoThread writevideoobject = new WriteRallyVideoThread(startmilisecond, endmilisecond, loaded_videopath, null, start_time); writevideoobject.donewritingrallyvideo += new DoneWritingRallyVideoEventHandler(writevideothread_donewritingvideo); writevideoobject.donewritingrallyframe += new DoneWritingRallyFrameEventHandler(writevideothread_donewritingframe); writeRallyVideoFromLoaded(writevideoobject); } button_startmove.Text = "Start of rally…"; // SAVE button_startmove.ForeColor = System.Drawing.Color.Black; new_move = false; } }
private void writeRallyVideoFromBuffer(WriteRallyVideoThread writevideothread) { System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(writevideothread.writeFromBuffer)); thread.SetApartmentState(System.Threading.ApartmentState.STA); thread.Start(); }