Revision b6125545
libavformat/mp3enc.c | ||
---|---|---|
76 | 76 |
put_byte(s->pb, size & 0x7f); |
77 | 77 |
} |
78 | 78 |
|
79 |
static void id3v2_put_ttag(AVFormatContext *s, const char *buf, int len, |
|
80 |
uint32_t tag) |
|
79 |
/** |
|
80 |
* Write a text frame with one (normal frames) or two (TXXX frames) strings |
|
81 |
* according to encoding (only UTF-8 or UTF-16+BOM supported). |
|
82 |
* @return number of bytes written. |
|
83 |
*/ |
|
84 |
static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2, |
|
85 |
uint32_t tag, enum ID3v2Encoding enc) |
|
81 | 86 |
{ |
87 |
int len; |
|
88 |
uint8_t *pb; |
|
89 |
void (*put)(ByteIOContext*, const char*) = avio_put_str; |
|
90 |
ByteIOContext *dyn_buf; |
|
91 |
if (url_open_dyn_buf(&dyn_buf) < 0) |
|
92 |
return 0; |
|
93 |
|
|
94 |
put_byte(dyn_buf, enc); |
|
95 |
if (enc == ID3v2_ENCODING_UTF16BOM) { |
|
96 |
put_le16(dyn_buf, 0xFEFF); /* BOM */ |
|
97 |
put = avio_put_str16le; |
|
98 |
} |
|
99 |
put(dyn_buf, str1); |
|
100 |
if (str2) |
|
101 |
put(dyn_buf, str2); |
|
102 |
len = url_close_dyn_buf(dyn_buf, &pb); |
|
103 |
|
|
82 | 104 |
put_be32(s->pb, tag); |
83 |
id3v2_put_size(s, len + 1);
|
|
105 |
id3v2_put_size(s, len); |
|
84 | 106 |
put_be16(s->pb, 0); |
85 |
put_byte(s->pb, 3); /* UTF-8 */ |
|
86 |
put_buffer(s->pb, buf, len); |
|
107 |
put_buffer(s->pb, pb, len); |
|
108 |
|
|
109 |
av_freep(&pb); |
|
110 |
return len + ID3v2_HEADER_SIZE; |
|
87 | 111 |
} |
88 | 112 |
|
89 | 113 |
|
... | ... | |
148 | 172 |
int i; |
149 | 173 |
for (i = 0; *ff_id3v2_tags[i]; i++) |
150 | 174 |
if (AV_RB32(t->key) == AV_RB32(ff_id3v2_tags[i])) { |
151 |
int len = strlen(t->value); |
|
152 | 175 |
tag = AV_RB32(t->key); |
153 |
totlen += len + ID3v2_HEADER_SIZE + 2; |
|
154 |
id3v2_put_ttag(s, t->value, len + 1, tag); |
|
176 |
totlen += id3v2_put_ttag(s, t->value, NULL, tag, ID3v2_ENCODING_UTF8); |
|
155 | 177 |
break; |
156 | 178 |
} |
157 | 179 |
} |
158 | 180 |
|
159 | 181 |
if (!tag) { /* unknown tag, write as TXXX frame */ |
160 |
int len = strlen(t->key), len1 = strlen(t->value); |
|
161 |
char *buf = av_malloc(len + len1 + 2); |
|
162 |
if (!buf) |
|
163 |
return AVERROR(ENOMEM); |
|
164 | 182 |
tag = MKBETAG('T', 'X', 'X', 'X'); |
165 |
strcpy(buf, t->key); |
|
166 |
strcpy(buf + len + 1, t->value); |
|
167 |
id3v2_put_ttag(s, buf, len + len1 + 2, tag); |
|
168 |
totlen += len + len1 + ID3v2_HEADER_SIZE + 3; |
|
169 |
av_free(buf); |
|
183 |
totlen += id3v2_put_ttag(s, t->key, t->value, tag, ID3v2_ENCODING_UTF8); |
|
170 | 184 |
} |
171 | 185 |
} |
172 | 186 |
|
Also available in: Unified diff