diff libmpcodecs/vd_divx4.c @ 10252:d275152390ee

I've found some time to implement the encoding support for the new DivX API. Now it's possible to play and encode movies with the latest DivX release. One thing that doesn't work is the new Video Buffer Verifier (VBV) multipass encoding. The encoder segfaults. Maybe it just isn't supported with the standard profile of the released binary encoder. Andreas Hess <jaska@gmx.net>
author arpi
date Fri, 06 Jun 2003 19:57:37 +0000
parents 32be26de0d7c
children 023937301637
line wrap: on
line diff
--- a/libmpcodecs/vd_divx4.c	Fri Jun 06 19:19:23 2003 +0000
+++ b/libmpcodecs/vd_divx4.c	Fri Jun 06 19:57:37 2003 +0000
@@ -42,22 +42,41 @@
 
 #define USE_DIVX_BUILTIN_PP
 
+#ifndef DECORE_VERSION
+#define DECORE_VERSION 0
+#endif
+
+#if DECORE_VERSION >= 20021112
+static void* dec_handle = NULL;
+#endif
+
 // to set/get/query special features/parameters
 static int control(sh_video_t *sh,int cmd,void* arg,...){
     switch(cmd){
 #ifdef USE_DIVX_BUILTIN_PP
     case VDCTRL_QUERY_MAX_PP_LEVEL:
-	return 9; // for divx4linux
+#if DECORE_VERSION >= 20021112
+        return 6; // divx4linux >= 5.0.5 -> 0..60
+#else
+        return 10; // divx4linux < 5.0.5 -> 0..100
+#endif 
     case VDCTRL_SET_PP_LEVEL: {
+        int quality=*((int*)arg);
+#if DECORE_VERSION >= 20021112
+        int32_t iInstruction, iPostproc;
+        if(quality<0 || quality>6) quality=6;
+        iInstruction = DEC_ADJ_POSTPROCESSING | DEC_ADJ_SET;
+        iPostproc = quality*10;
+        decore(dec_handle, DEC_OPT_ADJUST, &iInstruction, &iPostproc);
+#else
 	DEC_SET dec_set;
-	int quality=*((int*)arg);
-	if(quality<0 || quality>9) quality=9;
+	if(quality<0 || quality>10) quality=10;
 	dec_set.postproc_level=quality*10;
 	decore(0x123,DEC_OPT_SETPP,&dec_set,NULL);
+#endif
 	return CONTROL_OK;
     }
 #endif
-#ifdef DECORE_VERSION
 #if DECORE_VERSION >= 20011010
     case VDCTRL_SET_EQUALIZER: {
 	va_list ap;
@@ -67,17 +86,35 @@
 	value=va_arg(ap, int);
 	va_end(ap);
 
-        if(!strcasecmp(arg,"Brightness")) option=DEC_GAMMA_BRIGHTNESS;
-        else if(!strcasecmp(arg, "Contrast")) option=DEC_GAMMA_CONTRAST;
-        else if(!strcasecmp(arg,"Saturation")) option=DEC_GAMMA_SATURATION;
+        if(!strcasecmp(arg,"Brightness"))
+#if DECORE_VERSION >= 20021112
+            option=DEC_ADJ_BRIGHTNESS | DEC_ADJ_SET;
+#else
+            option=DEC_GAMMA_BRIGHTNESS;
+#endif
+        else if(!strcasecmp(arg, "Contrast"))
+#if DECORE_VERSION >= 20021112
+            option=DEC_ADJ_CONTRAST | DEC_ADJ_SET;
+#else
+            option=DEC_GAMMA_CONTRAST;
+#endif
+        else if(!strcasecmp(arg,"Saturation"))
+#if DECORE_VERSION >= 20021112
+            option=DEC_ADJ_SATURATION | DEC_ADJ_SET;
+#else
+            option=DEC_GAMMA_SATURATION;
+#endif
         else return CONTROL_FALSE;
 	
         value = (value * 128) / 100;
+#if DECORE_VERSION >= 20021112
+        decore(dec_handle, DEC_OPT_ADJUST, &option, &value);
+#else
         decore(0x123, DEC_OPT_GAMMA, (void *)option, (void *) value);
+#endif
 	return CONTROL_OK;
     }
 #endif
-#endif
     
     }
 
@@ -86,6 +123,89 @@
 
 // init driver
 static int init(sh_video_t *sh){
+#if DECORE_VERSION >= 20021112
+    DEC_INIT dec_init;
+    int iSize=sizeof(DivXBitmapInfoHeader);
+    DivXBitmapInfoHeader* pbi=malloc(iSize);
+    int32_t iInstruction;
+
+    if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YUY2)) return 0;
+
+    memset(&dec_init, 0, sizeof(dec_init));
+    memset(pbi, 0, iSize);
+
+    switch(sh->format) {
+      case mmioFOURCC('D','I','V','3'):
+        dec_init.codec_version = 311;
+        break;
+      case mmioFOURCC('D','I','V','X'):
+        dec_init.codec_version = 412;
+        break;
+      case mmioFOURCC('D','X','5','0'):
+      default: // Fallback to DivX 5 behaviour
+        dec_init.codec_version = 500;
+    }
+
+    // no smoothing of the CPU load
+    dec_init.smooth_playback = 0;
+
+    pbi->biSize=iSize;
+
+    switch(sh->codec->outfmt[sh->outfmtidx]){
+        case IMGFMT_YV12: {
+            pbi->biCompression=mmioFOURCC('Y','V','1','2');
+            break;
+        }
+        case IMGFMT_YUY2: {
+            pbi->biCompression=mmioFOURCC('Y','U','Y','2');
+            break;
+        }
+        case IMGFMT_UYVY: {
+            pbi->biCompression=mmioFOURCC('U','Y','V','Y');
+            break;
+        }
+        case IMGFMT_I420: {
+            pbi->biCompression=mmioFOURCC('I','4','2','0');
+            break;
+        }
+        case IMGFMT_BGR15: {
+            pbi->biCompression=0;
+            pbi->biBitCount=16;
+            break;
+        }
+        case IMGFMT_BGR16: {
+            pbi->biCompression=3;
+            pbi->biBitCount=16;
+            break;
+        }
+        case IMGFMT_BGR24: {
+            pbi->biCompression=0;
+            pbi->biBitCount=24;
+            break;
+        }
+        case IMGFMT_BGR32: {
+            pbi->biCompression=0;
+            pbi->biBitCount=32;
+            break;
+        }
+        default:
+          mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Unsupported out_fmt: 0x%X\n",sh->codec->outfmt[sh->outfmtidx]);
+          return 0;
+    }
+
+    pbi->biWidth = sh->disp_w;
+    pbi->biHeight = sh->disp_h;
+
+    decore(&dec_handle, DEC_OPT_INIT, &dec_init, NULL);
+    decore(dec_handle, DEC_OPT_SETOUT, pbi, NULL);
+
+#ifdef USE_DIVX_BUILTIN_PP
+    iInstruction = DEC_ADJ_POSTPROCESSING | DEC_ADJ_SET;
+    decore(dec_handle, DEC_OPT_ADJUST, &iInstruction, &divx_quality);
+#endif
+
+    free(pbi);
+#else // DECORE_VERSION < 20021112
     DEC_PARAM dec_param;
     DEC_SET dec_set;
     int bits=16;
@@ -142,7 +262,8 @@
     dec_set.postproc_level = divx_quality;
     decore(0x123, DEC_OPT_SETPP, &dec_set, NULL);
 #endif
-    
+#endif // DECORE_VERSION    
+
     mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: DivX4Linux video codec init OK!\n");
 
     return 1;
@@ -150,7 +271,12 @@
 
 // uninit driver
 static void uninit(sh_video_t *sh){
+#if DECORE_VERSION >= 20021112
+    decore(dec_handle, DEC_OPT_RELEASE, NULL, NULL);
+    dec_handle = NULL;
+#else
     decore(0x123,DEC_OPT_RELEASE,NULL,NULL);
+#endif
 }
 
 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
@@ -176,7 +302,12 @@
     dec_frame.bmp=mpi->planes[0];
     dec_frame.stride=mpi->width;
 
-    decore(0x123,
+    decore(
+#if DECORE_VERSION >= 20021112
+        dec_handle,
+#else
+        0x123,
+#endif
 #ifndef DEC_OPT_FRAME_311
         DEC_OPT_FRAME,
 #else