46 #define DEFAULT_FRAME_MS 160 47 #define DEFAULT_CONFIG_FLAGS 0 48 #define DEFAULT_CONFIG_SIZE (DEFAULT_FRAME_MS) * 10 49 #define DEFAULT_CONFIG_RESYNC_THRESHOLD (DEFAULT_FRAME_MS) * 2 50 #define DEFAULT_CONFIG_TARGET_EXTRA -1 100 #define LONG_INT_TEST(actual, expected) do { \ 101 if ((actual) != (expected)) { \ 102 ast_test_status_update(test, #actual ": expected [%ld]; actual [%ld]\n", (long int)(expected), (long int)(actual)); \ 103 return AST_TEST_FAIL; \ 109 #define INT_TEST(actual, expected) do { \ 110 if ((actual) != (expected)) { \ 111 ast_test_status_update(test, #actual ": expected [%d]; actual [%d]\n", (expected), (actual)); \ 112 return AST_TEST_FAIL; \ 118 #define UINT_TEST(actual, expected) do { \ 119 if ((actual) != (expected)) { \ 120 ast_test_status_update(test, #actual ": expected [%u]; actual [%u]\n", (expected), (actual)); \ 121 return AST_TEST_FAIL; \ 127 #define STRING_TEST(actual, expected) do { \ 128 if (strcmp((actual), (expected))) { \ 129 ast_test_status_update(test, #actual ": expected [%s]; actual [%s]\n", (expected), (actual)); \ 130 return AST_TEST_FAIL; \ 136 #define VERIFY_FRAME(actual, expected) do { \ 137 UINT_TEST((actual)->frametype, (expected)->frametype); \ 138 INT_TEST((actual)->seqno, (expected)->seqno); \ 139 LONG_INT_TEST((actual)->ts, (expected)->ts); \ 140 LONG_INT_TEST((actual)->len, (expected)->len); \ 141 STRING_TEST((actual)->src, (expected)->src); \ 147 #define OBTAIN_JITTERBUFFER_IMPL(impl, ast_jb_type, literal_name) do { \ 148 (impl) = ast_jb_get_impl((ast_jb_type)); \ 150 ast_test_status_update(test, "Error: no %s jitterbuffer defined\n", (literal_name)); \ 151 return AST_TEST_FAIL; \ 153 if (strcmp((impl)->name, (literal_name))) { \ 154 ast_test_status_update(test, "Error: requested %s jitterbuffer and received %s\n", (literal_name), (impl)->name); \ 155 return AST_TEST_FAIL; \ 161 #define MAKE_DEFAULT_CONFIG(conf, impl) do { \ 162 (conf)->flags = DEFAULT_CONFIG_FLAGS; \ 163 strcpy((conf)->impl, (impl)->name); \ 164 (conf)->max_size = DEFAULT_CONFIG_SIZE; \ 165 (conf)->resync_threshold = DEFAULT_CONFIG_RESYNC_THRESHOLD; \ 166 (conf)->target_extra = DEFAULT_CONFIG_TARGET_EXTRA; \ 182 #define TEST_NAME(type_name, specifier) type_name ## _ ## specifier 184 #define TEST_NAME2(test_name) #test_name 185 #define STRINGIFY_TESTNAME(test_name) TEST_NAME2(test_name) 194 #define test_create_nominal(type_name, literal_type_name) AST_TEST_DEFINE(TEST_NAME(type_name, create)) {\ 195 RAII_VAR(struct ast_jb *, jb, &default_jb, dispose_jitterbuffer); \ 196 const struct ast_jb_impl *impl; \ 197 struct ast_jb_conf conf; \ 201 info->name = STRINGIFY_TESTNAME(TEST_NAME(type_name, create)); \ 202 info->category = "/main/abstract_jb/"; \ 203 info->summary = "Test nominal creation of a " literal_type_name " jitterbuffer"; \ 204 info->description = \ 205 "Tests nominal creation of a " literal_type_name " jitterbuffer using the " \ 206 " jitterbuffer API."; \ 207 return AST_TEST_NOT_RUN; \ 212 ast_test_status_update(test, "Executing " STRINGIFY_TESTNAME(TEST_NAME(type_name, create))"...\n"); \ 213 OBTAIN_JITTERBUFFER_IMPL(impl, (type_name), (literal_type_name)); \ 214 MAKE_DEFAULT_CONFIG(&conf, impl); \ 216 jb->jbobj = impl->create(&conf); \ 219 ast_test_status_update(test, "Error: Failed to adaptive jitterbuffer\n"); \ 220 return AST_TEST_FAIL; \ 223 return AST_TEST_PASS; \ 233 #define test_put_first(type_name, literal_type_name) AST_TEST_DEFINE(TEST_NAME(type_name, put_first)) {\ 234 RAII_VAR(struct ast_jb *, jb, &default_jb, dispose_jitterbuffer); \ 235 const struct ast_jb_impl *impl; \ 236 struct ast_jb_conf conf; \ 237 RAII_VAR(struct ast_frame *, expected_frame, NULL, ast_frame_dtor); \ 238 RAII_VAR(struct ast_frame *, actual_frame, NULL, ast_frame_dtor); \ 243 info->name = STRINGIFY_TESTNAME(TEST_NAME(type_name, put_first)); \ 244 info->category = "/main/abstract_jb/"; \ 245 info->summary = "Test putting a frame into a " literal_type_name " jitterbuffer"; \ 246 info->description = \ 247 "This tests putting a single frame into a " literal_type_name " jitterbuffer " \ 248 "when the jitterbuffer is empty and verifying that it is indeed " \ 249 "the first frame on the jitterbufffer"; \ 250 return AST_TEST_NOT_RUN; \ 255 ast_test_status_update(test, "Executing " STRINGIFY_TESTNAME(TEST_NAME(type_name, create))"...\n"); \ 256 OBTAIN_JITTERBUFFER_IMPL(impl, (type_name), (literal_type_name)); \ 257 MAKE_DEFAULT_CONFIG(&conf, impl); \ 258 jb->jbobj = impl->create(&conf); \ 261 ast_test_status_update(test, "Error: Failed to adaptive jitterbuffer\n"); \ 262 return AST_TEST_FAIL; \ 265 expected_frame = create_test_frame(1000, 0); \ 266 res = jb->impl->put_first(jb->jbobj, \ 269 if (res != AST_JB_IMPL_OK) { \ 270 ast_test_status_update(test, "Error: Got %d back from put_first (expected %d)\n", \ 271 res, AST_JB_IMPL_OK); \ 272 return AST_TEST_FAIL; \ 275 res = jb->impl->remove(jb->jbobj, &actual_frame); \ 276 if (!actual_frame || res != AST_JB_IMPL_OK) { \ 277 ast_test_status_update(test, "Error: failed to retrieve first frame\n"); \ 278 return AST_TEST_FAIL; \ 280 expected_frame = create_test_frame(1000, 0); \ 281 VERIFY_FRAME(actual_frame, expected_frame); \ 282 return AST_TEST_PASS; \ 292 #define test_put(type_name, literal_type_name) AST_TEST_DEFINE(TEST_NAME(type_name, put)) {\ 293 RAII_VAR(struct ast_jb *, jb, &default_jb, dispose_jitterbuffer); \ 294 const struct ast_jb_impl *impl; \ 295 struct ast_jb_conf conf; \ 296 RAII_VAR(struct ast_frame *, expected_frame, NULL, ast_frame_dtor); \ 297 RAII_VAR(struct ast_frame *, actual_frame, NULL, ast_frame_dtor); \ 304 info->name = STRINGIFY_TESTNAME(TEST_NAME(type_name, put)); \ 305 info->category = "/main/abstract_jb/"; \ 306 info->summary = "Test putting frames onto a " literal_type_name " jitterbuffer"; \ 307 info->description = \ 308 "This tests putting multiple frames into a " literal_type_name " jitterbuffer"; \ 309 return AST_TEST_NOT_RUN; \ 314 ast_test_status_update(test, "Executing "STRINGIFY_TESTNAME(TEST_NAME(type_name, put))"...\n"); \ 315 OBTAIN_JITTERBUFFER_IMPL(impl, (type_name), (literal_type_name)); \ 316 MAKE_DEFAULT_CONFIG(&conf, impl); \ 317 jb->jbobj = impl->create(&conf); \ 320 expected_frame = create_test_frame(1000, 0); \ 321 jb->impl->put_first(jb->jbobj, expected_frame, 1100); \ 322 for (i = 1; i < 10; i++) { \ 323 expected_frame = create_test_frame(1000 + i * DEFAULT_FRAME_MS, 0); \ 324 res = jb->impl->put(jb->jbobj, \ 326 1100 + i * DEFAULT_FRAME_MS); \ 327 if (res != AST_JB_IMPL_OK) { \ 328 ast_test_status_update(test, "Error: On frame %d, got %d back from put (expected %d)\n", \ 329 i, res, AST_JB_IMPL_OK); \ 330 return AST_TEST_FAIL; \ 334 for (i = 0; i < 10; i++) { \ 335 expected_frame = create_test_frame(1000 + i * DEFAULT_FRAME_MS, 0); \ 336 next = jb->impl->next(jb->jbobj); \ 337 res = jb->impl->get(jb->jbobj, &actual_frame, next, DEFAULT_FRAME_MS); \ 338 if (res != AST_JB_IMPL_OK) { \ 339 ast_test_status_update(test, "Error: failed to retrieve frame %i at time %ld\n", \ 341 return AST_TEST_FAIL; \ 343 VERIFY_FRAME(actual_frame, expected_frame); \ 344 ast_frfree(expected_frame); \ 345 expected_frame = NULL; \ 347 return AST_TEST_PASS; \ 358 #define test_put_overflow(type_name, literal_type_name, overflow_limit) AST_TEST_DEFINE(TEST_NAME(type_name, put_overflow)) {\ 359 RAII_VAR(struct ast_jb *, jb, &default_jb, dispose_jitterbuffer); \ 360 const struct ast_jb_impl *impl; \ 361 struct ast_jb_conf conf; \ 362 RAII_VAR(struct ast_frame *, expected_frame, NULL, ast_frame_dtor); \ 368 info->name = STRINGIFY_TESTNAME(TEST_NAME(type_name, put_overflow)); \ 369 info->category = "/main/abstract_jb/"; \ 370 info->summary = "Test putting frames onto a " literal_type_name " jitterbuffer " \ 371 "that ends up overflowing the maximum allowed slots in the buffer"; \ 372 info->description = \ 373 "This tests putting multiple frames into a " literal_type_name " jitterbuffer " \ 374 "until the jitterbuffer overflows"; \ 375 return AST_TEST_NOT_RUN; \ 380 ast_test_status_update(test, "Executing "STRINGIFY_TESTNAME(TEST_NAME(type_name, put_overflow))"...\n"); \ 381 OBTAIN_JITTERBUFFER_IMPL(impl, (type_name), (literal_type_name)); \ 382 MAKE_DEFAULT_CONFIG(&conf, impl); \ 383 jb->jbobj = impl->create(&conf); \ 386 expected_frame = create_test_frame(1000, 0); \ 387 jb->impl->put_first(jb->jbobj, expected_frame, 1100); \ 388 for (i = 1; i <= (overflow_limit); i++) { \ 389 expected_frame = create_test_frame(1000 + i * DEFAULT_FRAME_MS, 0); \ 390 res = jb->impl->put(jb->jbobj, \ 392 1100 + i * DEFAULT_FRAME_MS); \ 393 if (res != AST_JB_IMPL_OK) { \ 394 ast_test_status_update(test, "Error: On frame %d, got %d back from put (expected %d)\n", \ 395 i, res, AST_JB_IMPL_OK); \ 396 return AST_TEST_FAIL; \ 400 for (i = (overflow_limit)+1; i < (overflow_limit) + 5; i++) { \ 401 expected_frame = create_test_frame(1000 + i * DEFAULT_FRAME_MS, 0); \ 402 res = jb->impl->put(jb->jbobj, \ 404 1100 + i * DEFAULT_FRAME_MS); \ 405 if (res != AST_JB_IMPL_DROP) { \ 406 expected_frame = NULL; \ 407 ast_test_status_update(test, "Error: On frame %d, got %d back from put (expected %d)\n", \ 408 i, res, AST_JB_IMPL_DROP); \ 409 return AST_TEST_FAIL; \ 411 ast_frfree(expected_frame); \ 412 expected_frame = NULL;\ 415 return AST_TEST_PASS; \ 426 #define test_put_out_of_order(type_name, literal_type_name, synch_limit) AST_TEST_DEFINE(TEST_NAME(type_name, put_out_of_order)) {\ 427 RAII_VAR(struct ast_jb *, jb, &default_jb, dispose_jitterbuffer); \ 428 const struct ast_jb_impl *impl; \ 429 struct ast_jb_conf conf; \ 430 RAII_VAR(struct ast_frame *, actual_frame, NULL, ast_frame_dtor); \ 431 RAII_VAR(struct ast_frame *, expected_frame, NULL, ast_frame_dtor); \ 438 info->name = STRINGIFY_TESTNAME(TEST_NAME(type_name, put_out_of_order)); \ 439 info->category = "/main/abstract_jb/"; \ 440 info->summary = "Test putting out of order frames onto a " literal_type_name " jitterbuffer"; \ 441 info->description = \ 442 "This tests putting multiple frames into a " literal_type_name " jitterbuffer " \ 443 "that arrive out of order. Every 3rd frame is put in out of order."; \ 444 return AST_TEST_NOT_RUN; \ 449 ast_test_status_update(test, "Executing " STRINGIFY_TESTNAME(TEST_NAME(type_name, put_out_of_order)) "...\n"); \ 450 OBTAIN_JITTERBUFFER_IMPL(impl, (type_name), (literal_type_name)); \ 451 MAKE_DEFAULT_CONFIG(&conf, impl); \ 452 conf.resync_threshold = (synch_limit); \ 453 jb->jbobj = impl->create(&conf); \ 456 expected_frame = create_test_frame(1000, 0); \ 457 jb->impl->put_first(jb->jbobj, expected_frame, 1100); \ 458 for (i = 1; i <= 10; i++) { \ 459 if (i % 3 == 1 && i != 10) { \ 460 expected_frame = create_test_frame(1000 + ((i + 1) * DEFAULT_FRAME_MS), 0); \ 461 } else if (i % 3 == 2) { \ 462 expected_frame = create_test_frame(1000 + ((i - 1) * DEFAULT_FRAME_MS), 0); \ 464 expected_frame = create_test_frame(1000 + i * DEFAULT_FRAME_MS, 0); \ 466 res = jb->impl->put(jb->jbobj, \ 468 1100 + i * DEFAULT_FRAME_MS); \ 469 if (res != AST_JB_IMPL_OK) { \ 470 ast_test_status_update(test, "Error: On frame %d, got %d back from put (expected %d)\n", \ 471 i, res, AST_JB_IMPL_OK); \ 472 return AST_TEST_FAIL; \ 476 for (i = 0; i <= 10; i++) { \ 477 expected_frame = create_test_frame(1000 + i * DEFAULT_FRAME_MS, 0); \ 478 next = jb->impl->next(jb->jbobj); \ 479 res = jb->impl->get(jb->jbobj, &actual_frame, next, DEFAULT_FRAME_MS); \ 480 if (res != AST_JB_IMPL_OK) { \ 481 ast_test_status_update(test, "Error: failed to retrieve frame at %ld\n", \ 483 return AST_TEST_FAIL; \ 485 VERIFY_FRAME(actual_frame, expected_frame); \ 486 ast_frfree(expected_frame); \ 487 expected_frame = NULL; \ 490 return AST_TEST_PASS; \ 498 test_put(AST_JB_ADAPTIVE, "adaptive")
#define DEFAULT_CONFIG_RESYNC_THRESHOLD
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Asterisk main include file. File version handling, generic pbx functions.
const struct ast_jb_impl * impl
Jitterbuffer implementation to be used.
#define AST_TEST_REGISTER(cb)
#define TEST_NAME(type_name, specifier)
#define test_put(type_name, literal_type_name)
#define test_put_overflow(type_name, literal_type_name, overflow_limit)
Common implementation-independent jitterbuffer stuff.
struct ast_frame_subclass subclass
Asterisk internal frame definitions.
void * jbobj
Jitterbuffer object, passed to the implementation.
static struct ast_frame * create_test_frame(long timestamp, int seqno)
#define test_put_out_of_order(type_name, literal_type_name, synch_limit)
static int load_module(void)
#define AST_TEST_UNREGISTER(cb)
General jitterbuffer state.
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
jb_empty_and_reset_impl empty_and_reset
static struct ast_jb default_jb
Data structure associated with a single frame of data.
static void dispose_jitterbuffer(struct ast_jb *jb)
enum ast_frame_type frametype
#define test_create_nominal(type_name, literal_type_name)
struct ast_format * format
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define test_put_first(type_name, literal_type_name)