Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
VideoWritersViewModel moved to ViewCore project
Browse files Browse the repository at this point in the history
  • Loading branch information
MathewSachin committed Mar 23, 2019
1 parent b3a6420 commit d44e99f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
47 changes: 27 additions & 20 deletions src/Captura.Console/ConsoleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ class ConsoleManager : IDisposable
readonly ScreenShotModel _screenShotModel;
readonly IEnumerable<IVideoSourceProvider> _videoSourceProviders;
readonly WebcamModel _webcamModel;
readonly VideoWritersViewModel _videoWritersViewModel;
readonly IPlatformServices _platformServices;
readonly IMessageProvider _messageProvider;

public ConsoleManager(Settings Settings,
RecordingModel RecordingModel,
ScreenShotModel ScreenShotModel,
IEnumerable<IVideoSourceProvider> VideoSourceProviders,
VideoWritersViewModel VideoWritersViewModel,
IPlatformServices PlatformServices,
WebcamModel WebcamModel,
IMessageProvider MessageProvider)
Expand All @@ -38,7 +36,6 @@ public ConsoleManager(Settings Settings,
_recordingModel = RecordingModel;
_screenShotModel = ScreenShotModel;
_videoSourceProviders = VideoSourceProviders;
_videoWritersViewModel = VideoWritersViewModel;
_platformServices = PlatformServices;
_webcamModel = WebcamModel;
_messageProvider = MessageProvider;
Expand Down Expand Up @@ -103,7 +100,7 @@ public void Start(StartCmdOptions StartOptions)

var videoSourceKind = HandleVideoSource(StartOptions);

HandleVideoEncoder(StartOptions);
var videoWriter = HandleVideoEncoder(StartOptions, out var videoWriterKind);

HandleAudioSource(StartOptions);

Expand All @@ -124,8 +121,8 @@ public void Start(StartCmdOptions StartOptions)
if (!_recordingModel.StartRecording(new RecordingModelParams
{
VideoSourceKind = videoSourceKind,
VideoWriterKind = _videoWritersViewModel.SelectedVideoWriterKind,
VideoWriter = _videoWritersViewModel.SelectedVideoWriter
VideoWriterKind = videoWriterKind,
VideoWriter = videoWriter
}, StartOptions.FileName))
return;

Expand Down Expand Up @@ -197,33 +194,40 @@ void HandleAudioSource(StartCmdOptions StartOptions)
}
}

void HandleVideoEncoder(StartCmdOptions StartOptions)
IVideoWriterItem HandleVideoEncoder(StartCmdOptions StartOptions, out IVideoWriterProvider VideoWriterKind)
{
if (StartOptions.Encoder == null)
return;

var ffmpegExists = FFmpegService.FFmpegExists;
var sharpAviWriterProvider = ServiceProvider.Get<SharpAviWriterProvider>();

// FFmpeg
if (ffmpegExists && Regex.IsMatch(StartOptions.Encoder, @"^ffmpeg:\d+$"))
{
var index = int.Parse(StartOptions.Encoder.Substring(7));

_videoWritersViewModel.SelectedVideoWriterKind = ServiceProvider.Get<FFmpegWriterProvider>();
var ffmpegWriterProvider = ServiceProvider.Get<FFmpegWriterProvider>();
var writers = ffmpegWriterProvider.ToArray();

if (index < _videoWritersViewModel.AvailableVideoWriters.Count)
_videoWritersViewModel.SelectedVideoWriter = _videoWritersViewModel.AvailableVideoWriters[index];
if (index < writers.Length)
{
VideoWriterKind = ffmpegWriterProvider;

return writers[index];
}
}

// SharpAvi
else if (ServiceProvider.FileExists("SharpAvi.dll") && Regex.IsMatch(StartOptions.Encoder, @"^sharpavi:\d+$"))
{
var index = int.Parse(StartOptions.Encoder.Substring(9));

_videoWritersViewModel.SelectedVideoWriterKind = ServiceProvider.Get<SharpAviWriterProvider>();
var writers = sharpAviWriterProvider.ToArray();

if (index < _videoWritersViewModel.AvailableVideoWriters.Count)
_videoWritersViewModel.SelectedVideoWriter = _videoWritersViewModel.AvailableVideoWriters[index];
if (index < writers.Length)
{
VideoWriterKind = sharpAviWriterProvider;

return writers[index];
}
}

// Stream
Expand All @@ -232,20 +236,23 @@ void HandleVideoEncoder(StartCmdOptions StartOptions)
var url = StartOptions.Encoder.Substring(7);
_settings.FFmpeg.CustomStreamingUrl = url;

_videoWritersViewModel.SelectedVideoWriterKind = ServiceProvider.Get<StreamingWriterProvider>();
VideoWriterKind = ServiceProvider.Get<StreamingWriterProvider>();

_videoWritersViewModel.SelectedVideoWriter = StreamingWriterProvider.GetCustomStreamingCodec();
return StreamingWriterProvider.GetCustomStreamingCodec();
}

// Rolling
else if (ffmpegExists && Regex.IsMatch(StartOptions.Encoder, @"^roll:\d+$"))
{
var duration = int.Parse(StartOptions.Encoder.Substring(5));

_videoWritersViewModel.SelectedVideoWriterKind = ServiceProvider.Get<FFmpegWriterProvider>();
VideoWriterKind = ServiceProvider.Get<FFmpegWriterProvider>();

_videoWritersViewModel.SelectedVideoWriter = new FFmpegRollingWriterItem(duration);
return new FFmpegRollingWriterItem(duration);
}

VideoWriterKind = sharpAviWriterProvider;
return sharpAviWriterProvider.First();
}

void HandleWebcam(StartCmdOptions StartOptions)
Expand Down
2 changes: 0 additions & 2 deletions src/Captura.Core/CoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ static void BindViewModels(IBinder Binder)
Binder.BindSingleton<ScreenShotModel>();
Binder.BindSingleton<RecordingModel>();
Binder.BindSingleton<WebcamModel>();
Binder.BindSingleton<VideoWritersViewModel>();
Binder.BindSingleton<KeymapViewModel>();

Binder.Bind<IRefreshable>(Binder.Get<WebcamModel>);
Binder.Bind<IRefreshable>(Binder.Get<VideoWritersViewModel>);
}

static void BindUpdateChecker(IBinder Binder)
Expand Down
5 changes: 4 additions & 1 deletion src/Captura.ViewCore/ViewCoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ public void OnLoad(IBinder Binder)
Binder.BindSingleton<HotkeysViewModel>();
Binder.BindSingleton<FFmpegLogViewModel>();
Binder.BindSingleton<FFmpegCodecsViewModel>();
Binder.BindSingleton<VideoSourcesViewModel>();
Binder.BindSingleton<ViewConditionsModel>();

Binder.BindSingleton<VideoSourcesViewModel>();
Binder.BindSingleton<VideoWritersViewModel>();
Binder.Bind<IRefreshable>(Binder.Get<VideoWritersViewModel>);

Binder.BindSingleton<CustomOverlaysViewModel>();
Binder.BindSingleton<CustomImageOverlaysViewModel>();
Binder.BindSingleton<CensorOverlaysViewModel>();
Expand Down

0 comments on commit d44e99f

Please sign in to comment.