mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-15 16:39:14 +00:00
[mod_opusfile] unit-tests: add timer to fix random failures due to the fact that the decoding callback is not installed immediatelly
This commit is contained in:
parent
97a0b0fbae
commit
0cf323c339
@ -171,6 +171,7 @@ FST_CORE_BEGIN(".")
|
|||||||
size_t write_len;
|
size_t write_len;
|
||||||
unsigned char decbuf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
|
unsigned char decbuf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
|
||||||
switch_stream_handle_t stream = { 0 };
|
switch_stream_handle_t stream = { 0 };
|
||||||
|
switch_timer_t timer;
|
||||||
#ifdef HAVE_OPUSFILE_ENCODE
|
#ifdef HAVE_OPUSFILE_ENCODE
|
||||||
switch_file_handle_t fh = { 0 };
|
switch_file_handle_t fh = { 0 };
|
||||||
unsigned char encbuf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
|
unsigned char encbuf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
|
||||||
@ -223,6 +224,8 @@ FST_CORE_BEGIN(".")
|
|||||||
|
|
||||||
switch_safe_free(stream.data);
|
switch_safe_free(stream.data);
|
||||||
|
|
||||||
|
switch_core_timer_init(&timer, "soft", 20, 960, fst_pool);
|
||||||
|
|
||||||
#ifdef HAVE_OPUSFILE_ENCODE
|
#ifdef HAVE_OPUSFILE_ENCODE
|
||||||
status = switch_core_codec_init(&write_codec,
|
status = switch_core_codec_init(&write_codec,
|
||||||
"OPUSSTREAM",
|
"OPUSSTREAM",
|
||||||
@ -252,6 +255,7 @@ FST_CORE_BEGIN(".")
|
|||||||
if (encoded_len) {
|
if (encoded_len) {
|
||||||
pages++;
|
pages++;
|
||||||
status = switch_core_codec_decode(&read_codec, NULL, &encbuf, encoded_len, filerate, &decbuf, &decoded_len, &rate, &flags);
|
status = switch_core_codec_decode(&read_codec, NULL, &encbuf, encoded_len, filerate, &decbuf, &decoded_len, &rate, &flags);
|
||||||
|
switch_core_timer_next(&timer);
|
||||||
fst_check(status == SWITCH_STATUS_SUCCESS);
|
fst_check(status == SWITCH_STATUS_SUCCESS);
|
||||||
write_len = decoded_len / sizeof(int16_t);
|
write_len = decoded_len / sizeof(int16_t);
|
||||||
if (write_len) switch_core_file_write(&fhw, &decbuf, &write_len);
|
if (write_len) switch_core_file_write(&fhw, &decbuf, &write_len);
|
||||||
@ -260,6 +264,7 @@ FST_CORE_BEGIN(".")
|
|||||||
|
|
||||||
// continue reading, encoded pages are buffered
|
// continue reading, encoded pages are buffered
|
||||||
while (switch_core_codec_decode(&read_codec, NULL, &encbuf, 0, filerate, &decbuf, &decoded_len, &rate, &flags) == SWITCH_STATUS_SUCCESS && decoded_len) {
|
while (switch_core_codec_decode(&read_codec, NULL, &encbuf, 0, filerate, &decbuf, &decoded_len, &rate, &flags) == SWITCH_STATUS_SUCCESS && decoded_len) {
|
||||||
|
switch_core_timer_next(&timer);
|
||||||
write_len = decoded_len / sizeof(int16_t);
|
write_len = decoded_len / sizeof(int16_t);
|
||||||
status = switch_core_file_write(&fhw, &decbuf, &write_len);
|
status = switch_core_file_write(&fhw, &decbuf, &write_len);
|
||||||
fst_check(status == SWITCH_STATUS_SUCCESS);
|
fst_check(status == SWITCH_STATUS_SUCCESS);
|
||||||
@ -288,6 +293,7 @@ FST_CORE_BEGIN(".")
|
|||||||
while (switch_file_read(fd, &buf, &flen) == SWITCH_STATUS_SUCCESS || flen != 0) {
|
while (switch_file_read(fd, &buf, &flen) == SWITCH_STATUS_SUCCESS || flen != 0) {
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
while (status == SWITCH_STATUS_SUCCESS) {
|
while (status == SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_core_timer_next(&timer);
|
||||||
status = switch_core_codec_decode(&read_codec, NULL, &buf, flen, filerate, &decbuf, &decoded_len, &rate, &flags);
|
status = switch_core_codec_decode(&read_codec, NULL, &buf, flen, filerate, &decbuf, &decoded_len, &rate, &flags);
|
||||||
fst_check(status == SWITCH_STATUS_SUCCESS);
|
fst_check(status == SWITCH_STATUS_SUCCESS);
|
||||||
write_len = decoded_len / sizeof(int16_t);
|
write_len = decoded_len / sizeof(int16_t);
|
||||||
@ -296,9 +302,9 @@ FST_CORE_BEGIN(".")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// continue reading, encoded pages are buffered
|
// continue reading, encoded pages are buffered
|
||||||
while (switch_core_codec_decode(&read_codec, NULL, &buf, 0, filerate, &decbuf, &decoded_len, &rate, &flags) == SWITCH_STATUS_SUCCESS && decoded_len) {
|
while (switch_core_codec_decode(&read_codec, NULL, &buf, 0, filerate, &decbuf, &decoded_len, &rate, &flags) == SWITCH_STATUS_SUCCESS && decoded_len) {
|
||||||
|
switch_core_timer_next(&timer);
|
||||||
write_len = decoded_len / sizeof(int16_t);
|
write_len = decoded_len / sizeof(int16_t);
|
||||||
status = switch_core_file_write(&fhw, &decbuf, &write_len);
|
status = switch_core_file_write(&fhw, &decbuf, &write_len);
|
||||||
fst_check(status == SWITCH_STATUS_SUCCESS);
|
fst_check(status == SWITCH_STATUS_SUCCESS);
|
||||||
@ -313,6 +319,8 @@ FST_CORE_BEGIN(".")
|
|||||||
status = test_detect_tone_in_file(tmp_filename, torate, 1000 /*Hz*/);
|
status = test_detect_tone_in_file(tmp_filename, torate, 1000 /*Hz*/);
|
||||||
fst_requires(status == SWITCH_STATUS_SUCCESS);
|
fst_requires(status == SWITCH_STATUS_SUCCESS);
|
||||||
|
|
||||||
|
switch_core_timer_destroy(&timer);
|
||||||
|
|
||||||
unlink(tmp_filename);
|
unlink(tmp_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user