1
0

Decoder.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "Decoder.h"
  2. bool Decoder::initted;
  3. unsigned char *Decoder::clp;
  4. unsigned char Decoder::clp_table[1024];
  5. int Decoder::DecodeFrame(YV12_PLANES *yv12, int *width, int *height, int *keyframe)
  6. {
  7. if (getheader())
  8. {
  9. if (firstFrame)
  10. {
  11. if (init())
  12. return 1;
  13. }
  14. Frame frame;
  15. getpicture(frame);
  16. yv12->y.baseAddr = frame[0];
  17. yv12->y.rowBytes = coded_picture_width;
  18. yv12->u.baseAddr = frame[1];
  19. yv12->u.rowBytes = chrom_width;
  20. yv12->v.baseAddr = frame[2];
  21. yv12->v.rowBytes = chrom_width;
  22. *width = horizontal_size;
  23. *height = vertical_size;
  24. *keyframe = (pict_type == PCT_INTRA)?1:0;
  25. return 0;
  26. }
  27. return 1;
  28. }
  29. Decoder::Decoder()
  30. {
  31. for (int cc=0; cc<3; cc++)
  32. {
  33. refframe[cc]=0;
  34. newframe[cc]=0;
  35. oldrefframe[cc]=0;
  36. edgeframe[cc]=0;
  37. edgeframeorig[cc]=0;
  38. }
  39. horizontal_size=0;
  40. vertical_size=0;
  41. mb_width=0;
  42. mb_height=0;
  43. coded_picture_width=0;
  44. coded_picture_height=0;
  45. chrom_width=0;
  46. chrom_height=0;
  47. pict_type=0;
  48. fault=0;
  49. refidct=0;
  50. quant=0;
  51. escapemode=0;
  52. firstFrame=true;
  53. if (!initted)
  54. {
  55. /* clip table */
  56. clp=&clp_table[384];
  57. for (int i=-384; i<640; i++)
  58. clp[i] = (i<0) ? 0 : ((i>255) ? 255 : i);
  59. initted=true;
  60. }
  61. idct.init();
  62. }
  63. Decoder::~Decoder()
  64. {
  65. for (int cc=0; cc<3; cc++)
  66. {
  67. free(refframe[cc]);
  68. free(oldrefframe[cc]);
  69. free(edgeframeorig[cc]);
  70. }
  71. }
  72. #define ROUNDUP16(size) (((size)+15) & ~15)
  73. int Decoder::init()
  74. {
  75. int cc;
  76. unsigned int size;
  77. mb_width = (horizontal_size+15)/16;
  78. mb_height = (vertical_size +15)/16;
  79. coded_picture_width = ROUNDUP16(horizontal_size);
  80. coded_picture_height = ROUNDUP16(vertical_size);
  81. chrom_width = coded_picture_width>>1;
  82. chrom_height = coded_picture_height>>1;
  83. if (coded_picture_width >= (65536 - 64)
  84. || coded_picture_height >= (65536 - 64))
  85. return 1;
  86. for (cc=0; cc<3; cc++)
  87. {
  88. if (cc==0)
  89. size = coded_picture_width*coded_picture_height;
  90. else
  91. size = chrom_width*chrom_height;
  92. refframe[cc] = (unsigned char *)malloc(size);
  93. oldrefframe[cc] = (unsigned char *)malloc(size);
  94. }
  95. for (cc=0; cc<3; cc++)
  96. {
  97. if (cc==0)
  98. {
  99. size = (coded_picture_width+64)*(coded_picture_height+64);
  100. edgeframeorig[cc] = (unsigned char *)malloc(size);
  101. edgeframe[cc] = edgeframeorig[cc] + (coded_picture_width+64) * 32 + 32;
  102. }
  103. else
  104. {
  105. size = (chrom_width+32)*(chrom_height+32);
  106. edgeframeorig[cc] = (unsigned char *)malloc(size);
  107. edgeframe[cc] = edgeframeorig[cc] + (chrom_width+32) * 16 + 16;
  108. }
  109. }
  110. return 0;
  111. }