[FFmpeg-devel] [PATCH 1/6] lavf: move ff_put_str16_nolen from asf to avio and rename it
Anton Khirnov
anton
Fri Jan 21 15:22:11 CET 2011
It will be useful in the mp3 muxer.
---
libavformat/asf.c | 17 -----------------
libavformat/asf.h | 1 -
libavformat/asfenc.c | 6 +++---
libavformat/avio.h | 5 +++++
libavformat/aviobuf.c | 17 +++++++++++++++++
libavformat/mmst.c | 3 +--
6 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/libavformat/asf.c b/libavformat/asf.c
index 58e17e9..e665992 100644
--- a/libavformat/asf.c
+++ b/libavformat/asf.c
@@ -156,20 +156,3 @@ const AVMetadataConv ff_asf_metadata_conv[] = {
// { "Year" , "date" }, TODO: conversion year<->date
{ 0 }
};
-
-int ff_put_str16_nolen(ByteIOContext *s, const char *tag)
-{
- const uint8_t *q = tag;
- int ret = 0;
-
- while (*q) {
- uint32_t ch;
- uint16_t tmp;
-
- GET_UTF8(ch, *q++, break;)
- PUT_UTF16(ch, tmp, put_le16(s, tmp);ret += 2;)
- }
- put_le16(s, 0);
- ret += 2;
- return ret;
-}
diff --git a/libavformat/asf.h b/libavformat/asf.h
index f3705e9..8cf517d 100644
--- a/libavformat/asf.h
+++ b/libavformat/asf.h
@@ -230,7 +230,6 @@ extern const AVMetadataConv ff_asf_metadata_conv[];
#define ASF_PL_FLAG_KEY_FRAME 0x80 //1000 0000
extern AVInputFormat asf_demuxer;
-int ff_put_str16_nolen(ByteIOContext *s, const char *tag);
int ff_guidcmp(const void *g1, const void *g2);
void ff_get_guid(ByteIOContext *s, ff_asf_guid *g);
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index b964953..4a47c0c 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -211,7 +211,7 @@ static void put_str16(ByteIOContext *s, const char *tag)
if (url_open_dyn_buf(&dyn_buf) < 0)
return;
- ff_put_str16_nolen(dyn_buf, tag);
+ ff_put_strz16le(dyn_buf, tag);
len = url_close_dyn_buf(dyn_buf, &pb);
put_le16(s, len);
put_buffer(s, pb, len);
@@ -346,7 +346,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
hpos = put_header(pb, &ff_asf_comment_header);
for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) {
- len = tags[n] ? ff_put_str16_nolen(dyn_buf, tags[n]->value) : 0;
+ len = tags[n] ? ff_put_strz16le(dyn_buf, tags[n]->value) : 0;
put_le16(pb, len);
}
len = url_close_dyn_buf(dyn_buf, &buf);
@@ -474,7 +474,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
if ( url_open_dyn_buf(&dyn_buf) < 0)
return AVERROR(ENOMEM);
- ff_put_str16_nolen(dyn_buf, desc);
+ ff_put_strz16le(dyn_buf, desc);
len = url_close_dyn_buf(dyn_buf, &buf);
put_le16(pb, len / 2); // "number of characters" = length in bytes / 2
diff --git a/libavformat/avio.h b/libavformat/avio.h
index e65f712..6880d64 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -366,6 +366,11 @@ void put_be16(ByteIOContext *s, unsigned int val);
void put_tag(ByteIOContext *s, const char *tag);
void put_strz(ByteIOContext *s, const char *buf);
+/**
+ * Convert an UTF-8 string to UTF-16LE and write it.
+ * @return number of bytes written.
+ */
+int ff_put_strz16le(ByteIOContext *s, const char *str);
/**
* fseek() equivalent for ByteIOContext.
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index df76507..f1a3130 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -273,6 +273,23 @@ void put_strz(ByteIOContext *s, const char *str)
put_byte(s, 0);
}
+int ff_put_strz16le(ByteIOContext *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, put_le16(s, tmp);ret += 2;)
+ }
+ put_le16(s, 0);
+ ret += 2;
+ return ret;
+}
+
int ff_get_v_length(uint64_t val){
int i=1;
diff --git a/libavformat/mmst.c b/libavformat/mmst.c
index 57cca5d..9a85617 100644
--- a/libavformat/mmst.c
+++ b/libavformat/mmst.c
@@ -34,7 +34,6 @@
#include "libavutil/intreadwrite.h"
#include "libavcodec/bytestream.h"
#include "network.h"
-#include "asf.h"
#define LOCAL_ADDRESS 0xc0a80081 // FIXME get and use correct local ip address.
#define LOCAL_PORT 1037 // as above.
@@ -159,7 +158,7 @@ static void mms_put_utf16(MMSContext *mms, uint8_t *src)
init_put_byte(&bic, mms->write_out_ptr,
sizeof(mms->out_buffer) - size, 1, NULL, NULL, NULL, NULL);
- len = ff_put_str16_nolen(&bic, src);
+ len = ff_put_strz16le(&bic, src);
mms->write_out_ptr += len;
}
--
1.7.2.3
More information about the ffmpeg-devel
mailing list