Browse code

Move find_info_tag to lavu and add av_ prefix to it

Signed-off-by: Janne Grunau <janne-ffmpeg@jannau.net>
(cherry picked from commit ab0287fcbdebc8ff416214535d7ee8424406990e)

Anton Khirnov authored on 2011/02/16 17:52:38
Showing 10 changed files
... ...
@@ -2135,10 +2135,10 @@ static int open_input_stream(HTTPContext *c, const char *info)
2135 2135
         strcpy(input_filename, c->stream->feed->feed_filename);
2136 2136
         buf_size = FFM_PACKET_SIZE;
2137 2137
         /* compute position (absolute time) */
2138
-        if (find_info_tag(buf, sizeof(buf), "date", info)) {
2138
+        if (av_find_info_tag(buf, sizeof(buf), "date", info)) {
2139 2139
             if ((ret = av_parse_time(&stream_pos, buf, 0)) < 0)
2140 2140
                 return ret;
2141
-        } else if (find_info_tag(buf, sizeof(buf), "buffer", info)) {
2141
+        } else if (av_find_info_tag(buf, sizeof(buf), "buffer", info)) {
2142 2142
             int prebuffer = strtol(buf, 0, 10);
2143 2143
             stream_pos = av_gettime() - prebuffer * (int64_t)1000000;
2144 2144
         } else
... ...
@@ -2147,7 +2147,7 @@ static int open_input_stream(HTTPContext *c, const char *info)
2147 2147
         strcpy(input_filename, c->stream->feed_filename);
2148 2148
         buf_size = 0;
2149 2149
         /* compute position (relative time) */
2150
-        if (find_info_tag(buf, sizeof(buf), "date", info)) {
2150
+        if (av_find_info_tag(buf, sizeof(buf), "date", info)) {
2151 2151
             if ((ret = av_parse_time(&stream_pos, buf, 1)) < 0)
2152 2152
                 return ret;
2153 2153
         } else
... ...
@@ -1501,13 +1501,12 @@ int64_t ffm_read_write_index(int fd);
1501 1501
 int ffm_write_write_index(int fd, int64_t pos);
1502 1502
 void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1503 1503
 
1504
+#if FF_API_FIND_INFO_TAG
1504 1505
 /**
1505
- * Attempt to find a specific tag in a URL.
1506
- *
1507
- * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1508
- * Return 1 if found.
1506
+ * @deprecated use av_find_info_tag in libavutil instead.
1509 1507
  */
1510
-int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1508
+attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1509
+#endif
1511 1510
 
1512 1511
 /**
1513 1512
  * Return in 'buf' the path with '%d' replaced by a number.
... ...
@@ -24,6 +24,7 @@
24 24
  * RTP protocol
25 25
  */
26 26
 
27
+#include "libavutil/parseutils.h"
27 28
 #include "libavutil/avstring.h"
28 29
 #include "avformat.h"
29 30
 #include "rtpdec.h"
... ...
@@ -161,25 +162,25 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
161 161
 
162 162
     p = strchr(uri, '?');
163 163
     if (p) {
164
-        if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
164
+        if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) {
165 165
             ttl = strtol(buf, NULL, 10);
166 166
         }
167
-        if (find_info_tag(buf, sizeof(buf), "rtcpport", p)) {
167
+        if (av_find_info_tag(buf, sizeof(buf), "rtcpport", p)) {
168 168
             rtcp_port = strtol(buf, NULL, 10);
169 169
         }
170
-        if (find_info_tag(buf, sizeof(buf), "localport", p)) {
170
+        if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {
171 171
             local_rtp_port = strtol(buf, NULL, 10);
172 172
         }
173
-        if (find_info_tag(buf, sizeof(buf), "localrtpport", p)) {
173
+        if (av_find_info_tag(buf, sizeof(buf), "localrtpport", p)) {
174 174
             local_rtp_port = strtol(buf, NULL, 10);
175 175
         }
176
-        if (find_info_tag(buf, sizeof(buf), "localrtcpport", p)) {
176
+        if (av_find_info_tag(buf, sizeof(buf), "localrtcpport", p)) {
177 177
             local_rtcp_port = strtol(buf, NULL, 10);
178 178
         }
179
-        if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
179
+        if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
180 180
             max_packet_size = strtol(buf, NULL, 10);
181 181
         }
182
-        if (find_info_tag(buf, sizeof(buf), "connect", p)) {
182
+        if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
183 183
             connect = strtol(buf, NULL, 10);
184 184
         }
185 185
     }
... ...
@@ -20,6 +20,7 @@
20 20
  */
21 21
 
22 22
 #include "avformat.h"
23
+#include "libavutil/parseutils.h"
23 24
 #include "libavutil/random_seed.h"
24 25
 #include "libavutil/avstring.h"
25 26
 #include "libavutil/intreadwrite.h"
... ...
@@ -87,16 +88,16 @@ static int sap_write_header(AVFormatContext *s)
87 87
     option_list = strrchr(path, '?');
88 88
     if (option_list) {
89 89
         char buf[50];
90
-        if (find_info_tag(buf, sizeof(buf), "announce_port", option_list)) {
90
+        if (av_find_info_tag(buf, sizeof(buf), "announce_port", option_list)) {
91 91
             port = strtol(buf, NULL, 10);
92 92
         }
93
-        if (find_info_tag(buf, sizeof(buf), "same_port", option_list)) {
93
+        if (av_find_info_tag(buf, sizeof(buf), "same_port", option_list)) {
94 94
             same_port = strtol(buf, NULL, 10);
95 95
         }
96
-        if (find_info_tag(buf, sizeof(buf), "ttl", option_list)) {
96
+        if (av_find_info_tag(buf, sizeof(buf), "ttl", option_list)) {
97 97
             ttl = strtol(buf, NULL, 10);
98 98
         }
99
-        if (find_info_tag(buf, sizeof(buf), "announce_addr", option_list)) {
99
+        if (av_find_info_tag(buf, sizeof(buf), "announce_addr", option_list)) {
100 100
             av_strlcpy(announce_addr, buf, sizeof(announce_addr));
101 101
         }
102 102
     }
... ...
@@ -21,6 +21,7 @@
21 21
 #include <string.h>
22 22
 #include "libavutil/avstring.h"
23 23
 #include "libavutil/base64.h"
24
+#include "libavutil/parseutils.h"
24 25
 #include "libavcodec/xiph.h"
25 26
 #include "avformat.h"
26 27
 #include "internal.h"
... ...
@@ -136,7 +137,7 @@ static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url)
136 136
     if (p) {
137 137
         char buff[64];
138 138
 
139
-        if (find_info_tag(buff, sizeof(buff), "ttl", p)) {
139
+        if (av_find_info_tag(buff, sizeof(buff), "ttl", p)) {
140 140
             *ttl = strtol(buff, NULL, 10);
141 141
         } else {
142 142
             *ttl = 5;
... ...
@@ -27,6 +27,7 @@
27 27
 #define _BSD_SOURCE     /* Needed for using struct ip_mreq with recent glibc */
28 28
 #define _DARWIN_C_SOURCE /* Needed for using IP_MULTICAST_TTL on OS X */
29 29
 #include "avformat.h"
30
+#include "libavutil/parseutils.h"
30 31
 #include <unistd.h>
31 32
 #include "internal.h"
32 33
 #include "network.h"
... ...
@@ -259,7 +260,7 @@ int udp_set_remote_url(URLContext *h, const char *uri)
259 259
     s->is_multicast = ff_is_multicast_address((struct sockaddr*) &s->dest_addr);
260 260
     p = strchr(uri, '?');
261 261
     if (p) {
262
-        if (find_info_tag(buf, sizeof(buf), "connect", p)) {
262
+        if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
263 263
             int was_connected = s->is_connected;
264 264
             s->is_connected = strtol(buf, NULL, 10);
265 265
             if (s->is_connected && !was_connected) {
... ...
@@ -330,7 +331,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
330 330
 
331 331
     p = strchr(uri, '?');
332 332
     if (p) {
333
-        if (find_info_tag(buf, sizeof(buf), "reuse", p)) {
333
+        if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) {
334 334
             const char *endptr=NULL;
335 335
             s->reuse_socket = strtol(buf, &endptr, 10);
336 336
             /* assume if no digits were found it is a request to enable it */
... ...
@@ -338,19 +339,19 @@ static int udp_open(URLContext *h, const char *uri, int flags)
338 338
                 s->reuse_socket = 1;
339 339
             reuse_specified = 1;
340 340
         }
341
-        if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
341
+        if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) {
342 342
             s->ttl = strtol(buf, NULL, 10);
343 343
         }
344
-        if (find_info_tag(buf, sizeof(buf), "localport", p)) {
344
+        if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {
345 345
             s->local_port = strtol(buf, NULL, 10);
346 346
         }
347
-        if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
347
+        if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
348 348
             h->max_packet_size = strtol(buf, NULL, 10);
349 349
         }
350
-        if (find_info_tag(buf, sizeof(buf), "buffer_size", p)) {
350
+        if (av_find_info_tag(buf, sizeof(buf), "buffer_size", p)) {
351 351
             s->buffer_size = strtol(buf, NULL, 10);
352 352
         }
353
-        if (find_info_tag(buf, sizeof(buf), "connect", p)) {
353
+        if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
354 354
             s->is_connected = strtol(buf, NULL, 10);
355 355
         }
356 356
     }
... ...
@@ -3391,44 +3391,14 @@ int64_t parse_date(const char *timestr, int duration)
3391 3391
 }
3392 3392
 #endif
3393 3393
 
3394
+#if FF_API_FIND_INFO_TAG
3395
+#include "libavutil/parseutils.h"
3396
+
3394 3397
 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
3395 3398
 {
3396
-    const char *p;
3397
-    char tag[128], *q;
3398
-
3399
-    p = info;
3400
-    if (*p == '?')
3401
-        p++;
3402
-    for(;;) {
3403
-        q = tag;
3404
-        while (*p != '\0' && *p != '=' && *p != '&') {
3405
-            if ((q - tag) < sizeof(tag) - 1)
3406
-                *q++ = *p;
3407
-            p++;
3408
-        }
3409
-        *q = '\0';
3410
-        q = arg;
3411
-        if (*p == '=') {
3412
-            p++;
3413
-            while (*p != '&' && *p != '\0') {
3414
-                if ((q - arg) < arg_size - 1) {
3415
-                    if (*p == '+')
3416
-                        *q++ = ' ';
3417
-                    else
3418
-                        *q++ = *p;
3419
-                }
3420
-                p++;
3421
-            }
3422
-        }
3423
-        *q = '\0';
3424
-        if (!strcmp(tag, tag1))
3425
-            return 1;
3426
-        if (*p != '&')
3427
-            break;
3428
-        p++;
3429
-    }
3430
-    return 0;
3399
+    return av_find_info_tag(arg, arg_size, tag1, info);
3431 3400
 }
3401
+#endif
3432 3402
 
3433 3403
 int av_get_frame_filename(char *buf, int buf_size,
3434 3404
                           const char *path, int number)
... ...
@@ -98,5 +98,8 @@
98 98
 #ifndef FF_API_PARSE_DATE
99 99
 #define FF_API_PARSE_DATE              (LIBAVFORMAT_VERSION_MAJOR < 54)
100 100
 #endif
101
+#ifndef FF_API_FIND_INFO_TAG
102
+#define FF_API_FIND_INFO_TAG           (LIBAVFORMAT_VERSION_MAJOR < 54)
103
+#endif
101 104
 
102 105
 #endif //AVFORMAT_VERSION_H
... ...
@@ -608,6 +608,45 @@ int av_parse_time(int64_t *timeval, const char *datestr, int duration)
608 608
     return 0;
609 609
 }
610 610
 
611
+int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
612
+{
613
+    const char *p;
614
+    char tag[128], *q;
615
+
616
+    p = info;
617
+    if (*p == '?')
618
+        p++;
619
+    for(;;) {
620
+        q = tag;
621
+        while (*p != '\0' && *p != '=' && *p != '&') {
622
+            if ((q - tag) < sizeof(tag) - 1)
623
+                *q++ = *p;
624
+            p++;
625
+        }
626
+        *q = '\0';
627
+        q = arg;
628
+        if (*p == '=') {
629
+            p++;
630
+            while (*p != '&' && *p != '\0') {
631
+                if ((q - arg) < arg_size - 1) {
632
+                    if (*p == '+')
633
+                        *q++ = ' ';
634
+                    else
635
+                        *q++ = *p;
636
+                }
637
+                p++;
638
+            }
639
+        }
640
+        *q = '\0';
641
+        if (!strcmp(tag, tag1))
642
+            return 1;
643
+        if (*p != '&')
644
+            break;
645
+        p++;
646
+    }
647
+    return 0;
648
+}
649
+
611 650
 #ifdef TEST
612 651
 
613 652
 #undef printf
... ...
@@ -106,4 +106,12 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
106 106
  */
107 107
 int av_parse_time(int64_t *timeval, const char *timestr, int duration);
108 108
 
109
+/**
110
+ * Attempt to find a specific tag in a URL.
111
+ *
112
+ * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
113
+ * Return 1 if found.
114
+ */
115
+int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
116
+
109 117
 #endif /* AVUTIL_PARSEUTILS_H */