diff mbox series

[8/8] v4l2-tracer: auto generate flags for DECODER_CMD

Message ID 3bc061be5dc073a4b3f5dd950a9959ca3a7333c4.1699904350.git.deborah.brouwer@collabora.com
State New
Headers show
Series v4l2-tracer: expand to stateful decoding | expand

Commit Message

Deborah Brouwer Nov. 13, 2023, 8:06 p.m. UTC
The flags for V4L2_DEC_CMD_START STOP, and PAUSE aren’t being traced
correctly because unknown flags aren’t traced as hex values and only one
flag is traced per command. Auto generate the possible flags and use the
standard helper functions to trace and retrace them.

Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
 utils/v4l2-tracer/retrace.cpp        | 15 ++++++---------
 utils/v4l2-tracer/trace.cpp          | 15 +++------------
 utils/v4l2-tracer/v4l2-tracer-gen.pl | 21 +++++++++++++++++++++
 3 files changed, 30 insertions(+), 21 deletions(-)
diff mbox series

Patch

diff --git a/utils/v4l2-tracer/retrace.cpp b/utils/v4l2-tracer/retrace.cpp
index d251180e..03fe13f8 100644
--- a/utils/v4l2-tracer/retrace.cpp
+++ b/utils/v4l2-tracer/retrace.cpp
@@ -1064,8 +1064,7 @@  struct v4l2_decoder_cmd *retrace_v4l2_decoder_cmd(json_object *parent_obj)
 
 	switch (ptr->cmd) {
 	case V4L2_DEC_CMD_START: {
-		if (flags == "V4L2_DEC_CMD_START_MUTE_AUDIO")
-			ptr->flags = V4L2_DEC_CMD_START_MUTE_AUDIO;
+		ptr->flags = s2flags(flags.c_str(), v4l2_decoder_cmd_start_flag_def);
 
 		json_object *start_obj;
 		json_object_object_get_ex(v4l2_decoder_cmd_obj, "start", &start_obj);
@@ -1087,10 +1086,7 @@  struct v4l2_decoder_cmd *retrace_v4l2_decoder_cmd(json_object *parent_obj)
 		break;
 	}
 	case V4L2_DEC_CMD_STOP: {
-		if (flags == "V4L2_DEC_CMD_STOP_TO_BLACK")
-			ptr->flags = V4L2_DEC_CMD_STOP_TO_BLACK;
-		else if (flags == "V4L2_DEC_CMD_STOP_IMMEDIATELY")
-			ptr->flags = V4L2_DEC_CMD_STOP_IMMEDIATELY;
+		ptr->flags = s2flags(flags.c_str(), v4l2_decoder_cmd_stop_flag_def);
 
 		json_object *stop_obj;
 		json_object_object_get_ex(v4l2_decoder_cmd_obj, "stop", &stop_obj);
@@ -1101,8 +1097,7 @@  struct v4l2_decoder_cmd *retrace_v4l2_decoder_cmd(json_object *parent_obj)
 		break;
 	}
 	case V4L2_DEC_CMD_PAUSE: {
-		if (flags == "V4L2_DEC_CMD_PAUSE_TO_BLACK")
-			ptr->flags = V4L2_DEC_CMD_PAUSE_TO_BLACK;
+		ptr->flags = s2flags(flags.c_str(), v4l2_decoder_cmd_pause_flag_def);
 		break;
 	}
 	default:
@@ -1542,7 +1537,9 @@  int retrace(std::string trace_filename)
 	json_object *root_array_obj = json_object_from_file(trace_filename.c_str());
 
 	if (root_array_obj == nullptr) {
-		line_info("\n\tCan't get JSON-object from file: %s", trace_filename.c_str());
+		line_info("\n\t%s\tCan't get JSON-object from file: %s",
+			  json_util_get_last_err(),
+			  trace_filename.c_str());
 		return 1;
 	}
 
diff --git a/utils/v4l2-tracer/trace.cpp b/utils/v4l2-tracer/trace.cpp
index 31447f24..c4fc1584 100644
--- a/utils/v4l2-tracer/trace.cpp
+++ b/utils/v4l2-tracer/trace.cpp
@@ -466,10 +466,7 @@  void trace_v4l2_decoder_cmd(void *arg, json_object *ioctl_args)
 
 	switch (ptr->cmd) {
 	case V4L2_DEC_CMD_START: {
-		/*  This command has one flag: V4L2_DEC_CMD_START_MUTE_AUDIO. */
-		if (ptr->flags == V4L2_DEC_CMD_START_MUTE_AUDIO)
-			flags = "V4L2_DEC_CMD_START_MUTE_AUDIO";
-
+		flags = fl2s(ptr->flags, v4l2_decoder_cmd_start_flag_def);
 		/* struct start */
 		json_object *start_obj = json_object_new_object();
 		json_object_object_add(start_obj, "speed", json_object_new_int(ptr->start.speed));
@@ -486,12 +483,7 @@  void trace_v4l2_decoder_cmd(void *arg, json_object *ioctl_args)
 		break;
 	}
 	case V4L2_DEC_CMD_STOP: {
-		/*  This command has two flags */
-		if (ptr->flags == V4L2_DEC_CMD_STOP_TO_BLACK)
-			flags = "V4L2_DEC_CMD_STOP_TO_BLACK";
-		else if (ptr->flags == V4L2_DEC_CMD_STOP_IMMEDIATELY)
-			flags = "V4L2_DEC_CMD_STOP_IMMEDIATELY";
-
+		flags = fl2s(ptr->flags, v4l2_decoder_cmd_stop_flag_def);
 		json_object *stop_obj = json_object_new_object();
 		json_object_object_add(stop_obj, "pts", json_object_new_uint64(ptr->stop.pts));
 
@@ -500,8 +492,7 @@  void trace_v4l2_decoder_cmd(void *arg, json_object *ioctl_args)
 	}
 
 	case V4L2_DEC_CMD_PAUSE: {
-		if (ptr->flags == V4L2_DEC_CMD_PAUSE_TO_BLACK)
-			flags = "V4L2_DEC_CMD_PAUSE_TO_BLACK";
+		flags = fl2s(ptr->flags, v4l2_decoder_cmd_pause_flag_def);
 		break;
 	}
 	case V4L2_DEC_CMD_RESUME:
diff --git a/utils/v4l2-tracer/v4l2-tracer-gen.pl b/utils/v4l2-tracer/v4l2-tracer-gen.pl
index e8f9d71e..cb9c3ab5 100755
--- a/utils/v4l2-tracer/v4l2-tracer-gen.pl
+++ b/utils/v4l2-tracer/v4l2-tracer-gen.pl
@@ -123,6 +123,12 @@  sub val_def_gen {
 	}
 	($val) = ($_) =~ /^#define\s*(\w+)\s*/;
 	printf $fh_common_info_h "\t{ %s,\t\"%s\" },\n", $val, $val;
+
+	# in case there is only one value e.g. flags for V4L2_DEC_CMD_START
+	if ($val eq $last_val) {
+		printf $fh_common_info_h "\t{ $sentinel, \"\" }\n};\n\n";
+		return;
+	}
 	while (<>) {
 		next if ($_ =~ /^\s*\/?\s?\*.*/); # skip comments
 		next if ($_ =~ /^\s*$/);  # skip blank lines
@@ -1000,6 +1006,21 @@  while (<>) {
 		val_def_gen("V4L2_DEC_CMD_FLUSH");
 		next;
 	}
+	if (grep {/^#define V4L2_DEC_CMD_START_MUTE_AUDIO\s+/} $_) {
+		printf $fh_common_info_h "constexpr flag_def v4l2_decoder_cmd_start_flag_def[] = {\n";
+		flag_def_gen("V4L2_DEC_CMD_START_MUTE_AUDIO");
+		next;
+	}
+	if (grep {/^#define V4L2_DEC_CMD_PAUSE_TO_BLACK\s+/} $_) {
+		printf $fh_common_info_h "constexpr flag_def v4l2_decoder_cmd_pause_flag_def[] = {\n";
+		flag_def_gen("V4L2_DEC_CMD_PAUSE_TO_BLACK");
+		next;
+	}
+	if (grep {/^#define V4L2_DEC_CMD_STOP_TO_BLACK\s+/} $_) {
+		printf $fh_common_info_h "constexpr flag_def v4l2_decoder_cmd_stop_flag_def[] = {\n";
+		flag_def_gen("V4L2_DEC_CMD_STOP_IMMEDIATELY");
+		next;
+	}
 	if (grep {/^#define V4L2_EVENT_ALL\s+/} $_) {
 		printf $fh_common_info_h "constexpr val_def event_val_def[] = {\n";
 		val_def_gen("V4L2_EVENT_PRIVATE_START");