[FFmpeg-cvslog] r23702 - in trunk/libavformat: allformats.c avformat.h avio.c avio.h

mstorsjo subversion
Tue Jun 22 15:58:48 CEST 2010


Author: mstorsjo
Date: Tue Jun 22 15:58:48 2010
New Revision: 23702

Log:
Add an av_register_protocol2 function that takes a size parameter

This allows extending the URLProtocol struct without breaking binary
compatibility with code compiled with older definitions of the struct.

Modified:
   trunk/libavformat/allformats.c
   trunk/libavformat/avformat.h
   trunk/libavformat/avio.c
   trunk/libavformat/avio.h

Modified: trunk/libavformat/allformats.c
==============================================================================
--- trunk/libavformat/allformats.c	Tue Jun 22 14:41:17 2010	(r23701)
+++ trunk/libavformat/allformats.c	Tue Jun 22 15:58:48 2010	(r23702)
@@ -34,7 +34,7 @@
 
 #define REGISTER_PROTOCOL(X,x) { \
     extern URLProtocol x##_protocol; \
-    if(CONFIG_##X##_PROTOCOL) av_register_protocol(&x##_protocol); }
+    if(CONFIG_##X##_PROTOCOL) av_register_protocol2(&x##_protocol, sizeof(x##_protocol)); }
 
 void av_register_all(void)
 {

Modified: trunk/libavformat/avformat.h
==============================================================================
--- trunk/libavformat/avformat.h	Tue Jun 22 14:41:17 2010	(r23701)
+++ trunk/libavformat/avformat.h	Tue Jun 22 15:58:48 2010	(r23702)
@@ -22,7 +22,7 @@
 #define AVFORMAT_AVFORMAT_H
 
 #define LIBAVFORMAT_VERSION_MAJOR 52
-#define LIBAVFORMAT_VERSION_MINOR 68
+#define LIBAVFORMAT_VERSION_MINOR 69
 #define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

Modified: trunk/libavformat/avio.c
==============================================================================
--- trunk/libavformat/avio.c	Tue Jun 22 14:41:17 2010	(r23701)
+++ trunk/libavformat/avio.c	Tue Jun 22 15:58:48 2010	(r23702)
@@ -56,9 +56,14 @@ URLProtocol *av_protocol_next(URLProtoco
     else  return first_protocol;
 }
 
-int av_register_protocol(URLProtocol *protocol)
+int av_register_protocol2(URLProtocol *protocol, int size)
 {
     URLProtocol **p;
+    if (size < sizeof(URLProtocol)) {
+        URLProtocol* temp = av_mallocz(sizeof(URLProtocol));
+        memcpy(temp, protocol, size);
+        protocol = temp;
+    }
     p = &first_protocol;
     while (*p != NULL) p = &(*p)->next;
     *p = protocol;
@@ -67,6 +72,22 @@ int av_register_protocol(URLProtocol *pr
 }
 
 #if LIBAVFORMAT_VERSION_MAJOR < 53
+/* The layout of URLProtocol as of when major was bumped to 52 */
+struct URLProtocol_compat {
+    const char *name;
+    int (*url_open)(URLContext *h, const char *filename, int flags);
+    int (*url_read)(URLContext *h, unsigned char *buf, int size);
+    int (*url_write)(URLContext *h, unsigned char *buf, int size);
+    int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
+    int (*url_close)(URLContext *h);
+    struct URLProtocol *next;
+};
+
+int av_register_protocol(URLProtocol *protocol)
+{
+    return av_register_protocol2(protocol, sizeof(struct URLProtocol_compat));
+}
+
 int register_protocol(URLProtocol *protocol)
 {
     return av_register_protocol(protocol);

Modified: trunk/libavformat/avio.h
==============================================================================
--- trunk/libavformat/avio.h	Tue Jun 22 14:41:17 2010	(r23701)
+++ trunk/libavformat/avio.h	Tue Jun 22 15:58:48 2010	(r23702)
@@ -252,12 +252,19 @@ URLProtocol *av_protocol_next(URLProtoco
  * @deprecated Use av_register_protocol() instead.
  */
 attribute_deprecated int register_protocol(URLProtocol *protocol);
+
+/**
+ * @deprecated Use av_register_protocol2() instead.
+ */
+attribute_deprecated int av_register_protocol(URLProtocol *protocol);
 #endif
 
 /**
  * Registers the URLProtocol protocol.
+ *
+ * @param size the size of the URLProtocol struct referenced
  */
-int av_register_protocol(URLProtocol *protocol);
+int av_register_protocol2(URLProtocol *protocol, int size);
 
 /**
  * Bytestream IO Context.



More information about the ffmpeg-cvslog mailing list