main.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #include "../Winamp/in2.h"
  2. #include "api__in_mkv.h"
  3. #include "MKVInfo.h"
  4. #include "../Winamp/wa_ipc.h"
  5. #include "main.h"
  6. #include "MKVPlayer.h"
  7. #include "MKVDuration.h"
  8. #include "../nu/ns_wc.h"
  9. #include "resource.h"
  10. #include <strsafe.h>
  11. #define MKV_PLUGIN_VERSION L"0.86"
  12. static wchar_t pluginName[256] = {0};
  13. int g_duration=0;
  14. int paused = 0;
  15. static HANDLE play_thread = 0;
  16. static MKVPlayer *player = 0;
  17. // {B6CB4A7C-A8D0-4c55-8E60-9F7A7A23DA0F}
  18. static const GUID playbackConfigGroupGUID =
  19. {
  20. 0xb6cb4a7c, 0xa8d0, 0x4c55, { 0x8e, 0x60, 0x9f, 0x7a, 0x7a, 0x23, 0xda, 0xf }
  21. };
  22. void SetFileExtensions(void)
  23. {
  24. static char fileExtensionsString[256] = {0}; // "MKV\0Matroska Video (MKV)\0"
  25. char* end = 0;
  26. size_t remaining;
  27. StringCchCopyExA(fileExtensionsString, 255, "MKV", &end, &remaining, 0);
  28. StringCchCopyExA(end+1, remaining-1, WASABI_API_LNGSTRING(IDS_MKV_DESC), &end, &remaining, 0);
  29. StringCchCopyExA(end+1, remaining-1, "webm", &end, &remaining, 0);
  30. StringCchCopyExA(end+1, remaining-1, WASABI_API_LNGSTRING(IDS_WEBM_DESC), &end, &remaining, 0);
  31. plugin.FileExtensions = fileExtensionsString;
  32. }
  33. static int DoAboutMessageBox(HWND parent, wchar_t* title, wchar_t* message)
  34. {
  35. MSGBOXPARAMS msgbx = {sizeof(MSGBOXPARAMS),0};
  36. msgbx.lpszText = message;
  37. msgbx.lpszCaption = title;
  38. msgbx.lpszIcon = MAKEINTRESOURCE(102);
  39. msgbx.hInstance = GetModuleHandle(0);
  40. msgbx.dwStyle = MB_USERICON;
  41. msgbx.hwndOwner = parent;
  42. return MessageBoxIndirect(&msgbx);
  43. }
  44. void About(HWND hwndParent)
  45. {
  46. wchar_t message[1024] = {0}, text[1024] = {0};
  47. WASABI_API_LNGSTRINGW_BUF(IDS_NULLSOFT_MKV_OLD,text,1024);
  48. StringCchPrintf(message, 1024, WASABI_API_LNGSTRINGW(IDS_ABOUT_TEXT),
  49. plugin.description, TEXT(__DATE__));
  50. DoAboutMessageBox(hwndParent,text,message);
  51. }
  52. int Init()
  53. {
  54. if (!IsWindow(plugin.hMainWindow))
  55. return IN_INIT_FAILURE;
  56. WasabiInit();
  57. StringCchPrintfW(pluginName,256,WASABI_API_LNGSTRINGW(IDS_NULLSOFT_MKV),MKV_PLUGIN_VERSION);
  58. plugin.description = (char*)pluginName;
  59. SetFileExtensions();
  60. return IN_INIT_SUCCESS;
  61. }
  62. void Quit()
  63. {
  64. WasabiQuit();
  65. }
  66. void GetFileInfo(const wchar_t *file, wchar_t *title, int *length_in_ms)
  67. {
  68. if (title)
  69. *title=0;
  70. if (length_in_ms)
  71. {
  72. if (file && *file)
  73. {
  74. MKVDuration duration;
  75. if (duration.Open(file))
  76. {
  77. if (title)
  78. {
  79. const char *mkv_title = duration.GetTitle();
  80. if (mkv_title)
  81. MultiByteToWideCharSZ(CP_UTF8, 0, mkv_title, -1, title, GETFILEINFO_TITLE_LENGTH);
  82. }
  83. *length_in_ms=duration.GetLengthMilliseconds();
  84. }
  85. else
  86. *length_in_ms=-1000;
  87. }
  88. else
  89. *length_in_ms = g_duration;
  90. }
  91. }
  92. int InfoBox(const wchar_t *file, HWND hwndParent)
  93. {
  94. MKVInfo info;
  95. if (info.Open(file))
  96. {
  97. WASABI_API_DIALOGBOXPARAMW(IDD_INFODIALOG, hwndParent, InfoDialog, (LPARAM)&info);
  98. }
  99. return INFOBOX_UNCHANGED;
  100. }
  101. int IsOurFile(const wchar_t *fn)
  102. {
  103. return 0;
  104. }
  105. DWORD CALLBACK MKVThread(LPVOID param);
  106. int Play(const wchar_t *fn) // return zero on success, -1 on file-not-found, some other value on other (stopping winamp) error
  107. {
  108. g_duration=-1000;
  109. delete player;
  110. player = new MKVPlayer(fn);
  111. play_thread = CreateThread(0, 0, MKVThread, player, 0, 0);
  112. SetThreadPriority(play_thread, (int)AGAVE_API_CONFIG->GetInt(playbackConfigGroupGUID, L"priority", THREAD_PRIORITY_HIGHEST));
  113. return 0; // success
  114. }
  115. void Pause()
  116. {
  117. paused = 1;
  118. plugin.outMod->Pause(1);
  119. }
  120. void UnPause()
  121. {
  122. paused = 0;
  123. plugin.outMod->Pause(0);
  124. }
  125. int IsPaused()
  126. {
  127. return paused;
  128. }
  129. void Stop()
  130. {
  131. if (player)
  132. {
  133. player->Kill();
  134. if (play_thread) {
  135. WaitForSingleObject(play_thread, INFINITE);
  136. }
  137. play_thread = 0;
  138. delete player;
  139. player=0;
  140. }
  141. }
  142. // time stuff
  143. int GetLength()
  144. {
  145. return g_duration;
  146. }
  147. int GetOutputTime()
  148. {
  149. if (plugin.outMod && player)
  150. return player->GetOutputTime();
  151. else
  152. return 0;
  153. }
  154. void SetOutputTime(int time_in_ms)
  155. {
  156. if (player)
  157. player->Seek(time_in_ms);
  158. }
  159. void SetVolume(int volume)
  160. {
  161. plugin.outMod->SetVolume(volume);
  162. }
  163. void SetPan(int pan)
  164. {
  165. plugin.outMod->SetPan(pan);
  166. }
  167. void EQSet(int on, char data[10], int preamp)
  168. {
  169. }
  170. In_Module plugin =
  171. {
  172. IN_VER_RET,
  173. "nullsoft(in_mkv.dll)",
  174. NULL, // hMainWindow
  175. NULL, // hDllInstance
  176. 0 /*"mkv\0Matroska Video\0"*/,
  177. 1, // is seekable
  178. IN_MODULE_FLAG_USES_OUTPUT_PLUGIN, //UsesOutputPlug
  179. About,
  180. About,
  181. Init,
  182. Quit,
  183. GetFileInfo,
  184. InfoBox,
  185. IsOurFile,
  186. Play,
  187. Pause,
  188. UnPause,
  189. IsPaused,
  190. Stop,
  191. GetLength,
  192. GetOutputTime,
  193. SetOutputTime,
  194. SetVolume,
  195. SetPan,
  196. 0,
  197. 0,
  198. 0,
  199. 0,
  200. 0,
  201. 0,
  202. 0,
  203. 0,
  204. 0,
  205. 0,
  206. 0,
  207. EQSet,
  208. 0,
  209. 0
  210. };
  211. extern "C" __declspec(dllexport) In_Module * winampGetInModule2()
  212. {
  213. return &plugin;
  214. }