[FFmpeg-devel] [RFC]Print a warning if a subtitle demuxer changes utf16 to utf8.

Carl Eugen Hoyos cehoyos at ag.or.at
Tue Oct 28 08:35:12 CET 2014


Hi!

The user should be told by libavformat if it does something unexpected.
Related to ticket #4059.

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/assdec.c b/libavformat/assdec.c
index ccbf4c0..c62e76f 100644
--- a/libavformat/assdec.c
+++ b/libavformat/assdec.c
@@ -112,7 +112,7 @@ static int ass_read_header(AVFormatContext *s)
     int res = 0;
     AVStream *st;
     FFTextReader tr;
-    ff_text_init_avio(&tr, s->pb);
+    ff_text_init_avio(s, &tr, s->pb);
 
     st = avformat_new_stream(s, NULL);
     if (!st)
diff --git a/libavformat/realtextdec.c b/libavformat/realtextdec.c
index 19af108..fff85d6 100644
--- a/libavformat/realtextdec.c
+++ b/libavformat/realtextdec.c
@@ -65,7 +65,7 @@ static int realtext_read_header(AVFormatContext *s)
     char c = 0;
     int res = 0, duration = read_ts("60"); // default duration is 60 seconds
     FFTextReader tr;
-    ff_text_init_avio(&tr, s->pb);
+    ff_text_init_avio(s, &tr, s->pb);
 
     if (!st)
         return AVERROR(ENOMEM);
diff --git a/libavformat/samidec.c b/libavformat/samidec.c
index 4dbf2cf..948e1ed 100644
--- a/libavformat/samidec.c
+++ b/libavformat/samidec.c
@@ -54,7 +54,7 @@ static int sami_read_header(AVFormatContext *s)
     char c = 0;
     int res = 0, got_first_sync_point = 0;
     FFTextReader tr;
-    ff_text_init_avio(&tr, s->pb);
+    ff_text_init_avio(s, &tr, s->pb);
 
     if (!st)
         return AVERROR(ENOMEM);
diff --git a/libavformat/srtdec.c b/libavformat/srtdec.c
index 02d75f1..b35e50f 100644
--- a/libavformat/srtdec.c
+++ b/libavformat/srtdec.c
@@ -87,7 +87,7 @@ static int srt_read_header(AVFormatContext *s)
     AVStream *st = avformat_new_stream(s, NULL);
     int res = 0;
     FFTextReader tr;
-    ff_text_init_avio(&tr, s->pb);
+    ff_text_init_avio(s, &tr, s->pb);
 
     if (!st)
         return AVERROR(ENOMEM);
diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
index 95faca6..b270dc5 100644
--- a/libavformat/subtitles.c
+++ b/libavformat/subtitles.c
@@ -24,7 +24,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 
-void ff_text_init_avio(FFTextReader *r, AVIOContext *pb)
+void ff_text_init_avio(AVFormatContext *s, FFTextReader *r, AVIOContext *pb)
 {
     int i;
     r->pb = pb;
@@ -45,13 +45,16 @@ void ff_text_init_avio(FFTextReader *r, AVIOContext *pb)
             r->buf_pos += 3;
         }
     }
+    if (s && (r->type == FF_UTF16LE || r->type == FF_UTF16BE))
+        av_log(s, AV_LOG_WARNING,
+               "UTF16 is automatically converted to UTF8, do not specify a character encoding\n");
 }
 
 void ff_text_init_buf(FFTextReader *r, void *buf, size_t size)
 {
     memset(&r->buf_pb, 0, sizeof(r->buf_pb));
     ffio_init_context(&r->buf_pb, buf, size, 0, NULL, NULL, NULL, NULL);
-    ff_text_init_avio(r, &r->buf_pb);
+    ff_text_init_avio(NULL, r, &r->buf_pb);
 }
 
 int64_t ff_text_pos(FFTextReader *r)
diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h
index 903c24d..c549584 100644
--- a/libavformat/subtitles.h
+++ b/libavformat/subtitles.h
@@ -53,10 +53,11 @@ typedef struct {
  * The purpose of FFTextReader is to transparently convert read data to UTF-8
  * if the stream had a UTF-16 BOM.
  *
+ * @param s AVFormatContext to provide av_log context
  * @param r object which will be initialized
  * @param pb stream to read from (referenced as long as FFTextReader is in use)
  */
-void ff_text_init_avio(FFTextReader *r, AVIOContext *pb);
+void ff_text_init_avio(AVFormatContext *s, FFTextReader *r, AVIOContext *pb);
 
 /**
  * Similar to ff_text_init_avio(), but sets it up to read from a bounded buffer.


More information about the ffmpeg-devel mailing list