Where is the image frame timestamp set in the VI module driver?

Hi NV,

JP5.1.2,AGX Orin
Where is the image frame timestamp set in the VI module driver?

I found the following:
kernel/nvidia/drivers/media/platform/tegra/camera/vi/vi2_fops.c
475 #if KERNEL_VERSION(5, 4, 0) > LINUX_VERSION_CODE
476 getrawmonotonic(&ts);
477 else
478 ktime_get_ts64(&ts);
479 endif

and :
kernel/nvidia/drivers/media/platform/tegra/camera/vi/vi5_fops.c
558 #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)
559 ts = ns_to_timespec((s64)descr->status.sof_timestamp);
560 else
561 ts = ns_to_timespec64((s64)descr->status.sof_timestamp);
562 endif

I want to know where the timestamp in the image frame structure is set? Is this timestamp UTC time?

Thanks

hello wangxiaojunfuture,

there’re different version of VI drivers, you should check vi5 as you’re working with Orin series. and… JP-5.1.2 is using kernel-5.10.

hence,
it’s ts = ns_to_timespec64((s64)descr->status.sof_timestamp); to report SOF timestamp to vb2 buffer.
this is TSC HW timestamp, you may see-also Argus::Ext::ISensorTimestampTsc::getSensorSofTimestampTsc for reference.

Hi Jerry,

I want to calculate the corresponding realtime (wall time) based on the current capture sof_timestamp(TSC)

  1. Get the TSC domain timestamp from VB2 buffer,
  2. Calculate the realtime boot time
  3. Calculate realtime timestamp of capture

Our sample code:

//1. Get the TSC domain timestamp from VB2 buffer,
struct v4l2_buffer bufferinfo;

bufferinfo.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
bufferinfo.memory = V4L2_MEMORY_DMABUF;

ioctl(camera.fd_, VIDIOC_DQBUF, &bufferinfo)
TSC_time = (bufferinfo.timestamp.tv_sec *1000 + bufferinfo.timestamp.tv_usec / 1000)

//2. Calculate the realtime boot time
clock_gettime(CLOCK_MONOTONIC, &ts);
gettimeofday(&cur_time, NULL);
BootTime = (cur_time.tv_sec * 1000 + cur_time.tv_usec / 1000) - (ts.tv_sec*1000 + ts.tv_nsec/1000000); //power on time

//3. Calculate realtime timestamp of capture
//offset_ns :cat /sys/devices/system/clocksource/clocksource0/offset_ns
RealTimeStamp = BootTime + TSC_time - offset_ns

Are there any logical errors in the above code?

Thanks!

hello wangxiaojunfuture,

there’s offset_ns to record the delta from TSC to start of MONOTONIC_RAW.
you may see-also Topic 159220 for an example to use offset_ns compensate the capture timestamp.

Hi Jerry,

Do TSC and MONOTONIC_RAW use the same hardware clock source?
If the system runs for 720 hours, will the difference between them become larger and larger?

Thanks a lot!

hello wangxiaojunfuture,

to be honest, I’ve never test it for such long period (i.e. 30-days)
as you may know, even the RTC accuracy is -11 ~ +20 seconds/day.

Hi Jerry,

Please help ask your company’s R&D personnel about the accuracy or error rules of TSC. Our products involve the fusion of each frame of image and radar data, and they work for a long time, so they must have very accurate timestamps.

Thanks a lot!

Please confirm:
Do TSC and MONOTONIC_RAW use the same hardware clock source?

hello wangxiaojunfuture,

they’re different. TSC is taking the timestamp of RCE, it’s a dedicated processor for camera management.
anyways, while EGL stream capture the timestamp when it rendering the frame to display. it’s close to end-of-frame of the sensor signaling, you may have alternative way by using EGLStream::IFrame::getTime
for instance, /usr/src/jetson_multimedia_api/argus/include/EGLStream/Frame.h

class IFrame : public Argus::Interface
{
public:
...
    /** 
     * Returns the timestamp of the frame, in nanoseconds.
     */
    virtual uint64_t getTime() const = 0;

Hi Herry,

from Topic 159220:
clock_gettime(MONOTONIC_RAW) = cycle_ns(TSC) - offset_ns

Why is the time format not MONOTONIC?

because the time has a fixed offset from CLOCK_MONOTONIC_RAW.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.