Mercurial > mplayer.hg
changeset 492:888a85621f50
preliminary DVD support using libcss
author | lgb |
---|---|
date | Tue, 17 Apr 2001 22:04:44 +0000 |
parents | 2313c6ea006f |
children | b8f1ed2b411b |
files | Makefile cfg-mplayer.h configure demux_mpg.c dvdauth.c dvdauth.h mplayer.c stream.c |
diffstat | 8 files changed, 206 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Tue Apr 17 21:00:46 2001 +0000 +++ b/Makefile Tue Apr 17 22:04:44 2001 +0000 @@ -1,10 +1,8 @@ -# DirectShow support (test code) -# make -f makefile.DS - # LINUX Makefile made by A'rpi / Astral # Some cleanup by LGB: * 'make -C dir' instead of 'cd dir;make;cd..' # * for loops instead of linear sequence of make directories # * some minor problems with make clean and distclean were corrected +# * DVD support include config.mak @@ -22,9 +20,9 @@ prefix = /usr/local BINDIR = ${prefix}/bin # BINDIR = /usr/local/bin -SRCS = codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c mixer.c -OBJS = codec-cfg.o subreader.o linux/getch2.o linux/timer-lx.o linux/shmem.o xa/xa_gsm.o lirc_mp.o cfgparser.o mixer.o -CFLAGS = $(OPTFLAGS) -Iloader -Ilibvo # -Wall +SRCS = codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c mixer.c dvdauth.c +OBJS = codec-cfg.o subreader.o linux/getch2.o linux/timer-lx.o linux/shmem.o xa/xa_gsm.o lirc_mp.o cfgparser.o mixer.o dvdauth.o +CFLAGS = $(OPTFLAGS) $(CSS_INC) -Iloader -Ilibvo # -Wall A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3 VO_LIBS = -Llibvo -lvo $(X_LIBS) @@ -65,7 +63,7 @@ $(MAKE) -C encore $(PRG): .depend mplayer.o $(OBJS) loader/libloader.a loader/DirectShow/libDS_Filter.a libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a - $(CC) $(CFLAGS) -o $(PRG) mplayer.o $(OBJS) $(XMM_LIBS) $(LIRC_LIBS) $(A_LIBS) -lm $(TERMCAP_LIB) -Lloader -lloader -Lloader/DirectShow -lDS_Filter -ldl -Llibmpeg2 -lmpeg2 -Lopendivx -ldecore $(VO_LIBS) -Lencore -lencore -lpthread -lstdc++ + $(CC) $(CFLAGS) -o $(PRG) mplayer.o $(OBJS) $(XMM_LIBS) $(LIRC_LIBS) $(A_LIBS) -lm $(TERMCAP_LIB) -Lloader -lloader -Lloader/DirectShow -lDS_Filter -ldl -Llibmpeg2 -lmpeg2 -Lopendivx -ldecore $(VO_LIBS) $(CSS_LIB) -Lencore -lencore -lpthread -lstdc++ $(PRG_HQ): .depend mplayerHQ.o $(OBJS) loader/libloader.a libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a $(CC) $(CFLAGS) -o $(PRG_HQ) mplayerHQ.o $(OBJS) $(XMM_LIBS) $(LIRC_LIBS) $(A_LIBS) -lm $(TERMCAP_LIB) -Lloader -lloader -ldl -Llibmpeg2 -lmpeg2 -Lopendivx -ldecore $(VO_LIBS) -Lencore -lencore -lpthread
--- a/cfg-mplayer.h Tue Apr 17 21:00:46 2001 +0000 +++ b/cfg-mplayer.h Tue Apr 17 22:04:44 2001 +0000 @@ -20,6 +20,13 @@ {"dsp", &dsp, CONF_TYPE_STRING, 0, 0, 0}, {"mixer", &mixer_device, CONF_TYPE_STRING, 0, 0, 0}, {"master", &mixer_usemaster, CONF_TYPE_FLAG, 0, 0, 1}, +#ifdef HAVE_LIBCSS + {"dvd", &dvd_device, CONF_TYPE_STRING, 0, 0, 0}, +#else + {"dvd", "DVD support was not compiled in. See file DOCS/DVD.\n", + CONF_TYPE_PRINT, CONF_NOCFG, 0 , 0}, +#endif + #ifdef HAVE_FBDEV {"fb", &fb_dev_name, CONF_TYPE_STRING, 0, 0, 0}, {"fbmode", &fb_mode_name, CONF_TYPE_STRING, 0, 0, 0},
--- a/configure Tue Apr 17 21:00:46 2001 +0000 +++ b/configure Tue Apr 17 22:04:44 2001 +0000 @@ -6,6 +6,9 @@ # # Changes in reversed order: # +# 2001/04/16 by LGB +# - added libcss stuffs +# # 2001/04/15 by Pontscho # - added --disable-select option # - added X11DIR variable in config.mak and fix syncfb Makefile -L/usr/X11/lib bug @@ -17,7 +20,7 @@ # - new option: --cc (to specify C compiler path+name) # # 2001/03/08 by LGB: -# - DGA detection-o-matic :) +# - DGA detect-o-matic :) # - '--disable-dga' option to force disabling DGA vo driver compiling into mplayer # - line about '--enable-dga' is added to the help message # @@ -100,6 +103,8 @@ --with-x11libdir=DIR X library files are in DIR --with-win32libdir=DIR windows codec files + --with-csslibdir=DIR directory contains libcss.so shared library + --with-cssincdir=DIR directory contains libcss header file (css.h) --size-x=SIZE default screen width --size-y=SIZE default screen height @@ -179,6 +184,7 @@ pmodel=`cat /proc/cpuinfo | grep "model$TAB" | cut -d ':' -f 2 | cut -d ' ' -f 2` pstepping=`cat /proc/cpuinfo | grep 'stepping' | cut -d ':' -f 2 | cut -d ' ' -f 2` +_css=no _mmx=no _mmx2=no _3dnow=no @@ -460,6 +466,9 @@ for ac_option do case "$ac_option" in + --enable-css) + _css=yes + ;; --enable-sse) _sse=yes ;; @@ -526,6 +535,9 @@ --enable-select) _select='#define HAVE_AUDIO_SELECT' ;; + --disable-css) + _css=no + ;; --disable-sse) _sse=no ;; @@ -582,6 +594,14 @@ _win32libdir=`echo $ac_option | cut -d '=' -f 2` _win32libdirnotify=no ;; + --with-csslibdir=*) + _csslibdir=`echo $ac_option | cut -d '=' -f 2` + _css='yes'; + ;; + --with-cssincdir=*) + _cssincdir=`echo $ac_option | cut -d '=' -f 2` + _css='yes'; + ;; --size-x=*) _x=`echo $ac_option | cut -d '=' -f 2` ;; @@ -624,12 +644,31 @@ echo "Checking for Xf86VM ... $_vm" echo "Checking for SVGAlib ... $_svga" echo "Checking for FBDev ... $_fbdev" +echo "Checking for DeCSS support ... $_css" # write conf files. if [ $_gl = yes ]; then _gllib='-lGL' fi +if [ $_css = yes ]; then + if [ ! -z $_csslibdir ]; then + _csslib="-L${_csslibdir} -lcss" + else + _csslib='-lcss' + fi + _css='#define HAVE_LIBCSS' + if [ ! -z $_cssincdir ]; then + _cssinc="-I${_cssincdir}" + else + _cssinc="" + fi +else + _css='#undef HAVE_LIBCSS' + _csslib='' + _cssinc='' +fi + if [ $_x11 = yes ]; then if [ $_xdpms = yes ]; then _x11lib='-lX11 -lXext -lXdpms' @@ -697,6 +736,8 @@ TERMCAP_LIB=$_libtermcap XMM_LIBS = $_xmmplibs LIRC_LIBS = $_lirclibs +CSS_LIB = $_csslib +CSS_INC = $_cssinc WIN32_PATH=-DWIN32_PATH=\"$_win32libdir\" EOF @@ -869,6 +910,9 @@ /* LIRC (remote control, see www.lirc.org) support: */ $_lircdefs +/* DeCSS support using libcss */ +$_css + /* Define this to enable MPEG 1/2 image postprocessing (requires FAST cpu!) */ #define MPEG12_POSTPROC
--- a/demux_mpg.c Tue Apr 17 21:00:46 2001 +0000 +++ b/demux_mpg.c Tue Apr 17 22:04:44 2001 +0000 @@ -17,6 +17,9 @@ static int demux_mpg_read_packet(demuxer_t *demux,int id){ int d; int len; +#ifdef HAVE_LIBCSS + int css=0; +#endif unsigned char c=0; unsigned int pts=0; unsigned int dts=0; @@ -31,7 +34,7 @@ len=stream_read_word(demux->stream); if(verbose>=3) printf("PACKET len=%d",len); - if(len==0 || len>4096) return -2; // invalid packet !!!!!! + if(len==0 || len>STREAM_BUFFER_SIZE) return -2; // invalid packet !!!!!! while(len>0){ // Skip stuFFing bytes c=stream_read_char(demux->stream);--len; @@ -60,7 +63,13 @@ int pts_flags; int hdrlen; // System-2 (.VOB) stream: - if((c>>4)&3) printf("Warning! Encrypted VOB file! (DeCSS not (yet) supported)\n"); + if((c>>4)&3) { +#ifdef HAVE_LIBCSS + css=1; +#else + printf("Encrypted VOB file (not compiled with libcss support)! Read file DOCS/DVD\n"); +#endif + } c=stream_read_char(demux->stream); pts_flags=c>>6; c=stream_read_char(demux->stream); hdrlen=c; len-=2; @@ -121,7 +130,7 @@ } if(verbose>=3) printf(" => len=%d\n",len); - if(len<=0 || len>4096) return -1; // Invalid packet size + if(len<=0 || len>STREAM_BUFFER_SIZE) return -1; // Invalid packet size if(id>=0x1C0 && id<=0x1DF){ // mpeg audio @@ -148,6 +157,9 @@ if(ds){ if(verbose>=2) printf("DEMUX_MPG: Read %d data bytes from packet %04X\n",len,id); // printf("packet start = 0x%X \n",stream_tell(demux->stream)-packet_start_pos); +#ifdef HAVE_LIBCSS + if (css) CSSDescramble(demux->stream->buffer,key_title); +#endif ds_read_packet(ds,demux->stream,len,pts/90000.0f,0); return 1; } @@ -164,7 +176,7 @@ // Elementary video stream if(demux->stream->eof) return 0; demux->filepos=stream_tell(demux->stream); - ds_read_packet(demux->video,demux->stream,4096,0,0); + ds_read_packet(demux->video,demux->stream,STREAM_BUFFER_SIZE,0,0); return 1; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dvdauth.c Tue Apr 17 22:04:44 2001 +0000 @@ -0,0 +1,106 @@ +/* (C)2001 by LGB (Gabor Lenart), based on example programs in libcss + Some TODO: root privilegies really needed?? */ + +/* don't do anything with this source if css support was not requested */ +#include "config.h" +#ifdef HAVE_LIBCSS + +#include <stdio.h> +#include <stdlib.h> +#include <linux/cdrom.h> +// FIXME #include <string.h> conflicts with #include <linux/fs.h> (below) +//#include <string.h> // FIXME this conflicts with #include <linux/fs.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sys/stat.h> + +#include <css.h> + +#include "dvdauth.h" + +char *dvd_device=NULL; +unsigned char key_disc[2048]; +unsigned char key_title[5]; + + +#include <linux/fs.h> + +#ifndef FIBMAP +#define FIBMAP 1 +#endif + + +static int path_to_lba ( int fd ) +{ + int lba = 0; + if (ioctl(fd, FIBMAP, &lba) < 0) { + perror ("ioctl FIBMAP"); + fprintf(stderr,"Hint: run mplayer as root!\n"); +// close(fd); + return -1; + } + return lba; +} + + + +static void reset_agids ( int fd ) +{ + dvd_authinfo ai; + int i; + for (i = 0; i < 4; i++) { + memset(&ai, 0, sizeof(ai)); + ai.type = DVD_INVALIDATE_AGID; + ai.lsa.agid = i; + ioctl(fd, DVD_AUTH, &ai); + } +} + + + +int dvd_auth ( char *dev , int fd ) +{ + int devfd; /* FD of DVD device */ + int lba; + +// printf("DVD: auth fd=%d on %s.\n",fd,dev); + + if ((devfd=open(dev,O_RDONLY))<0) { + fprintf(stderr,"DVD: cannot open DVD device \"%s\".\n",dev); + return 1; + } + + /* reset AGIDs */ + reset_agids(devfd); + + /* authenticate disc */ + if (CSSAuthDisc(devfd,key_disc)) { + fprintf(stderr,"DVD: CSSAuthDisc() failed.\n"); + return 1; + } + + /* authenticate title */ + lba=path_to_lba(fd); + if (lba==-1) { + fprintf(stderr,"DVD: path_to_lba() failed.\n"); + return 1; + } + if (CSSAuthTitle(devfd,key_title,lba)) { + fprintf(stderr,"DVD: CSSAuthTitle() failed.\n"); + return 1; + } + + /* decrypting title */ + if (CSSDecryptTitleKey (key_title, key_disc) < 0) { + fprintf(stderr,"DVD: CSSDecryptTitleKey() failed.\n"); + return 1; + } + + close(devfd); + return 0; +} + + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dvdauth.h Tue Apr 17 22:04:44 2001 +0000 @@ -0,0 +1,14 @@ +#include "config.h" +#ifdef HAVE_LIBCSS +#ifndef _MPLAYER_CSS_H +#define _MPLAYER_CSS_H + +extern char *dvd_device; +extern unsigned char key_disc[]; +extern unsigned char key_title[]; + +int dvd_auth ( char *, int ); + + +#endif +#endif \ No newline at end of file
--- a/mplayer.c Tue Apr 17 21:00:46 2001 +0000 +++ b/mplayer.c Tue Apr 17 22:04:44 2001 +0000 @@ -50,6 +50,8 @@ #include "codec-cfg.h" +#include "dvdauth.h" + #ifdef USE_DIRECTSHOW #include "DirectShow/DS_VideoDec.h" #include "DirectShow/DS_AudioDec.h" @@ -605,6 +607,12 @@ //============ Open plain FILE ============ f=open(filename,O_RDONLY); if(f<0){ printf("File not found: '%s'\n",filename);return 1; } +#ifdef HAVE_LIBCSS + if (dvd_device) { + if (dvd_auth(dvd_device,f)) exit(0); + printf("DVD auth sequence seems to be OK.\n"); + } +#endif stream_type=STREAMTYPE_FILE; } @@ -1900,6 +1908,9 @@ // picture->bitrate=2324*75*8; // standard VCD bitrate (75 sectors / sec) if(newpos<seek_to_byte) newpos=seek_to_byte; +#ifdef HAVE_LIBCSS + if (dvd_device) newpos&=~(STREAM_BUFFER_SIZE-1); /* sector boundary */ +#endif stream_seek(demuxer->stream,newpos); // re-sync video: videobuf_code_len=0; // reset ES stream buffer
--- a/stream.c Tue Apr 17 21:00:46 2001 +0000 +++ b/stream.c Tue Apr 17 22:04:44 2001 +0000 @@ -3,7 +3,7 @@ //=================== STREAMER ========================= -#define STREAM_BUFFER_SIZE 4096 +#define STREAM_BUFFER_SIZE 2048 #define STREAMTYPE_FILE 0 #define STREAMTYPE_VCD 1 @@ -126,7 +126,7 @@ switch(s->type){ case STREAMTYPE_FILE: - newpos=pos&(~4095);break; + newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; case STREAMTYPE_VCD: newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break; }