2012-06-11 23:24:57 +00:00
using System ;
2017-04-18 17:27:44 +00:00
using System.IO ;
2012-06-11 23:24:57 +00:00
2013-11-04 01:39:19 +00:00
using BizHawk.Emulation.Common ;
2013-11-03 03:54:37 +00:00
namespace BizHawk.Client.EmuHawk
2012-06-11 23:24:57 +00:00
{
/// <summary>
/// dumps in the "nut" container format
/// uncompressed video and audio
/// </summary>
2014-10-10 18:09:00 +00:00
[VideoWriter("nut", "NUT writer", "Writes a series of .nut files to disk, a container format which can be opened by ffmpeg. All data is uncompressed. Splits occur on resolution changes. NOT RECCOMENDED FOR USE.")]
2012-06-11 23:24:57 +00:00
class NutWriter : IVideoWriter
{
/// <summary>
/// dummy codec token class
/// </summary>
class NutWriterToken : IDisposable
{
public void Dispose ( )
{
}
}
2014-06-18 02:28:07 +00:00
public void SetFrame ( int frame ) { }
2012-06-11 23:24:57 +00:00
public void SetVideoCodecToken ( IDisposable token )
{
// ignored
}
2012-06-16 16:51:47 +00:00
public IDisposable AcquireVideoCodecToken ( System . Windows . Forms . IWin32Window hwnd )
2012-06-11 23:24:57 +00:00
{
return new NutWriterToken ( ) ;
}
/// <summary>
/// avparams
/// </summary>
2017-04-18 17:27:44 +00:00
private int fpsnum , fpsden , width , height , sampleRate , channels ;
2012-06-11 23:24:57 +00:00
2017-04-18 17:27:44 +00:00
private NutMuxer _current = null ;
private string _baseName ;
private int _segment ;
2012-06-11 23:24:57 +00:00
public void OpenFile ( string baseName )
{
2017-04-18 17:27:44 +00:00
_baseName = Path . Combine (
Path . GetDirectoryName ( baseName ) ,
Path . GetFileNameWithoutExtension ( baseName ) ) ;
_segment = 0 ;
2012-06-11 23:24:57 +00:00
startsegment ( ) ;
}
2017-04-18 17:27:44 +00:00
private void startsegment ( )
2012-06-11 23:24:57 +00:00
{
2017-04-18 17:27:44 +00:00
var currentfile = File . Open ( $"{_baseName}_{_segment,4:D4}.nut" , FileMode . Create , FileAccess . Write ) ;
_current = new NutMuxer ( width , height , fpsnum , fpsden , sampleRate , channels , currentfile ) ;
2012-06-11 23:24:57 +00:00
}
2017-04-18 17:27:44 +00:00
private void endsegment ( )
2012-06-11 23:24:57 +00:00
{
2017-04-18 17:27:44 +00:00
_current . Finish ( ) ;
_current = null ;
2012-06-11 23:24:57 +00:00
}
public void CloseFile ( )
{
endsegment ( ) ;
}
public void AddFrame ( IVideoProvider source )
{
if ( source . BufferHeight ! = height | | source . BufferWidth ! = width )
2017-04-18 17:27:44 +00:00
{
2012-06-11 23:24:57 +00:00
SetVideoParameters ( source . BufferWidth , source . BufferHeight ) ;
2017-04-18 17:27:44 +00:00
}
_current . WriteVideoFrame ( source . GetVideoBuffer ( ) ) ;
2012-06-11 23:24:57 +00:00
}
public void AddSamples ( short [ ] samples )
{
2017-04-18 17:27:44 +00:00
_current . WriteAudioFrame ( samples ) ;
2012-06-11 23:24:57 +00:00
}
public void SetMovieParameters ( int fpsnum , int fpsden )
{
this . fpsnum = fpsnum ;
this . fpsden = fpsden ;
2017-04-18 17:27:44 +00:00
if ( _current ! = null )
2012-06-11 23:24:57 +00:00
{
endsegment ( ) ;
2017-04-18 17:27:44 +00:00
_segment + + ;
2012-06-11 23:24:57 +00:00
startsegment ( ) ;
}
}
public void SetVideoParameters ( int width , int height )
{
this . width = width ;
this . height = height ;
2017-04-18 17:27:44 +00:00
if ( _current ! = null )
2012-06-11 23:24:57 +00:00
{
endsegment ( ) ;
2017-04-18 17:27:44 +00:00
_segment + + ;
2012-06-11 23:24:57 +00:00
startsegment ( ) ;
}
}
public void SetAudioParameters ( int sampleRate , int channels , int bits )
{
if ( bits ! = 16 )
2017-04-18 17:27:44 +00:00
{
2017-04-10 12:36:42 +00:00
throw new ArgumentOutOfRangeException ( nameof ( bits ) , "Audio depth must be 16 bit!" ) ;
2017-04-18 17:27:44 +00:00
}
2012-06-11 23:24:57 +00:00
this . sampleRate = sampleRate ;
this . channels = channels ;
}
public void SetMetaData ( string gameName , string authors , ulong lengthMS , ulong rerecords )
{
// could be implemented?
}
public void Dispose ( )
{
2017-04-18 17:27:44 +00:00
if ( _current ! = null )
{
2012-07-23 00:33:30 +00:00
endsegment ( ) ;
2017-04-18 17:27:44 +00:00
}
_baseName = null ;
2012-06-11 23:24:57 +00:00
}
2012-06-13 19:50:50 +00:00
public string DesiredExtension ( )
{
return "nut" ;
}
2012-07-23 00:33:30 +00:00
public void SetDefaultVideoCodecToken ( )
{
// ignored
}
2016-03-05 23:19:12 +00:00
2017-04-18 17:27:44 +00:00
public bool UsesAudio = > true ;
public bool UsesVideo = > true ;
2012-06-11 23:24:57 +00:00
}
}