From 9585903227b42931b823910eb3ce33854490f7af Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Tue, 3 Dec 2013 20:15:33 +0000 Subject: [PATCH] Allow user settable threads. Fixes #10. Signed-off-by: Derek Buitenhuis --- README | 11 ++++++----- core/decode.cpp | 5 ++++- core/decode.hpp | 2 +- vs/d2vsource.cpp | 13 ++++++++++++- vs/vapoursynth.cpp | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README b/README index 0e3b813..b31f6ce 100644 --- a/README +++ b/README @@ -15,11 +15,12 @@ There's not much else to say, so let's get right to an example: ret.set_output() Parameters: - input - Full path to input D2V file. - nocrop - Always use direct-rendered buffer, which may need cropping. - Provides a speedup when you know you need to crop your image - anyway, by avoiding extra memcpy calls. - rff - Invoke ApplyRFF (True by default) + input - Full path to input D2V file. + nocrop - Always use direct-rendered buffer, which may need cropping. + Provides a speedup when you know you need to crop your image + anyway, by avoiding extra memcpy calls. + rff - Invoke ApplyRFF (True by default) + threads - Number of threads FFmpeg should use. Default is 0 (auto). About RFF Flags diff --git a/core/decode.cpp b/core/decode.cpp index 98c6ac7..52f117d 100644 --- a/core/decode.cpp +++ b/core/decode.cpp @@ -153,7 +153,7 @@ void decodefreep(decodecontext **ctx) } /* Initialize everything we can with regards to decoding */ -decodecontext *decodeinit(d2vcontext *dctx, string& err) +decodecontext *decodeinit(d2vcontext *dctx, int threads, string& err) { decodecontext *ret; int i, av_ret; @@ -221,6 +221,9 @@ decodecontext *decodeinit(d2vcontext *dctx, string& err) /* Set the IDCT algorithm. */ ret->avctx->idct_algo = dctx->idct_algo; + /* Set the thread count. */ + ret->avctx->thread_count = threads; + /* * Enable EMU_EDGE so that we can use buffers that are * not padded by 32 pixels. diff --git a/core/decode.hpp b/core/decode.hpp index ddb10f6..bc0a109 100644 --- a/core/decode.hpp +++ b/core/decode.hpp @@ -53,7 +53,7 @@ typedef struct decodecontext { uint64_t orig_file_offset; } decodecontext; -decodecontext *decodeinit(d2vcontext *dctx, string& err); +decodecontext *decodeinit(d2vcontext *dctx, int threads, string& err); void decodefreep(decodecontext **ctx); int decodeframe(int frame, d2vcontext *ctx, decodecontext *dctx, AVFrame *out, string& err); diff --git a/vs/d2vsource.cpp b/vs/d2vsource.cpp index 2482b6f..6bb1f8e 100644 --- a/vs/d2vsource.cpp +++ b/vs/d2vsource.cpp @@ -98,8 +98,19 @@ void VS_CC d2vCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, string msg; bool no_crop; bool rff; + int threads; int err; + /* Need to get thread info before anything to pass to decodeinit(). */ + threads = vsapi->propGetInt(in, "threads", 0, &err); + if (err) + threads = 0; + + if (threads < 0) { + vsapi->setError(out, "Invalid number of threads."); + return; + } + /* Allocate our private data. */ data = (d2vData *) malloc(sizeof(*data)); if (!data) { @@ -114,7 +125,7 @@ void VS_CC d2vCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, return; } - data->dec = decodeinit(data->d2v, msg); + data->dec = decodeinit(data->d2v, threads, msg); if (!data->dec) { vsapi->setError(out, msg.c_str()); d2vfreep(&data->d2v); diff --git a/vs/vapoursynth.cpp b/vs/vapoursynth.cpp index 2a8b8d7..894c5ac 100644 --- a/vs/vapoursynth.cpp +++ b/vs/vapoursynth.cpp @@ -34,6 +34,6 @@ extern "C" { VS_EXTERNAL_API(void) VapourSynthPluginInit(VSConfigPlugin configFunc, VSRegisterFunction registerFunc, VSPlugin *plugin) { configFunc("com.sources.d2vsource", "d2v", "D2V Source", VAPOURSYNTH_API_VERSION, 1, plugin); - registerFunc("Source", "input:data;nocrop:int:opt;rff:int:opt;", d2vCreate, 0, plugin); + registerFunc("Source", "input:data;threads:int:opt;nocrop:int:opt;rff:int:opt;", d2vCreate, 0, plugin); registerFunc("ApplyRFF", "clip:clip;d2v:data;", rffCreate, 0, plugin); }