WingRecorder/TestAddin/VitualEngine.cs

352 lines
11 KiB
C#

using IWingRecorder;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using Point = System.Drawing.Point;
namespace TestAddin
{
public class VitualEngine : IWingEngine
{
/// <summary>
/// 模拟录制的计时器
/// </summary>
readonly DispatcherTimer timer;
public VitualEngine()
{
timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1), IsEnabled = false }; //间隔一秒
timer.Tick += Timer_Tick;
}
//以秒为单位
ulong recordingTime = 0;
private void Timer_Tick(object sender, EventArgs e)
{
recordingTime++;
}
public bool IsSupportRecordVideo => true;
public bool IsSupportRecordAudio => true;
public CursorEffect SupportCursorEffect => CursorEffect.KnownAll;
public bool IsSupportSelectRecordRegion => true;
public bool IsSupportRecordCamera => true;
public bool IsSupportScreenShot => false;
public bool IsRecordOutputAudio { get; set; }
public bool IsRecordInputAudio { get; set; }
public int SystemAudioVolume { get; set; }
public int RecordingAudioVolume { get; set; }
public Color HilightColor { get; set; } = Colors.Yellow;
public Color LeftClickColor { get; set; } = Colors.Red;
public Color RightClickColor { get; set; } = Colors.Green;
public Color TrackColor { get; set; } = Colors.Red;
public ulong RecordingTime => recordingTime;
public int AudioBitrate { get; set; } = 50;
public IReadOnlyList<FormatInfo> SupportRecordingFormats => formats;
public string Name => "WingRecordVirtualEngine";
public string Description => "This is a VITRUAL ENGINE that has no real function.Only for TEST!";
public string Author => "WingSummer (Engine)";
public uint Version => 1;
public string Corporation => "WingCloudStudio (Engine)";
public bool IsFree => true;
public bool LockBorder => false;
public bool IsSupportZoomInScreen => true;
public Rect? RecordingArea { get; set; } = null;
public bool IsRecordingMouse { get; set; } = false;
private RecordingState recordingState = RecordingState.Ready;
public RecordingState RecordingState => recordingState;
public int ZoomInScreenRatio { get; set; } = 0;
public int ZoomSpeed { get; set; } = 0;
public int InputAudioDeviceCount => 0;
public string[] InputAudioDevice => null;
public int OutputAudioDeviceCount => 0;
public string[] OutputAudioDevice => null;
public int CamDeviceCount => 2;
readonly string[] VirtualCam = { "VitualTestCam", "VitualTestCam_LONGString" };
public string[] AllCamDevice => VirtualCam;
public bool PreviewWebcam { get; set; }
public Size WebcamViewSize { get; set; }
public bool FlippingWebcam { get; set; }
public bool MirroringWebcam { get; set; }
public string WaterMarkPicPath
{
get => waterMarkPicPath;
set
{
FormTest.WriteLine($"{nameof(WaterMarkPicPath)} : {value}");
waterMarkPicPath = value;
}
}
public WaterMarkType WaterMarkType
{
get => waterMarkType;
set
{
FormTest.WriteLine($"WaterMarkType : {value}");
waterMarkType = value;
}
}
public string WateMarkText { get; set; } = "This is A Test!";
public double LogoOpacity { get; set; } = 80;
readonly Random random = new Random();
public int InputRealTimeAudioVolume => random.Next(0, 100);
public bool UsingHilightColor { get; set; } = true;
public bool UsingTrackColor { get; set; } = true;
readonly static string[] screenShotFormat = { "png", "bmp", "jpg" };
public string[] SupportScreenShotFormat => screenShotFormat;
public bool IsSupportWaterMark => true;
public bool UsingClickSound { get; set; }
public bool UsingClickColor { get; set; }
public bool IsSupportRecordMouse => false;
public string CurrentRecordingFormat => currentRecordingFormat;
public string CurrentScreenShotFormat => currentScreenShotFormat;
public Utilities.WingFont LogoFont
{
get => logoFont;
set
{
FormTest.WriteLine($"{nameof(LogoFont)} : {value}");
logoFont = value;
OnPropertyChanged(nameof(LogoFont));
}
}
public Quality CurrentRecordingQuality
{
get => currentRecordingQuality;
set
{
currentRecordingQuality = value;
FormTest.WriteLine($"{nameof(CurrentRecordingQuality)}: {value}");
OnPropertyChanged(nameof(CurrentRecordingQuality));
}
}
public string[] SupportedPicMarkExt => screenShotFormat; //偷懒这么写的,写真实的插件一定做好区分
public bool IsSupportPicMark => true;
public bool IsSupportTextMark => true;
public Rect LogoRect
{
get => logoRect;
set
{
logoRect = value;
}
}
public Color WateMarkTextColor { get; set; } = Colors.Red;
public bool IsSupportSoundCustom => true;
public bool UsingAddinSystemClock => true;
readonly static List<FormatInfo> formats = new List<FormatInfo>
{
new FormatInfo{ Name="MP3", IsVideo= false},
new FormatInfo{Name="MP4",IsVideo= true},
new FormatInfo{Name="AVI",IsVideo = true}
};
private string currentRecordingFormat = formats[1].Name;
private string currentScreenShotFormat = screenShotFormat[0];
private WaterMarkType waterMarkType = WaterMarkType.Text;
private Quality currentRecordingQuality = Quality.StandardQuality;
private Utilities.WingFont logoFont = new Utilities.WingFont
{
FontFamily = Fonts.SystemFontFamilies.FirstOrDefault(),
FontSize = 30,
FontStyle = FontStyles.Normal,
FontStretch = FontStretches.Normal,
FontWeight = FontWeights.Normal,
};
private Rect logoRect = new Rect(100, 100, SystemParameters.VirtualScreenWidth / 2, SystemParameters.VirtualScreenHeight / 2);
private string waterMarkPicPath;
public event PropertyChangedEventHandler PropertyChanged;
public bool PauseRecording()
{
recordingState = RecordingState.Paused;
timer.Stop();
return true;
}
public bool SelectCameraDevice(int nIndex)
{
return true;
}
public bool StartRecording(string filename)
{
FormTest.WriteLine($"+ StartRecording : {filename}");
timer.Start();
recordingState = RecordingState.Recording;
return true;
}
public bool StopRecording()
{
recordingState = RecordingState.Ready;
recordingTime = 0;
timer.Stop();
return true;
}
public bool TakeScreenshot(StringBuilder Path, Rect? rect)
{
if (rect == null)
{
return ScreenShotHelper.GetScreenShot(Point.Empty,
new System.Drawing.Size((int)SystemParameters.VirtualScreenWidth,
(int)SystemParameters.VirtualScreenHeight), Path.ToString());
}
else
{
Rect r = rect.Value;
return ScreenShotHelper.GetScreenShot(new Point((int)r.X, (int)r.Y),
new System.Drawing.Size((int)r.Width, (int)r.Height), Path.ToString());
}
}
public bool TakeScreenshot(StringBuilder Path, int left, int top, int right, int bottom)
{
if (top > bottom || left > right)
return false;
return ScreenShotHelper.GetScreenShot(new Point(left, top),
new System.Drawing.Size(right - left, bottom - top), Path.ToString());
}
public bool ResumeRecording()
{
recordingState = RecordingState.Recording;
timer.Start();
return true;
}
public string GetCamName(int nIndex)
{
if (nIndex < 0 && nIndex >= VirtualCam.Length)
{
return null;
}
else
{
return VirtualCam[nIndex];
}
}
public string GetOutputAudioDeviceName(int nIndex)
{
throw new NotImplementedException();
}
public string GetInputAudioDeviceName(int nIndex)
{
throw new NotImplementedException();
}
/// <summary>
/// 这个函数需要自己实现,宿主没法帮你管一切东西,这里帮你写好了
/// </summary>
/// <param name="format"></param>
/// <returns></returns>
public bool SetCurrentRecordingFormat(string format)
{
if (format == null) return false;
foreach (var item in SupportRecordingFormats)
{
if (Utilities.StringCompareIgnoreCase(item.Name, format))
{
currentRecordingFormat = format;
OnPropertyChanged(nameof(CurrentRecordingFormat));
return true;
}
}
return false;
}
/// <summary>
/// 对于某些属性,必须显示调用该函数,否则宿主程序的 UI 数据不会更新
/// 影响范围:当前录制格式、当前截屏格式、当前录制品质
/// 使用方式:在修改之后必须调用该函数的对应值时显式调用该函数
/// </summary>
/// <param name="propertyName"></param>
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
/// <summary>
/// 这个函数需要自己实现,宿主没法帮你管一切东西,这里帮你写好了
/// </summary>
/// <param name="format"></param>
/// <returns></returns>
public bool SetCurrentScreenShotFormat(string format)
{
if (format == null) return false;
foreach (var item in SupportScreenShotFormat)
{
if (Utilities.StringCompareIgnoreCase(item, format))
{
currentScreenShotFormat = format;
OnPropertyChanged(nameof(CurrentScreenShotFormat));
return true;
}
}
return false;
}
}
}