void _CaptureOpeningScenes(Action onComplete)
        {
            if (bRecordUsingPauseResume)
            {
            }
            var data    = iRacing.GetDataFeed().First();
            var session = data.SessionData.SessionInfo.Sessions.Qualifying();

            if (session == null || session.ResultsPositions == null)
            {
                return;
            }

            if (!iRacing.Replay.AttempToMoveToQualifyingSection())
            {
                return;
            }

            data = iRacing.GetDataFeed().First();
            var f = data.Telemetry.ReplayFrameNum;

            iRacing.Replay.MoveToFrame(f + 60 * 4, ReplayPositionMode.Begin, 100);
            iRacing.Replay.SetSpeed(1);

            var camera = data.SessionData.CameraInfo.Groups.FirstOrDefault(c => c.GroupName == "Scenic");

            if (camera == null)
            {
                camera = data.SessionData.CameraInfo.Groups.FirstOrDefault(c => c.GroupName.StartsWith("Pit Lane"));
            }
            if (camera == null)
            {
                camera = data.SessionData.CameraInfo.Groups.FirstOrDefault(c => c.GroupName == "Chopper");
            }
            if (camera == null)
            {
                camera = data.SessionData.CameraInfo.Groups.FirstOrDefault(c => c.GroupName == "TV3");
            }
            if (camera == null)
            {
                camera = data.SessionData.CameraInfo.Groups.First();
            }

            var scenicCameras = camera.GroupNum;
            var aCar          = data.SessionData.DriverInfo.CompetingDrivers[1].CarNumberRaw;

            //Don't use Methode from iRacing SDK - instead use methode from cameracontrol
            ReplayControl.cameraControl.CameraOnDriver((short)aCar, (short)scenicCameras);
            //iRacing.Replay.CameraOnDriver((short)aCar, (short)scenicCameras);

            //var videoCapture = new VideoCapture();

            raceVideo.Activate(workingFolder);

            Thread.Sleep(shortTestOnly ? 5000 : 20000);

            var fileNames = raceVideo.Deactivate(bRecordUsingPauseResume);

            if (fileNames.Count == 0)
            {
                return;
            }

            TraceInfo.WriteLine("Captured intro video into file {0}", fileNames[0]);
            _WithIntroVideo(fileNames[0].FileName);
        }
Exemple #2
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);
        }
Exemple #3
0
        void RunTest(string workingFolder, SynchronizationContext context)
        {
            try
            {
                TraceInfo.WriteLine("Switching to iRacing ....");

                var hwnd = Win32.Messages.FindWindow(null, "iRacing.com Simulator");
                Win32.Messages.ShowWindow(hwnd, Win32.Messages.SW_SHOWNORMAL);
                Win32.Messages.SetForegroundWindow(hwnd);
                Thread.Sleep(2000);

                TraceInfo.WriteLine("Begining Test....");
                var videoCapture = new VideoCapture();

                TraceInfo.WriteLine("Broadcasting keypress ALT+F9 to activate your video capture software");
                videoCapture.Activate(workingFolder);

                TraceInfo.WriteLine("Expecting video file to be written in folder: {0}", workingFolder);

                TraceInfo.WriteLine("Waiting for 5 seconds");

                for (var i = 5; i >= 0; i--)
                {
                    Thread.Sleep(1.Seconds());
                    TraceInfo.WriteLine("{0} Seconds...", i);
                }

                TraceInfo.WriteLine("Broadcasting keypress ALT+F9 to deactivate your video capture software");
                var filenames = videoCapture.Deactivate();


                TraceInfo.WriteLine("Minimising iRacing");

                AltTabBackToApp();

                if (filenames.Count == 0)
                {
                    TraceInfo.WriteLine("\nFailure - Did not find any video files");
                    return;
                }

                if (filenames.Count != 1)
                {
                    TraceInfo.WriteLine("\nFailure - Found more than 1 video file!");
                    return;
                }

                var filename = filenames[0];

                if (filename != null)
                {
                    TraceInfo.WriteLine("");
                    TraceInfo.WriteLine("Found your video file {0}.", filename);

                    TranscodeVideoTest(filename.FileName);
                }
                else
                {
                    TraceInfo.WriteLine("");
                    TraceInfo.WriteLine("Failure!");
                }
            }
            catch (Exception e)
            {
                TraceError.WriteLine(e.Message);
                TraceError.WriteLine(e.StackTrace);
            }
            finally
            {
                context.Post(ignored => testVideoCaptureButton.Enabled = true, null);
            }
        }
Exemple #4
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));
                }
            }
        }