summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoriive <iive@b3059339-0415-0410-9bf9-f77b7e298cf2>2011-06-26 14:42:35 +0000
committerUoti Urpala <uau@mplayer2.org>2011-07-06 13:01:08 +0300
commit860e66818b6f93d80f0e61763de21892c8596dc0 (patch)
tree125e6fc62260eed1cae4e36c5afe0d7ad4471501
parent01e441dddc3cb9677819513b9ef32f502c58c2fd (diff)
downloadmpv-860e66818b6f93d80f0e61763de21892c8596dc0.tar.bz2
mpv-860e66818b6f93d80f0e61763de21892c8596dc0.tar.xz
stream/tvi_v4l[2]: fix calculation of free RAM for buffers
Do a proper calculation of free RAM to be used as V4L buffers. The code uses sysinfo to query the available RAM, however it used ancient form available in some early development 2.3.x kernels. Newer form reports the size in memory units (usually same as page size), as result the code would fall back on 2 buffers even on multi GB system. The commit does: Improve the check in configure to ensure that we do use sysinfo struct with present mem_unit. Use free RAM instead of total RAM (to avoid swapping). Tweak memory constants and simplify code. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33732 b3059339-0415-0410-9bf9-f77b7e298cf2
-rwxr-xr-xconfigure2
-rw-r--r--stream/tvi_v4l.c13
-rw-r--r--stream/tvi_v4l2.c13
3 files changed, 11 insertions, 17 deletions
diff --git a/configure b/configure
index 8d86901f2f..59b9f6d9e0 100755
--- a/configure
+++ b/configure
@@ -3551,7 +3551,7 @@ fi #if sunos
echocheck "sys/sysinfo.h"
_sys_sysinfo=no
-statement_check sys/sysinfo.h 'struct sysinfo s_info; sysinfo(&s_info)' && _sys_sysinfo=yes
+statement_check sys/sysinfo.h 'struct sysinfo s_info; s_info.mem_unit=0; sysinfo(&s_info)' && _sys_sysinfo=yes
if test "$_sys_sysinfo" = yes ; then
def_sys_sysinfo_h='#define HAVE_SYS_SYSINFO_H 1'
else
diff --git a/stream/tvi_v4l.c b/stream/tvi_v4l.c
index bbf290eeaf..31f767850b 100644
--- a/stream/tvi_v4l.c
+++ b/stream/tvi_v4l.c
@@ -760,7 +760,8 @@ static int uninit(priv_t *priv)
static int get_capture_buffer_size(priv_t *priv)
{
- int bufsize, cnt;
+ uint64_t bufsize;
+ int cnt;
if (priv->tv_param->buffer_size >= 0) {
bufsize = priv->tv_param->buffer_size*1024*1024;
@@ -769,14 +770,10 @@ static int get_capture_buffer_size(priv_t *priv)
struct sysinfo si;
sysinfo(&si);
- if (si.totalram<2*1024*1024) {
- bufsize = 1024*1024;
- } else {
- bufsize = si.totalram/2;
- }
-#else
- bufsize = 16*1024*1024;
+ bufsize = (si.freeram/2)*si.mem_unit;
+ if (bufsize < 16*1024*1024)
#endif
+ bufsize = 16*1024*1024;
}
cnt = bufsize/(priv->height*priv->bytesperline);
diff --git a/stream/tvi_v4l2.c b/stream/tvi_v4l2.c
index 234a5ac019..a3be9e799a 100644
--- a/stream/tvi_v4l2.c
+++ b/stream/tvi_v4l2.c
@@ -1376,7 +1376,8 @@ static int init(priv_t *priv)
static int get_capture_buffer_size(priv_t *priv)
{
- int bufsize, cnt;
+ uint64_t bufsize;
+ int cnt;
if (priv->tv_param->buffer_size >= 0) {
bufsize = priv->tv_param->buffer_size*1024*1024;
@@ -1385,14 +1386,10 @@ static int get_capture_buffer_size(priv_t *priv)
struct sysinfo si;
sysinfo(&si);
- if (si.totalram<2*1024*1024) {
- bufsize = 1024*1024;
- } else {
- bufsize = si.totalram/2;
- }
-#else
- bufsize = 16*1024*1024;
+ bufsize = (si.freeram/2)*si.mem_unit;
+ if ( bufsize < 16*1024*1024)
#endif
+ bufsize = 16*1024*1024;
}
cnt = bufsize/priv->format.fmt.pix.sizeimage;