|
Packit |
47f805 |
/**
|
|
Packit |
47f805 |
*
|
|
Packit |
47f805 |
* Lame ACM wrapper, encode/decode MP3 based RIFF/AVI files in MS Windows
|
|
Packit |
47f805 |
*
|
|
Packit |
47f805 |
* Copyright (c) 2002 Steve Lhomme <steve.lhomme at free.fr>
|
|
Packit |
47f805 |
*
|
|
Packit |
47f805 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
47f805 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
47f805 |
* License as published by the Free Software Foundation; either
|
|
Packit |
47f805 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
47f805 |
*
|
|
Packit |
47f805 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
47f805 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
47f805 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
47f805 |
* Lesser General Public License for more details.
|
|
Packit |
47f805 |
*
|
|
Packit |
47f805 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
47f805 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
47f805 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
Packit |
47f805 |
*
|
|
Packit |
47f805 |
*/
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
/*!
|
|
Packit |
47f805 |
\author Steve Lhomme
|
|
Packit |
47f805 |
\version \$Id: main.cpp,v 1.5 2006/12/25 21:37:34 robert Exp $
|
|
Packit |
47f805 |
*/
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#if !defined(STRICT)
|
|
Packit |
47f805 |
#define STRICT
|
|
Packit |
47f805 |
#endif // STRICT
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#include <windows.h>
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
/// The ACM is considered as a driver and run in Kernel-Mode
|
|
Packit |
47f805 |
/// So the new/delete operators have to be overriden in order to use memory
|
|
Packit |
47f805 |
/// readable out of the calling process
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
void * operator new( unsigned int cb )
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
return LocalAlloc(LPTR, cb); // VirtualAlloc
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
void operator delete(void *block) {
|
|
Packit |
47f805 |
LocalFree(block);
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
extern "C" {
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
void *acm_Calloc( size_t num, size_t size )
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
return LocalAlloc(LPTR, num * size); // VirtualAlloc
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
void *acm_Malloc( size_t size )
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
return LocalAlloc(LPTR, size); // VirtualAlloc
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
void acm_Free( void * mem)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
LocalFree(mem);
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
};
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
////// End of memory instrumentation
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#include <mmreg.h>
|
|
Packit |
47f805 |
#include <msacm.h>
|
|
Packit |
47f805 |
#include <msacmdrv.h>
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#include <assert.h>
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
#include "AEncodeProperties.h"
|
|
Packit |
47f805 |
#include "ACM.h"
|
|
Packit |
47f805 |
#include "resource.h"
|
|
Packit |
47f805 |
#include "adebug.h"
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
ADbg * debug = NULL;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
LONG WINAPI DriverProc(DWORD dwDriverId, HDRVR hdrvr, UINT msg, LONG lParam1, LONG lParam2)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
switch (msg)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
case DRV_OPEN: // acmDriverOpen
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
if (debug == NULL) {
|
|
Packit |
47f805 |
debug = new ADbg(DEBUG_LEVEL_CREATION);
|
|
Packit |
47f805 |
debug->setPrefix("LAMEdrv");
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
// Sent when the driver is opened.
|
|
Packit |
47f805 |
if (lParam2 != NULL)
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_MSG, "DRV_OPEN (ID 0x%08X), pDesc = 0x%08X",dwDriverId,lParam2);
|
|
Packit |
47f805 |
else
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_MSG, "DRV_OPEN (ID 0x%08X), pDesc = NULL",dwDriverId);
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
if (lParam2 != NULL) {
|
|
Packit |
47f805 |
LPACMDRVOPENDESC pDesc = (LPACMDRVOPENDESC)lParam2;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
if (pDesc->fccType != ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC) {
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "wrong pDesc->fccType (0x%08X)",pDesc->fccType);
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
return NULL;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
} else {
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "pDesc == NULL");
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
ACM * ThisACM = new ACM(GetDriverModuleHandle(hdrvr));
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "OPENED instance 0x%08X",ThisACM);
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
return (LONG)ThisACM;// returns 0L to fail
|
|
Packit |
47f805 |
// value subsequently used
|
|
Packit |
47f805 |
// for dwDriverId.
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
break;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
case DRV_CLOSE: // acmDriverClose
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
// Sent when the driver is closed. Drivers are
|
|
Packit |
47f805 |
// unloaded when the open count reaches zero.
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_MSG, "DRV_CLOSE");
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
ACM * ThisACM = (ACM *)dwDriverId;
|
|
Packit |
47f805 |
delete ThisACM;
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "CLOSED instance 0x%08X",ThisACM);
|
|
Packit |
47f805 |
delete debug;
|
|
Packit |
47f805 |
debug = NULL;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
return 1L; // returns 0L to fail
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
break;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
case DRV_LOAD:
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
// nothing to do
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
// debug->OutPut(DEBUG_LEVEL_MSG, "DRV_LOAD, version %s %s %s", ACM_VERSION, __DATE__, __TIME__);
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_MSG, "DRV_LOAD, %s %s", __DATE__, __TIME__);
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
return 1L;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
break;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
case DRV_ENABLE:
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
// nothing to do
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_MSG, "DRV_ENABLE");
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
return 1L;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
break;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
case DRV_DISABLE:
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
// nothing to do
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_MSG, "DRV_DISABLE");
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
return 1L;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
break;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
case DRV_FREE:
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_MSG, "DRV_FREE");
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
return 1L;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
break;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
default:
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
ACM * ThisACM = (ACM *)dwDriverId;
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
if (ThisACM != NULL)
|
|
Packit |
47f805 |
return ThisACM->DriverProcedure(hdrvr, msg, lParam1, lParam2);
|
|
Packit |
47f805 |
else
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
if (debug != NULL)
|
|
Packit |
47f805 |
{
|
|
Packit |
47f805 |
debug->OutPut(DEBUG_LEVEL_MSG, "Driver not opened, unknown message (0x%08X), lParam1 = 0x%08X, lParam2 = 0x%08X", msg, lParam1, lParam2);
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|
|
Packit |
47f805 |
return DefDriverProc (dwDriverId, hdrvr, msg, lParam1, lParam2);
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
break;
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
}
|
|
Packit |
47f805 |
|