KLVideo.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:3k
源码类别:

模拟服务器

开发平台:

C/C++

  1. // KLVideo.cpp : Defines the entry point for the DLL application.
  2. //
  3. #include "stdafx.h"
  4. #include "KLVideo.h"
  5. #include <windows.h>
  6. #include <Mmsystem.h>
  7. #include "KLMp4Video.h"
  8. #include "KLMp4Audio.h"
  9. BOOL APIENTRY DllMain( HANDLE hModule, 
  10.                        DWORD  ul_reason_for_call, 
  11.                        LPVOID lpReserved
  12.  )
  13. {
  14.     switch (ul_reason_for_call)
  15. {
  16. case DLL_PROCESS_ATTACH:
  17. case DLL_THREAD_ATTACH:
  18. case DLL_THREAD_DETACH:
  19. case DLL_PROCESS_DETACH:
  20. break;
  21.     }
  22.     return TRUE;
  23. }
  24. RADEXPFUNC u8 KLVideoSetSoundSystem(void PTR4* dd)
  25. {
  26. return 0;
  27. }
  28. RADEXPFUNC HKLVIDEO KLVideoOpen(char PTR4* name,u32 flags, void PTR4* hWnd)
  29. {
  30. HKLVIDEO hVideo = new KLVIDEO;
  31. char *cc;
  32. if(!hVideo)
  33. goto ErrorExit;
  34. char szPathName[256];
  35. if(GetModuleFileName(NULL, szPathName, 255) == 0)
  36. goto ErrorExit;
  37. cc = strrchr(szPathName,'\');
  38. if(cc == NULL)
  39. goto ErrorExit;
  40. *(cc+1) = 0;
  41. strcat(szPathName,name);
  42. hVideo->pMpeg4Audio = new KLMp4Audio;
  43. if(!hVideo->pMpeg4Audio)
  44. goto ErrorExit;
  45. hVideo->pMpeg4Audio->SetWinHandle((HWND) hWnd);
  46. if(!hVideo->pMpeg4Audio->Open(name))
  47. {
  48. delete hVideo->pMpeg4Audio;
  49. hVideo->pMpeg4Audio = NULL;
  50. }
  51. else
  52. hVideo->pMpeg4Audio->Play();
  53. hVideo->pMpeg4Video = new KLMp4Video;
  54. if(!hVideo->pMpeg4Video)
  55. goto ErrorExit;
  56. if(!hVideo->pMpeg4Video->Open(name))
  57. goto ErrorExit;
  58. int nWidth, nHeight;
  59. hVideo->pMpeg4Video->GetVideoSize(nWidth, nHeight);
  60. hVideo->Width = (u32)nWidth;
  61. hVideo->Height = (u32)nHeight;
  62. hVideo->Frames = hVideo->pMpeg4Video->GetVideoFrames();
  63. hVideo->FrameNum = 0;
  64. hVideo->pMpeg4Video->Play();
  65. return hVideo;
  66. ErrorExit:
  67. if(hVideo)
  68. {
  69. if(hVideo->pMpeg4Video)
  70. delete hVideo->pMpeg4Video;
  71. if(hVideo->pMpeg4Audio)
  72. delete hVideo->pMpeg4Audio;
  73. delete hVideo;
  74. }
  75. return NULL;
  76. }
  77. RADEXPFUNC void KLVideoClose(HKLVIDEO bnk)
  78. {
  79. if(!bnk)
  80. return;
  81. if(bnk->pMpeg4Video)
  82. {
  83. bnk->pMpeg4Video->Close();
  84. delete bnk->pMpeg4Video;
  85. }
  86. if(bnk->pMpeg4Audio)
  87. {
  88. bnk->pMpeg4Audio->Close();
  89. delete bnk->pMpeg4Audio;
  90. }
  91. delete bnk;
  92. }
  93. RADEXPFUNC u32 KLVideoWait(HKLVIDEO bnk)
  94. {
  95. if(!bnk || !bnk->pMpeg4Video)
  96. return false;
  97. return bnk->pMpeg4Video->ShouldWait();
  98. }
  99. RADEXPFUNC void KLVideoCopyToBuffer(HKLVIDEO bnk,void PTR4* buf,u32 left,u32 top,u32 Pitch,u32 destheight,u32 Flags)
  100. {
  101. if(!bnk || !bnk->pMpeg4Video)
  102. return;
  103. bnk->pMpeg4Video->VideoCopyToBuffer(buf, left, top, Pitch, destheight, Flags);
  104. bnk->FrameNum = bnk->pMpeg4Video->GetCurFrame();
  105. }
  106. RADEXPFUNC u32 KLVideoDoFrame(HKLVIDEO bnk)
  107. {
  108. return 1;
  109. }
  110. RADEXPFUNC void KLVideoNextFrame(HKLVIDEO bnk)
  111. {
  112. }
  113. RADEXPFUNC void KLVideoSetSoundVolume(HKLVIDEO bnk,u32 nVolume)
  114. {
  115. if(!bnk || !bnk->pMpeg4Audio)
  116. return;
  117. if(nVolume > 100)
  118. return;
  119. long n = 100 - (long)nVolume;
  120. bnk->pMpeg4Audio->SetVolume(-n * n);
  121. }
  122. RADEXPFUNC void KLVideoSetSoundTrack(u32 track)
  123. {
  124. }
  125. RADEXPFUNC u32 KLVideoGetCurrentFrame(HKLVIDEO bnk)
  126. {
  127. if(!bnk || !bnk->pMpeg4Video)
  128. return 0;
  129. return bnk->pMpeg4Video->GetCurFrame();
  130. }