Browse code

add ff_find_stream_index

Originally committed as revision 26092 to svn://svn.ffmpeg.org/ffmpeg/trunk

Peter Ross authored on 2010/12/26 10:24:51
Showing 3 changed files
... ...
@@ -21,6 +21,7 @@
21 21
 
22 22
 #include "libavutil/common.h"
23 23
 #include "avformat.h"
24
+#include "internal.h"
24 25
 #include "gxf.h"
25 26
 
26 27
 struct gxf_stream_info {
... ...
@@ -77,10 +78,9 @@ static int gxf_probe(AVProbeData *p) {
77 77
 static int get_sindex(AVFormatContext *s, int id, int format) {
78 78
     int i;
79 79
     AVStream *st = NULL;
80
-    for (i = 0; i < s->nb_streams; i++) {
81
-        if (s->streams[i]->id == id)
82
-            return i;
83
-    }
80
+    i = ff_find_stream_index(s, id);
81
+    if (i >= 0)
82
+        return i;
84 83
     st = av_new_stream(s, id);
85 84
     if (!st)
86 85
         return AVERROR(ENOMEM);
... ...
@@ -220,4 +220,10 @@ typedef void (*ff_parse_key_val_cb)(void *context, const char *key,
220 220
 void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
221 221
                         void *context);
222 222
 
223
+/**
224
+ * Find stream index based on format-specific stream ID
225
+ * @return stream index, or < 0 on error
226
+ */
227
+int ff_find_stream_index(AVFormatContext *s, int id);
228
+
223 229
 #endif /* AVFORMAT_INTERNAL_H */
... ...
@@ -3806,3 +3806,12 @@ void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
3806 3806
     }
3807 3807
 }
3808 3808
 
3809
+int ff_find_stream_index(AVFormatContext *s, int id)
3810
+{
3811
+    int i;
3812
+    for (i = 0; i < s->nb_streams; i++) {
3813
+        if (s->streams[i]->id == id)
3814
+            return i;
3815
+    }
3816
+    return -1;
3817
+}