diff --git a/BizHawk.MultiClient/AviWriter.cs b/BizHawk.MultiClient/AviWriter.cs index 33af053b2e..1094338f9e 100644 --- a/BizHawk.MultiClient/AviWriter.cs +++ b/BizHawk.MultiClient/AviWriter.cs @@ -10,7 +10,7 @@ using BizHawk; namespace BizHawk.MultiClient { - class AviWriter : IDisposable + class AviWriter : VideoWriter { CodecToken currVideoCodecToken = null; AviWriterSegment currSegment; @@ -27,9 +27,12 @@ namespace BizHawk.MultiClient /// /// sets the codec token to be used for video compression /// - public void SetVideoCodecToken(CodecToken token) + public void SetVideoCodecToken(IDisposable token) { - currVideoCodecToken = token; + if (token is CodecToken) + currVideoCodecToken = (CodecToken)token; + else + throw new ArgumentException("AviWriter only takes its own Codec Tokens!"); } public static IEnumerator CreateBasicNameProvider(string template) @@ -192,7 +195,7 @@ namespace BizHawk.MultiClient /// Acquires a video codec configuration from the user. you may save it for future use, but you must dispose of it when youre done with it. /// returns null if the user canceled the dialog /// - public static CodecToken AcquireVideoCodecToken(IntPtr hwnd, CodecToken lastToken) + public IDisposable AcquireVideoCodecToken(IntPtr hwnd) //, CodecToken lastToken) { var temp_params = new Parameters(); temp_params.height = 256; @@ -206,8 +209,8 @@ namespace BizHawk.MultiClient string tempfile = Path.GetTempFileName(); File.Delete(tempfile); tempfile = Path.ChangeExtension(tempfile, "avi"); - temp.OpenFile(tempfile, temp_params, lastToken); - CodecToken token = temp.AcquireVideoCodecToken(hwnd); + temp.OpenFile(tempfile, temp_params, null); //lastToken); + CodecToken token = (CodecToken) temp.AcquireVideoCodecToken(hwnd); temp.CloseFile(); File.Delete(tempfile); return token; @@ -469,7 +472,7 @@ namespace BizHawk.MultiClient /// /// Acquires a video codec configuration from the user /// - public CodecToken AcquireVideoCodecToken(IntPtr hwnd) + public IDisposable AcquireVideoCodecToken(IntPtr hwnd) { if (!IsOpen) throw new InvalidOperationException("File must be opened before acquiring a codec token (or else the stream formats wouldnt be known)"); diff --git a/BizHawk.MultiClient/BizHawk.MultiClient.csproj b/BizHawk.MultiClient/BizHawk.MultiClient.csproj index e02ed1f455..a5a2ef0a59 100644 --- a/BizHawk.MultiClient/BizHawk.MultiClient.csproj +++ b/BizHawk.MultiClient/BizHawk.MultiClient.csproj @@ -292,6 +292,7 @@ + GifAnimator.cs diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 004a0f4cf0..1f700e2a1b 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -32,7 +32,7 @@ namespace BizHawk.MultiClient public bool PressRewind = false; //avi/wav state - AviWriter CurrAviWriter = null; + VideoWriter CurrAviWriter = null; //runloop control bool exit; @@ -2666,13 +2666,13 @@ namespace BizHawk.MultiClient //TODO - cores should be able to specify exact values for these instead of relying on this to calculate them int fps = (int)(Global.Emulator.CoreOutputComm.VsyncRate * 0x01000000); - AviWriter aw = new AviWriter(); + VideoWriter aw = new AviWriter(); try { aw.SetMovieParameters(fps, 0x01000000); aw.SetVideoParameters(Global.Emulator.VideoProvider.BufferWidth, Global.Emulator.VideoProvider.BufferHeight); aw.SetAudioParameters(44100, 2, 16); - var token = AviWriter.AcquireVideoCodecToken(Global.MainForm.Handle, null); + var token = aw.AcquireVideoCodecToken(Global.MainForm.Handle); //, null); aw.SetVideoCodecToken(token); aw.OpenFile(sfd.FileName); diff --git a/BizHawk.MultiClient/VideoWriter.cs b/BizHawk.MultiClient/VideoWriter.cs new file mode 100644 index 0000000000..b0855cde9d --- /dev/null +++ b/BizHawk.MultiClient/VideoWriter.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace BizHawk +{ + public interface VideoWriter : IDisposable + { + /// + /// sets the codec token to be used for video compression + /// + void SetVideoCodecToken(IDisposable token); + + + // why no OpenFile(IEnumerator) ? + // different video writers may have different ideas of how and why splitting is to occur + /// + /// opens a recording stream + /// set a video codec token first. + /// + void OpenFile(string baseName); + + /// + /// close recording stream + /// + void CloseFile(); + + /// + /// adds a frame to the stream + /// + void AddFrame(IVideoProvider source); + + /// + /// adds audio samples to the stream + /// no attempt is made to sync this to the video + /// + void AddSamples(short[] samples); + + /// + /// obtain a set of recording compression parameters + /// + /// hwnd to attach to if the user is shown config dialog + /// codec token, dispose of it when you're done with it + IDisposable AcquireVideoCodecToken(IntPtr hwnd); + + /// + /// set framerate to fpsnum/fpsden (assumed to be unchanging over the life of the stream) + /// + void SetMovieParameters(int fpsnum, int fpsden); + + /// + /// set resolution parameters (width x height) + /// must be set before file is opened + /// can be changed in future + /// should always match IVideoProvider + /// + /// + /// + void SetVideoParameters(int width, int height); + + /// + /// set audio parameters. cannot change later + /// + void SetAudioParameters(int sampleRate, int channels, int bits); + + } +}