Skip to content

Commit

Permalink
[media] [FOR,v3.3] uvcvideo: Avoid division by 0 in timestamp calcula…
Browse files Browse the repository at this point in the history
…tion

Use system timestamps if the timestamp can't be computed from the data
sent by the device.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Laurent Pinchart authored and Mauro Carvalho Chehab committed Feb 27, 2012
1 parent fda2787 commit 8e57dec
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions drivers/media/video/uvc/uvc_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,11 @@ void uvc_video_clock_update(struct uvc_streaming *stream,
delta_stc = buf->pts - (1UL << 31);
x1 = first->dev_stc - delta_stc;
x2 = last->dev_stc - delta_stc;
if (x1 == x2)
goto done;

y1 = (first->dev_sof + 2048) << 16;
y2 = (last->dev_sof + 2048) << 16;

if (y2 < y1)
y2 += 2048 << 16;

Expand All @@ -631,14 +633,16 @@ void uvc_video_clock_update(struct uvc_streaming *stream,
x1, x2, y1, y2, clock->sof_offset);

/* Second step, SOF to host clock conversion. */
ts = timespec_sub(last->host_ts, first->host_ts);
x1 = (uvc_video_clock_host_sof(first) + 2048) << 16;
x2 = (uvc_video_clock_host_sof(last) + 2048) << 16;
y1 = NSEC_PER_SEC;
y2 = (ts.tv_sec + 1) * NSEC_PER_SEC + ts.tv_nsec;

if (x2 < x1)
x2 += 2048 << 16;
if (x1 == x2)
goto done;

ts = timespec_sub(last->host_ts, first->host_ts);
y1 = NSEC_PER_SEC;
y2 = (ts.tv_sec + 1) * NSEC_PER_SEC + ts.tv_nsec;

/* Interpolated and host SOF timestamps can wrap around at slightly
* different times. Handle this by adding or removing 2048 to or from
Expand Down

0 comments on commit 8e57dec

Please sign in to comment.