[Mplayer-users] small changes to MPlayer-20010723

Adam Tla/lka atlka at pg.gda.pl
Wed Jul 25 08:45:20 CEST 2001


Hello,

I made a patch which implements:

* reading subtitles text encoded in utf8 (option -utf8)
* reading fonts files from LIBDIR/font if there is no font dir in ~/.mplayer
* better detection of local display connection ("unix:" and "localhost:" are
  assumed local and automagically changed to ":" )
* displaying status only while "verbose" option is on -  maybe not all want 
  this but on slower machines we should display only that what is absolutely 
  needed ( film and subtitles in my opinion)

Next, what's about an idea of displaying subtitles below the film rectangle.
We would see all of the film picture and subtitles wolud be more visible
on the black border. Especially in fullscreen mode we have free space on the
screen and if we place film window at the top left corner of the screen 
we could place subtitles just below the film window. 

Regards

  
-- 
 . .  Adam Tla/lka      mailto:atlka at pg.gda.pl    ^v^ ^v^ ^v^
-------------- next part --------------
diff -ruN MPlayer-20010723/cfg-mplayer.h MPlayer-20010723n/cfg-mplayer.h
--- MPlayer-20010723/cfg-mplayer.h	Sun Jul 22 11:46:54 2001
+++ MPlayer-20010723n/cfg-mplayer.h	Tue Jul 24 08:42:14 2001
@@ -32,6 +32,7 @@
 extern int vo_dbpp;
 extern int osd_level;
 extern int sub_unicode;
+extern int sub_utf8;
 
 extern char *ao_outputfilename;
 extern int ao_pcm_waveheader;
@@ -83,6 +84,8 @@
         {"noautosub", &sub_auto, CONF_TYPE_FLAG, 0, 1, 0},
 	{"unicode", &sub_unicode, CONF_TYPE_FLAG, 0, 0, 1},
 	{"nounicode", &sub_unicode, CONF_TYPE_FLAG, 0, 1, 0},
+	{"utf8", &sub_utf8, CONF_TYPE_FLAG, 0, 0, 1},
+	{"noutf8", &sub_utf8, CONF_TYPE_FLAG, 0, 1, 0},
 	{"font", &font_name, CONF_TYPE_STRING, 0, 0, 0},
 	{"ffactor", &font_factor, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 10.0},
 	{"bg", &play_in_bg, CONF_TYPE_FLAG, 0, 0, 1},

diff -ruN MPlayer-20010723/libvo/font_load.c MPlayer-20010723n/libvo/font_load.c
--- MPlayer-20010723/libvo/font_load.c	Fri Jul 20 04:03:50 2001
+++ MPlayer-20010723n/libvo/font_load.c	Tue Jul 24 13:35:44 2001
@@ -2,6 +2,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #include "config.h"
 #include "font_load.h"
@@ -42,6 +45,7 @@
 unsigned char sor2[1024];
 font_desc_t *desc;
 FILE *f;
+struct stat fstate;
 char section[64];
 int i,j;
 int chardb=0;
@@ -51,10 +55,15 @@
 desc=malloc(sizeof(font_desc_t));if(!desc) return NULL;
 memset(desc,0,sizeof(font_desc_t));
 
-desc->fpath=get_path("font/");
-
-f=fopen(fname,"rt");if(!f){ printf("font: can't open file: %s\n",fname); return NULL;}
+if (!(f = fopen(fname,"rt"))) { 
+   printf("font: can't open file: %s\n",fname);
+   return NULL;
+}
 
+desc->fpath=get_path("font/");
+	
+if (stat(desc->fpath, &fstate)!=0) desc->fpath=DATADIR"/font" ;
+		
 // set up some defaults, and erase table
 desc->charspace=2;
 desc->spacewidth=12;
diff -ruN MPlayer-20010723/libvo/sub.c MPlayer-20010723n/libvo/sub.c
--- MPlayer-20010723/libvo/sub.c	Tue Jun 12 16:03:18 2001
+++ MPlayer-20010723n/libvo/sub.c	Tue Jul 24 12:03:17 2001
@@ -5,7 +5,8 @@
 font_desc_t* vo_font=NULL;
 
 unsigned char* vo_osd_text="00:00:00";
-int sub_unicode=0;
+int sub_unicode = 0;
+int sub_utf8 = 0;
 
 static void vo_draw_text_osd(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
         int len=strlen(vo_osd_text);
@@ -90,6 +91,28 @@
 
 subtitle* vo_sub=NULL;
 
+static int  getcharcode(unsigned char *tptr, int *p) {
+    int c = tptr[*p] ;
+    if (c >= 0x80) {
+       if (sub_unicode) c = (c<<8)+tptr[++(*p)]; else
+       if (sub_utf8) {
+	  if ((c & 0xe0) == 0xc0)      /* 2 bytes U+00080..U+0007FF */
+	     c = (c & 0x1f)<<6 | 
+		 (tptr[++(*p)] & 0x3f); 
+	  else if ((c & 0xf0) == 0xe0) /* 3 bytes U+00800..U+00FFFF */
+	     c = ((c & 0x0f)<<6 | 
+		 (tptr[++(*p)] & 0x3f))<<6 |
+		 (tptr[++(*p)] & 0x3f);
+	  else if ((c & 0xf8) == 0xf0) /* 4 bytes U+10000..U+10FFFF */
+	     c = (((c & 0x07)<<6 | 
+		 (tptr[++(*p)] & 0x3f))<<6 |
+		 (tptr[++(*p)] & 0x3f))<<6 |
+		 (tptr[++(*p)] & 0x3f);
+       }
+    }
+    return c;    
+}
+
 static void vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
     int i;
     int y;
@@ -106,11 +129,9 @@
 	int lastxsize=0;
 
 	for(j=0;j<len;j++){
-          int c=text[j];
-          int w;
-          if (sub_unicode && (c>=0x80)) c=(c<<8)+text[++j];
-          w = vo_font->width[c];
-	  if (text[j]==' ' && dxs>xsize)
+	  int c=getcharcode(text, &j);
+          int w=vo_font->width[c];
+	  if (c==' ' && dxs>xsize)
 	  {
 	    lastStripPosition=j;
 	    lastxsize=xsize;
@@ -140,10 +161,8 @@
 	int lastxsize=xsize;
 
 	for(j=0;j<len;j++){
-          int c=text[j];
-          int w;
-          if (sub_unicode && (c>=0x80)) c=(c<<8)+text[++j];
-          w = vo_font->width[c];
+          int c=getcharcode(text, &j);
+          int w=vo_font->width[c];
           if (c==' ' && dxs>xsize)
 	  {
 	    lastStripPosition=j;
@@ -159,10 +178,8 @@
             x=dxs/2-xsize/2;
 
             for(k=previousStrip;k<lastStripPosition;k++){
-              int c=text[k];
-	      int font;
-              if (sub_unicode && (c>=0x80)) c=(c<<8)+text[++k];
-              font=vo_font->font[c];
+              int c=getcharcode(text, &k);
+	      int font=vo_font->font[c];
               if(x>=0 && x+vo_font->width[c]<dxs)
                 if(font>=0)
                   draw_alpha(x,y,
diff -ruN MPlayer-20010723/libvo/x11_common.c MPlayer-20010723n/libvo/x11_common.c
--- MPlayer-20010723/libvo/x11_common.c	Thu Jul 19 20:47:22 2001
+++ MPlayer-20010723n/libvo/x11_common.c	Tue Jul 24 11:04:21 2001
@@ -91,7 +91,11 @@
    }
    XDestroyImage( mXImage );
 // XCloseDisplay( mDisplay );
-#warning Better local display detection method is needed. 
+ /* slightly improved local display detection AST */
+ if ( strncmp(mDisplayName, "unix:", 5) == 0)
+		mDisplayName += 4;
+ else if ( strncmp(mDisplayName, "localhost:", 10) == 0)
+		mDisplayName += 9;
  if (*mDisplayName==':') mLocalDisplay=1; else mLocalDisplay=0;
  printf("vo: X11 running at %dx%d depth: %d (\"%s\" => %s display)\n",vo_screenwidth,vo_screenheight,vo_depthonscreen,mDisplayName,mLocalDisplay?"local":"remote");
  return 1;
diff -ruN MPlayer-20010723/mplayer.c MPlayer-20010723n/mplayer.c
--- MPlayer-20010723/mplayer.c	Sun Jul 22 00:36:39 2001
+++ MPlayer-20010723n/mplayer.c	Tue Jul 24 14:40:13 2001
@@ -1350,6 +1350,7 @@
       float x=frame_correction;
       if(delay_corrected){
 //        printf("A:%6.1f  V:%6.1f  A-V:%7.3f",a_pts-audio_delay-delay,v_pts,x);
+	if(verbose)  
         printf("A:%6.1f (%6.1f)  V:%6.1f  A-V:%7.3f",a_pts,a_pts-audio_delay-delay,v_pts,x);
         x*=0.1f;
         if(x<-max_pts_correction) x=-max_pts_correction; else
@@ -1359,6 +1360,7 @@
         else
           max_pts_correction=sh_video->frametime*0.10; // +-10% of time
         sh_audio->timer+=x; c_total+=x;
+	if(verbose)      
         printf(" ct:%7.3f  %3d  %2d%% %2d%% %4.1f%% %d\r",c_total,
         (int)num_frames,
         (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
@@ -1379,6 +1381,7 @@
     float v_pts=d_video->pts;
     if(frame_corr_num==5){
 //      printf("A: ---   V:%6.1f   \r",v_pts);
+     if(verbose) 
       printf("V:%6.1f  %3d  %2d%%  %2d%%  %3.1f%% \r",v_pts,
         (int)num_frames,
         (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
@@ -1746,10 +1749,13 @@
         current_module=NULL;
 
         c_total=0; // kell ez?
-        printf("A:%6.1f  V:%6.1f  A-V:%7.3f",d_audio->pts,d_video->pts,0.0f);
-        printf("  ct:%7.3f   \r",c_total);fflush(stdout);
+	if(verbose) {      
+          printf("A:%6.1f  V:%6.1f  A-V:%7.3f",d_audio->pts,d_video->pts,0.0f);
+          printf("  ct:%7.3f   \r",c_total);fflush(stdout);
+	}
       } else {
-        printf("A: ---   V:%6.1f   \r",d_video->pts);fflush(stdout);
+	if(verbose)      
+           printf("A: ---   V:%6.1f   \r",d_video->pts);fflush(stdout);
       }
 
         // Set OSD:


More information about the MPlayer-users mailing list