vp5stub.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include <windows.h>
  2. #include "../nsvlib.h"
  3. #include "../dec_if.h"
  4. #include "vfw.h"
  5. class VP5_Decoder : public IVideoDecoder {
  6. public:
  7. VP5_Decoder(int w, int h);
  8. ~VP5_Decoder();
  9. int decode(int need_kf,
  10. void *in, int in_len,
  11. void **out, // out is set to a pointer to data
  12. unsigned int *out_type, // 'Y','V','1','2' is currently defined
  13. int *is_kf);
  14. void flush() { }
  15. int m_err;
  16. private:
  17. int width,height;
  18. BITMAPINFO vp5_bmo,vp5_bmi;
  19. HIC vp5_hic;
  20. unsigned char *vidbufdec;
  21. };
  22. VP5_Decoder::VP5_Decoder(int w, int h)
  23. {
  24. width=w;
  25. height=h;
  26. m_err=0;
  27. vp5_hic=0;
  28. vidbufdec=(unsigned char*)malloc(sizeof(YV12_PLANES) + w*h*3/2);
  29. // init vp5 decode
  30. memset((void *) &vp5_bmi,0,sizeof(BITMAPINFO));
  31. memset((void *) &vp5_bmo,0,sizeof(BITMAPINFO));
  32. vp5_bmi.bmiHeader.biCompression = mmioFOURCC('V','P','5','0');
  33. vp5_bmi.bmiHeader.biHeight=h;
  34. vp5_bmi.bmiHeader.biWidth =w;
  35. vp5_bmo.bmiHeader.biCompression = mmioFOURCC('Y','V','1','2');
  36. vp5_bmo.bmiHeader.biHeight=h;
  37. vp5_bmo.bmiHeader.biWidth =w;
  38. vp5_bmo.bmiHeader.biBitCount = 12;
  39. vp5_hic = ICOpen(ICTYPE_VIDEO, vp5_bmi.bmiHeader.biCompression, ICMODE_DECOMPRESS);
  40. vp5_bmo.bmiHeader.biHeight*=-1;
  41. if(!vp5_hic || ICERR_OK !=ICDecompressBegin(vp5_hic, &vp5_bmi, &vp5_bmo))
  42. {
  43. m_err=1;
  44. return;
  45. }
  46. }
  47. VP5_Decoder::~VP5_Decoder()
  48. {
  49. if (vp5_hic)
  50. {
  51. ICDecompressEnd(vp5_hic);
  52. ICClose(vp5_hic);
  53. }
  54. free(vidbufdec);
  55. }
  56. int VP5_Decoder::decode(int need_kf,
  57. void *in, int in_len,
  58. void **out, // out is set to a pointer to data
  59. unsigned int *out_type, // 'Y','V','1','2' is currently defined
  60. int *is_kf)
  61. {
  62. *out_type=NSV_MAKETYPE('Y','V','1','2');
  63. vp5_bmi.bmiHeader.biSizeImage = in_len;
  64. if(ICERR_OK == ICDecompress(vp5_hic,0,(BITMAPINFOHEADER *) &vp5_bmi, (char*)in,(BITMAPINFOHEADER *) &vp5_bmo, (char*)vidbufdec+sizeof(YV12_PLANES)))
  65. {
  66. *is_kf=!(!in_len || ((unsigned char *)in)[0] > 0x7f);
  67. if (need_kf && !*is_kf)
  68. {
  69. return 0;
  70. }
  71. YV12_PLANES *image_vbd=(YV12_PLANES *)vidbufdec;
  72. image_vbd->y.baseAddr=(unsigned char *)(image_vbd+1);
  73. image_vbd->v.baseAddr=((unsigned char *)(image_vbd+1)) + width*height;
  74. image_vbd->u.baseAddr=((unsigned char *)(image_vbd+1)) + width*height*5/4;
  75. image_vbd->y.rowBytes=width;
  76. image_vbd->v.rowBytes=width/2;
  77. image_vbd->u.rowBytes=width/2;
  78. *out=(void*)vidbufdec;
  79. return 0;
  80. }
  81. return -1;
  82. }
  83. IVideoDecoder *VP5_CREATE(int w, int h, double framerate, unsigned int fmt, int *flip)
  84. {
  85. if (fmt == NSV_MAKETYPE('V','P','5','0'))
  86. {
  87. *flip=0;
  88. VP5_Decoder *a=new VP5_Decoder(w,h);
  89. if (a->m_err)
  90. {
  91. delete a;
  92. return NULL;
  93. }
  94. return a;
  95. }
  96. return NULL;
  97. }