1
0

vp6stub.cpp 5.1 KB

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