diff options
author | James Almer <jamrial@gmail.com> | 2020-03-09 17:05:57 +0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2020-03-21 19:57:23 +0300 |
commit | 89ea92ba12bab0bd06a12828480af6bf809e065f (patch) | |
tree | b23a28ec57728492d5aff91e47445038938d19f0 /src/lib.c | |
parent | e8e92d358d57add6ec20b5921df99e5a7bac0210 (diff) |
lib: restructure the internal implementation of the decode API
Process input data as soon as it's fed to dav1d_send_data() instead of storing
a single packet and expecting the user to call dav1d_get_picture() in order to
trigger the decoding process before they are allowed to feed more data.
Diffstat (limited to 'src/lib.c')
-rw-r--r-- | src/lib.c | 65 |
1 files changed, 38 insertions, 27 deletions
@@ -273,21 +273,6 @@ error: return res; } -int dav1d_send_data(Dav1dContext *const c, Dav1dData *const in) -{ - validate_input_or_ret(c != NULL, DAV1D_ERR(EINVAL)); - validate_input_or_ret(in != NULL, DAV1D_ERR(EINVAL)); - validate_input_or_ret(in->data == NULL || in->sz, DAV1D_ERR(EINVAL)); - - c->drain = 0; - - if (c->in.data) - return DAV1D_ERR(EAGAIN); - dav1d_data_move_ref(&c->in, in); - - return 0; -} - static int output_image(Dav1dContext *const c, Dav1dPicture *const out, Dav1dPicture *const in) { @@ -374,21 +359,13 @@ static int drain_picture(Dav1dContext *const c, Dav1dPicture *const out) { return DAV1D_ERR(EAGAIN); } -int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out) +static int gen_picture(Dav1dContext *const c) { int res; - - validate_input_or_ret(c != NULL, DAV1D_ERR(EINVAL)); - validate_input_or_ret(out != NULL, DAV1D_ERR(EINVAL)); - - const int drain = c->drain; - c->drain = 1; - Dav1dData *const in = &c->in; - if (!in->data) { - if (c->n_fc == 1) return DAV1D_ERR(EAGAIN); - return drain_picture(c, out); - } + + if (output_picture_ready(c)) + return 0; while (in->sz > 0) { res = dav1d_parse_obus(c, in, 0); @@ -406,6 +383,40 @@ int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out) return res; } + return 0; +} + +int dav1d_send_data(Dav1dContext *const c, Dav1dData *const in) +{ + validate_input_or_ret(c != NULL, DAV1D_ERR(EINVAL)); + validate_input_or_ret(in != NULL, DAV1D_ERR(EINVAL)); + validate_input_or_ret(in->data == NULL || in->sz, DAV1D_ERR(EINVAL)); + + if (in->data) + c->drain = 0; + if (c->in.data) + return DAV1D_ERR(EAGAIN); + dav1d_data_ref(&c->in, in); + + int res = gen_picture(c); + if (!res) + dav1d_data_unref_internal(in); + + return res; +} + +int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out) +{ + validate_input_or_ret(c != NULL, DAV1D_ERR(EINVAL)); + validate_input_or_ret(out != NULL, DAV1D_ERR(EINVAL)); + + const int drain = c->drain; + c->drain = 1; + + int res = gen_picture(c); + if (res < 0) + return res; + if (output_picture_ready(c)) return output_image(c, out, &c->out); |