@@ -7,7 +7,7 @@ namespace EmergenceGuardian.FFmpegExampleApplication {
7
7
/// <summary>
8
8
/// Interaction logic for FFmpegWindow.xaml
9
9
/// </summary>
10
- public partial class FFmpegWindow : Window , IUserInterface {
10
+ public partial class FFmpegWindow : Window , IUserInterfaceWindow {
11
11
public static FFmpegWindow Instance ( Window parent , string title , bool autoClose ) {
12
12
FFmpegWindow F = new FFmpegWindow ( ) ;
13
13
F . Owner = parent ;
@@ -17,15 +17,14 @@ public static FFmpegWindow Instance(Window parent, string title, bool autoClose)
17
17
return F ;
18
18
}
19
19
20
- private FFmpegProcess host ;
21
- private FFmpegProcess task ;
22
- private bool autoClose ;
23
- private string title { get ; set ; }
24
- private TimeLeftCalculator timeCalc ;
20
+ protected IProcessManager host ;
21
+ protected IProcessManagerFFmpeg hostFFmpeg ;
22
+ protected IProcessManager task ;
23
+ protected bool autoClose ;
24
+ protected string title { get ; set ; }
25
+ protected ITimeLeftCalculator timeCalc ;
25
26
26
- public void Stop ( ) {
27
- Dispatcher . Invoke ( ( ) => this . Close ( ) ) ;
28
- }
27
+ public void Stop ( ) => Dispatcher . Invoke ( ( ) => this . Close ( ) ) ;
29
28
30
29
public FFmpegWindow ( ) {
31
30
InitializeComponent ( ) ;
@@ -35,22 +34,25 @@ private void Window_Loaded(object sender, RoutedEventArgs e) {
35
34
SetPageTitle ( null ) ;
36
35
}
37
36
38
- public void DisplayTask ( FFmpegProcess taskArg ) {
37
+ public void DisplayTask ( IProcessManager taskArg ) {
39
38
Dispatcher . Invoke ( ( ) => {
40
39
if ( taskArg . Options . IsMainTask ) {
41
40
host = taskArg ;
42
- host . InfoUpdated += FFmpeg_InfoUpdated ;
43
- host . StatusUpdated += FFmpeg_StatusUpdated ;
44
- host . Completed += FFmpeg_Completed ;
41
+ hostFFmpeg = host as IProcessManagerFFmpeg ;
42
+ if ( hostFFmpeg != null ) {
43
+ hostFFmpeg . InfoUpdated += FFmpeg_InfoUpdated ;
44
+ hostFFmpeg . StatusUpdated += FFmpeg_StatusUpdated ;
45
+ }
46
+ host . ProcessCompleted += FFmpeg_Completed ;
45
47
PercentText . Text = 0 . ToString ( "p1" ) ;
46
48
SetPageTitle ( PercentText . Text ) ;
47
49
} else {
48
50
task = taskArg ;
49
51
TaskStatusText . Text = task . Options . Title ;
50
- task . Completed += ( sender , e ) => {
51
- FFmpegProcess Proc = ( FFmpegProcess ) sender ;
52
+ task . ProcessCompleted += ( sender , e ) => {
53
+ ProcessManager Proc = ( ProcessManager ) sender ;
52
54
Dispatcher . Invoke ( ( ) => {
53
- if ( e . Status == CompletionStatus . Error && ! Proc . WorkProcess . StartInfo . FileName . EndsWith ( "avs2yuv.exe" ) )
55
+ if ( e . Status == CompletionStatus . Failed && ! Proc . WorkProcess . StartInfo . FileName . EndsWith ( "avs2yuv.exe" ) )
54
56
FFmpegErrorWindow . Instance ( Owner , Proc ) ;
55
57
TaskStatusText . Text = "" ;
56
58
task = null ;
@@ -62,40 +64,42 @@ public void DisplayTask(FFmpegProcess taskArg) {
62
64
} ) ;
63
65
}
64
66
67
+ protected long ResumePos => hostFFmpeg . Options ? . ResumePos ?? 0 ;
68
+
65
69
private void SetPageTitle ( string status ) {
66
70
this . Title = string . IsNullOrEmpty ( status ) ? title : string . Format ( "{0} ({1})" , title , status ) ;
67
71
}
68
72
69
73
private void FFmpeg_InfoUpdated ( object sender , EventArgs e ) {
70
74
Dispatcher . Invoke ( ( ) => {
71
- WorkProgressBar . Maximum = host . FrameCount + host . Options . ResumePos ;
72
- timeCalc = new TimeLeftCalculator ( host . FrameCount + host . Options . ResumePos ) ;
75
+ WorkProgressBar . Maximum = hostFFmpeg . FrameCount + ResumePos ;
76
+ timeCalc = new TimeLeftCalculator ( hostFFmpeg . FrameCount + hostFFmpeg ? . Options . ResumePos ?? 0 ) ;
73
77
} ) ;
74
78
}
75
79
76
80
private bool EstimatedTimeLeftToggle = false ;
77
81
private void FFmpeg_StatusUpdated ( object sender , FFmpeg . StatusUpdatedEventArgs e ) {
78
82
Dispatcher . Invoke ( ( ) => {
79
- WorkProgressBar . Value = e . Status . Frame + host . Options . ResumePos ;
83
+ WorkProgressBar . Value = e . Status . Frame + ResumePos ;
80
84
PercentText . Text = ( WorkProgressBar . Value / WorkProgressBar . Maximum ) . ToString ( "p1" ) ;
81
85
SetPageTitle ( PercentText . Text ) ;
82
86
FpsText . Text = e . Status . Fps . ToString ( ) ;
83
87
84
88
// Time left will be updated only 1 out of 2 to prevent changing too quick.
85
89
EstimatedTimeLeftToggle = ! EstimatedTimeLeftToggle ;
86
90
if ( EstimatedTimeLeftToggle ) {
87
- timeCalc ? . Calculate ( e . Status . Frame + host . Options . ResumePos ) ;
91
+ timeCalc ? . Calculate ( e . Status . Frame + ResumePos ) ;
88
92
TimeSpan TimeLeft = timeCalc . ResultTimeLeft ;
89
93
if ( TimeLeft > TimeSpan . Zero )
90
94
TimeLeftText . Text = TimeLeft . ToString ( TimeLeft . TotalHours < 1 ? "m\\ :ss" : "h\\ :mm\\ :ss" ) ;
91
95
}
92
96
} ) ;
93
97
}
94
98
95
- private void FFmpeg_Completed ( object sender , FFmpeg . CompletedEventArgs e ) {
99
+ private void FFmpeg_Completed ( object sender , FFmpeg . ProcessCompletedEventArgs e ) {
96
100
Dispatcher . Invoke ( ( ) => {
97
- FFmpegProcess Proc = sender as FFmpegProcess ;
98
- if ( e . Status == CompletionStatus . Error && ! Proc . WorkProcess . StartInfo . FileName . EndsWith ( "avs2yuv.exe" ) )
101
+ ProcessManager Proc = sender as ProcessManager ;
102
+ if ( e . Status == CompletionStatus . Failed && ! Proc . WorkProcess . StartInfo . FileName . EndsWith ( "avs2yuv.exe" ) )
99
103
FFmpegErrorWindow . Instance ( Owner , Proc ) ;
100
104
if ( autoClose )
101
105
this . Close ( ) ;
0 commit comments