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

Commit

Permalink
#47. Adding copyFrom parameter to ConfigureOutputPort.
Browse files Browse the repository at this point in the history
  • Loading branch information
techyian committed Jan 20, 2020
1 parent 7ff0bf8 commit 076cfbd
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public MMALImageEncoder(bool rawBayer = false, bool useExif = true, bool continu
}

/// <inheritdoc />
public override IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler)
public override IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler, IInputPort copyFrom = null)
{
base.ConfigureOutputPort(outputPort, config, handler);
base.ConfigureOutputPort(outputPort, config, handler, copyFrom);

if (this.RawBayer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public MMALVideoEncoder()
}

/// <inheritdoc />
public override IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler)
public override IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler, IInputPort copyFrom = null)
{
this.Quality = config.Quality;

Expand All @@ -86,7 +86,7 @@ public override IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPo
config.Quality, bitrate, config.ZeroCopy, config.Timeout, config.BufferNum, bufferSize, config.Crop,
config.StoreMotionVectors);

base.ConfigureOutputPort(outputPort, config, handler);
base.ConfigureOutputPort(outputPort, config, handler, copyFrom);

if (this.Outputs[outputPort].EncodingType == MMALEncoding.H264)
{
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 @@ -67,8 +67,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(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler);
IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler, IInputPort copyFrom = null);

/// <summary>
/// Configures the output port. In addition, it will create a new instance of the port
Expand Down
12 changes: 10 additions & 2 deletions src/MMALSharp/Components/MMALDownstreamComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public virtual IDownstreamComponent ConfigureOutputPort(IMMALPortConfig config,
/// <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 IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler)
public virtual IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler, IInputPort copyFrom = null)
{
if (this.ProcessingPorts.ContainsKey(outputPort))
{
Expand All @@ -114,7 +115,14 @@ public virtual IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPor

this.ProcessingPorts.Add(outputPort, this.Outputs[outputPort]);

this.Outputs[outputPort].Configure(config, this.Inputs[0], handler);
if (copyFrom != null)
{
this.Outputs[outputPort].Configure(config, copyFrom, handler);
}
else
{
this.Outputs[outputPort].Configure(config, this.Inputs[0], handler);
}

return this;
}
Expand Down
26 changes: 12 additions & 14 deletions src/MMALSharp/Components/MMALRawcamComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public class MMALRawcamComponent : MMALDownstreamHandlerComponent
public unsafe MMALRawcamComponent()
: base(MMAL_COMPONENT_RAWCAM)
{
// Default to use still image port behaviour.
this.Inputs.Add(new InputPort((IntPtr)(&(*this.Ptr->Input[0])), this, Guid.NewGuid()));
// Default to use still image port behaviour.
this.Outputs.Add(new StillPort((IntPtr)(&(*this.Ptr->Output[0])), this, Guid.NewGuid()));
}

Expand All @@ -47,29 +46,28 @@ public unsafe MMALRawcamComponent()
/// <param name="outputPortType">The user defined output port type.</param>
public unsafe MMALRawcamComponent(Type outputPortType)
: base(MMAL_COMPONENT_RAWCAM)
{
this.Inputs.Add(new InputPort((IntPtr)(&(*this.Ptr->Input[0])), this, Guid.NewGuid()));
{
this.Outputs.Add((IOutputPort)Activator.CreateInstance(outputPortType, (IntPtr)(&(*this.Ptr->Output[0])), this, Guid.NewGuid()));
}

/// <inheritdoc />
public override IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler)
{
public override IDownstreamComponent ConfigureOutputPort(int outputPort, IMMALPortConfig config, IOutputCaptureHandler handler, IInputPort copyFrom = null)
{
if (config is MMALRawcamPortConfig)
{
var rawcamConfig = config as MMALRawcamPortConfig;

this.ConfigureCameraInterface(rawcamConfig.CameraInterface);
this.ConfigureCameraClockingMode(rawcamConfig.ClockingMode);
// this.ConfigureCameraClockingMode(rawcamConfig.ClockingMode);
this.ConfigureCameraRxConfig(rawcamConfig.RxConfig);
this.ConfigureTimingRegisters(rawcamConfig.TimingConfig);
}
else
{
MMALLog.Logger.LogWarning($"Rawcam component should be given port configuration of type {nameof(MMALRawcamPortConfig)}. Defaults will be used.");
}
return base.ConfigureOutputPort(outputPort, config, handler);

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

private unsafe void ConfigureCameraInterface(MMAL_CAMERA_INTERFACE_T cameraInterface)
Expand All @@ -83,7 +81,7 @@ private unsafe void ConfigureCameraInterface(MMAL_CAMERA_INTERFACE_T cameraInter
try
{
MMALCheck(
MMALPort.mmal_port_parameter_set(this.Inputs[0].Ptr, (MMAL_PARAMETER_HEADER_T*)ptr),
MMALPort.mmal_port_parameter_set(this.Outputs[0].Ptr, (MMAL_PARAMETER_HEADER_T*)ptr),
"Unable to set camera interface type.");
}
finally
Expand All @@ -103,7 +101,7 @@ private unsafe void ConfigureCameraClockingMode(MMAL_CAMERA_CLOCKING_MODE_T cloc
try
{
MMALCheck(
MMALPort.mmal_port_parameter_set(this.Inputs[0].Ptr, (MMAL_PARAMETER_HEADER_T*)ptr),
MMALPort.mmal_port_parameter_set(this.Outputs[0].Ptr, (MMAL_PARAMETER_HEADER_T*)ptr),
"Unable to set camera clocking mode.");
}
finally
Expand All @@ -124,7 +122,7 @@ private unsafe void ConfigureCameraRxConfig(MMALRawcamRxConfig rxConfig)
try
{
MMALCheck(
MMALPort.mmal_port_parameter_set(this.Inputs[0].Ptr, (MMAL_PARAMETER_HEADER_T*)ptr),
MMALPort.mmal_port_parameter_set(this.Outputs[0].Ptr, (MMAL_PARAMETER_HEADER_T*)ptr),
"Unable to set camera peripheral config.");
}
finally
Expand All @@ -146,7 +144,7 @@ private unsafe void ConfigureTimingRegisters(MMALRawcamTimingConfig timingConfig
try
{
MMALCheck(
MMALPort.mmal_port_parameter_set(this.Inputs[0].Ptr, (MMAL_PARAMETER_HEADER_T*)ptr),
MMALPort.mmal_port_parameter_set(this.Outputs[0].Ptr, (MMAL_PARAMETER_HEADER_T*)ptr),
"Unable to set camera timing registers.");
}
finally
Expand Down
14 changes: 0 additions & 14 deletions src/MMALSharp/Components/MMALSplitterComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,5 @@ public override IDownstreamComponent ConfigureInputPort(IMMALPortConfig config,

return this;
}

/// <inheritdoc />
public override IDownstreamComponent ConfigureInputPort(IMMALPortConfig config, IInputCaptureHandler handler)
{
var bufferNum = Math.Max(this.Inputs[0].BufferNumRecommended, 3);

config = new MMALPortConfig(config.EncodingType, config.PixelFormat, config.Width, config.Height, config.Framerate,
config.Quality, config.Bitrate, config.ZeroCopy, config.Timeout, bufferNum, config.BufferSize, config.Crop,
config.StoreMotionVectors);

base.ConfigureInputPort(config, handler);

return this;
}
}
}
7 changes: 3 additions & 4 deletions src/MMALSharp/Ports/MMALRawcamPortConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@ public class MMALRawcamPortConfig : MMALPortConfig
/// <param name="encodingType">The encoding type. Set this to specify the output format. Colour format should be
/// RGB565, RGB888, ABGR8888, YUV420 packed planar, YUV422 packed
/// planar, or one of the flavours of YUYV.</param>
/// <param name="pixelFormat">The pixel format.</param>
/// <param name="bitrate">The output bitrate.</param>
/// <param name="pixelFormat">The pixel format.</param>
/// <param name="timeout">Video record timeout.</param>
/// <param name="cameraInterface">The physical camera interface type.</param>
/// <param name="clockingMode">Camera peripheral clocking mode.</param>
/// <param name="rxConfig">The receiver peripheral configuration for unpacking/packing DPCM, and decoding or encoding Bayer images.</param>
/// <param name="timingConfig">Camera peripheral timing registers.</param>
public MMALRawcamPortConfig(MMALEncoding encodingType, MMALEncoding pixelFormat, int bitrate, DateTime? timeout,
public MMALRawcamPortConfig(MMALEncoding encodingType, MMALEncoding pixelFormat, DateTime? timeout,
MMAL_CAMERA_INTERFACE_T cameraInterface, MMAL_CAMERA_CLOCKING_MODE_T clockingMode, MMALRawcamRxConfig rxConfig,
MMALRawcamTimingConfig timingConfig)
: base(encodingType, pixelFormat, 0, bitrate, timeout, null, false)
: base(encodingType, pixelFormat, 0, 0, 0, 0, 0, true, timeout)
{
this.CameraInterface = cameraInterface;
this.ClockingMode = clockingMode;
Expand Down

0 comments on commit 076cfbd

Please sign in to comment.