Added pad_query with percent format on filesrc and some constants
authorWim Taymans <wim.taymans@gmail.com>
Sun, 22 Dec 2002 14:03:09 +0000 (14:03 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Sun, 22 Dec 2002 14:03:09 +0000 (14:03 +0000)
Original commit message from CVS:
Added pad_query with percent format on filesrc and some constants

gst/elements/gstfilesrc.c
gst/gstformat.h
plugins/elements/gstfilesrc.c

index d20176c..c9e0772 100644 (file)
@@ -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;
index f4fa251..429862f 100644 (file)
@@ -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 
index d20176c..c9e0772 100644 (file)
@@ -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;