summaryrefslogtreecommitdiffstats
path: root/stream/tvi_v4l2.c
diff options
context:
space:
mode:
authorvoroshil <voroshil@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-06-30 17:42:35 +0000
committervoroshil <voroshil@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-06-30 17:42:35 +0000
commitfddbd849924748088d719d0289b768a493d0be9e (patch)
tree7a58a0705082e892db06d4bc270aa29679da656e /stream/tvi_v4l2.c
parent61d2b20de17481ae6c0ff399cde63bfd2593d83b (diff)
downloadmpv-fddbd849924748088d719d0289b768a493d0be9e.tar.bz2
mpv-fddbd849924748088d719d0289b768a493d0be9e.tar.xz
Fix division by zero in tvi_v4l2 which occures when capture device
driver (such as uvcvideo USB video driver) does not provide VIDIOC_G_STD ioctl. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27170 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'stream/tvi_v4l2.c')
-rw-r--r--stream/tvi_v4l2.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/stream/tvi_v4l2.c b/stream/tvi_v4l2.c
index a13d4c203a..c188da92a4 100644
--- a/stream/tvi_v4l2.c
+++ b/stream/tvi_v4l2.c
@@ -336,13 +336,23 @@ static int amode2v4l(int amode)
}
+/*
+** Get current FPS.
+*/
+static double getfps(priv_t *priv)
+{
+ if (priv->tv_param->fps > 0)
+ return priv->tv_param->fps;
+ if (priv->standard.frameperiod.denominator && priv->standard.frameperiod.numerator)
+ return (double)priv->standard.frameperiod.denominator / priv->standard.frameperiod.numerator;
+ return 25.0;
+}
+
// sets and sanitizes audio buffer/block sizes
static void setup_audio_buffer_sizes(priv_t *priv)
{
int bytes_per_sample = priv->audio_in.bytes_per_sample;
- double fps = (double)priv->standard.frameperiod.denominator /
- priv->standard.frameperiod.numerator;
- int seconds = priv->video_buffer_size_max/fps;
+ int seconds = priv->video_buffer_size_max/getfps(priv);
if (seconds < 5) seconds = 5;
if (seconds > 500) seconds = 500;
@@ -701,6 +711,10 @@ static int control(priv_t *priv, int cmd, void *arg)
priv->immediate_mode = 1;
return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_GET_FPS:
+ if (!priv->standard.frameperiod.denominator || !priv->standard.frameperiod.numerator) {
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: Cannot get fps\n", info.short_name);
+ return TVI_CONTROL_FALSE;
+ }
*(float *)arg = (float)priv->standard.frameperiod.denominator /
priv->standard.frameperiod.numerator;
mp_msg(MSGT_TV, MSGL_V, "%s: get fps: %f\n", info.short_name,
@@ -1089,11 +1103,7 @@ static int uninit(priv_t *priv)
struct v4l2_buffer buf;
/* get performance */
- frames = 1 + (priv->curr_frame - priv->first_frame +
- priv->standard.frameperiod.numerator * 500000 /
- priv->standard.frameperiod.denominator) *
- priv->standard.frameperiod.denominator /
- priv->standard.frameperiod.numerator / 1000000;
+ frames = 1 + lrintf((double)(priv->curr_frame - priv->first_frame) / (1e6 * getfps(priv)));
dropped = frames - priv->frames;
/* turn off streaming */