@@ -127,6 +127,22 @@ static int cmd_video_stop(const struct shell *sh, size_t argc, char **argv)
127
127
return 0 ;
128
128
}
129
129
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
+
130
146
static int cmd_video_capture (const struct shell * sh , size_t argc , char * * argv )
131
147
{
132
148
const struct device * dev ;
@@ -140,7 +156,7 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
140
156
uint32_t frmival_msec ;
141
157
uint32_t frmrate_fps ;
142
158
size_t buf_size ;
143
- unsigned long num_frames ;
159
+ unsigned long num_buffers ;
144
160
int ret ;
145
161
146
162
dev = device_get_binding (argv [1 ]);
@@ -155,7 +171,7 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
155
171
return ret ;
156
172
}
157
173
158
- num_frames = strtoull (arg2 , & arg2 , 10 );
174
+ num_buffers = strtoull (arg2 , & arg2 , 10 );
159
175
if (* arg2 != '\0' ) {
160
176
shell_error (sh , "Invalid integer '%s' for this type" , argv [1 ]);
161
177
return - EINVAL ;
@@ -180,7 +196,7 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
180
196
}
181
197
}
182
198
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 );
184
200
185
201
ret = video_stream_start (dev );
186
202
if (ret != 0 ) {
@@ -190,7 +206,7 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
190
206
191
207
first_uptime = prev_uptime = this_uptime = k_uptime_get_32 ();
192
208
193
- for (unsigned long i = 0 ; i < num_frames ;) {
209
+ for (unsigned long i = 0 ; i < num_buffers ;) {
194
210
ret = video_dequeue (dev , VIDEO_EP_OUT , & vbuf , K_FOREVER );
195
211
if (ret != 0 ) {
196
212
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)
202
218
frmrate_fps = (frmival_msec == 0 ) ? (UINT32_MAX ) : (MSEC_PER_SEC / frmival_msec );
203
219
prev_uptime = this_uptime ;
204
220
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 );
211
222
212
223
/* Only increment the frame counter on the beginning of a new frame */
213
224
i += (vbuf -> line_offset == 0 );
@@ -221,10 +232,10 @@ static int cmd_video_capture(const struct shell *sh, size_t argc, char **argv)
221
232
222
233
frmival_msec = this_uptime - first_uptime ;
223
234
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 );
225
236
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 );
228
239
229
240
end :
230
241
video_stream_stop (dev );
@@ -1021,8 +1032,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_video_cmds,
1021
1032
"Usage: video stop <device>" ,
1022
1033
cmd_video_stop , 2 , 0 ),
1023
1034
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 >" ,
1026
1037
cmd_video_capture , 3 , 0 ),
1027
1038
SHELL_CMD_ARG (format , & dsub_video_format_dev ,
1028
1039
"Query or set the video format of a device\n"
0 commit comments