Skip to content

Commit

Permalink
Set libvmaf's threads according to core's threads
Browse files Browse the repository at this point in the history
  • Loading branch information
HolyWu committed Feb 1, 2019
1 parent 37f66a7 commit 4c6d972
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ Requires `libvmaf`.
```
meson build
ninja -C build
ninja -C build install
```
10 changes: 6 additions & 4 deletions VMAF/VMAF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ struct VMAFData {
char * fmt, * logFmt, * pool;
std::unique_ptr<char[]> modelPath, logPath;
bool psnr, ssim, ms_ssim, ci, frameSet, eof;
int numThreads, error;
std::thread vmafThread;
std::mutex mtx;
std::condition_variable cond;
int error;
};

template<typename T>
Expand Down Expand Up @@ -94,9 +94,9 @@ static int readFrame(float * VS_RESTRICT refData, float * VS_RESTRICT mainData,

static void callVMAF(VMAFData * const VS_RESTRICT d) noexcept {
if (d->vi->format->bytesPerSample == 1)
d->error = compute_vmaf(&d->vmafScore, d->fmt, d->vi->width, d->vi->height, readFrame<uint8_t>, d, d->modelPath.get(), d->logPath.get(), d->logFmt, 0, 0, 0, 0, d->psnr, d->ssim, d->ms_ssim, d->pool, 0, 1, d->ci);
d->error = compute_vmaf(&d->vmafScore, d->fmt, d->vi->width, d->vi->height, readFrame<uint8_t>, d, d->modelPath.get(), d->logPath.get(), d->logFmt, 0, 0, 0, 0, d->psnr, d->ssim, d->ms_ssim, d->pool, d->numThreads, 1, d->ci);
else
d->error = compute_vmaf(&d->vmafScore, d->fmt, d->vi->width, d->vi->height, readFrame<uint16_t>, d, d->modelPath.get(), d->logPath.get(), d->logFmt, 0, 0, 0, 0, d->psnr, d->ssim, d->ms_ssim, d->pool, 0, 1, d->ci);
d->error = compute_vmaf(&d->vmafScore, d->fmt, d->vi->width, d->vi->height, readFrame<uint16_t>, d, d->modelPath.get(), d->logPath.get(), d->logFmt, 0, 0, 0, 0, d->psnr, d->ssim, d->ms_ssim, d->pool, d->numThreads, 1, d->ci);

if (d->error) {
d->mtx.lock();
Expand All @@ -122,7 +122,7 @@ static const VSFrameRef *VS_CC vmafGetFrame(int n, int activationReason, void **
d->cond.wait(lck);

if (d->error) {
vsapi->setFilterError(std::string{ "VMAF: libvmaf error" }.c_str(), frameCtx);
vsapi->setFilterError("VMAF: libvmaf error", frameCtx);
return nullptr;
}

Expand Down Expand Up @@ -244,6 +244,8 @@ static void VS_CC vmafCreate(const VSMap *in, VSMap *out, void *userData, VSCore
else
d->pool = const_cast<char *>("min");

d->numThreads = vsapi->getCoreInfo(core)->numThreads;

d->vmafThread = std::thread{ callVMAF, d.get() };
} catch (const std::string & error) {
vsapi->setError(out, ("VMAF: " + error).c_str());
Expand Down
3 changes: 1 addition & 2 deletions VMAF/VMAF.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@
<WarningLevel>Level3</WarningLevel>
<DiagnosticsFormat>Column</DiagnosticsFormat>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FloatingPointModel>Fast</FloatingPointModel>
<ConformanceMode>true</ConformanceMode>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>libpthread-static.lib;libvmaf.lib;ptools.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libvmaf.lib;pthreads.lib;ptools.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project('VMAF', 'cpp',
default_options : ['buildtype=release', 'b_ndebug=if-release', 'cpp_std=c++14'],
meson_version : '>=0.48.0',
version : '2'
version : '3'
)

add_project_arguments('-ffast-math', language : 'cpp')
Expand Down

0 comments on commit 4c6d972

Please sign in to comment.