Skip to content

Commit 94665c5

Browse files
committed
vdec/lavc: thread option to keep default val
1 parent e8e4401 commit 94665c5

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/video_decompress/libavcodec.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,20 @@ static int check_av_opt_set(void *state, const char *key, const char *val) {
140140
return ret;
141141
}
142142

143+
/// @todo 'd' flag is not entirely thread-specific - maybe new param or rename
144+
/// this to "lavd-opts" or so?
143145
ADD_TO_PARAM("lavd-thread-count",
144-
"* lavd-thread-count=[<thread_count>][F][S][n][d]\n"
146+
"* lavd-thread-count=[<thread_count>][F][S][n][d][D]\n"
145147
" Use <thread_count> decoding threads (0 is usually auto).\n"
146148
" Flag 'F' enables frame parallelism (disabled by default), 'S' "
147149
"slice based, can be both (default slice), 'n' for none; 'd' - "
148-
"disable low delay\n");
150+
"disable low delay\n"
151+
" 'D' - don't set anything (keep codec defaults)\n");
149152
static void
150-
set_codec_context_params(struct state_libavcodec_decompress *s)
153+
set_thread_count(struct state_libavcodec_decompress *s, bool *req_low_delay)
151154
{
152155
int thread_count = 0; ///< decoder may use <cpu_count> frame threads with AV_CODEC_CAP_OTHER_THREADS (latency)
153156
int req_thread_type = 0;
154-
bool req_low_delay = true;
155157
const char *thread_count_opt = get_commandline_param("lavd-thread-count");
156158
if (thread_count_opt != NULL) {
157159
char *endptr = NULL;
@@ -162,10 +164,11 @@ set_codec_context_params(struct state_libavcodec_decompress *s)
162164
}
163165
while (*endptr) {
164166
switch (toupper(*endptr)) {
167+
case 'D': thread_count = -1; break;
165168
case 'F': req_thread_type |= FF_THREAD_FRAME; break;
166169
case 'S': req_thread_type |= FF_THREAD_SLICE; break;
167170
case 'n': req_thread_type = -1; break;
168-
case 'd': req_low_delay = false; break;
171+
case 'd': *req_low_delay = false; break;
169172
default: errno = EINVAL; break;
170173
}
171174
endptr++;
@@ -176,6 +179,9 @@ set_codec_context_params(struct state_libavcodec_decompress *s)
176179
handle_error(EXIT_FAIL_USAGE);
177180
}
178181
}
182+
if (thread_count == -1) {
183+
return;
184+
}
179185

180186
s->codec_ctx->thread_count = thread_count; // zero should mean count equal to the number of virtual cores
181187
s->codec_ctx->thread_type = 0;
@@ -199,6 +205,13 @@ set_codec_context_params(struct state_libavcodec_decompress *s)
199205
}
200206
}
201207
log_msg(LOG_LEVEL_INFO, MOD_NAME "Setting thread count to %d, type: %s\n", s->codec_ctx->thread_count, lavc_thread_type_to_str(s->codec_ctx->thread_type));
208+
}
209+
210+
static void
211+
set_codec_context_params(struct state_libavcodec_decompress *s)
212+
{
213+
bool req_low_delay = true;
214+
set_thread_count(s, &req_low_delay);
202215

203216
s->codec_ctx->flags |= req_low_delay ? AV_CODEC_FLAG_LOW_DELAY : 0;
204217
s->codec_ctx->flags2 |= AV_CODEC_FLAG2_FAST;

0 commit comments

Comments
 (0)