dllmain.c
上传用户:bjsgzm
上传日期:2007-01-08
资源大小:256k
文件大小:5k
源码类别:

mpeg/mp3

开发平台:

Visual C++

  1. #include <windows.h>
  2. #define _BLADEDLL
  3. #include "codec.h"
  4. #include "bladedll.h"
  5. /************ Version *************/
  6. #define DLL_MAJOR_VERSION 0x01
  7. #define DLL_MINOR_VERSION 0x01
  8. #define ENCODER_MAJOR_VERSION 0x00
  9. #define ENCODER_MINOR_VERSION 0x5A // 90
  10. #define RELEASE_DAY 23
  11. #define RELEASE_MONTH 11
  12. #define RELEASE_YEAR 1999
  13. const char BladeEncHomepage[BE_MAX_HOMEPAGE + 1] = "http://www.bladeenc.cjb.net";
  14. /************ MP3 Variables *************/
  15. DWORD MP3_AllowedSamplerate[] = { 48000, 44100, 32000 };
  16. WORD MP3_AllowedBitrate[] = { 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 };
  17. #define MP3_SAMPLERATES (sizeof(MP3_AllowedSamplerate)/sizeof(DWORD))
  18. #define MP3_BITRATES (sizeof(MP3_AllowedBitrate)/sizeof(WORD))
  19. /****************************************/
  20. // Only one handle is supported, this is the only valid handle value
  21. #define BE_EMPTY_HANDLE_VALUE 0
  22. #define BE_VALID_HANDLE_VALUE 1
  23. HBE_STREAM StreamHandle = BE_EMPTY_HANDLE_VALUE;
  24. /****************************************/
  25. BOOL WINAPI DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
  26. {   
  27. switch(dwReason) {
  28. case DLL_PROCESS_ATTACH:
  29. break;
  30. case DLL_THREAD_ATTACH:
  31. break;
  32. case DLL_THREAD_DETACH:
  33. break;
  34. case DLL_PROCESS_DETACH:
  35. break;
  36. }    
  37. return TRUE;
  38. }
  39. __declspec(dllexport) VOID beVersion(PBE_VERSION pbeVersion)
  40. {
  41. pbeVersion->byDLLMajorVersion = DLL_MAJOR_VERSION;
  42. pbeVersion->byDLLMinorVersion = DLL_MINOR_VERSION;
  43. pbeVersion->byMajorVersion = ENCODER_MAJOR_VERSION;
  44. pbeVersion->byMinorVersion = ENCODER_MINOR_VERSION;
  45. pbeVersion->byDay = RELEASE_DAY;
  46. pbeVersion->byMonth = RELEASE_MONTH;
  47. pbeVersion->wYear = RELEASE_YEAR;
  48. lstrcpy(pbeVersion->zHomepage, BladeEncHomepage);
  49. }
  50. __declspec(dllexport) BE_ERR beInitStream(PBE_CONFIG pbeConfig, PDWORD dwSamples, PDWORD dwBufferSize, PHBE_STREAM phbeStream)
  51. {
  52. int i;
  53. CodecInitIn In;
  54. CodecInitOut *pOut;
  55. // Check if there are handles available (only one handle is supported)
  56. if(StreamHandle != BE_EMPTY_HANDLE_VALUE) {
  57. return BE_ERR_NO_MORE_HANDLES;
  58. }
  59. // Check for supported encoding format
  60. if(pbeConfig->dwConfig != BE_CONFIG_MP3) {
  61. return BE_ERR_INVALID_FORMAT;
  62. }
  63. // Check for valid sample rate 
  64. for(i = 0; i < MP3_SAMPLERATES; i++) {
  65. if(pbeConfig->format.mp3.dwSampleRate == MP3_AllowedSamplerate[i])
  66. break;
  67. }
  68. // Valid sample rate were found? 
  69. if(i == MP3_SAMPLERATES) {
  70. return BE_ERR_INVALID_FORMAT_PARAMETERS;
  71. }
  72. // Check for valid bitrate
  73. for(i = 0; i < MP3_BITRATES; i++) {
  74. if(pbeConfig->format.mp3.wBitrate == MP3_AllowedBitrate[i])
  75. break;
  76. }
  77. // Valid bitrate found?
  78. if(i == MP3_BITRATES) {
  79. return BE_ERR_INVALID_FORMAT_PARAMETERS;
  80. }
  81. // Check for valid mode 
  82. if( pbeConfig->format.mp3.byMode != BE_MP3_MODE_STEREO &&
  83. pbeConfig->format.mp3.byMode != BE_MP3_MODE_DUALCHANNEL &&
  84. pbeConfig->format.mp3.byMode != BE_MP3_MODE_MONO) {
  85. return BE_ERR_INVALID_FORMAT_PARAMETERS;
  86. }
  87. // Initialize Stream
  88. In.frequency = (int) pbeConfig->format.mp3.dwSampleRate;
  89. In.mode = (int) pbeConfig->format.mp3.byMode;
  90. In.bitrate = (int) pbeConfig->format.mp3.wBitrate;
  91. In.emphasis = 0;
  92. In.fPrivate = pbeConfig->format.mp3.bPrivate ? 1 : 0;
  93. In.fCRC = pbeConfig->format.mp3.bCRC ? 1 : 0;
  94. In.fCopyright = pbeConfig->format.mp3.bCopyright ? 1 : 0;
  95. In.fOriginal = pbeConfig->format.mp3.bOriginal ? 1 : 0;
  96. pOut = codecInit(&In);
  97. *dwSamples = (DWORD) pOut->nSamples;
  98. *dwBufferSize = (DWORD) pOut->bufferSize;
  99. *phbeStream = BE_VALID_HANDLE_VALUE;
  100. StreamHandle = BE_VALID_HANDLE_VALUE;
  101. return BE_ERR_SUCCESSFUL;
  102. }
  103. __declspec(dllexport) BE_ERR beEncodeChunk(HBE_STREAM hbeStream, DWORD nSamples, PSHORT pSamples, PBYTE pOutput, PDWORD pdwOutput)
  104. {
  105. // Check for valid handle
  106. if(hbeStream != BE_VALID_HANDLE_VALUE) {
  107. return BE_ERR_INVALID_HANDLE ;
  108. }
  109. // Encode the chunk
  110. *pdwOutput = codecEncodeChunk((int)nSamples, pSamples, pOutput);
  111. return BE_ERR_SUCCESSFUL;
  112. }
  113. __declspec(dllexport) BE_ERR beDeinitStream(HBE_STREAM hbeStream, PBYTE pOutput, PDWORD pdwOutput)
  114. {
  115. // Check for valid handle
  116. if(hbeStream != BE_VALID_HANDLE_VALUE) {
  117. return BE_ERR_INVALID_HANDLE ;
  118. }
  119. // Exit/Close stream
  120. *pdwOutput = codecExit(pOutput);
  121. return BE_ERR_SUCCESSFUL;
  122. }
  123. __declspec(dllexport) BE_ERR beCloseStream(HBE_STREAM hbeStream)
  124. {
  125. // Check for valid handle
  126. if(hbeStream != BE_VALID_HANDLE_VALUE) {
  127. return BE_ERR_INVALID_HANDLE ;
  128. }
  129. // Close stream
  130. StreamHandle = BE_EMPTY_HANDLE_VALUE;
  131. return BE_ERR_SUCCESSFUL;
  132. }