Skip to content

Commit 9585903

Browse files
committed
Allow user settable threads.
Fixes #10. Signed-off-by: Derek Buitenhuis <[email protected]>
1 parent 13af506 commit 9585903

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

README

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ There's not much else to say, so let's get right to an example:
1515
ret.set_output()
1616

1717
Parameters:
18-
input - Full path to input D2V file.
19-
nocrop - Always use direct-rendered buffer, which may need cropping.
20-
Provides a speedup when you know you need to crop your image
21-
anyway, by avoiding extra memcpy calls.
22-
rff - Invoke ApplyRFF (True by default)
18+
input - Full path to input D2V file.
19+
nocrop - Always use direct-rendered buffer, which may need cropping.
20+
Provides a speedup when you know you need to crop your image
21+
anyway, by avoiding extra memcpy calls.
22+
rff - Invoke ApplyRFF (True by default)
23+
threads - Number of threads FFmpeg should use. Default is 0 (auto).
2324

2425

2526
About RFF Flags

core/decode.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void decodefreep(decodecontext **ctx)
153153
}
154154

155155
/* Initialize everything we can with regards to decoding */
156-
decodecontext *decodeinit(d2vcontext *dctx, string& err)
156+
decodecontext *decodeinit(d2vcontext *dctx, int threads, string& err)
157157
{
158158
decodecontext *ret;
159159
int i, av_ret;
@@ -221,6 +221,9 @@ decodecontext *decodeinit(d2vcontext *dctx, string& err)
221221
/* Set the IDCT algorithm. */
222222
ret->avctx->idct_algo = dctx->idct_algo;
223223

224+
/* Set the thread count. */
225+
ret->avctx->thread_count = threads;
226+
224227
/*
225228
* Enable EMU_EDGE so that we can use buffers that are
226229
* not padded by 32 pixels.

core/decode.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef struct decodecontext {
5353
uint64_t orig_file_offset;
5454
} decodecontext;
5555

56-
decodecontext *decodeinit(d2vcontext *dctx, string& err);
56+
decodecontext *decodeinit(d2vcontext *dctx, int threads, string& err);
5757
void decodefreep(decodecontext **ctx);
5858
int decodeframe(int frame, d2vcontext *ctx, decodecontext *dctx, AVFrame *out, string& err);
5959

vs/d2vsource.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,19 @@ void VS_CC d2vCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core,
9898
string msg;
9999
bool no_crop;
100100
bool rff;
101+
int threads;
101102
int err;
102103

104+
/* Need to get thread info before anything to pass to decodeinit(). */
105+
threads = vsapi->propGetInt(in, "threads", 0, &err);
106+
if (err)
107+
threads = 0;
108+
109+
if (threads < 0) {
110+
vsapi->setError(out, "Invalid number of threads.");
111+
return;
112+
}
113+
103114
/* Allocate our private data. */
104115
data = (d2vData *) malloc(sizeof(*data));
105116
if (!data) {
@@ -114,7 +125,7 @@ void VS_CC d2vCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core,
114125
return;
115126
}
116127

117-
data->dec = decodeinit(data->d2v, msg);
128+
data->dec = decodeinit(data->d2v, threads, msg);
118129
if (!data->dec) {
119130
vsapi->setError(out, msg.c_str());
120131
d2vfreep(&data->d2v);

vs/vapoursynth.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ extern "C" {
3434
VS_EXTERNAL_API(void) VapourSynthPluginInit(VSConfigPlugin configFunc, VSRegisterFunction registerFunc, VSPlugin *plugin)
3535
{
3636
configFunc("com.sources.d2vsource", "d2v", "D2V Source", VAPOURSYNTH_API_VERSION, 1, plugin);
37-
registerFunc("Source", "input:data;nocrop:int:opt;rff:int:opt;", d2vCreate, 0, plugin);
37+
registerFunc("Source", "input:data;threads:int:opt;nocrop:int:opt;rff:int:opt;", d2vCreate, 0, plugin);
3838
registerFunc("ApplyRFF", "clip:clip;d2v:data;", rffCreate, 0, plugin);
3939
}

0 commit comments

Comments
 (0)