From patchwork Thu Nov 15 22:06:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 1752021 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 9C06F4005F for ; Thu, 15 Nov 2012 22:06:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751564Ab2KOWGy (ORCPT ); Thu, 15 Nov 2012 17:06:54 -0500 Received: from nblzone-211-213.nblnetworks.fi ([83.145.211.213]:38740 "EHLO hillosipuli.retiisi.org.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751024Ab2KOWGv (ORCPT ); Thu, 15 Nov 2012 17:06:51 -0500 Received: from salottisipuli.retiisi.org.uk (salottisipuli.retiisi.org.uk [IPv6:2001:1bc8:102:6d9a::83:2]) by hillosipuli.retiisi.org.uk (Postfix) with ESMTP id BA887600A0; Fri, 16 Nov 2012 00:06:49 +0200 (EET) Received: by salottisipuli.retiisi.org.uk (Postfix, from userid 1000) id 1F42020B4E; Fri, 16 Nov 2012 00:06:48 +0200 (EET) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com Subject: [PATCH 2/4] v4l: Helper function for obtaining timestamps Date: Fri, 16 Nov 2012 00:06:45 +0200 Message-Id: <1353017207-370-2-git-send-email-sakari.ailus@iki.fi> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <20121115220627.GB29863@valkosipuli.retiisi.org.uk> References: <20121115220627.GB29863@valkosipuli.retiisi.org.uk> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org v4l2_get_timestamp() produces a monotonic timestamp but unlike ktime_get_ts(), it uses struct timeval instead of struct timespec, saving the drivers the conversion job when getting timestamps for v4l2_buffer's timestamp field. Signed-off-by: Sakari Ailus Acked-by: Hans Verkuil --- drivers/media/v4l2-core/v4l2-common.c | 10 ++++++++++ include/media/v4l2-common.h | 2 ++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c index 380ddd8..614316f 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -978,3 +978,13 @@ const struct v4l2_frmsize_discrete *v4l2_find_nearest_format( return best; } EXPORT_SYMBOL_GPL(v4l2_find_nearest_format); + +void v4l2_get_timestamp(struct timeval *tv) +{ + struct timespec ts; + + ktime_get_ts(&ts); + tv->tv_sec = ts.tv_sec; + tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC; +} +EXPORT_SYMBOL_GPL(v4l2_get_timestamp); diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index 1a0b2db..ec7c9c0 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -225,4 +225,6 @@ bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync, struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait); +void v4l2_get_timestamp(struct timeval *tv); + #endif /* V4L2_COMMON_H_ */