[vlc-commits] v4l2: use buffer PTS where available (fix #5474)
Rémi Denis-Courmont
git at videolan.org
Fri Mar 8 19:42:41 CET 2013
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Mar 8 20:42:18 2013 +0200| [03fafd80fbf02169b6d0d9377c05748137d70ced] | committer: Rémi Denis-Courmont
v4l2: use buffer PTS where available (fix #5474)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=03fafd80fbf02169b6d0d9377c05748137d70ced
---
modules/access/v4l2/demux.c | 3 +--
modules/access/v4l2/v4l2.h | 1 +
modules/access/v4l2/video.c | 20 ++++++++++++++++++++
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/modules/access/v4l2/demux.c b/modules/access/v4l2/demux.c
index 598c082..9d9b2ff 100644
--- a/modules/access/v4l2/demux.c
+++ b/modules/access/v4l2/demux.c
@@ -566,7 +566,7 @@ static void *UserPtrThread (void *data)
assert (block->p_buffer == (void *)buf.m.userptr);
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;
es_out_Control (demux->out, ES_OUT_SET_PCR, block->i_pts);
es_out_Send (demux->out, sys->es, block);
@@ -611,7 +611,6 @@ static void *MmapThread (void *data)
block_t *block = GrabVideo (VLC_OBJECT(demux), fd, sys->bufv);
if (block != NULL)
{
- block->i_pts = block->i_dts = mdate ();
block->i_flags |= sys->block_flags;
es_out_Control (demux->out, ES_OUT_SET_PCR, block->i_pts);
es_out_Send (demux->out, sys->es, block);
diff --git a/modules/access/v4l2/v4l2.h b/modules/access/v4l2/v4l2.h
index dd219c9..9888785 100644
--- a/modules/access/v4l2/v4l2.h
+++ b/modules/access/v4l2/v4l2.h
@@ -55,6 +55,7 @@ int StartUserPtr (vlc_object_t *, int);
struct buffer_t *StartMmap (vlc_object_t *, int, 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 *);
#ifdef ZVBI_COMPILED
diff --git a/modules/access/v4l2/video.c b/modules/access/v4l2/video.c
index 3772662..bcc3afa 100644
--- a/modules/access/v4l2/video.c
+++ b/modules/access/v4l2/video.c
@@ -28,6 +28,7 @@
# include "config.h"
#endif
+#include <assert.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
@@ -513,6 +514,24 @@ int SetupFormat (vlc_object_t *obj, int fd, uint32_t fourcc,
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
@@ -545,6 +564,7 @@ block_t *GrabVideo (vlc_object_t *demux, int fd,
block_t *block = block_Alloc (buf.bytesused);
if (unlikely(block == NULL))
return NULL;
+ block->i_pts = block->i_dts = GetBufferPTS (&buf);
memcpy (block->p_buffer, bufv[buf.index].start, buf.bytesused);
/* Unlock */
More information about the vlc-commits
mailing list