WinampInterface.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include "Main.h"
  2. #include "WinampInterface.h"
  3. #include "../Winamp/wa_ipc.h"
  4. #include <cassert>
  5. #include "WMDRMModule.h"
  6. #include <strsafe.h>
  7. #include "WMPlaylist.h"
  8. #include "../nu/AutoChar.h"
  9. WinampInterface winamp;
  10. extern WMDRM mod;
  11. using namespace Nullsoft::Utility;
  12. #ifndef NO_DRM
  13. #include "vid_overlay.h"
  14. #include "vid_ddraw.h"
  15. OverlayVideoOutput overlay;
  16. DDrawVideoOutput ddraw;
  17. #endif
  18. WinampInterface::WinampInterface()
  19. : videoWindow(0), bufferCount(0),
  20. statusGuard(GUARDNAME("WinampInterface::statusGuard"))
  21. {
  22. statusFilename[0] = 0;
  23. status[0] = 0;
  24. }
  25. /*
  26. @returns winamp's video window handle
  27. */
  28. HWND WinampInterface::GetVideoWindow()
  29. {
  30. return (HWND)GetVideoOutput()->extended(VIDUSER_GET_VIDEOHWND, 0, 0); // ask for the video hwnd
  31. }
  32. IVideoOutput *WinampInterface::GetVideoOutput()
  33. {
  34. if (!videoWindow)
  35. videoWindow = (IVideoOutput *)SendMessage(GetWinampWindow(), WM_WA_IPC, 0, IPC_GET_IVIDEOOUTPUT); // ask winamp for an interface to the video output
  36. return videoWindow;
  37. }
  38. void WinampInterface::EndOfFile()
  39. {
  40. PostMessage(GetWinampWindow(), WM_WA_MPEG_EOF, 0, 0);
  41. }
  42. HWND WinampInterface::GetWinampWindow()
  43. {
  44. return plugin.hMainWindow;
  45. }
  46. void WinampInterface::SetStatus(wchar_t *_status)
  47. {
  48. {
  49. AutoLock lock (statusGuard);
  50. StringCchCopy(status, 1024, _status);
  51. StringCchCopy(statusFilename, FILENAME_SIZE, activePlaylist.GetFileName());
  52. }
  53. PostMessage(GetWinampWindow(), WM_WA_IPC, 0, IPC_UPDTITLE);
  54. }
  55. bool WinampInterface::GetStatus(wchar_t *title, size_t titleLen, const wchar_t *filename)
  56. {
  57. AutoLock lock (statusGuard);
  58. if (status[0] && title && filename && !lstrcmpi(statusFilename, filename))
  59. {
  60. StringCchPrintf(title, titleLen, L"[%s]%s", status, filename);
  61. return true;
  62. }
  63. else
  64. return false;
  65. }
  66. bool WinampInterface::GetStatusHook(wchar_t *title, size_t titleLen, const wchar_t *filename)
  67. {
  68. AutoLock lock (statusGuard);
  69. if (status[0] && title && filename && !lstrcmpi(statusFilename, filename))
  70. {
  71. wchar_t *oldTitle = _wcsdup(title);
  72. StringCchPrintf(title, titleLen, L"[%s]%s", status, oldTitle);
  73. free(oldTitle);
  74. return true;
  75. }
  76. else
  77. return false;
  78. }
  79. bool WinampInterface::HasStatus(const wchar_t *filename)
  80. {
  81. AutoLock lock (statusGuard);
  82. if (status[0] && filename && !lstrcmpi(statusFilename, filename))
  83. return true;
  84. return false;
  85. }
  86. void WinampInterface::ClearStatus()
  87. {
  88. {
  89. //AutoLock lock (statusGuard); // should be safe not to lock here
  90. status[0] = 0;
  91. statusFilename[0]=0;
  92. }
  93. PostMessage(GetWinampWindow(), WM_WA_IPC, 0, IPC_UPDTITLE);
  94. }
  95. void WinampInterface::EncryptedDrawFrame(void *frame)
  96. {
  97. #ifndef NO_DRM
  98. overlay.SetFrame(frame);
  99. ddraw.SetFrame(frame);
  100. SecureZeroMemory(&frame, sizeof(void *));
  101. GetVideoOutput()->draw((void *)1);
  102. #endif
  103. }
  104. bool WinampInterface::OpenEncryptedVideo(int width, int height, bool flip, double aspect, int fourcc)
  105. {
  106. #ifndef NO_DRM
  107. VideoOpenStruct openVideo = {width, height, flip, aspect, fourcc};
  108. bool openedOK = false;
  109. if (config_video.overlays())
  110. {
  111. openedOK = !!GetVideoOutput()->extended(VIDUSER_OPENVIDEORENDERER, (intptr_t)(VideoRenderer *)&overlay, (intptr_t)&openVideo);
  112. if (openedOK)
  113. return true;
  114. }
  115. openedOK = !!GetVideoOutput()->extended(VIDUSER_OPENVIDEORENDERER, (intptr_t)(VideoRenderer *)&ddraw, (intptr_t)&openVideo);
  116. if (openedOK)
  117. return true;
  118. #endif
  119. return false;
  120. }
  121. void WinampInterface::CloseEncryptedVideo()
  122. {
  123. GetVideoOutput()->extended(VIDUSER_CLOSEVIDEORENDERER, 0, 0);
  124. }
  125. void WinampInterface::Buffering(int bufStatus, const wchar_t *displayString)
  126. {
  127. char tempdata[75*2] = {0, };
  128. int csa = plugin.SAGetMode();
  129. if (csa & 1)
  130. {
  131. for (int x = 0; x < bufStatus*75 / 100; x ++)
  132. tempdata[x] = x * 16 / 75;
  133. }
  134. else if (csa&2)
  135. {
  136. int offs = (csa & 1) ? 75 : 0;
  137. int x = 0;
  138. while (x < bufStatus*75 / 100)
  139. {
  140. tempdata[offs + x++] = -6 + x * 14 / 75;
  141. }
  142. while (x < 75)
  143. {
  144. tempdata[offs + x++] = 0;
  145. }
  146. }
  147. else if (csa == 4)
  148. {
  149. tempdata[0] = tempdata[1] = (bufStatus * 127 / 100);
  150. }
  151. if (csa) plugin.SAAdd(tempdata, ++bufferCount, (csa == 3) ? 0x80000003 : csa);
  152. wchar_t temp[64] = {0};
  153. StringCchPrintf(temp, 64, L"%s: %d%%",displayString, bufStatus);
  154. SetStatus(temp);
  155. //SetVideoStatusText(temp); // TODO: find a way to set the old status back
  156. GetVideoOutput()->notifyBufferState(static_cast<int>(bufStatus*2.55f));
  157. }