]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/aviobuf.c
Merge commit '9993a067f6c8c7e7838052ac3146aa6b80dd7e81'
[ffmpeg] / libavformat / aviobuf.c
index 8fd04668c04d856f169fe204c907bbb51f5217f5..7de59f10f34e357dfca4add590c2189c9559ea2e 100644 (file)
@@ -342,7 +342,7 @@ int avio_put_str(AVIOContext *s, const char *str)
     return len;
 }
 
-int avio_put_str16le(AVIOContext *s, const char *str)
+static inline int put_str16(AVIOContext *s, const char *str, const int be)
 {
     const uint8_t *q = str;
     int ret = 0;
@@ -353,19 +353,34 @@ int avio_put_str16le(AVIOContext *s, const char *str)
         uint16_t tmp;
 
         GET_UTF8(ch, *q++, goto invalid;)
-        PUT_UTF16(ch, tmp, avio_wl16(s, tmp); ret += 2;)
+        PUT_UTF16(ch, tmp, be ? avio_wb16(s, tmp) : avio_wl16(s, tmp);
+                  ret += 2;)
         continue;
 invalid:
-        av_log(s, AV_LOG_ERROR, "Invaid UTF8 sequence in avio_put_str16le\n");
+        av_log(s, AV_LOG_ERROR, "Invaid UTF8 sequence in avio_put_str16%s\n", be ? "be" : "le");
         err = AVERROR(EINVAL);
     }
-    avio_wl16(s, 0);
+    if (be)
+        avio_wb16(s, 0);
+    else
+        avio_wl16(s, 0);
     if (err)
         return err;
     ret += 2;
     return ret;
 }
 
+#define PUT_STR16(type, big_endian)                          \
+int avio_put_str16 ## type(AVIOContext *s, const char *str)  \
+{                                                            \
+return put_str16(s, str, big_endian);                        \
+}
+
+PUT_STR16(le, 0)
+PUT_STR16(be, 1)
+
+#undef PUT_STR16
+
 int ff_get_v_length(uint64_t val)
 {
     int i = 1;
@@ -763,7 +778,9 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
         return AVERROR(ENOMEM);
 
     *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h,
-                            (void*)ffurl_read, (void*)ffurl_write, (void*)ffurl_seek);
+                            (int (*)(void *, uint8_t *, int)) ffurl_read,
+                            (int (*)(void *, uint8_t *, int)) ffurl_write,
+                            (int64_t (*)(void *, int64_t, int)) ffurl_seek);
     if (!*s) {
         av_free(buffer);
         return AVERROR(ENOMEM);