mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
gst/videotestsrc/gstvideotestsrc.*: Implement seeking in videotestsrc.
Original commit message from CVS: * gst/videotestsrc/gstvideotestsrc.c: (gst_video_test_src_class_init), (gst_video_test_src_init), (gst_video_test_src_parse_caps), (gst_video_test_src_query), (gst_video_test_src_do_seek), (gst_video_test_src_is_seekable), (gst_video_test_src_create): * gst/videotestsrc/gstvideotestsrc.h: Implement seeking in videotestsrc. Small cleanups.
This commit is contained in:
parent
d02b57f7e0
commit
eb9cd91b27
3 changed files with 121 additions and 68 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2005-12-12 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
|
* gst/videotestsrc/gstvideotestsrc.c:
|
||||||
|
(gst_video_test_src_class_init), (gst_video_test_src_init),
|
||||||
|
(gst_video_test_src_parse_caps), (gst_video_test_src_query),
|
||||||
|
(gst_video_test_src_do_seek), (gst_video_test_src_is_seekable),
|
||||||
|
(gst_video_test_src_create):
|
||||||
|
* gst/videotestsrc/gstvideotestsrc.h:
|
||||||
|
Implement seeking in videotestsrc.
|
||||||
|
Small cleanups.
|
||||||
|
|
||||||
2005-12-12 Wim Taymans <wim@fluendo.com>
|
2005-12-12 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
* ext/cdparanoia/Makefile.am:
|
* ext/cdparanoia/Makefile.am:
|
||||||
|
|
|
@ -79,7 +79,10 @@ static GstCaps *gst_video_test_src_getcaps (GstBaseSrc * bsrc);
|
||||||
static gboolean gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
|
static gboolean gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
|
||||||
static void gst_video_test_src_src_fixate (GstPad * pad, GstCaps * caps);
|
static void gst_video_test_src_src_fixate (GstPad * pad, GstCaps * caps);
|
||||||
|
|
||||||
static gboolean gst_video_test_src_event (GstBaseSrc * bsrc, GstEvent * event);
|
static gboolean gst_video_test_src_is_seekable (GstBaseSrc * psrc);
|
||||||
|
static gboolean gst_video_test_src_do_seek (GstBaseSrc * bsrc,
|
||||||
|
GstSegment * segment);
|
||||||
|
static gboolean gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
|
||||||
|
|
||||||
static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
|
static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
|
||||||
GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
|
GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
|
||||||
|
@ -147,9 +150,11 @@ gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
|
||||||
|
|
||||||
gstbasesrc_class->get_caps = gst_video_test_src_getcaps;
|
gstbasesrc_class->get_caps = gst_video_test_src_getcaps;
|
||||||
gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
|
gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
|
||||||
gstbasesrc_class->event = gst_video_test_src_event;
|
gstbasesrc_class->is_seekable = gst_video_test_src_is_seekable;
|
||||||
|
gstbasesrc_class->do_seek = gst_video_test_src_do_seek;
|
||||||
|
gstbasesrc_class->query = gst_video_test_src_query;
|
||||||
gstbasesrc_class->get_times = gst_video_test_src_get_times;
|
gstbasesrc_class->get_times = gst_video_test_src_get_times;
|
||||||
|
|
||||||
gstpushsrc_class->create = gst_video_test_src_create;
|
gstpushsrc_class->create = gst_video_test_src_create;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,10 +167,10 @@ gst_video_test_src_init (GstVideoTestSrc * src, GstVideoTestSrcClass * g_class)
|
||||||
|
|
||||||
gst_video_test_src_set_pattern (src, GST_VIDEO_TEST_SRC_SMPTE);
|
gst_video_test_src_set_pattern (src, GST_VIDEO_TEST_SRC_SMPTE);
|
||||||
|
|
||||||
src->segment_start_frame = -1;
|
|
||||||
src->segment_end_frame = -1;
|
|
||||||
src->timestamp_offset = 0;
|
src->timestamp_offset = 0;
|
||||||
|
|
||||||
|
/* we operate in time */
|
||||||
|
gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
|
||||||
gst_base_src_set_live (GST_BASE_SRC (src), FALSE);
|
gst_base_src_set_live (GST_BASE_SRC (src), FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,24 +295,32 @@ gst_video_test_src_parse_caps (const GstCaps * caps,
|
||||||
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
|
|
||||||
*fourcc = paintinfo_find_by_structure (structure);
|
if (!(*fourcc = paintinfo_find_by_structure (structure)))
|
||||||
if (!*fourcc) {
|
goto unknown_format;
|
||||||
g_critical ("videotestsrc format not found");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = gst_structure_get_int (structure, "width", width);
|
ret = gst_structure_get_int (structure, "width", width);
|
||||||
ret &= gst_structure_get_int (structure, "height", height);
|
ret &= gst_structure_get_int (structure, "height", height);
|
||||||
|
|
||||||
framerate = gst_structure_get_value (structure, "framerate");
|
framerate = gst_structure_get_value (structure, "framerate");
|
||||||
|
|
||||||
if (framerate) {
|
if (framerate) {
|
||||||
*rate_numerator = gst_value_get_fraction_numerator (framerate);
|
*rate_numerator = gst_value_get_fraction_numerator (framerate);
|
||||||
*rate_denominator = gst_value_get_fraction_denominator (framerate);
|
*rate_denominator = gst_value_get_fraction_denominator (framerate);
|
||||||
} else
|
} else
|
||||||
ret = FALSE;
|
goto no_framerate;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
unknown_format:
|
||||||
|
{
|
||||||
|
GST_DEBUG ("videotestsrc format not found");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
no_framerate:
|
||||||
|
{
|
||||||
|
GST_DEBUG ("videotestsrc no framerate given");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -339,58 +352,67 @@ gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_video_test_src_event (GstBaseSrc * bsrc, GstEvent * event)
|
gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
|
||||||
{
|
{
|
||||||
gboolean res = TRUE;
|
gboolean res;
|
||||||
GstVideoTestSrc *videotestsrc;
|
GstVideoTestSrc *src;
|
||||||
gint64 new_n_frames;
|
|
||||||
|
|
||||||
videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
|
src = GST_VIDEO_TEST_SRC (bsrc);
|
||||||
new_n_frames = videotestsrc->n_frames;
|
|
||||||
|
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
switch (GST_QUERY_TYPE (query)) {
|
||||||
case GST_EVENT_SEEK:
|
case GST_QUERY_CONVERT:
|
||||||
{
|
{
|
||||||
GstFormat format;
|
GstFormat src_fmt, dest_fmt;
|
||||||
GstSeekType cur_type, stop_type;
|
gint64 src_val, dest_val;
|
||||||
GstSeekFlags flags;
|
|
||||||
gint64 cur, stop;
|
|
||||||
|
|
||||||
gst_event_parse_seek (event, NULL, &format, &flags, &cur_type, &cur,
|
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
||||||
&stop_type, &stop);
|
if (src_fmt == dest_fmt) {
|
||||||
|
dest_val = src_val;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
switch (format) {
|
switch (src_fmt) {
|
||||||
case GST_FORMAT_TIME:
|
|
||||||
new_n_frames = cur * videotestsrc->rate_numerator /
|
|
||||||
(videotestsrc->rate_denominator * GST_SECOND);
|
|
||||||
videotestsrc->segment_start_frame = new_n_frames;
|
|
||||||
videotestsrc->segment_end_frame =
|
|
||||||
stop * videotestsrc->rate_numerator /
|
|
||||||
(videotestsrc->rate_denominator * GST_SECOND);
|
|
||||||
videotestsrc->segment = flags & GST_SEEK_FLAG_SEGMENT;
|
|
||||||
break;
|
|
||||||
case GST_FORMAT_DEFAULT:
|
case GST_FORMAT_DEFAULT:
|
||||||
new_n_frames = cur;
|
switch (dest_fmt) {
|
||||||
videotestsrc->segment_start_frame = new_n_frames;
|
case GST_FORMAT_TIME:
|
||||||
videotestsrc->segment_end_frame = stop;
|
/* frames to time */
|
||||||
videotestsrc->segment = flags & GST_SEEK_FLAG_SEGMENT;
|
dest_val = gst_util_uint64_scale (src_val,
|
||||||
|
src->rate_denominator * GST_SECOND, src->rate_numerator);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GST_FORMAT_TIME:
|
||||||
|
switch (dest_fmt) {
|
||||||
|
case GST_FORMAT_DEFAULT:
|
||||||
|
/* time to frames */
|
||||||
|
dest_val = gst_util_uint64_scale (src_val,
|
||||||
|
src->rate_numerator, src->rate_denominator * GST_SECOND);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res = FALSE;
|
goto error;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
done:
|
||||||
|
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
||||||
|
res = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
res = FALSE;
|
res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (videotestsrc->n_frames != new_n_frames) {
|
|
||||||
videotestsrc->n_frames = new_n_frames;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
/* ERROR */
|
||||||
|
error:
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (src, "query failed");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -416,6 +438,34 @@ gst_video_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
|
||||||
|
{
|
||||||
|
GstClockTime time;
|
||||||
|
GstVideoTestSrc *src;
|
||||||
|
|
||||||
|
src = GST_VIDEO_TEST_SRC (bsrc);
|
||||||
|
|
||||||
|
time = segment->time = segment->start;
|
||||||
|
|
||||||
|
/* now move to the time indicated */
|
||||||
|
src->n_frames = gst_util_uint64_scale (time,
|
||||||
|
src->rate_numerator, src->rate_denominator * GST_SECOND);
|
||||||
|
src->running_time = gst_util_uint64_scale (src->n_frames,
|
||||||
|
src->rate_denominator * GST_SECOND, src->rate_numerator);
|
||||||
|
|
||||||
|
g_assert (src->running_time <= time);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_video_test_src_is_seekable (GstBaseSrc * psrc)
|
||||||
|
{
|
||||||
|
/* we're seekable... */
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_video_test_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
gst_video_test_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
||||||
{
|
{
|
||||||
|
@ -423,10 +473,11 @@ gst_video_test_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
||||||
gulong newsize;
|
gulong newsize;
|
||||||
GstBuffer *outbuf;
|
GstBuffer *outbuf;
|
||||||
GstFlowReturn res;
|
GstFlowReturn res;
|
||||||
|
GstClockTime next_time;
|
||||||
|
|
||||||
src = GST_VIDEO_TEST_SRC (psrc);
|
src = GST_VIDEO_TEST_SRC (psrc);
|
||||||
|
|
||||||
if (src->fourcc == NULL)
|
if (src->fourcc == NULL || src->rate_numerator == 0)
|
||||||
goto not_negotiated;
|
goto not_negotiated;
|
||||||
|
|
||||||
newsize = gst_video_test_src_get_size (src, src->width, src->height);
|
newsize = gst_video_test_src_get_size (src, src->width, src->height);
|
||||||
|
@ -444,11 +495,7 @@ gst_video_test_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
||||||
if (res != GST_FLOW_OK)
|
if (res != GST_FLOW_OK)
|
||||||
goto no_buffer;
|
goto no_buffer;
|
||||||
#else
|
#else
|
||||||
res = GST_FLOW_OK;
|
|
||||||
|
|
||||||
outbuf = gst_buffer_new_and_alloc (newsize);
|
outbuf = gst_buffer_new_and_alloc (newsize);
|
||||||
if (outbuf == NULL)
|
|
||||||
goto no_buffer;
|
|
||||||
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc)));
|
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -456,16 +503,14 @@ gst_video_test_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
|
||||||
src->width, src->height);
|
src->width, src->height);
|
||||||
|
|
||||||
GST_BUFFER_TIMESTAMP (outbuf) = src->timestamp_offset + src->running_time;
|
GST_BUFFER_TIMESTAMP (outbuf) = src->timestamp_offset + src->running_time;
|
||||||
if (src->rate_numerator != 0) {
|
GST_BUFFER_OFFSET (outbuf) = src->n_frames;
|
||||||
GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale_int (GST_SECOND,
|
|
||||||
src->rate_denominator, src->rate_numerator);
|
|
||||||
}
|
|
||||||
|
|
||||||
src->n_frames++;
|
src->n_frames++;
|
||||||
if (src->rate_numerator != 0) {
|
GST_BUFFER_OFFSET_END (outbuf) = src->n_frames;
|
||||||
src->running_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
|
next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
|
||||||
src->rate_denominator, src->rate_numerator);
|
src->rate_denominator, src->rate_numerator);
|
||||||
}
|
GST_BUFFER_DURATION (outbuf) = next_time - src->running_time;
|
||||||
|
|
||||||
|
src->running_time = next_time;
|
||||||
|
|
||||||
*buffer = outbuf;
|
*buffer = outbuf;
|
||||||
|
|
||||||
|
@ -479,11 +524,12 @@ not_negotiated:
|
||||||
}
|
}
|
||||||
no_buffer:
|
no_buffer:
|
||||||
{
|
{
|
||||||
|
GST_DEBUG_OBJECT (src, "could not allocate buffer, reason %s",
|
||||||
|
gst_flow_get_name (res));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
plugin_init (GstPlugin * plugin)
|
plugin_init (GstPlugin * plugin)
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,10 +65,6 @@ struct _GstVideoTestSrc {
|
||||||
gint64 timestamp_offset; /* base offset */
|
gint64 timestamp_offset; /* base offset */
|
||||||
GstClockTime running_time; /* total running time */
|
GstClockTime running_time; /* total running time */
|
||||||
gint64 n_frames; /* total frames sent */
|
gint64 n_frames; /* total frames sent */
|
||||||
gint64 segment_start_frame;
|
|
||||||
gint64 segment_end_frame;
|
|
||||||
gboolean segment;
|
|
||||||
GstClockID clock_id;
|
|
||||||
|
|
||||||
void (*make_image) (GstVideoTestSrc *v, unsigned char *dest, int w, int h);
|
void (*make_image) (GstVideoTestSrc *v, unsigned char *dest, int w, int h);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue