From 155369d80cc06941919232746c83f3f68d742cb7 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sun, 22 Dec 2002 14:03:09 +0000 Subject: [PATCH] Added pad_query with percent format on filesrc and some constants Original commit message from CVS: Added pad_query with percent format on filesrc and some constants --- gst/elements/gstfilesrc.c | 14 +++++++++++--- gst/gstformat.h | 4 ++++ plugins/elements/gstfilesrc.c | 14 +++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/gst/elements/gstfilesrc.c b/gst/elements/gstfilesrc.c index d20176c..c9e0772 100644 --- a/gst/elements/gstfilesrc.c +++ b/gst/elements/gstfilesrc.c @@ -745,10 +745,18 @@ gst_filesrc_srcpad_query (GstPad *pad, GstPadQueryType type, *value = src->filelen; break; case GST_PAD_QUERY_POSITION: - if (*format != GST_FORMAT_BYTES) { - return FALSE; + switch (*format) { + case GST_FORMAT_BYTES: + *value = src->curoffset; + break; + case GST_FORMAT_PERCENT: + if (src->filelen == 0) + return FALSE; + *value = src->curoffset * GST_FORMAT_PERCENT_MAX / src->filelen; + break; + default: + return FALSE; } - *value = src->curoffset; break; default: return FALSE; diff --git a/gst/gstformat.h b/gst/gstformat.h index f4fa251..429862f 100644 --- a/gst/gstformat.h +++ b/gst/gstformat.h @@ -40,6 +40,10 @@ typedef enum { GST_FORMAT_UNITS = 6 } GstFormat; +/* a percentage is always relative to 1000000 */ +#define GST_FORMAT_PERCENT_MAX 1000000LL +#define GST_FORMAT_PERCENT_SCALE 10000LL + typedef struct _GstFormatDefinition GstFormatDefinition; struct _GstFormatDefinition diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c index d20176c..c9e0772 100644 --- a/plugins/elements/gstfilesrc.c +++ b/plugins/elements/gstfilesrc.c @@ -745,10 +745,18 @@ gst_filesrc_srcpad_query (GstPad *pad, GstPadQueryType type, *value = src->filelen; break; case GST_PAD_QUERY_POSITION: - if (*format != GST_FORMAT_BYTES) { - return FALSE; + switch (*format) { + case GST_FORMAT_BYTES: + *value = src->curoffset; + break; + case GST_FORMAT_PERCENT: + if (src->filelen == 0) + return FALSE; + *value = src->curoffset * GST_FORMAT_PERCENT_MAX / src->filelen; + break; + default: + return FALSE; } - *value = src->curoffset; break; default: return FALSE; -- 2.7.4