This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 8f50bf386739e2c0913770a8344f107695d35211
Author: shizhenghui <[email protected]>
AuthorDate: Tue Sep 3 10:48:34 2024 +0800

    nxcodec: add rich debugging logs
    
    Signed-off-by: shizhenghui <[email protected]>
---
 system/nxcodec/nxcodec.c         | 40 ++++++++++++++++++++++++++++------------
 system/nxcodec/nxcodec_context.c | 26 +++++++++++++++++---------
 system/nxcodec/nxcodec_main.c    | 29 +++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 21 deletions(-)

diff --git a/system/nxcodec/nxcodec.c b/system/nxcodec/nxcodec.c
index b019a4f42..ddcc64bb9 100644
--- a/system/nxcodec/nxcodec.c
+++ b/system/nxcodec/nxcodec.c
@@ -60,6 +60,7 @@ static int nxcodec_prepare_contexts(FAR nxcodec_t *codec)
   ret = ioctl(codec->fd, VIDIOC_QUERYCAP, &cap);
   if (ret < 0)
     {
+      printf("nxcodec VIDIOC_QUERYCAP error: %d\n", errno);
       return -errno;
     }
 
@@ -67,6 +68,9 @@ static int nxcodec_prepare_contexts(FAR nxcodec_t *codec)
     {
       codec->capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
       codec->output.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
+
+      printf("nxcodec is multi-planar\n");
+
       return 0;
     }
 
@@ -74,6 +78,9 @@ static int nxcodec_prepare_contexts(FAR nxcodec_t *codec)
     {
       codec->capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
       codec->output.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+
+      printf("nxcodec is single-planar\n");
+
       return 0;
     }
 
@@ -91,26 +98,28 @@ int nxcodec_init(FAR nxcodec_t *codec)
   codec->fd = open(codec->devname, O_RDWR | O_NONBLOCK);
   if (codec->fd < 0)
     {
+      printf("nxcodec open device error: %d\n", errno);
       return -errno;
     }
 
   ret = nxcodec_prepare_contexts(codec);
   if (ret < 0)
     {
+      printf("nxcodec prepare context error: %d\n", errno);
       goto err0;
     }
 
   ret = nxcodec_context_get_format(&codec->output);
   if (ret < 0)
     {
-      printf("v4l2 output format not supported\n");
+      printf("nxcodec v4l2 output format not supported\n");
       goto err0;
     }
 
   ret = nxcodec_context_get_format(&codec->capture);
   if (ret < 0)
     {
-      printf("v4l2 capture format not supported\n");
+      printf("nxcodec v4l2 capture format not supported\n");
       goto err0;
     }
 
@@ -119,14 +128,17 @@ int nxcodec_init(FAR nxcodec_t *codec)
   ret = nxcodec_context_set_format(&codec->output);
   if (ret < 0)
     {
-      printf("can't set v4l2 output format\n");
+      printf("nxcodec can't set v4l2 output format\n");
       goto err0;
     }
 
+  printf("nxcodec set output format DONE\n");
+
   codec->output.fd = open(codec->output.filename, O_RDONLY);
   if (codec->output.fd < 0)
     {
-      printf("Failed to open output file %s \n", codec->output.filename);
+      printf("nxcodec failed to open output file: %s \n",
+             codec->output.filename);
       ret = -errno;
       goto err0;
     }
@@ -136,15 +148,18 @@ int nxcodec_init(FAR nxcodec_t *codec)
   ret = nxcodec_context_set_format(&codec->capture);
   if (ret < 0)
     {
-      printf("can't to set v4l2 capture format\n");
+      printf("nxcodec can't to set v4l2 capture format\n");
       goto err1;
     }
 
+  printf("nxcodec set capture format DONE\n");
+
   codec->capture.fd = open(codec->capture.filename,
                            O_WRONLY | O_CREAT, 0644);
   if (codec->capture.fd < 0)
     {
-      printf("Failed to open input file %s \n", codec->capture.filename);
+      printf("nxcodec failed to open input file %s \n",
+             codec->capture.filename);
       ret = -errno;
       goto err1;
     }
@@ -165,34 +180,35 @@ int nxcodec_start(FAR nxcodec_t *codec)
   ret = nxcodec_context_init(&codec->output);
   if (ret < 0)
     {
-      printf("can't request output buffers\n");
+      printf("nxcodec can't request output buffers\n");
       return ret;
     }
 
   ret = nxcodec_context_set_status(&codec->output, VIDIOC_STREAMON);
   if (ret < 0)
     {
-      printf("set output VIDIOC_STREAMON failed\n");
+      printf("nxcodec set output VIDIOC_STREAMON failed\n");
       goto err0;
     }
 
   ret = nxcodec_context_init(&codec->capture);
   if (ret < 0)
     {
-      printf("can't request capture buffers\n");
+      printf("nxcodec can't request capture buffers\n");
       goto err0;
     }
 
   ret = nxcodec_context_set_status(&codec->capture, VIDIOC_STREAMON);
   if (ret < 0)
     {
-      printf("set capture VIDIOC_STREAMON failed\n");
+      printf("nxcodec set capture VIDIOC_STREAMON failed\n");
       goto err1;
     }
 
   ret = nxcodec_context_enqueue_frame(&codec->output);
   if (ret < 0 && ret != -EAGAIN)
     {
+      printf("nxcodec enqueue frame failed %d\n", errno);
       goto err1;
     }
 
@@ -219,7 +235,7 @@ int nxcodec_stop(FAR nxcodec_t *codec)
   ret = nxcodec_context_set_status(&codec->output, VIDIOC_STREAMOFF);
   if (ret < 0)
     {
-      printf("set output VIDIOC_STREAMOFF failed\n");
+      printf("nxcodec set output VIDIOC_STREAMOFF failed\n");
       return ret;
     }
 
@@ -228,7 +244,7 @@ int nxcodec_stop(FAR nxcodec_t *codec)
   ret = nxcodec_context_set_status(&codec->capture, VIDIOC_STREAMOFF);
   if (ret < 0)
     {
-      printf("set capture VIDIOC_STREAMOFF failed\n");
+      printf("nxcodec set capture VIDIOC_STREAMOFF failed\n");
       return ret;
     }
 
diff --git a/system/nxcodec/nxcodec_context.c b/system/nxcodec/nxcodec_context.c
index 510112253..258c3c3e8 100644
--- a/system/nxcodec/nxcodec_context.c
+++ b/system/nxcodec/nxcodec_context.c
@@ -67,9 +67,9 @@ nxcodec_context_dequeue_buf(FAR nxcodec_context_t *ctx)
   ret = ioctl(codec->fd, VIDIOC_DQBUF, &buf);
   if (ret < 0)
     {
-      printf("%s: VIDIOC_DQBUF - %s\n",
-        V4L2_TYPE_IS_OUTPUT(ctx->type) ? "output" : "capture",
-        strerror(errno));
+      printf("nxcodec %s VIDIOC_DQBUF - %s\n",
+             V4L2_TYPE_IS_OUTPUT(ctx->type) ? "output" : "capture",
+             strerror(errno));
       return NULL;
     }
 
@@ -269,12 +269,14 @@ int nxcodec_context_get_format(FAR nxcodec_context_t *ctx)
   int ret;
 
   fdesc.type = ctx->type;
-
   while (true)
     {
       ret = ioctl(codec->fd, VIDIOC_ENUM_FMT, &fdesc);
       if (ret < 0)
         {
+          printf("nxcodec %s enum_fmt error: %d\n",
+                 V4L2_TYPE_IS_OUTPUT(ctx->type) ? "output" : "capture",
+                 errno);
           return -errno;
         }
 
@@ -294,6 +296,9 @@ int nxcodec_context_set_format(FAR nxcodec_context_t *ctx)
 {
   FAR nxcodec_t *codec = nxcodec_context_to_nxcodec(ctx);
 
+  printf("nxcodec %s VIDIOC_S_FMT\n",
+         V4L2_TYPE_IS_OUTPUT(ctx->type) ? "output" : "capture");
+
   return ioctl(codec->fd, VIDIOC_S_FMT, &ctx->format) < 0 ? -errno : 0;
 }
 
@@ -312,8 +317,9 @@ int nxcodec_context_init(FAR nxcodec_context_t *ctx)
   ret = ioctl(codec->fd, VIDIOC_REQBUFS, &req);
   if (ret < 0)
     {
-      printf("type: %d VIDIOC_REQBUFS failed: %s\n",
-              ctx->type, strerror(errno));
+      printf("nxcodec type: %s, VIDIOC_REQBUFS failed: %s\n",
+             V4L2_TYPE_IS_OUTPUT(ctx->type) ? "output" : "capture",
+             strerror(errno));
       return -errno;
     }
 
@@ -321,7 +327,8 @@ int nxcodec_context_init(FAR nxcodec_context_t *ctx)
   ctx->buf = calloc(ctx->nbuffers, sizeof(nxcodec_context_buf_t));
   if (!ctx->buf)
     {
-      printf("type: %d malloc enomem\n", ctx->type);
+      printf("nxcodec type: %s, alloc memory error\n",
+             V4L2_TYPE_IS_OUTPUT(ctx->type) ? "output" : "capture");
       return -ENOMEM;
     }
 
@@ -393,8 +400,9 @@ void nxcodec_context_uninit(FAR nxcodec_context_t *ctx)
         {
           if (munmap(buf->addr, buf->length) < 0)
             {
-              printf("type: %d unmap plane (%s))\n",
-                      ctx->type, strerror(errno));
+              printf("nxcodec type: %s, unmap plane (%s))\n",
+                     V4L2_TYPE_IS_OUTPUT(ctx->type) ? "output" : "capture",
+                     strerror(errno));
             }
         }
     }
diff --git a/system/nxcodec/nxcodec_main.c b/system/nxcodec/nxcodec_main.c
index ea562fea5..39cc5308d 100644
--- a/system/nxcodec/nxcodec_main.c
+++ b/system/nxcodec/nxcodec_main.c
@@ -22,6 +22,7 @@
  * Included Files
  ****************************************************************************/
 
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <poll.h>
@@ -125,6 +126,9 @@ int main(int argc, FAR char **argv)
           case 'd':
             memset(codec.devname, 0, sizeof(codec.devname));
             snprintf(codec.devname, sizeof(codec.devname), "%s", optarg);
+
+            printf("nxcodec device name: %s\n", codec.devname);
+
             break;
 
           case 's' :
@@ -136,6 +140,10 @@ int main(int argc, FAR char **argv)
                                 codec.capture.format.fmt.pix.width;
             codec.output.format.fmt.pix.height =
                                 codec.capture.format.fmt.pix.height;
+            printf("nxcodec size: %lux%lu\n",
+                   codec.output.format.fmt.pix.width,
+                   codec.output.format.fmt.pix.height);
+
             break;
 
           case 'h':
@@ -156,6 +164,12 @@ int main(int argc, FAR char **argv)
                 codec.output.format.fmt.pix.pixelformat =
                                     v4l2_fourcc(cc[0], cc[1], cc[2], cc[3]);
               }
+
+            printf("nxcodec input  file: %s, format %c%c%c%c - %"PRIu32"\n",
+                   codec.output.filename,
+                   cc[0], cc[1], cc[2], cc[3],
+                   codec.output.format.fmt.pix.pixelformat);
+
             break;
 
           case 'o':
@@ -169,6 +183,12 @@ int main(int argc, FAR char **argv)
                 codec.capture.format.fmt.pix.pixelformat =
                                      v4l2_fourcc(cc[0], cc[1], cc[2], cc[3]);
               }
+
+            printf("nxcodec output file: %s, format %c%c%c%c - %"PRIu32"\n",
+                   codec.capture.filename,
+                   cc[0], cc[1], cc[2], cc[3],
+                   codec.capture.format.fmt.pix.pixelformat);
+
             break;
 
           default:
@@ -180,15 +200,21 @@ int main(int argc, FAR char **argv)
   ret = nxcodec_init(&codec);
   if (ret < 0)
     {
+      printf("nxcodec init failed: %d\n", ret);
       return ret;
     }
 
+  printf("nxcodec init DONE.\n");
+
   ret = nxcodec_start(&codec);
   if (ret < 0)
     {
+      printf("nxcodec start failed: %d\n", ret);
       goto end0;
     }
 
+  printf("nxcodec started.\n");
+
   while (1)
     {
       struct pollfd pfd =
@@ -203,6 +229,7 @@ int main(int argc, FAR char **argv)
         {
           if (nxcodec_context_dequeue_frame(&codec.capture) < 0)
             {
+              printf("nxcodec dequeue frame failed: %s\n", strerror(errno));
               break;
             }
         }
@@ -211,12 +238,14 @@ int main(int argc, FAR char **argv)
         {
           if (nxcodec_context_enqueue_frame(&codec.output) < 0)
             {
+              printf("nxcodec enqueue frame failed: %s\n", strerror(errno));
               break;
             }
         }
     }
 
   nxcodec_stop(&codec);
+  printf("nxcodec stop DONE.\n");
 
 end0:
   nxcodec_uninit(&codec);

Reply via email to