Verify all media codec IDs and key configuration bounds
This commit is contained in:
1 parent
876a5a65ec
commit
305eacbe95
2 files changed
+21
-2
No files matched your search
@@ -205,13 +205,32 @@ static void test_stereo(void) {
|
||||
stream_media_receiver_destroy(receiver);
|
||||
}
|
||||
|
||||
static void test_codecs(void) {
|
||||
uint8_t wire[256], key[] = {0, 0, 0, 2, 11, 12, 13}; size_t length = 0;
|
||||
struct stream_media_block b = {.format = {64, 64, 0, STREAM_MEDIA_H264, 0, 1}, .video_count = 1};
|
||||
b.video[0] = (struct stream_media_video){1, 0, sizeof(key), 0, sizeof(key), STREAM_MEDIA_KEY, key};
|
||||
struct stream_media_block parsed;
|
||||
for (unsigned codec = STREAM_MEDIA_H264; codec <= STREAM_MEDIA_H266; codec++) {
|
||||
b.format.video_codec = codec;
|
||||
CHECK(stream_media_encode(&b, wire, sizeof(wire), &length) == STREAM_OK && !memcmp(wire, "uAV2", 4));
|
||||
CHECK(stream_media_parse(wire, length, &parsed) == STREAM_OK && parsed.format.video_codec == codec);
|
||||
}
|
||||
wire[3] = '1'; CHECK(stream_media_parse(wire, length, &parsed) == STREAM_ERR_FORMAT);
|
||||
const uint8_t *config, *frame; size_t config_size, frame_size;
|
||||
CHECK(stream_media_key_parse(key, sizeof(key), &config, &config_size, &frame, &frame_size) == STREAM_OK);
|
||||
CHECK(config_size == 2 && frame_size == 1 && config[0] == 11 && frame[0] == 13);
|
||||
for (size_t n = 0; n < sizeof(key); n++) CHECK(stream_media_key_parse(key, n, &config, &config_size, &frame, &frame_size) < 0);
|
||||
key[0] = 1; CHECK(stream_media_key_parse(key, sizeof(key), &config, &config_size, &frame, &frame_size) < 0);
|
||||
memset(key, 0, 4); CHECK(stream_media_key_parse(key, sizeof(key), &config, &config_size, &frame, &frame_size) == STREAM_OK);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
debug_config_init(); debug_set_level(DEBUG_LEVEL_INFO);
|
||||
/* Усечения проверяются массово; ожидаемые отказы не загромождают диагностический лог. */
|
||||
debug_set_category_level(DEBUG_CATEGORY_STREAM, DEBUG_LEVEL_DISABLED);
|
||||
size_t before = u_get_allocated_count();
|
||||
for (unsigned i = 0; i < sizeof(expected_video); i++) expected_video[i] = (uint8_t)(i * 31 + 7);
|
||||
test_media(); test_batches(); test_revisions(); test_stereo();
|
||||
test_media(); test_batches(); test_revisions(); test_stereo(); test_codecs();
|
||||
CHECK(u_get_allocated_count() == before);
|
||||
debug_set_category_level(DEBUG_CATEGORY_STREAM, DEBUG_LEVEL_INFO);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_STREAM, "PASS stream_media: protocol, FEC, frame recovery, boundaries, no leaks");
|
||||
|
||||
Reference in new issue
Block a user