changeset 1291:36ed1692c0b8

video codec stuff moved to dec_video.c
author arpi
date Sun, 08 Jul 2001 00:21:20 +0000
parents af0b764f34c5
children f20f1851f193
files Makefile dec_audio.c libmpeg2/mpeg2.h libmpeg2/mpeg2_internal.h mplayer.c
diffstat 5 files changed, 33 insertions(+), 333 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sat Jul 07 20:53:01 2001 +0000
+++ b/Makefile	Sun Jul 08 00:21:20 2001 +0000
@@ -16,7 +16,7 @@
 #prefix = /usr/local
 BINDIR = ${prefix}/bin
 # BINDIR = /usr/local/bin
-SRCS = find_sub.c aviprint.c dll_init.c dec_audio.c aviwrite.c aviheader.c asfheader.c demux_avi.c demux_asf.c demux_mpg.c demuxer.c stream.c 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 spudec.c $(STREAM_SRCS)
+SRCS = find_sub.c aviprint.c dll_init.c dec_audio.c dec_video.c aviwrite.c aviheader.c asfheader.c demux_avi.c demux_asf.c demux_mpg.c demuxer.c stream.c 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 spudec.c $(STREAM_SRCS)
 OBJS = $(SRCS:.c=.o)
 CFLAGS = $(OPTFLAGS) -Iloader -Ilibvo $(CSS_INC) $(EXTRA_INC) # -Wall
 A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3 $(ALSA_LIB) $(ESD_LIB)
--- a/dec_audio.c	Sat Jul 07 20:53:01 2001 +0000
+++ b/dec_audio.c	Sun Jul 08 00:21:20 2001 +0000
@@ -28,8 +28,9 @@
 
 #include "xa/xa_gsm.h"
 
+#ifdef USE_DIRECTSHOW
 #include "loader/DirectShow/DS_AudioDec.h"
-
+#endif
 
 static sh_audio_t* dec_audio_sh=NULL;
 
--- a/libmpeg2/mpeg2.h	Sat Jul 07 20:53:01 2001 +0000
+++ b/libmpeg2/mpeg2.h	Sun Jul 08 00:21:20 2001 +0000
@@ -56,7 +56,6 @@
 //void mpeg2_drop (int flag);
 
 
-
 /* initialize mpegdec with a opaque user pointer */
 //void mpeg2_init (mpeg2dec_t * mpeg2dec, uint32_t mm_accel
 //		 ,vo_instance_t * output
--- a/libmpeg2/mpeg2_internal.h	Sat Jul 07 20:53:01 2001 +0000
+++ b/libmpeg2/mpeg2_internal.h	Sun Jul 08 00:21:20 2001 +0000
@@ -213,6 +213,9 @@
 /* stats.c */
 void stats_header (uint8_t code, uint8_t * buffer);
 
+void mpeg2_allocate_image_buffers(picture_t * picture);
+
+
 #ifdef MPEG12_POSTPROC
 #define MBC 48
 #define MBR 36
--- a/mplayer.c	Sat Jul 07 20:53:01 2001 +0000
+++ b/mplayer.c	Sun Jul 08 00:21:20 2001 +0000
@@ -61,18 +61,11 @@
 #include "spudec.h"
 
 #ifdef USE_DIRECTSHOW
-#include "DirectShow/DS_VideoDec.h"
-#include "DirectShow/DS_AudioDec.h"
+//#include "DirectShow/DS_VideoDec.h"
+//#include "DirectShow/DS_AudioDec.h"
 #endif
 
-#ifdef USE_LIBAVCODEC
-#include "libavcodec/avcodec.h"
-    AVCodec *lavc_codec=NULL;
-    AVCodecContext lavc_context;
-    AVPicture lavc_picture;
-#endif
-
-#include "opendivx/decore.h"
+//#include "opendivx/decore.h"
 
 extern char* win32_codec_name;  // must be set before calling DrvOpen() !!!
 
@@ -227,32 +220,6 @@
 };
 
 //**************************************************************************//
-//             The OpenDivX stuff:
-//**************************************************************************//
-
-#ifndef NEW_DECORE
-
-unsigned char *opendivx_src[3];
-int opendivx_stride[3];
-
-// callback, the opendivx decoder calls this for each frame:
-void convert_linux(unsigned char *puc_y, int stride_y,
-	unsigned char *puc_u, unsigned char *puc_v, int stride_uv,
-	unsigned char *bmp, int width_y, int height_y){
-
-//    printf("convert_yuv called  %dx%d  stride: %d,%d\n",width_y,height_y,stride_y,stride_uv);
-
-    opendivx_src[0]=puc_y;
-    opendivx_src[1]=puc_u;
-    opendivx_src[2]=puc_v;
-    
-    opendivx_stride[0]=stride_y;
-    opendivx_stride[1]=stride_uv;
-    opendivx_stride[2]=stride_uv;
-}
-#endif
-
-//**************************************************************************//
 //**************************************************************************//
 
 // Common FIFO functions, and keyboard/event FIFO code
@@ -263,8 +230,8 @@
 static vo_functions_t *video_out=NULL;
 static ao_functions_t *audio_out=NULL;
 
-static double video_time_usage=0;
-static double vout_time_usage=0;
+double video_time_usage=0;
+double vout_time_usage=0;
 static double audio_time_usage=0;
 static int total_time_usage_start=0;
 static int benchmark=0;
@@ -1197,133 +1164,10 @@
 
 if(verbose) printf("vo_debug1: out_fmt=%s\n",vo_format_name(out_fmt));
 
-switch(sh_video->codec->driver){
- case 2: {
-   if(!init_video_codec(sh_video)) {
+if(!init_video(sh_video)){
+     fprintf(stderr,"FATAL: Couldn't initialize video codec :(\n");
      GUI_MSG( mplUnknowError )
      exit(1);
-   }  
-   if(verbose) printf("INFO: Win32 video codec init OK!\n");
-   break;
- }
- case 4: { // Win32/DirectShow
-#ifndef USE_DIRECTSHOW
-   fprintf(stderr,"MPlayer was compiled WITHOUT directshow support!\n");
-   GUI_MSG( mplCompileWithoutDSSupport )
-   exit(1);
-#else
-   sh_video->our_out_buffer=NULL;
-   if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, &sh_video->our_out_buffer)){
-//   if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, NULL)){
-        printf("ERROR: Couldn't open required DirectShow codec: %s\n",sh_video->codec->dll);
-        printf("Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n");
-        printf("package from:  ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip  !\n");
-        printf("Or you should disable DShow support: make distclean;make -f Makefile.No-DS\n");
-        #ifdef HAVE_GUI
-         if ( !nogui )
-          {
-           strcpy(  mplShMem->items.videodata.codecdll,sh_video->codec->dll );
-           mplSendMessage( mplDSCodecNotFound );
-           usec_sleep( 10000 );
-          }
-        #endif
-        exit(1);
-   }
-   
-   switch(out_fmt){
-   case IMGFMT_YUY2:
-   case IMGFMT_UYVY:
-     DS_VideoDecoder_SetDestFmt(16,out_fmt);break;        // packed YUV
-   case IMGFMT_YV12:
-   case IMGFMT_I420:
-   case IMGFMT_IYUV:
-     DS_VideoDecoder_SetDestFmt(12,out_fmt);break;        // planar YUV
-   default:
-     DS_VideoDecoder_SetDestFmt(out_fmt&255,0);           // RGB/BGR
-   }
-
-   DS_VideoDecoder_Start();
-
-   printf("DivX setting result = %d\n", DS_SetAttr_DivX("Quality",divx_quality) );
-//   printf("DivX setting result = %d\n", DS_SetValue_DivX("Brightness",60) );
-   
-   if(verbose) printf("INFO: Win32/DShow video codec init OK!\n");
-   break;
-#endif
- }
- case 3: {  // OpenDivX
-   if(verbose) printf("OpenDivX video codec\n");
-   { DEC_PARAM dec_param;
-     DEC_SET dec_set;
-#ifdef NEW_DECORE
-     DEC_MEM_REQS dec_mem;
-        dec_param.output_format=DEC_USER;
-#else
-        dec_param.color_depth = 32;
-#endif
-	dec_param.x_dim = sh_video->bih->biWidth;
-	dec_param.y_dim = sh_video->bih->biHeight;
-#ifdef NEW_DECORE
-        // 0.50-CVS new malloc scheme
-        decore(0x123, DEC_OPT_MEMORY_REQS, &dec_param, &dec_mem);
-        dec_param.buffers.mp4_edged_ref_buffers=malloc(dec_mem.mp4_edged_ref_buffers_size);
-        dec_param.buffers.mp4_edged_for_buffers=malloc(dec_mem.mp4_edged_for_buffers_size);
-        dec_param.buffers.mp4_display_buffers=malloc(dec_mem.mp4_display_buffers_size);
-        dec_param.buffers.mp4_state=malloc(dec_mem.mp4_state_size);
-        dec_param.buffers.mp4_tables=malloc(dec_mem.mp4_tables_size);
-        dec_param.buffers.mp4_stream=malloc(dec_mem.mp4_stream_size);
-#endif
-	decore(0x123, DEC_OPT_INIT, &dec_param, NULL);
-
-	dec_set.postproc_level = divx_quality;
-	decore(0x123, DEC_OPT_SETPP, &dec_set, NULL);
-
-   }
-   if(verbose) printf("INFO: OpenDivX video codec init OK!\n");
-   break;
- }
- case 5: {  // FFmpeg's libavcodec
-#ifndef USE_LIBAVCODEC
-   fprintf(stderr,"MPlayer was compiled WITHOUT libavcodec support!\n");
-   exit(1);
-#else
-   if(verbose) printf("FFmpeg's libavcodec video codec\n");
-    avcodec_init();
-    avcodec_register_all();
-    lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_video->codec->dll);
-    if(!lavc_codec){
-	fprintf(stderr,"Can't find codec '%s' in libavcodec...\n",sh_video->codec->dll);
-	exit(1);
-    }
-    memset(&lavc_context, 0, sizeof(lavc_context));
-    lavc_context.width=sh_video->disp_w;
-    lavc_context.height=sh_video->disp_h;
-    printf("libavcodec.size: %d x %d\n",lavc_context.width,lavc_context.height);
-    /* open it */
-    if (avcodec_open(&lavc_context, lavc_codec) < 0) {
-        fprintf(stderr, "could not open codec\n");
-        exit(1);
-    }
-   
-   if(verbose) printf("INFO: libavcodec init OK!\n");
-   break;
-#endif
- }
-
- case 1: {
-   // init libmpeg2:
-#ifdef MPEG12_POSTPROC
-   picture->pp_options=divx_quality;
-#else
-   if(divx_quality){
-       printf("WARNING! You requested image postprocessing for an MPEG 1/2 video,\n");
-       printf("         but compiled MPlayer without MPEG 1/2 postprocessing support!\n");
-       printf("         #define MPEG12_POSTPROC in config.h, and recompile libmpeg2!\n");
-   }
-#endif
-   mpeg2_allocate_image_buffers (picture);
-   break;
- }
 }
 
 if(verbose) printf("vo_debug2: out_fmt=%s\n",vo_format_name(out_fmt));
@@ -1657,7 +1501,7 @@
   
     float frame_time=1;
     float pts1=d_video->pts;
-    int blit_frame=1;
+    int blit_frame=0;
 
     current_module="decode_video";
     
@@ -1665,161 +1509,8 @@
 //    if(drop_frame) ++drop_frame_cnt;
 
   //--------------------  Decode a frame: -----------------------
-switch(sh_video->codec->driver){
-  case 3: {
-    // OpenDivX
-    unsigned int t=GetTimer();
-    unsigned int t2;
-    DEC_FRAME dec_frame;
-#ifdef NEW_DECORE
-    DEC_PICTURE dec_pic;
-#endif
-    unsigned char* start=NULL;
-    int in_size=ds_get_packet(d_video,&start);
-    if(in_size<0){ eof=1;break;}
-    if(in_size>max_framesize) max_framesize=in_size;
-    // let's decode
-        dec_frame.length = in_size;
-	dec_frame.bitstream = start;
-	dec_frame.render_flag = 1;
-#ifdef NEW_DECORE
-        dec_frame.bmp=&dec_pic;
-        dec_pic.y=dec_pic.u=dec_pic.v=NULL;
-#endif
-	decore(0x123, 0, &dec_frame, NULL);
-      t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f;
 
-#ifdef NEW_DECORE
-      if(dec_pic.y){
-        void* src[3];
-        int stride[3];
-        src[0]=dec_pic.y;
-        src[1]=dec_pic.u;
-        src[2]=dec_pic.v;
-        stride[0]=dec_pic.stride_y;
-        stride[1]=stride[2]=dec_pic.stride_uv;
-        video_out->draw_slice(src,stride,
-                            sh_video->disp_w,sh_video->disp_h,0,0);
-      }
-#else
-      if(opendivx_src[0]){
-        video_out->draw_slice(opendivx_src,opendivx_stride,
-                            sh_video->disp_w,sh_video->disp_h,0,0);
-        opendivx_src[0]=NULL;
-      }
-#endif
-      t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
-
-    break;
-  }
-#ifdef USE_DIRECTSHOW
-  case 4: {        // W32/DirectShow
-    unsigned char* start=NULL;
-    unsigned int t=GetTimer();
-    unsigned int t2;
-    int in_size=ds_get_packet(d_video,&start);
-    if(in_size<0){ eof=1;break;}
-    if(in_size>max_framesize) max_framesize=in_size;
-
-    if(d_video->flags) if(verbose) printf("***keyframe***\n");
-
-    if(drop_frame<2) DS_VideoDecoder_DecodeFrame(start, in_size, 0, !drop_frame);
-    current_module="draw_frame";
-
-    if(!drop_frame && sh_video->our_out_buffer){
-      t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f;
-      if(out_fmt==IMGFMT_YV12||out_fmt==IMGFMT_IYUV||out_fmt==IMGFMT_I420){
-        uint8_t* dst[3];
-        int stride[3];
-        stride[0]=sh_video->disp_w;
-        stride[1]=stride[2]=sh_video->disp_w/2;
-        dst[0]=sh_video->our_out_buffer;
-        dst[2]=dst[0]+sh_video->disp_w*sh_video->disp_h;
-        dst[1]=dst[2]+sh_video->disp_w*sh_video->disp_h/4;
-        video_out->draw_slice(dst,stride,sh_video->disp_w,sh_video->disp_h,0,0);
-      } else
-        video_out->draw_frame((uint8_t **)&sh_video->our_out_buffer);
-      t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
-    }
-    break;
-  }
-#endif
-#ifdef USE_LIBAVCODEC
-  case 5: {        // libavcodec
-    unsigned char* start=NULL;
-    unsigned int t=GetTimer();
-    unsigned int t2;
-    int got_picture=0;
-    int in_size=ds_get_packet(d_video,&start);
-    if(in_size<0){ eof=1;break;}
-    if(in_size>max_framesize) max_framesize=in_size;
-
-    if(d_video->flags) if(verbose) printf("***keyframe***\n");
-
-    if(in_size<=0) blit_frame=0; else
-    if(drop_frame<2){
-        int ret = avcodec_decode_video(&lavc_context, &lavc_picture,
-	     &got_picture, start, in_size);
-	if(ret<0) fprintf(stderr, "Error while decoding frame!\n");
-    }
-
-    current_module="draw_frame";
-
-    if(!drop_frame && got_picture){
-      t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f;
-      video_out->draw_slice(lavc_picture.data,lavc_picture.linesize,sh_video->disp_w,sh_video->disp_h,0,0);
-      t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
-    }
-    
-    break;
-  }
-#endif
-  case 2: {
-    HRESULT ret;
-    unsigned char* start=NULL;
-    unsigned int t=GetTimer();
-    unsigned int t2;
-    int in_size=ds_get_packet(d_video,&start);
-    if(in_size<0){ eof=1;break;}
-    if(in_size>max_framesize) max_framesize=in_size;
-    
-    if(d_video->flags) if(verbose) printf("***keyframe***\n");
-    
-    if(in_size){
-      sh_video->bih->biSizeImage = in_size;
-
-//      sh_video->bih->biWidth = 1280;
-//      sh_video->o_bih.biWidth = 1280;
-	    //      ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME|(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL), 
-      ret = ICDecompress(sh_video->hic, 
-	  ( (d_video->flags&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME ) |
-	  ( (drop_frame==2 && !(d_video->flags&1))?(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL):0 ) , 
-                         sh_video->bih,   start,
-                        &sh_video->o_bih,
-                        drop_frame ? 0 : sh_video->our_out_buffer);
-
-      if(ret){ printf("Error decompressing frame, err=%d\n",(int)ret);break; }
-    }
-    current_module="draw_frame";
-    if(!drop_frame){
-      t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f;
-//      if(out_fmt==IMGFMT_YV12){
-      if(out_fmt==IMGFMT_YV12||out_fmt==IMGFMT_IYUV||out_fmt==IMGFMT_I420){
-        uint8_t* dst[3];
-        int stride[3];
-        stride[0]=sh_video->disp_w;
-        stride[1]=stride[2]=sh_video->disp_w/2;
-        dst[0]=sh_video->our_out_buffer;
-        dst[2]=dst[0]+sh_video->disp_w*sh_video->disp_h;
-        dst[1]=dst[2]+sh_video->disp_w*sh_video->disp_h/4;
-        video_out->draw_slice(dst,stride,sh_video->disp_w,sh_video->disp_h,0,0);
-      } else
-        video_out->draw_frame((uint8_t **)&sh_video->our_out_buffer);
-      t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
-    }
-    break;
-  }
-  case 1: {
+  if(file_format==DEMUXER_TYPE_MPEG_ES || file_format==DEMUXER_TYPE_MPEG_PS){
         int in_frame=0;
         int t=0;
         float newfps;
@@ -1856,24 +1547,30 @@
 	      fwrite(videobuffer,videobuf_len-4,1,f);
 	      fclose(f);
 	}
-        
-        t-=GetTimer();
-          mpeg2_decode_data(video_out, videobuffer, videobuffer+videobuf_len,drop_frame);
-        t+=GetTimer(); video_time_usage+=t*0.000001;
+
+    blit_frame=decode_video(video_out,sh_video,videobuffer,videobuf_len,drop_frame);
 
-        newfps=frameratecode2framerate[picture->frame_rate_code]*0.0001f;
-        if(ABS(sh_video->fps-newfps)>0.01f) if(!force_fps){
+    // get mpeg fps:
+    newfps=frameratecode2framerate[picture->frame_rate_code]*0.0001f;
+    if(ABS(sh_video->fps-newfps)>0.01f) if(!force_fps){
             printf("Warning! FPS changed %5.3f -> %5.3f  (%f) [%d]  \n",sh_video->fps,newfps,sh_video->fps-newfps,picture->frame_rate_code);
             sh_video->fps=newfps;
             sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code];
-        }
-        
-        frame_time=(100+picture->repeat_count)*0.01f;
-        picture->repeat_count=0;
+    }
+
+    // fix mpeg2 frametime:
+    frame_time=(100+picture->repeat_count)*0.01f;
+    picture->repeat_count=0;
 
-    break;
+  } else {
+      // frame-based file formats: (AVI,ASF,MOV)
+    unsigned char* start=NULL;
+    int in_size=ds_get_packet(d_video,&start);
+    if(in_size<0){ eof=1;break;}
+    if(in_size>max_framesize) max_framesize=in_size;
+    blit_frame=decode_video(video_out,sh_video,start,in_size,drop_frame);
   }
-} // switch
+
 //------------------------ frame decoded. --------------------
 
     // Increase video timers: