Commit f713e250 authored by James Almer's avatar James Almer

Add a DAV1D_ERR define to negate errno values when needed

parent 11da4086
Pipeline #6829 passed with stages
in 5 minutes and 57 seconds
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#ifndef DAV1D_COMMON_H #ifndef DAV1D_COMMON_H
#define DAV1D_COMMON_H #define DAV1D_COMMON_H
#include <errno.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
...@@ -47,6 +48,12 @@ ...@@ -47,6 +48,12 @@
#endif #endif
#endif #endif
#if EPERM > 0
#define DAV1D_ERR(e) (-(e)) ///< Negate POSIX error code.
#else
#define DAV1D_ERR(e) (e)
#endif
/** /**
* A reference-counted object wrapper for a user-configurable pointer. * A reference-counted object wrapper for a user-configurable pointer.
*/ */
......
...@@ -62,7 +62,7 @@ DAV1D_API uint8_t * dav1d_data_create(Dav1dData *data, size_t sz); ...@@ -62,7 +62,7 @@ DAV1D_API uint8_t * dav1d_data_create(Dav1dData *data, size_t sz);
* be the $cookie input argument to this function. * be the $cookie input argument to this function.
* @param cookie Opaque parameter passed to free_callback(). * @param cookie Opaque parameter passed to free_callback().
* *
* @return 0 on success. A negative errno value on error. * @return 0 on success. A negative DAV1D_ERR value on error.
*/ */
DAV1D_API int dav1d_data_wrap(Dav1dData *data, const uint8_t *buf, size_t sz, DAV1D_API int dav1d_data_wrap(Dav1dData *data, const uint8_t *buf, size_t sz,
void (*free_callback)(const uint8_t *buf, void *cookie), void (*free_callback)(const uint8_t *buf, void *cookie),
...@@ -87,7 +87,7 @@ DAV1D_API int dav1d_data_wrap(Dav1dData *data, const uint8_t *buf, size_t sz, ...@@ -87,7 +87,7 @@ DAV1D_API int dav1d_data_wrap(Dav1dData *data, const uint8_t *buf, size_t sz,
* function. * function.
* @param cookie Opaque parameter passed to $free_callback. * @param cookie Opaque parameter passed to $free_callback.
* *
* @return 0 on success. A negative errno value on error. * @return 0 on success. A negative DAV1D_ERR value on error.
*/ */
DAV1D_API int dav1d_data_wrap_user_data(Dav1dData *data, DAV1D_API int dav1d_data_wrap_user_data(Dav1dData *data,
const uint8_t *user_data, const uint8_t *user_data,
......
...@@ -90,7 +90,7 @@ DAV1D_API void dav1d_default_settings(Dav1dSettings *s); ...@@ -90,7 +90,7 @@ DAV1D_API void dav1d_default_settings(Dav1dSettings *s);
* @note The context must be freed using dav1d_close() when decoding is * @note The context must be freed using dav1d_close() when decoding is
* finished. * finished.
* *
* @return 0 on success, or < 0 (a negative errno code) on error. * @return 0 on success, or < 0 (a negative DAV1D_ERR code) on error.
*/ */
DAV1D_API int dav1d_open(Dav1dContext **c_out, const Dav1dSettings *s); DAV1D_API int dav1d_open(Dav1dContext **c_out, const Dav1dSettings *s);
...@@ -101,7 +101,7 @@ DAV1D_API int dav1d_open(Dav1dContext **c_out, const Dav1dSettings *s); ...@@ -101,7 +101,7 @@ DAV1D_API int dav1d_open(Dav1dContext **c_out, const Dav1dSettings *s);
* @param buf The data to be parser. * @param buf The data to be parser.
* @param sz Size of the data. * @param sz Size of the data.
* *
* @return 0 on success, or < 0 (a negative errno code) on error. * @return 0 on success, or < 0 (a negative DAV1D_ERR code) on error.
* *
* @note It is safe to feed this function data containing other OBUs than a * @note It is safe to feed this function data containing other OBUs than a
* Sequence Header, as they will simply be ignored. If there is more than * Sequence Header, as they will simply be ignored. If there is more than
...@@ -119,11 +119,11 @@ DAV1D_API int dav1d_parse_sequence_header(Dav1dSequenceHeader *out, ...@@ -119,11 +119,11 @@ DAV1D_API int dav1d_parse_sequence_header(Dav1dSequenceHeader *out,
* *
* @return * @return
* 0: Success, and the data was consumed. * 0: Success, and the data was consumed.
* -EAGAIN: The data can't be consumed. dav1d_get_picture() should be called * DAV1D_ERR(EAGAIN): The data can't be consumed. dav1d_get_picture() should
* to get one or more frames before the function can consume new * be called to get one or more frames before the function
* data. * can consume new data.
* other negative errno codes: Error during decoding or because of invalid * other negative DAV1D_ERR codes: Error during decoding or because of invalid
* passed-in arguments. * passed-in arguments.
*/ */
DAV1D_API int dav1d_send_data(Dav1dContext *c, Dav1dData *in); DAV1D_API int dav1d_send_data(Dav1dContext *c, Dav1dData *in);
...@@ -136,10 +136,10 @@ DAV1D_API int dav1d_send_data(Dav1dContext *c, Dav1dData *in); ...@@ -136,10 +136,10 @@ DAV1D_API int dav1d_send_data(Dav1dContext *c, Dav1dData *in);
* *
* @return * @return
* 0: Success, and a frame is returned. * 0: Success, and a frame is returned.
* -EAGAIN: Not enough data to output a frame. dav1d_send_data() should be * DAV1D_ERR(EAGAIN): Not enough data to output a frame. dav1d_send_data()
* called with new input. * should be called with new input.
* other negative errno codes: Error during decoding or because of invalid * other negative DAV1D_ERR codes: Error during decoding or because of invalid
* passed-in arguments. * passed-in arguments.
* *
* @note To drain buffered frames from the decoder (i.e. on end of stream), * @note To drain buffered frames from the decoder (i.e. on end of stream),
* call this function until it returns -EAGAIN. * call this function until it returns -EAGAIN.
......
...@@ -109,7 +109,7 @@ typedef struct Dav1dPicAllocator { ...@@ -109,7 +109,7 @@ typedef struct Dav1dPicAllocator {
* *
* @note No fields other than data, stride and allocator_data must be filled * @note No fields other than data, stride and allocator_data must be filled
* by this callback. * by this callback.
* @return 0 on success. A negative errno value on error. * @return 0 on success. A negative DAV1D_ERR value on error.
*/ */
int (*alloc_picture_callback)(Dav1dPicture *pic, void *cookie); int (*alloc_picture_callback)(Dav1dPicture *pic, void *cookie);
/** /**
......
...@@ -30,7 +30,7 @@ project('dav1d', ['c'], ...@@ -30,7 +30,7 @@ project('dav1d', ['c'],
'b_ndebug=if-release'], 'b_ndebug=if-release'],
meson_version: '>= 0.47.0') meson_version: '>= 0.47.0')
dav1d_soname_version = '1.0.1' dav1d_soname_version = '1.1.0'
dav1d_api_version_array = dav1d_soname_version.split('.') dav1d_api_version_array = dav1d_soname_version.split('.')
dav1d_api_version_major = dav1d_api_version_array[0] dav1d_api_version_major = dav1d_api_version_array[0]
dav1d_api_version_minor = dav1d_api_version_array[1] dav1d_api_version_minor = dav1d_api_version_array[1]
......
...@@ -4181,7 +4181,7 @@ int dav1d_cdf_thread_alloc(CdfThreadContext *const cdf, ...@@ -4181,7 +4181,7 @@ int dav1d_cdf_thread_alloc(CdfThreadContext *const cdf,
{ {
cdf->ref = dav1d_ref_create(sizeof(CdfContext) + cdf->ref = dav1d_ref_create(sizeof(CdfContext) +
(t != NULL) * sizeof(atomic_uint)); (t != NULL) * sizeof(atomic_uint));
if (!cdf->ref) return -ENOMEM; if (!cdf->ref) return DAV1D_ERR(ENOMEM);
cdf->data.cdf = cdf->ref->data; cdf->data.cdf = cdf->ref->data;
if (t) { if (t) {
cdf->progress = (atomic_uint *) &cdf->data.cdf[1]; cdf->progress = (atomic_uint *) &cdf->data.cdf[1];
......
...@@ -58,12 +58,12 @@ int dav1d_data_wrap_internal(Dav1dData *const buf, const uint8_t *const ptr, ...@@ -58,12 +58,12 @@ int dav1d_data_wrap_internal(Dav1dData *const buf, const uint8_t *const ptr,
void *cookie), void *cookie),
void *const cookie) void *const cookie)
{ {
validate_input_or_ret(buf != NULL, -EINVAL); validate_input_or_ret(buf != NULL, DAV1D_ERR(EINVAL));
validate_input_or_ret(ptr != NULL, -EINVAL); validate_input_or_ret(ptr != NULL, DAV1D_ERR(EINVAL));
validate_input_or_ret(free_callback != NULL, -EINVAL); validate_input_or_ret(free_callback != NULL, DAV1D_ERR(EINVAL));
buf->ref = dav1d_ref_wrap(ptr, free_callback, cookie); buf->ref = dav1d_ref_wrap(ptr, free_callback, cookie);
if (!buf->ref) return -ENOMEM; if (!buf->ref) return DAV1D_ERR(ENOMEM);
buf->data = ptr; buf->data = ptr;
buf->sz = buf->m.size = sz; buf->sz = buf->m.size = sz;
dav1d_data_props_set_defaults(&buf->m); dav1d_data_props_set_defaults(&buf->m);
...@@ -77,11 +77,11 @@ int dav1d_data_wrap_user_data_internal(Dav1dData *const buf, ...@@ -77,11 +77,11 @@ int dav1d_data_wrap_user_data_internal(Dav1dData *const buf,
void *cookie), void *cookie),
void *const cookie) void *const cookie)
{ {
validate_input_or_ret(buf != NULL, -EINVAL); validate_input_or_ret(buf != NULL, DAV1D_ERR(EINVAL));
validate_input_or_ret(free_callback != NULL, -EINVAL); validate_input_or_ret(free_callback != NULL, DAV1D_ERR(EINVAL));
buf->m.user_data.ref = dav1d_ref_wrap(user_data, free_callback, cookie); buf->m.user_data.ref = dav1d_ref_wrap(user_data, free_callback, cookie);
if (!buf->m.user_data.ref) return -ENOMEM; if (!buf->m.user_data.ref) return DAV1D_ERR(ENOMEM);
buf->m.user_data.data = user_data; buf->m.user_data.data = user_data;
return 0; return 0;
......
...@@ -2566,7 +2566,7 @@ int dav1d_decode_tile_sbrow(Dav1dTileContext *const t) { ...@@ -2566,7 +2566,7 @@ int dav1d_decode_tile_sbrow(Dav1dTileContext *const t) {
int dav1d_decode_frame(Dav1dFrameContext *const f) { int dav1d_decode_frame(Dav1dFrameContext *const f) {
const Dav1dContext *const c = f->c; const Dav1dContext *const c = f->c;
int retval = -ENOMEM; int retval = DAV1D_ERR(ENOMEM);
if (f->n_tc > 1) { if (f->n_tc > 1) {
if (f->frame_hdr->tiling.cols * f->sbh > f->tile_thread.titsati_sz) { if (f->frame_hdr->tiling.cols * f->sbh > f->tile_thread.titsati_sz) {
...@@ -2778,7 +2778,7 @@ int dav1d_decode_frame(Dav1dFrameContext *const f) { ...@@ -2778,7 +2778,7 @@ int dav1d_decode_frame(Dav1dFrameContext *const f) {
if (c->n_fc == 1 && f->frame_hdr->use_ref_frame_mvs) if (c->n_fc == 1 && f->frame_hdr->use_ref_frame_mvs)
dav1d_init_ref_mv_tile_row(f->libaom_cm, 0, f->bw, 0, f->bh); dav1d_init_ref_mv_tile_row(f->libaom_cm, 0, f->bw, 0, f->bh);
} }
retval = -EINVAL; retval = DAV1D_ERR(EINVAL);
// setup dequant tables // setup dequant tables
init_quant_tables(f->seq_hdr, f->frame_hdr, f->frame_hdr->quant.yac, f->dq); init_quant_tables(f->seq_hdr, f->frame_hdr, f->frame_hdr->quant.yac, f->dq);
...@@ -3115,7 +3115,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3115,7 +3115,7 @@ int dav1d_submit_frame(Dav1dContext *const c) {
default: default:
dav1d_log(c, "Compiled without support for %d-bit decoding\n", dav1d_log(c, "Compiled without support for %d-bit decoding\n",
8 + 2 * f->seq_hdr->hbd); 8 + 2 * f->seq_hdr->hbd);
res = -ENOPROTOOPT; res = DAV1D_ERR(ENOPROTOOPT);
goto error; goto error;
} }
} }
...@@ -3142,7 +3142,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3142,7 +3142,7 @@ int dav1d_submit_frame(Dav1dContext *const c) {
if (f->frame_hdr->primary_ref_frame != DAV1D_PRIMARY_REF_NONE) { if (f->frame_hdr->primary_ref_frame != DAV1D_PRIMARY_REF_NONE) {
const int pri_ref = f->frame_hdr->refidx[f->frame_hdr->primary_ref_frame]; const int pri_ref = f->frame_hdr->refidx[f->frame_hdr->primary_ref_frame];
if (!c->refs[pri_ref].p.p.data[0]) { if (!c->refs[pri_ref].p.p.data[0]) {
res = -EINVAL; res = DAV1D_ERR(EINVAL);
goto error; goto error;
} }
} }
...@@ -3158,7 +3158,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3158,7 +3158,7 @@ int dav1d_submit_frame(Dav1dContext *const c) {
{ {
for (int j = 0; j < i; j++) for (int j = 0; j < i; j++)
dav1d_thread_picture_unref(&f->refp[j]); dav1d_thread_picture_unref(&f->refp[j]);
res = -EINVAL; res = DAV1D_ERR(EINVAL);
goto error; goto error;
} }
dav1d_thread_picture_ref(&f->refp[i], &c->refs[refidx].p); dav1d_thread_picture_ref(&f->refp[i], &c->refs[refidx].p);
...@@ -3255,7 +3255,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3255,7 +3255,7 @@ int dav1d_submit_frame(Dav1dContext *const c) {
f->mvs_ref = dav1d_ref_create(f->sb128h * 32 * f->b4_stride * f->mvs_ref = dav1d_ref_create(f->sb128h * 32 * f->b4_stride *
sizeof(*f->mvs)); sizeof(*f->mvs));
if (!f->mvs_ref) { if (!f->mvs_ref) {
res = -ENOMEM; res = DAV1D_ERR(ENOMEM);
goto error; goto error;
} }
f->mvs = f->mvs_ref->data; f->mvs = f->mvs_ref->data;
...@@ -3318,7 +3318,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3318,7 +3318,7 @@ int dav1d_submit_frame(Dav1dContext *const c) {
// actually gets set elsewhere) // actually gets set elsewhere)
f->cur_segmap_ref = dav1d_ref_create(f->b4_stride * 32 * f->sb128h); f->cur_segmap_ref = dav1d_ref_create(f->b4_stride * 32 * f->sb128h);
if (!f->cur_segmap_ref) { if (!f->cur_segmap_ref) {
res = -ENOMEM; res = DAV1D_ERR(ENOMEM);
goto error; goto error;
} }
f->cur_segmap = f->cur_segmap_ref->data; f->cur_segmap = f->cur_segmap_ref->data;
...@@ -3332,7 +3332,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3332,7 +3332,7 @@ int dav1d_submit_frame(Dav1dContext *const c) {
// We need to make a new map. Allocate one here and zero it out. // We need to make a new map. Allocate one here and zero it out.
f->cur_segmap_ref = dav1d_ref_create(f->b4_stride * 32 * f->sb128h); f->cur_segmap_ref = dav1d_ref_create(f->b4_stride * 32 * f->sb128h);
if (!f->cur_segmap_ref) { if (!f->cur_segmap_ref) {
res = -ENOMEM; res = DAV1D_ERR(ENOMEM);
goto error; goto error;
} }
f->cur_segmap = f->cur_segmap_ref->data; f->cur_segmap = f->cur_segmap_ref->data;
......
...@@ -77,21 +77,21 @@ int dav1d_open(Dav1dContext **const c_out, ...@@ -77,21 +77,21 @@ int dav1d_open(Dav1dContext **const c_out,
static pthread_once_t initted = PTHREAD_ONCE_INIT; static pthread_once_t initted = PTHREAD_ONCE_INIT;
pthread_once(&initted, init_internal); pthread_once(&initted, init_internal);
validate_input_or_ret(c_out != NULL, -EINVAL); validate_input_or_ret(c_out != NULL, DAV1D_ERR(EINVAL));
validate_input_or_ret(s != NULL, -EINVAL); validate_input_or_ret(s != NULL, DAV1D_ERR(EINVAL));
validate_input_or_ret(s->n_tile_threads >= 1 && validate_input_or_ret(s->n_tile_threads >= 1 &&
s->n_tile_threads <= DAV1D_MAX_TILE_THREADS, -EINVAL); s->n_tile_threads <= DAV1D_MAX_TILE_THREADS, DAV1D_ERR(EINVAL));
validate_input_or_ret(s->n_frame_threads >= 1 && validate_input_or_ret(s->n_frame_threads >= 1 &&
s->n_frame_threads <= DAV1D_MAX_FRAME_THREADS, -EINVAL); s->n_frame_threads <= DAV1D_MAX_FRAME_THREADS, DAV1D_ERR(EINVAL));
validate_input_or_ret(s->allocator.alloc_picture_callback != NULL, validate_input_or_ret(s->allocator.alloc_picture_callback != NULL,
-EINVAL); DAV1D_ERR(EINVAL));
validate_input_or_ret(s->allocator.release_picture_callback != NULL, validate_input_or_ret(s->allocator.release_picture_callback != NULL,
-EINVAL); DAV1D_ERR(EINVAL));
validate_input_or_ret(s->operating_point >= 0 && validate_input_or_ret(s->operating_point >= 0 &&
s->operating_point <= 31, -EINVAL); s->operating_point <= 31, DAV1D_ERR(EINVAL));
pthread_attr_t thread_attr; pthread_attr_t thread_attr;
if (pthread_attr_init(&thread_attr)) return -ENOMEM; if (pthread_attr_init(&thread_attr)) return DAV1D_ERR(ENOMEM);
pthread_attr_setstacksize(&thread_attr, 512 * 1024); pthread_attr_setstacksize(&thread_attr, 512 * 1024);
Dav1dContext *const c = *c_out = dav1d_alloc_aligned(sizeof(*c), 32); Dav1dContext *const c = *c_out = dav1d_alloc_aligned(sizeof(*c), 32);
...@@ -193,7 +193,7 @@ int dav1d_open(Dav1dContext **const c_out, ...@@ -193,7 +193,7 @@ int dav1d_open(Dav1dContext **const c_out,
error: error:
if (c) close_internal(c_out, 0); if (c) close_internal(c_out, 0);
pthread_attr_destroy(&thread_attr); pthread_attr_destroy(&thread_attr);
return -ENOMEM; return DAV1D_ERR(ENOMEM);
} }
static void dummy_free(const uint8_t *const data, void *const user_data) { static void dummy_free(const uint8_t *const data, void *const user_data) {
...@@ -206,7 +206,7 @@ int dav1d_parse_sequence_header(Dav1dSequenceHeader *const out, ...@@ -206,7 +206,7 @@ int dav1d_parse_sequence_header(Dav1dSequenceHeader *const out,
Dav1dData buf = { 0 }; Dav1dData buf = { 0 };
int res; int res;
validate_input_or_ret(out != NULL, -EINVAL); validate_input_or_ret(out != NULL, DAV1D_ERR(EINVAL));
Dav1dSettings s; Dav1dSettings s;
dav1d_default_settings(&s); dav1d_default_settings(&s);
...@@ -231,7 +231,7 @@ int dav1d_parse_sequence_header(Dav1dSequenceHeader *const out, ...@@ -231,7 +231,7 @@ int dav1d_parse_sequence_header(Dav1dSequenceHeader *const out,
} }
if (!c->seq_hdr) { if (!c->seq_hdr) {
res = -EINVAL; res = DAV1D_ERR(EINVAL);
goto error; goto error;
} }
...@@ -247,14 +247,14 @@ error: ...@@ -247,14 +247,14 @@ error:
int dav1d_send_data(Dav1dContext *const c, Dav1dData *const in) int dav1d_send_data(Dav1dContext *const c, Dav1dData *const in)
{ {
validate_input_or_ret(c != NULL, -EINVAL); validate_input_or_ret(c != NULL, DAV1D_ERR(EINVAL));
validate_input_or_ret(in != NULL, -EINVAL); validate_input_or_ret(in != NULL, DAV1D_ERR(EINVAL));
validate_input_or_ret(in->data == NULL || in->sz, -EINVAL); validate_input_or_ret(in->data == NULL || in->sz, DAV1D_ERR(EINVAL));
c->drain = 0; c->drain = 0;
if (c->in.data) if (c->in.data)
return -EAGAIN; return DAV1D_ERR(EAGAIN);
dav1d_data_move_ref(&c->in, in); dav1d_data_move_ref(&c->in, in);
return 0; return 0;
...@@ -343,22 +343,22 @@ static int drain_picture(Dav1dContext *const c, Dav1dPicture *const out) { ...@@ -343,22 +343,22 @@ static int drain_picture(Dav1dContext *const c, Dav1dPicture *const out) {
} }
} while (++drain_count < c->n_fc); } while (++drain_count < c->n_fc);
return -EAGAIN; return DAV1D_ERR(EAGAIN);
} }
int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out) int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out)
{ {
int res; int res;
validate_input_or_ret(c != NULL, -EINVAL); validate_input_or_ret(c != NULL, DAV1D_ERR(EINVAL));
validate_input_or_ret(out != NULL, -EINVAL); validate_input_or_ret(out != NULL, DAV1D_ERR(EINVAL));
const int drain = c->drain; const int drain = c->drain;
c->drain = 1; c->drain = 1;
Dav1dData *const in = &c->in; Dav1dData *const in = &c->in;
if (!in->data) { if (!in->data) {
if (c->n_fc == 1) return -EAGAIN; if (c->n_fc == 1) return DAV1D_ERR(EAGAIN);
return drain_picture(c, out); return drain_picture(c, out);
} }
...@@ -384,7 +384,7 @@ int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out) ...@@ -384,7 +384,7 @@ int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out)
if (c->n_fc > 1 && drain) if (c->n_fc > 1 && drain)
return drain_picture(c, out); return drain_picture(c, out);
return -EAGAIN; return DAV1D_ERR(EAGAIN);
} }
void dav1d_flush(Dav1dContext *const c) { void dav1d_flush(Dav1dContext *const c) {
......
...@@ -284,7 +284,7 @@ static int parse_seq_hdr(Dav1dContext *const c, GetBits *const gb, ...@@ -284,7 +284,7 @@ static int parse_seq_hdr(Dav1dContext *const c, GetBits *const gb,
error: error:
dav1d_log(c, "Error parsing sequence header\n"); dav1d_log(c, "Error parsing sequence header\n");
return -EINVAL; return DAV1D_ERR(EINVAL);
} }
static int read_frame_size(Dav1dContext *const c, GetBits *const gb, static int read_frame_size(Dav1dContext *const c, GetBits *const gb,
...@@ -756,7 +756,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { ...@@ -756,7 +756,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) {
// segmentation data from the reference frame. // segmentation data from the reference frame.
assert(hdr->primary_ref_frame != DAV1D_PRIMARY_REF_NONE); assert(hdr->primary_ref_frame != DAV1D_PRIMARY_REF_NONE);
const int pri_ref = hdr->refidx[hdr->primary_ref_frame]; const int pri_ref = hdr->refidx[hdr->primary_ref_frame];
if (!c->refs[pri_ref].p.p.frame_hdr) return -EINVAL; if (!c->refs[pri_ref].p.p.frame_hdr) return DAV1D_ERR(EINVAL);
hdr->segmentation.seg_data = hdr->segmentation.seg_data =
c->refs[pri_ref].p.p.frame_hdr->segmentation.seg_data; c->refs[pri_ref].p.p.frame_hdr->segmentation.seg_data;
} }
...@@ -818,7 +818,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { ...@@ -818,7 +818,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) {
hdr->loopfilter.mode_ref_deltas = default_mode_ref_deltas; hdr->loopfilter.mode_ref_deltas = default_mode_ref_deltas;
} else { } else {
const int ref = hdr->refidx[hdr->primary_ref_frame]; const int ref = hdr->refidx[hdr->primary_ref_frame];
if (!c->refs[ref].p.p.frame_hdr) return -EINVAL; if (!c->refs[ref].p.p.frame_hdr) return DAV1D_ERR(EINVAL);
hdr->loopfilter.mode_ref_deltas = hdr->loopfilter.mode_ref_deltas =
c->refs[ref].p.p.frame_hdr->loopfilter.mode_ref_deltas; c->refs[ref].p.p.frame_hdr->loopfilter.mode_ref_deltas;
} }
...@@ -922,7 +922,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { ...@@ -922,7 +922,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) {
int off_before_idx[2], off_after_idx; int off_before_idx[2], off_after_idx;
off_before_idx[0] = 0; off_before_idx[0] = 0;
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
if (!c->refs[hdr->refidx[i]].p.p.data[0]) return -EINVAL; if (!c->refs[hdr->refidx[i]].p.p.data[0]) return DAV1D_ERR(EINVAL);
const unsigned refpoc = c->refs[hdr->refidx[i]].p.p.frame_hdr->frame_offset; const unsigned refpoc = c->refs[hdr->refidx[i]].p.p.frame_hdr->frame_offset;
const int diff = get_poc_diff(seqhdr->order_hint_n_bits, refpoc, poc); const int diff = get_poc_diff(seqhdr->order_hint_n_bits, refpoc, poc);
...@@ -999,7 +999,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { ...@@ -999,7 +999,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) {
ref_gmv = &dav1d_default_wm_params; ref_gmv = &dav1d_default_wm_params;
} else { } else {
const int pri_ref = hdr->refidx[hdr->primary_ref_frame]; const int pri_ref = hdr->refidx[hdr->primary_ref_frame];
if (!c->refs[pri_ref].p.p.frame_hdr) return -EINVAL; if (!c->refs[pri_ref].p.p.frame_hdr) return DAV1D_ERR(EINVAL);
ref_gmv = &c->refs[pri_ref].p.p.frame_hdr->gmv[i]; ref_gmv = &c->refs[pri_ref].p.p.frame_hdr->gmv[i];
} }
int32_t *const mat = hdr->gmv[i].matrix; int32_t *const mat = hdr->gmv[i].matrix;
...@@ -1122,7 +1122,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { ...@@ -1122,7 +1122,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) {
error: error:
dav1d_log(c, "Error parsing frame header\n"); dav1d_log(c, "Error parsing frame header\n");
return -EINVAL; return DAV1D_ERR(EINVAL);
} }
static void parse_tile_hdr(Dav1dContext *const c, GetBits *const gb) { static void parse_tile_hdr(Dav1dContext *const c, GetBits *const gb) {
...@@ -1227,7 +1227,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1227,7 +1227,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
switch (type) { switch (type) {
case OBU_SEQ_HDR: { case OBU_SEQ_HDR: {
Dav1dRef *ref = dav1d_ref_create(sizeof(Dav1dSequenceHeader)); Dav1dRef *ref = dav1d_ref_create(sizeof(Dav1dSequenceHeader));
if (!ref) return -ENOMEM; if (!ref) return DAV1D_ERR(ENOMEM);
Dav1dSequenceHeader *seq_hdr = ref->data; Dav1dSequenceHeader *seq_hdr = ref->data;
memset(seq_hdr, 0, sizeof(*seq_hdr)); memset(seq_hdr, 0, sizeof(*seq_hdr));
if ((res = parse_seq_hdr(c, &gb, seq_hdr)) < 0) { if ((res = parse_seq_hdr(c, &gb, seq_hdr)) < 0) {
...@@ -1236,7 +1236,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1236,7 +1236,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
} }
if (check_for_overrun(c, &gb, init_bit_pos, len)) { if (check_for_overrun(c, &gb, init_bit_pos, len)) {
dav1d_ref_dec(&ref); dav1d_ref_dec(&ref);
return -EINVAL; return DAV1D_ERR(EINVAL);
} }
// If we have read a sequence header which is different from // If we have read a sequence header which is different from
// the old one, this is a new video sequence and can't use any // the old one, this is a new video sequence and can't use any
...@@ -1273,7 +1273,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1273,7 +1273,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
if (!c->seq_hdr) goto error; if (!c->seq_hdr) goto error;
if (!c->frame_hdr_ref) { if (!c->frame_hdr_ref) {
c->frame_hdr_ref = dav1d_ref_create(sizeof(Dav1dFrameHeader)); c->frame_hdr_ref = dav1d_ref_create(sizeof(Dav1dFrameHeader));
if (!c->frame_hdr_ref) return -ENOMEM; if (!c->frame_hdr_ref) return DAV1D_ERR(ENOMEM);
} }
// ensure that the reference is writable // ensure that the reference is writable
assert(dav1d_ref_is_writable(c->frame_hdr_ref)); assert(dav1d_ref_is_writable(c->frame_hdr_ref));
...@@ -1295,7 +1295,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1295,7 +1295,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
dav1d_get_bits(&gb, 1); dav1d_get_bits(&gb, 1);
if (check_for_overrun(c, &gb, init_bit_pos, len)) { if (check_for_overrun(c, &gb, init_bit_pos, len)) {
c->frame_hdr = NULL; c->frame_hdr = NULL;
return -EINVAL; return DAV1D_ERR(EINVAL);
} }
break; break;
...@@ -1326,7 +1326,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1326,7 +1326,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
// Align to the next byte boundary and check for overrun. // Align to the next byte boundary and check for overrun.
dav1d_bytealign_get_bits(&gb); dav1d_bytealign_get_bits(&gb);
if (check_for_overrun(c, &gb, init_bit_pos, len)) if (check_for_overrun(c, &gb, init_bit_pos, len))
return -EINVAL; return DAV1D_ERR(EINVAL);
// The current bit position is a multiple of 8 (because we // The current bit position is a multiple of 8 (because we
// just aligned it) and less than 8*pkt_bytelen because // just aligned it) and less than 8*pkt_bytelen because
// otherwise the overrun check would have fired. // otherwise the overrun check would have fired.
...@@ -1362,7 +1362,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1362,7 +1362,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
switch (meta_type) { switch (meta_type) {
case OBU_META_HDR_CLL: case OBU_META_HDR_CLL:
ref = dav1d_ref_create(sizeof(Dav1dContentLightLevel)); ref = dav1d_ref_create(sizeof(Dav1dContentLightLevel));
if (!ref) return -ENOMEM; if (!ref) return DAV1D_ERR(ENOMEM);
content_light = ref->data; content_light = ref->data;
memset(content_light, 0, sizeof(*content_light)); memset(content_light, 0, sizeof(*content_light));
...@@ -1383,7 +1383,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1383,7 +1383,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
break; break;
case OBU_META_HDR_MDCV: { case OBU_META_HDR_MDCV: {
ref = dav1d_ref_create(sizeof(Dav1dMasteringDisplay)); ref = dav1d_ref_create(sizeof(Dav1dMasteringDisplay));
if (!ref) return -ENOMEM; if (!ref) return DAV1D_ERR(ENOMEM);
mastering_display = ref->data; mastering_display = ref->data;
memset(mastering_display, 0, sizeof(*mastering_display)); memset(mastering_display, 0, sizeof(*mastering_display));
...@@ -1428,12 +1428,12 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1428,12 +1428,12 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
break; break;
default: default:
dav1d_log(c, "Unknown OBU type %d of size %u\n", type, len); dav1d_log(c, "Unknown OBU type %d of size %u\n", type, len);
return -EINVAL; return DAV1D_ERR(EINVAL);
} }
if (c->seq_hdr && c->frame_hdr) { if (c->seq_hdr && c->frame_hdr) {
if (c->frame_hdr->show_existing_frame) { if (c->frame_hdr->show_existing_frame) {
if (!c->refs[c->frame_hdr->existing_frame_idx].p.p.data[0]) return -EINVAL; if (!c->refs[c->frame_hdr->existing_frame_idx].p.p.data[0]) return DAV1D_ERR(EINVAL);
if (c->n_fc == 1) { if (c->n_fc == 1) {
dav1d_picture_ref(&c->out, dav1d_picture_ref(&c->out,
&c->refs[c->frame_hdr->existing_frame_idx].p.p); &c->refs[c->frame_hdr->existing_frame_idx].p.p);
...@@ -1486,7 +1486,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1486,7 +1486,7 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
c->frame_hdr = NULL; c->frame_hdr = NULL;
} else if (c->n_tiles == c->frame_hdr->tiling.cols * c->frame_hdr->tiling.rows) { } else if (c->n_tiles == c->frame_hdr->tiling.cols * c->frame_hdr->tiling.rows) {
if (!c->n_tile_data) if (!c->n_tile_data)
return -EINVAL; return DAV1D_ERR(EINVAL);
if ((res = dav1d_submit_frame(c)) < 0) if ((res = dav1d_submit_frame(c)) < 0)
return res; return res;
assert(!c->n_tile_data); assert(!c->n_tile_data);
...@@ -1499,5 +1499,5 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) { ...@@ -1499,5 +1499,5 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
error: error:
dav1d_log(c, "Error parsing OBU data\n"); dav1d_log(c, "Error parsing OBU data\n");
return -EINVAL; return DAV1D_ERR(EINVAL);
} }
...@@ -62,7 +62,7 @@ int dav1d_default_picture_alloc(Dav1dPicture *const p, void *const cookie) { ...@@ -62,7 +62,7 @@ int dav1d_default_picture_alloc(Dav1dPicture *const p, void *const cookie) {
uint8_t *data = dav1d_alloc_aligned(pic_size + DAV1D_PICTURE_ALIGNMENT, uint8_t *data = dav1d_alloc_aligned(pic_size + DAV1D_PICTURE_ALIGNMENT,
DAV1D_PICTURE_ALIGNMENT); DAV1D_PICTURE_ALIGNMENT);
if (data == NULL) { if (data == NULL) {
return -ENOMEM; return DAV1D_ERR(ENOMEM);
} }
p->data[0] = data; p->data[0] = data;
...@@ -116,7 +116,7 @@ static int picture_alloc_with_edges(Dav1dContext *const c, Dav1dPicture *const p ...@@ -116,7 +116,7 @@ static int picture_alloc_with_edges(Dav1dContext *const c, Dav1dPicture *const p
struct pic_ctx_context *pic_ctx = malloc(extra + sizeof(struct pic_ctx_context)); struct pic_ctx_context *pic_ctx = malloc(extra + sizeof(struct pic_ctx_context));
if (pic_ctx == NULL) { if (pic_ctx == NULL) {
return -ENOMEM; return DAV1D_ERR(ENOMEM);
} }
p->p.w = w; p->p.w = w;
...@@ -141,7 +141,7 @@ static int picture_alloc_with_edges(Dav1dContext *const c, Dav1dPicture *const p ...@@ -141,7 +141,7 @@ static int picture_alloc_with_edges(Dav1dContext *const c, Dav1dPicture *const p
p_allocator->release_picture_callback(p, p_allocator->cookie); p_allocator->release_picture_callback(p, p_allocator->cookie);