[MPlayer-dev-eng] [patch] dvdnav check during event processing

Kees Cook mplayer at outflux.net
Sun Apr 7 18:41:55 CEST 2002


If you had compiled --with-libdvdnav, but were not playing -dvdnav, any 
dvdnav key events would crash mplayer.  This patch fixes it.

Also, I've included an updated "box" patch that should NOT be applied, and 
is only for other people playing with dvdnav and want to see the menu 
button boxes.

-- 
Kees Cook                                            @outflux.net
-------------- next part --------------
diff -ur MPlayer-20020406-clean/mplayer.c MPlayer-20020406-bug/mplayer.c
--- MPlayer-20020406-clean/mplayer.c	Thu Apr  4 06:44:47 2002
+++ MPlayer-20020406-bug/mplayer.c	Sun Apr  7 09:37:32 2002
@@ -2485,6 +2485,9 @@
       dvdnav_priv_t * dvdnav_priv = (dvdnav_priv_t*)(stream->priv);
       dvdnav_event_t * dvdnav_event = (dvdnav_event_t *)(cmd->args[0].v.v);
 
+      /* ignore these events if we're not in dvd_nav mode */
+      if (!dvd_nav) break;
+
       if (!dvdnav_event) {
         printf("DVDNAV Event NULL?!\n");
         break;
@@ -2638,6 +2641,9 @@
     case MP_CMD_DVDNAV: {
       dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
 
+      /* ignore these events if we're not in dvd_nav mode */
+      if (!dvd_nav) break;
+
       switch (cmd->args[0].v.i) {
         case MP_CMD_DVDNAV_UP:
           dvdnav_upper_button_select(dvdnav_priv->dvdnav);
-------------- next part --------------
diff -ur MPlayer-20020406-clean/libvo/sub.c MPlayer-20020406-dvdnav/libvo/sub.c
--- MPlayer-20020406-clean/libvo/sub.c	Sat Mar 23 16:32:13 2002
+++ MPlayer-20020406-dvdnav/libvo/sub.c	Sat Apr  6 21:51:33 2002
@@ -6,6 +6,8 @@
 
 #include <stdlib.h>
 
+#include "../libmpdemux/stream.h"
+
 char * __sub_osd_names[]={
     "Seekbar",
     "Play",
@@ -51,6 +53,110 @@
 
 }
 
+/* draws a line from sx,sy to ex,ey */
+inline static void vo_osd_draw_line(int dxs, int dys, unsigned char color, int width,
+                                    int sx, int sy, int ex, int ey,
+                                    void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
+        int cx, cy, i; /* current x,y location */
+        int xspan, yspan; /* how far they need to go */
+        float xwhole, ywhole; /* how large is a "whole" step */
+        float xstep, ystep; /* x, y steps */
+        float xcounter, ycounter;
+        unsigned char bitmap[36];
+        unsigned char alphamap[36];
+
+        if (!vo_font) return;
+
+        if (width>6) width=6;
+        if (width<1) width=1;
+        for (i=0;i<width*width;i++) {
+          bitmap[i]=color;
+          alphamap[i]=1;
+        }
+
+        /* stay within screen */
+        if (sx>=dxs) sx=dxs-1;
+        if (ex>=dxs) ex=dxs-1;
+        if (sy>=dys) sy=dys-1;
+        if (ey>=dys) ey=dys-1;
+        if (sx<0) sx=0;
+        if (ex<0) ex=0;
+        if (sy<0) sy=0;
+        if (ey<0) ey=0;
+
+        /* only draw left to right */
+        if ( sx > ex ) {
+                int tmp;
+                tmp=sx;
+                sx=ex;
+                ex=tmp;
+                tmp=sy;
+                sy=ey;
+                ey=tmp;
+        }
+
+        xspan=ex-sx;
+        yspan=ey-sy;
+
+        if (xspan==0 && yspan==0)
+                return; /* nothing to draw! */
+
+        xwhole=ywhole=1.0;
+
+        // invert the y drawing if need to go bottom to top
+        if (yspan<0) {
+                yspan=0-yspan;
+                ywhole*=-1;
+        }
+
+        if (xspan>yspan) {
+                xstep=xwhole;
+                ystep=(float)ywhole*(float)yspan/(float)xspan;
+        }
+        else {
+                xstep=(float)xwhole*(float)xspan/(float)yspan;
+                ystep=ywhole;
+        }
+
+        cx=sx;
+        cy=sy;
+        xcounter=ycounter=0.0;
+        if (ywhole>0.0) {
+            while (cx<=ex && cy<=ey) {
+                //printf("pixel: %d,%d\n",cx,cy);
+                /* draw the "pixel" */
+                draw_alpha(cx,cy,width,width,bitmap,alphamap,1);
+
+                /* update the positions */
+                if ((xcounter+=xstep)>=xwhole) {
+                        xcounter-=xwhole;
+                        cx+=xwhole;
+                }
+                if ((ycounter+=ystep)>=ywhole) {
+                        ycounter-=ywhole;
+                        cy+=ywhole;
+                }
+            }
+        }
+        else {
+            while (cx<=ex && cy>=ey) {
+                //printf("pixel: %d,%d\n",cx,cy);
+                /* draw the "pixel" */
+                draw_alpha(cx,cy,width,width,bitmap,alphamap,1);
+
+                /* update the positions */
+                if ((xcounter+=xstep)>=xwhole) {
+                        xcounter-=xwhole;
+                        cx+=xwhole;
+                }
+                if ((ycounter+=ystep)<=ywhole) {
+                        ycounter-=ywhole;
+                        cy+=ywhole;
+                }
+            }
+        }
+}
+
 int vo_osd_progbar_type=-1;
 int vo_osd_progbar_value=100;   // 0..256
 
@@ -319,6 +425,35 @@
         vo_draw_text_progbar(dxs,dys,draw_alpha);
     }
 
+    if (osd_show_dvd_nav_highlight) {
+        /* black borders */
+        vo_osd_draw_line(dxs,dys,0x0,3, /* |   left */
+                        osd_show_dvd_nav_sx-1,osd_show_dvd_nav_sy-1,
+                        osd_show_dvd_nav_sx-1,osd_show_dvd_nav_ey-1,draw_alpha);
+        vo_osd_draw_line(dxs,dys,0x0,3, /*   | right */
+                        osd_show_dvd_nav_ex-1,osd_show_dvd_nav_sy-1,
+                        osd_show_dvd_nav_ex-1,osd_show_dvd_nav_ey-1,draw_alpha);
+        vo_osd_draw_line(dxs,dys,0x0,3, /* --- top */
+                        osd_show_dvd_nav_sx-1,osd_show_dvd_nav_sy-1,
+                        osd_show_dvd_nav_ex-1,osd_show_dvd_nav_sy-1,draw_alpha);
+        vo_osd_draw_line(dxs,dys,0x0,3, /* ___ bottom */
+                        osd_show_dvd_nav_sx-1,osd_show_dvd_nav_ey-1,
+                        osd_show_dvd_nav_ex-1,osd_show_dvd_nav_ey-1,draw_alpha);
+        /* white centers */
+        vo_osd_draw_line(dxs,dys,0xff,1, /* |   left */
+                        osd_show_dvd_nav_sx,osd_show_dvd_nav_sy,
+                        osd_show_dvd_nav_sx,osd_show_dvd_nav_ey,draw_alpha);
+        vo_osd_draw_line(dxs,dys,0xff,1, /*   | right */
+                        osd_show_dvd_nav_ex,osd_show_dvd_nav_sy,
+                        osd_show_dvd_nav_ex,osd_show_dvd_nav_ey,draw_alpha);
+        vo_osd_draw_line(dxs,dys,0xff,1, /* --- top */
+                        osd_show_dvd_nav_sx,osd_show_dvd_nav_sy,
+                        osd_show_dvd_nav_ex,osd_show_dvd_nav_sy,draw_alpha);
+        vo_osd_draw_line(dxs,dys,0xff,1, /* ___ bottom */
+                        osd_show_dvd_nav_sx,osd_show_dvd_nav_ey,
+                        osd_show_dvd_nav_ex,osd_show_dvd_nav_ey,draw_alpha);
+    }
+
 }
          
 static int vo_osd_changed_status = 0;


More information about the MPlayer-dev-eng mailing list