This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: dvb-vb2: add dvb_v5_stream_alloc/free
Author:  Hans Verkuil <[email protected]>
Date:    Wed Apr 30 10:13:48 2025 +0200

Add new functions to allocate/free a stream context.

Signed-off-by: Hans Verkuil <[email protected]>
Acked-by: Mauro Carvalho Chehab <[email protected]>

 lib/include/libdvbv5/dvb-vb2.h | 14 +++++++++++
 lib/libdvbv5/dvb-vb2.c         | 57 ++++++++++++++++++++++++++++++------------
 2 files changed, 55 insertions(+), 16 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=fdd7dc5e6794c2aea2c65c534c59e7accf5acb32
diff --git a/lib/include/libdvbv5/dvb-vb2.h b/lib/include/libdvbv5/dvb-vb2.h
index 26b73fbf691c..cef046e81ece 100644
--- a/lib/include/libdvbv5/dvb-vb2.h
+++ b/lib/include/libdvbv5/dvb-vb2.h
@@ -101,6 +101,13 @@ int dvb_v5_stream_dqbuf(struct dvb_v5_stream_ctx *sc, 
struct dmx_buffer *buf);
  */
 int dvb_v5_stream_expbuf(struct dvb_v5_stream_ctx *sc, int idx);
 
+/**
+ * dvb_v5_stream_alloc - Allocate stream context
+ *
+ * @return a stream context or NULL.
+ */
+struct dvb_v5_stream_ctx *dvb_v5_stream_alloc(void);
+
 /**
  * dvb_v5_stream_init - Requests number of buffers from memory
  * Gets pointer to the buffers from driver, mmaps those buffers
@@ -124,6 +131,13 @@ int dvb_v5_stream_init(struct dvb_v5_stream_ctx *sc, int 
in_fd, int buf_size, in
  */
 void dvb_v5_stream_deinit(struct dvb_v5_stream_ctx *sc);
 
+/**
+ * dvb_v5_stream_free - Free stream context
+ *
+ * @param sc - Context for streaming management
+ */
+void dvb_v5_stream_free(struct dvb_v5_stream_ctx *sc);
+
 /**
  * dvb_v5_stream_to_file - Implements enqueue and dequeue logic
  * First enqueues all the available buffers then dequeues
diff --git a/lib/libdvbv5/dvb-vb2.c b/lib/libdvbv5/dvb-vb2.c
index 8678a767f88d..56a35f817ac3 100644
--- a/lib/libdvbv5/dvb-vb2.c
+++ b/lib/libdvbv5/dvb-vb2.c
@@ -155,6 +155,17 @@ int dvb_v5_stream_expbuf(struct dvb_v5_stream_ctx *sc, int 
idx)
                        idx, sc->exp_fd[idx]);
        return ret;
 }
+
+/**
+ * dvb_v5_stream_alloc - Allocate stream context
+ *
+ * @return a stream context or NULL.
+ */
+struct dvb_v5_stream_ctx *dvb_v5_stream_alloc(void)
+{
+       return calloc(1, sizeof(struct dvb_v5_stream_ctx));
+}
+
 /**
  * dvb_v5_stream_init - Requests number of buffers from memory
  * Gets pointer to the buffers from driver, mmaps those buffers
@@ -262,6 +273,16 @@ void dvb_v5_stream_deinit(struct dvb_v5_stream_ctx *sc)
        return;
 }
 
+/**
+ * dvb_v5_stream_free - Free stream context
+ *
+ * @param sc - Context for streaming management
+ */
+void dvb_v5_stream_free(struct dvb_v5_stream_ctx *sc)
+{
+       free(sc);
+}
+
 /**
  * dvb_v5_stream_to_file - Implements enqueue and dequeue logic
  * First enqueues all the available buffers then dequeues
@@ -278,33 +299,36 @@ void dvb_v5_stream_deinit(struct dvb_v5_stream_ctx *sc)
 void dvb_v5_stream_to_file(int in_fd, int out_fd, int timeout, int dbg_level,
                           int *exit_flag)
 {
-       struct dvb_v5_stream_ctx sc;
-       int ret;
+       struct dvb_v5_stream_ctx *sc = dvb_v5_stream_alloc();
        long long int rc = 0LL;
+       int ret;
 
-       ret = dvb_v5_stream_init(&sc, in_fd, STREAM_BUF_SIZ, STREAM_BUF_CNT);
+       if (!sc) {
+               PERROR("[%s] Failed to allocate stream context", __func__);
+               return;
+       }
+       ret = dvb_v5_stream_init(sc, in_fd, STREAM_BUF_SIZ, STREAM_BUF_CNT);
        if (ret < 0) {
-               PERROR("[%s] Failed to setup buffers!!!", __func__);
-               sc.error = 1;
+               PERROR("[%s] Failed to initialize stream context", __func__);
+               dvb_v5_stream_free(sc);
                return;
        }
        fprintf(stderr, "start streaming!!!\n");
-       sc.out_fd = out_fd;
+       sc->out_fd = out_fd;
 
-       while (!*exit_flag  && !sc.error) {
+       while (!*exit_flag  && !sc->error) {
                /* dequeue the buffer */
                struct dmx_buffer b;
 
                memzero(b);
-               ret = dvb_v5_stream_dqbuf(&sc, &b);
+               ret = dvb_v5_stream_dqbuf(sc, &b);
                if (ret < 0) {
-                       sc.error = 1;
+                       sc->error = 1;
                        break;
                }
                else {
-                       sc.buf_flag[b.index] = 0;
-                       ret = write(sc.out_fd, sc.buf[b.index],
-                                       b.bytesused);
+                       sc->buf_flag[b.index] = 0;
+                       ret = write(sc->out_fd, sc->buf[b.index], b.bytesused);
                        if (ret < 0) {
                                PERROR("Write failed err=%d", ret);
                                break;
@@ -313,15 +337,16 @@ void dvb_v5_stream_to_file(int in_fd, int out_fd, int 
timeout, int dbg_level,
                }
 
                /* enqueue the buffer */
-               ret = dvb_v5_stream_qbuf(&sc, b.index);
+               ret = dvb_v5_stream_qbuf(sc, b.index);
                if (ret < 0)
-                       sc.error = 1;
+                       sc->error = 1;
                else
-                       sc.buf_flag[b.index] = 1;
+                       sc->buf_flag[b.index] = 1;
        }
        if (dbg_level < 2) {
                fprintf(stderr, "copied %lld bytes (%lld Kbytes/sec)\n", rc,
                        rc / (1024 * timeout));
        }
-       dvb_v5_stream_deinit(&sc);
+       dvb_v5_stream_deinit(sc);
+       dvb_v5_stream_free(sc);
 }
_______________________________________________
linuxtv-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to