void proxy_NewFrame(object sender, NewFrameEventArgs e) { FFMPEGProxy proxy = sender as FFMPEGProxy; var frame = e.NewFrame; if (proxy == null || frame == null) { return; } Dispatcher.Invoke(new Action (() => { if (!IsBitmapValid(frame)) { double ratio = proxy.GuessAspectRatio(frame); if (ratio == 0) { ratio = 16 / 9; } bitmapFrame = new WriteableBitmap( frame.Width, frame.Height, 96, 96 * ratio, PixelFormats.Pbgra32 , null ); videodest.Source = bitmapFrame; } bitmapFrame.Lock(); proxy.CopyToBuffer(frame, bitmapFrame.BackBuffer, bitmapFrame.BackBufferStride); bitmapFrame.AddDirtyRect(new Int32Rect(0, 0, frame.Width, frame.Height)); bitmapFrame.Unlock(); })); // e.NewFrame }
private void Button_Click(object sender, RoutedEventArgs e) { if (proxy != null) { var oldproxy = proxy; oldproxy.NewFrame -= proxy_NewFrame; // desynchronisation pour eviter les interblocage avec l'affichage. Task.Run(() => oldproxy.Dispose()); } proxy = new FFMPEGProxy(); proxy.NewFrame += proxy_NewFrame; proxy.Options.Add("fflags", "nobuffer"); proxy.Options.Add("tot", "nobuffer"); string uri = "rtsp://mafreebox.freebox.fr/fbxtv_pub/stream?namespace=1&service=201&flavour=sd"; Task.Run( () => { try { proxy.Open(uri); } catch (Exception error) { Console.WriteLine(error.Message); } }); }
void PlaySomethingInvalid() { FFMPEGProxy testProxy = new FFMPEGProxy(); testProxy.Open("InexistentFileName"); }
void GuessAspectRatio() { FFMPEGProxy testProxy = new FFMPEGProxy(); Assert.ThrowsAny <ArgumentNullException>(() => testProxy.GuessAspectRatio(null)); }
void PlayNull() { FFMPEGProxy testProxy = new FFMPEGProxy(); Assert.ThrowsAny <ArgumentNullException>(() => testProxy.Open(null)); }