* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <strings.h>
#include "avformat.h"
#include "avio_internal.h"
#include "id3v1.h"
buf[0] = 'T';
buf[1] = 'A';
buf[2] = 'G';
- count += id3v1_set_string(s, "TIT2", buf + 3, 30); //title
- count += id3v1_set_string(s, "TPE1", buf + 33, 30); //author|artist
- count += id3v1_set_string(s, "TALB", buf + 63, 30); //album
- count += id3v1_set_string(s, "TDRL", buf + 93, 4); //date
- count += id3v1_set_string(s, "comment", buf + 97, 30);
+ /* we knowingly overspecify each tag length by one byte to compensate for the mandatory null byte added by av_strlcpy */
+ count += id3v1_set_string(s, "TIT2", buf + 3, 30 + 1); //title
+ count += id3v1_set_string(s, "TPE1", buf + 33, 30 + 1); //author|artist
+ count += id3v1_set_string(s, "TALB", buf + 63, 30 + 1); //album
+ count += id3v1_set_string(s, "TDRL", buf + 93, 4 + 1); //date
+ count += id3v1_set_string(s, "comment", buf + 97, 30 + 1);
if ((tag = av_dict_get(s->metadata, "TRCK", NULL, 0))) { //track
buf[125] = 0;
buf[126] = atoi(tag->value);
buf[127] = 0xFF; /* default to unknown genre */
if ((tag = av_dict_get(s->metadata, "TCON", NULL, 0))) { //genre
for(i = 0; i <= ID3v1_GENRE_MAX; i++) {
- if (!strcasecmp(tag->value, ff_id3v1_genre_str[i])) {
+ if (!av_strcasecmp(tag->value, ff_id3v1_genre_str[i])) {
buf[127] = i;
count++;
break;
{
AVCodecContext *codec = s->streams[0]->codec;
MP3Context *mp3 = s->priv_data;
- int bitrate_idx = 3;
+ int bitrate_idx;
+ int best_bitrate_idx;
+ int best_bitrate_error= INT_MAX;
int64_t xing_offset;
- int32_t mask, header;
+ int32_t header;
MPADecodeHeader c;
int srate_idx, i, channels;
int needed;
header |= (srate_idx << 2) << 8;
header |= channels << 6;
- for (;;) {
+ for (bitrate_idx=1; bitrate_idx<15; bitrate_idx++) {
+ int error;
+ avpriv_mpegaudio_decode_header(&c, header | (bitrate_idx << (4+8)));
+ error= FFABS(c.bit_rate - codec->bit_rate);
+ if(error < best_bitrate_error){
+ best_bitrate_error= error;
+ best_bitrate_idx = bitrate_idx;
+ }
+ }
+
+ for (bitrate_idx= best_bitrate_idx;; bitrate_idx++) {
if (15 == bitrate_idx)
return -1;
- mask = (bitrate_idx << 4) << 8;
- header |= mask;
- avpriv_mpegaudio_decode_header(&c, header);
+ avpriv_mpegaudio_decode_header(&c, header | (bitrate_idx << (4+8)));
xing_offset=xing_offtbl[c.lsf == 1][c.nb_channels == 1];
needed = 4 // header
+ xing_offset
if (needed <= c.frame_size)
break;
-
- header &= ~mask;
- ++bitrate_idx;
}
avio_wb32(s->pb, header);