On Thu, Sep 04, 2014 at 10:40:27PM +0200, wm4 wrote: > --- > Follows reimar's suggestion for detecting UTF-16. If the detection goes > wrong, probing the format won't succeed, so this should not break > anything. > > I didn't use ffio_ensure_seekback), because this apparently reallocates > the buffer - which we certainly don't want, because the probe API > doesn't allow this. > > Probably too messy, feel free to drop. > --- > libavformat/subtitles.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c > index 3069477..7d6a93c 100644 > --- a/libavformat/subtitles.c > +++ b/libavformat/subtitles.c > @@ -26,6 +26,7 @@ > > void ff_text_init_avio(FFTextReader *r, AVIOContext *pb) > { > + int can_seekback_2_bytes = pb->buf_end - pb->buf_ptr >= 2; > int i; > r->pb = pb; > r->buf_pos = r->buf_len = 0; > @@ -38,6 +39,14 @@ void ff_text_init_avio(FFTextReader *r, AVIOContext *pb) > } else if (strncmp("\xFE\xFF", r->buf, 2) == 0) { > r->type = FF_UTF16BE; > r->buf_pos += 2; > + } else if (can_seekback_2_bytes && r->buf[0] && !r->buf[1]) { > + r->type = FF_UTF16LE; // with high probability > + r->pb->buf_ptr -= 2; > + r->buf_pos = r->buf_len = 0; > + } else if (can_seekback_2_bytes && !r->buf[0] && r->buf[1]) { > + r->type = FF_UTF16BE; // with high probability > + r->pb->buf_ptr -= 2; > + r->buf_pos = r->buf_len = 0; > } else { > r->buf[r->buf_len++] = avio_r8(r->pb); > if (strncmp("\xEF\xBB\xBF", r->buf, 3) == 0) {
I left this one for Reimar or someone else to review. I'm not familiar enough with the avio internals. Note: that change is pretty useful for testing since iconv doesn't look to be able to add a BOM by itself. -- Clément B.
pgpigaDHXs6vY.pgp
Description: PGP signature
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel