/* * test_media_sync.c -- tests for the A/V clock (T7.5) * * License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. */ #include "dc_internal.h" #include static int fails; #define CHECK(cond) do { \ if (!(cond)) { \ fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, \ #cond); \ fails++; \ } \ } while (0) int main(void) { DcSync sync; dc_sync_init(&sync); CHECK(sync.audio_ms == 0); /* the first frame at zero is exactly on time */ CHECK(dc_sync_video(&sync, 0) == 1); CHECK(dc_sync_offset(&sync) == 0); CHECK(dc_sync_dropped(&sync) == 0); /* 20 ms of audio: 20 ms late is fine */ dc_sync_audio(&sync, 1); CHECK(sync.audio_ms == DC_AUDIO_FRAME_MS); CHECK(dc_sync_video(&sync, 0) == 1); CHECK(dc_sync_offset(&sync) == -20); /* 100 ms of audio: video at 0 is 100 ms late, more than the budget */ dc_sync_audio(&sync, 4); CHECK(sync.audio_ms == 100); CHECK(dc_sync_video(&sync, 0) == 0); CHECK(dc_sync_dropped(&sync) == 1); /* exactly the budget is still rendered */ CHECK(dc_sync_video(&sync, 20) == 1); CHECK(dc_sync_offset(&sync) == -80); /* early frames are rendered too */ CHECK(dc_sync_video(&sync, 120) == 1); CHECK(dc_sync_offset(&sync) == 20); /* one millisecond past the budget is dropped */ CHECK(dc_sync_video(&sync, 19) == 0); CHECK(dc_sync_dropped(&sync) == 2); /* a long call stays correct */ dc_sync_audio(&sync, 3000); /* one minute */ CHECK(sync.audio_ms == 60100); CHECK(dc_sync_video(&sync, 60050) == 1); CHECK(dc_sync_offset(&sync) == -50); CHECK(dc_sync_video(&sync, 60100) == 1); CHECK(dc_sync_offset(&sync) == 0); /* a frame far behind is dropped, a far ahead one rendered */ CHECK(dc_sync_video(&sync, 1000) == 0); CHECK(dc_sync_video(&sync, 70000) == 1); /* NULL is not a crash */ dc_sync_init(NULL); dc_sync_audio(NULL, 1); CHECK(dc_sync_video(NULL, 0) == 0); CHECK(dc_sync_offset(NULL) == 0); CHECK(dc_sync_dropped(NULL) == 0); if (fails != 0) { fprintf(stderr, "%d test(s) failed\n", fails); return 1; } printf("test_media_sync: all ok\n"); return 0; }