Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dev' into 47-rawcam-isp-components
Browse files Browse the repository at this point in the history
  • Loading branch information
techyian committed Jan 20, 2020
2 parents 610ba75 + 976ee0d commit 7ff0bf8
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 4 deletions.
6 changes: 6 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions run-sonar.ps1
Original file line number Diff line number Diff line change
@@ -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 = "dev"
$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'"
}
1 change: 1 addition & 0 deletions src/MMALSharp.Common/MMALSharp.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<VersionPrefix>0.6.0</VersionPrefix>
<CodeAnalysisRuleSet>..\..\StyleCop.Analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<ProjectGuid>{65a1440e-72e1-4943-b469-5cfba8cb5633}</ProjectGuid> <!--Project guid for Sonar-->
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='AnyCPU'">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand Down
1 change: 1 addition & 0 deletions src/MMALSharp.FFmpeg/MMALSharp.FFmpeg.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<VersionPrefix>0.6.0</VersionPrefix>
<CodeAnalysisRuleSet>..\..\StyleCop.Analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<ProjectGuid>{0600c674-e587-4267-89f3-b52ae9591f80}</ProjectGuid> <!--Project guid for Sonar-->
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='AnyCPU'">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand Down
7 changes: 5 additions & 2 deletions src/MMALSharp.Processing/Handlers/InputCaptureHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public class InputCaptureHandler : IInputCaptureHandler
/// </summary>
public Stream CurrentStream { get; }

private int Processed { get; set; }
/// <summary>
/// The total amount of data processed by this <see cref="InputCaptureHandler"/>.
/// </summary>
public int Processed { get; protected set; }

/// <summary>
/// Creates a new instance of the <see cref="InputCaptureHandler"/> class with the specified input stream, output directory and output filename extension.
Expand All @@ -42,7 +45,7 @@ public virtual ProcessResult Process(uint allocSize)

this.Processed += read;

if (read < allocSize)
if (read == 0)
{
return new ProcessResult { Success = true, BufferFeed = buffer, EOF = true, DataLength = read };
}
Expand Down
1 change: 1 addition & 0 deletions src/MMALSharp.Processing/MMALSharp.Processing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<VersionPrefix>0.6.0</VersionPrefix>
<CodeAnalysisRuleSet>..\..\StyleCop.Analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<ProjectGuid>{dabc9991-56ad-4235-ba86-63def12c261a}</ProjectGuid> <!--Project guid for Sonar-->
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
36 changes: 34 additions & 2 deletions src/MMALSharp/MMALCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,46 @@ public void ForceStop(IOutputPort port)
});
}

/// <summary>
/// Self-contained method for recording raw video frames directly from the camera's video port.
/// Uses the encoding and pixel format as set in <see cref="MMALCameraConfig.VideoEncoding"/> and <see cref="MMALCameraConfig.VideoSubformat"/>.
/// </summary>
/// <param name="handler">The video capture handler to apply to the encoder.</param>
/// <param name="cancellationToken">A cancellationToken to signal when to stop video capture.</param>
/// <returns>The awaitable Task.</returns>
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<SplitterVideoPort>(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);
}
}

/// <summary>
/// Self-contained method for recording H.264 video for a specified amount of time. Records at 30fps, 25Mb/s at the highest quality.
/// </summary>
/// <param name="handler">The video capture handler to apply to the encoder.</param>
/// <param name="cancellationToken">A cancellationToken to signal when to stop video capture.</param>
/// <param name="split">Used for Segmented video mode.</param>
/// <returns>The awaitable Task.</returns>
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)
{
Expand Down Expand Up @@ -116,7 +148,7 @@ public async Task TakeVideo(IOutputCaptureHandler handler, CancellationToken can
await this.ProcessAsync(this.Camera.VideoPort, cancellationToken).ConfigureAwait(false);
}
}

/// <summary>
/// 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.
Expand Down
1 change: 1 addition & 0 deletions src/MMALSharp/MMALSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<VersionPrefix>0.6.0</VersionPrefix>
<CodeAnalysisRuleSet>..\..\StyleCop.Analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<ProjectGuid>{47af9428-8246-4267-bc76-5fc648848e40}</ProjectGuid> <!--Project guid for Sonar-->
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='AnyCPU'">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand Down

0 comments on commit 7ff0bf8

Please sign in to comment.