[FFmpeg-cvslog] r17779 - in trunk/libavformat: avio.c avio.h file.c http.c rtpdec.h rtpproto.c rtsp.c tcp.c udp.c

rbultje subversion
Tue Mar 3 18:04:51 CET 2009


Author: rbultje
Date: Tue Mar  3 18:04:51 2009
New Revision: 17779

Log:
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.

Modified:
   trunk/libavformat/avio.c
   trunk/libavformat/avio.h
   trunk/libavformat/file.c
   trunk/libavformat/http.c
   trunk/libavformat/rtpdec.h
   trunk/libavformat/rtpproto.c
   trunk/libavformat/rtsp.c
   trunk/libavformat/tcp.c
   trunk/libavformat/udp.c

Modified: trunk/libavformat/avio.c
==============================================================================
--- trunk/libavformat/avio.c	Tue Mar  3 17:53:04 2009	(r17778)
+++ trunk/libavformat/avio.c	Tue Mar  3 18:04:51 2009	(r17779)
@@ -206,6 +206,13 @@ int64_t url_filesize(URLContext *h)
     return size;
 }
 
+int url_get_file_handle(URLContext *h)
+{
+    if (!h->prot->url_get_file_handle)
+        return -1;
+    return h->prot->url_get_file_handle(h);
+}
+
 int url_get_max_packet_size(URLContext *h)
 {
     return h->max_packet_size;

Modified: trunk/libavformat/avio.h
==============================================================================
--- trunk/libavformat/avio.h	Tue Mar  3 17:53:04 2009	(r17778)
+++ trunk/libavformat/avio.h	Tue Mar  3 18:04:51 2009	(r17779)
@@ -78,6 +78,15 @@ int url_exist(const char *filename);
 int64_t url_filesize(URLContext *h);
 
 /**
+ * Return the file descriptor associated with this URL. For RTP, this
+ * will return only the RTP file descriptor, not the RTCP file descriptor.
+ * To get both, use rtp_get_file_handles().
+ *
+ * @return the file descriptor associated with this URL, or <0 on error.
+ */
+int url_get_file_handle(URLContext *h);
+
+/**
  * Return the maximum packet size associated to packetized file
  * handle. If the file is not packetized (stream like HTTP or file on
  * disk), then 0 is returned.
@@ -144,6 +153,7 @@ typedef struct URLProtocol {
     int (*url_read_pause)(URLContext *h, int pause);
     int64_t (*url_read_seek)(URLContext *h, int stream_index,
                              int64_t timestamp, int flags);
+    int (*url_get_file_handle)(URLContext *h);
 } URLProtocol;
 
 #if LIBAVFORMAT_VERSION_MAJOR < 53
@@ -389,6 +399,8 @@ void init_checksum(ByteIOContext *s,
 /* udp.c */
 int udp_set_remote_url(URLContext *h, const char *uri);
 int udp_get_local_port(URLContext *h);
+#if (LIBAVFORMAT_VERSION_MAJOR <= 52)
 int udp_get_file_handle(URLContext *h);
+#endif
 
 #endif /* AVFORMAT_AVIO_H */

Modified: trunk/libavformat/file.c
==============================================================================
--- trunk/libavformat/file.c	Tue Mar  3 17:53:04 2009	(r17778)
+++ trunk/libavformat/file.c	Tue Mar  3 18:04:51 2009	(r17779)
@@ -82,6 +82,11 @@ static int file_close(URLContext *h)
     return close(fd);
 }
 
+static int file_get_handle(URLContext *h)
+{
+    return (int) h->priv_data;
+}
+
 URLProtocol file_protocol = {
     "file",
     file_open,
@@ -89,6 +94,7 @@ URLProtocol file_protocol = {
     file_write,
     file_seek,
     file_close,
+    .url_get_file_handle = file_get_handle,
 };
 
 /* pipe protocol */
@@ -120,4 +126,5 @@ URLProtocol pipe_protocol = {
     pipe_open,
     file_read,
     file_write,
+    .url_get_file_handle = file_get_handle,
 };

Modified: trunk/libavformat/http.c
==============================================================================
--- trunk/libavformat/http.c	Tue Mar  3 17:53:04 2009	(r17778)
+++ trunk/libavformat/http.c	Tue Mar  3 18:04:51 2009	(r17779)
@@ -345,6 +345,13 @@ static int64_t http_seek(URLContext *h, 
     return off;
 }
 
+static int
+http_get_file_handle(URLContext *h)
+{
+    HTTPContext *s = h->priv_data;
+    return url_get_file_handle(s->hd);
+}
+
 URLProtocol http_protocol = {
     "http",
     http_open,
@@ -352,4 +359,5 @@ URLProtocol http_protocol = {
     http_write,
     http_seek,
     http_close,
+    .url_get_file_handle = http_get_file_handle,
 };

Modified: trunk/libavformat/rtpdec.h
==============================================================================
--- trunk/libavformat/rtpdec.h	Tue Mar  3 17:53:04 2009	(r17778)
+++ trunk/libavformat/rtpdec.h	Tue Mar  3 18:04:51 2009	(r17779)
@@ -69,7 +69,9 @@ void rtp_parse_close(RTPDemuxContext *s)
 
 int rtp_get_local_port(URLContext *h);
 int rtp_set_remote_url(URLContext *h, const char *uri);
+#if (LIBAVFORMAT_VERSION_MAJOR <= 52)
 void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd);
+#endif
 
 /**
  * some rtp servers assume client is dead if they don't hear from them...

Modified: trunk/libavformat/rtpproto.c
==============================================================================
--- trunk/libavformat/rtpproto.c	Tue Mar  3 17:53:04 2009	(r17778)
+++ trunk/libavformat/rtpproto.c	Tue Mar  3 18:04:51 2009	(r17779)
@@ -169,8 +169,8 @@ static int rtp_open(URLContext *h, const
 
     /* just to ease handle access. XXX: need to suppress direct handle
        access */
-    s->rtp_fd = udp_get_file_handle(s->rtp_hd);
-    s->rtcp_fd = udp_get_file_handle(s->rtcp_hd);
+    s->rtp_fd = url_get_file_handle(s->rtp_hd);
+    s->rtcp_fd = url_get_file_handle(s->rtcp_hd);
 
     h->max_packet_size = url_get_max_packet_size(s->rtp_hd);
     h->is_streamed = 1;
@@ -296,6 +296,7 @@ int rtp_get_local_port(URLContext *h)
     return udp_get_local_port(s->rtp_hd);
 }
 
+#if (LIBAVFORMAT_VERSION_MAJOR <= 52)
 /**
  * Return the rtp and rtcp file handles for select() usage to wait for
  * several RTP streams at the same time.
@@ -309,6 +310,13 @@ void rtp_get_file_handles(URLContext *h,
     *prtp_fd = s->rtp_fd;
     *prtcp_fd = s->rtcp_fd;
 }
+#endif
+
+static int rtp_get_file_handle(URLContext *h)
+{
+    RTPContext *s = h->priv_data;
+    return s->rtp_fd;
+}
 
 URLProtocol rtp_protocol = {
     "rtp",
@@ -317,4 +325,5 @@ URLProtocol rtp_protocol = {
     rtp_write,
     NULL, /* seek */
     rtp_close,
+    .url_get_file_handle = rtp_get_file_handle,
 };

Modified: trunk/libavformat/rtsp.c
==============================================================================
--- trunk/libavformat/rtsp.c	Tue Mar  3 17:53:04 2009	(r17778)
+++ trunk/libavformat/rtsp.c	Tue Mar  3 18:04:51 2009	(r17779)
@@ -1305,7 +1305,7 @@ static int udp_read_packet(AVFormatConte
     RTSPState *rt = s->priv_data;
     RTSPStream *rtsp_st;
     fd_set rfds;
-    int fd1, fd2, fd_max, n, i, ret;
+    int fd1, fd_max, n, i, ret;
     struct timeval tv;
 
     for(;;) {
@@ -1318,7 +1318,7 @@ static int udp_read_packet(AVFormatConte
             if (rtsp_st->rtp_handle) {
                 /* currently, we cannot probe RTCP handle because of
                  * blocking restrictions */
-                rtp_get_file_handles(rtsp_st->rtp_handle, &fd1, &fd2);
+                fd1 = url_get_file_handle(rtsp_st->rtp_handle);
                 if (fd1 > fd_max)
                     fd_max = fd1;
                 FD_SET(fd1, &rfds);
@@ -1331,7 +1331,7 @@ static int udp_read_packet(AVFormatConte
             for(i = 0; i < rt->nb_rtsp_streams; i++) {
                 rtsp_st = rt->rtsp_streams[i];
                 if (rtsp_st->rtp_handle) {
-                    rtp_get_file_handles(rtsp_st->rtp_handle, &fd1, &fd2);
+                    fd1 = url_get_file_handle(rtsp_st->rtp_handle);
                     if (FD_ISSET(fd1, &rfds)) {
                         ret = url_read(rtsp_st->rtp_handle, buf, buf_size);
                         if (ret > 0) {

Modified: trunk/libavformat/tcp.c
==============================================================================
--- trunk/libavformat/tcp.c	Tue Mar  3 17:53:04 2009	(r17778)
+++ trunk/libavformat/tcp.c	Tue Mar  3 18:04:51 2009	(r17779)
@@ -181,6 +181,12 @@ static int tcp_close(URLContext *h)
     return 0;
 }
 
+static int tcp_get_file_handle(URLContext *h)
+{
+    TCPContext *s = h->priv_data;
+    return s->fd;
+}
+
 URLProtocol tcp_protocol = {
     "tcp",
     tcp_open,
@@ -188,4 +194,5 @@ URLProtocol tcp_protocol = {
     tcp_write,
     NULL, /* seek */
     tcp_close,
+    .url_get_file_handle = tcp_get_file_handle,
 };

Modified: trunk/libavformat/udp.c
==============================================================================
--- trunk/libavformat/udp.c	Tue Mar  3 17:53:04 2009	(r17778)
+++ trunk/libavformat/udp.c	Tue Mar  3 18:04:51 2009	(r17779)
@@ -326,6 +326,9 @@ int udp_get_local_port(URLContext *h)
  * streams at the same time.
  * @param h media file context
  */
+#if (LIBAVFORMAT_VERSION_MAJOR >= 53)
+static
+#endif
 int udp_get_file_handle(URLContext *h)
 {
     UDPContext *s = h->priv_data;
@@ -528,4 +531,5 @@ URLProtocol udp_protocol = {
     udp_write,
     NULL, /* seek */
     udp_close,
+    .url_get_file_handle = udp_get_file_handle,
 };




More information about the ffmpeg-cvslog mailing list