This reduces memory requirements
Unified · Split
| @@ -233,6 +233,10 @@ av_cold void ff_ffv1_close(FFV1Context *s) · 232 unmodified lines | ||
| 233 | 233 | |
| 234 | 234 | av_freep(&sc->sample_buffer); |
| 235 | 235 | av_freep(&sc->sample_buffer32); |
| 236 | + for(int p = 0; p < 4 ; p++) { | |
| 237 | + av_freep(&sc->fltmap[p]); | |
| 238 | + av_freep(&sc->fltmap32[p]); | |
| 239 | + } | |
| 236 | 240 | |
| 237 | 241 | av_refstruct_unref(&sc->plane); |
| 238 | 242 | } |
| @@ -106,11 +106,10 @@ typedef struct FFV1SliceContext { · 105 unmodified lines | ||
| 106 | 106 | uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; |
| 107 | 107 | }; |
| 108 | 108 | }; |
| 109 | − union { | |
| 110 | − uint16_t bitmap [4][65536]; //float encode | |
| 111 | − uint16_t fltmap [4][65536]; //halffloat encode & decode | |
| 112 | − uint32_t fltmap32[4][65536]; //float decode | |
| 113 | − }; | |
| 109 | + | |
| 110 | + uint16_t *bitmap [4]; //float encode | |
| 111 | + uint16_t *fltmap [4]; //halffloat encode & decode | |
| 112 | + uint32_t *fltmap32[4]; //float decode | |
| 114 | 113 | struct Unit { |
| 115 | 114 | uint32_t val; //this is unneeded if you accept a dereference on each access |
| 116 | 115 | uint16_t ndx; |
| @@ -326,7 +326,7 @@ static int decode_remap(FFV1Context *f, FFV1SliceContext *sc) · 325 unmodified lines | ||
| 326 | 326 | } |
| 327 | 327 | if (i - 1 >= end) |
| 328 | 328 | break; |
| 329 | − if (j >= FF_ARRAY_ELEMS(sc->fltmap[p])) | |
| 329 | + if (j >= 65536 /*FF_ARRAY_ELEMS(sc->fltmap[p])*/) | |
| 330 | 330 | return AVERROR_INVALIDDATA; |
| 331 | 331 | if (end <= 0xFFFF) { |
| 332 | 332 | sc->fltmap [p][j++] = i ^ ((i& 0x8000) ? 0 : flip); |
| @@ -387,6 +387,22 @@ static int decode_slice(AVCodecContext *c, void *arg) · 54 unmodified lines | ||
| 387 | 387 | y = sc->slice_y; |
| 388 | 388 | |
| 389 | 389 | if (sc->remap) { |
| 390 | + for(int p = 0; p < 1 + 2*f->chroma_planes + f->transparency ; p++) { | |
| 391 | + if (f->avctx->bits_per_raw_sample == 32) { | |
| 392 | + if (!sc->fltmap32[p]) { | |
| 393 | + sc->fltmap32[p] = av_malloc_array(65536, sizeof(*sc->fltmap32[p])); | |
| 394 | + if (!sc->fltmap32[p]) | |
| 395 | + return AVERROR(ENOMEM); | |
| 396 | + } | |
| 397 | + } else { | |
| 398 | + if (!sc->fltmap[p]) { | |
| 399 | + sc->fltmap[p] = av_malloc_array(65536, sizeof(*sc->fltmap[p])); | |
| 400 | + if (!sc->fltmap[p]) | |
| 401 | + return AVERROR(ENOMEM); | |
| 402 | + } | |
| 403 | + } | |
| 404 | + } | |
| 405 | + | |
| 390 | 406 | ret = decode_remap(f, sc); |
| 391 | 407 | if (ret < 0) |
| 392 | 408 | return ret; |
| @@ -326,7 +326,7 @@ static void load_plane(FFV1Context *f, FFV1SliceContext *sc, · 325 unmodified lines | ||
| 326 | 326 | { |
| 327 | 327 | int x, y; |
| 328 | 328 | |
| 329 | − memset(sc->fltmap[remap_index], 0, sizeof(sc->fltmap[remap_index])); | |
| 329 | + memset(sc->fltmap[remap_index], 0, 65536 * sizeof(*sc->fltmap[remap_index])); | |
| 330 | 330 | |
| 331 | 331 | for (y = 0; y < h; y++) { |
| 332 | 332 | if (f->bits_per_raw_sample <= 8) { |
| @@ -1012,11 +1012,20 @@ static av_cold int encode_init_internal(AVCodecContext *avctx) · 679 unmodified lines | ||
| 1012 | 1012 | p->context_count = s->context_count[p->quant_table_index]; |
| 1013 | 1013 | } |
| 1014 | 1014 | av_assert0(s->remap_mode >= 0); |
| 1015 | − if (s->remap_mode && s->bits_per_raw_sample == 32) { | |
| 1015 | + if (s->remap_mode) { | |
| 1016 | 1016 | for (int p = 0; p < 1 + 2*s->chroma_planes + s->transparency ; p++) { |
| 1017 | − sc->unit[p] = av_malloc_array(sc->slice_width, sc->slice_height * sizeof(**sc->unit)); | |
| 1018 | − if (!sc->unit[p]) | |
| 1019 | − return AVERROR(ENOMEM); | |
| 1017 | + if (s->bits_per_raw_sample == 32) { | |
| 1018 | + sc->unit[p] = av_malloc_array(sc->slice_width, sc->slice_height * sizeof(**sc->unit)); | |
| 1019 | + if (!sc->unit[p]) | |
| 1020 | + return AVERROR(ENOMEM); | |
| 1021 | + sc->bitmap[p] = av_malloc_array(sc->slice_width * sc->slice_height, sizeof(*sc->bitmap[p])); | |
| 1022 | + if (!sc->bitmap[p]) | |
| 1023 | + return AVERROR(ENOMEM); | |
| 1024 | + } else { | |
| 1025 | + sc->fltmap[p] = av_malloc_array(65536, sizeof(*sc->fltmap[p])); | |
| 1026 | + if (!sc->fltmap[p]) | |
| 1027 | + return AVERROR(ENOMEM); | |
| 1028 | + } | |
| 1020 | 1029 | } |
| 1021 | 1030 | } |
| 1022 | 1031 | |
| @@ -1821,8 +1830,10 @@ static av_cold int encode_close(AVCodecContext *avctx) · 798 unmodified lines | ||
| 1821 | 1830 | for (int j = 0; j < s->max_slice_count; j++) { |
| 1822 | 1831 | FFV1SliceContext *sc = &s->slices[j]; |
| 1823 | 1832 | |
| 1824 | − for(int p = 0; p<4; p++) | |
| 1833 | + for(int p = 0; p<4; p++) { | |
| 1825 | 1834 | av_freep(&sc->unit[p]); |
| 1835 | + av_freep(&sc->bitmap[p]); | |
| 1836 | + } | |
| 1826 | 1837 | } |
| 1827 | 1838 | |
| 1828 | 1839 | av_freep(&avctx->stats_out); |
| @@ -134,7 +134,8 @@ static void RENAME(load_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc, · 133 unmodified lines | ||
| 134 | 134 | int x, y; |
| 135 | 135 | int transparency = f->transparency; |
| 136 | 136 | |
| 137 | − memset(sc->fltmap, 0, sizeof(sc->fltmap)); | |
| 137 | + for (int p = 0; p<3 + transparency; p++) | |
| 138 | + memset(sc->fltmap[p], 0, 65536 * sizeof(**sc->fltmap)); | |
| 138 | 139 | |
| 139 | 140 | for (y = 0; y < h; y++) { |
| 140 | 141 | for (x = 0; x < w; x++) { |