You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

247 lines
7.9KB

  1. /*
  2. * H263 internal header
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_H263_H
  21. #define AVCODEC_H263_H
  22. // The defines below define the number of bits that are read at once for
  23. // reading vlc values. Changing these may improve speed and data cache needs
  24. // be aware though that decreasing them may need the number of stages that is
  25. // passed to get_vlc* to be increased.
  26. #define INTRA_MCBPC_VLC_BITS 6
  27. #define INTER_MCBPC_VLC_BITS 7
  28. #define CBPY_VLC_BITS 6
  29. #define TEX_VLC_BITS 9
  30. extern const AVRational ff_h263_pixel_aspect[16];
  31. extern const uint8_t ff_h263_cbpy_tab[16][2];
  32. extern const uint8_t cbpc_b_tab[4][2];
  33. extern const uint8_t mvtab[33][2];
  34. extern const uint8_t ff_h263_intra_MCBPC_code[9];
  35. extern const uint8_t ff_h263_intra_MCBPC_bits[9];
  36. extern const uint8_t ff_h263_inter_MCBPC_code[28];
  37. extern const uint8_t ff_h263_inter_MCBPC_bits[28];
  38. extern const uint8_t h263_mbtype_b_tab[15][2];
  39. extern VLC ff_h263_intra_MCBPC_vlc;
  40. extern VLC ff_h263_inter_MCBPC_vlc;
  41. extern VLC ff_h263_cbpy_vlc;
  42. extern RLTable ff_h263_rl_inter;
  43. extern RLTable rl_intra_aic;
  44. extern const uint16_t h263_format[8][2];
  45. extern const uint8_t modified_quant_tab[2][32];
  46. extern uint16_t ff_mba_max[6];
  47. extern uint8_t ff_mba_length[7];
  48. extern uint8_t ff_h263_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
  49. int h263_decode_motion(MpegEncContext * s, int pred, int f_code);
  50. av_const int ff_h263_aspect_to_info(AVRational aspect);
  51. int ff_h263_decode_init(AVCodecContext *avctx);
  52. int ff_h263_decode_frame(AVCodecContext *avctx,
  53. void *data, int *data_size,
  54. AVPacket *avpkt);
  55. int ff_h263_decode_end(AVCodecContext *avctx);
  56. void h263_encode_mb(MpegEncContext *s,
  57. DCTELEM block[6][64],
  58. int motion_x, int motion_y);
  59. void h263_encode_picture_header(MpegEncContext *s, int picture_number);
  60. void h263_encode_gob_header(MpegEncContext * s, int mb_line);
  61. int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir,
  62. int *px, int *py);
  63. void h263_encode_init(MpegEncContext *s);
  64. void h263_decode_init_vlc(MpegEncContext *s);
  65. int h263_decode_picture_header(MpegEncContext *s);
  66. int ff_h263_decode_gob_header(MpegEncContext *s);
  67. void ff_h263_update_motion_val(MpegEncContext * s);
  68. void ff_h263_loop_filter(MpegEncContext * s);
  69. void ff_set_qscale(MpegEncContext * s, int qscale);
  70. int ff_h263_decode_mba(MpegEncContext *s);
  71. void ff_h263_encode_mba(MpegEncContext *s);
  72. void ff_init_qscale_tab(MpegEncContext *s);
  73. int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr);
  74. void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n);
  75. /**
  76. * Prints picture info if FF_DEBUG_PICT_INFO is set.
  77. */
  78. void ff_h263_show_pict_info(MpegEncContext *s);
  79. int ff_intel_h263_decode_picture_header(MpegEncContext *s);
  80. int ff_h263_decode_mb(MpegEncContext *s,
  81. DCTELEM block[6][64]);
  82. /**
  83. * Returns the value of the 3bit "source format" syntax element.
  84. * that represents some standard picture dimensions or indicates that
  85. * width&height are explicitly stored later.
  86. */
  87. int av_const h263_get_picture_format(int width, int height);
  88. void ff_clean_h263_qscales(MpegEncContext *s);
  89. int ff_h263_resync(MpegEncContext *s);
  90. const uint8_t *ff_h263_find_resync_marker(const uint8_t *p, const uint8_t *end);
  91. int ff_h263_get_gob_height(MpegEncContext *s);
  92. void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code);
  93. static inline int h263_get_motion_length(MpegEncContext * s, int val, int f_code){
  94. int l, bit_size, code;
  95. if (val == 0) {
  96. return mvtab[0][1];
  97. } else {
  98. bit_size = f_code - 1;
  99. /* modulo encoding */
  100. l= INT_BIT - 6 - bit_size;
  101. val = (val<<l)>>l;
  102. val--;
  103. code = (val >> bit_size) + 1;
  104. return mvtab[code][1] + 1 + bit_size;
  105. }
  106. }
  107. static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y, int f_code){
  108. if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
  109. skip_put_bits(&s->pb,
  110. h263_get_motion_length(s, x, f_code)
  111. +h263_get_motion_length(s, y, f_code));
  112. }else{
  113. ff_h263_encode_motion(s, x, f_code);
  114. ff_h263_encode_motion(s, y, f_code);
  115. }
  116. }
  117. static inline int get_p_cbp(MpegEncContext * s,
  118. DCTELEM block[6][64],
  119. int motion_x, int motion_y){
  120. int cbp, i;
  121. if(s->flags & CODEC_FLAG_CBP_RD){
  122. int best_cbpy_score= INT_MAX;
  123. int best_cbpc_score= INT_MAX;
  124. int cbpc = (-1), cbpy= (-1);
  125. const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0);
  126. const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
  127. for(i=0; i<4; i++){
  128. int score= ff_h263_inter_MCBPC_bits[i + offset] * lambda;
  129. if(i&1) score += s->coded_score[5];
  130. if(i&2) score += s->coded_score[4];
  131. if(score < best_cbpc_score){
  132. best_cbpc_score= score;
  133. cbpc= i;
  134. }
  135. }
  136. for(i=0; i<16; i++){
  137. int score= ff_h263_cbpy_tab[i ^ 0xF][1] * lambda;
  138. if(i&1) score += s->coded_score[3];
  139. if(i&2) score += s->coded_score[2];
  140. if(i&4) score += s->coded_score[1];
  141. if(i&8) score += s->coded_score[0];
  142. if(score < best_cbpy_score){
  143. best_cbpy_score= score;
  144. cbpy= i;
  145. }
  146. }
  147. cbp= cbpc + 4*cbpy;
  148. if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){
  149. if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0)
  150. cbp= 0;
  151. }
  152. for (i = 0; i < 6; i++) {
  153. if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){
  154. s->block_last_index[i]= -1;
  155. s->dsp.clear_block(s->block[i]);
  156. }
  157. }
  158. }else{
  159. cbp= 0;
  160. for (i = 0; i < 6; i++) {
  161. if (s->block_last_index[i] >= 0)
  162. cbp |= 1 << (5 - i);
  163. }
  164. }
  165. return cbp;
  166. }
  167. static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64],
  168. int motion_x, int motion_y, int mb_type){
  169. int cbp=0, i;
  170. if(s->flags & CODEC_FLAG_CBP_RD){
  171. int score=0;
  172. const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
  173. for(i=0; i<6; i++){
  174. if(s->coded_score[i] < 0){
  175. score += s->coded_score[i];
  176. cbp |= 1 << (5 - i);
  177. }
  178. }
  179. if(cbp){
  180. int zero_score= -6;
  181. if ((motion_x | motion_y | s->dquant | mb_type) == 0){
  182. zero_score-= 4; //2*MV + mb_type + cbp bit
  183. }
  184. zero_score*= lambda;
  185. if(zero_score <= score){
  186. cbp=0;
  187. }
  188. }
  189. for (i = 0; i < 6; i++) {
  190. if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){
  191. s->block_last_index[i]= -1;
  192. s->dsp.clear_block(s->block[i]);
  193. }
  194. }
  195. }else{
  196. for (i = 0; i < 6; i++) {
  197. if (s->block_last_index[i] >= 0)
  198. cbp |= 1 << (5 - i);
  199. }
  200. }
  201. return cbp;
  202. }
  203. static inline void memsetw(short *tab, int val, int n)
  204. {
  205. int i;
  206. for(i=0;i<n;i++)
  207. tab[i] = val;
  208. }
  209. #endif