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.

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