1159b3361Sopenharmony_ci/** 2159b3361Sopenharmony_ci * 3159b3361Sopenharmony_ci * Lame ACM wrapper, encode/decode MP3 based RIFF/AVI files in MS Windows 4159b3361Sopenharmony_ci * 5159b3361Sopenharmony_ci * Copyright (c) 2002 Steve Lhomme <steve.lhomme at free.fr> 6159b3361Sopenharmony_ci * 7159b3361Sopenharmony_ci * This library is free software; you can redistribute it and/or 8159b3361Sopenharmony_ci * modify it under the terms of the GNU Lesser General Public 9159b3361Sopenharmony_ci * License as published by the Free Software Foundation; either 10159b3361Sopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 11159b3361Sopenharmony_ci * 12159b3361Sopenharmony_ci * This library is distributed in the hope that it will be useful, 13159b3361Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 14159b3361Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15159b3361Sopenharmony_ci * Lesser General Public License for more details. 16159b3361Sopenharmony_ci * 17159b3361Sopenharmony_ci * You should have received a copy of the GNU Lesser General Public 18159b3361Sopenharmony_ci * License along with this library; if not, write to the Free Software 19159b3361Sopenharmony_ci * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20159b3361Sopenharmony_ci * 21159b3361Sopenharmony_ci */ 22159b3361Sopenharmony_ci 23159b3361Sopenharmony_ci/*! 24159b3361Sopenharmony_ci \author Steve Lhomme 25159b3361Sopenharmony_ci \version \$Id$ 26159b3361Sopenharmony_ci*/ 27159b3361Sopenharmony_ci 28159b3361Sopenharmony_ci#if !defined(STRICT) 29159b3361Sopenharmony_ci#define STRICT 30159b3361Sopenharmony_ci#endif // STRICT 31159b3361Sopenharmony_ci 32159b3361Sopenharmony_ci#include <windows.h> 33159b3361Sopenharmony_ci 34159b3361Sopenharmony_ci/// The ACM is considered as a driver and run in Kernel-Mode 35159b3361Sopenharmony_ci/// So the new/delete operators have to be overriden in order to use memory 36159b3361Sopenharmony_ci/// readable out of the calling process 37159b3361Sopenharmony_ci 38159b3361Sopenharmony_civoid * operator new( unsigned int cb ) 39159b3361Sopenharmony_ci{ 40159b3361Sopenharmony_ci return LocalAlloc(LPTR, cb); // VirtualAlloc 41159b3361Sopenharmony_ci} 42159b3361Sopenharmony_ci 43159b3361Sopenharmony_civoid operator delete(void *block) { 44159b3361Sopenharmony_ci LocalFree(block); 45159b3361Sopenharmony_ci} 46159b3361Sopenharmony_ci 47159b3361Sopenharmony_ciextern "C" { 48159b3361Sopenharmony_ci 49159b3361Sopenharmony_ci void *acm_Calloc( size_t num, size_t size ) 50159b3361Sopenharmony_ci { 51159b3361Sopenharmony_ci return LocalAlloc(LPTR, num * size); // VirtualAlloc 52159b3361Sopenharmony_ci } 53159b3361Sopenharmony_ci 54159b3361Sopenharmony_ci void *acm_Malloc( size_t size ) 55159b3361Sopenharmony_ci { 56159b3361Sopenharmony_ci return LocalAlloc(LPTR, size); // VirtualAlloc 57159b3361Sopenharmony_ci } 58159b3361Sopenharmony_ci 59159b3361Sopenharmony_ci void acm_Free( void * mem) 60159b3361Sopenharmony_ci { 61159b3361Sopenharmony_ci LocalFree(mem); 62159b3361Sopenharmony_ci } 63159b3361Sopenharmony_ci}; 64159b3361Sopenharmony_ci 65159b3361Sopenharmony_ci////// End of memory instrumentation 66159b3361Sopenharmony_ci 67159b3361Sopenharmony_ci#include <mmreg.h> 68159b3361Sopenharmony_ci#include <msacm.h> 69159b3361Sopenharmony_ci#include <msacmdrv.h> 70159b3361Sopenharmony_ci 71159b3361Sopenharmony_ci#include <assert.h> 72159b3361Sopenharmony_ci 73159b3361Sopenharmony_ci#include "AEncodeProperties.h" 74159b3361Sopenharmony_ci#include "ACM.h" 75159b3361Sopenharmony_ci#include "resource.h" 76159b3361Sopenharmony_ci#include "adebug.h" 77159b3361Sopenharmony_ci 78159b3361Sopenharmony_ci 79159b3361Sopenharmony_ciADbg * debug = NULL; 80159b3361Sopenharmony_ci 81159b3361Sopenharmony_ciLONG WINAPI DriverProc(DWORD dwDriverId, HDRVR hdrvr, UINT msg, LONG lParam1, LONG lParam2) 82159b3361Sopenharmony_ci{ 83159b3361Sopenharmony_ci 84159b3361Sopenharmony_ci switch (msg) 85159b3361Sopenharmony_ci { 86159b3361Sopenharmony_ci case DRV_OPEN: // acmDriverOpen 87159b3361Sopenharmony_ci { 88159b3361Sopenharmony_ci if (debug == NULL) { 89159b3361Sopenharmony_ci debug = new ADbg(DEBUG_LEVEL_CREATION); 90159b3361Sopenharmony_ci debug->setPrefix("LAMEdrv"); 91159b3361Sopenharmony_ci } 92159b3361Sopenharmony_ci 93159b3361Sopenharmony_ci if (debug != NULL) 94159b3361Sopenharmony_ci { 95159b3361Sopenharmony_ci // Sent when the driver is opened. 96159b3361Sopenharmony_ci if (lParam2 != NULL) 97159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_MSG, "DRV_OPEN (ID 0x%08X), pDesc = 0x%08X",dwDriverId,lParam2); 98159b3361Sopenharmony_ci else 99159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_MSG, "DRV_OPEN (ID 0x%08X), pDesc = NULL",dwDriverId); 100159b3361Sopenharmony_ci } 101159b3361Sopenharmony_ci 102159b3361Sopenharmony_ci if (lParam2 != NULL) { 103159b3361Sopenharmony_ci LPACMDRVOPENDESC pDesc = (LPACMDRVOPENDESC)lParam2; 104159b3361Sopenharmony_ci 105159b3361Sopenharmony_ci if (pDesc->fccType != ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC) { 106159b3361Sopenharmony_ci if (debug != NULL) 107159b3361Sopenharmony_ci { 108159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "wrong pDesc->fccType (0x%08X)",pDesc->fccType); 109159b3361Sopenharmony_ci } 110159b3361Sopenharmony_ci return NULL; 111159b3361Sopenharmony_ci } 112159b3361Sopenharmony_ci } else { 113159b3361Sopenharmony_ci if (debug != NULL) 114159b3361Sopenharmony_ci { 115159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "pDesc == NULL"); 116159b3361Sopenharmony_ci } 117159b3361Sopenharmony_ci } 118159b3361Sopenharmony_ci 119159b3361Sopenharmony_ci ACM * ThisACM = new ACM(GetDriverModuleHandle(hdrvr)); 120159b3361Sopenharmony_ci 121159b3361Sopenharmony_ci if (debug != NULL) 122159b3361Sopenharmony_ci { 123159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "OPENED instance 0x%08X",ThisACM); 124159b3361Sopenharmony_ci } 125159b3361Sopenharmony_ci 126159b3361Sopenharmony_ci return (LONG)ThisACM;// returns 0L to fail 127159b3361Sopenharmony_ci // value subsequently used 128159b3361Sopenharmony_ci // for dwDriverId. 129159b3361Sopenharmony_ci } 130159b3361Sopenharmony_ci break; 131159b3361Sopenharmony_ci 132159b3361Sopenharmony_ci case DRV_CLOSE: // acmDriverClose 133159b3361Sopenharmony_ci { 134159b3361Sopenharmony_ci if (debug != NULL) 135159b3361Sopenharmony_ci { 136159b3361Sopenharmony_ci // Sent when the driver is closed. Drivers are 137159b3361Sopenharmony_ci // unloaded when the open count reaches zero. 138159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_MSG, "DRV_CLOSE"); 139159b3361Sopenharmony_ci } 140159b3361Sopenharmony_ci 141159b3361Sopenharmony_ci ACM * ThisACM = (ACM *)dwDriverId; 142159b3361Sopenharmony_ci delete ThisACM; 143159b3361Sopenharmony_ci if (debug != NULL) 144159b3361Sopenharmony_ci { 145159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "CLOSED instance 0x%08X",ThisACM); 146159b3361Sopenharmony_ci delete debug; 147159b3361Sopenharmony_ci debug = NULL; 148159b3361Sopenharmony_ci } 149159b3361Sopenharmony_ci return 1L; // returns 0L to fail 150159b3361Sopenharmony_ci } 151159b3361Sopenharmony_ci break; 152159b3361Sopenharmony_ci 153159b3361Sopenharmony_ci case DRV_LOAD: 154159b3361Sopenharmony_ci { 155159b3361Sopenharmony_ci // nothing to do 156159b3361Sopenharmony_ci if (debug != NULL) 157159b3361Sopenharmony_ci { 158159b3361Sopenharmony_ci// debug->OutPut(DEBUG_LEVEL_MSG, "DRV_LOAD, version %s %s %s", ACM_VERSION, __DATE__, __TIME__); 159159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_MSG, "DRV_LOAD, %s %s", __DATE__, __TIME__); 160159b3361Sopenharmony_ci } 161159b3361Sopenharmony_ci return 1L; 162159b3361Sopenharmony_ci } 163159b3361Sopenharmony_ci break; 164159b3361Sopenharmony_ci 165159b3361Sopenharmony_ci case DRV_ENABLE: 166159b3361Sopenharmony_ci { 167159b3361Sopenharmony_ci // nothing to do 168159b3361Sopenharmony_ci if (debug != NULL) 169159b3361Sopenharmony_ci { 170159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_MSG, "DRV_ENABLE"); 171159b3361Sopenharmony_ci } 172159b3361Sopenharmony_ci return 1L; 173159b3361Sopenharmony_ci } 174159b3361Sopenharmony_ci break; 175159b3361Sopenharmony_ci 176159b3361Sopenharmony_ci case DRV_DISABLE: 177159b3361Sopenharmony_ci { 178159b3361Sopenharmony_ci // nothing to do 179159b3361Sopenharmony_ci if (debug != NULL) 180159b3361Sopenharmony_ci { 181159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_MSG, "DRV_DISABLE"); 182159b3361Sopenharmony_ci } 183159b3361Sopenharmony_ci return 1L; 184159b3361Sopenharmony_ci } 185159b3361Sopenharmony_ci break; 186159b3361Sopenharmony_ci 187159b3361Sopenharmony_ci case DRV_FREE: 188159b3361Sopenharmony_ci { 189159b3361Sopenharmony_ci if (debug != NULL) 190159b3361Sopenharmony_ci { 191159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_MSG, "DRV_FREE"); 192159b3361Sopenharmony_ci } 193159b3361Sopenharmony_ci return 1L; 194159b3361Sopenharmony_ci } 195159b3361Sopenharmony_ci break; 196159b3361Sopenharmony_ci 197159b3361Sopenharmony_ci default: 198159b3361Sopenharmony_ci { 199159b3361Sopenharmony_ci ACM * ThisACM = (ACM *)dwDriverId; 200159b3361Sopenharmony_ci 201159b3361Sopenharmony_ci if (ThisACM != NULL) 202159b3361Sopenharmony_ci return ThisACM->DriverProcedure(hdrvr, msg, lParam1, lParam2); 203159b3361Sopenharmony_ci else 204159b3361Sopenharmony_ci { 205159b3361Sopenharmony_ci if (debug != NULL) 206159b3361Sopenharmony_ci { 207159b3361Sopenharmony_ci debug->OutPut(DEBUG_LEVEL_MSG, "Driver not opened, unknown message (0x%08X), lParam1 = 0x%08X, lParam2 = 0x%08X", msg, lParam1, lParam2); 208159b3361Sopenharmony_ci } 209159b3361Sopenharmony_ci 210159b3361Sopenharmony_ci return DefDriverProc (dwDriverId, hdrvr, msg, lParam1, lParam2); 211159b3361Sopenharmony_ci } 212159b3361Sopenharmony_ci } 213159b3361Sopenharmony_ci break; 214159b3361Sopenharmony_ci } 215159b3361Sopenharmony_ci} 216159b3361Sopenharmony_ci 217