Skip to content

Commit

Permalink
fcWaitAsyncDelete() on app exit
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed May 12, 2017
1 parent a1717aa commit 0a3d4a3
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 46 deletions.
50 changes: 17 additions & 33 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,52 +1,36 @@
*.obj
*.pch
*.exe
*.exp
*.ilk
*.ipch
*.pdb
*.suo
*.sdf
*.opensdf
*.opendb
*.db
*.user
*.log
*.tlog

*.exe
*.dll
*.so
*.bundle
*.dylib
*.exr
*.gif
*.png
*.mp4
*.h264
*.aac
*.webm
*.exr
*.gif
*.png
*.dll
*.db
*.opendb
*.ogg
*.flac
*.wav

.vs/
_out/
_tmp/
external/
Library/
Temp/
Build/
Hidden/
Hidden.meta
_Hidden/
_Hidden.meta
obj/
libs/
Plugin/_build_*
Plugin/_build_*/

openh264-*
FrameCapturer/*.csproj
FrameCapturer/*.sln

.build/
release/
debug/
dependencies/
*.dblite
excons.cache

FAACSelfBuild*
FAAC_SelfBuild*
FrameRecorder/
FrameRecorder.meta
3 changes: 1 addition & 2 deletions FrameCapturer/Assets/FrameCapturerPackaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

public class FrameCapturerPackaging
{
[MenuItem("Assets/UTJ/FrameCapturer/MakePackage")]
[MenuItem("Assets/Make FrameCapturer.unitypackage")]
public static void MakePackage()
{
// FrameCapturer.unitypackage
{
string[] files = new string[]
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void Setup()
}
}

public abstract class AudioEncoder
public abstract class AudioEncoder : EncoderBase
{
public enum Type
{
Expand All @@ -31,7 +31,6 @@ public enum Type

// config: config struct (fcGifConfig, fcWebMConfig, etc)
public abstract void Initialize(object config, string outPath);
public abstract void Release();
public abstract void AddAudioFrame(float[] samples, double timestamp = -1.0);


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using UnityEngine;
using UnityEngine.Rendering;


namespace UTJ.FrameCapturer
{
public abstract class EncoderBase
{
public EncoderBase()
{
AppDomain.CurrentDomain.DomainUnload += WaitAsyncDelete;
}
public static void WaitAsyncDelete(object sender, EventArgs e)
{
fcAPI.fcWaitAsyncDelete();
}

public abstract void Release();
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void Setup(int w, int h, int ch = 4, int targetFrameRate = 60)
}
}

public abstract class MovieEncoder
public abstract class MovieEncoder : EncoderBase
{
public enum Type
{
Expand All @@ -115,7 +115,6 @@ public enum Type

// config: config struct (fcGifConfig, fcWebMConfig, etc)
public abstract void Initialize(object config, string outPath);
public abstract void Release();
public abstract void AddVideoFrame(byte[] frame, fcAPI.fcPixelFormat format, double timestamp = -1.0);
public abstract void AddAudioFrame(float[] samples, double timestamp = -1.0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public static int fcGetNumAudioChannels()
}


[DllImport ("fccore")] public static extern void fcEnableAsyncReleaseContext(Bool v);
[DllImport ("fccore")] public static extern void fcWaitAsyncDelete();
[DllImport ("fccore")] public static extern void fcReleaseContext(IntPtr ctx);

Expand Down
2 changes: 1 addition & 1 deletion Plugin/fccore/Foundation/ConvertKernel.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export void Rf32ToRGf32(uniform float dst[], uniform float src[], uniform size_t

export void F32ToU8Samples(uniform unsigned int8 dst[], uniform const float src[], uniform size_t size)
{
foreach(i=0 ... size) { dst[i] = (unsigned int8)((src[i] * 0.5 + 0.5) * 255.0f); }
foreach(i=0 ... size) { dst[i] = (int)((src[i] * 0.5 + 0.5) * 255.0f) & 0xFF; }
}
export void F32ToI16Samples(uniform int16 dst[], uniform const float src[], uniform size_t size)
{
Expand Down
17 changes: 13 additions & 4 deletions Plugin/fccore/fcInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ class fcAsyncDeleteManager

private:
TaskQueue m_task_queue;
} g_asyncReleaseManager;
};

static fcAsyncDeleteManager g_async_delete_manager;
static bool g_async_delete = true;


fcAPI void fcEnableAsyncReleaseContext(bool v)
{
g_async_delete = v;
}

fcAPI void fcWaitAsyncDelete()
{
g_asyncReleaseManager.wait();
g_async_delete_manager.wait();
}


Expand All @@ -38,9 +47,9 @@ fcContextBase::~fcContextBase()
}
}

void fcContextBase::release(bool async)
void fcContextBase::release()
{
if (async) { g_asyncReleaseManager.add([this]() { delete this; }); }
if (g_async_delete) { g_async_delete_manager.add([this]() { delete this; }); }
else { delete this; }
}

Expand Down
2 changes: 1 addition & 1 deletion Plugin/fccore/fcInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class fcContextBase
protected:
virtual ~fcContextBase();
public:
virtual void release(bool async = true);
virtual void release();
virtual void setOnDeleteCallback(void(*cb)(void*), void *param);

private:
Expand Down
4 changes: 3 additions & 1 deletion Plugin/fccore/fccore.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ fcAPI void fcGfxSync();
fcAPI void fcSetModulePath(const char *path);
fcAPI const char* fcGetModulePath();
fcAPI fcTime fcGetTime(); // current time in seconds
fcAPI void fcWaitAsyncDelete();


#ifndef fcImpl
Expand Down Expand Up @@ -99,6 +98,9 @@ fcAPI void fcReleaseStream(fcStream *s);
fcAPI fcBufferData fcStreamGetBufferData(fcStream *s); // s must be created by fcCreateMemoryStream(), otherwise return {nullptr, 0}.
fcAPI uint64_t fcStreamGetWrittenSize(fcStream *s);

fcAPI void fcEnableAsyncReleaseContext(bool v);
fcAPI void fcWaitAsyncDelete();

fcAPI void fcReleaseContext(fcContextBase *ctx);
fcAPI void fcSetOnDeleteCallback(fcContextBase *ctx, void(*cb)(void*), void *param);

Expand Down

0 comments on commit 0a3d4a3

Please sign in to comment.