Browse code

Add url_get_file_handle(), which is used to get the file descriptor associated with the I/O handle (e.g. the fd returned by open()). See "[RFC] rtsp.c EOF support" thread.

There were previously some URI-specific implementations of the same idea,
e.g. rtp_get_file_handles() and udp_get_file_handle(). All of these are
deprecated by this patch and will be removed at the next major API bump.

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

Ronald S. Bultje authored on 2009/03/04 02:04:51
Showing 9 changed files
... ...
@@ -206,6 +206,13 @@ int64_t url_filesize(URLContext *h)
206 206
     return size;
207 207
 }
208 208
 
209
+int url_get_file_handle(URLContext *h)
210
+{
211
+    if (!h->prot->url_get_file_handle)
212
+        return -1;
213
+    return h->prot->url_get_file_handle(h);
214
+}
215
+
209 216
 int url_get_max_packet_size(URLContext *h)
210 217
 {
211 218
     return h->max_packet_size;
... ...
@@ -78,6 +78,15 @@ int url_exist(const char *filename);
78 78
 int64_t url_filesize(URLContext *h);
79 79
 
80 80
 /**
81
+ * Return the file descriptor associated with this URL. For RTP, this
82
+ * will return only the RTP file descriptor, not the RTCP file descriptor.
83
+ * To get both, use rtp_get_file_handles().
84
+ *
85
+ * @return the file descriptor associated with this URL, or <0 on error.
86
+ */
87
+int url_get_file_handle(URLContext *h);
88
+
89
+/**
81 90
  * Return the maximum packet size associated to packetized file
82 91
  * handle. If the file is not packetized (stream like HTTP or file on
83 92
  * disk), then 0 is returned.
... ...
@@ -144,6 +153,7 @@ typedef struct URLProtocol {
144 144
     int (*url_read_pause)(URLContext *h, int pause);
145 145
     int64_t (*url_read_seek)(URLContext *h, int stream_index,
146 146
                              int64_t timestamp, int flags);
147
+    int (*url_get_file_handle)(URLContext *h);
147 148
 } URLProtocol;
148 149
 
149 150
 #if LIBAVFORMAT_VERSION_MAJOR < 53
... ...
@@ -389,6 +399,8 @@ void init_checksum(ByteIOContext *s,
389 389
 /* udp.c */
390 390
 int udp_set_remote_url(URLContext *h, const char *uri);
391 391
 int udp_get_local_port(URLContext *h);
392
+#if (LIBAVFORMAT_VERSION_MAJOR <= 52)
392 393
 int udp_get_file_handle(URLContext *h);
394
+#endif
393 395
 
394 396
 #endif /* AVFORMAT_AVIO_H */
... ...
@@ -82,6 +82,11 @@ static int file_close(URLContext *h)
82 82
     return close(fd);
83 83
 }
84 84
 
85
+static int file_get_handle(URLContext *h)
86
+{
87
+    return (int) h->priv_data;
88
+}
89
+
85 90
 URLProtocol file_protocol = {
86 91
     "file",
87 92
     file_open,
... ...
@@ -89,6 +94,7 @@ URLProtocol file_protocol = {
89 89
     file_write,
90 90
     file_seek,
91 91
     file_close,
92
+    .url_get_file_handle = file_get_handle,
92 93
 };
93 94
 
94 95
 /* pipe protocol */
... ...
@@ -120,4 +126,5 @@ URLProtocol pipe_protocol = {
120 120
     pipe_open,
121 121
     file_read,
122 122
     file_write,
123
+    .url_get_file_handle = file_get_handle,
123 124
 };
... ...
@@ -345,6 +345,13 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence)
345 345
     return off;
346 346
 }
347 347
 
348
+static int
349
+http_get_file_handle(URLContext *h)
350
+{
351
+    HTTPContext *s = h->priv_data;
352
+    return url_get_file_handle(s->hd);
353
+}
354
+
348 355
 URLProtocol http_protocol = {
349 356
     "http",
350 357
     http_open,
... ...
@@ -352,4 +359,5 @@ URLProtocol http_protocol = {
352 352
     http_write,
353 353
     http_seek,
354 354
     http_close,
355
+    .url_get_file_handle = http_get_file_handle,
355 356
 };
... ...
@@ -69,7 +69,9 @@ void rtp_parse_close(RTPDemuxContext *s);
69 69
 
70 70
 int rtp_get_local_port(URLContext *h);
71 71
 int rtp_set_remote_url(URLContext *h, const char *uri);
72
+#if (LIBAVFORMAT_VERSION_MAJOR <= 52)
72 73
 void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd);
74
+#endif
73 75
 
74 76
 /**
75 77
  * some rtp servers assume client is dead if they don't hear from them...
... ...
@@ -169,8 +169,8 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
169 169
 
170 170
     /* just to ease handle access. XXX: need to suppress direct handle
171 171
        access */
172
-    s->rtp_fd = udp_get_file_handle(s->rtp_hd);
173
-    s->rtcp_fd = udp_get_file_handle(s->rtcp_hd);
172
+    s->rtp_fd = url_get_file_handle(s->rtp_hd);
173
+    s->rtcp_fd = url_get_file_handle(s->rtcp_hd);
174 174
 
175 175
     h->max_packet_size = url_get_max_packet_size(s->rtp_hd);
176 176
     h->is_streamed = 1;
... ...
@@ -296,6 +296,7 @@ int rtp_get_local_port(URLContext *h)
296 296
     return udp_get_local_port(s->rtp_hd);
297 297
 }
298 298
 
299
+#if (LIBAVFORMAT_VERSION_MAJOR <= 52)
299 300
 /**
300 301
  * Return the rtp and rtcp file handles for select() usage to wait for
301 302
  * several RTP streams at the same time.
... ...
@@ -309,6 +310,13 @@ void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd)
309 309
     *prtp_fd = s->rtp_fd;
310 310
     *prtcp_fd = s->rtcp_fd;
311 311
 }
312
+#endif
313
+
314
+static int rtp_get_file_handle(URLContext *h)
315
+{
316
+    RTPContext *s = h->priv_data;
317
+    return s->rtp_fd;
318
+}
312 319
 
313 320
 URLProtocol rtp_protocol = {
314 321
     "rtp",
... ...
@@ -317,4 +325,5 @@ URLProtocol rtp_protocol = {
317 317
     rtp_write,
318 318
     NULL, /* seek */
319 319
     rtp_close,
320
+    .url_get_file_handle = rtp_get_file_handle,
320 321
 };
... ...
@@ -1305,7 +1305,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
1305 1305
     RTSPState *rt = s->priv_data;
1306 1306
     RTSPStream *rtsp_st;
1307 1307
     fd_set rfds;
1308
-    int fd1, fd2, fd_max, n, i, ret;
1308
+    int fd1, fd_max, n, i, ret;
1309 1309
     struct timeval tv;
1310 1310
 
1311 1311
     for(;;) {
... ...
@@ -1318,7 +1318,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
1318 1318
             if (rtsp_st->rtp_handle) {
1319 1319
                 /* currently, we cannot probe RTCP handle because of
1320 1320
                  * blocking restrictions */
1321
-                rtp_get_file_handles(rtsp_st->rtp_handle, &fd1, &fd2);
1321
+                fd1 = url_get_file_handle(rtsp_st->rtp_handle);
1322 1322
                 if (fd1 > fd_max)
1323 1323
                     fd_max = fd1;
1324 1324
                 FD_SET(fd1, &rfds);
... ...
@@ -1331,7 +1331,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
1331 1331
             for(i = 0; i < rt->nb_rtsp_streams; i++) {
1332 1332
                 rtsp_st = rt->rtsp_streams[i];
1333 1333
                 if (rtsp_st->rtp_handle) {
1334
-                    rtp_get_file_handles(rtsp_st->rtp_handle, &fd1, &fd2);
1334
+                    fd1 = url_get_file_handle(rtsp_st->rtp_handle);
1335 1335
                     if (FD_ISSET(fd1, &rfds)) {
1336 1336
                         ret = url_read(rtsp_st->rtp_handle, buf, buf_size);
1337 1337
                         if (ret > 0) {
... ...
@@ -181,6 +181,12 @@ static int tcp_close(URLContext *h)
181 181
     return 0;
182 182
 }
183 183
 
184
+static int tcp_get_file_handle(URLContext *h)
185
+{
186
+    TCPContext *s = h->priv_data;
187
+    return s->fd;
188
+}
189
+
184 190
 URLProtocol tcp_protocol = {
185 191
     "tcp",
186 192
     tcp_open,
... ...
@@ -188,4 +194,5 @@ URLProtocol tcp_protocol = {
188 188
     tcp_write,
189 189
     NULL, /* seek */
190 190
     tcp_close,
191
+    .url_get_file_handle = tcp_get_file_handle,
191 192
 };
... ...
@@ -326,6 +326,9 @@ int udp_get_local_port(URLContext *h)
326 326
  * streams at the same time.
327 327
  * @param h media file context
328 328
  */
329
+#if (LIBAVFORMAT_VERSION_MAJOR >= 53)
330
+static
331
+#endif
329 332
 int udp_get_file_handle(URLContext *h)
330 333
 {
331 334
     UDPContext *s = h->priv_data;
... ...
@@ -528,4 +531,5 @@ URLProtocol udp_protocol = {
528 528
     udp_write,
529 529
     NULL, /* seek */
530 530
     udp_close,
531
+    .url_get_file_handle = udp_get_file_handle,
531 532
 };