[MPlayer-dev-eng] [patch] DVD NAV work continues...

Kees Cook mplayer at outflux.net
Sun Mar 31 09:16:34 CEST 2002


Here is my continuing work for DVD nav support.

A few things happen in this patch, some of which I may need to slapped on 
the wrist for and told how to deal with better...

- I needed a way to feed d_dvdsub->id changes into mplayer.c from 
  libmpdemux/stream.c where the various DVDNAV events are seen.  As
  a result, I made mp_input_parse_cmd visible, and used that to feed
  input to mplayer.c.  And then I added a command to change the active
  sid.  And it works!  :P
- I tried to do this for the active audio channel too, but there is a
  disconnect between dvdnav and mplayer on stream numbering that I'm still 
  working on.
- I have the caching subsystem check the STREAMTYPE_*, and skips if
  it sees a DVDNAV stream.
- I fixed the stream seeking to not rewind a DVDNAV stream, since this
  seemed to corrupt things pretty badly.  I've left the arrow keys active
  for now, but they'll be disabled at some point (maybe).
- Since I'm still working on getting menu navigation visible the Right 
  way, I hacked in some code to draw lines around the menu box.  Since
  I don't have the brain power to understand the draw_alpha routines
  right now, I hacked together a "line drawing" routine using font
  characters.  :)  With that routine, I draw the menu box.  Unfortunately,
  you have to move the menu around at least once before it appears (this
  is due to DVDNAV events...)
- I added an option to skip all still-image timers since still images
  don't work yet.  ("-skipopening")

This patch is against 20020331.

-- 
Kees Cook                                            @outflux.net
-------------- next part --------------
diff --exclude=CVS -ur MPlayer-20020331-clean/cfg-common.h MPlayer-20020331-dvdnav/cfg-common.h
--- MPlayer-20020331-clean/cfg-common.h	Thu Mar 28 19:17:57 2002
+++ MPlayer-20020331-dvdnav/cfg-common.h	Sat Mar 30 20:43:19 2002
@@ -14,7 +14,8 @@
 	{"vcd", "VCD support is NOT available on this system!\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
 #endif
 #ifdef USE_DVDNAV
-	{"dvdnav", &dvd_nav, CONF_TYPE_FLAG, 0, 0, 1},
+	{"dvdnav", &dvd_nav, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+	{"skipopening", &dvd_nav_skip_opening, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 #endif
 #ifdef USE_DVDREAD
 	{"dvd-device", &dvd_device,  CONF_TYPE_STRING, 0, 0, 0, NULL}, 
diff --exclude=CVS -ur MPlayer-20020331-clean/input/input.c MPlayer-20020331-dvdnav/input/input.c
--- MPlayer-20020331-clean/input/input.c	Thu Mar 28 12:40:21 2002
+++ MPlayer-20020331-dvdnav/input/input.c	Sat Mar 30 23:13:57 2002
@@ -78,8 +78,10 @@
 
 #ifdef USE_DVDNAV
   { MP_CMD_DVDNAV, "dvdnav", 1, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
+  { MP_CMD_CHANGE_AID, "aid", 1, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
+  { MP_CMD_CHANGE_SID, "sid", 1, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
 #endif
-  
+
   { 0, NULL, 0, {} }
 };
 
@@ -394,7 +396,7 @@
 
 
 
-static mp_cmd_t*
+mp_cmd_t*
 mp_input_parse_cmd(char* str) {
   int i,l;
   char *ptr,*e;
diff --exclude=CVS -ur MPlayer-20020331-clean/input/input.h MPlayer-20020331-dvdnav/input/input.h
--- MPlayer-20020331-clean/input/input.h	Thu Mar 28 12:40:21 2002
+++ MPlayer-20020331-dvdnav/input/input.h	Sat Mar 30 20:50:10 2002
@@ -25,6 +25,8 @@
 #define MP_CMD_VO_FULLSCREEN 20
 #define MP_CMD_SUB_POS 21
 #define MP_CMD_DVDNAV 22
+#define MP_CMD_CHANGE_AID 23
+#define MP_CMD_CHANGE_SID 24
 
 #define MP_CMD_GUI_EVENTS       5000
 #define MP_CMD_GUI_LOADFILE     5001
@@ -155,6 +157,11 @@
 mp_cmd_t*
 mp_cmd_clone(mp_cmd_t* cmd);
 
+// This will parse a string into a command.  Can be injected via mp_input_queue_cmd
+mp_cmd_t*
+mp_input_parse_cmd(char* str);
+
+
 // When you create a new driver you should add it in this 2 functions.
 void
 mp_input_init(void);
diff --exclude=CVS -ur MPlayer-20020331-clean/libmpdemux/cache2.c MPlayer-20020331-dvdnav/libmpdemux/cache2.c
--- MPlayer-20020331-clean/libmpdemux/cache2.c	Sat Feb 23 13:22:55 2002
+++ MPlayer-20020331-dvdnav/libmpdemux/cache2.c	Thu Mar 28 23:07:17 2002
@@ -232,7 +232,7 @@
 int cache_stream_fill_buffer(stream_t *s){
   int len;
   if(s->eof){ s->buf_pos=s->buf_len=0; return 0; }
-  if(!s->cache_pid) return stream_fill_buffer(s);
+  if(!s->cache_pid || s->type==STREAMTYPE_DVDNAV) return stream_fill_buffer(s);
 
 //  cache_stats(s->cache_data);
 
diff --exclude=CVS -ur MPlayer-20020331-clean/libmpdemux/demuxer.c MPlayer-20020331-dvdnav/libmpdemux/demuxer.c
--- MPlayer-20020331-clean/libmpdemux/demuxer.c	Sat Mar 30 18:45:14 2002
+++ MPlayer-20020331-dvdnav/libmpdemux/demuxer.c	Sat Mar 30 20:11:27 2002
@@ -264,6 +264,7 @@
   if(verbose>2){
     if(ds==demux->audio) mp_dbg(MSGT_DEMUXER,MSGL_DBG3,"ds_fill_buffer(d_audio) called\n");else
     if(ds==demux->video) mp_dbg(MSGT_DEMUXER,MSGL_DBG3,"ds_fill_buffer(d_video) called\n");else
+    if(ds==demux->sub)   mp_dbg(MSGT_DEMUXER,MSGL_DBG3,"ds_fill_buffer(d_sub) called\n");else
                          mp_dbg(MSGT_DEMUXER,MSGL_DBG3,"ds_fill_buffer(unknown 0x%X) called\n",(unsigned int)ds);
   }
   while(1){
diff --exclude=CVS -ur MPlayer-20020331-clean/libmpdemux/open.c MPlayer-20020331-dvdnav/libmpdemux/open.c
--- MPlayer-20020331-clean/libmpdemux/open.c	Thu Mar 28 14:45:09 2002
+++ MPlayer-20020331-dvdnav/libmpdemux/open.c	Sat Mar 30 20:11:27 2002
@@ -31,7 +31,15 @@
 int dvd_angle=1;
 char* dvd_device=NULL;
 char* cdrom_device=NULL;
-int dvd_nav=0;
+int dvd_nav=0;                  /* use libdvdnav? */
+int dvd_nav_skip_opening=0;     /* skip opening stalls? */
+int osd_show_dvd_nav_delay=0;   /* count down for dvd nav text on OSD */
+char dvd_nav_text[50];          /* for reporting stuff to OSD */
+int osd_show_dvd_nav_highlight; /* show highlight area */
+int osd_show_dvd_nav_sx;        /* start x .... */
+int osd_show_dvd_nav_ex;
+int osd_show_dvd_nav_sy;
+int osd_show_dvd_nav_ey;
 
 #ifdef USE_DVDNAV
 #include <dvdnav.h>
@@ -117,20 +125,35 @@
 //============ Open DVD title ==============
 #ifdef USE_DVDNAV
 if(dvd_nav){
+    char * title_str;
+    dvdnav_priv_t *dvdnav_priv;
     dvdnav_t *dvdnav;
     int event,len,tmplen=0;
+
     if(!filename) filename=DEFAULT_DVD_DEVICE;
     if(dvdnav_open(&dvdnav,filename)!=DVDNAV_STATUS_OK) {
 	mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CantOpenDVD,filename);
         return NULL;
     }
 
+    /* turn on dvdnav caching */
+    dvdnav_set_readahead_flag(dvdnav,1);
+
     stream=new_stream(-1,STREAMTYPE_DVDNAV);
     if (!stream) {
         mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_Exit_error);
         return NULL;
     }
-    stream->priv=(void*)dvdnav;
+
+    if (dvdnav_get_title_string(dvdnav,&title_str)==DVDNAV_STATUS_OK) {
+        mp_msg(MSGT_OPEN,MSGL_INFO,"Title: '%s'\n",title_str);
+    } 
+
+    dvdnav_priv=(dvdnav_priv_t*)malloc(sizeof(dvdnav_priv_t)); memset(dvdnav_priv,0,sizeof(*dvdnav_priv));
+    dvdnav_priv->dvdnav=dvdnav;
+    dvdnav_priv->skip_opening_timers=dvd_nav_skip_opening; // ignore damned copyright timers?
+
+    stream->priv=(void*)dvdnav_priv;
     return stream;
 }
 #endif
diff --exclude=CVS -ur MPlayer-20020331-clean/libmpdemux/stream.c MPlayer-20020331-dvdnav/libmpdemux/stream.c
--- MPlayer-20020331-clean/libmpdemux/stream.c	Thu Mar 28 15:14:14 2002
+++ MPlayer-20020331-dvdnav/libmpdemux/stream.c	Sat Mar 30 20:39:13 2002
@@ -16,6 +16,8 @@
 #include "stream.h"
 #include "demuxer.h"
 
+#include "../input/input.h"
+
 extern int verbose; // defined in mplayer.c
 
 #ifdef HAVE_VCD
@@ -29,7 +31,6 @@
 #endif
 
 #ifdef USE_DVDNAV
-#include <dvdnav.h>
 #include <../linux/timer.h>
 static int still_sleep_until;
 static int sleeping=0;
@@ -68,14 +69,21 @@
 #endif
 #ifdef USE_DVDNAV
   case STREAMTYPE_DVDNAV: {
+    dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)s->priv;
     int event = DVDNAV_NOP;
+
     if(sleeping)
     {
-      dvdnav_still_skip(s->priv);
-      if(sleeping==1) if(GetTimer()>=still_sleep_until) sleeping = 0;
+      while((!dvdnav_priv->skip_opening_timers || dvdnav_priv->seen_root_menu) &&
+            GetTimer()<still_sleep_until) {
+        usec_sleep(1000); /* 1ms granularity */
+        return 0; // returns with 0 bytes added to buffer until timer finishes
+      }
+      dvdnav_still_skip(dvdnav_priv->dvdnav);
+      sleeping=0;
       len = stillen;
     }
-    if(dvdnav_get_next_block(s->priv,s->buffer,&event,&len)!=DVDNAV_STATUS_OK)
+    if(dvdnav_get_next_block(dvdnav_priv->dvdnav,s->buffer,&event,&len)!=DVDNAV_STATUS_OK)
       printf( "Error getting next block from DVD (%s)\n",dvdnav_err_to_string(s->priv) );
     else switch(event) {
       case DVDNAV_BLOCK_OK: {
@@ -85,74 +93,127 @@
       case DVDNAV_HIGHLIGHT: {
           dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t*)(s->buffer);
           if (!hevent) {
-                printf("Highlight event broken\n");
+                printf("DVDNAV Event: Highlight event broken\n");
                 break;
           }
 
-          if (hevent->display)
+          if (hevent->display && hevent->buttonN>0)
           {
-    	        printf( "Highlight (%u,%u)-(%u,%u) (button %d)\n",
+                dvdnav_priv->seen_root_menu=1; /* if we got a highlight, we're on a menu */
+    	        sprintf( dvd_nav_text, "Highlight (%u,%u)-(%u,%u) (button %d)",
                      hevent->sx,hevent->sy,
                      hevent->ex,hevent->ey,
                      hevent->buttonN );
+                printf("DVDNAV Event: %s\n",dvd_nav_text);
+                //osd_show_dvd_nav_delay = 60;
+
+                osd_show_dvd_nav_highlight=1;
+                osd_show_dvd_nav_sx=hevent->sx;
+                osd_show_dvd_nav_ex=hevent->ex;
+                osd_show_dvd_nav_sy=hevent->sy;
+                osd_show_dvd_nav_ey=hevent->ey;
           }
           else {
-                  printf("Highlight Hide\n");
+                  osd_show_dvd_nav_highlight=0;
+                  printf("DVDNAV Event: Highlight Hide\n");
           }
         break;
         }
       case DVDNAV_STILL_FRAME: {
           dvdnav_still_event_t *still_event = (dvdnav_still_event_t*)(s->buffer);
-          printf( "Still Frame\n" );
+
+          printf( "DVDNAV Event: Still Frame\n" );
 	  if(still_event->length==0xff) { printf( "Sleeping indefinately\n" ); sleeping=2; }
 	  else  {
-	    InitTimer();
+	    InitTimer(); // FIXME: is this needed here?
 	    still_sleep_until = GetTimer() + still_event->length*1000000;
 	    printf( "Sleeping %d sec(s)\n", still_event->length );
 	    sleeping=1;
 	  }
-          stillen = len;          
+          stillen = len;
 	break;
         }
       case DVDNAV_STOP: {
-          printf( "Nav Stop\n" );
+          printf( "DVDNAV Event: Nav Stop\n" );
           len=0;
 	break;
         }
       case DVDNAV_NOP: {
-        printf("Nav NOP\n");
+        printf("DVDNAV Event: Nav NOP\n");
 	break;
         }
       case DVDNAV_SPU_STREAM_CHANGE: {
-        printf("Nav SPU Stream Change\n");
+        mp_cmd_t * cmd;
+        char buf[16];
+        dvdnav_stream_change_event_t * stream_change=(dvdnav_stream_change_event_t*)(s->buffer);
+
+        printf("DVDNAV Event: Nav SPU Stream Change: phys: %d logical: %d\n",
+                stream_change->physical,
+                stream_change->logical);
+
+        // activate this SPU in the decoder
+        sprintf(buf,"sid %d",stream_change->physical);
+        cmd=mp_input_parse_cmd(buf);
+        if (cmd)
+          mp_input_queue_cmd(cmd);
+        else
+          printf("could not queue command\n");
+
 	break;
         }
       case DVDNAV_AUDIO_STREAM_CHANGE: {
-        printf("Nav Audio Stream Change\n");
+        mp_cmd_t * cmd;
+        char buf[16];
+        dvdnav_stream_change_event_t *stream_change = (dvdnav_stream_change_event_t*)(s->buffer);
+
+        printf("DVDNAV Event: Nav Audio Stream Change: phys: %d logical: %d\n",
+                stream_change->physical,
+                stream_change->logical);
+
+        // activate this AID in the decoder
+        sprintf(buf,"aid %d",stream_change->physical);
+        cmd=mp_input_parse_cmd(buf);
+        if (cmd)
+          mp_input_queue_cmd(cmd);
+        else
+          printf("could not queue command\n");
+
 	break;
         }
       case DVDNAV_VTS_CHANGE: {
-        printf("Nav VTS Change\n");
+        printf("DVDNAV Event: Nav VTS Change\n");
 	break;
         }
       case DVDNAV_CELL_CHANGE: {
-        printf("Nav Cell Change\n");
+        dvdnav_cell_change_event_t *cell_change = (dvdnav_cell_change_event_t*)(s->buffer);
+        cell_playback_t * cell_playback = cell_change->new_cell;
+
+        printf("DVDNAV Event: Nav Cell Change\n");
+        osd_show_dvd_nav_highlight=0; /* screen changed, disable menu */
+        printf("new still time: %d\n",cell_playback->still_time);
+        printf("new cell_cmd_nr: %d\n",cell_playback->cell_cmd_nr);
+        printf("new playback_time: %02d:%02d:%02d.%02d\n",
+                        cell_playback->playback_time.hour,
+                        cell_playback->playback_time.minute,
+                        cell_playback->playback_time.second,
+                        cell_playback->playback_time.frame_u);
+
 	break;
         }
       case DVDNAV_NAV_PACKET: {
-        // printf("Nav Packet\n");
+        // printf("DVDNAV Event: Nav Packet\n");
 	break;
         }
       case DVDNAV_SPU_CLUT_CHANGE: {
-        printf("Nav SPU CLUT Change\n");
+        printf("DVDNAV Event: Nav SPU CLUT Change\n");
 	break;
         }
       case DVDNAV_SEEK_DONE: {
-        printf("Nav Seek Done\n");
+        printf("DVDNAV Event: Nav Seek Done\n");
 	break;
         }
       default:
-        printf("Weird nav event %d\n",event);
+        printf("DVDNAV Event: Weird nav event %d\n",event);
         break;
       }
     break;
@@ -237,6 +298,17 @@
 #endif
     break;
 #endif
+#ifdef USE_DVDNAV
+  case STREAMTYPE_DVDNAV: {
+//    if (newpos==0) {
+//    }
+    if(newpos<s->pos){
+      mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n");
+      return 1;
+    }
+    break;
+  }
+#endif
 #ifdef USE_DVDREAD
   case STREAMTYPE_DVD:
     s->pos=newpos; // real seek
diff --exclude=CVS -ur MPlayer-20020331-clean/libmpdemux/stream.h MPlayer-20020331-dvdnav/libmpdemux/stream.h
--- MPlayer-20020331-clean/libmpdemux/stream.h	Thu Mar 28 12:40:05 2002
+++ MPlayer-20020331-dvdnav/libmpdemux/stream.h	Sat Mar 30 20:37:04 2002
@@ -16,7 +16,7 @@
 #define STREAMTYPE_PLAYLIST 6
 #define STREAMTYPE_MF   7
 #define STREAMTYPE_DS   8
-#define STREAMTYPE_DVDNAV 9
+#define STREAMTYPE_DVDNAV 9   // we cannot safely "seek" in this...
 
 #define VCD_SECTOR_SIZE 2352
 #define VCD_SECTOR_OFFS 24
@@ -199,9 +199,27 @@
 extern int dvd_last_chapter;
 extern int dvd_angle;
 extern int dvd_nav;
+extern int dvd_nav_skip_opening;
+extern char dvd_nav_text[50];
+extern int osd_show_dvd_nav_delay;
+extern int osd_show_dvd_nav_highlight;
+extern int osd_show_dvd_nav_sx;
+extern int osd_show_dvd_nav_ex;
+extern int osd_show_dvd_nav_sy;
+extern int osd_show_dvd_nav_ey;
 int dvd_parse_chapter_range(struct config*, const char*);
 //#endif
 
+#ifdef USE_DVDNAV
+#include <dvdnav.h>
+
+typedef struct {
+  dvdnav_t * dvdnav;                    /* handle to libdvdnav stuff */
+  int        seen_root_menu;            /* have we seen the root menu yet? */
+  int        skip_opening_timers;       /* should pre-root-menu timers be skipped? */
+} dvdnav_priv_t;
+#endif
+
 #ifdef USE_DVDREAD
 
 #include <dvdread/dvd_reader.h>
diff --exclude=CVS -ur MPlayer-20020331-clean/libvo/sub.c MPlayer-20020331-dvdnav/libvo/sub.c
--- MPlayer-20020331-clean/libvo/sub.c	Sat Mar 23 16:32:13 2002
+++ MPlayer-20020331-dvdnav/libvo/sub.c	Sat Mar 30 23:09:18 2002
@@ -6,6 +6,8 @@
 
 #include <stdlib.h>
 
+#include "../libmpdemux/stream.h"
+
 char * __sub_osd_names[]={
     "Seekbar",
     "Play",
@@ -51,6 +53,87 @@
 
 }
 
+/* draws a line with a font character.  :P */
+inline static void vo_osd_draw_line(int dxs, int dys, unsigned char c, 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 font;
+        int cx, cy; /* current x,y location */
+        int xspan, yspan; /* how far they need to go */
+        int xwhole, ywhole; /* how large is a "whole" step */
+        float xstep, ystep; /* x, y steps */
+        float xcounter, ycounter;
+
+        if (!vo_font) return;
+
+        /* 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;
+
+        /* only draw left to right */
+        if ( sx > ex ) {
+                int tmp;
+                tmp=sx;
+                sx=ex;
+                ex=tmp;
+                c=sy;
+                sy=ey;
+                ey=tmp;
+        }
+
+        xspan=ex-sx;
+        yspan=ey-sy;
+
+        if (xspan==0 && yspan==0)
+                return; /* nothing to draw! */
+
+        if ((font=vo_font->font[c])<0)
+                return; /* font not there?! */
+
+        //printf("xspan: %d\n",xspan);
+        //printf("yspan: %d\n",yspan);
+
+        xwhole=ywhole=vo_font->width[c]/2;
+
+        // 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;
+        while (cx<=ex) {
+                /* draw the "pixel" */
+                draw_alpha(cx-(vo_font->width[c]/2),cy-(vo_font->pic_a[font]->h/2),
+                  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);
+
+                /* 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 +402,21 @@
         vo_draw_text_progbar(dxs,dys,draw_alpha);
     }
 
+    if (osd_show_dvd_nav_highlight) {
+        vo_osd_draw_line(dxs,dys,'+',
+                        osd_show_dvd_nav_sx,osd_show_dvd_nav_sy,
+                        osd_show_dvd_nav_ex,osd_show_dvd_nav_sy,draw_alpha); /* --- top */
+        vo_osd_draw_line(dxs,dys,'+',
+                        osd_show_dvd_nav_sx,osd_show_dvd_nav_sy,
+                        osd_show_dvd_nav_sx,osd_show_dvd_nav_ey,draw_alpha); /* |   left */
+        vo_osd_draw_line(dxs,dys,'+',
+                        osd_show_dvd_nav_sx,osd_show_dvd_nav_ey,
+                        osd_show_dvd_nav_ex,osd_show_dvd_nav_ey,draw_alpha); /* ___ bottom */
+        vo_osd_draw_line(dxs,dys,'+',
+                        osd_show_dvd_nav_ex,osd_show_dvd_nav_sy,
+                        osd_show_dvd_nav_ex,osd_show_dvd_nav_ey,draw_alpha); /*   | right */
+    }
+
 }
          
 static int vo_osd_changed_status = 0;
diff --exclude=CVS -ur MPlayer-20020331-clean/mplayer.c MPlayer-20020331-dvdnav/mplayer.c
--- MPlayer-20020331-clean/mplayer.c	Sat Mar 30 18:22:40 2002
+++ MPlayer-20020331-dvdnav/mplayer.c	Sat Mar 30 23:12:15 2002
@@ -49,6 +49,7 @@
 
 #include "dvdauth.h"
 #ifdef USE_DVDNAV
+#include <dvdnav_internal.h>    /* need to get to the pgc palette */
 #include <dvdnav.h>
 #endif
 #ifdef USE_DVDREAD
@@ -301,14 +302,14 @@
     getch2_disable();
   }
 
-#ifdef USE_DVDREAD
+//#ifdef USE_DVDREAD
   if (mask&INITED_SPUDEC){
     inited_flags&=~INITED_SPUDEC;
     current_module="uninit_spudec";
     spudec_free(vo_spudec);
     vo_spudec=NULL;
   }
-#endif
+//#endif
   if(mask&INITED_VO){
     inited_flags&=~INITED_VO;
     current_module="uninit_vo";
@@ -1116,13 +1117,16 @@
     vo_spudec=spudec_new_scaled(palette, sh_video->disp_w, sh_video->disp_h);
 }
 
-#ifdef USE_DVDREAD
+#if USE_DVDREAD || USE_DVDNAV
 if (vo_spudec==NULL) {
-current_module="spudec_init";
-vo_spudec=spudec_new_scaled(stream->type==STREAMTYPE_DVD?((dvd_priv_t *)(stream->priv))->cur_pgc->palette:NULL,
+  current_module="spudec_init";
+  vo_spudec=spudec_new_scaled(stream->type==STREAMTYPE_DVD?((dvd_priv_t *)(stream->priv))->cur_pgc->palette:
+                            (stream->type==STREAMTYPE_DVDNAV?((dvdnav_priv_t*)(stream->priv))->dvdnav->vm->state.pgc->palette
+                             :NULL),
 			    sh_video->disp_w, sh_video->disp_h);
 }
 #endif
+
 if (vo_spudec!=NULL)
   inited_flags|=INITED_SPUDEC;
 
@@ -1484,7 +1488,7 @@
 
 if(1)
   while(1){
-  
+
     float frame_time=0;
     int blit_frame=0;
     
@@ -2459,25 +2463,42 @@
 	if(sub_pos <0) sub_pos=0;
     }	break;
 #ifdef USE_DVDNAV
+    case MP_CMD_CHANGE_AID: {
+        /* this doesn't appear to work right...
+        int aid_temp=cmd->args[0].v.i;
+        if (aid_temp>=0) aid_temp+=128; // FIXME: is this sane?
+        printf("aid change: was %d is now %d\n",d_audio->id,aid_temp);
+        d_audio->id=aid_temp;
+        */
+        break;
+    }
+    case MP_CMD_CHANGE_SID: {
+        mp_msg(MSGT_INPUT,MSGL_DBG2,"d_dvdsub->id change: was %d is now %d\n",d_dvdsub->id,cmd->args[0].v.i);
+        d_dvdsub->id=cmd->args[0].v.i;
+        break;
+    }
     case MP_CMD_DVDNAV: {
+      dvdnav_priv_t * dvdnav_priv=(dvdnav_priv_t*)stream->priv;
+
       switch (cmd->args[0].v.i) {
         case MP_CMD_DVDNAV_UP:
-          dvdnav_upper_button_select(stream->priv);
+          dvdnav_upper_button_select(dvdnav_priv->dvdnav);
           break;
         case MP_CMD_DVDNAV_DOWN:
-          dvdnav_lower_button_select(stream->priv);
+          dvdnav_lower_button_select(dvdnav_priv->dvdnav);
           break;
         case MP_CMD_DVDNAV_LEFT:
-          dvdnav_left_button_select(stream->priv);
+          dvdnav_left_button_select(dvdnav_priv->dvdnav);
           break;
         case MP_CMD_DVDNAV_RIGHT:
-          dvdnav_right_button_select(stream->priv);
+          dvdnav_right_button_select(dvdnav_priv->dvdnav);
           break;
         case MP_CMD_DVDNAV_MENU:
-          dvdnav_menu_call(stream->priv,DVD_MENU_Root);
+          printf("Menu call\n");
+          dvdnav_menu_call(dvdnav_priv->dvdnav,DVD_MENU_Root);
           break;
         case MP_CMD_DVDNAV_SELECT:
-          dvdnav_button_activate(stream->priv);
+          dvdnav_button_activate(dvdnav_priv->dvdnav);
           break;
         default:
           mp_msg(MSGT_CPLAYER, MSGL_V, "Weird DVD Nav cmd %d\n",cmd->args[0].v.i);
@@ -2573,9 +2594,9 @@
 	too_slow_frame_cnt=0;
 	too_fast_frame_cnt=0;
 
-#ifdef USE_DVDREAD
+//#ifdef USE_DVDREAD
       if(vo_spudec) spudec_reset(vo_spudec);
-#endif
+//#endif
       }
   }
   rel_seek_secs=0;
@@ -2630,6 +2651,10 @@
       char osd_text_tmp[50];
       if(pts==osd_last_pts-1) ++pts; else osd_last_pts=pts;
       vo_osd_text=osd_text_buffer;
+      if (osd_show_dvd_nav_delay) {
+          sprintf(osd_text_tmp, "DVDNAV: %s", dvd_nav_text);
+          osd_show_dvd_nav_delay--;
+      } else
       if (osd_show_sub_delay) {
 	  sprintf(osd_text_tmp, "Sub delay: %d ms",(int)(sub_delay*1000));
 	  osd_show_sub_delay--;
@@ -2680,7 +2705,7 @@
     current_module=NULL;
   }
 
-#ifdef USE_DVDREAD
+//#ifdef USE_DVDREAD
   // DVD sub:
   if(vo_flags & 0x08){
     static vo_mpegpes_t packet;
@@ -2696,16 +2721,16 @@
     int len;
     current_module="spudec";
     while((len=ds_get_packet_sub(d_dvdsub,&packet))>0){
-      mp_msg(MSGT_CPLAYER,MSGL_V,"\rDVD sub: len=%d  v_pts=%5.3f  s_pts=%5.3f  \n",len,d_video->pts,d_dvdsub->pts);
+      mp_msg(MSGT_CPLAYER,MSGL_V,"\rDVD spu: len=%d  v_pts=%5.3f  s_pts=%5.3f  \n",len,d_video->pts,d_dvdsub->pts);
       spudec_assemble(vo_spudec,packet,len,100*d_dvdsub->pts);
     }
     spudec_heartbeat(vo_spudec,100*d_video->pts);
 
-    /* Don't know how to detect wether the sub has changed or not */
+    /* Don't know how to detect whether the sub has changed or not */
     vo_osd_changed(1);
     current_module=NULL;
   }
-#endif
+//#endif
   
 } // while(!eof)
 
diff --exclude=CVS -ur MPlayer-20020331-clean/spudec.c MPlayer-20020331-dvdnav/spudec.c
--- MPlayer-20020331-clean/spudec.c	Thu Mar 28 19:17:57 2002
+++ MPlayer-20020331-dvdnav/spudec.c	Sat Mar 30 23:12:44 2002
@@ -206,6 +206,8 @@
       case 0x00:
 	/* Menu ID, 1 byte */
 	mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Menu ID\n");
+	//this->start_pts = pts100 + date;
+	//this->end_pts = UINT_MAX;
 	break;
       case 0x01:
 	/* Start display */
@@ -385,12 +387,13 @@
   if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts) {
     if (spu->orig_frame_width == 0 || spu->orig_frame_height == 0
 	|| (spu->orig_frame_width == dxs && spu->orig_frame_height == dys)) {
-      if (spu->image)
+      if (spu->image) {
 	draw_alpha(spu->start_col, spu->start_row, spu->width, spu->height,
 		   spu->image, spu->aimage, spu->stride);
+      }
     }
     else {
-      if (spu->scaled_frame_width != dxs || spu->scaled_frame_height != dys) {	/* Resizing is needed */
+      if (spu->scaled_frame_width != dxs || spu->scaled_frame_height != dys) { /* Resizing is needed */
 	/* scaled_x = scalex * x / 0x100
 	   scaled_y = scaley * y / 0x100
 	   order of operations is important because of rounding. */
@@ -646,11 +649,17 @@
 	  spu->scaled_frame_height = dys;
 	}
       }
-      if (spu->scaled_image)
+      if (spu->scaled_image) {
 	draw_alpha(spu->scaled_start_col, spu->scaled_start_row, spu->scaled_width, spu->scaled_height,
 		   spu->scaled_image, spu->scaled_aimage, spu->scaled_stride);
+      }
     }
   }
+  else
+  {
+    mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPU not displayed: start_pts=%d  end_pts=%d  now_pts=%d\n",
+        spu->start_pts, spu->end_pts, spu->now_pts);
+  }
 }
 
 void *spudec_new_scaled(unsigned int *palette, unsigned int frame_width, unsigned int frame_height)


More information about the MPlayer-dev-eng mailing list