flvdemux: Speedup GstIndex usage
authorEdward Hervey <bilboed@bilboed.com>
Sat, 13 Feb 2010 10:01:53 +0000 (11:01 +0100)
committerEdward Hervey <bilboed@bilboed.com>
Sat, 13 Feb 2010 13:57:59 +0000 (14:57 +0100)
Used the _add_associationv variant of GstIndex since we know how many
associations we're adding. Trims up to 50% from index generation time.

Note : It would be great if the index could be generated on the fly or
on request as opposed to being fully created at startup.

gst/flv/gstflvparse.c

index 43dc1eb..c62433f 100644 (file)
@@ -425,14 +425,20 @@ gst_flv_parse_tag_script (GstFLVDemux * demux, GstBuffer * buffer)
       /* If an index was found and we're in push mode, insert associations */
       for (i = 0; i < MIN (demux->times->len, demux->filepositions->len); i++) {
         guint64 time, fileposition;
+        static GstIndexAssociation associations[2];
 
         time = g_array_index (demux->times, gdouble, i) * GST_SECOND;
         fileposition = g_array_index (demux->filepositions, gdouble, i);
         GST_LOG_OBJECT (demux, "adding association %" GST_TIME_FORMAT "-> %"
             G_GUINT64_FORMAT, GST_TIME_ARGS (time), fileposition);
-        gst_index_add_association (demux->index, demux->index_id,
-            GST_ASSOCIATION_FLAG_KEY_UNIT, GST_FORMAT_TIME, time,
-            GST_FORMAT_BYTES, fileposition, NULL);
+        associations[0].format = GST_FORMAT_TIME;
+        associations[0].value = time;
+        associations[1].format = GST_FORMAT_BYTES;
+        associations[1].value = fileposition;
+
+        gst_index_add_associationv (demux->index, demux->index_id,
+            GST_ASSOCIATION_FLAG_KEY_UNIT, 2,
+            (const GstIndexAssociation *) &associations);
       }
       demux->indexed = TRUE;
     }
@@ -1237,12 +1243,19 @@ gst_flv_parse_tag_timestamp (GstFLVDemux * demux, GstBuffer * buffer,
 
   if (demux->index && !demux->indexed && (type == 9 || (type == 8
               && !demux->has_video))) {
+    static GstIndexAssociation associations[2];
     GST_LOG_OBJECT (demux,
         "adding association %" GST_TIME_FORMAT "-> %" G_GUINT64_FORMAT,
         GST_TIME_ARGS (ret), demux->offset);
-    gst_index_add_association (demux->index, demux->index_id,
+
+    associations[0].format = GST_FORMAT_TIME;
+    associations[0].value = ret;
+    associations[1].format = GST_FORMAT_BYTES;
+    associations[1].value = demux->offset;
+
+    gst_index_add_associationv (demux->index, demux->index_id,
         (keyframe) ? GST_ASSOCIATION_FLAG_KEY_UNIT : GST_ASSOCIATION_FLAG_NONE,
-        GST_FORMAT_TIME, ret, GST_FORMAT_BYTES, demux->offset, NULL);
+        2, (const GstIndexAssociation *) &associations);
   }
 
   if (demux->duration == GST_CLOCK_TIME_NONE || demux->duration < ret)