Skip to content

Commit

Permalink
Merge pull request #11 from Speykious/hang
Browse files Browse the repository at this point in the history
Fix `CameraManager.GetCamera()` hanging and `FrameConverter` crashing
  • Loading branch information
adryzz authored Dec 17, 2021
2 parents e900cc4 + d2e32e8 commit 9359180
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 4 additions & 5 deletions SeeShark.Example.Ascii/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ static void Main(string[] args)
/// </summary>
public static void OnFrameEventHandler(object? _sender, FrameEventArgs e)
{
// Don't redraw the frame if it's not new, unless it's resized.
if (e.Status != FFmpeg.DecodeStatus.NewFrame)
return;

var frame = e.Frame;
if (converter == null || Console.WindowWidth != converter.SrcWidth ||
Console.WindowHeight != converter.SrcHeight)
Expand All @@ -130,11 +134,6 @@ public static void OnFrameEventHandler(object? _sender, FrameEventArgs e)
converter?.Dispose();
converter = new FrameConverter(frame, Console.WindowWidth, Console.WindowHeight, PixelFormat.Gray8);
}
else if (e.Status != FFmpeg.DecodeStatus.NewFrame)
{
// Don't redraw the frame if it's not new, unless it's resized.
return;
}

// Resize the frame to the size of the terminal window, then draw it in ASCII.
Frame cFrame = converter.Convert(frame);
Expand Down
1 change: 0 additions & 1 deletion SeeShark/FFmpeg/VideoStreamDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public VideoStreamDecoder(string url, AVInputFormat* inputFormat = null)

var formatContext = FormatContext;
ffmpeg.avformat_open_input(&formatContext, url, inputFormat, null).ThrowExceptionIfError();
ffmpeg.avformat_find_stream_info(formatContext, null).ThrowExceptionIfError();

AVCodec* codec = null;
StreamIndex = ffmpeg
Expand Down
3 changes: 3 additions & 0 deletions SeeShark/FrameConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public FrameConverter(
int srcWidth, int srcHeight, PixelFormat srcPixelFormat,
int dstWidth, int dstHeight, PixelFormat dstPixelFormat)
{
if (srcWidth == 0 || srcHeight == 0 || dstWidth == 0 || dstHeight == 0)
throw new ArgumentException("Source/Destination's Width/Height cannot be zero");

SrcWidth = srcWidth;
SrcHeight = srcHeight;
DstWidth = dstWidth;
Expand Down

0 comments on commit 9359180

Please sign in to comment.