h261dec.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /*
  2. * H261 decoder
  3. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  4. * Copyright (c) 2004 Maarten Daniels
  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/h261dec.c
  24. * H.261 decoder.
  25. */
  26. #include "dsputil.h"
  27. #include "avcodec.h"
  28. #include "mpegvideo.h"
  29. #include "h261.h"
  30. #include "h261data.h"
  31. #define H261_MBA_VLC_BITS 9
  32. #define H261_MTYPE_VLC_BITS 6
  33. #define H261_MV_VLC_BITS 7
  34. #define H261_CBP_VLC_BITS 9
  35. #define TCOEFF_VLC_BITS 9
  36. #define MBA_STUFFING 33
  37. #define MBA_STARTCODE 34
  38. extern uint8_t ff_h261_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3];
  39. static VLC h261_mba_vlc;
  40. static VLC h261_mtype_vlc;
  41. static VLC h261_mv_vlc;
  42. static VLC h261_cbp_vlc;
  43. static int h261_decode_block(H261Context * h, DCTELEM * block, int n, int coded);
  44. static av_cold void h261_decode_init_vlc(H261Context *h){
  45. static int done = 0;
  46. if(!done){
  47. done = 1;
  48. init_vlc(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
  49. h261_mba_bits, 1, 1,
  50. h261_mba_code, 1, 1, 1);
  51. init_vlc(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
  52. h261_mtype_bits, 1, 1,
  53. h261_mtype_code, 1, 1, 1);
  54. init_vlc(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
  55. &h261_mv_tab[0][1], 2, 1,
  56. &h261_mv_tab[0][0], 2, 1, 1);
  57. init_vlc(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
  58. &h261_cbp_tab[0][1], 2, 1,
  59. &h261_cbp_tab[0][0], 2, 1, 1);
  60. init_rl(&h261_rl_tcoeff, ff_h261_rl_table_store);
  61. INIT_VLC_RL(h261_rl_tcoeff, 552);
  62. }
  63. }
  64. static av_cold int h261_decode_init(AVCodecContext *avctx){
  65. H261Context *h= avctx->priv_data;
  66. MpegEncContext * const s = &h->s;
  67. // set defaults
  68. MPV_decode_defaults(s);
  69. s->avctx = avctx;
  70. s->width = s->avctx->coded_width;
  71. s->height = s->avctx->coded_height;
  72. s->codec_id = s->avctx->codec->id;
  73. s->out_format = FMT_H261;
  74. s->low_delay= 1;
  75. avctx->pix_fmt= PIX_FMT_YUV420P;
  76. s->codec_id= avctx->codec->id;
  77. h261_decode_init_vlc(h);
  78. h->gob_start_code_skipped = 0;
  79. return 0;
  80. }
  81. /**
  82. * decodes the group of blocks header or slice header.
  83. * @return <0 if an error occurred
  84. */
  85. static int h261_decode_gob_header(H261Context *h){
  86. unsigned int val;
  87. MpegEncContext * const s = &h->s;
  88. if ( !h->gob_start_code_skipped ){
  89. /* Check for GOB Start Code */
  90. val = show_bits(&s->gb, 15);
  91. if(val)
  92. return -1;
  93. /* We have a GBSC */
  94. skip_bits(&s->gb, 16);
  95. }
  96. h->gob_start_code_skipped = 0;
  97. h->gob_number = get_bits(&s->gb, 4); /* GN */
  98. s->qscale = get_bits(&s->gb, 5); /* GQUANT */
  99. /* Check if gob_number is valid */
  100. if (s->mb_height==18){ //cif
  101. if ((h->gob_number<=0) || (h->gob_number>12))
  102. return -1;
  103. }
  104. else{ //qcif
  105. if ((h->gob_number!=1) && (h->gob_number!=3) && (h->gob_number!=5))
  106. return -1;
  107. }
  108. /* GEI */
  109. while (get_bits1(&s->gb) != 0) {
  110. skip_bits(&s->gb, 8);
  111. }
  112. if(s->qscale==0) {
  113. av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n");
  114. if (s->avctx->error_recognition >= FF_ER_COMPLIANT)
  115. return -1;
  116. }
  117. // For the first transmitted macroblock in a GOB, MBA is the absolute address. For
  118. // subsequent macroblocks, MBA is the difference between the absolute addresses of
  119. // the macroblock and the last transmitted macroblock.
  120. h->current_mba = 0;
  121. h->mba_diff = 0;
  122. return 0;
  123. }
  124. /**
  125. * decodes the group of blocks / video packet header.
  126. * @return <0 if no resync found
  127. */
  128. static int ff_h261_resync(H261Context *h){
  129. MpegEncContext * const s = &h->s;
  130. int left, ret;
  131. if ( h->gob_start_code_skipped ){
  132. ret= h261_decode_gob_header(h);
  133. if(ret>=0)
  134. return 0;
  135. }
  136. else{
  137. if(show_bits(&s->gb, 15)==0){
  138. ret= h261_decode_gob_header(h);
  139. if(ret>=0)
  140. return 0;
  141. }
  142. //OK, it is not where it is supposed to be ...
  143. s->gb= s->last_resync_gb;
  144. align_get_bits(&s->gb);
  145. left= s->gb.size_in_bits - get_bits_count(&s->gb);
  146. for(;left>15+1+4+5; left-=8){
  147. if(show_bits(&s->gb, 15)==0){
  148. GetBitContext bak= s->gb;
  149. ret= h261_decode_gob_header(h);
  150. if(ret>=0)
  151. return 0;
  152. s->gb= bak;
  153. }
  154. skip_bits(&s->gb, 8);
  155. }
  156. }
  157. return -1;
  158. }
  159. /**
  160. * decodes skipped macroblocks
  161. * @return 0
  162. */
  163. static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 )
  164. {
  165. MpegEncContext * const s = &h->s;
  166. int i;
  167. s->mb_intra = 0;
  168. for(i=mba1; i<mba2; i++){
  169. int j, xy;
  170. s->mb_x= ((h->gob_number-1) % 2) * 11 + i % 11;
  171. s->mb_y= ((h->gob_number-1) / 2) * 3 + i / 11;
  172. xy = s->mb_x + s->mb_y * s->mb_stride;
  173. ff_init_block_index(s);
  174. ff_update_block_index(s);
  175. for(j=0;j<6;j++)
  176. s->block_last_index[j] = -1;
  177. s->mv_dir = MV_DIR_FORWARD;
  178. s->mv_type = MV_TYPE_16X16;
  179. s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
  180. s->mv[0][0][0] = 0;
  181. s->mv[0][0][1] = 0;
  182. s->mb_skipped = 1;
  183. h->mtype &= ~MB_TYPE_H261_FIL;
  184. MPV_decode_mb(s, s->block);
  185. }
  186. return 0;
  187. }
  188. static int decode_mv_component(GetBitContext *gb, int v){
  189. int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
  190. /* check if mv_diff is valid */
  191. if ( mv_diff < 0 )
  192. return v;
  193. mv_diff = mvmap[mv_diff];
  194. if(mv_diff && !get_bits1(gb))
  195. mv_diff= -mv_diff;
  196. v += mv_diff;
  197. if (v <=-16) v+= 32;
  198. else if(v >= 16) v-= 32;
  199. return v;
  200. }
  201. static int h261_decode_mb(H261Context *h){
  202. MpegEncContext * const s = &h->s;
  203. int i, cbp, xy;
  204. cbp = 63;
  205. // Read mba
  206. do{
  207. h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table, H261_MBA_VLC_BITS, 2);
  208. /* Check for slice end */
  209. /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
  210. if (h->mba_diff == MBA_STARTCODE){ // start code
  211. h->gob_start_code_skipped = 1;
  212. return SLICE_END;
  213. }
  214. }
  215. while( h->mba_diff == MBA_STUFFING ); // stuffing
  216. if ( h->mba_diff < 0 ){
  217. if ( get_bits_count(&s->gb) + 7 >= s->gb.size_in_bits )
  218. return SLICE_END;
  219. av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
  220. return SLICE_ERROR;
  221. }
  222. h->mba_diff += 1;
  223. h->current_mba += h->mba_diff;
  224. if ( h->current_mba > MBA_STUFFING )
  225. return SLICE_ERROR;
  226. s->mb_x= ((h->gob_number-1) % 2) * 11 + ((h->current_mba-1) % 11);
  227. s->mb_y= ((h->gob_number-1) / 2) * 3 + ((h->current_mba-1) / 11);
  228. xy = s->mb_x + s->mb_y * s->mb_stride;
  229. ff_init_block_index(s);
  230. ff_update_block_index(s);
  231. // Read mtype
  232. h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
  233. if (h->mtype < 0) {
  234. av_log(s->avctx, AV_LOG_ERROR, "illegal mtype %d\n", h->mtype);
  235. return SLICE_ERROR;
  236. }
  237. h->mtype = h261_mtype_map[h->mtype];
  238. // Read mquant
  239. if ( IS_QUANT ( h->mtype ) ){
  240. ff_set_qscale(s, get_bits(&s->gb, 5));
  241. }
  242. s->mb_intra = IS_INTRA4x4(h->mtype);
  243. // Read mv
  244. if ( IS_16X16 ( h->mtype ) ){
  245. // Motion vector data is included for all MC macroblocks. MVD is obtained from the macroblock vector by subtracting the
  246. // vector of the preceding macroblock. For this calculation the vector of the preceding macroblock is regarded as zero in the
  247. // following three situations:
  248. // 1) evaluating MVD for macroblocks 1, 12 and 23;
  249. // 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
  250. // 3) MTYPE of the previous macroblock was not MC.
  251. if ( ( h->current_mba == 1 ) || ( h->current_mba == 12 ) || ( h->current_mba == 23 ) ||
  252. ( h->mba_diff != 1))
  253. {
  254. h->current_mv_x = 0;
  255. h->current_mv_y = 0;
  256. }
  257. h->current_mv_x= decode_mv_component(&s->gb, h->current_mv_x);
  258. h->current_mv_y= decode_mv_component(&s->gb, h->current_mv_y);
  259. }else{
  260. h->current_mv_x = 0;
  261. h->current_mv_y = 0;
  262. }
  263. // Read cbp
  264. if ( HAS_CBP( h->mtype ) ){
  265. cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1;
  266. }
  267. if(s->mb_intra){
  268. s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
  269. goto intra;
  270. }
  271. //set motion vectors
  272. s->mv_dir = MV_DIR_FORWARD;
  273. s->mv_type = MV_TYPE_16X16;
  274. s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
  275. s->mv[0][0][0] = h->current_mv_x * 2;//gets divided by 2 in motion compensation
  276. s->mv[0][0][1] = h->current_mv_y * 2;
  277. intra:
  278. /* decode each block */
  279. if(s->mb_intra || HAS_CBP(h->mtype)){
  280. s->dsp.clear_blocks(s->block[0]);
  281. for (i = 0; i < 6; i++) {
  282. if (h261_decode_block(h, s->block[i], i, cbp&32) < 0){
  283. return SLICE_ERROR;
  284. }
  285. cbp+=cbp;
  286. }
  287. }else{
  288. for (i = 0; i < 6; i++)
  289. s->block_last_index[i]= -1;
  290. }
  291. MPV_decode_mb(s, s->block);
  292. return SLICE_OK;
  293. }
  294. /**
  295. * decodes a macroblock
  296. * @return <0 if an error occurred
  297. */
  298. static int h261_decode_block(H261Context * h, DCTELEM * block,
  299. int n, int coded)
  300. {
  301. MpegEncContext * const s = &h->s;
  302. int code, level, i, j, run;
  303. RLTable *rl = &h261_rl_tcoeff;
  304. const uint8_t *scan_table;
  305. // For the variable length encoding there are two code tables, one being used for
  306. // the first transmitted LEVEL in INTER, INTER+MC and INTER+MC+FIL blocks, the second
  307. // for all other LEVELs except the first one in INTRA blocks which is fixed length
  308. // coded with 8 bits.
  309. // NOTE: the two code tables only differ in one VLC so we handle that manually.
  310. scan_table = s->intra_scantable.permutated;
  311. if (s->mb_intra){
  312. /* DC coef */
  313. level = get_bits(&s->gb, 8);
  314. // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
  315. if((level&0x7F) == 0){
  316. av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
  317. return -1;
  318. }
  319. // The code 1000 0000 is not used, the reconstruction level of 1024 being coded as 1111 1111.
  320. if (level == 255)
  321. level = 128;
  322. block[0] = level;
  323. i = 1;
  324. }else if(coded){
  325. // Run Level Code
  326. // EOB Not possible for first level when cbp is available (that's why the table is different)
  327. // 0 1 1s
  328. // * * 0*
  329. int check = show_bits(&s->gb, 2);
  330. i = 0;
  331. if ( check & 0x2 ){
  332. skip_bits(&s->gb, 2);
  333. block[0] = ( check & 0x1 ) ? -1 : 1;
  334. i = 1;
  335. }
  336. }else{
  337. i = 0;
  338. }
  339. if(!coded){
  340. s->block_last_index[n] = i - 1;
  341. return 0;
  342. }
  343. for(;;){
  344. code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_VLC_BITS, 2);
  345. if (code < 0){
  346. av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
  347. return -1;
  348. }
  349. if (code == rl->n) {
  350. /* escape */
  351. // The remaining combinations of (run, level) are encoded with a 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits level.
  352. run = get_bits(&s->gb, 6);
  353. level = get_sbits(&s->gb, 8);
  354. }else if(code == 0){
  355. break;
  356. }else{
  357. run = rl->table_run[code];
  358. level = rl->table_level[code];
  359. if (get_bits1(&s->gb))
  360. level = -level;
  361. }
  362. i += run;
  363. if (i >= 64){
  364. av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n", s->mb_x, s->mb_y);
  365. return -1;
  366. }
  367. j = scan_table[i];
  368. block[j] = level;
  369. i++;
  370. }
  371. s->block_last_index[n] = i-1;
  372. return 0;
  373. }
  374. /**
  375. * decodes the H261 picture header.
  376. * @return <0 if no startcode found
  377. */
  378. static int h261_decode_picture_header(H261Context *h){
  379. MpegEncContext * const s = &h->s;
  380. int format, i;
  381. uint32_t startcode= 0;
  382. for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){
  383. startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
  384. if(startcode == 0x10)
  385. break;
  386. }
  387. if (startcode != 0x10){
  388. av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
  389. return -1;
  390. }
  391. /* temporal reference */
  392. i= get_bits(&s->gb, 5); /* picture timestamp */
  393. if(i < (s->picture_number&31))
  394. i += 32;
  395. s->picture_number = (s->picture_number&~31) + i;
  396. s->avctx->time_base= (AVRational){1001, 30000};
  397. s->current_picture.pts= s->picture_number;
  398. /* PTYPE starts here */
  399. skip_bits1(&s->gb); /* split screen off */
  400. skip_bits1(&s->gb); /* camera off */
  401. skip_bits1(&s->gb); /* freeze picture release off */
  402. format = get_bits1(&s->gb);
  403. //only 2 formats possible
  404. if (format == 0){//QCIF
  405. s->width = 176;
  406. s->height = 144;
  407. s->mb_width = 11;
  408. s->mb_height = 9;
  409. }else{//CIF
  410. s->width = 352;
  411. s->height = 288;
  412. s->mb_width = 22;
  413. s->mb_height = 18;
  414. }
  415. s->mb_num = s->mb_width * s->mb_height;
  416. skip_bits1(&s->gb); /* still image mode off */
  417. skip_bits1(&s->gb); /* Reserved */
  418. /* PEI */
  419. while (get_bits1(&s->gb) != 0){
  420. skip_bits(&s->gb, 8);
  421. }
  422. // h261 has no I-FRAMES, but if we pass FF_I_TYPE for the first frame, the codec crashes if it does
  423. // not contain all I-blocks (e.g. when a packet is lost)
  424. s->pict_type = FF_P_TYPE;
  425. h->gob_number = 0;
  426. return 0;
  427. }
  428. static int h261_decode_gob(H261Context *h){
  429. MpegEncContext * const s = &h->s;
  430. ff_set_qscale(s, s->qscale);
  431. /* decode mb's */
  432. while(h->current_mba <= MBA_STUFFING)
  433. {
  434. int ret;
  435. /* DCT & quantize */
  436. ret= h261_decode_mb(h);
  437. if(ret<0){
  438. if(ret==SLICE_END){
  439. h261_decode_mb_skipped(h, h->current_mba, 33);
  440. return 0;
  441. }
  442. av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", s->mb_x + s->mb_y*s->mb_stride);
  443. return -1;
  444. }
  445. h261_decode_mb_skipped(h, h->current_mba-h->mba_diff, h->current_mba-1);
  446. }
  447. return -1;
  448. }
  449. /**
  450. * returns the number of bytes consumed for building the current frame
  451. */
  452. static int get_consumed_bytes(MpegEncContext *s, int buf_size){
  453. int pos= get_bits_count(&s->gb)>>3;
  454. if(pos==0) pos=1; //avoid infinite loops (i doubt that is needed but ...)
  455. if(pos+10>buf_size) pos=buf_size; // oops ;)
  456. return pos;
  457. }
  458. static int h261_decode_frame(AVCodecContext *avctx,
  459. void *data, int *data_size,
  460. const uint8_t *buf, int buf_size)
  461. {
  462. H261Context *h= avctx->priv_data;
  463. MpegEncContext *s = &h->s;
  464. int ret;
  465. AVFrame *pict = data;
  466. #ifdef DEBUG
  467. av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
  468. av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
  469. #endif
  470. s->flags= avctx->flags;
  471. s->flags2= avctx->flags2;
  472. h->gob_start_code_skipped=0;
  473. retry:
  474. init_get_bits(&s->gb, buf, buf_size*8);
  475. if(!s->context_initialized){
  476. if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
  477. return -1;
  478. }
  479. //we need to set current_picture_ptr before reading the header, otherwise we cannot store anyting im there
  480. if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){
  481. int i= ff_find_unused_picture(s, 0);
  482. s->current_picture_ptr= &s->picture[i];
  483. }
  484. ret = h261_decode_picture_header(h);
  485. /* skip if the header was thrashed */
  486. if (ret < 0){
  487. av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
  488. return -1;
  489. }
  490. if (s->width != avctx->coded_width || s->height != avctx->coded_height){
  491. ParseContext pc= s->parse_context; //FIXME move this demuxing hack to libavformat
  492. s->parse_context.buffer=0;
  493. MPV_common_end(s);
  494. s->parse_context= pc;
  495. }
  496. if (!s->context_initialized) {
  497. avcodec_set_dimensions(avctx, s->width, s->height);
  498. goto retry;
  499. }
  500. // for hurry_up==5
  501. s->current_picture.pict_type= s->pict_type;
  502. s->current_picture.key_frame= s->pict_type == FF_I_TYPE;
  503. /* skip everything if we are in a hurry>=5 */
  504. if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size);
  505. if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE)
  506. ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE)
  507. || avctx->skip_frame >= AVDISCARD_ALL)
  508. return get_consumed_bytes(s, buf_size);
  509. if(MPV_frame_start(s, avctx) < 0)
  510. return -1;
  511. ff_er_frame_start(s);
  512. /* decode each macroblock */
  513. s->mb_x=0;
  514. s->mb_y=0;
  515. while(h->gob_number < (s->mb_height==18 ? 12 : 5)){
  516. if(ff_h261_resync(h)<0)
  517. break;
  518. h261_decode_gob(h);
  519. }
  520. MPV_frame_end(s);
  521. assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
  522. assert(s->current_picture.pict_type == s->pict_type);
  523. *pict= *(AVFrame*)s->current_picture_ptr;
  524. ff_print_debug_info(s, pict);
  525. *data_size = sizeof(AVFrame);
  526. return get_consumed_bytes(s, buf_size);
  527. }
  528. static av_cold int h261_decode_end(AVCodecContext *avctx)
  529. {
  530. H261Context *h= avctx->priv_data;
  531. MpegEncContext *s = &h->s;
  532. MPV_common_end(s);
  533. return 0;
  534. }
  535. AVCodec h261_decoder = {
  536. "h261",
  537. CODEC_TYPE_VIDEO,
  538. CODEC_ID_H261,
  539. sizeof(H261Context),
  540. h261_decode_init,
  541. NULL,
  542. h261_decode_end,
  543. h261_decode_frame,
  544. CODEC_CAP_DR1,
  545. .long_name = NULL_IF_CONFIG_SMALL("H.261"),
  546. };