+2004-05-13 Thomas Vander Stichele <thomas at apestaart dot org>
+
+ * 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 <walters@redhat.com>
* gst/asfdemux/gstasfdemux.c (gst_asf_demux_process_segment): Avoid
gint num;
gdouble fps = 0.;
v4lsrc_private_t *v4lsrc_private = NULL;
+ GstClockTime now, until;
g_return_val_if_fail (pad != NULL, NULL);
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);
}
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;
#include <gstv4lelement.h>
G_BEGIN_DECLS
-
#define GST_TYPE_V4LSRC \
(gst_v4lsrc_get_type())
#define GST_V4LSRC(obj) \
(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 */
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;
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__ */
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 */
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 */
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));
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));
}
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);