Verify bounded assembly of large retained frames without new packets
This commit is contained in:
1 parent
30ab69fc5f
commit
2865158f2e
1 file changed
+38
@@ -155,12 +155,50 @@ static void test_shared_media_ring(void) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_STREAM, "[PASS] media ring: independent readers, authenticated frozen parts, lookahead, expiry, GAP and EOF");
|
||||
}
|
||||
|
||||
/* Полный кадр уже в общем кольце: MORE продолжает ограниченную сборку без новых сетевых событий. */
|
||||
static void test_large_frame_budget(void) {
|
||||
uint8_t key[32] = {2}; struct stream_encoder *encoder = NULL; struct stream_buffer *buffer = NULL;
|
||||
struct stream_media_store *store = NULL; struct stream_media_cursor *cursor = NULL;
|
||||
CHECK(stream_encoder_create(&encoder, &descriptor, key) == STREAM_OK);
|
||||
CHECK(stream_buffer_create(&buffer, &descriptor, stream_encoder_public_key(encoder), 1024 * 1300) == STREAM_OK);
|
||||
CHECK(stream_media_store_create(&store, buffer, &descriptor) == STREAM_OK);
|
||||
CHECK(stream_media_cursor_create(&cursor, store, STREAM_MEDIA_TRACK_VIDEO) == STREAM_OK);
|
||||
size_t frame_size = 200000; uint8_t *frame = u_malloc((uint32_t)frame_size); CHECK(frame);
|
||||
for (size_t i = 0; i < frame_size; i++) frame[i] = (uint8_t)(i * 19 + 7);
|
||||
unsigned seq = 0;
|
||||
for (size_t offset = 0; offset < frame_size; seq++) {
|
||||
size_t take = frame_size - offset; if (take > 6000) take = 6000;
|
||||
struct stream_media_block media = {.format = {64, 64, 0, STREAM_MEDIA_H264, 0, 1}, .video_count = 1};
|
||||
media.video[0] = (struct stream_media_video){1, 1000000, (uint32_t)frame_size, (uint32_t)offset,
|
||||
(uint32_t)take, STREAM_MEDIA_KEY, frame + offset};
|
||||
uint8_t data[7345], decoded[7345]; size_t length = 0, decoded_length = 0, part_size = 0;
|
||||
const uint8_t *parts[RS_MAX_BLOCKS];
|
||||
CHECK(stream_media_encode(&media, data, sizeof(data), &length) == STREAM_OK);
|
||||
CHECK(stream_encoder_encode(encoder, seq, 1, 0, data, length, parts, &part_size) == STREAM_OK);
|
||||
for (unsigned sub = 0; sub < 8; sub++) CHECK(stream_buffer_put(buffer, parts[sub], part_size) == STREAM_OK);
|
||||
CHECK(stream_buffer_decode(buffer, seq, decoded, sizeof(decoded), &decoded_length) == STREAM_OK);
|
||||
CHECK(stream_media_store_feed(store, seq, decoded, decoded_length) == STREAM_OK);
|
||||
offset += take;
|
||||
}
|
||||
struct stream_media_packet packet; unsigned more = 0; int result;
|
||||
do { result = stream_media_cursor_read(cursor, -1, 0, -1, &packet); if (result == STREAM_MORE) more++; }
|
||||
while (result == STREAM_MORE && more < 10);
|
||||
CHECK(result == STREAM_OK && more >= 2 && packet.kind == STREAM_MEDIA_READ_VIDEO);
|
||||
CHECK(packet.video.length == frame_size && !memcmp(packet.video.data, frame, frame_size));
|
||||
stream_media_store_finish(store);
|
||||
CHECK(stream_media_cursor_read(cursor, 1000000, 0, -1, &packet) == STREAM_OK && packet.kind == STREAM_MEDIA_READ_END);
|
||||
stream_media_cursor_destroy(cursor); stream_media_store_destroy(store); stream_buffer_destroy(buffer);
|
||||
stream_encoder_destroy(encoder); u_free(frame);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_STREAM, "[PASS] large frame: bounded MORE work, complete existing-ring assembly and video-only EOF");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR);
|
||||
debug_set_category_level(DEBUG_CATEGORY_STREAM, DEBUG_LEVEL_INFO);
|
||||
size_t allocations = u_get_allocated_count();
|
||||
for (unsigned i = 0; i < sizeof(video_bytes); i++) video_bytes[i] = (uint8_t)(i * 71 + 3);
|
||||
test_history_correction(); test_catchup_device_queue(); test_invalid_and_sampling_gap(); test_shared_media_ring();
|
||||
test_large_frame_budget();
|
||||
CHECK(u_get_allocated_count() == allocations);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user