Commit 03fafd80 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

v4l2: use buffer PTS where available (fix #5474)

parent 7f52b2ae
...@@ -566,7 +566,7 @@ static void *UserPtrThread (void *data) ...@@ -566,7 +566,7 @@ static void *UserPtrThread (void *data)
assert (block->p_buffer == (void *)buf.m.userptr); assert (block->p_buffer == (void *)buf.m.userptr);
block->i_buffer = buf.length; block->i_buffer = buf.length;
block->i_pts = block->i_dts = mdate (); block->i_pts = block->i_dts = GetBufferPTS (&buf);
block->i_flags |= sys->block_flags; block->i_flags |= sys->block_flags;
es_out_Control (demux->out, ES_OUT_SET_PCR, block->i_pts); es_out_Control (demux->out, ES_OUT_SET_PCR, block->i_pts);
es_out_Send (demux->out, sys->es, block); es_out_Send (demux->out, sys->es, block);
...@@ -611,7 +611,6 @@ static void *MmapThread (void *data) ...@@ -611,7 +611,6 @@ static void *MmapThread (void *data)
block_t *block = GrabVideo (VLC_OBJECT(demux), fd, sys->bufv); block_t *block = GrabVideo (VLC_OBJECT(demux), fd, sys->bufv);
if (block != NULL) if (block != NULL)
{ {
block->i_pts = block->i_dts = mdate ();
block->i_flags |= sys->block_flags; block->i_flags |= sys->block_flags;
es_out_Control (demux->out, ES_OUT_SET_PCR, block->i_pts); es_out_Control (demux->out, ES_OUT_SET_PCR, block->i_pts);
es_out_Send (demux->out, sys->es, block); es_out_Send (demux->out, sys->es, block);
......
...@@ -55,6 +55,7 @@ int StartUserPtr (vlc_object_t *, int); ...@@ -55,6 +55,7 @@ int StartUserPtr (vlc_object_t *, int);
struct buffer_t *StartMmap (vlc_object_t *, int, uint32_t *); struct buffer_t *StartMmap (vlc_object_t *, int, uint32_t *);
void StopMmap (int, struct buffer_t *, uint32_t); void StopMmap (int, struct buffer_t *, uint32_t);
mtime_t GetBufferPTS (const struct v4l2_buffer *);
block_t* GrabVideo (vlc_object_t *, int, const struct buffer_t *); block_t* GrabVideo (vlc_object_t *, int, const struct buffer_t *);
#ifdef ZVBI_COMPILED #ifdef ZVBI_COMPILED
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/mman.h> #include <sys/mman.h>
...@@ -513,6 +514,24 @@ int SetupFormat (vlc_object_t *obj, int fd, uint32_t fourcc, ...@@ -513,6 +514,24 @@ int SetupFormat (vlc_object_t *obj, int fd, uint32_t fourcc,
return 0; return 0;
} }
mtime_t GetBufferPTS (const struct v4l2_buffer *buf)
{
mtime_t pts;
switch (buf->flags & V4L2_BUF_FLAG_TIMESTAMP_MASK)
{
case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC:
pts = (buf->timestamp.tv_sec * CLOCK_FREQ)
+ buf->timestamp.tv_usec;
static_assert (CLOCK_FREQ == 1000000, "Clock unit mismatch");
break;
case V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN:
default:
pts = mdate ();
break;
}
return pts;
}
/***************************************************************************** /*****************************************************************************
* GrabVideo: Grab a video frame * GrabVideo: Grab a video frame
...@@ -545,6 +564,7 @@ block_t *GrabVideo (vlc_object_t *demux, int fd, ...@@ -545,6 +564,7 @@ block_t *GrabVideo (vlc_object_t *demux, int fd,
block_t *block = block_Alloc (buf.bytesused); block_t *block = block_Alloc (buf.bytesused);
if (unlikely(block == NULL)) if (unlikely(block == NULL))
return NULL; return NULL;
block->i_pts = block->i_dts = GetBufferPTS (&buf);
memcpy (block->p_buffer, bufv[buf.index].start, buf.bytesused); memcpy (block->p_buffer, bufv[buf.index].start, buf.bytesused);
/* Unlock */ /* Unlock */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment