media_capture.c: V4L2 (YUYV, 4 mmap buffers, poll, QBUF again after use) and a test pattern; a camera with another size is scaled to the call's 640x360, and a build without HAVE_V4L2 gets the pattern. On this T14 the integrated camera is /dev/video0 and gives frames (test_capture: v4l2:/dev/video0, non-uniform frame, 320x180 through the scaler; pattern frames differ and have Y and chroma). configure defines HAVE_V4L2 for linux/videodev2.h. media_video.c gains dc_vpx_enc_keyframe (VPX_EFLAG_FORCE_KF on the next frame), media_packet a DC_MEDIA_KFREQ control, media_call dc_call_request_keyframe/take and DC_MEDIA_KFREQ in the sealed type range. dc_call_video_out now decodes the reassembled VP8 frame into I420 (it returned the compressed frame, which the UI drew as a green picture); dc_call_video_packet keeps the compressed frame for tests and recordings. Video timestamps are wall clock, not frame counts, so a pump slower than 15 fps does not drift behind the audio clock. localui starts camera+encoder on entering the call, sends 15 fps, requests a keyframe after a loss, forces one when asked, decodes incoming frames into the call window, drains up to four 20 ms capture frames per 40 ms pump (one per pump halved the audio clock), and logs video in/out under DTCHAT_CALL_DEBUG; DTCHAT_TEST_VIDEO switches to the pattern. Two UIs under Xvfb: A pattern, B camera, 90 frames each way in about 6 s, audio 300 frames (real time), the window shows the peer's picture (build/mcde-shots/dtchat-t71-video-call.png). test_video_packet uses the packet interface; its 50 KB/42-fragment loopback check still passes. New harness entry DtChat/test_capture (43). In-tree build pending: a foreign make release holds the lock.
129 lines
3.0 KiB
C
129 lines
3.0 KiB
C
/*
|
|
* test_capture.c -- tests for the camera layer (T7.1)
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* The test pattern is checked to the frame (size, changing content, non-blank
|
|
* Y and chroma). A camera is opened when /dev/video0 exists: a frame must
|
|
* arrive and be non-uniform; a machine without a camera (or with one that is
|
|
* busy) skips that part, because the pattern is the fallback and its check is
|
|
* the one that always runs.
|
|
*/
|
|
#include "dc_internal.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static int fails;
|
|
|
|
#define CHECK(cond) do { \
|
|
if (!(cond)) { \
|
|
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, \
|
|
#cond); \
|
|
fails++; \
|
|
} \
|
|
} while (0)
|
|
|
|
static int
|
|
nonuniform(const unsigned char *p, size_t n)
|
|
{
|
|
size_t i;
|
|
|
|
for (i = 1; i < n; i++)
|
|
if (p[i] != p[0])
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
unsigned char *a;
|
|
unsigned char *b;
|
|
DcCapture *cap;
|
|
char err[256] = "";
|
|
size_t ysize = (size_t)DC_VIDEO_W * DC_VIDEO_H;
|
|
int i;
|
|
|
|
a = malloc(ysize * 3 / 2);
|
|
b = malloc(ysize * 3 / 2);
|
|
CHECK(a != NULL && b != NULL);
|
|
if (a == NULL || b == NULL)
|
|
return 1;
|
|
|
|
/* the pattern: two frames differ, both have a Y and chroma signal */
|
|
cap = dc_capture_open(DC_VIDEO_W, DC_VIDEO_H, DC_VIDEO_FPS, "pattern",
|
|
err, sizeof(err));
|
|
CHECK(cap != NULL);
|
|
if (cap == NULL) {
|
|
fprintf(stderr, "pattern: %s\n", err);
|
|
free(a);
|
|
free(b);
|
|
return 1;
|
|
}
|
|
CHECK(strcmp(dc_capture_backend(cap), "test-pattern") == 0);
|
|
CHECK(dc_capture_frame(cap, a, 0) == 1);
|
|
CHECK(dc_capture_frame(cap, b, 0) == 1);
|
|
CHECK(memcmp(a, b, ysize * 3 / 2) != 0);
|
|
CHECK(nonuniform(a, ysize));
|
|
CHECK(nonuniform(a + ysize, ysize / 2));
|
|
/* the bad sizes are refused */
|
|
{
|
|
DcCapture *bad = dc_capture_open(0, 0, 15, "pattern", err,
|
|
sizeof(err));
|
|
|
|
CHECK(bad == NULL);
|
|
}
|
|
dc_capture_close(cap);
|
|
|
|
/* a real camera, when this machine has one */
|
|
{
|
|
FILE *f = fopen("/dev/video0", "r");
|
|
|
|
if (f == NULL) {
|
|
printf("capture: no /dev/video0, camera skipped\n");
|
|
} else {
|
|
fclose(f);
|
|
cap = dc_capture_open(DC_VIDEO_W, DC_VIDEO_H,
|
|
DC_VIDEO_FPS, "auto", err, sizeof(err));
|
|
if (cap == NULL) {
|
|
printf("capture: camera not usable (%s), "
|
|
"skipped\n", err);
|
|
} else {
|
|
int got = 0;
|
|
|
|
printf("capture: camera is %s\n",
|
|
dc_capture_backend(cap));
|
|
for (i = 0; i < 20 && !got; i++)
|
|
got = dc_capture_frame(cap, a, 500);
|
|
CHECK(got == 1);
|
|
if (got == 1)
|
|
CHECK(nonuniform(a, ysize));
|
|
/* a second size goes through the scaler */
|
|
dc_capture_close(cap);
|
|
cap = dc_capture_open(320, 180, 15,
|
|
"auto", err, sizeof(err));
|
|
CHECK(cap != NULL);
|
|
if (cap != NULL) {
|
|
got = 0;
|
|
for (i = 0; i < 20 && !got; i++)
|
|
got = dc_capture_frame(cap,
|
|
a, 500);
|
|
CHECK(got == 1);
|
|
dc_capture_close(cap);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
free(a);
|
|
free(b);
|
|
if (fails != 0) {
|
|
fprintf(stderr, "%d test(s) failed\n", fails);
|
|
return 1;
|
|
}
|
|
printf("test_capture: all ok\n");
|
|
return 0;
|
|
}
|