1
0

main.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #include <windows.h>
  2. #include "main.h"
  3. #include "video.h"
  4. #include "resource.h"
  5. typedef struct
  6. {
  7. VideoOutput *vidOut;
  8. NSVDecoder *decode;
  9. int quit;
  10. } parms;
  11. HINSTANCE g_hInstance;
  12. int g_bitmap_id=IDB_BITMAP1;
  13. //#define NO_ABOUT_EGG
  14. extern long glCounterNSVf, glSyncFrameCount, glNonSyncFrameCount;
  15. #define WNDMENU_CAPTION "NSVPlay/0.994"
  16. #include "about.h"
  17. #include "wndmenu.h"
  18. DWORD WINAPI pooThread(LPVOID p)
  19. {
  20. parms *parm=(parms*)p;
  21. unsigned int last_title_check=0;
  22. while (!parm->quit)
  23. {
  24. int r=parm->decode->run(&parm->quit);
  25. if (r < 0)
  26. {
  27. if (parm->decode->get_error()) MessageBox(parm->vidOut->getHwnd(),parm->decode->get_error(),"NSV Player Error",MB_OK|MB_ICONSTOP);
  28. break;
  29. }
  30. else if (!r)
  31. {
  32. if ((GetTickCount()-last_title_check) > 1000)
  33. {
  34. char *v=parm->decode->getTitle();
  35. char *buf=(char*)malloc((v?strlen(v):0)+128);
  36. int posms=parm->decode->getpos();
  37. int lenms=parm->decode->getlen();
  38. char *s=parm->decode->getStatus();
  39. if (lenms != ~0)
  40. wsprintf(buf,"%s [%d:%02d/%d:%02d] @ %dkbps %s%s%s- NSV Player",v?v:"",
  41. posms/60000,(posms/1000)%60,
  42. lenms/60000,(lenms/1000)%60,
  43. parm->decode->getBitrate()/1000,
  44. s?"[":"",s?s:"",s?"] ":""
  45. );
  46. else
  47. wsprintf(buf,"%s [%d:%02d] @ %dkbps %s%s%s- NSV Player",v?v:"",
  48. posms/60000,(posms/1000)%60,
  49. parm->decode->getBitrate()/1000,
  50. s?"[":"",s?s:"",s?"] ":""
  51. );
  52. char *p=buf;
  53. while (*p)
  54. {
  55. if (*p == '_') *p=' ';
  56. p++;
  57. }
  58. SetWindowText(parm->vidOut->getHwnd(),buf);
  59. free(buf);
  60. last_title_check=GetTickCount();
  61. }
  62. Sleep(1);
  63. }
  64. }
  65. parm->quit++;
  66. return 0;
  67. }
  68. int g_quit;
  69. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpszCmdParam, int nCmdShow)
  70. {
  71. g_hInstance=hInstance;
  72. BOOL bDisplayInfoAtEnd = FALSE;
  73. char *subtitlefile=NULL;
  74. char buf[11];
  75. lstrcpyn(buf,lpszCmdParam,11);
  76. if(strstr(lpszCmdParam, "/info")) {
  77. bDisplayInfoAtEnd = TRUE;
  78. }
  79. if (!lstrcmpi(buf,"/subtitle="))
  80. {
  81. lpszCmdParam += 10;
  82. char scanc=' ';
  83. if (*lpszCmdParam == '\"')
  84. {
  85. scanc=*lpszCmdParam++;
  86. }
  87. subtitlefile=lpszCmdParam;
  88. while (*lpszCmdParam && *lpszCmdParam != scanc) lpszCmdParam++;
  89. *lpszCmdParam++=0;
  90. while (*lpszCmdParam == ' ') lpszCmdParam++;
  91. }
  92. if (*lpszCmdParam == '\"')
  93. {
  94. lpszCmdParam++;
  95. char *p=strstr(lpszCmdParam,"\"");
  96. if (p) *p=0;
  97. }
  98. if (!*lpszCmdParam)
  99. {
  100. MessageBox(NULL,"Usage: nsvplay.exe [/subtitle=\"file|url\"] filename.nsv|http://url.nsv","NSV Player",MB_OK|MB_ICONINFORMATION);
  101. return 0;
  102. }
  103. int xpos=CW_USEDEFAULT;
  104. int ypos=CW_USEDEFAULT;
  105. _ReadConfigItemInt("xpos",&xpos);
  106. _ReadConfigItemInt("ypos",&ypos);
  107. VideoOutput *vidOut = new VideoOutput(NULL,xpos,ypos);
  108. Decoders_Init();
  109. NSVDecoder *decode=new NSVDecoder(lpszCmdParam,vidOut,subtitlefile);
  110. vidOut->setNSVDecoder(decode);
  111. int m_pause=0;
  112. vidOut->vid_vsync=false;
  113. _ReadConfigItemInt("vsync",&vidOut->vid_vsync);
  114. _ReadConfigItemInt("overlays",&vidOut->vid_overlays);
  115. _ReadConfigItemInt("ddraw",&vidOut->vid_ddraw);
  116. _ReadConfigItemInt("aspectadj",&vidOut->vid_aspectadj);
  117. _ReadConfigItemInt("use_mixer",&g_audio_use_mixer);
  118. {
  119. int temp=1;
  120. _ReadConfigItemInt("subtitles",&temp);
  121. decode->enableSubs(temp);
  122. temp=0;
  123. _ReadConfigItemInt("subtitles_size",&temp);
  124. decode->setSubsFontSize(temp);
  125. }
  126. DWORD id;
  127. parms parm={0,};
  128. parm.decode=decode;
  129. parm.vidOut=vidOut;
  130. vidOut->setcallback(my_wndcallback,&parm);
  131. HANDLE hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)pooThread,(LPVOID)&parm,0,&id);
  132. for (;;)
  133. {
  134. MSG msg;
  135. while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  136. {
  137. if (msg.hwnd == vidOut->getHwnd() && msg.message == WM_KEYDOWN)
  138. {
  139. if (msg.wParam == VK_SPACE) decode->pause(m_pause=!m_pause);
  140. if (msg.wParam == VK_LEFT) decode->seek(decode->getpos()-30000);
  141. if (msg.wParam == VK_RIGHT) decode->seek(decode->getpos()+30000);
  142. if (msg.wParam == VK_UP)
  143. {
  144. int vol=decode->getvolume()+16;
  145. if (vol > 255) vol=255;
  146. decode->setvolume(vol);
  147. }
  148. if (msg.wParam == VK_DOWN)
  149. {
  150. int vol=decode->getvolume()-16;
  151. if (vol < 0) vol=0;
  152. decode->setvolume(vol);
  153. }
  154. if (msg.wParam == VK_RETURN)
  155. {
  156. if (vidOut->is_fullscreen()) vidOut->remove_fullscreen();
  157. else vidOut->fullscreen();
  158. }
  159. if (msg.wParam == 'v' || msg.wParam == 'V')
  160. {
  161. vidOut->vid_vsync=!vidOut->vid_vsync;
  162. }
  163. if (msg.wParam == 'a' || msg.wParam == 'A')
  164. {
  165. vidOut->vid_aspectadj=!vidOut->vid_aspectadj;
  166. PostMessage(vidOut->getHwnd(),WM_TIMER,1,0);
  167. }
  168. }
  169. DispatchMessage(&msg);
  170. }
  171. if (!IsWindow(vidOut->getHwnd()) || parm.quit) break;
  172. Sleep(50);
  173. }
  174. parm.quit++;
  175. WaitForSingleObject(hThread,INFINITE);
  176. CloseHandle(hThread);
  177. delete decode;
  178. delete vidOut;
  179. Decoders_Quit();
  180. #if _DEBUG
  181. // if "/info" on the command line, display some statistics about the movie
  182. if(bDisplayInfoAtEnd) {
  183. char szMessage[MAX_PATH];
  184. wsprintf(szMessage, "File Header Count=%ld\nSync Frames=%ld\nNon-sync Frames=%ld", glCounterNSVf, glSyncFrameCount, glNonSyncFrameCount);
  185. MessageBox(NULL, szMessage, WNDMENU_CAPTION, MB_OK);
  186. }
  187. #endif
  188. return 0;
  189. }