You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avfilter/vf_v360: reduce allocations by reusing duplicated remaps
This commit is contained in:
@@ -97,9 +97,11 @@ typedef struct V360Context {
|
|||||||
int planewidth[4], planeheight[4];
|
int planewidth[4], planeheight[4];
|
||||||
int inplanewidth[4], inplaneheight[4];
|
int inplanewidth[4], inplaneheight[4];
|
||||||
int nb_planes;
|
int nb_planes;
|
||||||
|
int nb_allocated;
|
||||||
|
|
||||||
uint16_t *u[4], *v[4];
|
uint16_t *u[4], *v[4];
|
||||||
int16_t *ker[4];
|
int16_t *ker[4];
|
||||||
|
unsigned map[4];
|
||||||
|
|
||||||
int (*remap_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
|
int (*remap_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
|
||||||
|
|
||||||
|
@@ -219,9 +219,10 @@ static int remap##ws##_##bits##bit_slice(AVFilterContext *ctx, void *arg, int jo
|
|||||||
const int slice_end = (height * (jobnr + 1)) / nb_jobs; \
|
const int slice_end = (height * (jobnr + 1)) / nb_jobs; \
|
||||||
\
|
\
|
||||||
for (int y = slice_start; y < slice_end; y++) { \
|
for (int y = slice_start; y < slice_end; y++) { \
|
||||||
const uint16_t *u = s->u[plane] + y * width * ws * ws; \
|
const unsigned map = s->map[plane]; \
|
||||||
const uint16_t *v = s->v[plane] + y * width * ws * ws; \
|
const uint16_t *u = s->u[map] + y * width * ws * ws; \
|
||||||
const int16_t *ker = s->ker[plane] + y * width * ws * ws; \
|
const uint16_t *v = s->v[map] + y * width * ws * ws; \
|
||||||
|
const int16_t *ker = s->ker[map] + y * width * ws * ws; \
|
||||||
\
|
\
|
||||||
s->remap_line(dst + y * out_linesize, width, src, in_linesize, u, v, ker); \
|
s->remap_line(dst + y * out_linesize, width, src, in_linesize, u, v, ker); \
|
||||||
} \
|
} \
|
||||||
@@ -1911,6 +1912,21 @@ static inline void mirror(const float *modifier, float *vec)
|
|||||||
vec[2] *= modifier[2];
|
vec[2] *= modifier[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int allocate_plane(V360Context *s, int sizeof_uv, int sizeof_ker, int p)
|
||||||
|
{
|
||||||
|
s->u[p] = av_calloc(s->planewidth[p] * s->planeheight[p], sizeof_uv);
|
||||||
|
s->v[p] = av_calloc(s->planewidth[p] * s->planeheight[p], sizeof_uv);
|
||||||
|
if (!s->u[p] || !s->v[p])
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
if (sizeof_ker) {
|
||||||
|
s->ker[p] = av_calloc(s->planewidth[p] * s->planeheight[p], sizeof_ker);
|
||||||
|
if (!s->ker[p])
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int config_output(AVFilterLink *outlink)
|
static int config_output(AVFilterLink *outlink)
|
||||||
{
|
{
|
||||||
AVFilterContext *ctx = outlink->src;
|
AVFilterContext *ctx = outlink->src;
|
||||||
@@ -2103,23 +2119,33 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
s->inplanewidth[0] = s->inplanewidth[3] = inlink->w;
|
s->inplanewidth[0] = s->inplanewidth[3] = inlink->w;
|
||||||
s->nb_planes = av_pix_fmt_count_planes(inlink->format);
|
s->nb_planes = av_pix_fmt_count_planes(inlink->format);
|
||||||
|
|
||||||
for (p = 0; p < s->nb_planes; p++) {
|
if (desc->log2_chroma_h == desc->log2_chroma_w && desc->log2_chroma_h == 0) {
|
||||||
s->u[p] = av_calloc(s->planewidth[p] * s->planeheight[p], sizeof_uv);
|
s->nb_allocated = 1;
|
||||||
s->v[p] = av_calloc(s->planewidth[p] * s->planeheight[p], sizeof_uv);
|
s->map[0] = s->map[1] = s->map[2] = s->map[3] = 0;
|
||||||
if (!s->u[p] || !s->v[p])
|
allocate_plane(s, sizeof_uv, sizeof_ker, 0);
|
||||||
return AVERROR(ENOMEM);
|
} else if (desc->log2_chroma_h == desc->log2_chroma_w) {
|
||||||
if (sizeof_ker) {
|
s->nb_allocated = 2;
|
||||||
s->ker[p] = av_calloc(s->planewidth[p] * s->planeheight[p], sizeof_ker);
|
s->map[0] = 0;
|
||||||
if (!s->ker[p])
|
s->map[1] = s->map[2] = 1;
|
||||||
return AVERROR(ENOMEM);
|
s->map[3] = 0;
|
||||||
}
|
allocate_plane(s, sizeof_uv, sizeof_ker, 0);
|
||||||
|
allocate_plane(s, sizeof_uv, sizeof_ker, 1);
|
||||||
|
} else {
|
||||||
|
s->nb_allocated = 3;
|
||||||
|
s->map[0] = 0;
|
||||||
|
s->map[1] = 1;
|
||||||
|
s->map[2] = 2;
|
||||||
|
s->map[3] = 0;
|
||||||
|
allocate_plane(s, sizeof_uv, sizeof_ker, 0);
|
||||||
|
allocate_plane(s, sizeof_uv, sizeof_ker, 1);
|
||||||
|
allocate_plane(s, sizeof_uv, sizeof_ker, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
calculate_rotation_matrix(s->yaw, s->pitch, s->roll, rot_mat);
|
calculate_rotation_matrix(s->yaw, s->pitch, s->roll, rot_mat);
|
||||||
set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, mirror_modifier);
|
set_mirror_modifier(s->h_flip, s->v_flip, s->d_flip, mirror_modifier);
|
||||||
|
|
||||||
// Calculate remap data
|
// Calculate remap data
|
||||||
for (p = 0; p < s->nb_planes; p++) {
|
for (p = 0; p < s->nb_allocated; p++) {
|
||||||
const int width = s->planewidth[p];
|
const int width = s->planewidth[p];
|
||||||
const int height = s->planeheight[p];
|
const int height = s->planeheight[p];
|
||||||
const int in_width = s->inplanewidth[p];
|
const int in_width = s->inplanewidth[p];
|
||||||
@@ -2176,7 +2202,7 @@ static av_cold void uninit(AVFilterContext *ctx)
|
|||||||
V360Context *s = ctx->priv;
|
V360Context *s = ctx->priv;
|
||||||
int p;
|
int p;
|
||||||
|
|
||||||
for (p = 0; p < s->nb_planes; p++) {
|
for (p = 0; p < s->nb_allocated; p++) {
|
||||||
av_freep(&s->u[p]);
|
av_freep(&s->u[p]);
|
||||||
av_freep(&s->v[p]);
|
av_freep(&s->v[p]);
|
||||||
av_freep(&s->ker[p]);
|
av_freep(&s->ker[p]);
|
||||||
|
Reference in New Issue
Block a user