@@ -127,6 +127,22 @@ static int cmd_video_stop(const struct shell *sh, size_t argc, char **argv)
127127 return 0 ;
128128}
129129
130+ static void video_shell_print_buffer (const struct shell * sh , struct video_buffer * vbuf ,
131+ struct video_format * fmt , int i , uint32_t num_buffer ,
132+ uint32_t frmrate_fps , uint32_t frmival_msec )
133+ {
134+ uint32_t line_offset = vbuf -> line_offset ;
135+ uint32_t byte_offset = line_offset * fmt -> pitch ;
136+ uint32_t bytes_in_buf = vbuf -> bytesused ;
137+ uint32_t lines_in_buf = vbuf -> bytesused / fmt -> pitch ;
138+
139+ shell_print (sh , "Buffer %u/%u at %u ms, Bytes %u-%u/%u, Lines %u-%u/%u, Rate %u FPS %u ms" ,
140+ /* Buffer */ i + 1 , num_buffer , vbuf -> timestamp ,
141+ /* Bytes */ byte_offset , byte_offset + bytes_in_buf , fmt -> height * fmt -> pitch ,
142+ /* Lines */ line_offset , line_offset + lines_in_buf , fmt -> height ,
143+ /* Rate */ frmrate_fps , frmival_msec );
144+ }
145+
130146static int cmd_video_capture (const struct shell * sh , size_t argc , char * * argv )
131147{
132148 const struct device * dev ;
@@ -140,7 +156,7 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
140156 uint32_t frmival_msec ;
141157 uint32_t frmrate_fps ;
142158 size_t buf_size ;
143- unsigned long num_frames ;
159+ unsigned long num_buffers ;
144160 int ret ;
145161
146162 dev = device_get_binding (argv [1 ]);
@@ -155,7 +171,7 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
155171 return ret ;
156172 }
157173
158- num_frames = strtoull (arg2 , & arg2 , 10 );
174+ num_buffers = strtoull (arg2 , & arg2 , 10 );
159175 if (* arg2 != '\0' ) {
160176 shell_error (sh , "Invalid integer '%s' for this type" , argv [1 ]);
161177 return - EINVAL ;
@@ -180,7 +196,7 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
180196 }
181197 }
182198
183- shell_print (sh , "Starting the capture of %lu frames from %s" , num_frames , dev -> name );
199+ shell_print (sh , "Starting the capture of %lu buffers from %s" , num_buffers , dev -> name );
184200
185201 ret = video_stream_start (dev );
186202 if (ret != 0 ) {
@@ -190,7 +206,7 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
190206
191207 first_uptime = prev_uptime = this_uptime = k_uptime_get_32 ();
192208
193- for (unsigned long i = 0 ; i < num_frames ;) {
209+ for (unsigned long i = 0 ; i < num_buffers ;) {
194210 ret = video_dequeue (dev , VIDEO_EP_OUT , & vbuf , K_FOREVER );
195211 if (ret != 0 ) {
196212 shell_error (sh , "Failed to dequeue this buffer: %s" , strerror (- ret ));
@@ -202,12 +218,7 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
202218 frmrate_fps = (frmival_msec == 0 ) ? (UINT32_MAX ) : (MSEC_PER_SEC / frmival_msec );
203219 prev_uptime = this_uptime ;
204220
205- shell_print (sh , "Frame %3lu/%lu, Bytes %u-%u/%u, Lines %u-%u/%u, %u ms %u FPS" ,
206- i , num_frames , vbuf -> line_offset * fmt .pitch ,
207- vbuf -> line_offset * fmt .pitch + vbuf -> bytesused , vbuf -> size ,
208- vbuf -> line_offset ,
209- vbuf -> line_offset + vbuf -> bytesused / fmt .pitch , fmt .height ,
210- frmival_msec , frmrate_fps );
221+ video_shell_print_buffer (sh , vbuf , & fmt , i , num_buffers , frmrate_fps , frmival_msec );
211222
212223 /* Only increment the frame counter on the beginning of a new frame */
213224 i += (vbuf -> line_offset == 0 );
@@ -221,10 +232,10 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
221232
222233 frmival_msec = this_uptime - first_uptime ;
223234 frmrate_fps =
224- (frmival_msec == 0 ) ? (UINT32_MAX ) : (num_frames * MSEC_PER_SEC / frmival_msec );
235+ (frmival_msec == 0 ) ? (UINT32_MAX ) : (num_buffers * MSEC_PER_SEC / frmival_msec );
225236
226- shell_print (sh , "Capture of %lu frames in %u ms in total, %u FPS on average, stopping %s" ,
227- num_frames , frmival_msec , frmrate_fps , dev -> name );
237+ shell_print (sh , "Capture of %lu buffers in %u ms in total, %u FPS on average, stopping %s" ,
238+ num_buffers , frmival_msec , frmrate_fps , dev -> name );
228239
229240end :
230241 video_stream_stop (dev );
@@ -1021,8 +1032,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_video_cmds,
10211032 "Usage: video stop <device>" ,
10221033 cmd_video_stop , 2 , 0 ),
10231034 SHELL_CMD_ARG (capture , & dsub_video_dev ,
1024- "Capture a given number of frames from a device\n"
1025- "Usage: video capture <device> <num-frames >" ,
1035+ "Capture a given number of buffers from a device\n"
1036+ "Usage: video capture <device> <num-buffers >" ,
10261037 cmd_video_capture , 3 , 0 ),
10271038 SHELL_CMD_ARG (format , & dsub_video_format_dev ,
10281039 "Query or set the video format of a device\n"
0 commit comments