vp5stub.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. ** nsvdec_vp5: vp5stub.cpp - VP5 decompressor
  3. **
  4. ** The VP5 portions that this plug-in links with are Copyright (C) On2, Inc.
  5. **
  6. ** Copyright (C) 2001-2002 Nullsoft, Inc.
  7. **
  8. ** This software is provided 'as-is', without any express or implied warranty.
  9. ** In no event will the authors be held liable for any damages arising from the use of this software.
  10. **
  11. ** Permission is granted to anyone to use this software for any purpose, including commercial
  12. ** applications, and to alter it and redistribute it freely, subject to the following restrictions:
  13. ** 1. The origin of this software must not be misrepresented; you must not claim that you wrote the
  14. ** original software. If you use this software in a product, an acknowledgment in the product
  15. ** documentation would be appreciated but is not required.
  16. ** 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
  17. ** being the original software.
  18. ** 3. This notice may not be removed or altered from any source distribution.
  19. **
  20. **
  21. */
  22. #include <windows.h>
  23. #include "../nsv/nsvlib.h"
  24. #include "../nsv/dec_if.h"
  25. #include "../libvp6/include/duck_dxl.h"
  26. #include <stddef.h>
  27. extern "C" {
  28. void GetImageBufs(DXL_XIMAGE_HANDLE x, YV12_PLANES *p);
  29. void vp50_SetParameter ( DXL_XIMAGE_HANDLE src, int Command, uintptr_t Parameter );
  30. };
  31. int vp5_postProcess=6;
  32. int vp5_cpuFree=70;
  33. int vp5_deInterlace=0;
  34. typedef enum
  35. {
  36. PBC_SET_POSTPROC,
  37. PBC_SET_CPUFREE,
  38. PBC_MAX_PARAM,
  39. PBC_SET_TESTMODE,
  40. PBC_SET_PBSTRUCT,
  41. PBC_SET_BLACKCLAMP,
  42. PBC_SET_WHITECLAMP,
  43. PBC_SET_REFERENCEFRAME,
  44. PBC_SET_DEINTERLACEMODE
  45. } PB_COMMAND_TYPE;
  46. extern "C"
  47. {
  48. int vp50_Init(void);
  49. int vp50_Exit(void);
  50. }
  51. class VP5_Decoder : public IVideoDecoder {
  52. public:
  53. VP5_Decoder(int w, int h);
  54. ~VP5_Decoder();
  55. int decode(int need_kf,
  56. void *in, int in_len,
  57. void **out, // out is set to a pointer to data
  58. unsigned int *out_type, // 'Y','V','1','2' is currently defined
  59. int *is_kf);
  60. void flush() { }
  61. void initMmx();
  62. private:
  63. int l_tcpu, l_pp;
  64. static int init;
  65. static int mmx_available;
  66. DXL_XIMAGE_HANDLE xim;
  67. YV12_PLANES vidbufdec;
  68. };
  69. int VP5_Decoder::init;
  70. int VP5_Decoder::mmx_available;
  71. VP5_Decoder::VP5_Decoder(int w, int h)
  72. {
  73. l_tcpu=-1;
  74. l_pp=-1;
  75. if (!init)
  76. {
  77. init=1;
  78. DXL_InitVideo(64,64);
  79. vp50_Init();
  80. initMmx();
  81. }
  82. vidbufdec.y.baseAddr=0;
  83. xim = DXL_AlterXImage( NULL, (unsigned char *)"" ,MAKEFOURCC('V','P','5','0'), DXRGBNULL,0,0);
  84. }
  85. void VP5_Decoder::initMmx()
  86. {
  87. #ifdef _M_IX86
  88. DWORD retval1,retval2;
  89. __try {
  90. _asm {
  91. mov eax, 1 // set up CPUID to return processor version and features
  92. // 0 = vendor string, 1 = version info, 2 = cache info
  93. _emit 0x0f // code bytes = 0fh, 0a2h
  94. _emit 0xa2
  95. mov retval1, eax
  96. mov retval2, edx
  97. }
  98. } __except(EXCEPTION_EXECUTE_HANDLER) { retval1 = retval2 = 0;}
  99. mmx_available = retval1 && (retval2&0x800000);
  100. #else
  101. mmx_available =0;
  102. #endif
  103. }
  104. VP5_Decoder::~VP5_Decoder()
  105. {
  106. if ( xim ) DXL_DestroyXImage( xim);
  107. }
  108. int VP5_Decoder::decode(int need_kf,
  109. void *in, int in_len,
  110. void **out, // out is set to a pointer to data
  111. unsigned int *out_type, // 'Y','V','1','2' is currently defined
  112. int *is_kf)
  113. {
  114. bool provide_width_height = (out_type[0] == 1);
  115. BYTE *data=(BYTE*)in;
  116. if (!xim) return -1;
  117. out_type[0]=NSV_MAKETYPE('Y','V','1','2');
  118. if (vp5_postProcess != l_pp || vp5_cpuFree != l_tcpu)
  119. {
  120. l_pp=vp5_postProcess;
  121. l_tcpu=vp5_cpuFree;
  122. if(vp5_cpuFree)
  123. DXL_SetParameter(xim, PBC_SET_CPUFREE, vp5_cpuFree);
  124. else
  125. DXL_SetParameter(xim, PBC_SET_POSTPROC, vp5_postProcess);
  126. DXL_SetParameter(xim, PBC_SET_DEINTERLACEMODE, vp5_deInterlace );
  127. DXL_SetParameter(xim, PBC_SET_BLACKCLAMP,0);
  128. DXL_SetParameter(xim, PBC_SET_WHITECLAMP,0);
  129. }
  130. DXL_AlterXImageData( xim, data);
  131. DXL_SetXImageCSize(xim, in_len);
  132. *is_kf=!(!in_len || data[0] > 0x7f);
  133. *out=NULL;
  134. if ((need_kf && !*is_kf) || !in_len)
  135. {
  136. return 0;
  137. }
  138. if (!DXL_dxImageToVScreen( xim, NULL))
  139. {
  140. if(mmx_available)
  141. {
  142. #ifdef _M_IX86
  143. _asm {
  144. emms;
  145. };
  146. #endif
  147. }
  148. GetImageBufs(xim,&vidbufdec);
  149. *out=&vidbufdec;
  150. if (provide_width_height)
  151. {
  152. int x, y, w, h;
  153. DXL_GetXImageXYWH(xim, &x, &y, &w, &h);
  154. out_type[1] = w;
  155. out_type[2] = h;
  156. }
  157. return 0;
  158. }
  159. return -1;
  160. }
  161. #ifndef ACTIVEX_CONTROL
  162. extern "C" {
  163. __declspec(dllexport) IVideoDecoder *CreateVideoDecoder(int w, int h, double framerate, unsigned int fmt, int *flip)
  164. {
  165. if (fmt == NSV_MAKETYPE('V','P','5','0'))
  166. {
  167. *flip=1;
  168. return new VP5_Decoder(w,h);
  169. }
  170. return NULL;
  171. }
  172. }
  173. #else
  174. IVideoDecoder *VP5_CREATE(int w, int h, double framerate, unsigned int fmt, int *flip)
  175. {
  176. if (fmt == NSV_MAKETYPE('V','P','5','0'))
  177. {
  178. *flip=1;
  179. return new VP5_Decoder(w,h);
  180. }
  181. return NULL;
  182. }
  183. #endif