public void Initialize() { try { Interop.FFmpeg.av_register_all(); Interop.FFmpeg.avformat_network_init(); unsafe { Interop.FFmpeg.av_log_set_level(FFmpegMacros.AV_LOG_INFO); Interop.av_log_set_callback_callback logCallback = (p0, level, format, vl) => { if (level > Interop.FFmpeg.av_log_get_level()) { return; } const int lineSize = 1024; var lineBuffer = stackalloc byte[lineSize]; var printPrefix = 1; Interop.FFmpeg.av_log_format_line(p0, level, format, vl, lineBuffer, lineSize, &printPrefix); var line = Marshal.PtrToStringAnsi((IntPtr)lineBuffer); Logger.Warn(line); }; Interop.FFmpeg.av_log_set_callback(logCallback); } } catch (Exception e) { Logger.Error(e, "Could not load and register FFmpeg library"); throw new DemuxerException("Could not load and register FFmpeg library", e); } }
private ArraySegment <byte> ReadPacket(int size) { try { var token = cancellationTokenSource.Token; var data = buffer.Take(size, token); return(data); } catch (TaskCanceledException) { Logger.Info("Take cancelled"); } catch (InvalidOperationException ex) { Logger.Warn(ex); } catch (Exception ex) { Logger.Error(ex, $"Unexpected exception: {ex.GetType()}"); } return(new ArraySegment <byte>()); }