nsvdec.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "nsvdec.h"
  2. #ifdef _WIN32
  3. #include <windows.h>
  4. #endif
  5. #include <bfc/platform/export.h>
  6. #include "../nsv/nsvlib.h"
  7. #include "../nsv/dec_if.h"
  8. #include "duck_dxl.h"
  9. #include <stddef.h>
  10. extern "C" {
  11. void GetImageBufs(DXL_XIMAGE_HANDLE x, YV12_PLANES *p);
  12. void vp60_SetParameter ( DXL_XIMAGE_HANDLE src, int Command, uintptr_t Parameter );
  13. int vp60_getWH(DXL_XIMAGE_HANDLE src, int *w, int *h);
  14. };
  15. int vp6_postProcess=6;
  16. int vp6_cpuFree=70;
  17. int vp6_deInterlace=0;
  18. int vp6_addNoise=1;
  19. typedef enum
  20. {
  21. PBC_SET_POSTPROC,
  22. PBC_SET_CPUFREE,
  23. PBC_MAX_PARAM,
  24. PBC_SET_TESTMODE,
  25. PBC_SET_PBSTRUCT,
  26. PBC_SET_BLACKCLAMP,
  27. PBC_SET_WHITECLAMP,
  28. PBC_SET_REFERENCEFRAME,
  29. PBC_SET_DEINTERLACEMODE,
  30. PBC_SET_ADDNOISE
  31. } PB_COMMAND_TYPE;
  32. VP6_Decoder::VP6_Decoder(int w, int h)
  33. {
  34. l_tcpu=-1;
  35. l_pp=-1;
  36. vidbufdec.y.baseAddr=0;
  37. xim = DXL_AlterXImage( NULL, (unsigned char *)"" ,NSV_MAKETYPE('V','P','6','0'), DXRGBNULL,0,0);
  38. }
  39. VP6_Decoder::~VP6_Decoder()
  40. {
  41. if ( xim ) DXL_DestroyXImage( xim);
  42. }
  43. int VP6_Decoder::decode(int need_kf,
  44. void *in, int in_len,
  45. void **out, // out is set to a pointer to data
  46. unsigned int *out_type, // 'Y','V','1','2' is currently defined
  47. int *is_kf)
  48. {
  49. bool provide_width_height = (out_type[0] == 1);
  50. unsigned char *data=(unsigned char *)in;
  51. if (!xim) return -1;
  52. *out_type=NSV_MAKETYPE('Y','V','1','2');
  53. if (vp6_postProcess != l_pp || vp6_cpuFree != l_tcpu)
  54. {
  55. l_pp=vp6_postProcess;
  56. l_tcpu=vp6_cpuFree;
  57. if(vp6_cpuFree)
  58. DXL_SetParameter(xim, PBC_SET_CPUFREE, vp6_cpuFree);
  59. else
  60. DXL_SetParameter(xim, PBC_SET_POSTPROC, vp6_postProcess);
  61. DXL_SetParameter(xim, PBC_SET_DEINTERLACEMODE, vp6_deInterlace );
  62. DXL_SetParameter(xim, PBC_SET_ADDNOISE, vp6_addNoise);
  63. DXL_SetParameter(xim, PBC_SET_BLACKCLAMP,0);
  64. DXL_SetParameter(xim, PBC_SET_WHITECLAMP,0);
  65. }
  66. DXL_AlterXImageData( xim, data);
  67. DXL_SetXImageCSize(xim, in_len);
  68. *is_kf=!(!in_len || data[0] > 0x7f);
  69. *out=NULL;
  70. if ((need_kf && !*is_kf) || !in_len)
  71. {
  72. return 0;
  73. }
  74. if (!DXL_dxImageToVScreen( xim, NULL))
  75. {
  76. #ifdef _M_IX86
  77. _asm {
  78. emms;
  79. };
  80. #endif
  81. GetImageBufs(xim,&vidbufdec);
  82. *out=&vidbufdec;
  83. if (provide_width_height)
  84. {
  85. int w, h;
  86. vp60_getWH(xim, &w, &h);
  87. out_type[1] = w;
  88. out_type[2] = h;
  89. }
  90. return 0;
  91. }
  92. return -1;
  93. }