Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/videolan/dav1d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/lib.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2020-03-09 17:05:57 +0300
committerJames Almer <jamrial@gmail.com>2020-03-21 19:57:23 +0300
commit89ea92ba12bab0bd06a12828480af6bf809e065f (patch)
treeb23a28ec57728492d5aff91e47445038938d19f0 /src/lib.c
parente8e92d358d57add6ec20b5921df99e5a7bac0210 (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.c65
1 files changed, 38 insertions, 27 deletions
diff --git a/src/lib.c b/src/lib.c
index a8246e3..40081bf 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -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);