c_encoder_nsv.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "c_encoder_nsv.h"
  2. #include "../../utils.h"
  3. #include <mmsystem.h>
  4. #include <stdio.h>
  5. static char * configfile;
  6. static unsigned int configfourcc;
  7. static HWND (*ConfigAudio3)(HWND intParent, HINSTANCE hinst, unsigned int outt, char *configfile);
  8. static HINSTANCE encoderDllInstance;
  9. static HWND cfgwnd=NULL;
  10. C_ENCODER_NSV::C_ENCODER_NSV(int ExtInfoSize) : C_ENCODER(ExtInfoSize) {
  11. hMutex = CreateMutex(NULL,TRUE,NULL);
  12. ReleaseMutex(hMutex);
  13. CreateAudio3 = NULL;
  14. ConfigAudio3 = NULL;
  15. GetAudioTypes3 = NULL;
  16. SetWinampHWND = NULL;
  17. SetConfigItem = NULL;
  18. GetConfigItem = NULL;
  19. winampWnd = NULL;
  20. fourcc = 0;
  21. encoder = NULL;
  22. }
  23. void C_ENCODER_NSV::SetEncoder(void * CreateAudio3, void * GetAudioTypes3, void * ConfigAudio3, void * SetWinampHWND, int encoderNum) {
  24. *(void **)&(this->CreateAudio3) = CreateAudio3;
  25. *(void **)&(this->GetAudioTypes3) = GetAudioTypes3;
  26. *(void **)&(this->ConfigAudio3) = ConfigAudio3;
  27. *(void **)&(this->SetWinampHWND) = SetWinampHWND;
  28. if(this->SetWinampHWND) {
  29. this->SetWinampHWND(winampWnd);
  30. }
  31. if(this->GetAudioTypes3) {
  32. char name[C_ENCODER_NameLen];
  33. fourcc = this->GetAudioTypes3(encoderNum,name);
  34. }
  35. }
  36. C_ENCODER_NSV::~C_ENCODER_NSV() {
  37. WaitForSingleObject(hMutex,INFINITE);
  38. CloseHandle(hMutex);
  39. hMutex = NULL;
  40. C_ENCODER::~C_ENCODER();
  41. }
  42. void C_ENCODER_NSV::Close() {
  43. C_ENCODER::Close();
  44. if(encoder)
  45. delete encoder;
  46. encoder = NULL;
  47. }
  48. void C_ENCODER_NSV::Reset() {
  49. if(WaitForSingleObject(hMutex,INFINITE) != WAIT_OBJECT_0) return;
  50. Close();
  51. if(!configfile) {
  52. configfile = GetSCIniFile(winampWnd);
  53. }
  54. FillConfFile(configfile);
  55. int nch = ((T_ENCODER_NSV_INFO*)ExtendedInfoPtr)->input_numChannels;
  56. int srate = ((T_ENCODER_NSV_INFO*)ExtendedInfoPtr)->input_sampleRate;
  57. if (CreateAudio3) {
  58. const int bps = 16; /* I think this is always the case. */
  59. encoder = CreateAudio3(nch,srate,bps,mmioFOURCC('P','C','M',' '),&fourcc,configfile);
  60. }
  61. else encoder = NULL;
  62. /* I think (in that I havn't found anything to the contrary) that in the CreateAudio3 call, the encoder
  63. * reads all its settings from the conf_file and never touches them again. Hence, this is safe. Ahem.
  64. */
  65. FillAttribs();
  66. ReleaseMutex(hMutex);
  67. }
  68. int C_ENCODER_NSV::Encode(const void *inputbuf, const unsigned int inputbufsize, void *outputbuf, const unsigned int outputbufsize, int *inputamtused) {
  69. if(WaitForSingleObject(hMutex,INFINITE) != WAIT_OBJECT_0) return 0;
  70. int ret=0;
  71. if(encoder && (inputbuf != NULL) && (outputbuf != NULL) && (inputbufsize != 0) && (outputbufsize != 0) && (inputamtused != NULL)) {
  72. ret = encoder->Encode(0,(void *)inputbuf,inputbufsize,inputamtused,outputbuf,outputbufsize);
  73. } else
  74. *inputamtused = inputbufsize; /* we havn't got the dll, so just say everything is ok? */
  75. ReleaseMutex(hMutex);
  76. return ret;
  77. }
  78. static BOOL CALLBACK configure_dlgproc(HWND intDlg, UINT uMsg, WPARAM wParam,LPARAM lParam) {
  79. switch(uMsg) {
  80. case WM_INITDIALOG:
  81. if(configfourcc == mmioFOURCC('A','D','T','S')) {
  82. SetWindowTextW(intDlg, LocalisedString(IDS_FHGAAC_ENCODER, NULL, 0));
  83. }
  84. #ifdef USE_OGG
  85. else if(configfourcc == mmioFOURCC('O','G','G',' ')) {
  86. SetWindowTextW(intDlg, LocalisedString(IDS_OGG_CONFIG_TITLE, NULL, 0));
  87. }
  88. #endif
  89. cfgwnd=ConfigAudio3(intDlg, encoderDllInstance, configfourcc, configfile);
  90. if(cfgwnd) {
  91. RECT r;
  92. GetWindowRect(GetDlgItem(intDlg,IDC_GO_HERE),&r);
  93. ScreenToClient(intDlg,(LPPOINT)&r);
  94. SetWindowPos(cfgwnd,NULL,r.left,r.top,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
  95. ShowWindow(cfgwnd,SW_SHOWNA);
  96. InvalidateRect(intDlg,NULL,FALSE);
  97. }
  98. break;
  99. case WM_COMMAND:
  100. if(LOWORD(wParam) == IDCANCEL) EndDialog(intDlg,0);
  101. break;
  102. case WM_DESTROY:
  103. DestroyWindow(cfgwnd);
  104. break;
  105. }
  106. return 0;
  107. }
  108. void C_ENCODER_NSV::Configure(HWND parent, HINSTANCE hDllInstance) {
  109. if(ConfigAudio3) {
  110. configfourcc = fourcc;
  111. if(!configfile) {
  112. configfile = GetSCIniFile(winampWnd);
  113. }
  114. ::ConfigAudio3 = this->ConfigAudio3;
  115. ::encoderDllInstance = GetEncoderInstance();
  116. if(WaitForSingleObject(hMutex,INFINITE) != WAIT_OBJECT_0) return;
  117. FillConfFile(configfile);
  118. ReleaseMutex(hMutex);
  119. LocalisedDialogBox(hDllInstance,IDD_NSVCONFIG,parent,::configure_dlgproc);
  120. if(WaitForSingleObject(hMutex,INFINITE) != WAIT_OBJECT_0) return;
  121. ReadConfFile(configfile);
  122. Reset();
  123. ReleaseMutex(hMutex);
  124. }
  125. }