+ avio_wb32(dyn_ctx, 0); // frames
+ avio_wb32(dyn_ctx, 0); // size
+
+ // TOC
+ for (i = 0; i < XING_TOC_SIZE; i++)
+ avio_w8(dyn_ctx, (uint8_t)(255 * i / XING_TOC_SIZE));
+
+ // vbr quality
+ // we write it, because some (broken) tools always expect it to be present
+ avio_wb32(dyn_ctx, 0);
+
+ // encoder short version string
+ if (enc) {
+ uint8_t encoder_str[9] = { 0 };
+ if ( strlen(enc->value) > sizeof(encoder_str)
+ && !strcmp("Lavc libmp3lame", enc->value)) {
+ memcpy(encoder_str, "Lavf lame", 9);
+ } else
+ memcpy(encoder_str, enc->value, FFMIN(strlen(enc->value), sizeof(encoder_str)));
+
+ avio_write(dyn_ctx, encoder_str, sizeof(encoder_str));
+ } else
+ avio_write(dyn_ctx, "Lavf\0\0\0\0\0", 9);
+
+ avio_w8(dyn_ctx, 0); // tag revision 0 / unknown vbr method
+ avio_w8(dyn_ctx, 0); // unknown lowpass filter value
+ ffio_fill(dyn_ctx, 0, 8); // empty replaygain fields
+ avio_w8(dyn_ctx, 0); // unknown encoding flags
+ avio_w8(dyn_ctx, 0); // unknown abr/minimal bitrate
+
+ // encoder delay
+ if (codec->initial_padding - 528 - 1 >= 1 << 12) {
+ av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n");
+ }
+ avio_wb24(dyn_ctx, FFMAX(codec->initial_padding - 528 - 1, 0)<<12);
+
+ avio_w8(dyn_ctx, 0); // misc
+ avio_w8(dyn_ctx, 0); // mp3gain
+ avio_wb16(dyn_ctx, 0); // preset