Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed May 30, 2017
1 parent cb613e0 commit e2d18f0
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 53 deletions.
10 changes: 6 additions & 4 deletions FrameCapturer/Assets/UTJ/FrameCapturer/Scripts/AudioRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override bool BeginRecording()

m_encoderConfigs.Setup();
m_encoder = AudioEncoder.Create(m_encoderConfigs, outPath);
if (m_encoder == null)
if (m_encoder == null || !m_encoder.IsValid())
{
EndRecording();
return false;
Expand All @@ -43,16 +43,18 @@ public override bool BeginRecording()

public override void EndRecording()
{
if (!m_recording) { return; }

if (m_encoder != null)
{
m_encoder.Release();
m_encoder = null;
}

if (m_recording)
{
Debug.Log("AudioMRecorder: EndRecording()");
}
base.EndRecording();
Debug.Log("AudioMRecorder: EndRecording()");

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static void WaitAsyncDelete(object sender, EventArgs e)
}

public abstract void Release();
public abstract bool IsValid();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class ExrEncoder : MovieEncoder
string m_outPath;
int m_frame;

public override void Release() { m_ctx.Release(); }
public override bool IsValid() { return m_ctx; }
public override Type type { get { return Type.Exr; } }

public override void Initialize(object config, string outPath)
Expand All @@ -29,11 +31,6 @@ public override void Initialize(object config, string outPath)
m_frame = 0;
}

public override void Release()
{
m_ctx.Release();
}

public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, double timestamp = -1.0)
{
if (m_ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class FlacEncoder : AudioEncoder
fcAPI.fcFlacContext m_ctx;
fcAPI.fcFlacConfig m_config;

public override void Release() { m_ctx.Release(); }
public override bool IsValid() { return m_ctx; }
public override Type type { get { return Type.Flac; } }

public override void Initialize(object config, string outPath)
Expand All @@ -30,11 +32,6 @@ public override void Initialize(object config, string outPath)
stream.Release();
}

public override void Release()
{
m_ctx.Release();
}

public override void AddAudioSamples(float[] samples)
{
if (m_ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class GifEncoder : MovieEncoder
fcAPI.fcGifContext m_ctx;
fcAPI.fcGifConfig m_config;

public override void Release() { m_ctx.Release(); }
public override bool IsValid() { return m_ctx; }
public override Type type { get { return Type.Gif; } }

public override void Initialize(object config, string outPath)
Expand All @@ -29,11 +31,6 @@ public override void Initialize(object config, string outPath)
stream.Release();
}

public override void Release()
{
m_ctx.Release();
}

public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, double timestamp)
{
if (m_ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class MP4Encoder : MovieEncoder
fcAPI.fcMP4Context m_ctx;
fcAPI.fcMP4Config m_config;

public override void Release() { m_ctx.Release(); }
public override bool IsValid() { return m_ctx; }
public override Type type { get { return Type.MP4; } }

public override void Initialize(object config, string outPath)
Expand All @@ -27,11 +29,6 @@ public override void Initialize(object config, string outPath)
m_ctx = fcAPI.fcMP4OSCreateContext(ref m_config, path);
}

public override void Release()
{
m_ctx.Release();
}

public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, double timestamp)
{
if (m_ctx && m_config.video)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class OggEncoder : AudioEncoder
fcAPI.fcOggContext m_ctx;
fcAPI.fcOggConfig m_config;

public override void Release() { m_ctx.Release(); }
public override bool IsValid() { return m_ctx; }
public override Type type { get { return Type.Ogg; } }

public override void Initialize(object config, string outPath)
Expand All @@ -30,11 +32,6 @@ public override void Initialize(object config, string outPath)
stream.Release();
}

public override void Release()
{
m_ctx.Release();
}

public override void AddAudioSamples(float[] samples)
{
if(m_ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class PngEncoder : MovieEncoder
int m_frame;


public override void Release() { m_ctx.Release(); }
public override bool IsValid() { return m_ctx; }
public override Type type { get { return Type.Png; } }

public override void Initialize(object config, string outPath)
Expand All @@ -27,11 +29,6 @@ public override void Initialize(object config, string outPath)
m_frame = 0;
}

public override void Release()
{
m_ctx.Release();
}

public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, double timestamp = -1.0)
{
if (m_ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class WaveEncoder : AudioEncoder
fcAPI.fcWaveContext m_ctx;
fcAPI.fcWaveConfig m_config;

public override void Release() { m_ctx.Release(); }
public override bool IsValid() { return m_ctx; }
public override Type type { get { return Type.Wave; } }

public override void Initialize(object config, string outPath)
Expand All @@ -30,11 +32,6 @@ public override void Initialize(object config, string outPath)
stream.Release();
}

public override void Release()
{
m_ctx.Release();
}

public override void AddAudioSamples(float[] samples)
{
if(m_ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class WebMEncoder : MovieEncoder
fcAPI.fcWebMContext m_ctx;
fcAPI.fcWebMConfig m_config;

public override void Release() { m_ctx.Release(); }
public override bool IsValid() { return m_ctx; }
public override Type type { get { return Type.WebM; } }

public override void Initialize(object config, string outPath)
Expand Down Expand Up @@ -40,11 +42,6 @@ public override void Initialize(object config, string outPath)
stream.Release();
}

public override void Release()
{
m_ctx.Release();
}

public override void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, double timestamp)
{
if (m_ctx && m_config.video)
Expand Down
19 changes: 14 additions & 5 deletions FrameCapturer/Assets/UTJ/FrameCapturer/Scripts/GBufferRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ public BufferRecorder(RenderTexture rt, int ch, string name, int tf)
m_name = name;
}

public void Initialize(MovieEncoderConfigs c, DataPath p)
public bool Initialize(MovieEncoderConfigs c, DataPath p)
{
string path = p.GetFullPath() + "/" + m_name;
c.Setup(m_rt.width, m_rt.height, m_channels, m_targetFramerate);
m_encoder = MovieEncoder.Create(c, path);
return m_encoder != null && m_encoder.IsValid();
}

public void Release()
Expand Down Expand Up @@ -231,7 +232,14 @@ public override bool BeginRecording()
if (m_fbComponents.depth) { m_recorders.Add(new BufferRecorder(m_rtGB[6], 1, "Depth", framerate)); }
if (m_fbComponents.velocity) { m_recorders.Add(new BufferRecorder(m_rtGB[7], 2, "Velocity", framerate)); }
}
foreach (var rec in m_recorders) { rec.Initialize(m_encoderConfigs, m_outputDir); }
foreach (var rec in m_recorders)
{
if (!rec.Initialize(m_encoderConfigs, m_outputDir))
{
EndRecording();
return false;
}
}

base.BeginRecording();

Expand All @@ -241,8 +249,6 @@ public override bool BeginRecording()

public override void EndRecording()
{
if (!m_recording) { return; }

foreach (var rec in m_recorders) { rec.Release(); }
m_recorders.Clear();

Expand Down Expand Up @@ -283,8 +289,11 @@ public override void EndRecording()
m_rtGB = null;
}

if (m_recording)
{
Debug.Log("GBufferRecorder: EndRecording()");
}
base.EndRecording();
Debug.Log("GBufferRecorder: EndRecording()");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public override bool BeginRecording()
m_encoderConfigs.captureAudio = m_captureAudio;
m_encoderConfigs.Setup(m_scratchBuffer.width, m_scratchBuffer.height, 3, targetFramerate);
m_encoder = MovieEncoder.Create(m_encoderConfigs, outPath);
if (m_encoder == null)
if (m_encoder == null || !m_encoder.IsValid())
{
EndRecording();
return false;
Expand Down Expand Up @@ -162,8 +162,6 @@ public override bool BeginRecording()

public override void EndRecording()
{
if (!m_recording) { return; }

if (m_encoder != null)
{
m_encoder.Release();
Expand All @@ -181,8 +179,11 @@ public override void EndRecording()
m_scratchBuffer = null;
}

if (m_recording)
{
Debug.Log("MovieRecorder: EndRecording()");
}
base.EndRecording();
Debug.Log("MovieRecorder: EndRecording()");
}


Expand Down

0 comments on commit e2d18f0

Please sign in to comment.