Simplified ContainsInputOutput implementation

Former-commit-id: 1d51163a05
This commit is contained in:
Максим Багрянцев 2020-04-28 18:50:29 +03:00
parent b0aedbad87
commit e462b424eb
3 changed files with 16 additions and 8 deletions

View file

@ -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)
{

View file

@ -102,10 +102,8 @@ public void Add(params Argument[] values)
/// <returns></returns>
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;
}
/// <summary>
@ -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<Type, Argument>[] array, int arrayIndex)
{
_args.CopyTo(array, arrayIndex);

View file

@ -75,7 +75,7 @@ public async Task<VideoInfo> 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<VideoInfo> 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 };