From e462b424eb7aeefdc8f4395dcd72aaa5aaaaa297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=91=D0=B0=D0=B3?= =?UTF-8?q?=D1=80=D1=8F=D0=BD=D1=86=D0=B5=D0=B2?= Date: Tue, 28 Apr 2020 18:50:29 +0300 Subject: [PATCH] Simplified ContainsInputOutput implementation Former-commit-id: 1d51163a05e6b8ad1b1567be02907827bdd01574 --- FFMpegCore.Test/VideoTest.cs | 4 ++-- FFMpegCore/FFMPEG/Argument/ArgumentContainer.cs | 16 ++++++++++++---- FFMpegCore/FFMPEG/FFProbe.cs | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 9d7009d..63c40d0 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -72,7 +72,7 @@ private void ConvertFromStreamPipe(VideoType type, ArgumentContainer container) var input = VideoInfo.FromFileInfo(VideoLibrary.LocalVideoWebm); using (var inputStream = System.IO.File.OpenRead(input.FullName)) { - var pipeSource = new StreamPipeSource(inputStream); + var pipeSource = new StreamPipeDataWriter(inputStream); var arguments = new ArgumentContainer { new InputPipeArgument(pipeSource) }; foreach (var arg in container) { @@ -183,7 +183,7 @@ public void ConvertFromPipe(VideoType type, ArgumentContainer container, PixelFo try { - var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, fmt, 256, 256)); + var videoFramesSource = new RawVideoPipeDataWriter(BitmapSource.CreateBitmaps(128, fmt, 256, 256)); var arguments = new ArgumentContainer { new InputPipeArgument(videoFramesSource) }; foreach (var arg in container) { diff --git a/FFMpegCore/FFMPEG/Argument/ArgumentContainer.cs b/FFMpegCore/FFMPEG/Argument/ArgumentContainer.cs index d2e5532..03e2014 100644 --- a/FFMpegCore/FFMPEG/Argument/ArgumentContainer.cs +++ b/FFMpegCore/FFMPEG/Argument/ArgumentContainer.cs @@ -102,10 +102,8 @@ public void Add(params Argument[] values) /// public bool ContainsInputOutput() { - return ((ContainsKey(typeof(InputArgument)) && !ContainsKey(typeof(ConcatArgument)) && !ContainsKey(typeof(InputPipeArgument))) || - (!ContainsKey(typeof(InputArgument)) && ContainsKey(typeof(ConcatArgument)) && !ContainsKey(typeof(InputPipeArgument))) || - (!ContainsKey(typeof(InputArgument)) && !ContainsKey(typeof(ConcatArgument)) && ContainsKey(typeof(InputPipeArgument)))) - && ContainsKey(typeof(OutputArgument)); + return CountExistedKeys(typeof(InputArgument), typeof(ConcatArgument), typeof(InputPipeArgument)) == 1 && + CountExistedKeys(typeof(OutputArgument), typeof(OutputPipeArgument)) == 1; } /// @@ -118,6 +116,16 @@ public bool ContainsKey(Type key) return _args.ContainsKey(key); } + public int CountExistedKeys(params Type[] types) + { + int count = 0; + for(int i =0; i < types.Length; i++) + if (_args.ContainsKey(types[i])) + count++; + + return count; + } + public void CopyTo(KeyValuePair[] array, int arrayIndex) { _args.CopyTo(array, arrayIndex); diff --git a/FFMpegCore/FFMPEG/FFProbe.cs b/FFMpegCore/FFMPEG/FFProbe.cs index a7aec84..53ee313 100644 --- a/FFMpegCore/FFMPEG/FFProbe.cs +++ b/FFMpegCore/FFMPEG/FFProbe.cs @@ -75,7 +75,7 @@ public async Task ParseVideoInfoAsync(VideoInfo info) public VideoInfo ParseVideoInfo(System.IO.Stream stream) { var info = new VideoInfo(); - var streamPipeSource = new StreamPipeSource(stream); + var streamPipeSource = new StreamPipeDataWriter(stream); var pipeArgument = new InputPipeArgument(streamPipeSource); var instance = new Instance(_ffprobePath, BuildFFProbeArguments(pipeArgument.PipePath)) { DataBufferCapacity = _outputCapacity }; @@ -105,7 +105,7 @@ public VideoInfo ParseVideoInfo(System.IO.Stream stream) public async Task ParseVideoInfoAsync(System.IO.Stream stream) { var info = new VideoInfo(); - var streamPipeSource = new StreamPipeSource(stream); + var streamPipeSource = new StreamPipeDataWriter(stream); var pipeArgument = new InputPipeArgument(streamPipeSource); var instance = new Instance(_ffprobePath, BuildFFProbeArguments(pipeArgument.PipePath)) { DataBufferCapacity = _outputCapacity };