Beispiel #1
0
        internal void _CaptureRaceTest(Action <string> onComplete, IEnumerable <DataSample> samples)
        {
            var overlayData        = new OverlayData();
            var removalEdits       = new RemovalEdits(overlayData.RaceEvents);
            var commentaryMessages = new CommentaryMessages(overlayData);
            var videoCapture       = new VideoCapture();
            var recordPitStop      = new RecordPitStop(commentaryMessages);
            var fastestLaps        = new RecordFastestLaps(overlayData);
            var replayControl      = new ReplayControl(samples.First().SessionData, incidents, removalEdits, TrackCameras);
            var sessionDataCapture = new SessionDataCapture(overlayData);
            var captureLeaderBoardEveryHalfSecond = new SampleFilter(TimeSpan.FromSeconds(0.5),
                                                                     new CaptureLeaderBoard(overlayData, commentaryMessages, removalEdits).Process);
            var captureCamDriverEveryQuaterSecond = new SampleFilter(TimeSpan.FromSeconds(0.25),
                                                                     new CaptureCamDriver(overlayData).Process);

            var captureCamDriverEvery4Seconds = new SampleFilter(TimeSpan.FromSeconds(4),
                                                                 new LogCamDriver().Process);


            TraceDebug.WriteLine("Cameras:");
            TraceDebug.WriteLine(TrackCameras.ToString());

            ApplyFirstLapCameraDirection(samples, replayControl);

            samples = samples
                      .VerifyReplayFrames()
                      .WithCorrectedPercentages()
                      .WithCorrectedDistances()
                      .WithFastestLaps()
                      .WithFinishingStatus()
                      .WithPitStopCounts()
                      .TakeUntil(3.Seconds()).Of(d => d.Telemetry.LeaderHasFinished && d.Telemetry.RaceCars.All(c => c.HasSeenCheckeredFlag || c.HasRetired || c.TrackSurface != TrackLocation.OnTrack))
                      .TakeUntil(3.Seconds()).AfterReplayPaused();

            if (shortTestOnly)
            {
                samples = samples.AtSpeed(Settings.Default.TimingFactorForShortTest);
                Settings.AppliedTimingFactor = 1.0 / Settings.Default.TimingFactorForShortTest;
            }

            videoCapture.Activate(workingFolder);
            var startTime = DateTime.Now;

            overlayData.CapturedVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            foreach (var data in samples)
            {
                var relativeTime = DateTime.Now - startTime;

                replayControl.Process(data);
                sessionDataCapture.Process(data);
                captureLeaderBoardEveryHalfSecond.Process(data, relativeTime);
                captureCamDriverEveryQuaterSecond.Process(data, relativeTime);
                recordPitStop.Process(data, relativeTime);
                fastestLaps.Process(data, relativeTime);
                removalEdits.Process(data, relativeTime);
                captureCamDriverEvery4Seconds.Process(data, relativeTime);
            }

            var files = videoCapture.Deactivate();

            removalEdits.Stop();

            var overlayFile = SaveOverlayData(overlayData, files);

            //terminate iRacing after video capture completed
            try
            {
                //ToBe added: Option to select/deselect termination of iRacing after capturing video in new settings Dialog
                Process[] iRacingProc = Process.GetProcessesByName("iRacingSim64DX11");
                iRacingProc[0].Kill();
            }
            catch
            {
                throw new Exception("Could not terminate iRacing Simulator".F(workingFolder));
            }

            iRacing.Replay.SetSpeed(0);

            AltTabBackToApp();

            if (files.Count == 0)
            {
                throw new Exception("Unable to find video files in '{0}' - possible wrong working folder".F(workingFolder));
            }

            _WithOverlayFile(overlayFile);

            onComplete(overlayFile);
        }
Beispiel #2
0
        internal void _CaptureRaceTest(Action <string> onComplete, IEnumerable <DataSample> samples)
        {
            //identify wheather highlights video only is selected and OBS pause/resume can be used (to be implemented)
            if (bRecordUsingPauseResume)
            {
                //Retrieve list of raceEvents selected depending on the duration of the highlight video
                var totalRaceEvents = RaceEventExtension.GetInterestingRaceEvents(overlayData.RaceEvents.ToList());

                ApplyFirstLapCameraDirection(samples, replayControl);


                //Record the selected race events into a highlight video
                raceVideo.Activate(workingFolder);                                      //Active video-capturing and send start command to recording software.

                OverlayData.CamDriver curCamDriver = overlayData.CamDrivers.First();

                //start thread to control / switch cameras while recording
                ReplayControl.cameraControl.ReplayCameraControlTask(overlayData);

                //ReplayControl.cameraControl.CameraOnDriver(short.Parse(curCamDriver.CurrentDriver.CarNumber), (short)curCamDriver.camGroupNumber);

                //cycle through all raceEvents selected for the highlight video and record them  (REMARK: Camera switching not implemented yet)
                foreach (var raceEvent in totalRaceEvents)
                {
                    TraceInfo.WriteLine("ADV_RECORDING: Type: {0} | Durations-Span: {1} | ".F(raceEvent.GetType(), raceEvent.Duration));

                    //jump to selected RaceEvent in iRacing Replay
                    int framePositionInRace = raceStartFrameNumber + (int)Math.Round(raceEvent.StartTime * 60.0);
                    iRacing.Replay.MoveToFrame(raceStartFrameNumber + (int)Math.Round(raceEvent.StartTime * 60.0));

                    iRacing.Replay.SetSpeed((int)replaySpeeds.normal);          //start iRacing Replay at selected position

                    raceVideo.Resume();                                         //resume recording

                    TraceDebug.WriteLine("Recording Race-Event. Frame-Position: {0}  | Duration: {1} ms".F(framePositionInRace, 1000 * raceEvent.Duration));

                    Thread.Sleep((int)(1000 * raceEvent.Duration));            //pause thread until scene is fully recorded.
                    raceVideo.Pause();                                         //pause recording software before jumping to new position in iRacing Replay
                }


                TraceDebug.WriteLine("Video Capture of Race-Events completed");
                raceVideo.Stop();
            }
            else            //Code to be removed after being able to implment working solution where analysis phase and replay-capture phase are distinct processes.
            //use local variables for original code instead of global variables introduced to support full analysis in analysis-phase

            {
                var overlayData        = new OverlayData();
                var removalEdits       = new RemovalEdits(overlayData.RaceEvents);
                var commentaryMessages = new CommentaryMessages(overlayData);
                var recordPitStop      = new RecordPitStop(commentaryMessages);
                var fastestLaps        = new RecordFastestLaps(overlayData);
                var replayControl      = new ReplayControl(samples.First().SessionData, incidents, removalEdits, TrackCameras);
                var sessionDataCapture = new SessionDataCapture(overlayData);
                var captureLeaderBoardEveryHalfSecond = new SampleFilter(TimeSpan.FromSeconds(0.5),
                                                                         new CaptureLeaderBoard(overlayData, commentaryMessages, removalEdits).Process);
                var captureCamDriverEveryQuaterSecond = new SampleFilter(TimeSpan.FromSeconds(0.25),
                                                                         new CaptureCamDriver(overlayData).Process);

                var captureCamDriverEvery4Seconds = new SampleFilter(TimeSpan.FromSeconds(4),
                                                                     new LogCamDriver().Process);


                TraceDebug.WriteLine("Cameras:");
                TraceDebug.WriteLine(TrackCameras.ToString());



                var videoCapture = new VideoCapture();

                ApplyFirstLapCameraDirection(samples, replayControl);

                samples = samples
                          .VerifyReplayFrames()
                          .WithCorrectedPercentages()
                          .WithCorrectedDistances()
                          .WithFastestLaps()
                          .WithFinishingStatus()
                          .WithPitStopCounts()
                          .TakeUntil(3.Seconds()).Of(d => d.Telemetry.LeaderHasFinished && d.Telemetry.RaceCars.All(c => c.HasSeenCheckeredFlag || c.HasRetired || c.TrackSurface != TrackLocation.OnTrack))
                          .TakeUntil(3.Seconds()).AfterReplayPaused();

                if (shortTestOnly)
                {
                    samples = samples.AtSpeed(Settings.Default.TimingFactorForShortTest);
                    Settings.AppliedTimingFactor = 1.0 / Settings.Default.TimingFactorForShortTest;
                }

                videoCapture.Activate(workingFolder);                           //Start video capturing FileName will be given by recording software.
                var startTime = DateTime.Now;

                overlayData.CapturedVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

                foreach (var data in samples)
                {
                    var relativeTime = DateTime.Now - startTime;

                    TraceDebug.WriteLine("Recording at time: {0}", relativeTime);

                    replayControl.Process(data);
                    sessionDataCapture.Process(data);
                    captureLeaderBoardEveryHalfSecond.Process(data, relativeTime);
                    captureCamDriverEveryQuaterSecond.Process(data, relativeTime);
                    recordPitStop.Process(data, relativeTime);
                    fastestLaps.Process(data, relativeTime);
                    removalEdits.Process(data, relativeTime);
                    captureCamDriverEvery4Seconds.Process(data, relativeTime);
                }

                var files = videoCapture.Deactivate();                          //Stop video capturing - returns list with "guessed" filename. Filenmae being different from replay-script due to different time stamp.
                                                                                //investigate whether renaming of video file is necessary.

                removalEdits.Stop();

                var overlayFile = SaveOverlayData(overlayData, files);

                iRacing.Replay.SetSpeed(0);

                AltTabBackToApp();

                if (files.Count == 0)
                {
                    throw new Exception("Unable to find video files in '{0}' - possible wrong working folder".F(workingFolder));
                }

                _WithOverlayFile(overlayFile);

                onComplete(overlayFile);
            }


            //terminate iRacing after video capture completed to free up CPU resources
            if (bCloseiRacingAfterRecording)
            {
                try
                {
                    //To be added: Option to select/deselect termination of iRacing after capturing video in new settings Dialog
                    Process[] iRacingProc = Process.GetProcessesByName("iRacingSim64DX11");
                    iRacingProc[0].Kill();
                }
                catch
                {
                    throw new Exception("Could not terminate iRacing Simulator".F(workingFolder));
                }
            }
        }