---
While writing some documentation I noticed this is strangely missing.
libavformat/avio.h | 12 ++++++++++++
libavformat/aviobuf.c | 34 ++++++++++++++++++++--------------
2 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 3360e82..a1497d9 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -178,11 +178,23 @@ int avio_put_str(AVIOContext *s, const char *str);
/**
* Convert an UTF-8 string to UTF-16LE and write it.
+ * @param s the AVIOContext
+ * @param str NULL-terminated UTF-8 string
+ *
* @return number of bytes written.
*/
int avio_put_str16le(AVIOContext *s, const char *str);
/**
+ * Convert an UTF-8 string to UTF-16BE and write it.
+ * @param s the AVIOContext
+ * @param str NULL-terminated UTF-8 string
+ *
+ * @return number of bytes written.
+ */
+int avio_put_str16be(AVIOContext *s, const char *str);
+
+/**
* Passing this as the "whence" parameter to a seek function causes it to
* return the filesize without seeking anywhere. Supporting this is optional.
* If it is not supported then the seek function will return <0.
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index d3e3452..a12e528 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -284,22 +284,28 @@ int avio_put_str(AVIOContext *s, const char *str)
return len;
}
-int avio_put_str16le(AVIOContext *s, const char *str)
-{
- const uint8_t *q = str;
- int ret = 0;
+#define PUT_STR16(type, write) \
+ int avio_put_str16 ## type(AVIOContext * s, const char *str) \
+ { \
+ const uint8_t *q = str; \
+ int ret = 0; \
+ \
+ while (*q) { \
+ uint32_t ch; \
+ uint16_t tmp; \
+ \
+ GET_UTF8(ch, *q++, break; ) \
+ PUT_UTF16(ch, tmp, write(s, tmp); ret += 2; ) \
+ } \
+ avio_wl16(s, 0); \
+ ret += 2; \
+ return ret; \
+ }
- while (*q) {
- uint32_t ch;
- uint16_t tmp;
+PUT_STR16(le, avio_wl16)
+PUT_STR16(be, avio_wb16)
- GET_UTF8(ch, *q++, break;)
- PUT_UTF16(ch, tmp, avio_wl16(s, tmp); ret += 2;)
- }
- avio_wl16(s, 0);
- ret += 2;
- return ret;
-}
+#undef PUT_STR16
int ff_get_v_length(uint64_t val)
{
--
1.9.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel