gst/elements/gstfilesrc.c: make seek events to before start/after end of file not fail, but seek to start/end instead

Original commit message from CVS:
* gst/elements/gstfilesrc.c: (gst_filesrc_open_file),
(gst_filesrc_srcpad_event):
make seek events to before start/after end of file not fail, but
seek to start/end instead
* testsuite/caps/fraction-convert.c: (check_from_double_convert):
add more output
This commit is contained in:
Benjamin Otte 2004-07-29 15:34:25 +00:00
parent 2bd5f3ad46
commit 6788d167d6
5 changed files with 61 additions and 34 deletions

View file

@ -1,3 +1,12 @@
2004-07-29 Benjamin Otte <otte@gnome.org>
* gst/elements/gstfilesrc.c: (gst_filesrc_open_file),
(gst_filesrc_srcpad_event):
make seek events to before start/after end of file not fail, but
seek to start/end instead
* testsuite/caps/fraction-convert.c: (check_from_double_convert):
add more output
2004-07-29 Benjamin Otte <otte@gnome.org>
* gst/gstpad.c: (gst_pad_set_explicit_caps):

View file

@ -55,6 +55,7 @@
#define O_BINARY (0)
#endif
/**********************************************************************
* GStreamer Default File Source
* Theory of Operation
@ -922,7 +923,8 @@ gst_filesrc_srcpad_event (GstPad * pad, GstEvent * event)
{
gint64 offset;
if (GST_EVENT_SEEK_FORMAT (event) != GST_FORMAT_BYTES) {
if (GST_EVENT_SEEK_FORMAT (event) != GST_FORMAT_BYTES &&
GST_EVENT_SEEK_FORMAT (event) != GST_FORMAT_DEFAULT) {
goto error;
}
if (!src->is_regular) {
@ -934,32 +936,39 @@ gst_filesrc_srcpad_event (GstPad * pad, GstEvent * event)
switch (GST_EVENT_SEEK_METHOD (event)) {
case GST_SEEK_METHOD_SET:
if (offset < 0 ||
(offset > src->filelen && (!gst_filesrc_check_filesize (src)
|| offset > src->filelen))) {
if (offset < 0) {
goto error;
} else if (offset > src->filelen && (!gst_filesrc_check_filesize (src)
|| offset > src->filelen)) {
src->curoffset = src->filelen;
} else {
src->curoffset = offset;
}
src->curoffset = offset;
GST_DEBUG_OBJECT (src, "seek set pending to %" G_GINT64_FORMAT,
src->curoffset);
break;
case GST_SEEK_METHOD_CUR:
if (offset + src->curoffset > src->filelen)
if (!gst_filesrc_check_filesize (src)
|| offset + src->curoffset > src->filelen)
goto error;
src->curoffset += offset;
if (offset + src->curoffset > src->filelen &&
(!gst_filesrc_check_filesize (src)
|| offset + src->curoffset > src->filelen)) {
src->curoffset = src->filelen;
} else if (offset + src->curoffset < 0) {
src->curoffset = 0;
} else {
src->curoffset += offset;
}
GST_DEBUG_OBJECT (src, "seek cur pending to %" G_GINT64_FORMAT,
src->curoffset);
break;
case GST_SEEK_METHOD_END:
if (ABS (offset) > src->filelen) {
if (!gst_filesrc_check_filesize (src)
|| ABS (offset) > src->filelen)
goto error;
if (offset > 0) {
goto error;
} else if (offset > src->filelen && (!gst_filesrc_check_filesize (src)
|| offset > src->filelen)) {
src->curoffset = 0;
} else {
src->curoffset = src->filelen + offset;
}
src->curoffset = src->filelen - ABS (offset);
GST_DEBUG_OBJECT (src, "seek end pending to %" G_GINT64_FORMAT,
src->curoffset);
break;

View file

@ -55,6 +55,7 @@
#define O_BINARY (0)
#endif
/**********************************************************************
* GStreamer Default File Source
* Theory of Operation
@ -922,7 +923,8 @@ gst_filesrc_srcpad_event (GstPad * pad, GstEvent * event)
{
gint64 offset;
if (GST_EVENT_SEEK_FORMAT (event) != GST_FORMAT_BYTES) {
if (GST_EVENT_SEEK_FORMAT (event) != GST_FORMAT_BYTES &&
GST_EVENT_SEEK_FORMAT (event) != GST_FORMAT_DEFAULT) {
goto error;
}
if (!src->is_regular) {
@ -934,32 +936,39 @@ gst_filesrc_srcpad_event (GstPad * pad, GstEvent * event)
switch (GST_EVENT_SEEK_METHOD (event)) {
case GST_SEEK_METHOD_SET:
if (offset < 0 ||
(offset > src->filelen && (!gst_filesrc_check_filesize (src)
|| offset > src->filelen))) {
if (offset < 0) {
goto error;
} else if (offset > src->filelen && (!gst_filesrc_check_filesize (src)
|| offset > src->filelen)) {
src->curoffset = src->filelen;
} else {
src->curoffset = offset;
}
src->curoffset = offset;
GST_DEBUG_OBJECT (src, "seek set pending to %" G_GINT64_FORMAT,
src->curoffset);
break;
case GST_SEEK_METHOD_CUR:
if (offset + src->curoffset > src->filelen)
if (!gst_filesrc_check_filesize (src)
|| offset + src->curoffset > src->filelen)
goto error;
src->curoffset += offset;
if (offset + src->curoffset > src->filelen &&
(!gst_filesrc_check_filesize (src)
|| offset + src->curoffset > src->filelen)) {
src->curoffset = src->filelen;
} else if (offset + src->curoffset < 0) {
src->curoffset = 0;
} else {
src->curoffset += offset;
}
GST_DEBUG_OBJECT (src, "seek cur pending to %" G_GINT64_FORMAT,
src->curoffset);
break;
case GST_SEEK_METHOD_END:
if (ABS (offset) > src->filelen) {
if (!gst_filesrc_check_filesize (src)
|| ABS (offset) > src->filelen)
goto error;
if (offset > 0) {
goto error;
} else if (offset > src->filelen && (!gst_filesrc_check_filesize (src)
|| offset > src->filelen)) {
src->curoffset = 0;
} else {
src->curoffset = src->filelen + offset;
}
src->curoffset = src->filelen - ABS (offset);
GST_DEBUG_OBJECT (src, "seek end pending to %" G_GINT64_FORMAT,
src->curoffset);
break;

View file

@ -36,8 +36,8 @@ check_from_double_convert (gdouble value, gint nom, gint denom, gdouble prec)
g_value_set_double (&value1, value);
g_value_transform (&value1, &value2);
g_print ("%s = %s\n",
gst_value_serialize (&value1), gst_value_serialize (&value2));
g_print ("%s = %s ? (expected: %d/%d )\n",
gst_value_serialize (&value1), gst_value_serialize (&value2), nom, denom);
g_assert (gst_value_get_fraction_numerator (&value2) == nom);
g_assert (gst_value_get_fraction_denominator (&value2) == denom);
g_value_transform (&value2, &value1);

View file

@ -36,8 +36,8 @@ check_from_double_convert (gdouble value, gint nom, gint denom, gdouble prec)
g_value_set_double (&value1, value);
g_value_transform (&value1, &value2);
g_print ("%s = %s\n",
gst_value_serialize (&value1), gst_value_serialize (&value2));
g_print ("%s = %s ? (expected: %d/%d )\n",
gst_value_serialize (&value1), gst_value_serialize (&value2), nom, denom);
g_assert (gst_value_get_fraction_numerator (&value2) == nom);
g_assert (gst_value_get_fraction_denominator (&value2) == denom);
g_value_transform (&value2, &value1);