Skip to content

Commit

Permalink
fix: Handle case when toRead is less than 0 in StreamHandler
Browse files Browse the repository at this point in the history
Previously, did not handle the case when `toRead` was less than 0 in the `StreamHandler` class. This commit fixes that by adding a condition to check if `toRead` is less than and logging an error if it is. If `toRead` is greater than or equal to  the code proceeds as before. This fix ensures that the program handles this edge case correctly and improves the overall reliability of the `StreamHandler` class.
  • Loading branch information
SenexCrenshaw committed Feb 10, 2024
1 parent 11a38c5 commit 81e637a
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions StreamMaster.Streams/Streams/StreamHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,24 @@ public async Task StartVideoStreamingAsync(Stream stream)
{
int overAge = accumulatedBytes + readBytes - videoBufferSize;
int toRead = readBytes - overAge;
videoBuffer.Write(clientDataToSend[..toRead]);
if (toRead < 0)
{
logger.LogError(overAge, "toRead is less than {overAge}", overAge);
logger.LogError(overAge, "accumulatedBytes {accumulatedBytes}", accumulatedBytes);
logger.LogError(overAge, "readBytes {readBytes}", readBytes);
logger.LogError(overAge, "readBytes {videoBufferSize}", videoBufferSize);
}
else
{
videoBuffer.Write(clientDataToSend[..toRead]);

byte[] videoMemory = videoBuffer.ReadLatestData();
Task task = BuildVideoInfoAsync(videoMemory);
byte[] videoMemory = videoBuffer.ReadLatestData();
Task task = BuildVideoInfoAsync(videoMemory);

++toRead;
accumulatedBytes = readBytes - toRead;
videoBuffer.Write(clientDataToSend[toRead..readBytes]);
++toRead;
accumulatedBytes = readBytes - toRead;
videoBuffer.Write(clientDataToSend[toRead..readBytes]);
}
}
else
{
Expand Down

0 comments on commit 81e637a

Please sign in to comment.