...
 
Commits (2)
......@@ -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 @@ uint8_t * dav1d_data_create(Dav1dData *const buf, const size_t sz) {
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 @@ void dav1d_data_move_ref(Dav1dData *const dst, Dav1dData *const src) {
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) {
......
......@@ -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__ */
......@@ -3002,7 +3002,7 @@ error:
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 @@ error:
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 @@ int dav1d_submit_frame(Dav1dContext *const c) {
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,17 +3384,17 @@ error:
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);
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) {
......
......@@ -198,7 +198,7 @@ int dav1d_parse_sequence_header(Dav1dSequenceHeader *const out,
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 @@ int dav1d_parse_sequence_header(Dav1dSequenceHeader *const out,
res = 0;
error:
dav1d_data_unref(&buf);
dav1d_data_unref_internal(&buf);
dav1d_close(&c);
return res;
......@@ -257,8 +257,8 @@ static int output_image(Dav1dContext *const c, Dav1dPicture *const out,
// 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 @@ static int output_image(Dav1dContext *const c, Dav1dPicture *const out,
assert(0);
}
dav1d_picture_unref(in);
dav1d_picture_unref_internal(in);
return 0;
}
......@@ -290,7 +290,7 @@ static int output_picture_ready(Dav1dContext *const c) {
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 @@ int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out)
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 @@ int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out)
}
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 @@ void dav1d_close(Dav1dContext **const c_out) {
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 @@ void dav1d_close(Dav1dContext **const c_out) {
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])
......@@ -503,3 +503,24 @@ void dav1d_close(Dav1dContext **const c_out) {
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);
}
......@@ -1283,7 +1283,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
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 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
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;
......
......@@ -224,7 +224,7 @@ void dav1d_thread_picture_ref(Dav1dThreadPicture *dst,
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_picture_unref(Dav1dPicture *const p) {
}
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;
......
......@@ -109,5 +109,6 @@ void dav1d_thread_picture_signal(const Dav1dThreadPicture *p, int y,
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__ */
......@@ -205,8 +205,9 @@ static int decode_coefs(Dav1dTileContext *const t,
// residual and sign
int dc_sign = 1;
const int lossless = f->frame_hdr->segmentation.lossless[b->seg_id];
const uint16_t *const dq_tbl = ts->dq[b->seg_id][plane];
const uint8_t *const qm_tbl = f->qm[is_1d || *txtp == IDTX][tx][plane];
const uint8_t *const qm_tbl = f->qm[lossless || is_1d || *txtp == IDTX][tx][plane];
const int dq_shift = imax(0, t_dim->ctx - 2);
const int bitdepth = BITDEPTH == 8 ? 8 : f->cur.p.bpc;
const int cf_min = -(1 << (7 + bitdepth));
......