driverproc.c
上传用户:hjq518
上传日期:2021-12-09
资源大小:5084k
文件大小:7k
源码类别:

Audio

开发平台:

Visual C++

  1. /*****************************************************************************
  2.  * drvproc.c: vfw x264 wrapper
  3.  *****************************************************************************
  4.  * Copyright (C) 2003 Laurent Aimar
  5.  * $Id: driverproc.c,v 1.1 2004/06/03 19:27:09 fenrir Exp $
  6.  *
  7.  * Authors: Justin Clay
  8.  *          Laurent Aimar <fenrir@via.ecp.fr>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  23.  *****************************************************************************/
  24. #include "x264vfw.h"
  25. /* Global dll instance */
  26. HINSTANCE g_hInst;
  27. /* Calling back point for our DLL so we can keep track of the window in g_hInst */
  28. BOOL WINAPI DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
  29. {
  30.     g_hInst = (HINSTANCE) hModule;
  31.     return TRUE;
  32. }
  33. /* This little puppy handles the calls which vfw programs send out to the codec */
  34. LRESULT WINAPI DriverProc( DWORD dwDriverId, HDRVR hDriver, UINT uMsg, LPARAM lParam1, LPARAM lParam2 )
  35. {
  36.     CODEC *codec = (CODEC *)dwDriverId;
  37.     switch( uMsg )
  38.     {
  39.         case DRV_LOAD:
  40.         case DRV_FREE:
  41.             return DRV_OK;
  42.         case DRV_OPEN:
  43.         {
  44.             ICOPEN *icopen = (ICOPEN *)lParam2;
  45.             if( icopen != NULL && icopen->fccType != ICTYPE_VIDEO )
  46.                 return DRV_CANCEL;
  47.             if( ( codec = malloc( sizeof( CODEC ) ) ) == NULL )
  48.             {
  49.                 if( icopen != NULL )
  50.                     icopen->dwError = ICERR_MEMORY;
  51.                 return 0;
  52.             }
  53.             memset( codec, 0, sizeof( CODEC ) );
  54.             config_reg_load( &codec->config );
  55.             codec->h = NULL;
  56.             if( icopen != NULL )
  57.                 icopen->dwError = ICERR_OK;
  58.             return (LRESULT)codec;
  59.         }
  60.         case DRV_CLOSE:
  61.             /* From xvid: compress_end/decompress_end don't always get called */
  62.             compress_end(codec);
  63.             free( codec );
  64.             return DRV_OK;
  65.         case DRV_DISABLE:
  66.         case DRV_ENABLE:
  67.             return DRV_OK;
  68.         case DRV_INSTALL:
  69.         case DRV_REMOVE:
  70.             return DRV_OK;
  71.         case DRV_QUERYCONFIGURE:
  72.         case DRV_CONFIGURE:
  73.             return DRV_CANCEL;
  74.         /* info */
  75.         case ICM_GETINFO:
  76.         {
  77.             ICINFO *icinfo = (ICINFO *)lParam1;
  78.             /* return a description */
  79.             icinfo->fccType      = ICTYPE_VIDEO;
  80.             icinfo->fccHandler   = FOURCC_X264;
  81.             icinfo->dwFlags      = VIDCF_COMPRESSFRAMES | VIDCF_FASTTEMPORALC;
  82.             icinfo->dwVersion    = 0;
  83.             icinfo->dwVersionICM = ICVERSION;
  84.             wcscpy( icinfo->szName, X264_NAME_L);
  85.             wcscpy( icinfo->szDescription, X264_DESC_L);
  86.             return lParam2; /* size of struct */
  87.         }
  88.         case ICM_ABOUT:
  89.             if( lParam1 != -1 )
  90.             {
  91.                 DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_ABOUT), (HWND)lParam1, callback_about, 0 );
  92.             }
  93.             return ICERR_OK;
  94.         case ICM_CONFIGURE:
  95.             if( lParam1 != -1 )
  96.             {
  97.                 CONFIG temp;
  98.                 codec->config.b_save = FALSE;
  99.                 memcpy( &temp, &codec->config, sizeof(CONFIG) );
  100.                 DialogBoxParam( g_hInst, MAKEINTRESOURCE(IDD_MAINCONFIG), (HWND)lParam1, callback_main, (LPARAM)&temp );
  101.                 if( temp.b_save )
  102.                 {
  103.                     memcpy( &codec->config, &temp, sizeof(CONFIG) );
  104.                     config_reg_save( &codec->config );
  105.                 }
  106.             }
  107.             return ICERR_OK;
  108.         case ICM_GETSTATE:
  109.             if( (void*)lParam1 == NULL )
  110.             {
  111.                 return sizeof( CONFIG );
  112.             }
  113.             memcpy( (void*)lParam1, &codec->config, sizeof( CONFIG ) );
  114.             return ICERR_OK;
  115.         case ICM_SETSTATE:
  116.             if( (void*)lParam1 == NULL )
  117.             {
  118.                 config_reg_load( &codec->config );
  119.                 return 0;
  120.             }
  121.             memcpy( &codec->config, (void*)lParam1, sizeof( CONFIG ) );
  122.             return 0;
  123.         /* not sure the difference, private/public data? */
  124.         case ICM_GET:
  125.         case ICM_SET:
  126.             return ICERR_OK;
  127.         /* older-stype config */
  128.         case ICM_GETDEFAULTQUALITY:
  129.         case ICM_GETQUALITY:
  130.         case ICM_SETQUALITY:
  131.         case ICM_GETBUFFERSWANTED:
  132.         case ICM_GETDEFAULTKEYFRAMERATE:
  133.             return ICERR_UNSUPPORTED;
  134.         /* compressor */
  135.         case ICM_COMPRESS_QUERY:
  136.             return compress_query(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2);
  137.         case ICM_COMPRESS_GET_FORMAT:
  138.             return compress_get_format(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2);
  139.         case ICM_COMPRESS_GET_SIZE:
  140.             return compress_get_size(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2);
  141.         case ICM_COMPRESS_FRAMES_INFO:
  142.             return compress_frames_info(codec, (ICCOMPRESSFRAMES *)lParam1);
  143.         case ICM_COMPRESS_BEGIN:
  144.             return compress_begin(codec, (BITMAPINFO *)lParam1, (BITMAPINFO *)lParam2);
  145.         case ICM_COMPRESS_END:
  146.             return compress_end(codec);
  147.         case ICM_COMPRESS:
  148.             return compress(codec, (ICCOMPRESS *)lParam1);
  149.         /* decompressor : not implemented */
  150.         case ICM_DECOMPRESS_QUERY:
  151.         case ICM_DECOMPRESS_GET_FORMAT:
  152.         case ICM_DECOMPRESS_BEGIN:
  153.         case ICM_DECOMPRESS_END:
  154.         case ICM_DECOMPRESS:
  155.         case ICM_DECOMPRESS_GET_PALETTE:
  156.         case ICM_DECOMPRESS_SET_PALETTE:
  157.         case ICM_DECOMPRESSEX_QUERY:
  158.         case ICM_DECOMPRESSEX_BEGIN:
  159.         case ICM_DECOMPRESSEX_END:
  160.         case ICM_DECOMPRESSEX:
  161.             return ICERR_UNSUPPORTED;
  162.         default:
  163.         if (uMsg < DRV_USER)
  164.             return DefDriverProc(dwDriverId, hDriver, uMsg, lParam1, lParam2);
  165.         else 
  166.             return ICERR_UNSUPPORTED;
  167.     }
  168. }
  169. void WINAPI Configure(HWND hwnd, HINSTANCE hinst, LPTSTR lpCmdLine, int nCmdShow)
  170. {
  171.     DWORD dwDriverId;
  172.     dwDriverId = DriverProc(0, 0, DRV_OPEN, 0, 0);
  173.     if (dwDriverId != (DWORD)NULL)
  174.     {
  175.         DriverProc(dwDriverId, 0, ICM_CONFIGURE, (LPARAM)GetDesktopWindow(), 0);
  176.         DriverProc(dwDriverId, 0, DRV_CLOSE, 0, 0);
  177.     }
  178. }