The 'stream_pos' in sess is automatically changed auto by uadk after a stream request is end. But sometimes users want to drop an old request and send a new request with the old sess.
So add the interface 'wd_comp_reset_sess' to allow the user set the 'stream_pos' to 'WD_COMP_STREAM_NEW' whenever they want.
Signed-off-by: Yang Shen shenyang39@huawei.com --- include/wd_comp.h | 9 ++++++++- wd_comp.c | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/include/wd_comp.h b/include/wd_comp.h index 782e5d2..45b0d0b 100644 --- a/include/wd_comp.h +++ b/include/wd_comp.h @@ -158,11 +158,18 @@ struct wd_comp_sess_setup { handle_t wd_comp_alloc_sess(struct wd_comp_sess_setup *setup);
/** - * wd_comp_free_sess() - Free a wd comp session. + * wd_comp_free_sess() - Free a wd comp session. * @h_sess: The sess to be freed. */ void wd_comp_free_sess(handle_t h_sess);
+/** + * wd_comp_reset_sess() - Reset a wd comp session. After reset h_sess, it can + * used for a new stream request. + * @h_sess: The sess to be reset. + */ +int wd_comp_reset_sess(handle_t h_sess); + /** * wd_do_comp_sync() - Send a sync compression request. * @h_sess: The session which request will be sent to. diff --git a/wd_comp.c b/wd_comp.c index 0e89304..32fda95 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -430,6 +430,21 @@ void wd_comp_free_sess(handle_t h_sess) free(sess); }
+int wd_comp_reset_sess(handle_t h_sess) +{ + struct wd_comp_sess *sess = (struct wd_comp_sess *)h_sess; + + if (!sess) { + WD_ERR("invalid: sess is NULL!\n"); + return -WD_EINVAL; + } + + sess->stream_pos = WD_COMP_STREAM_NEW; + memset(sess->ctx_buf, 0, HW_CTX_SIZE); + + return 0; +} + static void fill_comp_msg(struct wd_comp_sess *sess, struct wd_comp_msg *msg, struct wd_comp_req *req) {