-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathFileItem.cs
More file actions
148 lines (122 loc) · 6.21 KB
/
FileItem.cs
File metadata and controls
148 lines (122 loc) · 6.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using OxyPlot;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
namespace FFBitrateViewer
{
public class FileItem : Bindable
{
public BitRate? BitRateAvg { get { return Get<BitRate?>(); } private set { Set(value); } }
public BitRate? BitRateMax { get { return Get<BitRate?>(); } private set { Set(value); } }
public BitRate? BitRateMin { get { return Get<BitRate?>(); } private set { Set(value); } }
public string? FS { // File Spec
get { return Get<string?>(); }
set {
Set(value);
IsExists = !string.IsNullOrEmpty(value) && File.Exists(value);
FN = Path.GetFileName(FS);
var ext = Path.GetExtension(value);
IsPreviewable = !string.IsNullOrEmpty(ext) && !string.IsNullOrEmpty(Helpers.GetAssociatedProgram(ext));
}
}
public string? FN { get { return Get<string?>(); } private set { Set(value); } } // File Name
public Frames? Frames { get { return Get<Frames?>(); } private set { Set(value); OnPropertyChanged(nameof(Duration)); } }
//public int? DropTarget { get { return Get<int?>(); } set { Set(value); } } // 1 -- top, 2 - bottom
public double? Duration { get { return MediaInfo?.Video0?.Duration ?? MediaInfo?.Duration ?? Frames?.Duration ?? Frames?.FramesDuration; } }
public bool IsAdjustStartTime { get { return Get<bool>(); } set { Set(value); FramesIsAdjustStartTimeSet(value); } }
public bool IsExists { get { return Get<bool>(); } private set { Set(value); OnPropertyChanged(nameof(IsReady)); } }
public bool IsEnabled { get { return Get<bool>(); } set { Set(value); OnPropertyChanged(nameof(IsReady)); } }
public bool IsMediaInfoLoading { get { return Get<bool>(); } private set { Set(value); } }
public bool IsFramesLoading { get { return Get<bool>(); } private set { Set(value); } }
public bool IsFramesLoaded { get { return Get<bool>(); } private set { Set(value); } }
public bool IsPreviewable { get; private set; }
public bool IsReady { get { return IsExists && IsEnabled && MediaInfo != null; } }
public MediaInfo? MediaInfo { get { return Get<MediaInfo>(); } private set { Set(value); OnPropertyChanged(nameof(IsReady)); OnPropertyChanged(nameof(Duration)); } }
public FileItem(string? fs = null, bool enabled = true)
{
Frames = null;
IsEnabled = enabled;
MediaInfo = null;
if (!string.IsNullOrEmpty(fs)) FS = fs;
}
private void BitRatesCalc(Frames frames)
{
var bitRates = frames.BitRatesCals();
BitRateAvg = bitRates.Avg;
BitRateMax = bitRates.Max;
BitRateMin = bitRates.Min;
}
public void FramesClear()
{
BitRateAvg = null;
BitRateMax = null;
BitRateMin = null;
Frames = null;
IsFramesLoaded = false;
}
public List<DataPoint> FramesDataPointsGet(string? plotViewType)
{
return Frames == null ? new List<DataPoint>() : Frames.DataPointsGet(plotViewType);
}
public void FramesGet(CancellationToken cancellationToken, Action<int?, Frame, int>? action = null)
{
// Cannot just clear & reload Frames as it will not updated in MediaInfoBox
if (!IsReady || string.IsNullOrEmpty(FS)) return;
IsFramesLoading = true;
IsFramesLoaded = false;
var frames = new Frames();
frames.IsAdjustStartTimeSet(IsAdjustStartTime);
if (MediaInfo != null) frames.StartTime = MediaInfo.StartTime;
int line = 0;
ExecStatus status = FF.FramesGet(FS, cancellationToken, o => {
++line;
if (o is Frame frame)
{
var pos = frames.Add(frame);
if(pos != null) action?.Invoke(pos, frame, line);
}
});
if (status.Code == 0)
{
frames.Analyze();
BitRatesCalc(frames);
Frames = frames;
IsFramesLoaded = true;
}
IsFramesLoading = false;
}
private void FramesIsAdjustStartTimeSet(bool isAdjustStartTime)
{
if (Frames != null)
{
if (isAdjustStartTime == Frames.IsAdjustStartTime) return;
Frames.IsAdjustStartTimeSet(isAdjustStartTime);
BitRatesCalc(Frames);
}
}
public double? FramesMaxXGet(string? plotViewType)
{
return Frames?.MaxXGet(plotViewType);
}
public int FramesMaxYGet(string? plotViewType)
{
return Frames?.MaxYGet(plotViewType) ?? 0;
}
public void MediaInfoClear()
{
MediaInfo = null;
}
public void MediaInfoGet()
{
if (!string.IsNullOrEmpty(FS) && IsExists)
{
IsMediaInfoLoading = true;
// Cannot just clear & reload MediaInfo as it will not updated in MediaInfoBox
MediaInfo = new MediaInfo(FS);
IsMediaInfoLoading = false;
if (Frames != null) Frames.StartTime = MediaInfo.StartTime;
}
}
}
}