[Mplayer-users] Patch to 20010801 snapshot

Adam Tla/lka atlka at pg.gda.pl
Wed Aug 1 12:05:09 CEST 2001


Hi,

I don't see any changes according to my previous post so I'am posting 
another patch files:

utf8quiet.diff	- implements -utf8 and -quiet options and optimizes OSD
font_load.c	- implements reading of font from LIBDIR/font 
		  if ~/.mplayer/font doesn't exist
x11_common.c	- implements better local display connection


I'm converting sub texts to ucs2 while reading them so further processing
while generating OSD is not needed. We have text in ucs2 and length of text
as the first element of an array. In the normal version we must decode utf8 
chars three times - one time while calculating y position and two times while
cutting lines and displaying them. Next optimization is calculating of y
position of subtitles only once for a given subtitle and not changed dxs 
and dys. Try it.

I'm using unix konwert program to recode sub files to utf8 so I do not need to
modify font description file to see polish texts. But of course if we need
chars from another charsets (japan etc.) we need other font  and font.desc
files which contains these chars.

Regards
-- 
 . .  Adam Tla/lka      mailto:atlka at pg.gda.pl    ^v^ ^v^ ^v^
     PGP public key:   finger atlka at sunrise.pg.gda.pl
-------------- next part --------------
diff -ruN MPlayer-20010801/cfg-mplayer.h MPlayer-20010801n/cfg-mplayer.h
--- MPlayer-20010801/cfg-mplayer.h	Mon Jul 30 04:00:54 2001
+++ MPlayer-20010801n/cfg-mplayer.h	Wed Aug  1 07:26:49 2001
@@ -35,6 +35,7 @@
 
 #ifdef USE_SUB
 extern int sub_unicode;
+extern int sub_utf8;
 #endif
 
 #ifdef USE_OSD
@@ -92,6 +93,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},
 #endif
 #ifdef USE_OSD
 	{"font", &font_name, CONF_TYPE_STRING, 0, 0, 0},
@@ -197,6 +200,8 @@
         
 	{"verbose", &verbose, CONF_TYPE_INT, CONF_RANGE, 0, 100},
 	{"v", cfg_inc_verbose, CONF_TYPE_FUNC, 0, 0, 0},
+	{"quiet", &quiet, CONF_TYPE_FLAG, 0, 0, 1},
+	{"q", &quiet, CONF_TYPE_FLAG, 0, 0, 1},
 	{"-help", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0},
 	{"help", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0},
 	{"h", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0},
diff -ruN MPlayer-20010801/libvo/sub.c MPlayer-20010801n/libvo/sub.c
--- MPlayer-20010801/libvo/sub.c	Tue Jun 12 16:03:18 2001
+++ MPlayer-20010801n/libvo/sub.c	Wed Aug  1 08:02:40 2001
@@ -6,24 +6,24 @@
 
 unsigned char* vo_osd_text="00:00:00";
 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);
-        int j;
+	unsigned char *cp=vo_osd_text;
+	int font;
         int y=10;
         int x=20;
+	int c;
 
-        for(j=0;j<len;j++){
-          int c=vo_osd_text[j];
-          int font=vo_font->font[c];
-          if(font>=0)
-            draw_alpha(x,y,
-              vo_font->width[c],
-              vo_font->pic_a[font]->h,
-              vo_font->pic_b[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->w);
-          x+=vo_font->width[c]+vo_font->charspace;
+        while ((c=*cp++)!=0){
+           if ((font=vo_font->font[c])>=0)
+	      draw_alpha(x,y,
+			 vo_font->width[c],
+			 vo_font->pic_a[font]->h,
+			 vo_font->pic_b[font]->bmp+vo_font->start[c],
+			 vo_font->pic_a[font]->bmp+vo_font->start[c],
+			 vo_font->pic_a[font]->w);
+	      x+=vo_font->width[c]+vo_font->charspace;
         }
 
 }
@@ -91,94 +91,100 @@
 subtitle* vo_sub=NULL;
 
 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)){
+static subtitle *memsub=NULL;
+static int memy;
+static int memlines;
+static int memcharspace;
+static int memheight;
+static int memdxs;
+static int memdys;
+unsigned short int *up;	
     int i;
+    int j;
+    int k;
+    int x;	
     int y;
-    y=dys-(1+vo_sub->lines-1)*vo_font->height-10;
-
-    // too long lines divide into smaller ones
-    for(i=0;i<vo_sub->lines;i++){
-        unsigned char* text=vo_sub->text[i];
-        int len=strlen(text);
-	int j;
-        int xsize=-vo_font->charspace;
-	int lastStripPosition=-1;
-	int previousStrip=0;
-	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)
-	  {
-	    lastStripPosition=j;
-	    lastxsize=xsize;
-	  }
-          xsize+=w+vo_font->charspace;
-	  if (dxs<xsize && lastStripPosition>0)
-	  {
-	    xsize=lastxsize;
-	    j=lastStripPosition;
-            y-=vo_font->height;
-	    previousStrip=lastStripPosition;
-            xsize=-vo_font->charspace;
-	  }
-        }
+    int c;
+    int len;
+    int font;
+    int lastStripPosition;
+    int previousStrip;
+    int xsize;
+    int lastxsize;
+    if ((memsub!=vo_sub)||(memdxs!=dxs)||(memdys!=dys)){
+       memsub=vo_sub;
+       memdxs=dxs;
+       memdys=dys;
+       memlines=memsub->lines;
+       memcharspace=vo_font->charspace;
+       memheight=vo_font->height;
+	    
+       memy=memdys-(1+memlines-1)*memheight-10;
+
+       // too long lines divide into smaller ones
+       for (i=0;i<memlines;i++){
+	   up = (unsigned short int *)vo_sub->text[i];
+	   len= *up++;
+	   xsize=-memcharspace;
+	   lastStripPosition=-1;
+
+	   for (j=0;j<len;j++){
+	       if ((c=up[j])==' ')
+		  lastStripPosition=j;
+	       xsize+=vo_font->width[c]+memcharspace;
+	       if (dxs<xsize && lastStripPosition>0){
+		  j=lastStripPosition;
+		  memy-=memheight;
+		  xsize=-memcharspace;
+	       }
+	   }
+       }
     }
 
+    y = memy;
 
-    for(i=0;i<vo_sub->lines;i++){
-        unsigned char* text=vo_sub->text[i];//  "Hello World! H?DEJ?!";
-        int len=strlen(text);
-        int j,k;
-        int xsize=-vo_font->charspace;
-        int x=0;
-
-	int lastStripPosition=-1;
-	int previousStrip=0;
-	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];
-          if (c==' ' && dxs>xsize)
-	  {
-	    lastStripPosition=j;
-	    lastxsize=xsize;
-	  }
-          xsize+=w+vo_font->charspace;
-	  if ((dxs<xsize && lastStripPosition>0) || j==len-1)
-	  {
-	    if (j==len-1) lastStripPosition=len;
-	      else xsize=lastxsize;
-	    j=lastStripPosition;
-
-            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];
-              if(x>=0 && x+vo_font->width[c]<dxs)
-                if(font>=0)
-                  draw_alpha(x,y,
-                    vo_font->width[c],
-                    vo_font->pic_a[font]->h,
-                    vo_font->pic_b[font]->bmp+vo_font->start[c],
-                    vo_font->pic_a[font]->bmp+vo_font->start[c],
-                    vo_font->pic_a[font]->w);
-              x+=vo_font->width[c]+vo_font->charspace;
-            }
-            x=0;
-            y+=vo_font->height;
+    for (i=0;i<memlines;i++){
+        up=(unsigned short int *)vo_sub->text[i];//  "Hello World! H?DEJ?!";
+        len=*up++ - 1;
+        xsize=-memcharspace;
+	lastStripPosition=-1;
+	previousStrip=0;
+	lastxsize=xsize;
+
+	for (j=0;j<=len;j++){
+            if ((c=up[j])==' '){
+	       lastStripPosition=j;
+	       lastxsize=xsize;
+	    }
+            xsize+=vo_font->width[c]+memcharspace;
+	    if ((dxs<xsize && lastStripPosition>0)){
+	       xsize=lastxsize; 
+	       j=lastStripPosition;
+	    } else if(j==len){
+	       lastStripPosition=len;
+	       lastStripPosition++;
+	    } else
+	       continue;
+
+	    x=(dxs-xsize)>>1;
+
+	    for (k=previousStrip;k<lastStripPosition;k++){
+		c=up[k];
+		font=vo_font->font[c];
+		if (x>=0 && x+vo_font->width[c]<dxs)
+		   if (font>=0)
+		      draw_alpha(x,y,
+				 vo_font->width[c],
+				 vo_font->pic_a[font]->h,
+				 vo_font->pic_b[font]->bmp+vo_font->start[c],
+				 vo_font->pic_a[font]->bmp+vo_font->start[c],
+				 vo_font->pic_a[font]->w);
+		x+=vo_font->width[c]+memcharspace;
+	    }
+	    y+=memheight;
 	    previousStrip=lastStripPosition;
-            xsize=lastxsize=-vo_font->charspace;
-	  }
-        }
+	    xsize=lastxsize=-memcharspace;
+	}
     }
 
 }
diff -ruN MPlayer-20010801/mplayer.c MPlayer-20010801n/mplayer.c
--- MPlayer-20010801/mplayer.c	Wed Aug  1 03:02:33 2001
+++ MPlayer-20010801n/mplayer.c	Wed Aug  1 08:08:56 2001
@@ -86,6 +86,7 @@
  int nogui=1;
 #endif
 int verbose=0;
+int quiet=0;
 
 #define ABS(x) (((x)>=0)?(x):(-(x)))
 
@@ -1422,7 +1423,8 @@
       if(delay_corrected){
         float x=(a_pts-delay-audio_delay)-v_pts;
 //        printf("A:%6.1f  V:%6.1f  A-V:%7.3f",a_pts-audio_delay-delay,v_pts,x);
-        printf("A:%6.1f (%6.1f)  V:%6.1f  A-V:%7.3f",a_pts,a_pts-audio_delay-delay,v_pts,x);
+	if (!quiet)
+	   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
         if(x> max_pts_correction) x= max_pts_correction;
@@ -1431,28 +1433,30 @@
         else
           max_pts_correction=sh_video->frametime*0.10; // +-10% of time
         sh_audio->timer+=x; c_total+=x;
-        printf(" ct:%7.3f  %3d  %2d%% %2d%% %4.1f%% %d\r",c_total,
-        (int)sh_video->num_frames,
-        (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
-        (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0,
-        (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0
-        ,drop_frame_cnt
-        );
-        fflush(stdout);
+	if (!quiet){
+           printf(" ct:%7.3f  %3d  %2d%% %2d%% %4.1f%% %d\r",c_total,
+		  (int)sh_video->num_frames,
+		  (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
+		  (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0,
+		  (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0
+		  ,drop_frame_cnt
+		  );
+	   fflush(stdout);
+	}
       }
     
   } else {
     // No audio:
-    
-      printf("V:%6.1f  %3d  %2d%%  %2d%%  %3.1f%% \r",d_video->pts,
-        (int)sh_video->num_frames,
-        (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
-        (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0,
-        (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0
-        );
-
-      fflush(stdout);
+      if (!quiet){
+         printf("V:%6.1f  %3d  %2d%%  %2d%%  %3.1f%% \r",d_video->pts,
+		(int)sh_video->num_frames,
+		(sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0,
+		(sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0,
+		(sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0
+		);
 
+	 fflush(stdout);
+      }
   }
 #endif
 
diff -ruN MPlayer-20010801/subreader.c MPlayer-20010801n/subreader.c
--- MPlayer-20010801/subreader.c	Sat Jun  9 22:09:18 2001
+++ MPlayer-20010801n/subreader.c	Wed Aug  1 08:50:34 2001
@@ -14,6 +14,9 @@
 
 #include "subreader.h"
 
+extern int sub_unicode;
+extern int sub_utf8;
+
 #define ERR (void *)-1
 
 
@@ -372,6 +375,52 @@
     return -1;  // too many bad lines
 }
 
+#define MAX_UCS2_TABLE 1024
+
+static inline int generateints(subtitle *csub) {
+    int i,l,r;
+    unsigned char *t;
+    unsigned short int u;
+    unsigned short int *up;
+    unsigned short int ut[MAX_UCS2_TABLE];	
+    unsigned short int *d;
+    unsigned short int *s;
+    
+    for (r=1,i=0;i<csub->lines;i++){
+	 for (l=0,t=csub->text[i];*t!='\0';t++){
+	     if ((u=*t)>=0x80){
+	        if (sub_unicode) u = (u<<8) | *++t; else
+		if (sub_utf8) {
+		   if ((u & 0xe0) == 0xc0)     /* 2 bytes U+00080..U+0007FF */
+		      u = (u & 0x1f)<<6 | 
+			  (*++t & 0x3f); 
+		   else if ((u & 0xf0) == 0xe0)/* 3 bytes U+00800..U+00FFFF */
+		      u = ((u & 0x0f)<<6 | 
+			  (*++t & 0x3f))<<6 |
+			  (*++t & 0x3f);
+		}
+	     }
+	     ut[l++]=u;
+	     if (l==MAX_UCS2_TABLE){
+		printf("\nError - subtitles line too long - cutting\n");
+		break;
+	     }
+	 }
+	 if ((up = malloc((l+1)*sizeof(unsigned short int)))==NULL){
+	    printf("\nError alocating memory for unicode subtitles\n");
+	    r=0;
+	    break; 
+	 } else {
+	   up[0]=l; 			    	   /* store length */
+	   for (d=up+1,s=ut;l>0;l--) *d++=*s++;    /* store ints */
+	   free(csub->text[i]); 		   /* free unused mem */
+	   csub->text[i]=(char *)up; 	 	   /* memorize ints */
+	 }
+    }
+    if (!r)
+       for (i=0;i<csub->lines;i++) free(csub->text[i]); /* free mem on error */
+    return r;
+}
 
 subtitle* sub_read_file (char *filename) {
     FILE *fd;
@@ -409,6 +458,7 @@
         }
         sub=func[sub_format](fd,&first[sub_num]);
         if(!sub) break;   // EOF
+	if ((sub!=ERR) && !generateints(sub)) sub=ERR;    
         if(sub==ERR) ++sub_errs; else ++sub_num; // Error vs. Valid
     }
     
-------------- next part --------------
diff -ruN MPlayer-20010801/libvo/font_load.c MPlayer-20010801n/libvo/font_load.c
--- MPlayer-20010801/libvo/font_load.c	Fri Jul 20 04:03:50 2001
+++ MPlayer-20010801n/libvo/font_load.c	Wed Aug  1 07:33:49 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,12 @@
 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;}
 
+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;
-------------- next part --------------
diff -ruN MPlayer-20010801/libvo/x11_common.c MPlayer-20010801n/libvo/x11_common.c
--- MPlayer-20010801/libvo/x11_common.c	Sun Jul 29 18:40:32 2001
+++ MPlayer-20010801n/libvo/x11_common.c	Wed Aug  1 08:04:14 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;


More information about the MPlayer-users mailing list