ref: ee8856ffeb4247375f6cce41c89090647ccad3ea
parent: b10771e9d6ab408b029b0cb5b22de8fa36e2f512
author: Henrik Gramner <gramner@twoorioles.com>
date: Wed Dec 19 17:22:03 EST 2018
Perform stack realignment in every API entry point Unlikely to cause problems in practice, but technically required since the compiler is free to use aligned AVX stores to zero local stack-allocated variables (when using the appropriate compiler flags) for example.
--- a/src/data.c
+++ b/src/data.c
@@ -39,7 +39,7 @@
#include "src/data.h"
#include "src/ref.h"
-uint8_t * dav1d_data_create(Dav1dData *const buf, const size_t sz) {
+uint8_t *dav1d_data_create_internal(Dav1dData *const buf, const size_t sz) {
validate_input_or_ret(buf != NULL, NULL);
buf->ref = dav1d_ref_create(sz);
@@ -53,9 +53,11 @@
return buf->ref->data;
}
-int dav1d_data_wrap(Dav1dData *const buf, const uint8_t *const ptr, const size_t sz,
- void (*free_callback)(const uint8_t *data, void *user_data),
- void *user_data)
+int dav1d_data_wrap_internal(Dav1dData *const buf, const uint8_t *const ptr,
+ const size_t sz,
+ void (*const free_callback)(const uint8_t *data,
+ void *user_data),
+ void *const user_data)
{
validate_input_or_ret(buf != NULL, -EINVAL);
validate_input_or_ret(ptr != NULL, -EINVAL);
@@ -84,7 +86,7 @@
memset(src, 0, sizeof(*src));
}
-void dav1d_data_unref(Dav1dData *const buf) {
+void dav1d_data_unref_internal(Dav1dData *const buf) {
validate_input(buf != NULL);
if (buf->ref) {
--- a/src/data.h
+++ b/src/data.h
@@ -35,4 +35,11 @@
*/
void dav1d_data_move_ref(Dav1dData *dst, Dav1dData *src);
+uint8_t *dav1d_data_create_internal(Dav1dData *buf, size_t sz);
+int dav1d_data_wrap_internal(Dav1dData *buf, const uint8_t *ptr, size_t sz,
+ void (*free_callback)(const uint8_t *data,
+ void *user_data),
+ void *user_data);
+void dav1d_data_unref_internal(Dav1dData *buf);
+
#endif /* __DAV1D_SRC_DATA_H__ */
--- a/src/decode.c
+++ b/src/decode.c
@@ -3002,7 +3002,7 @@
dav1d_ref_dec(&f->ref_mvs_ref[i]);
}
- dav1d_picture_unref(&f->cur);
+ dav1d_picture_unref_internal(&f->cur);
dav1d_thread_picture_unref(&f->sr_cur);
dav1d_cdf_thread_unref(&f->in_cdf);
if (f->frame_hdr->refresh_context) {
@@ -3016,7 +3016,7 @@
dav1d_ref_dec(&f->frame_hdr_ref);
for (int i = 0; i < f->n_tile_data; i++)
- dav1d_data_unref(&f->tile[i].data);
+ dav1d_data_unref_internal(&f->tile[i].data);
return retval;
}
@@ -3356,7 +3356,7 @@
if (c->n_fc == 1) {
const unsigned refresh_frame_flags = f->frame_hdr->refresh_frame_flags;
if ((res = dav1d_decode_frame(f)) < 0) {
- dav1d_picture_unref(&c->out);
+ dav1d_picture_unref_internal(&c->out);
for (int i = 0; i < 8; i++) {
if (refresh_frame_flags & (1 << i)) {
if (c->refs[i].p.p.data[0])
@@ -3384,10 +3384,10 @@
dav1d_ref_dec(&f->ref_mvs_ref[i]);
}
if (c->n_fc == 1)
- dav1d_picture_unref(&c->out);
+ dav1d_picture_unref_internal(&c->out);
else
dav1d_thread_picture_unref(out_delayed);
- dav1d_picture_unref(&f->cur);
+ dav1d_picture_unref_internal(&f->cur);
dav1d_thread_picture_unref(&f->sr_cur);
dav1d_ref_dec(&f->mvs_ref);
dav1d_ref_dec(&f->seq_hdr_ref);
@@ -3394,7 +3394,7 @@
dav1d_ref_dec(&f->frame_hdr_ref);
for (int i = 0; i < f->n_tile_data; i++)
- dav1d_data_unref(&f->tile[i].data);
+ dav1d_data_unref_internal(&f->tile[i].data);
f->n_tile_data = 0;
if (c->n_fc > 1) {
--- a/src/lib.c
+++ b/src/lib.c
@@ -198,7 +198,7 @@
if (res < 0) return res;
if (ptr) {
- res = dav1d_data_wrap(&buf, ptr, sz, dummy_free, NULL);
+ res = dav1d_data_wrap_internal(&buf, ptr, sz, dummy_free, NULL);
if (res < 0) goto error;
}
@@ -220,7 +220,7 @@
res = 0;
error:
- dav1d_data_unref(&buf);
+ dav1d_data_unref_internal(&buf);
dav1d_close(&c);
return res;
@@ -257,8 +257,8 @@
// Apply film grain to a new copy of the image to avoid corrupting refs
int res = dav1d_picture_alloc_copy(out, in->p.w, in);
if (res < 0) {
- dav1d_picture_unref(in);
- dav1d_picture_unref(out);
+ dav1d_picture_unref_internal(in);
+ dav1d_picture_unref_internal(out);
return res;
}
@@ -278,7 +278,7 @@
assert(0);
}
- dav1d_picture_unref(in);
+ dav1d_picture_unref_internal(in);
return 0;
}
@@ -290,7 +290,7 @@
if (c->operating_point_idc && !c->all_layers) {
const int max_spatial_id = ulog2(c->operating_point_idc >> 8);
if (max_spatial_id > c->out.frame_hdr->spatial_id) {
- dav1d_picture_unref(&c->out);
+ dav1d_picture_unref_internal(&c->out);
return 0;
}
}
@@ -346,12 +346,12 @@
while (in->sz > 0) {
res = dav1d_parse_obus(c, in, 0);
if (res < 0) {
- dav1d_data_unref(in);
+ dav1d_data_unref_internal(in);
} else {
assert((size_t)res <= in->sz);
in->sz -= res;
in->data += res;
- if (!in->sz) dav1d_data_unref(in);
+ if (!in->sz) dav1d_data_unref_internal(in);
}
if (output_picture_ready(c))
break;
@@ -369,7 +369,7 @@
}
void dav1d_flush(Dav1dContext *const c) {
- dav1d_data_unref(&c->in);
+ dav1d_data_unref_internal(&c->in);
c->drain = 0;
if (c->n_fc == 1) return;
@@ -482,7 +482,7 @@
dav1d_free_aligned(f->lf.lr_lpf_line);
}
dav1d_free_aligned(c->fc);
- dav1d_data_unref(&c->in);
+ dav1d_data_unref_internal(&c->in);
if (c->n_fc > 1) {
for (unsigned n = 0; n < c->n_fc; n++)
if (c->frame_thread.out_delayed[n].p.data[0])
@@ -490,7 +490,7 @@
free(c->frame_thread.out_delayed);
}
for (int n = 0; n < c->n_tile_data; n++)
- dav1d_data_unref(&c->tile[n].data);
+ dav1d_data_unref_internal(&c->tile[n].data);
for (int n = 0; n < 8; n++) {
dav1d_cdf_thread_unref(&c->cdf[n]);
if (c->refs[n].p.p.data[0])
@@ -502,4 +502,25 @@
dav1d_ref_dec(&c->frame_hdr_ref);
dav1d_freep_aligned(c_out);
+}
+
+void dav1d_picture_unref(Dav1dPicture *const p) {
+ dav1d_picture_unref_internal(p);
+}
+
+uint8_t *dav1d_data_create(Dav1dData *const buf, const size_t sz) {
+ return dav1d_data_create_internal(buf, sz);
+}
+
+int dav1d_data_wrap(Dav1dData *const buf, const uint8_t *const ptr,
+ const size_t sz,
+ void (*const free_callback)(const uint8_t *data,
+ void *user_data),
+ void *const user_data)
+{
+ return dav1d_data_wrap_internal(buf, ptr, sz, free_callback, user_data);
+}
+
+void dav1d_data_unref(Dav1dData *const buf) {
+ dav1d_data_unref_internal(buf);
}
--- a/src/obu.c
+++ b/src/obu.c
@@ -1283,7 +1283,7 @@
return res;
}
for (int n = 0; n < c->n_tile_data; n++)
- dav1d_data_unref(&c->tile[n].data);
+ dav1d_data_unref_internal(&c->tile[n].data);
c->n_tile_data = 0;
c->n_tiles = 0;
if (type != OBU_FRAME) {
@@ -1333,7 +1333,7 @@
c->tile[c->n_tile_data].start != c->n_tiles)
{
for (int i = 0; i <= c->n_tile_data; i++)
- dav1d_data_unref(&c->tile[i].data);
+ dav1d_data_unref_internal(&c->tile[i].data);
c->n_tile_data = 0;
c->n_tiles = 0;
goto error;
--- a/src/picture.c
+++ b/src/picture.c
@@ -224,7 +224,7 @@
dst->progress = src->progress;
}
-void dav1d_picture_unref(Dav1dPicture *const p) {
+void dav1d_picture_unref_internal(Dav1dPicture *const p) {
validate_input(p != NULL);
if (p->ref) {
@@ -237,7 +237,7 @@
}
void dav1d_thread_picture_unref(Dav1dThreadPicture *const p) {
- dav1d_picture_unref(&p->p);
+ dav1d_picture_unref_internal(&p->p);
p->t = NULL;
p->progress = NULL;
--- a/src/picture.h
+++ b/src/picture.h
@@ -109,5 +109,6 @@
int default_picture_allocator(Dav1dPicture *, void *cookie);
void default_picture_release(Dav1dPicture *, void *cookie);
+void dav1d_picture_unref_internal(Dav1dPicture *p);
#endif /* __DAV1D_SRC_PICTURE_H__ */