vp3stub.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include "../nsv/nsvplay/main.h"
  2. #include "../vp32/include/duck_dxl.h"
  3. #include "vfw.h"
  4. extern "C" {
  5. void GetImageBufs(DXL_XIMAGE_HANDLE x, YV12_PLANES *p);
  6. };
  7. int vp3_postprocess=0;
  8. int vp3_targetcpu=0;
  9. class VP3_Decoder : public IVideoDecoder {
  10. public:
  11. VP3_Decoder(int w, int h, int uvflip);
  12. ~VP3_Decoder();
  13. int decode(int need_kf,
  14. void *in, int in_len,
  15. void **out, // out is set to a pointer to data
  16. unsigned int *out_type, // 'Y','V','1','2' is currently defined
  17. int *is_kf);
  18. void flush() { }
  19. private:
  20. int m_uvflip;
  21. int l_tcpu, l_pp;
  22. static int init;
  23. DXL_XIMAGE_HANDLE xim;
  24. YV12_PLANES vidbufdec;
  25. };
  26. int VP3_Decoder::init;
  27. VP3_Decoder::VP3_Decoder(int w, int h, int uvflip)
  28. {
  29. l_tcpu=-1;
  30. l_pp=-1;
  31. if (!init)
  32. {
  33. init=1;
  34. DXL_InitVideoEx(1,1);
  35. }
  36. m_uvflip=uvflip;
  37. vidbufdec.y.baseAddr=0;
  38. xim = DXL_AlterXImage( NULL, (unsigned char *)"" ,MAKEFOURCC('V','P','3','1'), DXRGBNULL,0,0);
  39. }
  40. VP3_Decoder::~VP3_Decoder()
  41. {
  42. if ( xim ) DXL_DestroyXImage( xim);
  43. }
  44. int VP3_Decoder::decode(int need_kf,
  45. void *in, int in_len,
  46. void **out, // out is set to a pointer to data
  47. unsigned int *out_type, // 'Y','V','1','2' is currently defined
  48. int *is_kf)
  49. {
  50. bool provide_width_height = (out_type[0] == 1);
  51. BYTE *data=(BYTE*)in;
  52. if (!xim) return -1;
  53. out_type[0]=NSV_MAKETYPE('Y','V','1','2');
  54. if (vp3_postprocess != l_pp || vp3_targetcpu != l_tcpu)
  55. {
  56. l_pp=vp3_postprocess;
  57. l_tcpu=vp3_targetcpu;
  58. if (l_pp)
  59. {
  60. int v=l_tcpu;
  61. if (v < 1) v=1;
  62. if (v > 100) v=100;
  63. vp31_SetParameter(xim,1, v);
  64. vp31_SetParameter(xim,0, 9);
  65. }
  66. else
  67. {
  68. vp31_SetParameter(xim,1, 0);
  69. vp31_SetParameter(xim,0, 0);
  70. }
  71. }
  72. DXL_AlterXImageData( xim, data);
  73. DXL_SetXImageCSize(xim, in_len);
  74. *is_kf=!(!in_len || data[0] > 0x7f);
  75. *out=NULL;
  76. if ((need_kf && !*is_kf) || !in_len)
  77. {
  78. return 0;
  79. }
  80. if (!DXL_dxImageToVScreen( xim, NULL))
  81. {
  82. GetImageBufs(xim,&vidbufdec);
  83. if (m_uvflip)
  84. {
  85. YV12_PLANE tmp=vidbufdec.v;
  86. vidbufdec.v=vidbufdec.u;
  87. vidbufdec.u=tmp;
  88. }
  89. *out=&vidbufdec;
  90. if (provide_width_height)
  91. {
  92. int x, y, w, h;
  93. DXL_GetXImageXYWH(xim, &x, &y, &w, &h);
  94. out_type[1] = w;
  95. out_type[2] = h;
  96. }
  97. return 0;
  98. }
  99. return -1;
  100. }
  101. /*
  102. IVideoDecoder *VP3_CREATE(int w, int h, double framerate, unsigned int fmt, int *flip)
  103. {
  104. if (fmt == NSV_MAKETYPE('V','P','3',' ') || fmt == NSV_MAKETYPE('V','P','3','1'))
  105. {
  106. *flip=1;
  107. return new VP3_Decoder(w,h,fmt == NSV_MAKETYPE('V','P','3',' '));
  108. }
  109. return NULL;
  110. }
  111. */
  112. extern "C" {
  113. __declspec(dllexport) IVideoDecoder *CreateVideoDecoder(int w, int h, double framerate, unsigned int fmt, int *flip)
  114. {
  115. if (fmt == NSV_MAKETYPE('V','P','3',' ') || fmt == NSV_MAKETYPE('V','P','3','0') || fmt == NSV_MAKETYPE('V','P','3','1'))
  116. {
  117. *flip=1;
  118. return new VP3_Decoder(w,h,fmt == NSV_MAKETYPE('V','P','3',' '));
  119. }
  120. return NULL;
  121. }
  122. }