lavf: move ff_put_str16_nolen from asf to avio and rename it

It will be useful in the mp3 muxer.

Signed-off-by: Mans Rullgard <mans@mansr.com>
(cherry picked from commit dccbd97d72)
This commit is contained in:
Anton Khirnov 2011-01-21 19:18:08 +00:00 committed by Michael Niedermayer
parent e910a77b0d
commit 6e89b61293
6 changed files with 27 additions and 23 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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);
avio_put_str16le(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] ? avio_put_str16le(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);
avio_put_str16le(dyn_buf, desc);
len = url_close_dyn_buf(dyn_buf, &buf);
put_le16(pb, len / 2); // "number of characters" = length in bytes / 2

View File

@ -377,6 +377,12 @@ attribute_deprecated void put_strz(ByteIOContext *s, const char *buf);
*/
int avio_put_str(ByteIOContext *s, const char *str);
/**
* Convert an UTF-8 string to UTF-16LE and write it.
* @return number of bytes written.
*/
int avio_put_str16le(ByteIOContext *s, const char *str);
/**
* fseek() equivalent for ByteIOContext.
* @return new position or AVERROR.

View File

@ -283,6 +283,23 @@ int avio_put_str(ByteIOContext *s, const char *str)
return len;
}
int avio_put_str16le(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;

View File

@ -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 = avio_put_str16le(&bic, src);
mms->write_out_ptr += len;
}