From 98c0fc6c02f8ea02c3d2551d6a1d2f07ea4d8948 Mon Sep 17 00:00:00 2001 From: techyian Date: Fri, 17 Jan 2020 10:34:07 +0000 Subject: [PATCH 1/4] #99. Add raw video helper method. --- src/MMALSharp/MMALCamera.cs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/MMALSharp/MMALCamera.cs b/src/MMALSharp/MMALCamera.cs index 67ca627f..c684c737 100644 --- a/src/MMALSharp/MMALCamera.cs +++ b/src/MMALSharp/MMALCamera.cs @@ -80,6 +80,38 @@ public void ForceStop(IOutputPort port) }); } + /// + /// Self-contained method for recording raw video frames directly from the camera's video port. + /// Uses the encoding and pixel format as set in and . + /// + /// The video capture handler to apply to the encoder. + /// A cancellationToken to signal when to stop video capture. + /// The awaitable Task. + public async Task TakeRawVideo(IVideoCaptureHandler handler, CancellationToken cancellationToken) + { + using (var splitter = new MMALSplitterComponent()) + using (var renderer = new MMALVideoRenderer()) + { + this.ConfigureCameraSettings(); + + var splitterOutputConfig = new MMALPortConfig(MMALCameraConfig.VideoEncoding, MMALCameraConfig.VideoSubformat, 0); + + // Force port type to SplitterVideoPort to prevent resolution from being set against splitter component. + splitter.ConfigureOutputPort(0, splitterOutputConfig, handler); + + // Create our component pipeline. + this.Camera.VideoPort.ConnectTo(splitter); + this.Camera.PreviewPort.ConnectTo(renderer); + + MMALLog.Logger.LogInformation($"Preparing to take raw video. Resolution: {this.Camera.VideoPort.Resolution.Width} x {this.Camera.VideoPort.Resolution.Height}. " + + $"Encoder: {MMALCameraConfig.VideoEncoding.EncodingName}. Pixel Format: {MMALCameraConfig.VideoSubformat.EncodingName}."); + + // Camera warm up time + await Task.Delay(2000).ConfigureAwait(false); + await this.ProcessAsync(this.Camera.VideoPort, cancellationToken).ConfigureAwait(false); + } + } + /// /// Self-contained method for recording H.264 video for a specified amount of time. Records at 30fps, 25Mb/s at the highest quality. /// @@ -87,7 +119,7 @@ public void ForceStop(IOutputPort port) /// A cancellationToken to signal when to stop video capture. /// Used for Segmented video mode. /// The awaitable Task. - public async Task TakeVideo(IOutputCaptureHandler handler, CancellationToken cancellationToken, Split split = null) + public async Task TakeVideo(IVideoCaptureHandler handler, CancellationToken cancellationToken, Split split = null) { if (split != null && !MMALCameraConfig.InlineHeaders) { @@ -116,7 +148,7 @@ public async Task TakeVideo(IOutputCaptureHandler handler, CancellationToken can await this.ProcessAsync(this.Camera.VideoPort, cancellationToken).ConfigureAwait(false); } } - + /// /// Self-contained method to capture raw image data directly from the Camera component - this method does not use an Image encoder. /// Note: We cannot use the OPAQUE encoding format with this helper method, the capture will not fail, but will not produce valid data. For reference, RaspiStillYUV uses YUV420. From fa75e0297b11a87812265dc5a4548f8a51eea780 Mon Sep 17 00:00:00 2001 From: techyian Date: Fri, 17 Jan 2020 11:22:18 +0000 Subject: [PATCH 2/4] #116. Add SonarCloud integration. --- appveyor.yml | 6 +++++ run-sonar.ps1 | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 run-sonar.ps1 diff --git a/appveyor.yml b/appveyor.yml index 6ea5c9f7..c454197a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -36,6 +36,9 @@ - dotnet pack .\src\MMALSharp.FFmpeg\MMALSharp.FFmpeg.csproj -c %CONFIGURATION% --version-suffix %APPVEYOR_BUILD_NUMBER% - dotnet pack .\src\MMALSharp.Processing\MMALSharp.Processing.csproj -c %CONFIGURATION% --version-suffix %APPVEYOR_BUILD_NUMBER% + test_script: + - ps: .\run-sonar.ps1 + deploy: # MyGet Deployment for builds & releases - provider: NuGet @@ -86,6 +89,9 @@ - dotnet pack .\src\MMALSharp.FFmpeg\MMALSharp.FFmpeg.csproj -c %CONFIGURATION% - dotnet pack .\src\MMALSharp.Processing\MMALSharp.Processing.csproj -c %CONFIGURATION% + test_script: + - ps: .\run-sonar.ps1 + deploy: # NuGet deployment - provider: NuGet diff --git a/run-sonar.ps1 b/run-sonar.ps1 new file mode 100644 index 00000000..891c292f --- /dev/null +++ b/run-sonar.ps1 @@ -0,0 +1,62 @@ +# Adapted from: https://github.com/NLog/NLog.Extensions.Logging/blob/master/run-sonar.ps1 + +$projectFile = "src\MMALSharp\MMALSharp.csproj" +$sonarQubeId = "MMALSharp" +$github = "techyian/MMALSharp" +$baseBranch = "master" +$framework = "netstandard2.0" + + +if ($env:APPVEYOR_REPO_NAME -eq $github) { + + if (-not $env:SONAR_TOKEN) { + Write-warning "Sonar: not running SonarQube, no SONAR_KEY" + return; + } + + $prMode = $false; + $branchMode = $false; + + if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { + # first check PR as that is on the base branch + $prMode = $true; + Write-Output "Sonar: on PR $env:APPVEYOR_PULL_REQUEST_NUMBER" + } + elseif ($env:APPVEYOR_REPO_BRANCH -eq $baseBranch) { + Write-Output "Sonar: on base branch ($baseBranch)" + } + else { + $branchMode = $true; + Write-Output "Sonar: on branch $env:APPVEYOR_REPO_BRANCH" + } + + choco install "msbuild-sonarqube-runner" -y + + $sonarUrl = "https://sonarcloud.io" + $sonarKey = $env:SONAR_KEY + $sonarToken = $env:SONAR_TOKEN + $buildVersion = $env:APPVEYOR_BUILD_VERSION + + + if ($prMode) { + $pr = $env:APPVEYOR_PULL_REQUEST_NUMBER + Write-Output "Sonar: Running Sonar for PR $pr" + SonarScanner.MSBuild.exe begin /o:"$sonarKey" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.analysis.mode=preview" /d:"sonar.github.pullRequest=$pr" /d:"sonar.github.repository=$github" /d:"sonar.github.oauth=$env:GITHUB_AUTH" + } + elseif ($branchMode) { + $branch = $env:APPVEYOR_REPO_BRANCH; + Write-Output "Sonar: Running Sonar in branch mode for branch $branch" + SonarScanner.MSBuild.exe begin /o:"$sonarKey" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" /d:"sonar.branch.name=$branch" + } + else { + Write-Output "Sonar: Running Sonar in non-preview mode, on branch $env:APPVEYOR_REPO_BRANCH" + SonarScanner.MSBuild.exe begin /o:"$sonarKey" /k:"$sonarQubeId" /d:"sonar.host.url=$sonarUrl" /d:"sonar.login=$sonarToken" /v:"$buildVersion" + } + + msbuild /t:Rebuild $projectFile /p:targetFrameworks=$framework /verbosity:minimal + + SonarScanner.MSBuild.exe end /d:"sonar.login=$env:sonar_token" +} +else { + Write-Output "Sonar: not running as we're on '$env:APPVEYOR_REPO_NAME'" +} \ No newline at end of file From c8ee4e206976225e14f90aeee8238327c0a12783 Mon Sep 17 00:00:00 2001 From: techyian Date: Fri, 17 Jan 2020 11:29:16 +0000 Subject: [PATCH 3/4] #116. Add project GUIDs for SonarCloud. --- src/MMALSharp.Common/MMALSharp.Common.csproj | 1 + src/MMALSharp.FFmpeg/MMALSharp.FFmpeg.csproj | 1 + src/MMALSharp.Processing/MMALSharp.Processing.csproj | 1 + src/MMALSharp/MMALSharp.csproj | 1 + 4 files changed, 4 insertions(+) diff --git a/src/MMALSharp.Common/MMALSharp.Common.csproj b/src/MMALSharp.Common/MMALSharp.Common.csproj index c4b61e51..40eca9ed 100644 --- a/src/MMALSharp.Common/MMALSharp.Common.csproj +++ b/src/MMALSharp.Common/MMALSharp.Common.csproj @@ -17,6 +17,7 @@ 0.6.0 ..\..\StyleCop.Analyzers.ruleset bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml + {65a1440e-72e1-4943-b469-5cfba8cb5633} True diff --git a/src/MMALSharp.FFmpeg/MMALSharp.FFmpeg.csproj b/src/MMALSharp.FFmpeg/MMALSharp.FFmpeg.csproj index 40911f8d..9ce5753c 100644 --- a/src/MMALSharp.FFmpeg/MMALSharp.FFmpeg.csproj +++ b/src/MMALSharp.FFmpeg/MMALSharp.FFmpeg.csproj @@ -17,6 +17,7 @@ 0.6.0 ..\..\StyleCop.Analyzers.ruleset bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml + {0600c674-e587-4267-89f3-b52ae9591f80} True diff --git a/src/MMALSharp.Processing/MMALSharp.Processing.csproj b/src/MMALSharp.Processing/MMALSharp.Processing.csproj index ffef7a9f..39e65839 100644 --- a/src/MMALSharp.Processing/MMALSharp.Processing.csproj +++ b/src/MMALSharp.Processing/MMALSharp.Processing.csproj @@ -18,6 +18,7 @@ 0.6.0 ..\..\StyleCop.Analyzers.ruleset bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml + {dabc9991-56ad-4235-ba86-63def12c261a} diff --git a/src/MMALSharp/MMALSharp.csproj b/src/MMALSharp/MMALSharp.csproj index 6aba7a45..0405bb34 100644 --- a/src/MMALSharp/MMALSharp.csproj +++ b/src/MMALSharp/MMALSharp.csproj @@ -17,6 +17,7 @@ 0.6.0 ..\..\StyleCop.Analyzers.ruleset bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml + {47af9428-8246-4267-bc76-5fc648848e40} True From d43f2aa37f55065391725c2d93211a0f24c89077 Mon Sep 17 00:00:00 2001 From: techyian Date: Fri, 17 Jan 2020 11:40:37 +0000 Subject: [PATCH 4/4] #116. Change base branch to dev. --- run-sonar.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-sonar.ps1 b/run-sonar.ps1 index 891c292f..4bd804e8 100644 --- a/run-sonar.ps1 +++ b/run-sonar.ps1 @@ -3,7 +3,7 @@ $projectFile = "src\MMALSharp\MMALSharp.csproj" $sonarQubeId = "MMALSharp" $github = "techyian/MMALSharp" -$baseBranch = "master" +$baseBranch = "dev" $framework = "netstandard2.0"