Skip to content

Commit

Permalink
Fix cscore
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Feb 19, 2024
1 parent 6e32605 commit 6d69bb6
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 188 deletions.
20 changes: 10 additions & 10 deletions src/cscore/HttpCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public class HttpCamera : VideoCamera
{
private static CsSource CreateHttpCamera(string name, string url, HttpCameraKind kind)
{
var source = CsNative.CreateHttpCamera(name, url, kind, out var status);
VideoException.ThrowIfFailed(status);
var source = CsNative.CreateHttpCamera(name, url, kind);

return source;
}

private static CsSource CreateHttpCamera(string name, ReadOnlySpan<string> urls, HttpCameraKind kind)
{
var source = CsNative.CreateHttpCamera(name, urls, kind, out var status);
VideoException.ThrowIfFailed(status);
var source = CsNative.CreateHttpCamera(name, urls, kind);

return source;
}

Expand All @@ -33,22 +33,22 @@ public HttpCameraKind HttpCameraKind
{
get
{
var ret = CsNative.GetHttpCameraKind(Handle, out var status);
VideoException.ThrowIfFailed(status);
var ret = CsNative.GetHttpCameraKind(Handle);

return ret;
}
}

public void SetUrls(ReadOnlySpan<string> urls)
{
CsNative.SetHttpCameraUrls(Handle, urls, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetHttpCameraUrls(Handle, urls);

}

public string[] GetUrls()
{
var ret = CsNative.GetHttpCameraUrls(Handle, out var status);
VideoException.ThrowIfFailed(status);
var ret = CsNative.GetHttpCameraUrls(Handle);

return ret;
}
}
12 changes: 6 additions & 6 deletions src/cscore/ImageSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ public abstract class ImageSink(CsSink handle) : VideoSink(handle)
{
set
{
CsNative.SetSinkDescription(Handle, value, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetSinkDescription(Handle, value);

}
}

public string GetError()
{
CsNative.GetSinkError(Handle, out var error, out var status);
VideoException.ThrowIfFailed(status);
CsNative.GetSinkError(Handle, out var error);

return error;
}

public bool Enabled
{
set
{
CsNative.SetSinkEnabled(Handle, value, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetSinkEnabled(Handle, value);

}
}
}
31 changes: 15 additions & 16 deletions src/cscore/ImageSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,53 @@ public abstract class ImageSource(CsSource handle) : VideoSource(handle)
{
public void NotifyError(string msg)
{
CsNative.NotifySourceError(Handle, msg, out var status);
VideoException.ThrowIfFailed(status);
CsNative.NotifySourceError(Handle, msg);

}

public bool Connected
{
set
{
CsNative.SetSourceConnected(Handle, value, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetSourceConnected(Handle, value);

}
}

public new string Description
{
set
{
CsNative.SetSourceDescription(Handle, value, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetSourceDescription(Handle, value);

}
}

public VideoProperty CreateProperty(string name, PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value)
{
var property = CsNative.CreateSourceProperty(Handle, name, kind, minimum, maximum, step, defaultValue, value, out var status);
VideoException.ThrowIfFailed(status);
var property = CsNative.CreateSourceProperty(Handle, name, kind, minimum, maximum, step, defaultValue, value);

return new VideoProperty(property);
}

public VideoProperty CreateIntegerProperty(string name, int minimum, int maximum, int step, int defaultValue, int value)
{
var property = CsNative.CreateSourceProperty(Handle, name, PropertyKind.Integer, minimum, maximum, step, defaultValue, value, out var status);
VideoException.ThrowIfFailed(status);
var property = CsNative.CreateSourceProperty(Handle, name, PropertyKind.Integer, minimum, maximum, step, defaultValue, value);

return new VideoProperty(property);
}

public VideoProperty CreateBooleanProperty(string name, bool defaultValue, bool value)
{
var property = CsNative.CreateSourceProperty(Handle, name, PropertyKind.Boolean, 0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0, out var status);
VideoException.ThrowIfFailed(status);
var property = CsNative.CreateSourceProperty(Handle, name, PropertyKind.Boolean, 0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0);

return new VideoProperty(property);
}

public VideoProperty CreateStringProperty(string name, string value)
{
var property = CsNative.CreateSourceProperty(Handle, name, PropertyKind.String, 0, 0, 0, 0, 0, out var status);
VideoException.ThrowIfFailed(status);
var property = CsNative.CreateSourceProperty(Handle, name, PropertyKind.String, 0, 0, 0, 0, 0);

return new VideoProperty(property)
{
StringValue = value
Expand All @@ -64,7 +64,6 @@ public VideoProperty CreateStringProperty(string name, string value)

public void SetEnumPropertyChoices(VideoProperty property, ReadOnlySpan<string> choices)
{
CsNative.SetSourceEnumPropertyChoices(Handle, property.Handle, choices, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetSourceEnumPropertyChoices(Handle, property.Handle, choices);
}
}
42 changes: 15 additions & 27 deletions src/cscore/MJpegServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class MJpegServer : VideoSink
{
private static CsSink CreateMJpegServer(string name, string listenAddress, int port)
{
var ret = CsNative.CreateMjpegServer(name, listenAddress, port, out var status);
VideoException.ThrowIfFailed(status);
var ret = CsNative.CreateMjpegServer(name, listenAddress, port);

return ret;
}

Expand All @@ -24,8 +24,7 @@ public string ListenAddress
{
get
{
CsNative.GetMjpegServerListenAddress(Handle, out var address, out var status);
VideoException.ThrowIfFailed(status);
CsNative.GetMjpegServerListenAddress(Handle, out var address);
return address;
}
}
Expand All @@ -34,46 +33,35 @@ public int Port
{
get
{
int port = CsNative.GetMjpegServerPort(Handle, out var status);
VideoException.ThrowIfFailed(status);
int port = CsNative.GetMjpegServerPort(Handle);
return port;
}
}

public void SetResolution(int width, int height)
{
CsProperty prop = CsNative.GetSinkProperty(Handle, "width"u8, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetProperty(prop, width, out status);
VideoException.ThrowIfFailed(status);

prop = CsNative.GetSinkProperty(Handle, "height"u8, out status);
VideoException.ThrowIfFailed(status);
CsNative.SetProperty(prop, height, out status);
VideoException.ThrowIfFailed(status);
CsProperty prop = CsNative.GetSinkProperty(Handle, "width"u8);
CsNative.SetProperty(prop, width);
prop = CsNative.GetSinkProperty(Handle, "height"u8);
CsNative.SetProperty(prop, height);
}

public void SetFPS(int fps)
{
CsProperty prop = CsNative.GetSinkProperty(Handle, "fps"u8, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetProperty(prop, fps, out status);
VideoException.ThrowIfFailed(status);
CsProperty prop = CsNative.GetSinkProperty(Handle, "fps"u8);
CsNative.SetProperty(prop, fps);
}

public void SetCompression(int quality)
{
CsProperty prop = CsNative.GetSinkProperty(Handle, "compression"u8, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetProperty(prop, quality, out status);
VideoException.ThrowIfFailed(status);
CsProperty prop = CsNative.GetSinkProperty(Handle, "compression"u8);
CsNative.SetProperty(prop, quality);
}

public void SetDefaultCompression(int quality)
{
CsProperty prop = CsNative.GetSinkProperty(Handle, "default_compression"u8, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetProperty(prop, quality, out status);
VideoException.ThrowIfFailed(status);
CsProperty prop = CsNative.GetSinkProperty(Handle, "default_compression"u8);
CsNative.SetProperty(prop, quality);

}
}
4 changes: 2 additions & 2 deletions src/cscore/Natives/CsNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public static string[] GetEnumPropertyChoices(CsProperty property, out StatusVal
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial CsSource CreateHttpCamera(WpiString name, WpiString url, HttpCameraKind kind, out StatusValue status);

[AutomateStatusCheck]
[LibraryImport("cscore", EntryPoint = "CS_CreateHttpCameraMulti")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial CsSource CreateHttpCamera(WpiString name, [MarshalUsing(typeof(WpiStringMarshaller), ElementIndirectionDepth = 1)] ReadOnlySpan<string> urls, int count, HttpCameraKind kind, out StatusValue status);

[AutomateStatusCheck]
public static CsSource CreateHttpCamera(string name, ReadOnlySpan<string> urls, HttpCameraKind kind, out StatusValue status)
{
return CreateHttpCamera(name, urls, urls.Length, kind, out status);
Expand Down Expand Up @@ -337,11 +337,11 @@ public static string[] GetHttpCameraUrls(CsSource source, out StatusValue status
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial CsProperty CreateSourceProperty(CsSource source, WpiString name, PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, out StatusValue status);

[AutomateStatusCheck]
[LibraryImport("cscore", EntryPoint = "CS_SetSourceEnumPropertyChoices")]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial void SetSourceEnumPropertyChoices(CsSource source, CsProperty property, [MarshalUsing(typeof(WpiStringMarshaller), ElementIndirectionDepth = 1)] ReadOnlySpan<string> choices, int count, out StatusValue status);

[AutomateStatusCheck]
public static void SetSourceEnumPropertyChoices(CsSource source, CsProperty property, ReadOnlySpan<string> choices, out StatusValue status)
{
SetSourceEnumPropertyChoices(source, property, choices, choices.Length, out status);
Expand Down
12 changes: 6 additions & 6 deletions src/cscore/Raw/RawSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class RawSink(string name) : ImageSink(CreateRawSink(name))
{
private static CsSink CreateRawSink(string name)
{
var sink = CsNative.CreateRawSink(name, out var status);
VideoException.ThrowIfFailed(status);
var sink = CsNative.CreateRawSink(name);

return sink;
}

Expand All @@ -21,15 +21,15 @@ public long GrabFrame(RawFrameReader frame)

public long GrabFrame(RawFrameReader frame, TimeSpan timeout)
{
var time = CsNative.GrabRawSinkFrame(Handle, frame, timeout.TotalSeconds, out var status);
VideoException.ThrowIfFailed(status);
var time = CsNative.GrabRawSinkFrame(Handle, frame, timeout.TotalSeconds);

return (long)time;
}

public long GrabFrameNoTimeout(RawFrameReader frame)
{
var time = CsNative.GrabRawSinkFrame(Handle, frame, out var status);
VideoException.ThrowIfFailed(status);
var time = CsNative.GrabRawSinkFrame(Handle, frame);

return (long)time;
}
}
8 changes: 4 additions & 4 deletions src/cscore/Raw/RawSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class RawSource(string name, VideoMode mode) : ImageSource(CreateRawSourc
{
private static CsSource CreateRawSource(string name, ref readonly VideoMode mode)
{
var source = CsNative.CreateRawSource(name, mode, out var status);
VideoException.ThrowIfFailed(status);
var source = CsNative.CreateRawSource(name, mode);

return source;
}

Expand All @@ -24,7 +24,7 @@ private static CsSource CreateRawSource(string name, ref readonly VideoMode mode

public void PutFrame(RawFrameWriter image)
{
CsNative.PutRawSourceFrame(Handle, image, out var status);
VideoException.ThrowIfFailed(status);
CsNative.PutRawSourceFrame(Handle, image);

}
}
28 changes: 13 additions & 15 deletions src/cscore/UsbCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ public class UsbCamera : VideoCamera
{
private static CsSource CreateUsbCameraDev(string name, int dev)
{
var handle = CsNative.CreateUsbCamera(name, dev, out var status);
VideoException.ThrowIfFailed(status);
var handle = CsNative.CreateUsbCamera(name, dev);

return handle;
}

private static CsSource CreateUsbCameraPath(string name, string path)
{
var handle = CsNative.CreateUsbCamera(name, path, out var status);
VideoException.ThrowIfFailed(status);
var handle = CsNative.CreateUsbCamera(name, path);

return handle;
}

Expand All @@ -30,40 +30,38 @@ public UsbCamera(string name, string path) : base(CreateUsbCameraPath(name, path
public static UsbCameraInfo[] EnumerateUsbCameras()
{
var info = CsNative.EnumerateUsbCameras(out var status);
VideoException.ThrowIfFailed(status);

return info;
}

public string Path
{
get
{
CsNative.GetUsbCameraPath(Handle, out var path, out var status);
VideoException.ThrowIfFailed(status);
CsNative.GetUsbCameraPath(Handle, out var path);

return path;
}
set
{
CsNative.SetUsbCameraPath(Handle, value, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetUsbCameraPath(Handle, value);

}
}

public UsbCameraInfo Info
{
get
{
var info = CsNative.GetUsbCameraInfo(Handle, out var status);
VideoException.ThrowIfFailed(status);
var info = CsNative.GetUsbCameraInfo(Handle);

return info;
}
}

public void SetConnectVerbose(int level)
{
var property = CsNative.GetSourceProperty(Handle, "connect_verbose"u8, out var status);
VideoException.ThrowIfFailed(status);
CsNative.SetProperty(property, level, out status);
VideoException.ThrowIfFailed(status);
var property = CsNative.GetSourceProperty(Handle, "connect_verbose"u8);
CsNative.SetProperty(property, level);
}
}
Loading

0 comments on commit 6d69bb6

Please sign in to comment.