-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Remove prometheus * fix: Remove bad logging
- Loading branch information
1 parent
497b721
commit bc1e9b3
Showing
22 changed files
with
331 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,3 +370,4 @@ Dockerfile.sm | |
basever | ||
buildver | ||
smver | ||
release.config.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base | ||
ARG TARGETPLATFORM | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
ARG TARGETVARIANT | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update -yq \ | ||
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache | ||
|
||
RUN \ | ||
--mount=type=cache,id=apt-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/apt \ | ||
apt-get update -yq \ | ||
&& apt-get upgrade -yq \ | ||
&& apt-get install -yq --no-install-recommends ffmpeg gosu postgresql postgresql-common curl gnupg lsb-release \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& mkdir /docker-entrypoint-initdb.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
using System.Reflection; | ||
|
||
[assembly: AssemblyVersion("0.13.1.0")] | ||
[assembly: AssemblyFileVersion("0.13.1.0")] | ||
[assembly: AssemblyInformationalVersion("0.13.1.Sha.19d3cf9344080dfb25a6559125410d00a3540665")] | ||
[assembly: AssemblyVersion("0.13.2.3")] | ||
[assembly: AssemblyFileVersion("0.13.2.3")] | ||
[assembly: AssemblyInformationalVersion("0.13.2-sh.3.Sha.d1570728f5c010f25cd649695fc1d1e339b3d084")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,125 @@ | ||
namespace StreamMaster.Domain; | ||
|
||
public class CircularBuffer | ||
namespace StreamMaster.Domain | ||
{ | ||
private readonly byte[] buffer; | ||
private int writePosition = 0; | ||
private readonly object lockObj = new(); | ||
|
||
public CircularBuffer(int capacity) | ||
public class CircularBuffer | ||
{ | ||
if (capacity <= 0) | ||
{ | ||
throw new ArgumentException("Capacity must be greater than 0", nameof(capacity)); | ||
} | ||
|
||
Capacity = capacity; | ||
buffer = new byte[capacity]; | ||
} | ||
private readonly byte[] buffer; | ||
private int writePosition = 0; | ||
private readonly object lockObj = new(); | ||
|
||
public void Write(byte[] data) | ||
{ | ||
if (data == null) | ||
/// <summary> | ||
/// Initializes a new instance of the CircularBuffer class with a specified capacity. | ||
/// </summary> | ||
/// <param name="capacity">The maximum amount of data the buffer can hold.</param> | ||
/// <exception cref="ArgumentException">Thrown when capacity is less than or equal to 0.</exception> | ||
public CircularBuffer(int capacity) | ||
{ | ||
throw new ArgumentNullException(nameof(data)); | ||
if (capacity <= 0) | ||
{ | ||
throw new ArgumentException("Capacity must be greater than 0.", nameof(capacity)); | ||
} | ||
|
||
Capacity = capacity; | ||
buffer = new byte[capacity]; | ||
} | ||
|
||
lock (lockObj) | ||
/// <summary> | ||
/// Writes data into the circular buffer. If the buffer does not have enough space, | ||
/// older data will be overwritten. | ||
/// </summary> | ||
/// <param name="data">The byte array to write into the buffer.</param> | ||
/// <exception cref="ArgumentNullException">Thrown when data is null.</exception> | ||
public void Write(byte[] data) | ||
{ | ||
int dataLength = data.Length; | ||
if (dataLength > Capacity) | ||
if (data == null) | ||
{ | ||
// If data is larger than the capacity, write only the last part of data that fits. | ||
Array.Copy(data, dataLength - Capacity, buffer, 0, Capacity); | ||
writePosition = 0; | ||
AvailableData = Capacity; | ||
throw new ArgumentNullException(nameof(data)); | ||
} | ||
else | ||
{ | ||
int part1Len = Math.Min(Capacity - writePosition, dataLength); | ||
Array.Copy(data, 0, buffer, writePosition, part1Len); | ||
|
||
if (part1Len < dataLength) | ||
lock (lockObj) | ||
{ | ||
int dataLength = data.Length; | ||
if (dataLength > Capacity) | ||
{ | ||
// If the data was split, write the remaining part at the beginning of the buffer. | ||
Array.Copy(data, part1Len, buffer, 0, dataLength - part1Len); | ||
// Overwrite the buffer with the last 'Capacity' bytes of 'data' | ||
Array.Copy(data, dataLength - Capacity, buffer, 0, Capacity); | ||
writePosition = 0; | ||
AvailableData = Capacity; | ||
} | ||
else | ||
{ | ||
// Calculate how much data can be written without wrapping | ||
int part1Len = Math.Min(Capacity - writePosition, dataLength); | ||
Array.Copy(data, 0, buffer, writePosition, part1Len); | ||
|
||
if (part1Len < dataLength) | ||
{ | ||
// Wrap and write the remaining data | ||
Array.Copy(data, part1Len, buffer, 0, dataLength - part1Len); | ||
} | ||
|
||
writePosition = (writePosition + dataLength) % Capacity; | ||
AvailableData = Math.Min(AvailableData + dataLength, Capacity); | ||
// Update write position and available data, wrapping the write position if necessary | ||
writePosition = (writePosition + dataLength) % Capacity; | ||
AvailableData = Math.Min(AvailableData + dataLength, Capacity); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public byte[] ReadLatestData() | ||
{ | ||
lock (lockObj) | ||
/// <summary> | ||
/// Reads the most recent data written into the buffer without removing it. | ||
/// </summary> | ||
/// <returns>A byte array containing the latest data. The size of the array is up to the amount of available data.</returns> | ||
public byte[] ReadLatestData() | ||
{ | ||
byte[] latestData = new byte[AvailableData]; // Prepare an array to hold the latest data. | ||
|
||
if (AvailableData == 0) | ||
lock (lockObj) | ||
{ | ||
// No data available to read. | ||
return latestData; | ||
} | ||
byte[] latestData = new byte[AvailableData]; | ||
|
||
if (writePosition == 0 || AvailableData == Capacity) | ||
{ | ||
// If writePosition is 0, it means the buffer has just wrapped around or is exactly full, | ||
// so the latest data is the entire buffer. | ||
Array.Copy(buffer, 0, latestData, 0, AvailableData); | ||
} | ||
else | ||
{ | ||
// Calculate the start position for the latest data that's not contiguous. | ||
int startIdx = writePosition - AvailableData; | ||
if (startIdx < 0) | ||
if (AvailableData == 0) | ||
{ | ||
// The data wraps around; copy the end segment and then the start segment. | ||
startIdx += Capacity; // Correct the start index to a positive value. | ||
int part1Length = Capacity - startIdx; | ||
Array.Copy(buffer, startIdx, latestData, 0, part1Length); | ||
Array.Copy(buffer, 0, latestData, part1Length, writePosition); | ||
return latestData; // Early exit if no data available | ||
} | ||
|
||
if (writePosition == 0 || AvailableData == Capacity) | ||
{ | ||
// Buffer is exactly full, or just wrapped around | ||
Array.Copy(buffer, 0, latestData, 0, AvailableData); | ||
} | ||
else | ||
{ | ||
// All available data is contiguous and can be copied directly. | ||
Array.Copy(buffer, startIdx, latestData, 0, AvailableData); | ||
// Data wraps around the buffer end; copy in two segments | ||
int startIdx = (Capacity + writePosition - AvailableData) % Capacity; | ||
int part1Length = Math.Min(AvailableData, Capacity - startIdx); | ||
Array.Copy(buffer, startIdx, latestData, 0, part1Length); | ||
if (part1Length < AvailableData) | ||
{ | ||
Array.Copy(buffer, 0, latestData, part1Length, AvailableData - part1Length); | ||
} | ||
} | ||
} | ||
|
||
return latestData; | ||
return latestData; | ||
} | ||
} | ||
} | ||
/// <summary> | ||
/// Gets the capacity of the buffer. | ||
/// </summary> | ||
public int Capacity { get; } | ||
|
||
/// <summary> | ||
/// Gets the amount of data currently stored in the buffer. | ||
/// </summary> | ||
public int AvailableData { get; private set; } = 0; | ||
|
||
/// <summary> | ||
/// Clears all data from the buffer, resetting its state. | ||
/// </summary> | ||
public void Clear() | ||
{ | ||
lock (lockObj) | ||
{ | ||
writePosition = 0; | ||
AvailableData = 0; | ||
} | ||
} | ||
|
||
public int Capacity { get; } | ||
public int AvailableData { get; private set; } = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.