Skip to content

Commit

Permalink
Allow user settable threads.
Browse files Browse the repository at this point in the history
Fixes #10.

Signed-off-by: Derek Buitenhuis <[email protected]>
  • Loading branch information
dwbuiten committed Dec 3, 2013
1 parent 13af506 commit 9585903
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
11 changes: 6 additions & 5 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion core/decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion core/decode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 12 additions & 1 deletion vs/d2vsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion vs/vapoursynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 9585903

Please sign in to comment.