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.

540 lines
19KB

  1. /*
  2. * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
  3. * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file cavs.c
  23. * Chinese AVS video (AVS1-P2, JiZhun profile) decoder
  24. * @author Stefan Gehrer <stefan.gehrer@gmx.de>
  25. */
  26. #include "avcodec.h"
  27. #include "bitstream.h"
  28. #include "golomb.h"
  29. #include "cavs.h"
  30. #include "cavsdata.h"
  31. /*****************************************************************************
  32. *
  33. * in-loop deblocking filter
  34. *
  35. ****************************************************************************/
  36. static inline int get_bs(vector_t *mvP, vector_t *mvQ, int b) {
  37. if((mvP->ref == REF_INTRA) || (mvQ->ref == REF_INTRA))
  38. return 2;
  39. if( (abs(mvP->x - mvQ->x) >= 4) || (abs(mvP->y - mvQ->y) >= 4) )
  40. return 1;
  41. if(b){
  42. mvP += MV_BWD_OFFS;
  43. mvQ += MV_BWD_OFFS;
  44. if( (abs(mvP->x - mvQ->x) >= 4) || (abs(mvP->y - mvQ->y) >= 4) )
  45. return 1;
  46. }else{
  47. if(mvP->ref != mvQ->ref)
  48. return 1;
  49. }
  50. return 0;
  51. }
  52. #define SET_PARAMS \
  53. alpha = alpha_tab[av_clip(qp_avg + h->alpha_offset,0,63)]; \
  54. beta = beta_tab[av_clip(qp_avg + h->beta_offset, 0,63)]; \
  55. tc = tc_tab[av_clip(qp_avg + h->alpha_offset,0,63)];
  56. /**
  57. * in-loop deblocking filter for a single macroblock
  58. *
  59. * boundary strength (bs) mapping:
  60. *
  61. * --4---5--
  62. * 0 2 |
  63. * | 6 | 7 |
  64. * 1 3 |
  65. * ---------
  66. *
  67. */
  68. void ff_cavs_filter(AVSContext *h, enum mb_t mb_type) {
  69. DECLARE_ALIGNED_8(uint8_t, bs[8]);
  70. int qp_avg, alpha, beta, tc;
  71. int i;
  72. /* save un-deblocked lines */
  73. h->topleft_border_y = h->top_border_y[h->mbx*16+15];
  74. h->topleft_border_u = h->top_border_u[h->mbx*10+8];
  75. h->topleft_border_v = h->top_border_v[h->mbx*10+8];
  76. memcpy(&h->top_border_y[h->mbx*16], h->cy + 15* h->l_stride,16);
  77. memcpy(&h->top_border_u[h->mbx*10+1], h->cu + 7* h->c_stride,8);
  78. memcpy(&h->top_border_v[h->mbx*10+1], h->cv + 7* h->c_stride,8);
  79. for(i=0;i<8;i++) {
  80. h->left_border_y[i*2+1] = *(h->cy + 15 + (i*2+0)*h->l_stride);
  81. h->left_border_y[i*2+2] = *(h->cy + 15 + (i*2+1)*h->l_stride);
  82. h->left_border_u[i+1] = *(h->cu + 7 + i*h->c_stride);
  83. h->left_border_v[i+1] = *(h->cv + 7 + i*h->c_stride);
  84. }
  85. if(!h->loop_filter_disable) {
  86. /* determine bs */
  87. if(mb_type == I_8X8)
  88. *((uint64_t *)bs) = 0x0202020202020202ULL;
  89. else{
  90. *((uint64_t *)bs) = 0;
  91. if(ff_cavs_partition_flags[mb_type] & SPLITV){
  92. bs[2] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X1], mb_type > P_8X8);
  93. bs[3] = get_bs(&h->mv[MV_FWD_X2], &h->mv[MV_FWD_X3], mb_type > P_8X8);
  94. }
  95. if(ff_cavs_partition_flags[mb_type] & SPLITH){
  96. bs[6] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X2], mb_type > P_8X8);
  97. bs[7] = get_bs(&h->mv[MV_FWD_X1], &h->mv[MV_FWD_X3], mb_type > P_8X8);
  98. }
  99. bs[0] = get_bs(&h->mv[MV_FWD_A1], &h->mv[MV_FWD_X0], mb_type > P_8X8);
  100. bs[1] = get_bs(&h->mv[MV_FWD_A3], &h->mv[MV_FWD_X2], mb_type > P_8X8);
  101. bs[4] = get_bs(&h->mv[MV_FWD_B2], &h->mv[MV_FWD_X0], mb_type > P_8X8);
  102. bs[5] = get_bs(&h->mv[MV_FWD_B3], &h->mv[MV_FWD_X1], mb_type > P_8X8);
  103. }
  104. if( *((uint64_t *)bs) ) {
  105. if(h->flags & A_AVAIL) {
  106. qp_avg = (h->qp + h->left_qp + 1) >> 1;
  107. SET_PARAMS;
  108. h->s.dsp.cavs_filter_lv(h->cy,h->l_stride,alpha,beta,tc,bs[0],bs[1]);
  109. h->s.dsp.cavs_filter_cv(h->cu,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
  110. h->s.dsp.cavs_filter_cv(h->cv,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
  111. }
  112. qp_avg = h->qp;
  113. SET_PARAMS;
  114. h->s.dsp.cavs_filter_lv(h->cy + 8,h->l_stride,alpha,beta,tc,bs[2],bs[3]);
  115. h->s.dsp.cavs_filter_lh(h->cy + 8*h->l_stride,h->l_stride,alpha,beta,tc,
  116. bs[6],bs[7]);
  117. if(h->flags & B_AVAIL) {
  118. qp_avg = (h->qp + h->top_qp[h->mbx] + 1) >> 1;
  119. SET_PARAMS;
  120. h->s.dsp.cavs_filter_lh(h->cy,h->l_stride,alpha,beta,tc,bs[4],bs[5]);
  121. h->s.dsp.cavs_filter_ch(h->cu,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
  122. h->s.dsp.cavs_filter_ch(h->cv,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
  123. }
  124. }
  125. }
  126. h->left_qp = h->qp;
  127. h->top_qp[h->mbx] = h->qp;
  128. }
  129. #undef SET_PARAMS
  130. /*****************************************************************************
  131. *
  132. * spatial intra prediction
  133. *
  134. ****************************************************************************/
  135. static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  136. int y;
  137. uint64_t a = unaligned64(&top[1]);
  138. for(y=0;y<8;y++) {
  139. *((uint64_t *)(d+y*stride)) = a;
  140. }
  141. }
  142. static void intra_pred_horiz(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  143. int y;
  144. uint64_t a;
  145. for(y=0;y<8;y++) {
  146. a = left[y+1] * 0x0101010101010101ULL;
  147. *((uint64_t *)(d+y*stride)) = a;
  148. }
  149. }
  150. static void intra_pred_dc_128(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  151. int y;
  152. uint64_t a = 0x8080808080808080ULL;
  153. for(y=0;y<8;y++)
  154. *((uint64_t *)(d+y*stride)) = a;
  155. }
  156. static void intra_pred_plane(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  157. int x,y,ia;
  158. int ih = 0;
  159. int iv = 0;
  160. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  161. for(x=0; x<4; x++) {
  162. ih += (x+1)*(top[5+x]-top[3-x]);
  163. iv += (x+1)*(left[5+x]-left[3-x]);
  164. }
  165. ia = (top[8]+left[8])<<4;
  166. ih = (17*ih+16)>>5;
  167. iv = (17*iv+16)>>5;
  168. for(y=0; y<8; y++)
  169. for(x=0; x<8; x++)
  170. d[y*stride+x] = cm[(ia+(x-3)*ih+(y-3)*iv+16)>>5];
  171. }
  172. #define LOWPASS(ARRAY,INDEX) \
  173. (( ARRAY[(INDEX)-1] + 2*ARRAY[(INDEX)] + ARRAY[(INDEX)+1] + 2) >> 2)
  174. static void intra_pred_lp(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  175. int x,y;
  176. for(y=0; y<8; y++)
  177. for(x=0; x<8; x++)
  178. d[y*stride+x] = (LOWPASS(top,x+1) + LOWPASS(left,y+1)) >> 1;
  179. }
  180. static void intra_pred_down_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  181. int x,y;
  182. for(y=0; y<8; y++)
  183. for(x=0; x<8; x++)
  184. d[y*stride+x] = (LOWPASS(top,x+y+2) + LOWPASS(left,x+y+2)) >> 1;
  185. }
  186. static void intra_pred_down_right(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  187. int x,y;
  188. for(y=0; y<8; y++)
  189. for(x=0; x<8; x++)
  190. if(x==y)
  191. d[y*stride+x] = (left[1]+2*top[0]+top[1]+2)>>2;
  192. else if(x>y)
  193. d[y*stride+x] = LOWPASS(top,x-y);
  194. else
  195. d[y*stride+x] = LOWPASS(left,y-x);
  196. }
  197. static void intra_pred_lp_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  198. int x,y;
  199. for(y=0; y<8; y++)
  200. for(x=0; x<8; x++)
  201. d[y*stride+x] = LOWPASS(left,y+1);
  202. }
  203. static void intra_pred_lp_top(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
  204. int x,y;
  205. for(y=0; y<8; y++)
  206. for(x=0; x<8; x++)
  207. d[y*stride+x] = LOWPASS(top,x+1);
  208. }
  209. #undef LOWPASS
  210. /*****************************************************************************
  211. *
  212. * motion compensation
  213. *
  214. ****************************************************************************/
  215. static inline void mc_dir_part(AVSContext *h,Picture *pic,int square,
  216. int chroma_height,int delta,int list,uint8_t *dest_y,
  217. uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset,
  218. int src_y_offset,qpel_mc_func *qpix_op,
  219. h264_chroma_mc_func chroma_op,vector_t *mv){
  220. MpegEncContext * const s = &h->s;
  221. const int mx= mv->x + src_x_offset*8;
  222. const int my= mv->y + src_y_offset*8;
  223. const int luma_xy= (mx&3) + ((my&3)<<2);
  224. uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->l_stride;
  225. uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->c_stride;
  226. uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->c_stride;
  227. int extra_width= 0; //(s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;
  228. int extra_height= extra_width;
  229. int emu=0;
  230. const int full_mx= mx>>2;
  231. const int full_my= my>>2;
  232. const int pic_width = 16*h->mb_width;
  233. const int pic_height = 16*h->mb_height;
  234. if(!pic->data[0])
  235. return;
  236. if(mx&7) extra_width -= 3;
  237. if(my&7) extra_height -= 3;
  238. if( full_mx < 0-extra_width
  239. || full_my < 0-extra_height
  240. || full_mx + 16/*FIXME*/ > pic_width + extra_width
  241. || full_my + 16/*FIXME*/ > pic_height + extra_height){
  242. ff_emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride,
  243. 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
  244. src_y= s->edge_emu_buffer + 2 + 2*h->l_stride;
  245. emu=1;
  246. }
  247. qpix_op[luma_xy](dest_y, src_y, h->l_stride); //FIXME try variable height perhaps?
  248. if(!square){
  249. qpix_op[luma_xy](dest_y + delta, src_y + delta, h->l_stride);
  250. }
  251. if(emu){
  252. ff_emulated_edge_mc(s->edge_emu_buffer, src_cb, h->c_stride,
  253. 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
  254. src_cb= s->edge_emu_buffer;
  255. }
  256. chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7);
  257. if(emu){
  258. ff_emulated_edge_mc(s->edge_emu_buffer, src_cr, h->c_stride,
  259. 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
  260. src_cr= s->edge_emu_buffer;
  261. }
  262. chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx&7, my&7);
  263. }
  264. static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int delta,
  265. uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr,
  266. int x_offset, int y_offset,qpel_mc_func *qpix_put,
  267. h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg,
  268. h264_chroma_mc_func chroma_avg, vector_t *mv){
  269. qpel_mc_func *qpix_op= qpix_put;
  270. h264_chroma_mc_func chroma_op= chroma_put;
  271. dest_y += 2*x_offset + 2*y_offset*h->l_stride;
  272. dest_cb += x_offset + y_offset*h->c_stride;
  273. dest_cr += x_offset + y_offset*h->c_stride;
  274. x_offset += 8*h->mbx;
  275. y_offset += 8*h->mby;
  276. if(mv->ref >= 0){
  277. Picture *ref= &h->DPB[mv->ref];
  278. mc_dir_part(h, ref, square, chroma_height, delta, 0,
  279. dest_y, dest_cb, dest_cr, x_offset, y_offset,
  280. qpix_op, chroma_op, mv);
  281. qpix_op= qpix_avg;
  282. chroma_op= chroma_avg;
  283. }
  284. if((mv+MV_BWD_OFFS)->ref >= 0){
  285. Picture *ref= &h->DPB[0];
  286. mc_dir_part(h, ref, square, chroma_height, delta, 1,
  287. dest_y, dest_cb, dest_cr, x_offset, y_offset,
  288. qpix_op, chroma_op, mv+MV_BWD_OFFS);
  289. }
  290. }
  291. void ff_cavs_inter(AVSContext *h, enum mb_t mb_type) {
  292. if(ff_cavs_partition_flags[mb_type] == 0){ // 16x16
  293. mc_part_std(h, 1, 8, 0, h->cy, h->cu, h->cv, 0, 0,
  294. h->s.dsp.put_cavs_qpel_pixels_tab[0],
  295. h->s.dsp.put_h264_chroma_pixels_tab[0],
  296. h->s.dsp.avg_cavs_qpel_pixels_tab[0],
  297. h->s.dsp.avg_h264_chroma_pixels_tab[0],&h->mv[MV_FWD_X0]);
  298. }else{
  299. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 0,
  300. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  301. h->s.dsp.put_h264_chroma_pixels_tab[1],
  302. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  303. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]);
  304. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 0,
  305. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  306. h->s.dsp.put_h264_chroma_pixels_tab[1],
  307. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  308. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]);
  309. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 4,
  310. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  311. h->s.dsp.put_h264_chroma_pixels_tab[1],
  312. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  313. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]);
  314. mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 4,
  315. h->s.dsp.put_cavs_qpel_pixels_tab[1],
  316. h->s.dsp.put_h264_chroma_pixels_tab[1],
  317. h->s.dsp.avg_cavs_qpel_pixels_tab[1],
  318. h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]);
  319. }
  320. }
  321. /*****************************************************************************
  322. *
  323. * motion vector prediction
  324. *
  325. ****************************************************************************/
  326. static inline void scale_mv(AVSContext *h, int *d_x, int *d_y, vector_t *src, int distp) {
  327. int den = h->scale_den[src->ref];
  328. *d_x = (src->x*distp*den + 256 + (src->x>>31)) >> 9;
  329. *d_y = (src->y*distp*den + 256 + (src->y>>31)) >> 9;
  330. }
  331. static inline void mv_pred_median(AVSContext *h, vector_t *mvP, vector_t *mvA, vector_t *mvB, vector_t *mvC) {
  332. int ax, ay, bx, by, cx, cy;
  333. int len_ab, len_bc, len_ca, len_mid;
  334. /* scale candidates according to their temporal span */
  335. scale_mv(h, &ax, &ay, mvA, mvP->dist);
  336. scale_mv(h, &bx, &by, mvB, mvP->dist);
  337. scale_mv(h, &cx, &cy, mvC, mvP->dist);
  338. /* find the geometrical median of the three candidates */
  339. len_ab = abs(ax - bx) + abs(ay - by);
  340. len_bc = abs(bx - cx) + abs(by - cy);
  341. len_ca = abs(cx - ax) + abs(cy - ay);
  342. len_mid = mid_pred(len_ab, len_bc, len_ca);
  343. if(len_mid == len_ab) {
  344. mvP->x = cx;
  345. mvP->y = cy;
  346. } else if(len_mid == len_bc) {
  347. mvP->x = ax;
  348. mvP->y = ay;
  349. } else {
  350. mvP->x = bx;
  351. mvP->y = by;
  352. }
  353. }
  354. void ff_cavs_mv(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC,
  355. enum mv_pred_t mode, enum block_t size, int ref) {
  356. vector_t *mvP = &h->mv[nP];
  357. vector_t *mvA = &h->mv[nP-1];
  358. vector_t *mvB = &h->mv[nP-4];
  359. vector_t *mvC = &h->mv[nC];
  360. const vector_t *mvP2 = NULL;
  361. mvP->ref = ref;
  362. mvP->dist = h->dist[mvP->ref];
  363. if(mvC->ref == NOT_AVAIL)
  364. mvC = &h->mv[nP-5]; // set to top-left (mvD)
  365. if((mode == MV_PRED_PSKIP) &&
  366. ((mvA->ref == NOT_AVAIL) || (mvB->ref == NOT_AVAIL) ||
  367. ((mvA->x | mvA->y | mvA->ref) == 0) ||
  368. ((mvB->x | mvB->y | mvB->ref) == 0) )) {
  369. mvP2 = &ff_cavs_un_mv;
  370. /* if there is only one suitable candidate, take it */
  371. } else if((mvA->ref >= 0) && (mvB->ref < 0) && (mvC->ref < 0)) {
  372. mvP2= mvA;
  373. } else if((mvA->ref < 0) && (mvB->ref >= 0) && (mvC->ref < 0)) {
  374. mvP2= mvB;
  375. } else if((mvA->ref < 0) && (mvB->ref < 0) && (mvC->ref >= 0)) {
  376. mvP2= mvC;
  377. } else if(mode == MV_PRED_LEFT && mvA->ref == ref){
  378. mvP2= mvA;
  379. } else if(mode == MV_PRED_TOP && mvB->ref == ref){
  380. mvP2= mvB;
  381. } else if(mode == MV_PRED_TOPRIGHT && mvC->ref == ref){
  382. mvP2= mvC;
  383. }
  384. if(mvP2){
  385. mvP->x = mvP2->x;
  386. mvP->y = mvP2->y;
  387. }else
  388. mv_pred_median(h, mvP, mvA, mvB, mvC);
  389. if(mode < MV_PRED_PSKIP) {
  390. mvP->x += get_se_golomb(&h->s.gb);
  391. mvP->y += get_se_golomb(&h->s.gb);
  392. }
  393. set_mvs(mvP,size);
  394. }
  395. /*****************************************************************************
  396. *
  397. * frame level
  398. *
  399. ****************************************************************************/
  400. void ff_cavs_init_pic(AVSContext *h) {
  401. int i;
  402. /* clear some predictors */
  403. for(i=0;i<=20;i+=4)
  404. h->mv[i] = ff_cavs_un_mv;
  405. h->mv[MV_BWD_X0] = ff_cavs_dir_mv;
  406. set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
  407. h->mv[MV_FWD_X0] = ff_cavs_dir_mv;
  408. set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
  409. h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
  410. h->cy = h->picture.data[0];
  411. h->cu = h->picture.data[1];
  412. h->cv = h->picture.data[2];
  413. h->l_stride = h->picture.linesize[0];
  414. h->c_stride = h->picture.linesize[1];
  415. h->luma_scan[2] = 8*h->l_stride;
  416. h->luma_scan[3] = 8*h->l_stride+8;
  417. h->mbx = h->mby = 0;
  418. h->flags = 0;
  419. }
  420. /*****************************************************************************
  421. *
  422. * headers and interface
  423. *
  424. ****************************************************************************/
  425. /**
  426. * some predictions require data from the top-neighbouring macroblock.
  427. * this data has to be stored for one complete row of macroblocks
  428. * and this storage space is allocated here
  429. */
  430. void ff_cavs_init_top_lines(AVSContext *h) {
  431. /* alloc top line of predictors */
  432. h->top_qp = av_malloc( h->mb_width);
  433. h->top_mv[0] = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
  434. h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(vector_t));
  435. h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y));
  436. h->top_border_y = av_malloc((h->mb_width+1)*16);
  437. h->top_border_u = av_malloc((h->mb_width)*10);
  438. h->top_border_v = av_malloc((h->mb_width)*10);
  439. /* alloc space for co-located MVs and types */
  440. h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(vector_t));
  441. h->col_type_base = av_malloc(h->mb_width*h->mb_height);
  442. h->block = av_mallocz(64*sizeof(DCTELEM));
  443. }
  444. int ff_cavs_init(AVCodecContext *avctx) {
  445. AVSContext *h = avctx->priv_data;
  446. MpegEncContext * const s = &h->s;
  447. MPV_decode_defaults(s);
  448. s->avctx = avctx;
  449. avctx->pix_fmt= PIX_FMT_YUV420P;
  450. h->luma_scan[0] = 0;
  451. h->luma_scan[1] = 8;
  452. h->intra_pred_l[ INTRA_L_VERT] = intra_pred_vert;
  453. h->intra_pred_l[ INTRA_L_HORIZ] = intra_pred_horiz;
  454. h->intra_pred_l[ INTRA_L_LP] = intra_pred_lp;
  455. h->intra_pred_l[ INTRA_L_DOWN_LEFT] = intra_pred_down_left;
  456. h->intra_pred_l[INTRA_L_DOWN_RIGHT] = intra_pred_down_right;
  457. h->intra_pred_l[ INTRA_L_LP_LEFT] = intra_pred_lp_left;
  458. h->intra_pred_l[ INTRA_L_LP_TOP] = intra_pred_lp_top;
  459. h->intra_pred_l[ INTRA_L_DC_128] = intra_pred_dc_128;
  460. h->intra_pred_c[ INTRA_C_LP] = intra_pred_lp;
  461. h->intra_pred_c[ INTRA_C_HORIZ] = intra_pred_horiz;
  462. h->intra_pred_c[ INTRA_C_VERT] = intra_pred_vert;
  463. h->intra_pred_c[ INTRA_C_PLANE] = intra_pred_plane;
  464. h->intra_pred_c[ INTRA_C_LP_LEFT] = intra_pred_lp_left;
  465. h->intra_pred_c[ INTRA_C_LP_TOP] = intra_pred_lp_top;
  466. h->intra_pred_c[ INTRA_C_DC_128] = intra_pred_dc_128;
  467. h->mv[ 7] = ff_cavs_un_mv;
  468. h->mv[19] = ff_cavs_un_mv;
  469. return 0;
  470. }
  471. int ff_cavs_end(AVCodecContext *avctx) {
  472. AVSContext *h = avctx->priv_data;
  473. av_free(h->top_qp);
  474. av_free(h->top_mv[0]);
  475. av_free(h->top_mv[1]);
  476. av_free(h->top_pred_Y);
  477. av_free(h->top_border_y);
  478. av_free(h->top_border_u);
  479. av_free(h->top_border_v);
  480. av_free(h->col_mv);
  481. av_free(h->col_type_base);
  482. av_free(h->block);
  483. return 0;
  484. }