summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphintuka <phintuka>2007-10-31 22:14:18 +0000
committerphintuka <phintuka>2007-10-31 22:14:18 +0000
commit0f7fb082f1c66af1b635c270d7e468d11dd9cd70 (patch)
treeef8bf797ebeaffcde7eb661ede576c8f7739f993
parent1824e9964ab1a13c77cb0be8dcb27a62a72623d2 (diff)
downloadxineliboutput-0f7fb082f1c66af1b635c270d7e468d11dd9cd70.tar.gz
xineliboutput-0f7fb082f1c66af1b635c270d7e468d11dd9cd70.tar.bz2
Auto-detect number of CPUs
-rw-r--r--xine_frontend.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/xine_frontend.c b/xine_frontend.c
index 9ef12449..1eb8927c 100644
--- a/xine_frontend.c
+++ b/xine_frontend.c
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: xine_frontend.c,v 1.42 2007-10-28 20:16:57 phintuka Exp $
+ * $Id: xine_frontend.c,v 1.43 2007-10-31 22:14:18 phintuka Exp $
*
*/
@@ -46,6 +46,31 @@ static inline char *strn0cpy(char *dest, const char *src, int n)
return s;
}
+static int guess_cpu_count(void)
+{
+ static int cores = -1;
+ FILE *f;
+
+ if(cores >= 0)
+ return cores;
+
+ cores = 0;
+ if(NULL != (f = fopen("/proc/cpuinfo", "r"))) {
+ char buf[256];
+ while (NULL != fgets(buf, 255, f))
+ sscanf(buf, "processor : %d", &cores);
+ fclose(f);
+ }
+ cores++;
+
+ if(cores > 1)
+ LOGMSG("Detected %d CPUs", cores);
+ else
+ LOGDBG("Detected single CPU. Multithreaded decoding and post processing disabled.");
+
+ return cores;
+}
+
/*
* detect input plugin
*/
@@ -635,6 +660,27 @@ static int fe_xine_init(frontend_t *this_gen, const char *audio_driver,
posts->video_port = this->video_port;
posts->stream = this->stream;
+ /* multithreaded decoding / post processing */
+
+ if(guess_cpu_count() > 1) {
+ int xmajor, xminor, xsub;
+ xine_get_version(&xmajor, &xminor, &xsub);
+ if(xmajor*10000 + xminor*100 + xsub < 10109)
+ LOGMSG("Multithreaded video decoding is not supported in xine-lib %d.%d.%d",
+ xmajor, xminor, xsub);
+ else
+ LOGMSG("Enabling multithreaded video decoding");
+
+ /* try to enable anyway, maybe someone is using patched 1.1.8 ... */
+ x_upd_num("video.processing.ffmpeg_thread_count", guess_cpu_count());
+#if 0
+ LOGMSG("Enabling multithreaded post processing");
+ vpplugin_parse_and_store_post(posts, "thread");
+#endif
+ }
+
+ /* static post plugins from command-line */
+
if(static_post_plugins && *static_post_plugins) {
int i;
LOGDBG("static post plugins (from command line): %s", static_post_plugins);