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

Commit b32dcec

Browse files
author
techyian
committed
Tidying up a few areas.
1 parent 0e7893e commit b32dcec

16 files changed

Lines changed: 332 additions & 375 deletions

src/MMALSharp.Common/Handlers/StreamCaptureHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using MMALSharp.Utility;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.IO;
54

src/MMALSharp.Common/Utility/Helpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Linq.Expressions;
33

4-
namespace MMALSharp.Utility
4+
namespace MMALSharp
55
{
66
public class Helpers
77
{

src/MMALSharp/Components/MMALCameraComponent.cs

Lines changed: 151 additions & 79 deletions
Large diffs are not rendered by default.

src/MMALSharp/Components/MMALCameraInfoComponent.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using MMALSharp.Native;
22
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
53
using System.Runtime.InteropServices;
6-
using System.Text;
7-
using System.Threading.Tasks;
84
using static MMALSharp.MMALCallerHelper;
95

106
namespace MMALSharp.Components
@@ -35,7 +31,7 @@ public MMALCameraInfoComponent() : base(MMALParameters.MMAL_COMPONENT_DEFAULT_CA
3531
this.MaxWidth = 2592;
3632
this.MaxHeight = 1944;
3733

38-
var ptr1 = Marshal.AllocHGlobal(Marshal.SizeOf<MMAL_PARAMETER_CAMERA_INFO_T>());
34+
IntPtr ptr1 = Marshal.AllocHGlobal(Marshal.SizeOf<MMAL_PARAMETER_CAMERA_INFO_T>());
3935
var str1 = (MMAL_PARAMETER_HEADER_T*)ptr1;
4036

4137
str1->Id = MMALParametersCamera.MMAL_PARAMETER_CAMERA_INFO;
@@ -51,9 +47,8 @@ public MMALCameraInfoComponent() : base(MMALParameters.MMAL_COMPONENT_DEFAULT_CA
5147
{
5248
Marshal.FreeHGlobal(ptr1);
5349

54-
//Running on newer firmware - default to first camera found.
55-
//152
56-
var ptr2 = Marshal.AllocHGlobal(Marshal.SizeOf<MMAL_PARAMETER_CAMERA_INFO_V2_T>());
50+
//Running on newer firmware - default to first camera found.
51+
IntPtr ptr2 = Marshal.AllocHGlobal(Marshal.SizeOf<MMAL_PARAMETER_CAMERA_INFO_V2_T>());
5752
var str2 = (MMAL_PARAMETER_HEADER_T*)ptr2;
5853

5954
str2->Id = MMALParametersCamera.MMAL_PARAMETER_CAMERA_INFO;
@@ -63,7 +58,7 @@ public MMALCameraInfoComponent() : base(MMALParameters.MMAL_COMPONENT_DEFAULT_CA
6358
{
6459
MMALCheck(MMALPort.mmal_port_parameter_get(this.Control.Ptr, str2), "Unable to get camera info for newer firmware.");
6560

66-
var p = (IntPtr)(str2);
61+
var p = (IntPtr)str2;
6762

6863
var s = Marshal.PtrToStructure<MMAL_PARAMETER_CAMERA_INFO_V2_T>(p);
6964

src/MMALSharp/Components/MMALComponentBase.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,7 @@ public virtual void ManagedCallback(MMALBufferImpl buffer, MMALPortBase port)
171171
/// <param name="managedCallback">The managed method to callback to from the native callback</param>
172172
internal void Start(int outputPortNumber, Action<MMALBufferImpl, MMALPortBase> managedCallback)
173173
{
174-
if (this.Handler != null && this.Handler.GetType().GetTypeInfo().IsSubclassOf(typeof(StreamCaptureHandler)))
175-
{
176-
((StreamCaptureHandler)this.Handler).NewFile();
177-
}
178-
179-
this.Outputs.ElementAt(outputPortNumber).EnablePort(managedCallback);
174+
this.Start(this.Outputs.ElementAt(outputPortNumber), managedCallback);
180175
}
181176

182177
/// <summary>

src/MMALSharp/Components/MMALEncoderComponent.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Text;
88
using static MMALSharp.MMALCallerHelper;
99
using static MMALSharp.Native.MMALParametersVideo;
10-
using MMALSharp.Utility;
1110

1211
namespace MMALSharp.Components
1312
{
@@ -217,12 +216,12 @@ public MMALVideoEncoder(ICaptureHandler handler, MMALEncoding encodingType, MMAL
217216
this.InputPort = this.Inputs.ElementAt(0);
218217
this.OutputPort = this.Outputs.ElementAt(0);
219218

220-
this.OutputPort.Ptr->Format->Encoding = this.EncodingType.EncodingVal;
221-
this.OutputPort.Ptr->Format->EncodingVariant = this.PixelFormat.EncodingVal;
219+
this.OutputPort.Ptr->Format->encoding = this.EncodingType.EncodingVal;
220+
this.OutputPort.Ptr->Format->encodingVariant = this.PixelFormat.EncodingVal;
222221

223222
this.ConfigureBitrate();
224223

225-
this.OutputPort.Ptr->Format->Bitrate = this.Bitrate;
224+
this.OutputPort.Ptr->Format->bitrate = this.Bitrate;
226225

227226
this.OutputPort.Ptr->BufferSize = 512 * 1024;
228227
this.OutputPort.Ptr->BufferNum = this.OutputPort.BufferNumMin;
@@ -231,10 +230,10 @@ public MMALVideoEncoder(ICaptureHandler handler, MMALEncoding encodingType, MMAL
231230
MMALCameraConfig.VideoResolution.Height,
232231
new MMAL_RECT_T(0, 0, MMALCameraConfig.VideoResolution.Width, MMALCameraConfig.VideoResolution.Height),
233232
new MMAL_RATIONAL_T(0, 1),
234-
this.OutputPort.Ptr->Format->Es->Video.Par,
235-
this.OutputPort.Ptr->Format->Es->Video.ColorSpace);
233+
this.OutputPort.Ptr->Format->es->video.Par,
234+
this.OutputPort.Ptr->Format->es->video.ColorSpace);
236235

237-
MMALCamera.Instance.Camera.VideoPort.Ptr->Format->Es->Video = vFormat;
236+
MMALCamera.Instance.Camera.VideoPort.Ptr->Format->es->video = vFormat;
238237

239238
this.OutputPort.Commit();
240239

@@ -581,8 +580,8 @@ public MMALImageEncoder(ICaptureHandler handler, MMALEncoding encodingType, MMAL
581580
this.InputPort = this.Inputs.ElementAt(0);
582581
this.OutputPort = this.Outputs.ElementAt(0);
583582

584-
this.OutputPort.Ptr->Format->Encoding = this.EncodingType.EncodingVal;
585-
this.OutputPort.Ptr->Format->EncodingVariant = this.PixelFormat.EncodingVal;
583+
this.OutputPort.Ptr->Format->encoding = this.EncodingType.EncodingVal;
584+
this.OutputPort.Ptr->Format->encodingVariant = this.PixelFormat.EncodingVal;
586585

587586
this.OutputPort.Ptr->BufferNum = Math.Max(this.OutputPort.Ptr->BufferNumRecommended, this.OutputPort.Ptr->BufferNumMin);
588587
this.OutputPort.Ptr->BufferSize = Math.Max(this.OutputPort.Ptr->BufferSizeRecommended, this.OutputPort.Ptr->BufferSizeMin);

src/MMALSharp/Exceptions.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using MMALSharp.Native;
22
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
73

84
namespace MMALSharp
95
{
@@ -167,9 +163,6 @@ public static void MMALCheck(MMALUtil.MMAL_STATUS_T status, string prefix)
167163
default:
168164
throw new MMALException(status, "Unknown error occurred");
169165
}
170-
171-
172-
throw new MMALException(status, prefix);
173166
}
174167
}
175168
}

src/MMALSharp/MMALCamera.cs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using MMALSharp.Components;
22
using MMALSharp.Native;
3-
using MMALSharp.Utility;
43
using System;
54
using System.Collections.Generic;
65
using System.Linq;
@@ -153,7 +152,7 @@ public async Task TakeRawPicture(ICaptureHandler handler)
153152
{
154153
Console.WriteLine($"Preparing to take picture - Resolution: {MMALCameraConfig.StillResolution.Width} x {MMALCameraConfig.StillResolution.Height}");
155154

156-
await BeginProcessing(this.Camera, null, this.Camera.StillPort, 0);
155+
await BeginProcessing(this.Camera, null, this.Camera.StillPort, MMALCameraComponent.MMALCameraStillPort);
157156
}
158157
finally
159158
{
@@ -280,10 +279,10 @@ public async Task TakePictureTimelapse(MMALPortImpl connPort, Timelapse tl, bool
280279
/// Helper method to begin processing image data. Starts the Camera port and awaits until processing is complete.
281280
/// Cleans up resources upon finish.
282281
/// </summary>
283-
/// <param name="component"></param>
284-
/// <param name="connection"></param>
285-
/// <param name="cameraPort"></param>
286-
/// <param name="outputPort"></param>
282+
/// <param name="component">The component we are processing data on</param>
283+
/// <param name="connection">The connection between </param>
284+
/// <param name="cameraPort">The camera port which image data is coming from</param>
285+
/// <param name="outputPort">The output port we are processing data from</param>
287286
/// <returns>The awaitable Task</returns>
288287
private async Task BeginProcessing(MMALComponentBase component, MMALConnectionImpl connection, MMALPortImpl cameraPort, int outputPort)
289288
{
@@ -412,29 +411,11 @@ public MMALCamera ConfigureCamera()
412411
}
413412

414413
this.DisableCamera();
415-
416-
this.SetSaturation(MMALCameraConfig.Saturation);
417-
this.SetSharpness(MMALCameraConfig.Sharpness);
418-
this.SetContrast(MMALCameraConfig.Contrast);
419-
this.SetBrightness(MMALCameraConfig.Brightness);
420-
this.SetISO(MMALCameraConfig.ISO);
421-
this.SetVideoStabilisation(MMALCameraConfig.VideoStabilisation);
422-
this.SetExposureCompensation(MMALCameraConfig.ExposureCompensation);
423-
this.SetExposureMode(MMALCameraConfig.ExposureMode);
424-
this.SetExposureMeteringMode(MMALCameraConfig.ExposureMeterMode);
425-
this.SetAwbMode(MMALCameraConfig.AwbMode);
426-
this.SetAwbGains(MMALCameraConfig.AwbGainsR, MMALCameraConfig.AwbGainsB);
427-
this.SetImageFx(MMALCameraConfig.ImageFx);
428-
this.SetColourFx(MMALCameraConfig.ColourFx);
429-
this.SetRotation(MMALCameraConfig.Rotation);
430-
this.SetShutterSpeed(MMALCameraConfig.ShutterSpeed);
431-
this.SetStatsPass(MMALCameraConfig.StatsPass);
432-
this.SetDRC(MMALCameraConfig.DrcLevel);
433-
this.SetFlips(MMALCameraConfig.Flips);
434-
this.SetZoom(MMALCameraConfig.ROI);
435-
436-
this.EnableCamera();
437414

415+
this.Camera.SetCameraParameters();
416+
417+
this.EnableCamera();
418+
438419
return this;
439420
}
440421

src/MMALSharp/MMALCameraConfig.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static class MMALCameraConfig
137137
public static MMALEncoding PreviewEncoding { get; set; } = MMALEncoding.MMAL_ENCODING_OPAQUE;
138138
public static MMALEncoding PreviewSubformat { get; set; } = MMALEncoding.MMAL_ENCODING_I420;
139139

140-
public static Resolution PreviewResolution { get; set; } = Resolution.As720p;
140+
public static Resolution PreviewResolution { get; set; } = new Resolution(1024, 768);
141141

142142
/*
143143
* -----------------------------------------------------------------------------------------------------------
@@ -257,15 +257,15 @@ public enum TimelapseMode
257257
Minute
258258
}
259259

260-
public class Resolution
260+
public class Resolution : IComparable<Resolution>
261261
{
262262
public int Width { get; set; }
263263
public int Height { get; set; }
264264

265265
public Resolution(int width, int height)
266266
{
267-
this.Width = MMALUtil.VCOS_ALIGN_UP(width, 16);
268-
this.Height = MMALUtil.VCOS_ALIGN_UP(height, 16);
267+
this.Width = width;
268+
this.Height = height;
269269
}
270270

271271
/*
@@ -297,7 +297,32 @@ public Resolution(int width, int height)
297297
public static Resolution As1080p => new Resolution(1920, 1080);
298298

299299
public static Resolution As1440p => new Resolution(2560, 1440);
300-
300+
301+
/// <summary>
302+
/// Compares this Resolution instance against the Resolution passed in.
303+
/// </summary>
304+
/// <param name="res"></param>
305+
/// <returns>0 if width and height are same. 1 if source width is greater than target. -1 if target greater than source.</returns>
306+
public int CompareTo(Resolution res)
307+
{
308+
if (this.Width == res.Width && this.Height == res.Height)
309+
{
310+
return 0;
311+
}
312+
if (this.Width == res.Width && this.Height > res.Height)
313+
{
314+
return 1;
315+
}
316+
if (this.Width == res.Width && this.Height < res.Height)
317+
{
318+
return -1;
319+
}
320+
321+
if (this.Width > res.Width)
322+
return 1;
323+
324+
return -1;
325+
}
301326
}
302327

303328
}

0 commit comments

Comments
 (0)