1
0

avi_vp6_decoder.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #include "avi_vp6_decoder.h"
  2. #include "../nsv/nsvlib.h"
  3. #include "../nsavi/nsavi.h"
  4. #include "../libvp6/include/vp6.h"
  5. int AVIDecoderCreator::CreateVideoDecoder(const nsavi::AVIH *avi_header, const nsavi::STRH *stream_header, const nsavi::STRF *stream_format, const nsavi::STRD *stream_data, ifc_avivideodecoder **decoder)
  6. {
  7. nsavi::video_format *format = (nsavi::video_format *)stream_format;
  8. if (format)
  9. {
  10. if (format->compression == '26PV' || format->compression == '16PV' || format->compression == '06PV')
  11. {
  12. DXL_XIMAGE_HANDLE xim = DXL_AlterXImage( NULL, (unsigned char *)"" ,NSV_MAKETYPE('V','P','6','0'), DXRGBNULL, 0, 0);
  13. if (!xim)
  14. return CREATEDECODER_FAILURE;
  15. *decoder = new AVIVP6(xim);
  16. return CREATEDECODER_SUCCESS;
  17. }
  18. }
  19. return CREATEDECODER_NOT_MINE;
  20. }
  21. #define CBCLASS AVIDecoderCreator
  22. START_DISPATCH;
  23. CB(CREATE_VIDEO_DECODER, CreateVideoDecoder)
  24. END_DISPATCH;
  25. #undef CBCLASS
  26. static const int vp6_postProcess=6;
  27. static const int vp6_cpuFree=70;
  28. static const int vp6_deInterlace=0;
  29. static const int vp6_addNoise=1;
  30. enum
  31. {
  32. PBC_SET_POSTPROC,
  33. PBC_SET_CPUFREE,
  34. PBC_MAX_PARAM,
  35. PBC_SET_TESTMODE,
  36. PBC_SET_PBSTRUCT,
  37. PBC_SET_BLACKCLAMP,
  38. PBC_SET_WHITECLAMP,
  39. PBC_SET_REFERENCEFRAME,
  40. PBC_SET_DEINTERLACEMODE,
  41. PBC_SET_ADDNOISE
  42. } ;
  43. extern "C"
  44. {
  45. void GetImageBufs(DXL_XIMAGE_HANDLE x, YV12_PLANES *p);
  46. void vp60_SetParameter(DXL_XIMAGE_HANDLE src, int Command, uintptr_t Parameter );
  47. };
  48. AVIVP6::AVIVP6(DXL_XIMAGE_HANDLE xim) : xim(xim)
  49. {
  50. decoded=0;
  51. if(vp6_cpuFree)
  52. DXL_SetParameter(xim, PBC_SET_CPUFREE, vp6_cpuFree);
  53. else
  54. DXL_SetParameter(xim, PBC_SET_POSTPROC, vp6_postProcess);
  55. DXL_SetParameter(xim, PBC_SET_DEINTERLACEMODE, vp6_deInterlace );
  56. DXL_SetParameter(xim, PBC_SET_ADDNOISE, vp6_addNoise);
  57. DXL_SetParameter(xim, PBC_SET_BLACKCLAMP,0);
  58. DXL_SetParameter(xim, PBC_SET_WHITECLAMP,0);
  59. }
  60. int AVIVP6::GetOutputProperties(int *x, int *y, int *color_format, double *aspect_ratio, int *flip)
  61. {
  62. if (xim)
  63. {
  64. if (vp60_getWH(xim, x, y) == DXL_OK)
  65. {
  66. *color_format = nsaviFOURCC('Y','V','1','2');
  67. *flip = 1;
  68. return AVI_SUCCESS;
  69. }
  70. }
  71. return AVI_FAILURE;
  72. }
  73. int AVIVP6::DecodeChunk(uint16_t type, const void *inputBuffer, size_t inputBufferBytes)
  74. {
  75. uint8_t *vp6_data = (uint8_t *)inputBuffer;
  76. if (inputBufferBytes)
  77. {
  78. // skip first byte
  79. //vp6_data++;
  80. //inputBufferBytes--;
  81. DXL_AlterXImageData(xim, (unsigned char *)vp6_data);
  82. DXL_SetXImageCSize(xim, inputBufferBytes);
  83. if (!vp60_decompress(xim))
  84. {
  85. decoded=1;
  86. return AVI_SUCCESS;
  87. }
  88. }
  89. return AVI_FAILURE;
  90. }
  91. void AVIVP6::Flush()
  92. {
  93. //if (decoder)
  94. // MPEG4Video_Flush(decoder);
  95. }
  96. int AVIVP6::GetPicture(void **data, void **decoder_data)
  97. {
  98. if (decoded)
  99. {
  100. GetImageBufs(xim,&vidbufdec);
  101. *data=&vidbufdec;
  102. *decoder_data = 0;
  103. decoded = 0;
  104. return AVI_SUCCESS;
  105. }
  106. return AVI_FAILURE;
  107. }
  108. void AVIVP6::FreePicture(void *data, void *decoder_data)
  109. {
  110. }
  111. void AVIVP6::HurryUp(int state)
  112. {
  113. }
  114. #define CBCLASS AVIVP6
  115. START_DISPATCH;
  116. CB(GET_OUTPUT_PROPERTIES, GetOutputProperties)
  117. CB(DECODE_CHUNK, DecodeChunk)
  118. VCB(FLUSH, Flush)
  119. CB(GET_PICTURE, GetPicture)
  120. VCB(FREE_PICTURE, FreePicture)
  121. VCB(HURRY_UP, HurryUp)
  122. END_DISPATCH;
  123. #undef CBCLASS