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.

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