Decoder.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #pragma once
  2. #include <bfc/platform/types.h>
  3. #include "BitReader.h"
  4. #include "IDCT.h"
  5. #include "IDCTRef.h"
  6. #include "lib.h"
  7. /* this is necessary for the max resolution 16CIF */
  8. #define MBC 88
  9. #define MBR 72
  10. #define PSC 1
  11. #define PSC_LENGTH 17
  12. #define SE_CODE 31
  13. #define MODE_INTER 0
  14. #define MODE_INTER_Q 1
  15. #define MODE_INTER4V 2
  16. #define MODE_INTRA 3
  17. #define MODE_INTRA_Q 4
  18. #define MODE_INTER4V_Q 5
  19. #define PBMODE_NORMAL 0
  20. #define PBMODE_MVDB 1
  21. #define PBMODE_CBPB_MVDB 2
  22. #define ESCAPE 7167
  23. #define ESCAPE_INDEX 102
  24. #define EP_FORWARD_PREDICTION 0
  25. #define EI_EP_UPWARD_PREDICTION 1
  26. #define EP_BIDIRECTIONAL_PREDICTION 2
  27. #define EI_EP_INTRA_PREDICTION 3
  28. #define MAX_LAYERS 2
  29. /* picture types */
  30. #define PCT_INTRA 0
  31. #define PCT_INTER 1
  32. #define PCT_DISPOSABLE_INTER 2
  33. //#define PCT_IPB 2
  34. #define PCT_B 3
  35. #define ON 1
  36. #define OFF 0
  37. #define YES 1
  38. #define NO 0
  39. #define B_EI_EP_STUFFING 5
  40. #define INVALID_MBTYPE 255
  41. #define B_DIRECT_PREDICTION 0
  42. #define B_FORWARD_PREDICTION 1
  43. #define B_BACKWARD_PREDICTION 2
  44. #define B_BIDIRECTIONAL_PREDICTION 3
  45. #define B_INTRA_PREDICTION 4
  46. #define SF_SQCIF 1 /* 001 */
  47. #define SF_QCIF 2 /* 010 */
  48. #define SF_CIF 3 /* 011 */
  49. #define SF_4CIF 4 /* 100 */
  50. #define SF_16CIF 5 /* 101 */
  51. /* this is necessary for the max resolution 16CIF */
  52. #define MBC 88
  53. #define MBR 72
  54. #define NO_VEC 999
  55. typedef unsigned char *Frame[3];
  56. class Decoder
  57. {
  58. public:
  59. Decoder();
  60. ~Decoder();
  61. int init();
  62. void getpicture(Frame frame);
  63. int getheader();
  64. int DecodeFrame(YV12_PLANES *yv12, int *width, int *height, int *keyframe);
  65. static unsigned char *clp;
  66. BitReader buffer;
  67. private:
  68. void reconstruct(int bx, int by, int mode);
  69. void get_I_P_MBs();
  70. void horiz_edge_filter(unsigned char *rec, int width, int height, int chr);
  71. void vert_edge_filter(unsigned char *rec, int width, int height, int chr);
  72. void edge_filter(unsigned char *lum, unsigned char *Cb, unsigned char *Cr, int width, int height);
  73. void vert_post_filter(unsigned char *rec, int width, int height, int chr);
  74. void horiz_post_filter(unsigned char *rec, int width, int height, int chr);
  75. void PostFilter(unsigned char *lum, unsigned char *Cb, unsigned char *Cr,int width, int height);
  76. void addblock(int comp, int bx, int by, int addflag);
  77. int find_pmv(int x, int y, int block, int comp);
  78. void getpicturehdr();
  79. void getblock(int comp, int mode);
  80. void clearblock(int comp);
  81. void startcode();
  82. /* vlc */
  83. int getTMNMV(void);
  84. int getMCBPC(void);
  85. int getMBTYPE (int *cbp_present, int *quant_present);
  86. int getMCBPCintra(void);
  87. int getCBPY(void);
  88. private:
  89. Frame refframe, oldrefframe, newframe;
  90. Frame edgeframe, edgeframeorig;
  91. int MV[2][5][MBR+1][MBC+2];
  92. int modemap[MBR+1][MBC+2];
  93. int coded_map[MBR + 1][MBC + 1];
  94. int quant_map[MBR + 1][MBC + 1];
  95. unsigned int horizontal_size,vertical_size,mb_width,mb_height;
  96. unsigned int coded_picture_width, coded_picture_height;
  97. unsigned int chrom_width,chrom_height;
  98. int pict_type;
  99. int fault;
  100. int deblock;
  101. int refidct;
  102. int quant;
  103. int escapemode;
  104. bool firstFrame;
  105. IDCT idct;
  106. /* block data */
  107. short block[12][64];
  108. static bool initted;
  109. static unsigned char clp_table[1024];
  110. };