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

Commit

Permalink
#124. Latest changes for Rawcam component. Various I2C bits wired up …
Browse files Browse the repository at this point in the history
…and reporting as working. Need to configure port pools manually and get callbacks working.
  • Loading branch information
techyian committed Feb 20, 2020
1 parent 7fb244e commit 702ae2d
Show file tree
Hide file tree
Showing 15 changed files with 299 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ private void AddExifTag(ExifTag exifTag)
}
finally
{
Marshal.DestroyStructure(ptr, typeof(MMAL_PARAMETER_EXIF_T));
Marshal.FreeHGlobal(ptr);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ private void ConfigureVideoProfile(int outputPort)
}
finally
{
Marshal.DestroyStructure(ptr, typeof(MMAL_PARAMETER_VIDEO_PROFILE_T));
Marshal.FreeHGlobal(ptr);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/MMALSharp/Components/IDownstreamComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ IDownstreamComponent ConfigureInputPort<TPort>(IMMALPortConfig config, IInputCap
/// <param name="outputPort">The output port number.</param>
/// <param name="config">The port configuration object.</param>
/// <param name="handler">The capture handler to use with this port.</param>
/// <param name="copyFrom">Optional port to copy format from.</param>
/// <returns>This component.</returns>
IDownstreamComponent ConfigureOutputPort<TPort>(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler)
IDownstreamComponent ConfigureOutputPort<TPort>(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler, IInputPort copyFrom = null)
where TPort : IOutputPort;
}
}
5 changes: 3 additions & 2 deletions src/MMALSharp/Components/MMALDownstreamComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ public virtual IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPor
/// <param name="outputPort">The output port number to configure.</param>
/// <param name="config">User provided port configuration object.</param>
/// <param name="handler">The output port capture handler.</param>
/// <param name="copyFrom">Optional port to copy format from.</param>
/// <returns>This <see cref="MMALDownstreamComponent"/>.</returns>
public virtual unsafe IDownstreamComponent ConfigureOutputPort<TPort>(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler)
public virtual unsafe IDownstreamComponent ConfigureOutputPort<TPort>(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler, IInputPort copyFrom = null)
where TPort : IOutputPort
{
this.Outputs[outputPort] = (IOutputPort)Activator.CreateInstance(typeof(TPort), (IntPtr)(&(*this.Ptr->Output[outputPort])), this, Guid.NewGuid());

return this.ConfigureOutputPort(outputPort, config, handler);
return this.ConfigureOutputPort(outputPort, config, handler, copyFrom);
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/MMALSharp/Components/MMALRawcamComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private unsafe void ConfigureCameraInterface(MMAL_CAMERA_INTERFACE_T cameraInter
}
finally
{
Marshal.DestroyStructure(ptr, typeof(MMAL_PARAMETER_CAMERA_INTERFACE_T));
Marshal.FreeHGlobal(ptr);
}
}
Expand All @@ -106,6 +107,7 @@ private unsafe void ConfigureCameraClockingMode(MMAL_CAMERA_CLOCKING_MODE_T cloc
}
finally
{
Marshal.DestroyStructure(ptr, typeof(MMAL_PARAMETER_CAMERA_CLOCKING_MODE_T));
Marshal.FreeHGlobal(ptr);
}
}
Expand All @@ -127,6 +129,7 @@ private unsafe void ConfigureCameraRxConfig(MMALRawcamRxConfig rxConfig)
}
finally
{
Marshal.DestroyStructure(ptr, typeof(MMAL_PARAMETER_CAMERA_RX_CONFIG_T));
Marshal.FreeHGlobal(ptr);
}
}
Expand All @@ -149,6 +152,7 @@ private unsafe void ConfigureTimingRegisters(MMALRawcamTimingConfig timingConfig
}
finally
{
Marshal.DestroyStructure(ptr, typeof(MMAL_PARAMETER_CAMERA_RX_TIMING_T));
Marshal.FreeHGlobal(ptr);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/MMALSharp/Components/MMALRendererComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public unsafe void ConfigureRenderer()
}
finally
{
Marshal.DestroyStructure(ptr, typeof(MMAL_DISPLAYREGION_T));
Marshal.FreeHGlobal(ptr);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/MMALSharp/IBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT License. Please see LICENSE.txt for License info.
// </copyright>

using System;
using System.Collections.Generic;
using MMALSharp.Native;

Expand Down Expand Up @@ -99,6 +100,14 @@ public interface IBuffer : IMMALObject
/// <param name="eof">Signal that we've reached the end of the input file.</param>
void ReadIntoBuffer(byte[] source, int length, bool eof);

/// <summary>
/// Primes the buffer for use via vcsm.
/// </summary>
/// <param name="handle">The vcsm opaque handle.</param>
/// <param name="bufferSize">The buffer size.</param>
/// <param name="userData">The memory handle.</param>
void ReadIntoBufferVcsm(IntPtr handle, int bufferSize, IntPtr userData);

/// <summary>
/// Acquire a buffer header. Acquiring a buffer header increases a reference counter on it and makes
/// sure that the buffer header won't be recycled until all the references to it are gone.
Expand Down
22 changes: 20 additions & 2 deletions src/MMALSharp/MMALBufferImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public unsafe class MMALBufferImpl : MMALObject, IBuffer
/// <summary>
/// Pointer to the data associated with this buffer header.
/// </summary>
public byte* Data => this.Ptr->data;
public IntPtr Data => this.Ptr->data;

/// <summary>
/// Defines what the buffer header contains. This is a FourCC with 0 as a special value meaning stream data.
Expand Down Expand Up @@ -185,7 +185,7 @@ public byte[] GetBufferData()

try
{
var ps = this.Ptr->data + this.Offset;
var ps = (byte*)this.Ptr->data + this.Offset;
var buffer = new byte[(int)this.Ptr->Length];
Marshal.Copy((IntPtr)ps, buffer, 0, buffer.Length);
MMALBuffer.mmal_buffer_header_mem_unlock(this.Ptr);
Expand Down Expand Up @@ -226,6 +226,24 @@ public void ReadIntoBuffer(byte[] source, int length, bool eof)
Marshal.Copy(source, 0, (IntPtr)this.Ptr->data, length);
}

/// <summary>
/// Primes the buffer for use via vcsm.
/// </summary>
/// <param name="handle">The vcsm opaque handle.</param>
/// <param name="bufferSize">The buffer size.</param>
/// <param name="userData">The memory handle.</param>
public void ReadIntoBufferVcsm(IntPtr handle, int bufferSize, IntPtr userData)
{
if (MMALCameraConfig.Debug)
{
MMALLog.Logger.LogDebug($"Priming buffer to handle {bufferSize} bytes.");
}

this.Ptr->data = handle;
this.Ptr->length = (uint)bufferSize;
this.Ptr->userData = userData;
}

/// <summary>
/// Acquire a buffer header. Acquiring a buffer header increases a reference counter on it and makes
/// sure that the buffer header won't be recycled until all the references to it are gone.
Expand Down
4 changes: 4 additions & 0 deletions src/MMALSharp/MMALCameraExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ internal static void SetAnnotateSettings(this MMALCameraComponent camera)
}
catch
{
Marshal.DestroyStructure(ptrV4, typeof(MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T));
Marshal.FreeHGlobal(ptrV4);

ptrV4 = IntPtr.Zero;

MMALLog.Logger.LogWarning("Unable to set V4 annotation structure. Trying V3. Please update firmware to latest version.");
Expand All @@ -358,6 +360,7 @@ internal static void SetAnnotateSettings(this MMALCameraComponent camera)
}
finally
{
Marshal.DestroyStructure(ptr, typeof(MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T));
Marshal.FreeHGlobal(ptr);
}
}
Expand Down Expand Up @@ -394,6 +397,7 @@ internal static void DisableAnnotate(this MMALCameraComponent camera)
}
finally
{
Marshal.DestroyStructure(ptr, typeof(MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T));
Marshal.FreeHGlobal(ptr);
}
}
Expand Down
Loading

0 comments on commit 702ae2d

Please sign in to comment.