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.

1080 lines
40KB

  1. /*
  2. * FFV1 decoder
  3. *
  4. * Copyright (c) 2003-2013 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
  24. * FF Video Codec 1 (a lossless codec) decoder
  25. */
  26. #include "libavutil/avassert.h"
  27. #include "libavutil/crc.h"
  28. #include "libavutil/opt.h"
  29. #include "libavutil/imgutils.h"
  30. #include "libavutil/pixdesc.h"
  31. #include "libavutil/timer.h"
  32. #include "avcodec.h"
  33. #include "internal.h"
  34. #include "get_bits.h"
  35. #include "rangecoder.h"
  36. #include "golomb.h"
  37. #include "mathops.h"
  38. #include "ffv1.h"
  39. static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state,
  40. int is_signed)
  41. {
  42. if (get_rac(c, state + 0))
  43. return 0;
  44. else {
  45. int i, e;
  46. unsigned a;
  47. e = 0;
  48. while (get_rac(c, state + 1 + FFMIN(e, 9))) { // 1..10
  49. e++;
  50. if (e > 31)
  51. return AVERROR_INVALIDDATA;
  52. }
  53. a = 1;
  54. for (i = e - 1; i >= 0; i--)
  55. a += a + get_rac(c, state + 22 + FFMIN(i, 9)); // 22..31
  56. e = -(is_signed && get_rac(c, state + 11 + FFMIN(e, 10))); // 11..21
  57. return (a ^ e) - e;
  58. }
  59. }
  60. static av_noinline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
  61. {
  62. return get_symbol_inline(c, state, is_signed);
  63. }
  64. static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state,
  65. int bits)
  66. {
  67. int k, i, v, ret;
  68. i = state->count;
  69. k = 0;
  70. while (i < state->error_sum) { // FIXME: optimize
  71. k++;
  72. i += i;
  73. }
  74. v = get_sr_golomb(gb, k, 12, bits);
  75. ff_dlog(NULL, "v:%d bias:%d error:%d drift:%d count:%d k:%d",
  76. v, state->bias, state->error_sum, state->drift, state->count, k);
  77. v ^= ((2 * state->drift + state->count) >> 31);
  78. ret = fold(v + state->bias, bits);
  79. update_vlc_state(state, v);
  80. return ret;
  81. }
  82. static int is_input_end(FFV1Context *s)
  83. {
  84. if (s->ac != AC_GOLOMB_RICE) {
  85. RangeCoder *const c = &s->c;
  86. if (c->overread > MAX_OVERREAD)
  87. return AVERROR_INVALIDDATA;
  88. } else {
  89. if (get_bits_left(&s->gb) < 1)
  90. return AVERROR_INVALIDDATA;
  91. }
  92. return 0;
  93. }
  94. #define TYPE int16_t
  95. #define RENAME(name) name
  96. #include "ffv1dec_template.c"
  97. #undef TYPE
  98. #undef RENAME
  99. #define TYPE int32_t
  100. #define RENAME(name) name ## 32
  101. #include "ffv1dec_template.c"
  102. static int decode_plane(FFV1Context *s, uint8_t *src,
  103. int w, int h, int stride, int plane_index,
  104. int pixel_stride)
  105. {
  106. int x, y;
  107. int16_t *sample[2];
  108. sample[0] = s->sample_buffer + 3;
  109. sample[1] = s->sample_buffer + w + 6 + 3;
  110. s->run_index = 0;
  111. memset(s->sample_buffer, 0, 2 * (w + 6) * sizeof(*s->sample_buffer));
  112. for (y = 0; y < h; y++) {
  113. int16_t *temp = sample[0]; // FIXME: try a normal buffer
  114. sample[0] = sample[1];
  115. sample[1] = temp;
  116. sample[1][-1] = sample[0][0];
  117. sample[0][w] = sample[0][w - 1];
  118. // { START_TIMER
  119. if (s->avctx->bits_per_raw_sample <= 8) {
  120. int ret = decode_line(s, w, sample, plane_index, 8);
  121. if (ret < 0)
  122. return ret;
  123. for (x = 0; x < w; x++)
  124. src[x*pixel_stride + stride * y] = sample[1][x];
  125. } else {
  126. int ret = decode_line(s, w, sample, plane_index, s->avctx->bits_per_raw_sample);
  127. if (ret < 0)
  128. return ret;
  129. if (s->packed_at_lsb) {
  130. for (x = 0; x < w; x++) {
  131. ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x];
  132. }
  133. } else {
  134. for (x = 0; x < w; x++) {
  135. ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x] << (16 - s->avctx->bits_per_raw_sample) | ((uint16_t **)sample)[1][x] >> (2 * s->avctx->bits_per_raw_sample - 16);
  136. }
  137. }
  138. }
  139. // STOP_TIMER("decode-line") }
  140. }
  141. return 0;
  142. }
  143. static int decode_slice_header(FFV1Context *f, FFV1Context *fs)
  144. {
  145. RangeCoder *c = &fs->c;
  146. uint8_t state[CONTEXT_SIZE];
  147. unsigned ps, i, context_count;
  148. memset(state, 128, sizeof(state));
  149. av_assert0(f->version > 2);
  150. fs->slice_x = get_symbol(c, state, 0) * f->width ;
  151. fs->slice_y = get_symbol(c, state, 0) * f->height;
  152. fs->slice_width = (get_symbol(c, state, 0) + 1) * f->width + fs->slice_x;
  153. fs->slice_height = (get_symbol(c, state, 0) + 1) * f->height + fs->slice_y;
  154. fs->slice_x /= f->num_h_slices;
  155. fs->slice_y /= f->num_v_slices;
  156. fs->slice_width = fs->slice_width /f->num_h_slices - fs->slice_x;
  157. fs->slice_height = fs->slice_height/f->num_v_slices - fs->slice_y;
  158. if ((unsigned)fs->slice_width > f->width || (unsigned)fs->slice_height > f->height)
  159. return -1;
  160. if ( (unsigned)fs->slice_x + (uint64_t)fs->slice_width > f->width
  161. || (unsigned)fs->slice_y + (uint64_t)fs->slice_height > f->height)
  162. return -1;
  163. for (i = 0; i < f->plane_count; i++) {
  164. PlaneContext * const p = &fs->plane[i];
  165. int idx = get_symbol(c, state, 0);
  166. if (idx >= (unsigned)f->quant_table_count) {
  167. av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n");
  168. return -1;
  169. }
  170. p->quant_table_index = idx;
  171. memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table));
  172. context_count = f->context_count[idx];
  173. if (p->context_count < context_count) {
  174. av_freep(&p->state);
  175. av_freep(&p->vlc_state);
  176. }
  177. p->context_count = context_count;
  178. }
  179. ps = get_symbol(c, state, 0);
  180. if (ps == 1) {
  181. f->cur->interlaced_frame = 1;
  182. f->cur->top_field_first = 1;
  183. } else if (ps == 2) {
  184. f->cur->interlaced_frame = 1;
  185. f->cur->top_field_first = 0;
  186. } else if (ps == 3) {
  187. f->cur->interlaced_frame = 0;
  188. }
  189. f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0);
  190. f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0);
  191. if (av_image_check_sar(f->width, f->height,
  192. f->cur->sample_aspect_ratio) < 0) {
  193. av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
  194. f->cur->sample_aspect_ratio.num,
  195. f->cur->sample_aspect_ratio.den);
  196. f->cur->sample_aspect_ratio = (AVRational){ 0, 1 };
  197. }
  198. if (fs->version > 3) {
  199. fs->slice_reset_contexts = get_rac(c, state);
  200. fs->slice_coding_mode = get_symbol(c, state, 0);
  201. if (fs->slice_coding_mode != 1) {
  202. fs->slice_rct_by_coef = get_symbol(c, state, 0);
  203. fs->slice_rct_ry_coef = get_symbol(c, state, 0);
  204. if ((uint64_t)fs->slice_rct_by_coef + (uint64_t)fs->slice_rct_ry_coef > 4) {
  205. av_log(f->avctx, AV_LOG_ERROR, "slice_rct_y_coef out of range\n");
  206. return AVERROR_INVALIDDATA;
  207. }
  208. }
  209. }
  210. return 0;
  211. }
  212. static int decode_slice(AVCodecContext *c, void *arg)
  213. {
  214. FFV1Context *fs = *(void **)arg;
  215. FFV1Context *f = fs->avctx->priv_data;
  216. int width, height, x, y, ret;
  217. const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;
  218. AVFrame * const p = f->cur;
  219. int i, si;
  220. for( si=0; fs != f->slice_context[si]; si ++)
  221. ;
  222. if(f->fsrc && !p->key_frame)
  223. ff_thread_await_progress(&f->last_picture, si, 0);
  224. if(f->fsrc && !p->key_frame) {
  225. FFV1Context *fssrc = f->fsrc->slice_context[si];
  226. FFV1Context *fsdst = f->slice_context[si];
  227. av_assert1(fsdst->plane_count == fssrc->plane_count);
  228. av_assert1(fsdst == fs);
  229. if (!p->key_frame)
  230. fsdst->slice_damaged |= fssrc->slice_damaged;
  231. for (i = 0; i < f->plane_count; i++) {
  232. PlaneContext *psrc = &fssrc->plane[i];
  233. PlaneContext *pdst = &fsdst->plane[i];
  234. av_free(pdst->state);
  235. av_free(pdst->vlc_state);
  236. memcpy(pdst, psrc, sizeof(*pdst));
  237. pdst->state = NULL;
  238. pdst->vlc_state = NULL;
  239. if (fssrc->ac) {
  240. pdst->state = av_malloc_array(CONTEXT_SIZE, psrc->context_count);
  241. memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count);
  242. } else {
  243. pdst->vlc_state = av_malloc_array(sizeof(*pdst->vlc_state), psrc->context_count);
  244. memcpy(pdst->vlc_state, psrc->vlc_state, sizeof(*pdst->vlc_state) * psrc->context_count);
  245. }
  246. }
  247. }
  248. fs->slice_rct_by_coef = 1;
  249. fs->slice_rct_ry_coef = 1;
  250. if (f->version > 2) {
  251. if (ff_ffv1_init_slice_state(f, fs) < 0)
  252. return AVERROR(ENOMEM);
  253. if (decode_slice_header(f, fs) < 0) {
  254. fs->slice_x = fs->slice_y = fs->slice_height = fs->slice_width = 0;
  255. fs->slice_damaged = 1;
  256. return AVERROR_INVALIDDATA;
  257. }
  258. }
  259. if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0)
  260. return ret;
  261. if (f->cur->key_frame || fs->slice_reset_contexts)
  262. ff_ffv1_clear_slice_state(f, fs);
  263. width = fs->slice_width;
  264. height = fs->slice_height;
  265. x = fs->slice_x;
  266. y = fs->slice_y;
  267. if (fs->ac == AC_GOLOMB_RICE) {
  268. if (f->version == 3 && f->micro_version > 1 || f->version > 3)
  269. get_rac(&fs->c, (uint8_t[]) { 129 });
  270. fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0;
  271. init_get_bits(&fs->gb,
  272. fs->c.bytestream_start + fs->ac_byte_count,
  273. (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8);
  274. }
  275. av_assert1(width && height);
  276. if (f->colorspace == 0 && (f->chroma_planes || !fs->transparency)) {
  277. const int chroma_width = AV_CEIL_RSHIFT(width, f->chroma_h_shift);
  278. const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
  279. const int cx = x >> f->chroma_h_shift;
  280. const int cy = y >> f->chroma_v_shift;
  281. decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1);
  282. if (f->chroma_planes) {
  283. decode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
  284. decode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1);
  285. }
  286. if (fs->transparency)
  287. decode_plane(fs, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1);
  288. } else if (f->colorspace == 0) {
  289. decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2);
  290. decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2);
  291. } else if (f->use32bit) {
  292. uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
  293. p->data[1] + ps * x + y * p->linesize[1],
  294. p->data[2] + ps * x + y * p->linesize[2],
  295. p->data[3] + ps * x + y * p->linesize[3] };
  296. decode_rgb_frame32(fs, planes, width, height, p->linesize);
  297. } else {
  298. uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
  299. p->data[1] + ps * x + y * p->linesize[1],
  300. p->data[2] + ps * x + y * p->linesize[2],
  301. p->data[3] + ps * x + y * p->linesize[3] };
  302. decode_rgb_frame(fs, planes, width, height, p->linesize);
  303. }
  304. if (fs->ac != AC_GOLOMB_RICE && f->version > 2) {
  305. int v;
  306. get_rac(&fs->c, (uint8_t[]) { 129 });
  307. v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec;
  308. if (v) {
  309. av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v);
  310. fs->slice_damaged = 1;
  311. }
  312. }
  313. emms_c();
  314. ff_thread_report_progress(&f->picture, si, 0);
  315. return 0;
  316. }
  317. static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale)
  318. {
  319. int v;
  320. int i = 0;
  321. uint8_t state[CONTEXT_SIZE];
  322. memset(state, 128, sizeof(state));
  323. for (v = 0; i < 128; v++) {
  324. unsigned len = get_symbol(c, state, 0) + 1U;
  325. if (len > 128 - i || !len)
  326. return AVERROR_INVALIDDATA;
  327. while (len--) {
  328. quant_table[i] = scale * v;
  329. i++;
  330. }
  331. }
  332. for (i = 1; i < 128; i++)
  333. quant_table[256 - i] = -quant_table[i];
  334. quant_table[128] = -quant_table[127];
  335. return 2 * v - 1;
  336. }
  337. static int read_quant_tables(RangeCoder *c,
  338. int16_t quant_table[MAX_CONTEXT_INPUTS][256])
  339. {
  340. int i;
  341. int context_count = 1;
  342. for (i = 0; i < 5; i++) {
  343. int ret = read_quant_table(c, quant_table[i], context_count);
  344. if (ret < 0)
  345. return ret;
  346. context_count *= ret;
  347. if (context_count > 32768U) {
  348. return AVERROR_INVALIDDATA;
  349. }
  350. }
  351. return (context_count + 1) / 2;
  352. }
  353. static int read_extra_header(FFV1Context *f)
  354. {
  355. RangeCoder *const c = &f->c;
  356. uint8_t state[CONTEXT_SIZE];
  357. int i, j, k, ret;
  358. uint8_t state2[32][CONTEXT_SIZE];
  359. unsigned crc = 0;
  360. memset(state2, 128, sizeof(state2));
  361. memset(state, 128, sizeof(state));
  362. ff_init_range_decoder(c, f->avctx->extradata, f->avctx->extradata_size);
  363. ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);
  364. f->version = get_symbol(c, state, 0);
  365. if (f->version < 2) {
  366. av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header\n");
  367. return AVERROR_INVALIDDATA;
  368. }
  369. if (f->version > 2) {
  370. c->bytestream_end -= 4;
  371. f->micro_version = get_symbol(c, state, 0);
  372. if (f->micro_version < 0)
  373. return AVERROR_INVALIDDATA;
  374. }
  375. f->ac = get_symbol(c, state, 0);
  376. if (f->ac == AC_RANGE_CUSTOM_TAB) {
  377. for (i = 1; i < 256; i++)
  378. f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i];
  379. }
  380. f->colorspace = get_symbol(c, state, 0); //YUV cs type
  381. f->avctx->bits_per_raw_sample = get_symbol(c, state, 0);
  382. f->chroma_planes = get_rac(c, state);
  383. f->chroma_h_shift = get_symbol(c, state, 0);
  384. f->chroma_v_shift = get_symbol(c, state, 0);
  385. f->transparency = get_rac(c, state);
  386. f->plane_count = 1 + (f->chroma_planes || f->version<4) + f->transparency;
  387. f->num_h_slices = 1 + get_symbol(c, state, 0);
  388. f->num_v_slices = 1 + get_symbol(c, state, 0);
  389. if (f->chroma_h_shift > 4U || f->chroma_v_shift > 4U) {
  390. av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n",
  391. f->chroma_h_shift, f->chroma_v_shift);
  392. return AVERROR_INVALIDDATA;
  393. }
  394. if (f->num_h_slices > (unsigned)f->width || !f->num_h_slices ||
  395. f->num_v_slices > (unsigned)f->height || !f->num_v_slices
  396. ) {
  397. av_log(f->avctx, AV_LOG_ERROR, "slice count invalid\n");
  398. return AVERROR_INVALIDDATA;
  399. }
  400. f->quant_table_count = get_symbol(c, state, 0);
  401. if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES || !f->quant_table_count) {
  402. av_log(f->avctx, AV_LOG_ERROR, "quant table count %d is invalid\n", f->quant_table_count);
  403. f->quant_table_count = 0;
  404. return AVERROR_INVALIDDATA;
  405. }
  406. for (i = 0; i < f->quant_table_count; i++) {
  407. f->context_count[i] = read_quant_tables(c, f->quant_tables[i]);
  408. if (f->context_count[i] < 0) {
  409. av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
  410. return AVERROR_INVALIDDATA;
  411. }
  412. }
  413. if ((ret = ff_ffv1_allocate_initial_states(f)) < 0)
  414. return ret;
  415. for (i = 0; i < f->quant_table_count; i++)
  416. if (get_rac(c, state)) {
  417. for (j = 0; j < f->context_count[i]; j++)
  418. for (k = 0; k < CONTEXT_SIZE; k++) {
  419. int pred = j ? f->initial_states[i][j - 1][k] : 128;
  420. f->initial_states[i][j][k] =
  421. (pred + get_symbol(c, state2[k], 1)) & 0xFF;
  422. }
  423. }
  424. if (f->version > 2) {
  425. f->ec = get_symbol(c, state, 0);
  426. if (f->micro_version > 2)
  427. f->intra = get_symbol(c, state, 0);
  428. }
  429. if (f->version > 2) {
  430. unsigned v;
  431. v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0,
  432. f->avctx->extradata, f->avctx->extradata_size);
  433. if (v || f->avctx->extradata_size < 4) {
  434. av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", v);
  435. return AVERROR_INVALIDDATA;
  436. }
  437. crc = AV_RB32(f->avctx->extradata + f->avctx->extradata_size - 4);
  438. }
  439. if (f->avctx->debug & FF_DEBUG_PICT_INFO)
  440. av_log(f->avctx, AV_LOG_DEBUG,
  441. "global: ver:%d.%d, coder:%d, colorspace: %d bpr:%d chroma:%d(%d:%d), alpha:%d slices:%dx%d qtabs:%d ec:%d intra:%d CRC:0x%08X\n",
  442. f->version, f->micro_version,
  443. f->ac,
  444. f->colorspace,
  445. f->avctx->bits_per_raw_sample,
  446. f->chroma_planes, f->chroma_h_shift, f->chroma_v_shift,
  447. f->transparency,
  448. f->num_h_slices, f->num_v_slices,
  449. f->quant_table_count,
  450. f->ec,
  451. f->intra,
  452. crc
  453. );
  454. return 0;
  455. }
  456. static int read_header(FFV1Context *f)
  457. {
  458. uint8_t state[CONTEXT_SIZE];
  459. int i, j, context_count = -1; //-1 to avoid warning
  460. RangeCoder *const c = &f->slice_context[0]->c;
  461. memset(state, 128, sizeof(state));
  462. if (f->version < 2) {
  463. int chroma_planes, chroma_h_shift, chroma_v_shift, transparency, colorspace, bits_per_raw_sample;
  464. unsigned v= get_symbol(c, state, 0);
  465. if (v >= 2) {
  466. av_log(f->avctx, AV_LOG_ERROR, "invalid version %d in ver01 header\n", v);
  467. return AVERROR_INVALIDDATA;
  468. }
  469. f->version = v;
  470. f->ac = get_symbol(c, state, 0);
  471. if (f->ac == AC_RANGE_CUSTOM_TAB) {
  472. for (i = 1; i < 256; i++)
  473. f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i];
  474. }
  475. colorspace = get_symbol(c, state, 0); //YUV cs type
  476. bits_per_raw_sample = f->version > 0 ? get_symbol(c, state, 0) : f->avctx->bits_per_raw_sample;
  477. chroma_planes = get_rac(c, state);
  478. chroma_h_shift = get_symbol(c, state, 0);
  479. chroma_v_shift = get_symbol(c, state, 0);
  480. transparency = get_rac(c, state);
  481. if (colorspace == 0 && f->avctx->skip_alpha)
  482. transparency = 0;
  483. if (f->plane_count) {
  484. if (colorspace != f->colorspace ||
  485. bits_per_raw_sample != f->avctx->bits_per_raw_sample ||
  486. chroma_planes != f->chroma_planes ||
  487. chroma_h_shift != f->chroma_h_shift ||
  488. chroma_v_shift != f->chroma_v_shift ||
  489. transparency != f->transparency) {
  490. av_log(f->avctx, AV_LOG_ERROR, "Invalid change of global parameters\n");
  491. return AVERROR_INVALIDDATA;
  492. }
  493. }
  494. if (chroma_h_shift > 4U || chroma_v_shift > 4U) {
  495. av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n",
  496. chroma_h_shift, chroma_v_shift);
  497. return AVERROR_INVALIDDATA;
  498. }
  499. f->colorspace = colorspace;
  500. f->avctx->bits_per_raw_sample = bits_per_raw_sample;
  501. f->chroma_planes = chroma_planes;
  502. f->chroma_h_shift = chroma_h_shift;
  503. f->chroma_v_shift = chroma_v_shift;
  504. f->transparency = transparency;
  505. f->plane_count = 2 + f->transparency;
  506. }
  507. if (f->colorspace == 0) {
  508. if (!f->transparency && !f->chroma_planes) {
  509. if (f->avctx->bits_per_raw_sample <= 8)
  510. f->avctx->pix_fmt = AV_PIX_FMT_GRAY8;
  511. else if (f->avctx->bits_per_raw_sample == 10) {
  512. f->packed_at_lsb = 1;
  513. f->avctx->pix_fmt = AV_PIX_FMT_GRAY10;
  514. } else if (f->avctx->bits_per_raw_sample == 12) {
  515. f->packed_at_lsb = 1;
  516. f->avctx->pix_fmt = AV_PIX_FMT_GRAY12;
  517. } else if (f->avctx->bits_per_raw_sample == 16) {
  518. f->packed_at_lsb = 1;
  519. f->avctx->pix_fmt = AV_PIX_FMT_GRAY16;
  520. } else if (f->avctx->bits_per_raw_sample < 16) {
  521. f->avctx->pix_fmt = AV_PIX_FMT_GRAY16;
  522. } else
  523. return AVERROR(ENOSYS);
  524. } else if (f->transparency && !f->chroma_planes) {
  525. if (f->avctx->bits_per_raw_sample <= 8)
  526. f->avctx->pix_fmt = AV_PIX_FMT_YA8;
  527. else
  528. return AVERROR(ENOSYS);
  529. } else if (f->avctx->bits_per_raw_sample<=8 && !f->transparency) {
  530. switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
  531. case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P; break;
  532. case 0x01: f->avctx->pix_fmt = AV_PIX_FMT_YUV440P; break;
  533. case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P; break;
  534. case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P; break;
  535. case 0x20: f->avctx->pix_fmt = AV_PIX_FMT_YUV411P; break;
  536. case 0x22: f->avctx->pix_fmt = AV_PIX_FMT_YUV410P; break;
  537. }
  538. } else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency) {
  539. switch(16*f->chroma_h_shift + f->chroma_v_shift) {
  540. case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P; break;
  541. case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P; break;
  542. case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P; break;
  543. }
  544. } else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency) {
  545. f->packed_at_lsb = 1;
  546. switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
  547. case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P9; break;
  548. case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P9; break;
  549. case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P9; break;
  550. }
  551. } else if (f->avctx->bits_per_raw_sample == 9 && f->transparency) {
  552. f->packed_at_lsb = 1;
  553. switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
  554. case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P9; break;
  555. case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P9; break;
  556. case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P9; break;
  557. }
  558. } else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency) {
  559. f->packed_at_lsb = 1;
  560. switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
  561. case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P10; break;
  562. case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P10; break;
  563. case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P10; break;
  564. }
  565. } else if (f->avctx->bits_per_raw_sample == 10 && f->transparency) {
  566. f->packed_at_lsb = 1;
  567. switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
  568. case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P10; break;
  569. case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P10; break;
  570. case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P10; break;
  571. }
  572. } else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency) {
  573. f->packed_at_lsb = 1;
  574. switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
  575. case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P12; break;
  576. case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P12; break;
  577. case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P12; break;
  578. }
  579. } else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency){
  580. f->packed_at_lsb = 1;
  581. switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
  582. case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P16; break;
  583. case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P16; break;
  584. case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P16; break;
  585. }
  586. } else if (f->avctx->bits_per_raw_sample == 16 && f->transparency){
  587. f->packed_at_lsb = 1;
  588. switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
  589. case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P16; break;
  590. case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P16; break;
  591. case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P16; break;
  592. }
  593. }
  594. } else if (f->colorspace == 1) {
  595. if (f->chroma_h_shift || f->chroma_v_shift) {
  596. av_log(f->avctx, AV_LOG_ERROR,
  597. "chroma subsampling not supported in this colorspace\n");
  598. return AVERROR(ENOSYS);
  599. }
  600. if ( f->avctx->bits_per_raw_sample <= 8 && !f->transparency)
  601. f->avctx->pix_fmt = AV_PIX_FMT_0RGB32;
  602. else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency)
  603. f->avctx->pix_fmt = AV_PIX_FMT_RGB32;
  604. else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency)
  605. f->avctx->pix_fmt = AV_PIX_FMT_GBRP9;
  606. else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency)
  607. f->avctx->pix_fmt = AV_PIX_FMT_GBRP10;
  608. else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency)
  609. f->avctx->pix_fmt = AV_PIX_FMT_GBRP12;
  610. else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency)
  611. f->avctx->pix_fmt = AV_PIX_FMT_GBRP14;
  612. else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency) {
  613. f->avctx->pix_fmt = AV_PIX_FMT_GBRP16;
  614. f->use32bit = 1;
  615. }
  616. else if (f->avctx->bits_per_raw_sample == 16 && f->transparency) {
  617. f->avctx->pix_fmt = AV_PIX_FMT_GBRAP16;
  618. f->use32bit = 1;
  619. }
  620. } else {
  621. av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n");
  622. return AVERROR(ENOSYS);
  623. }
  624. if (f->avctx->pix_fmt == AV_PIX_FMT_NONE) {
  625. av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");
  626. return AVERROR(ENOSYS);
  627. }
  628. ff_dlog(f->avctx, "%d %d %d\n",
  629. f->chroma_h_shift, f->chroma_v_shift, f->avctx->pix_fmt);
  630. if (f->version < 2) {
  631. context_count = read_quant_tables(c, f->quant_table);
  632. if (context_count < 0) {
  633. av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
  634. return AVERROR_INVALIDDATA;
  635. }
  636. f->slice_count = f->max_slice_count;
  637. } else if (f->version < 3) {
  638. f->slice_count = get_symbol(c, state, 0);
  639. } else {
  640. const uint8_t *p = c->bytestream_end;
  641. for (f->slice_count = 0;
  642. f->slice_count < MAX_SLICES && 3 + 5*!!f->ec < p - c->bytestream_start;
  643. f->slice_count++) {
  644. int trailer = 3 + 5*!!f->ec;
  645. int size = AV_RB24(p-trailer);
  646. if (size + trailer > p - c->bytestream_start)
  647. break;
  648. p -= size + trailer;
  649. }
  650. }
  651. if (f->slice_count > (unsigned)MAX_SLICES || f->slice_count <= 0 || f->slice_count > f->max_slice_count) {
  652. av_log(f->avctx, AV_LOG_ERROR, "slice count %d is invalid (max=%d)\n", f->slice_count, f->max_slice_count);
  653. return AVERROR_INVALIDDATA;
  654. }
  655. for (j = 0; j < f->slice_count; j++) {
  656. FFV1Context *fs = f->slice_context[j];
  657. fs->ac = f->ac;
  658. fs->packed_at_lsb = f->packed_at_lsb;
  659. fs->slice_damaged = 0;
  660. if (f->version == 2) {
  661. fs->slice_x = get_symbol(c, state, 0) * f->width ;
  662. fs->slice_y = get_symbol(c, state, 0) * f->height;
  663. fs->slice_width = (get_symbol(c, state, 0) + 1) * f->width + fs->slice_x;
  664. fs->slice_height = (get_symbol(c, state, 0) + 1) * f->height + fs->slice_y;
  665. fs->slice_x /= f->num_h_slices;
  666. fs->slice_y /= f->num_v_slices;
  667. fs->slice_width = fs->slice_width / f->num_h_slices - fs->slice_x;
  668. fs->slice_height = fs->slice_height / f->num_v_slices - fs->slice_y;
  669. if ((unsigned)fs->slice_width > f->width ||
  670. (unsigned)fs->slice_height > f->height)
  671. return AVERROR_INVALIDDATA;
  672. if ( (unsigned)fs->slice_x + (uint64_t)fs->slice_width > f->width
  673. || (unsigned)fs->slice_y + (uint64_t)fs->slice_height > f->height)
  674. return AVERROR_INVALIDDATA;
  675. }
  676. for (i = 0; i < f->plane_count; i++) {
  677. PlaneContext *const p = &fs->plane[i];
  678. if (f->version == 2) {
  679. int idx = get_symbol(c, state, 0);
  680. if (idx > (unsigned)f->quant_table_count) {
  681. av_log(f->avctx, AV_LOG_ERROR,
  682. "quant_table_index out of range\n");
  683. return AVERROR_INVALIDDATA;
  684. }
  685. p->quant_table_index = idx;
  686. memcpy(p->quant_table, f->quant_tables[idx],
  687. sizeof(p->quant_table));
  688. context_count = f->context_count[idx];
  689. } else {
  690. memcpy(p->quant_table, f->quant_table, sizeof(p->quant_table));
  691. }
  692. if (f->version <= 2) {
  693. av_assert0(context_count >= 0);
  694. if (p->context_count < context_count) {
  695. av_freep(&p->state);
  696. av_freep(&p->vlc_state);
  697. }
  698. p->context_count = context_count;
  699. }
  700. }
  701. }
  702. return 0;
  703. }
  704. static av_cold int decode_init(AVCodecContext *avctx)
  705. {
  706. FFV1Context *f = avctx->priv_data;
  707. int ret;
  708. if ((ret = ff_ffv1_common_init(avctx)) < 0)
  709. return ret;
  710. if (avctx->extradata_size > 0 && (ret = read_extra_header(f)) < 0)
  711. return ret;
  712. if ((ret = ff_ffv1_init_slice_contexts(f)) < 0)
  713. return ret;
  714. avctx->internal->allocate_progress = 1;
  715. return 0;
  716. }
  717. static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
  718. {
  719. uint8_t *buf = avpkt->data;
  720. int buf_size = avpkt->size;
  721. FFV1Context *f = avctx->priv_data;
  722. RangeCoder *const c = &f->slice_context[0]->c;
  723. int i, ret;
  724. uint8_t keystate = 128;
  725. uint8_t *buf_p;
  726. AVFrame *p;
  727. if (f->last_picture.f)
  728. ff_thread_release_buffer(avctx, &f->last_picture);
  729. FFSWAP(ThreadFrame, f->picture, f->last_picture);
  730. f->cur = p = f->picture.f;
  731. if (f->version < 3 && avctx->field_order > AV_FIELD_PROGRESSIVE) {
  732. /* we have interlaced material flagged in container */
  733. p->interlaced_frame = 1;
  734. if (avctx->field_order == AV_FIELD_TT || avctx->field_order == AV_FIELD_TB)
  735. p->top_field_first = 1;
  736. }
  737. f->avctx = avctx;
  738. ff_init_range_decoder(c, buf, buf_size);
  739. ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);
  740. p->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P
  741. if (get_rac(c, &keystate)) {
  742. p->key_frame = 1;
  743. f->key_frame_ok = 0;
  744. if ((ret = read_header(f)) < 0)
  745. return ret;
  746. f->key_frame_ok = 1;
  747. } else {
  748. if (!f->key_frame_ok) {
  749. av_log(avctx, AV_LOG_ERROR,
  750. "Cannot decode non-keyframe without valid keyframe\n");
  751. return AVERROR_INVALIDDATA;
  752. }
  753. p->key_frame = 0;
  754. }
  755. if ((ret = ff_thread_get_buffer(avctx, &f->picture, AV_GET_BUFFER_FLAG_REF)) < 0)
  756. return ret;
  757. if (avctx->debug & FF_DEBUG_PICT_INFO)
  758. av_log(avctx, AV_LOG_DEBUG, "ver:%d keyframe:%d coder:%d ec:%d slices:%d bps:%d\n",
  759. f->version, p->key_frame, f->ac, f->ec, f->slice_count, f->avctx->bits_per_raw_sample);
  760. ff_thread_finish_setup(avctx);
  761. buf_p = buf + buf_size;
  762. for (i = f->slice_count - 1; i >= 0; i--) {
  763. FFV1Context *fs = f->slice_context[i];
  764. int trailer = 3 + 5*!!f->ec;
  765. int v;
  766. if (i || f->version > 2) v = AV_RB24(buf_p-trailer) + trailer;
  767. else v = buf_p - c->bytestream_start;
  768. if (buf_p - c->bytestream_start < v) {
  769. av_log(avctx, AV_LOG_ERROR, "Slice pointer chain broken\n");
  770. ff_thread_report_progress(&f->picture, INT_MAX, 0);
  771. return AVERROR_INVALIDDATA;
  772. }
  773. buf_p -= v;
  774. if (f->ec) {
  775. unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, buf_p, v);
  776. if (crc) {
  777. int64_t ts = avpkt->pts != AV_NOPTS_VALUE ? avpkt->pts : avpkt->dts;
  778. av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!", crc);
  779. if (ts != AV_NOPTS_VALUE && avctx->pkt_timebase.num) {
  780. av_log(f->avctx, AV_LOG_ERROR, "at %f seconds\n", ts*av_q2d(avctx->pkt_timebase));
  781. } else if (ts != AV_NOPTS_VALUE) {
  782. av_log(f->avctx, AV_LOG_ERROR, "at %"PRId64"\n", ts);
  783. } else {
  784. av_log(f->avctx, AV_LOG_ERROR, "\n");
  785. }
  786. fs->slice_damaged = 1;
  787. }
  788. if (avctx->debug & FF_DEBUG_PICT_INFO) {
  789. av_log(avctx, AV_LOG_DEBUG, "slice %d, CRC: 0x%08"PRIX32"\n", i, AV_RB32(buf_p + v - 4));
  790. }
  791. }
  792. if (i) {
  793. ff_init_range_decoder(&fs->c, buf_p, v);
  794. } else
  795. fs->c.bytestream_end = buf_p + v;
  796. fs->avctx = avctx;
  797. fs->cur = p;
  798. }
  799. avctx->execute(avctx,
  800. decode_slice,
  801. &f->slice_context[0],
  802. NULL,
  803. f->slice_count,
  804. sizeof(void*));
  805. for (i = f->slice_count - 1; i >= 0; i--) {
  806. FFV1Context *fs = f->slice_context[i];
  807. int j;
  808. if (fs->slice_damaged && f->last_picture.f->data[0]) {
  809. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
  810. const uint8_t *src[4];
  811. uint8_t *dst[4];
  812. ff_thread_await_progress(&f->last_picture, INT_MAX, 0);
  813. for (j = 0; j < desc->nb_components; j++) {
  814. int pixshift = desc->comp[j].depth > 8;
  815. int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0;
  816. int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0;
  817. dst[j] = p->data[j] + p->linesize[j] *
  818. (fs->slice_y >> sv) + ((fs->slice_x >> sh) << pixshift);
  819. src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j] *
  820. (fs->slice_y >> sv) + ((fs->slice_x >> sh) << pixshift);
  821. }
  822. if (desc->flags & AV_PIX_FMT_FLAG_PAL ||
  823. desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
  824. dst[1] = p->data[1];
  825. src[1] = f->last_picture.f->data[1];
  826. }
  827. av_image_copy(dst, p->linesize, src,
  828. f->last_picture.f->linesize,
  829. avctx->pix_fmt,
  830. fs->slice_width,
  831. fs->slice_height);
  832. }
  833. }
  834. ff_thread_report_progress(&f->picture, INT_MAX, 0);
  835. f->picture_number++;
  836. if (f->last_picture.f)
  837. ff_thread_release_buffer(avctx, &f->last_picture);
  838. f->cur = NULL;
  839. if ((ret = av_frame_ref(data, f->picture.f)) < 0)
  840. return ret;
  841. *got_frame = 1;
  842. return buf_size;
  843. }
  844. #if HAVE_THREADS
  845. static int init_thread_copy(AVCodecContext *avctx)
  846. {
  847. FFV1Context *f = avctx->priv_data;
  848. int i, ret;
  849. f->picture.f = NULL;
  850. f->last_picture.f = NULL;
  851. f->sample_buffer = NULL;
  852. f->max_slice_count = 0;
  853. f->slice_count = 0;
  854. for (i = 0; i < f->quant_table_count; i++) {
  855. av_assert0(f->version > 1);
  856. f->initial_states[i] = av_memdup(f->initial_states[i],
  857. f->context_count[i] * sizeof(*f->initial_states[i]));
  858. }
  859. f->picture.f = av_frame_alloc();
  860. f->last_picture.f = av_frame_alloc();
  861. if ((ret = ff_ffv1_init_slice_contexts(f)) < 0)
  862. return ret;
  863. return 0;
  864. }
  865. #endif
  866. static void copy_fields(FFV1Context *fsdst, FFV1Context *fssrc, FFV1Context *fsrc)
  867. {
  868. fsdst->version = fsrc->version;
  869. fsdst->micro_version = fsrc->micro_version;
  870. fsdst->chroma_planes = fsrc->chroma_planes;
  871. fsdst->chroma_h_shift = fsrc->chroma_h_shift;
  872. fsdst->chroma_v_shift = fsrc->chroma_v_shift;
  873. fsdst->transparency = fsrc->transparency;
  874. fsdst->plane_count = fsrc->plane_count;
  875. fsdst->ac = fsrc->ac;
  876. fsdst->colorspace = fsrc->colorspace;
  877. fsdst->ec = fsrc->ec;
  878. fsdst->intra = fsrc->intra;
  879. fsdst->slice_damaged = fssrc->slice_damaged;
  880. fsdst->key_frame_ok = fsrc->key_frame_ok;
  881. fsdst->bits_per_raw_sample = fsrc->bits_per_raw_sample;
  882. fsdst->packed_at_lsb = fsrc->packed_at_lsb;
  883. fsdst->slice_count = fsrc->slice_count;
  884. if (fsrc->version<3){
  885. fsdst->slice_x = fssrc->slice_x;
  886. fsdst->slice_y = fssrc->slice_y;
  887. fsdst->slice_width = fssrc->slice_width;
  888. fsdst->slice_height = fssrc->slice_height;
  889. }
  890. }
  891. #if HAVE_THREADS
  892. static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
  893. {
  894. FFV1Context *fsrc = src->priv_data;
  895. FFV1Context *fdst = dst->priv_data;
  896. int i, ret;
  897. if (dst == src)
  898. return 0;
  899. {
  900. ThreadFrame picture = fdst->picture, last_picture = fdst->last_picture;
  901. uint8_t (*initial_states[MAX_QUANT_TABLES])[32];
  902. struct FFV1Context *slice_context[MAX_SLICES];
  903. memcpy(initial_states, fdst->initial_states, sizeof(fdst->initial_states));
  904. memcpy(slice_context, fdst->slice_context , sizeof(fdst->slice_context));
  905. memcpy(fdst, fsrc, sizeof(*fdst));
  906. memcpy(fdst->initial_states, initial_states, sizeof(fdst->initial_states));
  907. memcpy(fdst->slice_context, slice_context , sizeof(fdst->slice_context));
  908. fdst->picture = picture;
  909. fdst->last_picture = last_picture;
  910. for (i = 0; i<fdst->num_h_slices * fdst->num_v_slices; i++) {
  911. FFV1Context *fssrc = fsrc->slice_context[i];
  912. FFV1Context *fsdst = fdst->slice_context[i];
  913. copy_fields(fsdst, fssrc, fsrc);
  914. }
  915. av_assert0(!fdst->plane[0].state);
  916. av_assert0(!fdst->sample_buffer);
  917. }
  918. av_assert1(fdst->max_slice_count == fsrc->max_slice_count);
  919. ff_thread_release_buffer(dst, &fdst->picture);
  920. if (fsrc->picture.f->data[0]) {
  921. if ((ret = ff_thread_ref_frame(&fdst->picture, &fsrc->picture)) < 0)
  922. return ret;
  923. }
  924. fdst->fsrc = fsrc;
  925. return 0;
  926. }
  927. #endif
  928. AVCodec ff_ffv1_decoder = {
  929. .name = "ffv1",
  930. .long_name = NULL_IF_CONFIG_SMALL("FFmpeg video codec #1"),
  931. .type = AVMEDIA_TYPE_VIDEO,
  932. .id = AV_CODEC_ID_FFV1,
  933. .priv_data_size = sizeof(FFV1Context),
  934. .init = decode_init,
  935. .close = ff_ffv1_close,
  936. .decode = decode_frame,
  937. .init_thread_copy = ONLY_IF_THREADS_ENABLED(init_thread_copy),
  938. .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
  939. .capabilities = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/ |
  940. AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
  941. .caps_internal = FF_CODEC_CAP_INIT_CLEANUP
  942. };