main.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. *
  3. * Lame ACM wrapper, encode/decode MP3 based RIFF/AVI files in MS Windows
  4. *
  5. * Copyright (c) 2002 Steve Lhomme <steve.lhomme at free.fr>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. /*!
  23. \author Steve Lhomme
  24. \version \$Id$
  25. */
  26. #if !defined(STRICT)
  27. #define STRICT
  28. #endif // STRICT
  29. #include <windows.h>
  30. /// The ACM is considered as a driver and run in Kernel-Mode
  31. /// So the new/delete operators have to be overriden in order to use memory
  32. /// readable out of the calling process
  33. void * operator new( unsigned int cb )
  34. {
  35. return LocalAlloc(LPTR, cb); // VirtualAlloc
  36. }
  37. void operator delete(void *block) {
  38. LocalFree(block);
  39. }
  40. extern "C" {
  41. void *acm_Calloc( size_t num, size_t size )
  42. {
  43. return LocalAlloc(LPTR, num * size); // VirtualAlloc
  44. }
  45. void *acm_Malloc( size_t size )
  46. {
  47. return LocalAlloc(LPTR, size); // VirtualAlloc
  48. }
  49. void acm_Free( void * mem)
  50. {
  51. LocalFree(mem);
  52. }
  53. };
  54. ////// End of memory instrumentation
  55. #include <mmreg.h>
  56. #include <msacm.h>
  57. #include <msacmdrv.h>
  58. #include <assert.h>
  59. #include "AEncodeProperties.h"
  60. #include "ACM.h"
  61. #include "resource.h"
  62. #include "adebug.h"
  63. ADbg * debug = NULL;
  64. LONG WINAPI DriverProc(DWORD dwDriverId, HDRVR hdrvr, UINT msg, LONG lParam1, LONG lParam2)
  65. {
  66. switch (msg)
  67. {
  68. case DRV_OPEN: // acmDriverOpen
  69. {
  70. if (debug == NULL) {
  71. debug = new ADbg(DEBUG_LEVEL_CREATION);
  72. debug->setPrefix("LAMEdrv");
  73. }
  74. if (debug != NULL)
  75. {
  76. // Sent when the driver is opened.
  77. if (lParam2 != NULL)
  78. debug->OutPut(DEBUG_LEVEL_MSG, "DRV_OPEN (ID 0x%08X), pDesc = 0x%08X",dwDriverId,lParam2);
  79. else
  80. debug->OutPut(DEBUG_LEVEL_MSG, "DRV_OPEN (ID 0x%08X), pDesc = NULL",dwDriverId);
  81. }
  82. if (lParam2 != NULL) {
  83. LPACMDRVOPENDESC pDesc = (LPACMDRVOPENDESC)lParam2;
  84. if (pDesc->fccType != ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC) {
  85. if (debug != NULL)
  86. {
  87. debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "wrong pDesc->fccType (0x%08X)",pDesc->fccType);
  88. }
  89. return NULL;
  90. }
  91. } else {
  92. if (debug != NULL)
  93. {
  94. debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "pDesc == NULL");
  95. }
  96. }
  97. ACM * ThisACM = new ACM(GetDriverModuleHandle(hdrvr));
  98. if (debug != NULL)
  99. {
  100. debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "OPENED instance 0x%08X",ThisACM);
  101. }
  102. return (LONG)ThisACM;// returns 0L to fail
  103. // value subsequently used
  104. // for dwDriverId.
  105. }
  106. break;
  107. case DRV_CLOSE: // acmDriverClose
  108. {
  109. if (debug != NULL)
  110. {
  111. // Sent when the driver is closed. Drivers are
  112. // unloaded when the open count reaches zero.
  113. debug->OutPut(DEBUG_LEVEL_MSG, "DRV_CLOSE");
  114. }
  115. ACM * ThisACM = (ACM *)dwDriverId;
  116. delete ThisACM;
  117. if (debug != NULL)
  118. {
  119. debug->OutPut(DEBUG_LEVEL_FUNC_CODE, "CLOSED instance 0x%08X",ThisACM);
  120. delete debug;
  121. debug = NULL;
  122. }
  123. return 1L; // returns 0L to fail
  124. }
  125. break;
  126. case DRV_LOAD:
  127. {
  128. // nothing to do
  129. if (debug != NULL)
  130. {
  131. // debug->OutPut(DEBUG_LEVEL_MSG, "DRV_LOAD, version %s %s %s", ACM_VERSION, __DATE__, __TIME__);
  132. debug->OutPut(DEBUG_LEVEL_MSG, "DRV_LOAD, %s %s", __DATE__, __TIME__);
  133. }
  134. return 1L;
  135. }
  136. break;
  137. case DRV_ENABLE:
  138. {
  139. // nothing to do
  140. if (debug != NULL)
  141. {
  142. debug->OutPut(DEBUG_LEVEL_MSG, "DRV_ENABLE");
  143. }
  144. return 1L;
  145. }
  146. break;
  147. case DRV_DISABLE:
  148. {
  149. // nothing to do
  150. if (debug != NULL)
  151. {
  152. debug->OutPut(DEBUG_LEVEL_MSG, "DRV_DISABLE");
  153. }
  154. return 1L;
  155. }
  156. break;
  157. case DRV_FREE:
  158. {
  159. if (debug != NULL)
  160. {
  161. debug->OutPut(DEBUG_LEVEL_MSG, "DRV_FREE");
  162. }
  163. return 1L;
  164. }
  165. break;
  166. default:
  167. {
  168. ACM * ThisACM = (ACM *)dwDriverId;
  169. if (ThisACM != NULL)
  170. return ThisACM->DriverProcedure(hdrvr, msg, lParam1, lParam2);
  171. else
  172. {
  173. if (debug != NULL)
  174. {
  175. debug->OutPut(DEBUG_LEVEL_MSG, "Driver not opened, unknown message (0x%08X), lParam1 = 0x%08X, lParam2 = 0x%08X", msg, lParam1, lParam2);
  176. }
  177. return DefDriverProc (dwDriverId, hdrvr, msg, lParam1, lParam2);
  178. }
  179. }
  180. break;
  181. }
  182. }