[Mplayer-users] small changes to MPlayer-20010723

Adam Tla/lka atlka at pg.gda.pl
Thu Jul 26 14:40:44 CEST 2001


Hello again,

I corrected my previous patch which now implements:                                                
* reading subtitles text encoded in utf8 (option -utf8) is done in subreader.c
  just while reading the subtitles file (not in generating subtitles function)
* changes in sub.c leading to calculating y position only once while
  displaying the same subtitle text on the screen
* reading fonts files from LIBDIR/font if there is no font dir in ~/.mplayer    
* not displaying status while "-q" or "-quiet" 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)
* better detection of local display connection ("unix:" and "localhost:" are    
  assumed local and automagically changed to ":"). Maybe it's not quite correct
  but I like to use shm while on the same machine.       

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-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	Thu Jul 26 13:28:20 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},
@@ -182,6 +185,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-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	Thu Jul 26 12:57:50 2001
@@ -5,33 +5,31 @@
 font_desc_t* vo_font=NULL;
 
 unsigned char* vo_osd_text="00:00:00";
-int sub_unicode=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);
+static inline 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)){
+	unsigned char *v=vo_osd_text;
+        int c;
         int j;
+	int font;
         int y=10;
         int x=20;
 
-        for(j=0;j<len;j++){
-          int c=vo_osd_text[j];
-          int font=vo_font->font[c];
-          if(font>=0)
+        for(;(c=*v)!=0;v++)
+          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;
-        }
-
+	    x+=vo_font->width[c]+vo_font->charspace;
+	  }
 }
 
 int vo_osd_progbar_type=-1;
 int vo_osd_progbar_value=100;   // 0..255
 
-static void vo_draw_text_progbar(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
+static inline void vo_draw_text_progbar(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=dys/2;
         int x;
@@ -42,8 +40,7 @@
         x=(dxs-width)/2;
 //        printf("osd.progbar  width=%d  xpos=%d\n",width,x);
 
-        c=vo_osd_progbar_type;font=vo_font->font[c];
-        if(vo_osd_progbar_type>0 && font>=0)
+        if((c=vo_osd_progbar_type)>0 && (font=vo_font->font[c])>=0)
             draw_alpha(x-vo_font->width[c]-vo_font->spacewidth,y,
               vo_font->width[c],
               vo_font->pic_a[font]->h,
@@ -51,19 +48,20 @@
               vo_font->pic_a[font]->bmp+vo_font->start[c],
               vo_font->pic_a[font]->w);
 
-        c=OSD_PB_START;font=vo_font->font[c];
-        if(font>=0)
+        c=OSD_PB_START;
+        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];
+	  x+=vo_font->width[c];
+	}
 
         for(i=0;i<elems;i++){
-          c=(i<mark)?OSD_PB_0:OSD_PB_1;font=vo_font->font[c];
-          if(font>=0)
+          c=(i<mark)?OSD_PB_0:OSD_PB_1;
+          if((font=vo_font->font[c])>=0)
             draw_alpha(x,y,
               vo_font->width[c],
               vo_font->pic_a[font]->h,
@@ -73,8 +71,8 @@
           x+=vo_font->width[c];
         }
 
-        c=OSD_PB_END;font=vo_font->font[c];
-        if(font>=0)
+        c=OSD_PB_END;
+        if((font=vo_font->font[c])>=0)
             draw_alpha(x,y,
               vo_font->width[c],
               vo_font->pic_a[font]->h,
@@ -91,65 +89,85 @@
 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;	
     int i;
+    int j;
+    int k;
+    int x;
     int y;
-    y=dys-(1+vo_sub->lines-1)*vo_font->height-10;
+    int c;
+    int len;
+    int font;
+    int *intp;
+    int lastStripPosition;
+    int previousStrip;
+    int xsize;
+    int lastxsize;
+
+    if(memsub!=vo_sub) { /* calculate y-position if needed */
+	    
+    memsub=vo_sub;
+    memlines=vo_sub->lines;
+    memcharspace=vo_font->charspace;
+    memheight=vo_font->height;
+	    
+    y=dys-(1+memlines-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(i=0;i<memlines>0;i++){
+        xsize=-memcharspace;
+	lastStripPosition=-1;
+	previousStrip=0;
+	lastxsize=0;
+
+	intp=(int *)vo_sub->text[i];
+	len=*intp++;
+	    
 	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)
+	  c=intp[j];
+	  if (c==' ' && dxs>xsize)
 	  {
 	    lastStripPosition=j;
 	    lastxsize=xsize;
 	  }
-          xsize+=w+vo_font->charspace;
+          xsize+=vo_font->width[c]+memcharspace;
 	  if (dxs<xsize && lastStripPosition>0)
 	  {
 	    xsize=lastxsize;
 	    j=lastStripPosition;
-            y-=vo_font->height;
+            y-=memheight;
 	    previousStrip=lastStripPosition;
-            xsize=-vo_font->charspace;
+            xsize=-memcharspace;
 	  }
         }
     }
 
-
-    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;
-
+      memy = y;
+    } /* calculate y-position if needed */ else
+      y = memy;
+	
+    for(i=0;i<memlines;i++){
+        xsize=-memcharspace;
+	lastStripPosition=-1;
+	previousStrip=0;
+	lastxsize=xsize;
+	x=0;
+	
+	intp=(int *)vo_sub->text[i];
+	len=*intp++;	    
+	    
 	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];
+	  c=intp[j];
           if (c==' ' && dxs>xsize)
 	  {
 	    lastStripPosition=j;
 	    lastxsize=xsize;
 	  }
-          xsize+=w+vo_font->charspace;
+          xsize+=vo_font->width[c]+memcharspace;
 	  if ((dxs<xsize && lastStripPosition>0) || j==len-1)
 	  {
 	    if (j==len-1) lastStripPosition=len;
@@ -159,10 +177,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];
+	      c = intp[k] ;
+	      font=vo_font->font[c];
               if(x>=0 && x+vo_font->width[c]<dxs)
                 if(font>=0)
                   draw_alpha(x,y,
@@ -171,12 +187,12 @@
                     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+=vo_font->width[c]+memcharspace;
             }
             x=0;
-            y+=vo_font->height;
+            y+=memheight;
 	    previousStrip=lastStripPosition;
-            xsize=lastxsize=-vo_font->charspace;
+            xsize=lastxsize=-memcharspace;
 	  }
         }
     }
@@ -186,6 +202,7 @@
 static int draw_alpha_init_flag=0;
 
 extern void vo_draw_alpha_init();
+
 
 void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
 
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	Thu Jul 26 13:30:59 2001
@@ -76,6 +76,7 @@
  int nogui=1;
 #endif
 int verbose=0;
+int quiet=0;
 
 #define ABS(x) (((x)>=0)?(x):(-(x)))
 
@@ -557,13 +558,12 @@
 
 // check font
   if(font_name){
-       vo_font=read_font_desc(font_name,font_factor,verbose>1);
-       if(!vo_font) fprintf(stderr,"Can't load font: %s\n",font_name);
+       if(!(vo_font=read_font_desc(font_name,font_factor,verbose>1)))
+	 fprintf(stderr,"Can't load font: %s\n",font_name);
   } else {
       // try default:
-       vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1);
-       if(!vo_font)
-       vo_font=read_font_desc(DATADIR"/font/font.desc",font_factor,verbose>1);
+       if(!(vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1)))
+	 vo_font=read_font_desc(DATADIR"/font/font.desc",font_factor,verbose>1);
   }
 
 // check .sub
@@ -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(!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
@@ -1359,6 +1360,7 @@
         else
           max_pts_correction=sh_video->frametime*0.10; // +-10% of time
         sh_audio->timer+=x; c_total+=x;
+	if(!quiet)      
         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(!quiet) 
       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(!quiet) {      
+          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(!quiet)      
+           printf("A: ---   V:%6.1f   \r",d_video->pts);fflush(stdout);
       }
 
         // Set OSD:
diff -ruN MPlayer-20010723/subreader.c MPlayer-20010723n/subreader.c
--- MPlayer-20010723/subreader.c	Sat Jun  9 22:09:18 2001
+++ MPlayer-20010723n/subreader.c	Thu Jul 26 14:00:09 2001
@@ -16,7 +16,8 @@
 
 #define ERR (void *)-1
 
-
+int sub_unicode = 0;
+int sub_utf8 = 0;
 int sub_uses_time=0;
 int sub_errs=0;
 int sub_num=0;          // number of subtitle structs
@@ -372,6 +373,56 @@
     return -1;  // too many bad lines
 }
 
+#define MAX_INTS_TABLE 1024
+
+static inline int generateints(subtitle *csub) {
+    int i,l,c,r;
+    unsigned char *t;
+    int *intp;
+    int intt[MAX_INTS_TABLE];
+    int *d;
+    int *s;
+    
+    for(r=1,i=0;i<csub->lines;i++) {
+	 for(l=0,t=csub->text[i];*t!='\0';t++) {
+	    if((c=*t)>=0x80) {
+	      if(sub_unicode) c = (c<<8) + *++t; else
+	      if(sub_utf8) {
+		if((c & 0xe0) == 0xc0)      /* 2 bytes U+00080..U+0007FF */
+		    c = (c & 0x1f)<<6 | 
+			(*++t & 0x3f); 
+		else if((c & 0xf0) == 0xe0) /* 3 bytes U+00800..U+00FFFF */
+		    c = ((c & 0x0f)<<6 | 
+			(*++t & 0x3f))<<6 |
+			(*++t & 0x3f);
+		else if((c & 0xf8) == 0xf0) /* 4 bytes U+10000..U+10FFFF */
+		    c = (((c & 0x07)<<6 | 
+			(*++t & 0x3f))<<6 |
+			(*++t & 0x3f))<<6 |
+			(*++t & 0x3f);
+	      }
+	    }
+	    intt[l++]=c;
+	    if(l==MAX_INTS_TABLE) {
+		    printf("\nError - subtitles line too long - cutting\n");
+		    break;
+	    } 
+	 }
+	 if((intp=malloc((l+1)*sizeof(int)))==NULL) {
+	    printf("\nError alocating memory for unicode subtitles\n");
+	    r=0;
+	    break; 
+	 } else {
+	   intp[0]=l; 			    	   /* store length */
+	   for(d=intp+1,s=intt;l>0;l--) *d++=*s++; /* store ints */
+	   free(csub->text[i]); 		   /* free unused mem */
+	   csub->text[i]=(char *)intp; 	 	   /* 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 +460,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
     }
     
@@ -527,4 +579,5 @@
     printf ("Read %i subtitles, %i errors.\n", sub_num, sub_errs);
     return 0;
 }
+
 #endif


More information about the MPlayer-users mailing list