error_resilience.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. /*
  2. * Error resilience / concealment
  3. *
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file libavcodec/error_resilience.c
  24. * Error resilience / concealment.
  25. */
  26. #include <limits.h>
  27. #include "avcodec.h"
  28. #include "dsputil.h"
  29. #include "mpegvideo.h"
  30. static void decode_mb(MpegEncContext *s){
  31. s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize ) + s->mb_x * 16;
  32. s->dest[1] = s->current_picture.data[1] + (s->mb_y * 8 * s->uvlinesize) + s->mb_x * 8;
  33. s->dest[2] = s->current_picture.data[2] + (s->mb_y * 8 * s->uvlinesize) + s->mb_x * 8;
  34. MPV_decode_mb(s, s->block);
  35. }
  36. /**
  37. * replaces the current MB with a flat dc only version.
  38. */
  39. static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y)
  40. {
  41. int dc, dcu, dcv, y, i;
  42. for(i=0; i<4; i++){
  43. dc= s->dc_val[0][mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride];
  44. if(dc<0) dc=0;
  45. else if(dc>2040) dc=2040;
  46. for(y=0; y<8; y++){
  47. int x;
  48. for(x=0; x<8; x++){
  49. dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8;
  50. }
  51. }
  52. }
  53. dcu = s->dc_val[1][mb_x + mb_y*s->mb_stride];
  54. dcv = s->dc_val[2][mb_x + mb_y*s->mb_stride];
  55. if (dcu<0 ) dcu=0;
  56. else if(dcu>2040) dcu=2040;
  57. if (dcv<0 ) dcv=0;
  58. else if(dcv>2040) dcv=2040;
  59. for(y=0; y<8; y++){
  60. int x;
  61. for(x=0; x<8; x++){
  62. dest_cb[x + y*(s->uvlinesize)]= dcu/8;
  63. dest_cr[x + y*(s->uvlinesize)]= dcv/8;
  64. }
  65. }
  66. }
  67. static void filter181(int16_t *data, int width, int height, int stride){
  68. int x,y;
  69. /* horizontal filter */
  70. for(y=1; y<height-1; y++){
  71. int prev_dc= data[0 + y*stride];
  72. for(x=1; x<width-1; x++){
  73. int dc;
  74. dc= - prev_dc
  75. + data[x + y*stride]*8
  76. - data[x + 1 + y*stride];
  77. dc= (dc*10923 + 32768)>>16;
  78. prev_dc= data[x + y*stride];
  79. data[x + y*stride]= dc;
  80. }
  81. }
  82. /* vertical filter */
  83. for(x=1; x<width-1; x++){
  84. int prev_dc= data[x];
  85. for(y=1; y<height-1; y++){
  86. int dc;
  87. dc= - prev_dc
  88. + data[x + y *stride]*8
  89. - data[x + (y+1)*stride];
  90. dc= (dc*10923 + 32768)>>16;
  91. prev_dc= data[x + y*stride];
  92. data[x + y*stride]= dc;
  93. }
  94. }
  95. }
  96. /**
  97. * guess the dc of blocks which do not have an undamaged dc
  98. * @param w width in 8 pixel blocks
  99. * @param h height in 8 pixel blocks
  100. */
  101. static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, int is_luma){
  102. int b_x, b_y;
  103. for(b_y=0; b_y<h; b_y++){
  104. for(b_x=0; b_x<w; b_x++){
  105. int color[4]={1024,1024,1024,1024};
  106. int distance[4]={9999,9999,9999,9999};
  107. int mb_index, error, j;
  108. int64_t guess, weight_sum;
  109. mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;
  110. error= s->error_status_table[mb_index];
  111. if(IS_INTER(s->current_picture.mb_type[mb_index])) continue; //inter
  112. if(!(error&DC_ERROR)) continue; //dc-ok
  113. /* right block */
  114. for(j=b_x+1; j<w; j++){
  115. int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
  116. int error_j= s->error_status_table[mb_index_j];
  117. int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
  118. if(intra_j==0 || !(error_j&DC_ERROR)){
  119. color[0]= dc[j + b_y*stride];
  120. distance[0]= j-b_x;
  121. break;
  122. }
  123. }
  124. /* left block */
  125. for(j=b_x-1; j>=0; j--){
  126. int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
  127. int error_j= s->error_status_table[mb_index_j];
  128. int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
  129. if(intra_j==0 || !(error_j&DC_ERROR)){
  130. color[1]= dc[j + b_y*stride];
  131. distance[1]= b_x-j;
  132. break;
  133. }
  134. }
  135. /* bottom block */
  136. for(j=b_y+1; j<h; j++){
  137. int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
  138. int error_j= s->error_status_table[mb_index_j];
  139. int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
  140. if(intra_j==0 || !(error_j&DC_ERROR)){
  141. color[2]= dc[b_x + j*stride];
  142. distance[2]= j-b_y;
  143. break;
  144. }
  145. }
  146. /* top block */
  147. for(j=b_y-1; j>=0; j--){
  148. int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
  149. int error_j= s->error_status_table[mb_index_j];
  150. int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
  151. if(intra_j==0 || !(error_j&DC_ERROR)){
  152. color[3]= dc[b_x + j*stride];
  153. distance[3]= b_y-j;
  154. break;
  155. }
  156. }
  157. weight_sum=0;
  158. guess=0;
  159. for(j=0; j<4; j++){
  160. int64_t weight= 256*256*256*16/distance[j];
  161. guess+= weight*(int64_t)color[j];
  162. weight_sum+= weight;
  163. }
  164. guess= (guess + weight_sum/2) / weight_sum;
  165. dc[b_x + b_y*stride]= guess;
  166. }
  167. }
  168. }
  169. /**
  170. * simple horizontal deblocking filter used for error resilience
  171. * @param w width in 8 pixel blocks
  172. * @param h height in 8 pixel blocks
  173. */
  174. static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){
  175. int b_x, b_y;
  176. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  177. for(b_y=0; b_y<h; b_y++){
  178. for(b_x=0; b_x<w-1; b_x++){
  179. int y;
  180. int left_status = s->error_status_table[( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride];
  181. int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride];
  182. int left_intra= IS_INTRA(s->current_picture.mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]);
  183. int right_intra= IS_INTRA(s->current_picture.mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]);
  184. int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
  185. int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
  186. int offset= b_x*8 + b_y*stride*8;
  187. int16_t *left_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ( b_x <<(1-is_luma))];
  188. int16_t *right_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ((b_x+1)<<(1-is_luma))];
  189. if(!(left_damage||right_damage)) continue; // both undamaged
  190. if( (!left_intra) && (!right_intra)
  191. && FFABS(left_mv[0]-right_mv[0]) + FFABS(left_mv[1]+right_mv[1]) < 2) continue;
  192. for(y=0; y<8; y++){
  193. int a,b,c,d;
  194. a= dst[offset + 7 + y*stride] - dst[offset + 6 + y*stride];
  195. b= dst[offset + 8 + y*stride] - dst[offset + 7 + y*stride];
  196. c= dst[offset + 9 + y*stride] - dst[offset + 8 + y*stride];
  197. d= FFABS(b) - ((FFABS(a) + FFABS(c) + 1)>>1);
  198. d= FFMAX(d, 0);
  199. if(b<0) d= -d;
  200. if(d==0) continue;
  201. if(!(left_damage && right_damage))
  202. d= d*16/9;
  203. if(left_damage){
  204. dst[offset + 7 + y*stride] = cm[dst[offset + 7 + y*stride] + ((d*7)>>4)];
  205. dst[offset + 6 + y*stride] = cm[dst[offset + 6 + y*stride] + ((d*5)>>4)];
  206. dst[offset + 5 + y*stride] = cm[dst[offset + 5 + y*stride] + ((d*3)>>4)];
  207. dst[offset + 4 + y*stride] = cm[dst[offset + 4 + y*stride] + ((d*1)>>4)];
  208. }
  209. if(right_damage){
  210. dst[offset + 8 + y*stride] = cm[dst[offset + 8 + y*stride] - ((d*7)>>4)];
  211. dst[offset + 9 + y*stride] = cm[dst[offset + 9 + y*stride] - ((d*5)>>4)];
  212. dst[offset + 10+ y*stride] = cm[dst[offset +10 + y*stride] - ((d*3)>>4)];
  213. dst[offset + 11+ y*stride] = cm[dst[offset +11 + y*stride] - ((d*1)>>4)];
  214. }
  215. }
  216. }
  217. }
  218. }
  219. /**
  220. * simple vertical deblocking filter used for error resilience
  221. * @param w width in 8 pixel blocks
  222. * @param h height in 8 pixel blocks
  223. */
  224. static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){
  225. int b_x, b_y;
  226. uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
  227. for(b_y=0; b_y<h-1; b_y++){
  228. for(b_x=0; b_x<w; b_x++){
  229. int x;
  230. int top_status = s->error_status_table[(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride];
  231. int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride];
  232. int top_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]);
  233. int bottom_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]);
  234. int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
  235. int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
  236. int offset= b_x*8 + b_y*stride*8;
  237. int16_t *top_mv= s->current_picture.motion_val[0][s->b8_stride*( b_y <<(1-is_luma)) + (b_x<<(1-is_luma))];
  238. int16_t *bottom_mv= s->current_picture.motion_val[0][s->b8_stride*((b_y+1)<<(1-is_luma)) + (b_x<<(1-is_luma))];
  239. if(!(top_damage||bottom_damage)) continue; // both undamaged
  240. if( (!top_intra) && (!bottom_intra)
  241. && FFABS(top_mv[0]-bottom_mv[0]) + FFABS(top_mv[1]+bottom_mv[1]) < 2) continue;
  242. for(x=0; x<8; x++){
  243. int a,b,c,d;
  244. a= dst[offset + x + 7*stride] - dst[offset + x + 6*stride];
  245. b= dst[offset + x + 8*stride] - dst[offset + x + 7*stride];
  246. c= dst[offset + x + 9*stride] - dst[offset + x + 8*stride];
  247. d= FFABS(b) - ((FFABS(a) + FFABS(c)+1)>>1);
  248. d= FFMAX(d, 0);
  249. if(b<0) d= -d;
  250. if(d==0) continue;
  251. if(!(top_damage && bottom_damage))
  252. d= d*16/9;
  253. if(top_damage){
  254. dst[offset + x + 7*stride] = cm[dst[offset + x + 7*stride] + ((d*7)>>4)];
  255. dst[offset + x + 6*stride] = cm[dst[offset + x + 6*stride] + ((d*5)>>4)];
  256. dst[offset + x + 5*stride] = cm[dst[offset + x + 5*stride] + ((d*3)>>4)];
  257. dst[offset + x + 4*stride] = cm[dst[offset + x + 4*stride] + ((d*1)>>4)];
  258. }
  259. if(bottom_damage){
  260. dst[offset + x + 8*stride] = cm[dst[offset + x + 8*stride] - ((d*7)>>4)];
  261. dst[offset + x + 9*stride] = cm[dst[offset + x + 9*stride] - ((d*5)>>4)];
  262. dst[offset + x + 10*stride] = cm[dst[offset + x + 10*stride] - ((d*3)>>4)];
  263. dst[offset + x + 11*stride] = cm[dst[offset + x + 11*stride] - ((d*1)>>4)];
  264. }
  265. }
  266. }
  267. }
  268. }
  269. static void guess_mv(MpegEncContext *s){
  270. uint8_t fixed[s->mb_stride * s->mb_height];
  271. #define MV_FROZEN 3
  272. #define MV_CHANGED 2
  273. #define MV_UNCHANGED 1
  274. const int mb_stride = s->mb_stride;
  275. const int mb_width = s->mb_width;
  276. const int mb_height= s->mb_height;
  277. int i, depth, num_avail;
  278. int mb_x, mb_y;
  279. num_avail=0;
  280. for(i=0; i<s->mb_num; i++){
  281. const int mb_xy= s->mb_index2xy[ i ];
  282. int f=0;
  283. int error= s->error_status_table[mb_xy];
  284. if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
  285. if(!(error&MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV
  286. fixed[mb_xy]= f;
  287. if(f==MV_FROZEN)
  288. num_avail++;
  289. }
  290. if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){
  291. for(mb_y=0; mb_y<s->mb_height; mb_y++){
  292. for(mb_x=0; mb_x<s->mb_width; mb_x++){
  293. const int mb_xy= mb_x + mb_y*s->mb_stride;
  294. if(IS_INTRA(s->current_picture.mb_type[mb_xy])) continue;
  295. if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;
  296. s->mv_dir = MV_DIR_FORWARD;
  297. s->mb_intra=0;
  298. s->mv_type = MV_TYPE_16X16;
  299. s->mb_skipped=0;
  300. s->dsp.clear_blocks(s->block[0]);
  301. s->mb_x= mb_x;
  302. s->mb_y= mb_y;
  303. s->mv[0][0][0]= 0;
  304. s->mv[0][0][1]= 0;
  305. decode_mb(s);
  306. }
  307. }
  308. return;
  309. }
  310. for(depth=0;; depth++){
  311. int changed, pass, none_left;
  312. none_left=1;
  313. changed=1;
  314. for(pass=0; (changed || pass<2) && pass<10; pass++){
  315. int mb_x, mb_y;
  316. int score_sum=0;
  317. changed=0;
  318. for(mb_y=0; mb_y<s->mb_height; mb_y++){
  319. for(mb_x=0; mb_x<s->mb_width; mb_x++){
  320. const int mb_xy= mb_x + mb_y*s->mb_stride;
  321. int mv_predictor[8][2]={{0}};
  322. int pred_count=0;
  323. int j;
  324. int best_score=256*256*256*64;
  325. int best_pred=0;
  326. const int mot_stride= s->b8_stride;
  327. const int mot_index= mb_x*2 + mb_y*2*mot_stride;
  328. int prev_x= s->current_picture.motion_val[0][mot_index][0];
  329. int prev_y= s->current_picture.motion_val[0][mot_index][1];
  330. if((mb_x^mb_y^pass)&1) continue;
  331. if(fixed[mb_xy]==MV_FROZEN) continue;
  332. assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));
  333. assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);
  334. j=0;
  335. if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1;
  336. if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_FROZEN) j=1;
  337. if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1;
  338. if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_FROZEN) j=1;
  339. if(j==0) continue;
  340. j=0;
  341. if(mb_x>0 && fixed[mb_xy-1 ]==MV_CHANGED) j=1;
  342. if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_CHANGED) j=1;
  343. if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1;
  344. if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_CHANGED) j=1;
  345. if(j==0 && pass>1) continue;
  346. none_left=0;
  347. if(mb_x>0 && fixed[mb_xy-1]){
  348. mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - 2][0];
  349. mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - 2][1];
  350. pred_count++;
  351. }
  352. if(mb_x+1<mb_width && fixed[mb_xy+1]){
  353. mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0];
  354. mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][1];
  355. pred_count++;
  356. }
  357. if(mb_y>0 && fixed[mb_xy-mb_stride]){
  358. mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*2][0];
  359. mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*2][1];
  360. pred_count++;
  361. }
  362. if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
  363. mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0];
  364. mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1];
  365. pred_count++;
  366. }
  367. if(pred_count==0) continue;
  368. if(pred_count>1){
  369. int sum_x=0, sum_y=0;
  370. int max_x, max_y, min_x, min_y;
  371. for(j=0; j<pred_count; j++){
  372. sum_x+= mv_predictor[j][0];
  373. sum_y+= mv_predictor[j][1];
  374. }
  375. /* mean */
  376. mv_predictor[pred_count][0] = sum_x/j;
  377. mv_predictor[pred_count][1] = sum_y/j;
  378. /* median */
  379. if(pred_count>=3){
  380. min_y= min_x= 99999;
  381. max_y= max_x=-99999;
  382. }else{
  383. min_x=min_y=max_x=max_y=0;
  384. }
  385. for(j=0; j<pred_count; j++){
  386. max_x= FFMAX(max_x, mv_predictor[j][0]);
  387. max_y= FFMAX(max_y, mv_predictor[j][1]);
  388. min_x= FFMIN(min_x, mv_predictor[j][0]);
  389. min_y= FFMIN(min_y, mv_predictor[j][1]);
  390. }
  391. mv_predictor[pred_count+1][0] = sum_x - max_x - min_x;
  392. mv_predictor[pred_count+1][1] = sum_y - max_y - min_y;
  393. if(pred_count==4){
  394. mv_predictor[pred_count+1][0] /= 2;
  395. mv_predictor[pred_count+1][1] /= 2;
  396. }
  397. pred_count+=2;
  398. }
  399. /* zero MV */
  400. pred_count++;
  401. /* last MV */
  402. mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0];
  403. mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1];
  404. pred_count++;
  405. s->mv_dir = MV_DIR_FORWARD;
  406. s->mb_intra=0;
  407. s->mv_type = MV_TYPE_16X16;
  408. s->mb_skipped=0;
  409. s->dsp.clear_blocks(s->block[0]);
  410. s->mb_x= mb_x;
  411. s->mb_y= mb_y;
  412. for(j=0; j<pred_count; j++){
  413. int score=0;
  414. uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
  415. s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];
  416. s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];
  417. decode_mb(s);
  418. if(mb_x>0 && fixed[mb_xy-1]){
  419. int k;
  420. for(k=0; k<16; k++)
  421. score += FFABS(src[k*s->linesize-1 ]-src[k*s->linesize ]);
  422. }
  423. if(mb_x+1<mb_width && fixed[mb_xy+1]){
  424. int k;
  425. for(k=0; k<16; k++)
  426. score += FFABS(src[k*s->linesize+15]-src[k*s->linesize+16]);
  427. }
  428. if(mb_y>0 && fixed[mb_xy-mb_stride]){
  429. int k;
  430. for(k=0; k<16; k++)
  431. score += FFABS(src[k-s->linesize ]-src[k ]);
  432. }
  433. if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
  434. int k;
  435. for(k=0; k<16; k++)
  436. score += FFABS(src[k+s->linesize*15]-src[k+s->linesize*16]);
  437. }
  438. if(score <= best_score){ // <= will favor the last MV
  439. best_score= score;
  440. best_pred= j;
  441. }
  442. }
  443. score_sum+= best_score;
  444. //FIXME no need to set s->current_picture.motion_val[0][mot_index][0] explicit
  445. s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0];
  446. s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1];
  447. decode_mb(s);
  448. if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){
  449. fixed[mb_xy]=MV_CHANGED;
  450. changed++;
  451. }else
  452. fixed[mb_xy]=MV_UNCHANGED;
  453. }
  454. }
  455. // printf(".%d/%d", changed, score_sum); fflush(stdout);
  456. }
  457. if(none_left)
  458. return;
  459. for(i=0; i<s->mb_num; i++){
  460. int mb_xy= s->mb_index2xy[i];
  461. if(fixed[mb_xy])
  462. fixed[mb_xy]=MV_FROZEN;
  463. }
  464. // printf(":"); fflush(stdout);
  465. }
  466. }
  467. static int is_intra_more_likely(MpegEncContext *s){
  468. int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
  469. if(!s->last_picture_ptr || !s->last_picture_ptr->data[0]) return 1; //no previous frame available -> use spatial prediction
  470. undamaged_count=0;
  471. for(i=0; i<s->mb_num; i++){
  472. const int mb_xy= s->mb_index2xy[i];
  473. const int error= s->error_status_table[mb_xy];
  474. if(!((error&DC_ERROR) && (error&MV_ERROR)))
  475. undamaged_count++;
  476. }
  477. if(undamaged_count < 5) return 0; //almost all MBs damaged -> use temporal prediction
  478. //prevent dsp.sad() check, that requires access to the image
  479. if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration && s->pict_type == FF_I_TYPE)
  480. return 1;
  481. skip_amount= FFMAX(undamaged_count/50, 1); //check only upto 50 MBs
  482. is_intra_likely=0;
  483. j=0;
  484. for(mb_y= 0; mb_y<s->mb_height-1; mb_y++){
  485. for(mb_x= 0; mb_x<s->mb_width; mb_x++){
  486. int error;
  487. const int mb_xy= mb_x + mb_y*s->mb_stride;
  488. error= s->error_status_table[mb_xy];
  489. if((error&DC_ERROR) && (error&MV_ERROR))
  490. continue; //skip damaged
  491. j++;
  492. if((j%skip_amount) != 0) continue; //skip a few to speed things up
  493. if(s->pict_type==FF_I_TYPE){
  494. uint8_t *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
  495. uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize;
  496. is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16);
  497. is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16);
  498. }else{
  499. if(IS_INTRA(s->current_picture.mb_type[mb_xy]))
  500. is_intra_likely++;
  501. else
  502. is_intra_likely--;
  503. }
  504. }
  505. }
  506. //printf("is_intra_likely: %d type:%d\n", is_intra_likely, s->pict_type);
  507. return is_intra_likely > 0;
  508. }
  509. void ff_er_frame_start(MpegEncContext *s){
  510. if(!s->error_recognition) return;
  511. memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t));
  512. s->error_count= 3*s->mb_num;
  513. }
  514. /**
  515. * adds a slice.
  516. * @param endx x component of the last macroblock, can be -1 for the last of the previous line
  517. * @param status the status at the end (MV_END, AC_ERROR, ...), it is assumed that no earlier end or
  518. * error of the same type occurred
  519. */
  520. void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status){
  521. const int start_i= av_clip(startx + starty * s->mb_width , 0, s->mb_num-1);
  522. const int end_i = av_clip(endx + endy * s->mb_width , 0, s->mb_num);
  523. const int start_xy= s->mb_index2xy[start_i];
  524. const int end_xy = s->mb_index2xy[end_i];
  525. int mask= -1;
  526. if(s->avctx->hwaccel)
  527. return;
  528. if(start_i > end_i || start_xy > end_xy){
  529. av_log(s->avctx, AV_LOG_ERROR, "internal error, slice end before start\n");
  530. return;
  531. }
  532. if(!s->error_recognition) return;
  533. mask &= ~VP_START;
  534. if(status & (AC_ERROR|AC_END)){
  535. mask &= ~(AC_ERROR|AC_END);
  536. s->error_count -= end_i - start_i + 1;
  537. }
  538. if(status & (DC_ERROR|DC_END)){
  539. mask &= ~(DC_ERROR|DC_END);
  540. s->error_count -= end_i - start_i + 1;
  541. }
  542. if(status & (MV_ERROR|MV_END)){
  543. mask &= ~(MV_ERROR|MV_END);
  544. s->error_count -= end_i - start_i + 1;
  545. }
  546. if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) s->error_count= INT_MAX;
  547. if(mask == ~0x7F){
  548. memset(&s->error_status_table[start_xy], 0, (end_xy - start_xy) * sizeof(uint8_t));
  549. }else{
  550. int i;
  551. for(i=start_xy; i<end_xy; i++){
  552. s->error_status_table[ i ] &= mask;
  553. }
  554. }
  555. if(end_i == s->mb_num)
  556. s->error_count= INT_MAX;
  557. else{
  558. s->error_status_table[end_xy] &= mask;
  559. s->error_status_table[end_xy] |= status;
  560. }
  561. s->error_status_table[start_xy] |= VP_START;
  562. if(start_xy > 0 && s->avctx->thread_count <= 1 && s->avctx->skip_top*s->mb_width < start_i){
  563. int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ];
  564. prev_status &= ~ VP_START;
  565. if(prev_status != (MV_END|DC_END|AC_END)) s->error_count= INT_MAX;
  566. }
  567. }
  568. void ff_er_frame_end(MpegEncContext *s){
  569. int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;
  570. int distance;
  571. int threshold_part[4]= {100,100,100};
  572. int threshold= 50;
  573. int is_intra_likely;
  574. int size = s->b8_stride * 2 * s->mb_height;
  575. Picture *pic= s->current_picture_ptr;
  576. if(!s->error_recognition || s->error_count==0 || s->avctx->lowres ||
  577. s->avctx->hwaccel ||
  578. s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU ||
  579. s->error_count==3*s->mb_width*(s->avctx->skip_top + s->avctx->skip_bottom)) return;
  580. if(s->current_picture.motion_val[0] == NULL){
  581. av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n");
  582. for(i=0; i<2; i++){
  583. pic->ref_index[i]= av_mallocz(size * sizeof(uint8_t));
  584. pic->motion_val_base[i]= av_mallocz((size+4) * 2 * sizeof(uint16_t));
  585. pic->motion_val[i]= pic->motion_val_base[i]+4;
  586. }
  587. pic->motion_subsample_log2= 3;
  588. s->current_picture= *s->current_picture_ptr;
  589. }
  590. for(i=0; i<2; i++){
  591. if(pic->ref_index[i])
  592. memset(pic->ref_index[i], 0, size * sizeof(uint8_t));
  593. }
  594. if(s->avctx->debug&FF_DEBUG_ER){
  595. for(mb_y=0; mb_y<s->mb_height; mb_y++){
  596. for(mb_x=0; mb_x<s->mb_width; mb_x++){
  597. int status= s->error_status_table[mb_x + mb_y*s->mb_stride];
  598. av_log(s->avctx, AV_LOG_DEBUG, "%2X ", status);
  599. }
  600. av_log(s->avctx, AV_LOG_DEBUG, "\n");
  601. }
  602. }
  603. #if 1
  604. /* handle overlapping slices */
  605. for(error_type=1; error_type<=3; error_type++){
  606. int end_ok=0;
  607. for(i=s->mb_num-1; i>=0; i--){
  608. const int mb_xy= s->mb_index2xy[i];
  609. int error= s->error_status_table[mb_xy];
  610. if(error&(1<<error_type))
  611. end_ok=1;
  612. if(error&(8<<error_type))
  613. end_ok=1;
  614. if(!end_ok)
  615. s->error_status_table[mb_xy]|= 1<<error_type;
  616. if(error&VP_START)
  617. end_ok=0;
  618. }
  619. }
  620. #endif
  621. #if 1
  622. /* handle slices with partitions of different length */
  623. if(s->partitioned_frame){
  624. int end_ok=0;
  625. for(i=s->mb_num-1; i>=0; i--){
  626. const int mb_xy= s->mb_index2xy[i];
  627. int error= s->error_status_table[mb_xy];
  628. if(error&AC_END)
  629. end_ok=0;
  630. if((error&MV_END) || (error&DC_END) || (error&AC_ERROR))
  631. end_ok=1;
  632. if(!end_ok)
  633. s->error_status_table[mb_xy]|= AC_ERROR;
  634. if(error&VP_START)
  635. end_ok=0;
  636. }
  637. }
  638. #endif
  639. /* handle missing slices */
  640. if(s->error_recognition>=4){
  641. int end_ok=1;
  642. for(i=s->mb_num-2; i>=s->mb_width+100; i--){ //FIXME +100 hack
  643. const int mb_xy= s->mb_index2xy[i];
  644. int error1= s->error_status_table[mb_xy ];
  645. int error2= s->error_status_table[s->mb_index2xy[i+1]];
  646. if(error1&VP_START)
  647. end_ok=1;
  648. if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
  649. && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
  650. && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninit
  651. end_ok=0;
  652. }
  653. if(!end_ok)
  654. s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_ERROR;
  655. }
  656. }
  657. #if 1
  658. /* backward mark errors */
  659. distance=9999999;
  660. for(error_type=1; error_type<=3; error_type++){
  661. for(i=s->mb_num-1; i>=0; i--){
  662. const int mb_xy= s->mb_index2xy[i];
  663. int error= s->error_status_table[mb_xy];
  664. if(!s->mbskip_table[mb_xy]) //FIXME partition specific
  665. distance++;
  666. if(error&(1<<error_type))
  667. distance= 0;
  668. if(s->partitioned_frame){
  669. if(distance < threshold_part[error_type-1])
  670. s->error_status_table[mb_xy]|= 1<<error_type;
  671. }else{
  672. if(distance < threshold)
  673. s->error_status_table[mb_xy]|= 1<<error_type;
  674. }
  675. if(error&VP_START)
  676. distance= 9999999;
  677. }
  678. }
  679. #endif
  680. /* forward mark errors */
  681. error=0;
  682. for(i=0; i<s->mb_num; i++){
  683. const int mb_xy= s->mb_index2xy[i];
  684. int old_error= s->error_status_table[mb_xy];
  685. if(old_error&VP_START)
  686. error= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
  687. else{
  688. error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
  689. s->error_status_table[mb_xy]|= error;
  690. }
  691. }
  692. #if 1
  693. /* handle not partitioned case */
  694. if(!s->partitioned_frame){
  695. for(i=0; i<s->mb_num; i++){
  696. const int mb_xy= s->mb_index2xy[i];
  697. error= s->error_status_table[mb_xy];
  698. if(error&(AC_ERROR|DC_ERROR|MV_ERROR))
  699. error|= AC_ERROR|DC_ERROR|MV_ERROR;
  700. s->error_status_table[mb_xy]= error;
  701. }
  702. }
  703. #endif
  704. dc_error= ac_error= mv_error=0;
  705. for(i=0; i<s->mb_num; i++){
  706. const int mb_xy= s->mb_index2xy[i];
  707. error= s->error_status_table[mb_xy];
  708. if(error&DC_ERROR) dc_error ++;
  709. if(error&AC_ERROR) ac_error ++;
  710. if(error&MV_ERROR) mv_error ++;
  711. }
  712. av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\n", dc_error, ac_error, mv_error);
  713. is_intra_likely= is_intra_more_likely(s);
  714. /* set unknown mb-type to most likely */
  715. for(i=0; i<s->mb_num; i++){
  716. const int mb_xy= s->mb_index2xy[i];
  717. error= s->error_status_table[mb_xy];
  718. if(!((error&DC_ERROR) && (error&MV_ERROR)))
  719. continue;
  720. if(is_intra_likely)
  721. s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
  722. else
  723. s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0;
  724. }
  725. /* handle inter blocks with damaged AC */
  726. for(mb_y=0; mb_y<s->mb_height; mb_y++){
  727. for(mb_x=0; mb_x<s->mb_width; mb_x++){
  728. const int mb_xy= mb_x + mb_y * s->mb_stride;
  729. const int mb_type= s->current_picture.mb_type[mb_xy];
  730. error= s->error_status_table[mb_xy];
  731. if(IS_INTRA(mb_type)) continue; //intra
  732. if(error&MV_ERROR) continue; //inter with damaged MV
  733. if(!(error&AC_ERROR)) continue; //undamaged inter
  734. s->mv_dir = MV_DIR_FORWARD;
  735. s->mb_intra=0;
  736. s->mb_skipped=0;
  737. if(IS_8X8(mb_type)){
  738. int mb_index= mb_x*2 + mb_y*2*s->b8_stride;
  739. int j;
  740. s->mv_type = MV_TYPE_8X8;
  741. for(j=0; j<4; j++){
  742. s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0];
  743. s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1];
  744. }
  745. }else{
  746. s->mv_type = MV_TYPE_16X16;
  747. s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][0];
  748. s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][1];
  749. }
  750. s->dsp.clear_blocks(s->block[0]);
  751. s->mb_x= mb_x;
  752. s->mb_y= mb_y;
  753. decode_mb(s);
  754. }
  755. }
  756. /* guess MVs */
  757. if(s->pict_type==FF_B_TYPE){
  758. for(mb_y=0; mb_y<s->mb_height; mb_y++){
  759. for(mb_x=0; mb_x<s->mb_width; mb_x++){
  760. int xy= mb_x*2 + mb_y*2*s->b8_stride;
  761. const int mb_xy= mb_x + mb_y * s->mb_stride;
  762. const int mb_type= s->current_picture.mb_type[mb_xy];
  763. error= s->error_status_table[mb_xy];
  764. if(IS_INTRA(mb_type)) continue;
  765. if(!(error&MV_ERROR)) continue; //inter with undamaged MV
  766. if(!(error&AC_ERROR)) continue; //undamaged inter
  767. s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD;
  768. s->mb_intra=0;
  769. s->mv_type = MV_TYPE_16X16;
  770. s->mb_skipped=0;
  771. if(s->pp_time){
  772. int time_pp= s->pp_time;
  773. int time_pb= s->pb_time;
  774. s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp;
  775. s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp;
  776. s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
  777. s->mv[1][0][1] = s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
  778. }else{
  779. s->mv[0][0][0]= 0;
  780. s->mv[0][0][1]= 0;
  781. s->mv[1][0][0]= 0;
  782. s->mv[1][0][1]= 0;
  783. }
  784. s->dsp.clear_blocks(s->block[0]);
  785. s->mb_x= mb_x;
  786. s->mb_y= mb_y;
  787. decode_mb(s);
  788. }
  789. }
  790. }else
  791. guess_mv(s);
  792. /* the filters below are not XvMC compatible, skip them */
  793. if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)
  794. goto ec_clean;
  795. /* fill DC for inter blocks */
  796. for(mb_y=0; mb_y<s->mb_height; mb_y++){
  797. for(mb_x=0; mb_x<s->mb_width; mb_x++){
  798. int dc, dcu, dcv, y, n;
  799. int16_t *dc_ptr;
  800. uint8_t *dest_y, *dest_cb, *dest_cr;
  801. const int mb_xy= mb_x + mb_y * s->mb_stride;
  802. const int mb_type= s->current_picture.mb_type[mb_xy];
  803. error= s->error_status_table[mb_xy];
  804. if(IS_INTRA(mb_type) && s->partitioned_frame) continue;
  805. // if(error&MV_ERROR) continue; //inter data damaged FIXME is this good?
  806. dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
  807. dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
  808. dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
  809. dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride];
  810. for(n=0; n<4; n++){
  811. dc=0;
  812. for(y=0; y<8; y++){
  813. int x;
  814. for(x=0; x<8; x++){
  815. dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize];
  816. }
  817. }
  818. dc_ptr[(n&1) + (n>>1)*s->b8_stride]= (dc+4)>>3;
  819. }
  820. dcu=dcv=0;
  821. for(y=0; y<8; y++){
  822. int x;
  823. for(x=0; x<8; x++){
  824. dcu+=dest_cb[x + y*(s->uvlinesize)];
  825. dcv+=dest_cr[x + y*(s->uvlinesize)];
  826. }
  827. }
  828. s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3;
  829. s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3;
  830. }
  831. }
  832. #if 1
  833. /* guess DC for damaged blocks */
  834. guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1);
  835. guess_dc(s, s->dc_val[1], s->mb_width , s->mb_height , s->mb_stride, 0);
  836. guess_dc(s, s->dc_val[2], s->mb_width , s->mb_height , s->mb_stride, 0);
  837. #endif
  838. /* filter luma DC */
  839. filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride);
  840. #if 1
  841. /* render DC only intra */
  842. for(mb_y=0; mb_y<s->mb_height; mb_y++){
  843. for(mb_x=0; mb_x<s->mb_width; mb_x++){
  844. uint8_t *dest_y, *dest_cb, *dest_cr;
  845. const int mb_xy= mb_x + mb_y * s->mb_stride;
  846. const int mb_type= s->current_picture.mb_type[mb_xy];
  847. error= s->error_status_table[mb_xy];
  848. if(IS_INTER(mb_type)) continue;
  849. if(!(error&AC_ERROR)) continue; //undamaged
  850. dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
  851. dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
  852. dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
  853. put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);
  854. }
  855. }
  856. #endif
  857. if(s->avctx->error_concealment&FF_EC_DEBLOCK){
  858. /* filter horizontal block boundaries */
  859. h_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
  860. h_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
  861. h_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
  862. /* filter vertical block boundaries */
  863. v_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
  864. v_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
  865. v_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
  866. }
  867. ec_clean:
  868. /* clean a few tables */
  869. for(i=0; i<s->mb_num; i++){
  870. const int mb_xy= s->mb_index2xy[i];
  871. int error= s->error_status_table[mb_xy];
  872. if(s->pict_type!=FF_B_TYPE && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){
  873. s->mbskip_table[mb_xy]=0;
  874. }
  875. s->mbintra_table[mb_xy]=1;
  876. }
  877. }