flv_vp6_decoder.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include "flv_vp6_decoder.h"
  2. #include "../nsv/nsvlib.h"
  3. #include "../libvp6/include/vp6.h"
  4. int FLVDecoderCreator::CreateVideoDecoder(int format_type, int width, int height, ifc_flvvideodecoder **decoder)
  5. {
  6. if (format_type == FLV::VIDEO_FORMAT_VP6 || format_type == FLV::VIDEO_FORMAT_VP62)
  7. {
  8. //DXL_XIMAGE_HANDLE xim = DXL_CreateXImageOfType((unsigned char *)"" , format_type == FLV::VIDEO_FORMAT_VP6?NSV_MAKETYPE('V','P','6','0'):NSV_MAKETYPE('V','P','6','2'));
  9. DXL_XIMAGE_HANDLE xim = DXL_AlterXImage( NULL, (unsigned char *)"" ,NSV_MAKETYPE('V','P','6','0'), DXRGBNULL, 0, 0);
  10. if (!xim)
  11. return CREATEDECODER_FAILURE;
  12. *decoder = new FLVVP6(xim);
  13. return CREATEDECODER_SUCCESS;
  14. }
  15. return CREATEDECODER_NOT_MINE;
  16. }
  17. int FLVDecoderCreator::HandlesVideo(int format_type)
  18. {
  19. if (format_type == FLV::VIDEO_FORMAT_VP6 || format_type == FLV::VIDEO_FORMAT_VP62)
  20. {
  21. return CREATEDECODER_SUCCESS;
  22. }
  23. return CREATEDECODER_NOT_MINE;
  24. }
  25. #define CBCLASS FLVDecoderCreator
  26. START_DISPATCH;
  27. CB(CREATE_VIDEO_DECODER, CreateVideoDecoder)
  28. CB(HANDLES_VIDEO, HandlesVideo)
  29. END_DISPATCH;
  30. #undef CBCLASS
  31. static const int vp6_postProcess=6;
  32. static const int vp6_cpuFree=70;
  33. static const int vp6_deInterlace=0;
  34. static const int vp6_addNoise=1;
  35. enum
  36. {
  37. PBC_SET_POSTPROC,
  38. PBC_SET_CPUFREE,
  39. PBC_MAX_PARAM,
  40. PBC_SET_TESTMODE,
  41. PBC_SET_PBSTRUCT,
  42. PBC_SET_BLACKCLAMP,
  43. PBC_SET_WHITECLAMP,
  44. PBC_SET_REFERENCEFRAME,
  45. PBC_SET_DEINTERLACEMODE,
  46. PBC_SET_ADDNOISE
  47. } ;
  48. extern "C"
  49. {
  50. void GetImageBufs(DXL_XIMAGE_HANDLE x, YV12_PLANES *p);
  51. void vp60_SetParameter(DXL_XIMAGE_HANDLE src, int Command, uintptr_t Parameter );
  52. };
  53. FLVVP6::FLVVP6(DXL_XIMAGE_HANDLE xim) : xim(xim)
  54. {
  55. decoded=0;
  56. if(vp6_cpuFree)
  57. vp60_SetParameter(xim, PBC_SET_CPUFREE, vp6_cpuFree);
  58. else
  59. vp60_SetParameter(xim, PBC_SET_POSTPROC, vp6_postProcess);
  60. vp60_SetParameter(xim, PBC_SET_DEINTERLACEMODE, vp6_deInterlace );
  61. vp60_SetParameter(xim, PBC_SET_ADDNOISE, vp6_addNoise);
  62. vp60_SetParameter(xim, PBC_SET_BLACKCLAMP,0);
  63. vp60_SetParameter(xim, PBC_SET_WHITECLAMP,0);
  64. }
  65. int FLVVP6::GetOutputFormat(int *x, int *y, int *color_format)
  66. {
  67. if (xim)
  68. {
  69. if (vp60_getWH(xim, x, y) == DXL_OK)
  70. {
  71. *color_format = NSV_MAKETYPE('Y','V','1','2');
  72. return FLV_VIDEO_SUCCESS;
  73. }
  74. }
  75. return FLV_VIDEO_FAILURE;
  76. }
  77. int FLVVP6::DecodeSample(const void *inputBuffer, size_t inputBufferBytes, int32_t timestamp)
  78. {
  79. uint8_t *vp6_data = (uint8_t *)inputBuffer;
  80. if (inputBufferBytes)
  81. {
  82. // skip first byte
  83. vp6_data++;
  84. inputBufferBytes--;
  85. DXL_AlterXImageData(xim, (unsigned char *)vp6_data);
  86. DXL_SetXImageCSize(xim, inputBufferBytes);
  87. if (!vp60_decompress(xim))
  88. {
  89. decoded=1;
  90. return FLV_VIDEO_SUCCESS;
  91. }
  92. }
  93. return FLV_VIDEO_FAILURE;
  94. }
  95. void FLVVP6::Close()
  96. {
  97. if (xim)
  98. DXL_DestroyXImage(xim);
  99. delete this;
  100. }
  101. int FLVVP6::GetPicture(void **data, void **decoder_data, uint64_t *timestamp)
  102. {
  103. if (decoded)
  104. {
  105. GetImageBufs(xim,&vidbufdec);
  106. *data=&vidbufdec;
  107. *decoder_data = 0;
  108. decoded = 0;
  109. return FLV_VIDEO_SUCCESS;
  110. }
  111. return FLV_VIDEO_FAILURE;
  112. }
  113. #define CBCLASS FLVVP6
  114. START_DISPATCH;
  115. CB(FLV_VIDEO_GETOUTPUTFORMAT, GetOutputFormat)
  116. CB(FLV_VIDEO_DECODE, DecodeSample)
  117. VCB(FLV_VIDEO_CLOSE, Close)
  118. CB(FLV_VIDEO_GET_PICTURE, GetPicture)
  119. END_DISPATCH;
  120. #undef CBCLASS