From fb0e748c506e6d6ab08753ef400fe4ca9e4b5ed9 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Thu, 13 May 2004 10:13:41 +0000 Subject: [PATCH] sys/v4l/: add more debugging send a discont at start Original commit message from CVS: * sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get), (gst_v4lsrc_change_state): * sys/v4l/gstv4lsrc.h: * sys/v4l/v4lmjpegsink_calls.c: (gst_v4lmjpegsink_playback_init): * sys/v4l/v4lmjpegsrc_calls.c: (gst_v4lmjpegsrc_capture_init): * sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init), (gst_v4lsrc_grab_frame): add more debugging send a discont at start --- ChangeLog | 11 ++++++++ sys/v4l/gstv4lsrc.c | 49 ++++++++++++++++++++++++++++++++++-- sys/v4l/gstv4lsrc.h | 22 ++++++++-------- sys/v4l/v4lmjpegsink_calls.c | 2 +- sys/v4l/v4lmjpegsrc_calls.c | 2 +- sys/v4l/v4lsrc_calls.c | 8 +++--- 6 files changed, 77 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f7d2d68db..82f2860d96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-05-13 Thomas Vander Stichele + + * sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get), (gst_v4lsrc_change_state): + * sys/v4l/gstv4lsrc.h: + * sys/v4l/v4lmjpegsink_calls.c: (gst_v4lmjpegsink_playback_init): + * sys/v4l/v4lmjpegsrc_calls.c: (gst_v4lmjpegsrc_capture_init): + * sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init), + (gst_v4lsrc_grab_frame): + add more debugging + send a discont at start + 2004-05-12 Colin Walters * gst/asfdemux/gstasfdemux.c (gst_asf_demux_process_segment): Avoid diff --git a/sys/v4l/gstv4lsrc.c b/sys/v4l/gstv4lsrc.c index 88e8eabce8..82ddbc8c38 100644 --- a/sys/v4l/gstv4lsrc.c +++ b/sys/v4l/gstv4lsrc.c @@ -665,6 +665,7 @@ gst_v4lsrc_get (GstPad * pad) gint num; gdouble fps = 0.; v4lsrc_private_t *v4lsrc_private = NULL; + GstClockTime now, until; g_return_val_if_fail (pad != NULL, NULL); @@ -745,16 +746,58 @@ gst_v4lsrc_get (GstPad * pad) GST_BUFFER_DATA (buf) = gst_v4lsrc_get_buffer (v4lsrc, num); GST_BUFFER_MAXSIZE (buf) = v4lsrc->mbuf.size / v4lsrc->mbuf.frames; GST_BUFFER_SIZE (buf) = v4lsrc->buffer_size; - if (v4lsrc->use_fixed_fps) + if (v4lsrc->use_fixed_fps) { GST_BUFFER_TIMESTAMP (buf) = v4lsrc->handled * GST_SECOND / fps; - else /* calculate time based on our own clock */ + GST_BUFFER_DURATION (buf) = GST_SECOND / fps; + } else { + /* calculate time based on our own clock */ GST_BUFFER_TIMESTAMP (buf) = v4lsrc->timestamp_sync - v4lsrc->substract_time; + /* FIXME: in this case we might calculate from the delta with last frame ? */ + GST_BUFFER_DURATION (buf) = GST_SECOND / fps; + } + GST_LOG_OBJECT (v4lsrc, "outgoing buffer duration: %" GST_TIME_FORMAT, + GST_TIME_ARGS (GST_BUFFER_DURATION (buf))); + v4lsrc->handled++; g_signal_emit (G_OBJECT (v4lsrc), gst_v4lsrc_signals[SIGNAL_FRAME_CAPTURE], 0); + now = gst_element_get_time (GST_ELEMENT (v4lsrc)); + until = GST_BUFFER_TIMESTAMP (buf) + v4lsrc->last_discont; + + GST_LOG_OBJECT (v4lsrc, "Current time %" GST_TIME_FORMAT + ", buffer timestamp %" GST_TIME_FORMAT, + GST_TIME_ARGS (now), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf))); + if (now < until) { + GST_LOG_OBJECT (v4lsrc, "waiting until %" GST_TIME_FORMAT, + GST_TIME_ARGS (until)); + if (!gst_element_wait (GST_ELEMENT (v4lsrc), until)) + g_warning ("gst_element_wait failed"); + } + /* check for discont; we do it after grabbing so that we drop the + * first frame grabbed, but get an accurate discont event */ + if (v4lsrc->need_discont) { + GstEvent *event; + + v4lsrc->need_discont = FALSE; + + /* drop the buffer we made */ + gst_buffer_unref (buf); + + /* get time for discont */ + now = gst_element_get_time (GST_ELEMENT (v4lsrc)); + GST_DEBUG_OBJECT (v4lsrc, "sending time discont with %" GST_TIME_FORMAT, + GST_TIME_ARGS (now)); + + /* store discont internally so we can wait when sending buffers too soon */ + v4lsrc->last_discont = now; + + /* return event */ + event = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, now, NULL); + return GST_DATA (event); + } return GST_DATA (buf); } @@ -831,6 +874,8 @@ gst_v4lsrc_change_state (GstElement * element) break; case GST_STATE_READY_TO_PAUSED: v4lsrc->handled = 0; + v4lsrc->need_discont = TRUE; + v4lsrc->last_discont = 0; v4lsrc->need_writes = 0; v4lsrc->last_frame = 0; v4lsrc->substract_time = 0; diff --git a/sys/v4l/gstv4lsrc.h b/sys/v4l/gstv4lsrc.h index 1e035d8411..b0ce618bcb 100644 --- a/sys/v4l/gstv4lsrc.h +++ b/sys/v4l/gstv4lsrc.h @@ -23,7 +23,6 @@ #include G_BEGIN_DECLS - #define GST_TYPE_V4LSRC \ (gst_v4lsrc_get_type()) #define GST_V4LSRC(obj) \ @@ -34,18 +33,19 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_V4LSRC)) #define GST_IS_V4LSRC_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_V4LSRC)) - typedef struct _GstV4lSrc GstV4lSrc; typedef struct _GstV4lSrcClass GstV4lSrcClass; -enum { +enum +{ QUEUE_STATE_ERROR = -1, QUEUE_STATE_READY_FOR_QUEUE, QUEUE_STATE_QUEUED, QUEUE_STATE_SYNCED, }; -struct _GstV4lSrc { +struct _GstV4lSrc +{ GstV4lElement v4lelement; /* pads */ @@ -73,6 +73,8 @@ struct _GstV4lSrc { gulong handled; gint last_frame; gint need_writes; + gboolean need_discont; + GstClockTime last_discont; /* gst_element_get_time () of last discont send */ /* clock */ GstClock *clock; @@ -90,17 +92,17 @@ struct _GstV4lSrc { gboolean use_fixed_fps; }; -struct _GstV4lSrcClass { +struct _GstV4lSrcClass +{ GstV4lElementClass parent_class; - void (*frame_capture) (GObject *object); - void (*frame_drop) (GObject *object); - void (*frame_insert) (GObject *object); + void (*frame_capture) (GObject * object); + void (*frame_drop) (GObject * object); + void (*frame_insert) (GObject * object); }; -GType gst_v4lsrc_get_type(void); +GType gst_v4lsrc_get_type (void); G_END_DECLS - #endif /* __GST_V4LSRC_H__ */ diff --git a/sys/v4l/v4lmjpegsink_calls.c b/sys/v4l/v4lmjpegsink_calls.c index 46f7ce9be1..7c319470c0 100644 --- a/sys/v4l/v4lmjpegsink_calls.c +++ b/sys/v4l/v4lmjpegsink_calls.c @@ -328,7 +328,7 @@ gst_v4lmjpegsink_playback_init (GstV4lMjpegSink * v4lmjpegsink) return FALSE; } - GST_INFO ("Got %ld buffers of size %ld KB\n", + GST_INFO ("Got %ld buffers of size %ld KB", v4lmjpegsink->breq.count, v4lmjpegsink->breq.size / 1024); /* Map the buffers */ diff --git a/sys/v4l/v4lmjpegsrc_calls.c b/sys/v4l/v4lmjpegsrc_calls.c index 024a8eabb8..05bf87856b 100644 --- a/sys/v4l/v4lmjpegsrc_calls.c +++ b/sys/v4l/v4lmjpegsrc_calls.c @@ -336,7 +336,7 @@ gst_v4lmjpegsrc_capture_init (GstV4lMjpegSrc * v4lmjpegsrc) return FALSE; } - GST_INFO ("Got %ld buffers of size %ld KB\n", + GST_INFO ("Got %ld buffers of size %ld KB", v4lmjpegsrc->breq.count, v4lmjpegsrc->breq.size / 1024); /* keep track of queued buffers */ diff --git a/sys/v4l/v4lsrc_calls.c b/sys/v4l/v4lsrc_calls.c index 6c01f054b9..718e8e4b2b 100644 --- a/sys/v4l/v4lsrc_calls.c +++ b/sys/v4l/v4lsrc_calls.c @@ -198,7 +198,7 @@ gst_v4lsrc_capture_init (GstV4lSrc * v4lsrc) return FALSE; } - GST_INFO ("Got %d buffers (\'%s\') of size %d KB\n", + GST_INFO ("Got %d buffers (\'%s\') of size %d KB", v4lsrc->mbuf.frames, palette_name[v4lsrc->mmap.format], v4lsrc->mbuf.size / (v4lsrc->mbuf.frames * 1024)); @@ -276,7 +276,8 @@ gst_v4lsrc_capture_start (GstV4lSrc * v4lsrc) gboolean gst_v4lsrc_grab_frame (GstV4lSrc * v4lsrc, gint * num) { - LOG ("grabbing frame"); + LOG ("(%" GST_TIME_FORMAT ") grabbing frame", + GST_TIME_ARGS (gst_clock_get_time (v4lsrc->clock))); GST_V4L_CHECK_OPEN (GST_V4LELEMENT (v4lsrc)); GST_V4L_CHECK_ACTIVE (GST_V4LELEMENT (v4lsrc)); @@ -311,7 +312,8 @@ gst_v4lsrc_grab_frame (GstV4lSrc * v4lsrc, gint * num) } v4lsrc->sync_frame = (v4lsrc->sync_frame + 1) % v4lsrc->mbuf.frames; - GST_LOG ("grabbed frame %d", *num); + LOG ("(%" GST_TIME_FORMAT ") grabbed frame %d", + GST_TIME_ARGS (gst_clock_get_time (v4lsrc->clock)), *num); g_mutex_unlock (v4lsrc->mutex_queue_state);