History

Move find_info_tag to lavu and add av_ prefix to it

Anton Khirnov committed 15 years ago

Commit 1b981071 parent 9c9912b10 files · +85 −62Browse files

Unified · Split

10 files
  1. ffserver.c +3 −3
  2. libavformat/avformat.h +4 −5
  3. libavformat/rtpproto.c +8 −7
  4. libavformat/sapenc.c +5 −4
  5. libavformat/sdp.c +2 −1
  6. libavformat/udp.c +8 −7
  7. libavformat/utils.c +5 −35
  8. libavformat/version.h +3 −0
  9. libavutil/parseutils.c +39 −0
  10. libavutil/parseutils.h +8 −0
ffserver.c+3−3
@@ -2135,10 +2135,10 @@ static int open_input_stream(HTTPContext *c, const char *info) · 2134 unmodified lines
21352135 strcpy(input_filename, c->stream->feed->feed_filename);
21362136 buf_size = FFM_PACKET_SIZE;
21372137 /* 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)) {
21392139 if ((ret = av_parse_time(&stream_pos, buf, 0)) < 0)
21402140 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)) {
21422142 int prebuffer = strtol(buf, 0, 10);
21432143 stream_pos = av_gettime() - prebuffer * (int64_t)1000000;
21442144 } else
@@ -2147,7 +2147,7 @@ static int open_input_stream(HTTPContext *c, const char *info) · 2 unmodified lines
21472147 strcpy(input_filename, c->stream->feed_filename);
21482148 buf_size = 0;
21492149 /* 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)) {
21512151 if ((ret = av_parse_time(&stream_pos, buf, 1)) < 0)
21522152 return ret;
21532153 } else
libavformat/avformat.h+4−5
@@ -1501,13 +1501,12 @@ int64_t ffm_read_write_index(int fd); · 1500 unmodified lines
15011501 int ffm_write_write_index(int fd, int64_t pos);
15021502 void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
15031503
1504+#if FF_API_FIND_INFO_TAG
15041505 /**
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.
15091507 */
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
15111510
15121511 /**
15131512 * Return in 'buf' the path with '%d' replaced by a number.
libavformat/rtpproto.c+8−7
@@ -24,6 +24,7 @@ · 23 unmodified lines
2424 * RTP protocol
2525 */
2626
27+#include "libavutil/parseutils.h"
2728 #include "libavutil/avstring.h"
2829 #include "avformat.h"
2930 #include "rtpdec.h"
@@ -161,25 +162,25 @@ static int rtp_open(URLContext *h, const char *uri, int flags) · 131 unmodified lines
161162
162163 p = strchr(uri, '?');
163164 if (p) {
164− if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
165+ if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) {
165166 ttl = strtol(buf, NULL, 10);
166167 }
167− if (find_info_tag(buf, sizeof(buf), "rtcpport", p)) {
168+ if (av_find_info_tag(buf, sizeof(buf), "rtcpport", p)) {
168169 rtcp_port = strtol(buf, NULL, 10);
169170 }
170− if (find_info_tag(buf, sizeof(buf), "localport", p)) {
171+ if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {
171172 local_rtp_port = strtol(buf, NULL, 10);
172173 }
173− if (find_info_tag(buf, sizeof(buf), "localrtpport", p)) {
174+ if (av_find_info_tag(buf, sizeof(buf), "localrtpport", p)) {
174175 local_rtp_port = strtol(buf, NULL, 10);
175176 }
176− if (find_info_tag(buf, sizeof(buf), "localrtcpport", p)) {
177+ if (av_find_info_tag(buf, sizeof(buf), "localrtcpport", p)) {
177178 local_rtcp_port = strtol(buf, NULL, 10);
178179 }
179− if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
180+ if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
180181 max_packet_size = strtol(buf, NULL, 10);
181182 }
182− if (find_info_tag(buf, sizeof(buf), "connect", p)) {
183+ if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
183184 connect = strtol(buf, NULL, 10);
184185 }
185186 }
libavformat/sapenc.c+5−4
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 */
2121
2222 #include "avformat.h"
23+#include "libavutil/parseutils.h"
2324 #include "libavutil/random_seed.h"
2425 #include "libavutil/avstring.h"
2526 #include "libavutil/intreadwrite.h"
@@ -87,16 +88,16 @@ static int sap_write_header(AVFormatContext *s) · 61 unmodified lines
8788 option_list = strrchr(path, '?');
8889 if (option_list) {
8990 char buf[50];
90− if (find_info_tag(buf, sizeof(buf), "announce_port", option_list)) {
91+ if (av_find_info_tag(buf, sizeof(buf), "announce_port", option_list)) {
9192 port = strtol(buf, NULL, 10);
9293 }
93− if (find_info_tag(buf, sizeof(buf), "same_port", option_list)) {
94+ if (av_find_info_tag(buf, sizeof(buf), "same_port", option_list)) {
9495 same_port = strtol(buf, NULL, 10);
9596 }
96− if (find_info_tag(buf, sizeof(buf), "ttl", option_list)) {
97+ if (av_find_info_tag(buf, sizeof(buf), "ttl", option_list)) {
9798 ttl = strtol(buf, NULL, 10);
9899 }
99− if (find_info_tag(buf, sizeof(buf), "announce_addr", option_list)) {
100+ if (av_find_info_tag(buf, sizeof(buf), "announce_addr", option_list)) {
100101 av_strlcpy(announce_addr, buf, sizeof(announce_addr));
101102 }
102103 }
libavformat/sdp.c+2−1
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include <string.h>
2222 #include "libavutil/avstring.h"
2323 #include "libavutil/base64.h"
24+#include "libavutil/parseutils.h"
2425 #include "libavcodec/xiph.h"
2526 #include "avformat.h"
2627 #include "internal.h"
@@ -136,7 +137,7 @@ static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url) · 109 unmodified lines
136137 if (p) {
137138 char buff[64];
138139
139− if (find_info_tag(buff, sizeof(buff), "ttl", p)) {
140+ if (av_find_info_tag(buff, sizeof(buff), "ttl", p)) {
140141 *ttl = strtol(buff, NULL, 10);
141142 } else {
142143 *ttl = 5;
libavformat/udp.c+8−7
@@ -27,6 +27,7 @@ · 26 unmodified lines
2727 #define _BSD_SOURCE /* Needed for using struct ip_mreq with recent glibc */
2828 #define _DARWIN_C_SOURCE /* Needed for using IP_MULTICAST_TTL on OS X */
2929 #include "avformat.h"
30+#include "libavutil/parseutils.h"
3031 #include <unistd.h>
3132 #include "internal.h"
3233 #include "network.h"
@@ -259,7 +260,7 @@ int udp_set_remote_url(URLContext *h, const char *uri) · 226 unmodified lines
259260 s->is_multicast = ff_is_multicast_address((struct sockaddr*) &s->dest_addr);
260261 p = strchr(uri, '?');
261262 if (p) {
262− if (find_info_tag(buf, sizeof(buf), "connect", p)) {
263+ if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
263264 int was_connected = s->is_connected;
264265 s->is_connected = strtol(buf, NULL, 10);
265266 if (s->is_connected && !was_connected) {
@@ -330,7 +331,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 64 unmodified lines
330331
331332 p = strchr(uri, '?');
332333 if (p) {
333− if (find_info_tag(buf, sizeof(buf), "reuse", p)) {
334+ if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) {
334335 const char *endptr=NULL;
335336 s->reuse_socket = strtol(buf, &endptr, 10);
336337 /* 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) · 1 unmodified line
338339 s->reuse_socket = 1;
339340 reuse_specified = 1;
340341 }
341− if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
342+ if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) {
342343 s->ttl = strtol(buf, NULL, 10);
343344 }
344− if (find_info_tag(buf, sizeof(buf), "localport", p)) {
345+ if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {
345346 s->local_port = strtol(buf, NULL, 10);
346347 }
347− if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
348+ if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
348349 h->max_packet_size = strtol(buf, NULL, 10);
349350 }
350− if (find_info_tag(buf, sizeof(buf), "buffer_size", p)) {
351+ if (av_find_info_tag(buf, sizeof(buf), "buffer_size", p)) {
351352 s->buffer_size = strtol(buf, NULL, 10);
352353 }
353− if (find_info_tag(buf, sizeof(buf), "connect", p)) {
354+ if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
354355 s->is_connected = strtol(buf, NULL, 10);
355356 }
356357 }
libavformat/utils.c+5−35
@@ -3391,44 +3391,14 @@ int64_t parse_date(const char *timestr, int duration) · 3390 unmodified lines
33913391 }
33923392 #endif
33933393
3394+#if FF_API_FIND_INFO_TAG
3395+#include "libavutil/parseutils.h"
3396+
33943397 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
33953398 {
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);
34313400 }
3401+#endif
34323402
34333403 int av_get_frame_filename(char *buf, int buf_size,
34343404 const char *path, int number)
libavformat/version.h+3−0
@@ -98,5 +98,8 @@ · 97 unmodified lines
9898 #ifndef FF_API_PARSE_DATE
9999 #define FF_API_PARSE_DATE (LIBAVFORMAT_VERSION_MAJOR < 54)
100100 #endif
101+#ifndef FF_API_FIND_INFO_TAG
102+#define FF_API_FIND_INFO_TAG (LIBAVFORMAT_VERSION_MAJOR < 54)
103+#endif
101104
102105 #endif //AVFORMAT_VERSION_H
libavutil/parseutils.c+39−0
@@ -608,6 +608,45 @@ int av_parse_time(int64_t *timeval, const char *datestr, int duration) · 607 unmodified lines
608608 return 0;
609609 }
610610
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+
611650 #ifdef TEST
612651
613652 #undef printf
libavutil/parseutils.h+8−0
@@ -106,4 +106,12 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, · 105 unmodified lines
106106 */
107107 int av_parse_time(int64_t *timeval, const char *timestr, int duration);
108108
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+
109117 #endif /* AVUTIL_PARSEUTILS_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t