16
16
#include "video_ctrls.h"
17
17
#include "video_device.h"
18
18
19
+ #include "video_h264_test.h"
20
+
19
21
LOG_MODULE_REGISTER (video_sw_generator , CONFIG_VIDEO_LOG_LEVEL );
20
22
21
23
#define VIDEO_PATTERN_COLOR_BAR 0
@@ -66,6 +68,7 @@ static const struct video_format_cap fmts[] = {
66
68
VIDEO_SW_GENERATOR_FORMAT_CAP (VIDEO_PIX_FMT_SGRBG8 ),
67
69
VIDEO_SW_GENERATOR_FORMAT_CAP (VIDEO_PIX_FMT_SBGGR8 ),
68
70
VIDEO_SW_GENERATOR_FORMAT_CAP (VIDEO_PIX_FMT_SGBRG8 ),
71
+ VIDEO_SW_GENERATOR_FORMAT_CAP (VIDEO_PIX_FMT_H264 ),
69
72
{0 },
70
73
};
71
74
@@ -215,6 +218,31 @@ static uint16_t video_sw_generator_fill_bayer8(uint8_t *buffer, uint16_t width,
215
218
return 2 ;
216
219
}
217
220
221
+ static uint16_t video_sw_generator_fill_h264 (uint8_t * buffer , size_t buffer_size , uint32_t * bytes_filled )
222
+ {
223
+ /* Static counter to track position */
224
+ static size_t position = 0 ;
225
+ size_t copy_size ;
226
+
227
+ /* Calculate copy size */
228
+ size_t remaining = h264_test_data_len - position ;
229
+ copy_size = (remaining > buffer_size ) ? buffer_size : remaining ;
230
+
231
+ /* Copy H.264 data chunk to buffer */
232
+ if (copy_size > 0 ) {
233
+ memcpy (buffer , & h264_test_data [position ], copy_size );
234
+ position += copy_size ;
235
+
236
+ /* Loop back to beginning when we reach the end */
237
+ if (position >= h264_test_data_len ) {
238
+ position = 0 ;
239
+ }
240
+ }
241
+
242
+ * bytes_filled = copy_size ;
243
+ return 1 ;
244
+ }
245
+
218
246
static int video_sw_generator_fill (const struct device * const dev , struct video_buffer * vbuf )
219
247
{
220
248
struct video_sw_generator_data * data = dev -> data ;
@@ -258,6 +286,9 @@ static int video_sw_generator_fill(const struct device *const dev, struct video_
258
286
lines = video_sw_generator_fill_bayer8 (vbuf -> buffer , fmt -> width , hflip ,
259
287
pattern_grbg_idx );
260
288
break ;
289
+ case VIDEO_PIX_FMT_H264 :
290
+ lines = video_sw_generator_fill_h264 (vbuf -> buffer , vbuf -> size , & (vbuf -> bytesused ));
291
+ break ;
261
292
default :
262
293
CODE_UNREACHABLE ;
263
294
break ;
@@ -267,17 +298,20 @@ static int video_sw_generator_fill(const struct device *const dev, struct video_
267
298
return - EINVAL ;
268
299
}
269
300
270
- /* How much was filled in so far */
271
- vbuf -> bytesused = data -> fmt .pitch * lines ;
301
+ /* Skip duplication for compressed formats */
302
+ if (video_bits_per_pixel (fmt -> pixelformat ) > 0 ) {
303
+ /* How much was filled in so far */
304
+ vbuf -> bytesused = data -> fmt .pitch * lines ;
272
305
273
- /* Duplicate the first line(s) all over the buffer */
274
- for (int h = lines ; h < data -> fmt .height ; h += lines ) {
275
- if (vbuf -> size < vbuf -> bytesused + pitch * lines ) {
276
- LOG_WRN ("Generation stopped early: buffer too small" );
277
- break ;
306
+ /* Duplicate the first line(s) all over the buffer */
307
+ for (int h = lines ; h < data -> fmt .height ; h += lines ) {
308
+ if (vbuf -> size < vbuf -> bytesused + pitch * lines ) {
309
+ LOG_WRN ("Generation stopped early: buffer too small" );
310
+ break ;
311
+ }
312
+ memcpy (vbuf -> buffer + h * pitch , vbuf -> buffer , pitch * lines );
313
+ vbuf -> bytesused += pitch * lines ;
278
314
}
279
- memcpy (vbuf -> buffer + h * pitch , vbuf -> buffer , pitch * lines );
280
- vbuf -> bytesused += pitch * lines ;
281
315
}
282
316
283
317
vbuf -> timestamp = k_uptime_get_32 ();
@@ -473,10 +507,10 @@ static int video_sw_generator_init(const struct device *dev)
473
507
474
508
#define VIDEO_SW_GENERATOR_DEFINE (n ) \
475
509
static struct video_sw_generator_data video_sw_generator_data_##n = { \
476
- .fmt.width = 320 , \
477
- .fmt.height = 160 , \
478
- .fmt.pitch = 320 * 2, \
479
- .fmt.pixelformat = VIDEO_PIX_FMT_RGB565, \
510
+ .fmt.width = 640 , \
511
+ .fmt.height = 320 , \
512
+ .fmt.pitch = 0, \
513
+ .fmt.pixelformat = VIDEO_PIX_FMT_H264, \
480
514
.frame_rate = DEFAULT_FRAME_RATE, \
481
515
}; \
482
516
\
0 commit comments