1
0

main.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #pragma comment(linker, "-nodefaultlib:libmmd.lib")
  2. #pragma message(__FILE__": telling linker to ignore libmmd.lib")
  3. #include "FhGAACEncoder.h"
  4. #include <windows.h>
  5. #include <mmsystem.h>
  6. #include <stdio.h>
  7. #include "../nsv/enc_if.h"
  8. #include "config.h"
  9. #include "preferences.h"
  10. #include "resource.h"
  11. #include <api/service/waservicefactory.h>
  12. #include "../Agave/Language/api_language.h"
  13. #include "../winamp/wa_ipc.h"
  14. #include "../nu/AutoWideFn.h"
  15. #include <strsafe.h>
  16. #include "../nu/AutoWideFn.h"
  17. #include "encoder_common.h"
  18. #include "ADTSAACEncoder.h"
  19. #define ENC_VERSION "1.08"
  20. HWND winampwnd = 0;
  21. api_service *WASABI_API_SVC = 0;
  22. api_language *WASABI_API_LNG = 0;
  23. api_application *WASABI_API_APP = 0;
  24. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
  25. HINSTANCE enc_fhg_HINST = 0;
  26. static HINSTANCE GetMyInstance()
  27. {
  28. MEMORY_BASIC_INFORMATION mbi = {0};
  29. if(VirtualQuery(GetMyInstance, &mbi, sizeof(mbi)))
  30. return (HINSTANCE)mbi.AllocationBase;
  31. return NULL;
  32. }
  33. void GetLocalisationApiService(void)
  34. {
  35. if (!enc_fhg_HINST)
  36. enc_fhg_HINST = GetMyInstance();
  37. if(winampwnd && !WASABI_API_LNG)
  38. {
  39. // loader so that we can get the localisation service api for use
  40. if(!WASABI_API_SVC)
  41. {
  42. WASABI_API_SVC = (api_service*)SendMessage(winampwnd, WM_WA_IPC, 0, IPC_GET_API_SERVICE);
  43. if (WASABI_API_SVC == (api_service*)1)
  44. {
  45. WASABI_API_SVC = NULL;
  46. return;
  47. }
  48. }
  49. if (!WASABI_API_SVC)
  50. return;
  51. if(!WASABI_API_APP)
  52. {
  53. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(applicationApiServiceGuid);
  54. if (sf) WASABI_API_APP = reinterpret_cast<api_application*>(sf->getInterface());
  55. }
  56. if(!WASABI_API_LNG)
  57. {
  58. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(languageApiGUID);
  59. if (sf) WASABI_API_LNG = reinterpret_cast<api_language*>(sf->getInterface());
  60. }
  61. // need to have this initialised before we try to do anything with localisation features
  62. WASABI_API_START_LANG(GetMyInstance(),EncFhgAacLangGUID);
  63. }
  64. }
  65. extern "C"
  66. {
  67. unsigned int __declspec(dllexport) GetAudioTypes3(int idx, char *desc)
  68. {
  69. switch(idx)
  70. {
  71. case 0:
  72. GetLocalisationApiService();
  73. StringCchPrintfA(desc, 1024, WASABI_API_LNGSTRING(IDS_ENC_FHGAAC_DESC), ENC_VERSION);
  74. return ENCODER_TYPE_MPEG4;
  75. case 1:
  76. GetLocalisationApiService();
  77. StringCchPrintfA(desc, 1024, WASABI_API_LNGSTRING(IDC_ENC_ADTS_DESC), ENC_VERSION);
  78. return ENCODER_TYPE_ADTS;
  79. default:
  80. return 0;
  81. }
  82. }
  83. AudioCoder __declspec(dllexport) *CreateAudio3(int nch, int srate, int bps, unsigned int srct, unsigned int *outt, char *configfile)
  84. {
  85. if (srct == mmioFOURCC('P','C','M',' '))
  86. {
  87. switch(*outt)
  88. {
  89. case ENCODER_TYPE_MPEG4:
  90. {
  91. FhGAACEncoder *t=0;
  92. AACConfigurationFile *wr = AACConfig_Create(ENCODER_TYPE_MPEG4, configfile);
  93. if (!wr)
  94. return 0;
  95. t = FhGAACEncoder::CreateDecoder(&wr->config, nch, srate, bps);
  96. free(wr);
  97. return t;
  98. }
  99. case ENCODER_TYPE_ADTS:
  100. {
  101. ADTSAACEncoder *t=0;
  102. AACConfigurationFile *wr = AACConfig_Create(ENCODER_TYPE_ADTS, configfile);
  103. if (!wr)
  104. return 0;
  105. t = ADTSAACEncoder::CreateDecoder(&wr->config, nch, srate, bps);
  106. free(wr);
  107. return t;
  108. }
  109. }
  110. }
  111. return NULL;
  112. }
  113. HWND __declspec(dllexport) ConfigAudio3(HWND hwndParent, HINSTANCE hinst, unsigned int outt, const char *configfile)
  114. {
  115. switch(outt)
  116. {
  117. case ENCODER_TYPE_MPEG4:
  118. {
  119. AACConfigurationFile *wr = AACConfig_Create(ENCODER_TYPE_MPEG4, configfile);
  120. if (!wr)
  121. return 0;
  122. wr->channels = 2; /* dummy defaults */
  123. wr->sample_rate = 44100; /* dummy defaults */
  124. GetLocalisationApiService();
  125. return WASABI_API_CREATEDIALOGPARAMW(IDD_PREFERENCES_MP4, hwndParent, Preferences_MP4_DlgProc, (LPARAM)wr);
  126. }
  127. case ENCODER_TYPE_ADTS:
  128. {
  129. AACConfigurationFile *wr = AACConfig_Create(ENCODER_TYPE_ADTS, configfile);
  130. if (!wr)
  131. return 0;
  132. wr->channels = 2; /* dummy defaults */
  133. wr->sample_rate = 44100; /* dummy defaults */
  134. GetLocalisationApiService();
  135. return WASABI_API_CREATEDIALOGPARAMW(IDD_PREFERENCES_ADTS, hwndParent, Preferences_ADTS_DlgProc, (LPARAM)wr);
  136. }
  137. }
  138. return NULL;
  139. }
  140. #if 0 // TODO
  141. HWND __declspec(dllexport) ConfigAudio4(HWND hwndParent, HINSTANCE hinst, unsigned int outt, const char *configfile, unsigned int channels, unsigned int sample_rate)
  142. {
  143. switch(outt)
  144. {
  145. case ENCODER_TYPE_MPEG4:
  146. {
  147. AACConfigurationFile *wr = (AACConfigurationFile*)calloc(1, sizeof(AACConfigurationFile));
  148. if (!wr)
  149. return 0;
  150. if (configfile)
  151. lstrcpynA(wr->config_file, configfile, MAX_PATH);
  152. else
  153. wr->config_file[0] = 0;
  154. wr->channels = channels;
  155. wr->sample_rate = sample_rate;
  156. AACConfig_Load(wr);
  157. GetLocalisationApiService();
  158. return WASABI_API_CREATEDIALOGPARAMW(IDD_PREFERENCES_MP4, hwndParent, Preferences_MP4_DlgProc, (LPARAM)wr);
  159. }
  160. case ENCODER_TYPE_ADTS:
  161. {
  162. AACConfigurationFile *wr = (AACConfigurationFile*)calloc(1, sizeof(AACConfigurationFile));
  163. if (!wr)
  164. return 0;
  165. if (configfile)
  166. lstrcpynA(wr->config_file, configfile, MAX_PATH);
  167. else
  168. wr->config_file[0] = 0;
  169. wr->channels = channels;
  170. wr->sample_rate = sample_rate;
  171. AACConfig_Load(wr);
  172. GetLocalisationApiService();
  173. return WASABI_API_CREATEDIALOGPARAMW(IDD_PREFERENCES_ADTS, hwndParent, Preferences_ADTS_DlgProc, (LPARAM)wr);
  174. }
  175. }
  176. return NULL;
  177. }
  178. #endif
  179. void __declspec(dllexport) PrepareToFinish(const char *filename, AudioCoder *coder)
  180. {
  181. ((EncoderCommon*)coder)->PrepareToFinish();
  182. }
  183. void __declspec(dllexport) PrepareToFinishW(const wchar_t *filename, AudioCoder *coder)
  184. {
  185. ((EncoderCommon*)coder)->PrepareToFinish();
  186. }
  187. void __declspec(dllexport) FinishAudio3(const char *filename, AudioCoder *coder)
  188. {
  189. ((EncoderCommon*)coder)->Finish(AutoWideFn(filename));
  190. }
  191. void __declspec(dllexport) FinishAudio3W(const wchar_t *filename, AudioCoder *coder)
  192. {
  193. ((EncoderCommon*)coder)->Finish(filename);
  194. }
  195. int __declspec(dllexport) GetConfigItem(unsigned int outt, const char *item, char *data, int len, char *configfile)
  196. {
  197. if (outt == mmioFOURCC('A','A','C','f'))
  198. {
  199. if (!lstrcmpiA(item,"extension"))
  200. lstrcpynA(data,"m4a",len);
  201. return 1;
  202. }
  203. else if (outt == mmioFOURCC('A','D','T','S'))
  204. {
  205. if (!lstrcmpiA(item,"extension"))
  206. {
  207. lstrcpynA(data,"aac",len);
  208. }
  209. else if (!lstrcmpiA(item,"aot"))
  210. {
  211. AACConfigurationFile *wr = AACConfig_Create(ENCODER_TYPE_ADTS, configfile);
  212. if (wr)
  213. {
  214. StringCbPrintfA(data, len, "%u", AACConfig_GetAOT(&wr->config));
  215. }
  216. else
  217. {
  218. StringCbPrintfA(data, len, "%u", AUD_OBJ_TYP_LC);
  219. }
  220. free(wr);
  221. }
  222. return 1;
  223. }
  224. return 0;
  225. }
  226. void __declspec(dllexport) SetWinampHWND(HWND hwnd)
  227. {
  228. winampwnd = hwnd;
  229. }
  230. }