Skip to content

Commit

Permalink
config cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed May 13, 2017
1 parent 9de1f55 commit 15211fc
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 52 deletions.
48 changes: 26 additions & 22 deletions FrameCapturer/Assets/UTJ/FrameCapturer/Scripts/Encoder/fcAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public enum fcPngPixelFormat
[Serializable]
public struct fcPngConfig
{
[Range(1, 32)] public int maxTasks;
public fcPngPixelFormat pixelFormat;
[Range(1, 32)] public int maxTasks;
// C# ext
[HideInInspector] public int width;
[HideInInspector] public int height;
Expand All @@ -181,8 +181,8 @@ public static fcPngConfig default_value
{
return new fcPngConfig
{
maxTasks = 4,
pixelFormat = fcPngPixelFormat.Adaptive,
maxTasks = 2,
};
}
}
Expand Down Expand Up @@ -224,9 +224,9 @@ public enum fcExrCompression
[Serializable]
public struct fcExrConfig
{
[Range(1, 32)] public int maxTasks;
public fcExrPixelFormat pixelFormat;
public fcExrCompression compression;
[Range(1, 32)] public int maxTasks;
// C# ext
[HideInInspector] public int width;
[HideInInspector] public int height;
Expand All @@ -238,9 +238,9 @@ public static fcExrConfig default_value
{
return new fcExrConfig
{
maxTasks = 4,
pixelFormat = fcExrPixelFormat.Adaptive,
compression = fcExrCompression.Zip,
maxTasks = 2,
};
}
}
Expand Down Expand Up @@ -279,8 +279,6 @@ public static fcGifConfig default_value
{
return new fcGifConfig
{
width = 320,
height = 240,
numColors = 256,
maxTasks = 8,
keyframeInterval = 30,
Expand Down Expand Up @@ -326,20 +324,21 @@ public enum fcMP4AudioFlags
public struct fcMP4Config
{
[HideInInspector] public Bool video;
[HideInInspector] public Bool audio;

[HideInInspector] public int videoWidth;
[HideInInspector] public int videoHeight;
[HideInInspector] public int videoTargetFramerate;
public fcBitrateMode videoBitrateMode;
public int videoTargetBitrate;
[HideInInspector] public int videoFlags;
[Range(1, 32)] public int videoMaxTasks;

[HideInInspector] public Bool audio;
[HideInInspector] public int audioSampleRate;
[HideInInspector] public int audioNumChannels;
public fcBitrateMode audioBitrateMode;
public int audioTargetBitrate;
[HideInInspector] public int audioFlags;
[Range(1, 32)] public int audioMaxTasks;

public static fcMP4Config default_value
{
Expand All @@ -348,20 +347,19 @@ public static fcMP4Config default_value
return new fcMP4Config
{
video = true,
audio = true,

videoWidth = 0,
videoHeight = 0,
videoBitrateMode = fcBitrateMode.VBR,
videoTargetBitrate = 1024 * 1000,
videoTargetFramerate = 30,
videoFlags = (int)fcMP4VideoFlags.H264Mask,
videoMaxTasks = 4,

audio = true,
audioSampleRate = 48000,
audioNumChannels = 2,
audioBitrateMode = fcBitrateMode.VBR,
audioTargetBitrate = 128 * 1000,
audioFlags = (int)fcMP4AudioFlags.AACMask,
audioMaxTasks = 4,
};
}
}
Expand Down Expand Up @@ -419,43 +417,43 @@ public enum fcWebMAudioEncoder
[Serializable]
public struct fcWebMConfig
{
public fcWebMVideoEncoder videoEncoder;
public fcWebMAudioEncoder audioEncoder;
[HideInInspector] public Bool video;
[HideInInspector] public Bool audio;

public fcWebMVideoEncoder videoEncoder;
[HideInInspector] public int videoWidth;
[HideInInspector] public int videoHeight;
[HideInInspector] public int videoTargetFramerate;
public fcBitrateMode videoBitrateMode;
public int videoTargetBitrate;
[Range(1, 32)] public int videoMaxTasks;

[HideInInspector] public Bool audio;
public fcWebMAudioEncoder audioEncoder;
[HideInInspector] public int audioSampleRate;
[HideInInspector] public int audioNumChannels;
public fcBitrateMode audioBitrateMode;
public int audioTargetBitrate;
[Range(1, 32)] public int audioMaxTasks;

public static fcWebMConfig default_value
{
get
{
return new fcWebMConfig
{
videoEncoder = fcWebMVideoEncoder.VP8,
audioEncoder = fcWebMAudioEncoder.Vorbis,
video = true,
audio = true,

videoWidth = 0,
videoHeight = 0,
videoEncoder = fcWebMVideoEncoder.VP8,
videoTargetFramerate = 60,
videoBitrateMode = fcBitrateMode.VBR,
videoTargetBitrate = 1024 * 1000,
videoMaxTasks = 4,

audio = true,
audioEncoder = fcWebMAudioEncoder.Vorbis,
audioSampleRate = 48000,
audioNumChannels = 2,
audioBitrateMode = fcBitrateMode.VBR,
audioTargetBitrate = 128 * 1000,
audioMaxTasks = 4,
};
}
}
Expand Down Expand Up @@ -486,6 +484,7 @@ public struct fcWaveConfig
[HideInInspector] public int sampleRate;
[HideInInspector] public int numChannels;
public fcAudioBitsPerSample bitsPerSample;
[Range(1, 32)] public int maxTasks;

public static fcWaveConfig default_value
{
Expand All @@ -496,6 +495,7 @@ public static fcWaveConfig default_value
sampleRate = 48000,
numChannels = 2,
bitsPerSample = fcAudioBitsPerSample._16Bits,
maxTasks = 2,
};
}
}
Expand Down Expand Up @@ -525,6 +525,7 @@ public struct fcOggConfig
[HideInInspector] public int numChannels;
public fcBitrateMode bitrateMode;
public int targetBitrate;
[Range(1, 32)] public int maxTasks;

public static fcOggConfig default_value
{
Expand All @@ -536,6 +537,7 @@ public static fcOggConfig default_value
numChannels = 2,
bitrateMode = fcBitrateMode.VBR,
targetBitrate = 128 * 1000,
maxTasks = 2,
};
}
}
Expand Down Expand Up @@ -566,6 +568,7 @@ public struct fcFlacConfig
[Range(0,9)] public int compressionLevel;
public int blockSize;
public Bool verify;
[Range(1, 32)] public int maxTasks;

public static fcFlacConfig default_value
{
Expand All @@ -579,6 +582,7 @@ public static fcFlacConfig default_value
compressionLevel = 5,
blockSize = 0,
verify = false,
maxTasks = 2,
};
}
}
Expand Down
4 changes: 3 additions & 1 deletion Plugin/fccore/Encoder/Audio/fcFlacContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ bool fcFlacWriter::write(const int *samples, int num_samples)
fcFlacContext::fcFlacContext(const fcFlacConfig& c)
: m_conf(c)
{
for (int i = 0; i < 8; ++i) {
m_conf.max_tasks = std::max<int>(m_conf.max_tasks, 1);

for (int i = 0; i < m_conf.max_tasks; ++i) {
m_buffers.emplace();
}
}
Expand Down
4 changes: 3 additions & 1 deletion Plugin/fccore/Encoder/Audio/fcOggContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void fcOggWriter::pageOut()
fcOggContext::fcOggContext(const fcOggConfig& conf)
: m_conf(conf)
{
m_conf.max_tasks = std::max<int>(m_conf.max_tasks, 1);

vorbis_info_init(&m_vo_info);
switch (conf.bitrate_mode) {
case fcBitrateMode::CBR:
Expand All @@ -122,7 +124,7 @@ fcOggContext::fcOggContext(const fcOggConfig& conf)
vorbis_block_init(&m_vo_dsp, &m_vo_block);
vorbis_analysis_headerout(&m_vo_dsp, &m_vo_comment, &m_og_header, &m_og_header_comm, &m_og_header_code);

for (int i = 0; i < 8; ++i) {
for (int i = 0; i < m_conf.max_tasks; ++i) {
m_buffers.emplace();
}
}
Expand Down
1 change: 1 addition & 0 deletions Plugin/fccore/Encoder/Audio/fcWaveContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct WaveHeader
fcWaveContext::fcWaveContext(const fcWaveConfig& c)
: m_conf(c)
{
m_conf.max_tasks = std::max<int>(m_conf.max_tasks, 1);
}

fcWaveContext::~fcWaveContext()
Expand Down
8 changes: 4 additions & 4 deletions Plugin/fccore/Encoder/Image/fcExrContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ fcExrContext::fcExrContext(const fcExrConfig& conf, fcIGraphicsDevice *dev)
, m_dev(dev)
{
m_conf = conf;
if (m_conf.max_active_tasks <= 0) {
m_conf.max_active_tasks = std::thread::hardware_concurrency();
if (m_conf.max_tasks <= 0) {
m_conf.max_tasks = std::thread::hardware_concurrency();
}
}

Expand All @@ -97,10 +97,10 @@ bool fcExrContext::beginFrame(const char *path, int width, int height)
}

// 実行中のタスクの数が上限に達している場合適当に待つ
if (m_active_task_count >= m_conf.max_active_tasks)
if (m_active_task_count >= m_conf.max_tasks)
{
std::this_thread::sleep_for(std::chrono::milliseconds(10));
if (m_active_task_count >= m_conf.max_active_tasks)
if (m_active_task_count >= m_conf.max_tasks)
{
m_tasks.wait();
}
Expand Down
8 changes: 3 additions & 5 deletions Plugin/fccore/Encoder/Image/fcGifContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ fcGifContext::fcGifContext(const fcGifConfig &conf, fcIGraphicsDevice *dev)
: m_conf(conf)
, m_dev(dev)
{
m_conf.max_tasks = std::max<int>(m_conf.max_tasks, 1);

m_gif = jo_gif_start(m_conf.width, m_conf.height, 0, m_conf.num_colors);

// allocate working buffers
if (m_conf.max_active_tasks <= 0) {
m_conf.max_active_tasks = std::thread::hardware_concurrency();
}
m_buffers.resize(m_conf.max_active_tasks);
m_buffers.resize(m_conf.max_tasks);
for (auto& buf : m_buffers)
{
buf.rgba8_pixels.resize(m_conf.width * m_conf.height * fcGetPixelSize(fcPixelFormat_RGBAu8));
Expand Down
8 changes: 4 additions & 4 deletions Plugin/fccore/Encoder/Image/fcPngContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fcPngContext::fcPngContext(const fcPngConfig& conf, fcIGraphicsDevice *dev)
: m_conf(conf)
, m_dev(dev)
{
if (m_conf.max_active_tasks <= 0) {
m_conf.max_active_tasks = std::thread::hardware_concurrency();
if (m_conf.max_tasks <= 0) {
m_conf.max_tasks = std::thread::hardware_concurrency();
}
}

Expand Down Expand Up @@ -113,9 +113,9 @@ bool fcPngContext::exportPixels(const char *path_, const void *pixels_, int widt

void fcPngContext::waitSome()
{
if (m_active_task_count >= m_conf.max_active_tasks) {
if (m_active_task_count >= m_conf.max_tasks) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
if (m_active_task_count >= m_conf.max_active_tasks) {
if (m_active_task_count >= m_conf.max_tasks) {
m_tasks.wait();
}
}
Expand Down
6 changes: 4 additions & 2 deletions Plugin/fccore/Encoder/MP4/fcMP4Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ fcMP4Context::fcMP4Context(fcMP4Config &conf, fcIGraphicsDevice *dev)
}
#endif // fcMaster

m_conf.video_max_tasks = std::max<int>(m_conf.video_max_tasks, 1);
m_conf.audio_max_tasks = std::max<int>(m_conf.audio_max_tasks, 1);

// create h264 encoder
m_video_encoder.reset();
Expand Down Expand Up @@ -140,7 +142,7 @@ fcMP4Context::fcMP4Context(fcMP4Config &conf, fcIGraphicsDevice *dev)

if (enc) {
m_video_encoder.reset(enc);
for (int i = 0; i < 4; ++i) {
for (int i = 0; i < m_conf.video_max_tasks; ++i) {
m_video_buffers.emplace();
}
}
Expand All @@ -165,7 +167,7 @@ fcMP4Context::fcMP4Context(fcMP4Config &conf, fcIGraphicsDevice *dev)

if (enc) {
m_audio_encoder.reset(enc);
for (int i = 0; i < 4; ++i) {
for (int i = 0; i < m_conf.audio_max_tasks; ++i) {
m_audio_buffers.emplace();
}
}
Expand Down
7 changes: 5 additions & 2 deletions Plugin/fccore/Encoder/MP4/fcMP4_Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ fcMP4ContextWMF::fcMP4ContextWMF(const fcMP4Config &conf, fcIGraphicsDevice *dev
, m_gdev(dev)
{
g_MFInitializer.get();
m_conf.video_max_tasks = std::max<int>(m_conf.video_max_tasks, 1);
m_conf.audio_max_tasks = std::max<int>(m_conf.audio_max_tasks, 1);

initializeSinkWriter(path);
}

Expand Down Expand Up @@ -248,7 +251,7 @@ bool fcMP4ContextWMF::initializeSinkWriter(const char *path)
}
}

for (int i = 0; i < 4; ++i) {
for (int i = 0; i < m_conf.video_max_tasks; ++i) {
m_video_buffers.emplace();
}
}
Expand Down Expand Up @@ -284,7 +287,7 @@ bool fcMP4ContextWMF::initializeSinkWriter(const char *path)
pAudioInMediaType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, 4 * m_conf.audio_num_channels);
pSinkWriter->SetInputMediaType(m_mf_audio_index, pAudioInMediaType.Get(), nullptr);

for (int i = 0; i < 4; ++i) {
for (int i = 0; i < m_conf.audio_max_tasks; ++i) {
m_audio_buffers.emplace();
}
}
Expand Down
7 changes: 5 additions & 2 deletions Plugin/fccore/Encoder/WebM/fcWebMContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ fcWebMContext::fcWebMContext(fcWebMConfig &conf, fcIGraphicsDevice *gd)
: m_conf(conf)
, m_gdev(gd)
{
m_conf.video_max_tasks = std::max<int>(m_conf.video_max_tasks, 1);
m_conf.audio_max_tasks = std::max<int>(m_conf.audio_max_tasks, 1);

if (conf.video) {
fcVPXEncoderConfig econf;
econf.width = conf.video_width;
Expand All @@ -87,7 +90,7 @@ fcWebMContext::fcWebMContext(fcWebMConfig &conf, fcIGraphicsDevice *gd)
break;
}

for (int i = 0; i < 4; ++i) {
for (int i = 0; i < m_conf.video_max_tasks; ++i) {
m_video_buffers.emplace();
}
}
Expand All @@ -108,7 +111,7 @@ fcWebMContext::fcWebMContext(fcWebMConfig &conf, fcIGraphicsDevice *gd)
break;
}

for (int i = 0; i < 4; ++i) {
for (int i = 0; i < m_conf.audio_max_tasks; ++i) {
m_audio_buffers.emplace();
}
}
Expand Down
Loading

0 comments on commit 15211fc

Please sign in to comment.