main.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. ** nsv_coder_lame: main.cpp - LAME mp3 encoder plug-in
  3. ** (requires lame_enc.dll)
  4. **
  5. ** Copyright (C) 2001-2006 Nullsoft, Inc.
  6. **
  7. ** This software is provided 'as-is', without any express or implied warranty.
  8. ** In no event will the authors be held liable for any damages arising from the use of this software.
  9. **
  10. ** Permission is granted to anyone to use this software for any purpose, including commercial
  11. ** applications, and to alter it and redistribute it freely, subject to the following restrictions:
  12. ** 1. The origin of this software must not be misrepresented; you must not claim that you wrote the
  13. ** original software. If you use this software in a product, an acknowledgment in the product
  14. ** documentation would be appreciated but is not required.
  15. ** 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
  16. ** being the original software.
  17. ** 3. This notice may not be removed or altered from any source distribution.
  18. */
  19. #define ENC_VERSION "v1.23"
  20. #include <windows.h>
  21. #include <stdio.h>
  22. #include <wmsdk.h>
  23. #include <mmreg.h>
  24. #include <msacm.h>
  25. #include "AudioCoderWMA.h"
  26. #include "../nu/AutoWideFn.h"
  27. // wasabi based services for localisation support
  28. #include <api/service/waServiceFactory.h>
  29. #include "../Agave/Language/api_language.h"
  30. #include "../winamp/wa_ipc.h"
  31. #include <strsafe.h>
  32. HWND winampwnd = 0;
  33. api_service *WASABI_API_SVC = 0;
  34. api_language *WASABI_API_LNG = 0;
  35. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
  36. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  37. {
  38. return TRUE;
  39. }
  40. int getwrittentime();
  41. HINSTANCE g_hinst;
  42. int g_srate, g_numchan, g_bps;
  43. volatile int writtentime, w_offset;
  44. // LGIVEN Mod 4-10-05
  45. void readconfig(char *configfile, configtype *cfg);
  46. void writeconfig(char *configfile, configtype *cfg);
  47. static HINSTANCE GetMyInstance()
  48. {
  49. MEMORY_BASIC_INFORMATION mbi = {0};
  50. if(VirtualQuery(GetMyInstance, &mbi, sizeof(mbi)))
  51. return (HINSTANCE)mbi.AllocationBase;
  52. return NULL;
  53. }
  54. void GetLocalisationApiService(void)
  55. {
  56. if(!WASABI_API_LNG)
  57. {
  58. // loader so that we can get the localisation service api for use
  59. if(!WASABI_API_SVC)
  60. {
  61. WASABI_API_SVC = (api_service*)SendMessage(winampwnd, WM_WA_IPC, 0, IPC_GET_API_SERVICE);
  62. if (WASABI_API_SVC == (api_service*)1)
  63. {
  64. WASABI_API_SVC = NULL;
  65. return;
  66. }
  67. }
  68. if(!WASABI_API_LNG)
  69. {
  70. waServiceFactory *sf;
  71. sf = WASABI_API_SVC->service_getServiceByGuid(languageApiGUID);
  72. if (sf) WASABI_API_LNG = reinterpret_cast<api_language*>(sf->getInterface());
  73. }
  74. // need to have this initialised before we try to do anything with localisation features
  75. WASABI_API_START_LANG(GetMyInstance(),EncWMALangGUID);
  76. }
  77. }
  78. // ==================================================================
  79. //
  80. // Published enc_wma methods.
  81. //
  82. // ==================================================================
  83. #include <cassert>
  84. extern "C"
  85. {
  86. unsigned int __declspec(dllexport) GetAudioTypes3(int idx, char *desc)
  87. {
  88. if ( idx == 0 )
  89. {
  90. GetLocalisationApiService();
  91. StringCchPrintfA(desc, 1024, WASABI_API_LNGSTRING(IDS_ENC_WMA_DESC), ENC_VERSION);
  92. return mmioFOURCC('W', 'M', 'A', ' ');
  93. }
  94. return 0;
  95. }
  96. AudioCoder __declspec(dllexport) *CreateAudio3(int nch, int srate, int bps, unsigned int srct, unsigned int *outt, char *configfile)
  97. {
  98. if (srct == mmioFOURCC('P', 'C', 'M', ' ') && *outt == mmioFOURCC('W', 'M', 'A', ' '))
  99. {
  100. GetLocalisationApiService();
  101. configtype cfg;
  102. readconfig(configfile, &cfg);
  103. AudioCoderWMA *t = new AudioCoderWMA(nch, srate, bps, &cfg, configfile);
  104. if ( t && t->GetLastError())
  105. {
  106. delete t;
  107. return NULL;
  108. }
  109. else return t;
  110. }
  111. return NULL;
  112. }
  113. void __declspec(dllexport) FinishAudio3(const char *filename, AudioCoder *coder)
  114. {
  115. ((AudioCoderWMA*)coder)->OnFinished(AutoWideFn(filename));
  116. }
  117. void __declspec(dllexport) FinishAudio3W(const wchar_t *filename, AudioCoder *coder)
  118. {
  119. ((AudioCoderWMA*)coder)->OnFinished(filename);
  120. }
  121. void __declspec(dllexport) PrepareToFinish(const char *filename, AudioCoder *coder)
  122. {
  123. ((AudioCoderWMA*)coder)->PrepareToFinish();
  124. }
  125. void __declspec(dllexport) PrepareToFinishW(const wchar_t *filename, AudioCoder *coder)
  126. {
  127. ((AudioCoderWMA*)coder)->PrepareToFinish();
  128. }
  129. HWND __declspec(dllexport) ConfigAudio3(HWND hwndParent, HINSTANCE hinst, unsigned int outt, char *configfile)
  130. {
  131. if (outt == mmioFOURCC('W', 'M', 'A', ' '))
  132. {
  133. configwndrec *wr = (configwndrec*)malloc(sizeof(configwndrec));
  134. if (configfile)
  135. {
  136. wr->configfile = _strdup(configfile);
  137. }
  138. else
  139. {
  140. wr->configfile = 0;
  141. }
  142. readconfig(configfile, &wr->cfg);
  143. GetLocalisationApiService();
  144. return WASABI_API_CREATEDIALOGPARAMW(IDD_DIALOG1, hwndParent, ConfigProc, (LPARAM)wr);
  145. }
  146. return NULL;
  147. }
  148. int __declspec(dllexport) SetConfigItem(unsigned int outt, char *item, char *data, char *configfile)
  149. {
  150. if (outt == mmioFOURCC('W', 'M', 'A', ' '))
  151. {
  152. configtype cfg;
  153. readconfig(configfile, &cfg);
  154. if (!lstrcmpiA(item, "bitrate"))
  155. {
  156. //cfg.config_bitrate = atoi(data) * 1000;
  157. }
  158. writeconfig(configfile, &cfg);
  159. return 1;
  160. }
  161. return 0;
  162. }
  163. int __declspec(dllexport) GetConfigItem(unsigned int outt, char *item, char *data, int len, char *configfile)
  164. {
  165. if (outt == mmioFOURCC('W', 'M', 'A', ' '))
  166. {
  167. configtype cfg;
  168. readconfig(configfile, &cfg);
  169. if (!lstrcmpiA(item, "bitrate"))
  170. {
  171. StringCchPrintfA(data, len, "%d", cfg.config_bitrate / 1000);
  172. }
  173. return 1;
  174. }
  175. return 0;
  176. }
  177. void __declspec(dllexport) SetWinampHWND(HWND hwnd)
  178. {
  179. winampwnd = hwnd;
  180. }
  181. };