Commit 66423e00 authored by Simon Morlat's avatar Simon Morlat

enhance jitter buffer tests to simulate a big timestamp offset (in order to...

enhance jitter buffer tests to simulate a big timestamp offset (in order to check computation accuracy)
parent 07d69113
......@@ -49,6 +49,7 @@ typedef enum _MSPCAPFilePlayerTimeRef {
#define MS_PCAP_FILE_PLAYER_SET_LAYER MS_FILTER_METHOD(MS_PCAP_FILE_PLAYER_ID,0,MSPCAPFilePlayerLayer)
#define MS_PCAP_FILE_PLAYER_SET_TIMEREF MS_FILTER_METHOD(MS_PCAP_FILE_PLAYER_ID,1,MSPCAPFilePlayerTimeRef)
#define MS_PCAP_FILE_PLAYER_SET_TO_PORT MS_FILTER_METHOD(MS_PCAP_FILE_PLAYER_ID,2,unsigned)
#define MS_PCAP_FILE_PLAYER_SET_TS_OFFSET MS_FILTER_METHOD(MS_PCAP_FILE_PLAYER_ID,3,uint32_t)
#endif
......@@ -60,6 +60,7 @@ struct _PlayerData{
struct timeval pcap_initial_timeval;
MSPCAPFilePlayerTimeRef pcap_timeref;
MSPCAPFilePlayerLayer pcap_layer;
uint32_t ts_offset;
};
typedef struct _PlayerData PlayerData;
......@@ -239,13 +240,9 @@ static void player_process(MSFilter *f){
if (d->pcap_layer == MSPCAPFilePlayerLayerRTP) {
int headers_size = link_layer_header - rtp_header;
int bytes_pcap = d->pcap_hdr->caplen + headers_size;
/*uncommented to add some offset to all packets*/
#if 0
if (pcap_seq>3000){
ts += 1e6;
*((uint32_t*)(rtp_header + 4)) = htonl(ts);
}
#endif
*((uint32_t*)(rtp_header + 4)) = htonl(ts + d->ts_offset);
om = allocb(bytes_pcap, 0);
memcpy(om->b_wptr, rtp_header, bytes_pcap);
om->b_wptr += bytes_pcap;
......@@ -315,12 +312,19 @@ static int player_set_to_port(MSFilter *f, void *arg){
return 0;
}
static int player_set_ts_offset(MSFilter *f, void *arg){
PlayerData *d=(PlayerData*)f->data;
d->ts_offset = *(uint32_t*)arg;
return 0;
}
static MSFilterMethod player_methods[]={
{ MS_FILTER_GET_SAMPLE_RATE, player_get_sr},
{ MS_FILTER_SET_SAMPLE_RATE, player_set_sr},
{ MS_PCAP_FILE_PLAYER_SET_LAYER, player_set_layer},
{ MS_PCAP_FILE_PLAYER_SET_TIMEREF, player_set_timeref},
{ MS_PCAP_FILE_PLAYER_SET_TO_PORT, player_set_to_port},
{ MS_PCAP_FILE_PLAYER_SET_TS_OFFSET, player_set_ts_offset},
/* this file player implements the MSFilterPlayerInterface*/
{ MS_PLAYER_OPEN , player_open },
......
......@@ -48,7 +48,7 @@ static void reader_notify_cb(void *user_data, MSFilter *f, unsigned int event, v
}
MSPCAPSender* ms_pcap_sendto(MSFactory *factory, const char* filepath, unsigned to_port, const MSIPPort *dest,
int sample_rate, MSPCAPFileEnded cb, void* user_data) {
int sample_rate, uint32_t ts_offset, MSPCAPFileEnded cb, void* user_data) {
MSTickerParams params;
MSConnectionHelper h;
MSPCAPSender * s;
......@@ -82,6 +82,13 @@ MSPCAPSender* ms_pcap_sendto(MSFactory *factory, const char* filepath, unsigned
ms_filter_destroy(udp_sender);
return NULL;
}
if (ms_filter_call_method(file_player, MS_PCAP_FILE_PLAYER_SET_TS_OFFSET, (void*)&ts_offset) != 0) {
ms_error("Failed to set ts_offset, aborting");
ms_filter_destroy(file_player);
ms_filter_destroy(udp_sender);
return NULL;
}
s = ms_new0(MSPCAPSender, 1);
s->udp_send = udp_sender;
......
......@@ -57,7 +57,7 @@ typedef struct _MSPCAPSender {
* @return the created PCAP sender or NULL if parameters are invalid
*/
MSPCAPSender* ms_pcap_sendto(MSFactory *factory, const char* filepath, unsigned from_port, const MSIPPort* dest,
int sample_rate, MSPCAPFileEnded cb, void* user_data);
int sample_rate, uint32_t ts_offset, MSPCAPFileEnded cb, void* user_data);
#endif
......@@ -133,6 +133,7 @@ RtpSession * ms_create_duplex_rtp_session(const char* local_ip, int loc_rtp_port
rtp_session_set_ssrc_changed_threshold(rtpr, 0);
rtp_session_set_rtcp_report_interval(rtpr, 2500); /* At the beginning of the session send more reports. */
rtp_session_set_multicast_loopback(rtpr,TRUE); /*very useful, specially for testing purposes*/
rtp_session_set_send_ts_offset(rtpr, (uint32_t)bctbx_random());
disable_checksums(rtp_session_get_rtp_socket(rtpr));
return rtpr;
}
......
......@@ -176,6 +176,17 @@ static void process_queue(OrtpEvQueue *evq) {
}
}
typedef struct _PcapTesterParams{
const char *file;
OrtpJitterBufferAlgorithm algo;
int congestion_count_expected;
int audio_clock_rate;
int audio_payload;
int video_clock_rate;
int video_payload;
uint32_t ts_offset;
}PcapTesterParams;
bool_t has_finished = FALSE;
rtp_stats_t final_audio_rtp_stats, final_video_rtp_stats;
......@@ -186,9 +197,9 @@ static OrtpEvQueue * setup_event_queue(MediaStream *ms){
return evq;
}
static void pcap_tester_streams_start(const char* file, OrtpJitterBufferAlgorithm algo, int congestion_count_expected,
int audio_file_port, int audio_to_port, int audio_clock_rate, int audio_payload,
int video_file_port, int video_to_port, int video_clock_rate, int video_payload) {
static void pcap_tester_streams_start(const PcapTesterParams *params,
int audio_file_port, int audio_to_port,
int video_file_port, int video_to_port) {
bool_t use_audio = (audio_file_port != -1);
bool_t use_video = (video_file_port != -1);
MSIPPort audio_dest = { RECEIVER_IP, audio_to_port };
......@@ -197,9 +208,10 @@ static void pcap_tester_streams_start(const char* file, OrtpJitterBufferAlgorith
has_finished = FALSE;
if (use_audio) {
receiver = audio_stream_new (_factory, audio_to_port, 0, FALSE);
test_setup(audio_payload, algo);
test_setup(params->audio_payload, params->algo);
rtp_session_enable_avpf_feature(receiver->ms.sessions.rtp_session, ORTP_AVPF_FEATURE_TMMBR, TRUE);
receiver_q = setup_event_queue(&receiver->ms);
}
if (use_video) {
......@@ -207,6 +219,7 @@ static void pcap_tester_streams_start(const char* file, OrtpJitterBufferAlgorith
receiverv = video_stream_new(_factory, video_to_port, 0, FALSE);
video_stream_set_direction(receiverv, MediaStreamRecvOnly);
rtp_session_enable_avpf_feature(receiverv->ms.sessions.rtp_session, ORTP_AVPF_FEATURE_TMMBR, TRUE);
BC_ASSERT_EQUAL(video_stream_start(receiverv
, profile
......@@ -214,11 +227,11 @@ static void pcap_tester_streams_start(const char* file, OrtpJitterBufferAlgorith
, 0
, 0
, 0
, video_payload
, params->video_payload
, 50
, mediastreamer2_tester_get_mire(_factory)),0, int, "%i");
rtp_session_get_jitter_buffer_params(receiverv->ms.sessions.rtp_session, &video_params);
video_params.buffer_algorithm = algo;
video_params.buffer_algorithm = params->algo;
video_params.refresh_ms = 5000;
video_params.max_size = 1000;
video_params.min_size = 20;
......@@ -227,8 +240,8 @@ static void pcap_tester_streams_start(const char* file, OrtpJitterBufferAlgorith
receiverv_q = setup_event_queue(&receiver->ms);
}
if (use_audio) has_finished |= (ms_pcap_sendto(_factory, file, audio_file_port, &audio_dest, audio_clock_rate, end_of_pcap, &has_finished) == NULL);
if (use_video) has_finished |= (ms_pcap_sendto(_factory, file, video_file_port, &video_dest, video_clock_rate, end_of_pcap, &has_finished) == NULL);
if (use_audio) has_finished |= (ms_pcap_sendto(_factory, params->file, audio_file_port, &audio_dest, params->audio_clock_rate, params->ts_offset, end_of_pcap, &has_finished) == NULL);
if (use_video) has_finished |= (ms_pcap_sendto(_factory, params->file, video_file_port, &video_dest, params->video_clock_rate, params->ts_offset, end_of_pcap, &has_finished) == NULL);
BC_ASSERT_FALSE(has_finished);
}
......@@ -270,22 +283,37 @@ void pcap_tester_stop(const char * file, int audio_clock_rate, int congestion_co
}
}
void pcap_tester_audio(const char* file, OrtpJitterBufferAlgorithm algo, int congestion_count_expected
, int clock_rate, int payload) {
pcap_tester_streams_start(file, algo, congestion_count_expected,
0, RECEIVER_RTP_PORT, clock_rate, payload,
-1, -1, 0, 0);
void pcap_tester_audio_with_params(const PcapTesterParams *params){
pcap_tester_streams_start(params,
0, RECEIVER_RTP_PORT,
-1, -1);
pcap_tester_iterate_until();
pcap_tester_stop(file, clock_rate, congestion_count_expected);
pcap_tester_stop(params->file, params->audio_clock_rate, params->congestion_count_expected);
}
void pcap_tester_audio(const char* file, OrtpJitterBufferAlgorithm algo, int congestion_count_expected
, int clock_rate, int payload) {
PcapTesterParams params = {0};
params.file = file;
params.algo = algo;
params.congestion_count_expected = congestion_count_expected;
params.audio_clock_rate = clock_rate;
params.audio_payload = payload;
pcap_tester_audio_with_params(&params);
}
void pcap_tester_video(const char* file
, OrtpJitterBufferAlgorithm algo, int congestion_count_expected
, int clock_rate, int payload) {
pcap_tester_streams_start(file, algo, congestion_count_expected,
-1, -1, 0, 0,
0, RECEIVER_RTP_PORT, clock_rate, payload);
PcapTesterParams params = {0};
params.file = file;
params.algo = algo;
params.congestion_count_expected = congestion_count_expected;
params.video_clock_rate = clock_rate;
params.video_payload = payload;
pcap_tester_streams_start(&params,-1, -1,
0, RECEIVER_RTP_PORT);
pcap_tester_iterate_until();
pcap_tester_stop(file, 0, congestion_count_expected);
}
......@@ -323,6 +351,21 @@ static void burstly_network_rls(void) {
BC_ASSERT_EQUAL((int)final_audio_rtp_stats.packet_recv, 7104, int, "%i");
}
static void burstly_network_rls_with_ts_offset(void) {
PcapTesterParams params = {0};
params.file = "./scenarios/rtp-534late-24loss-7000total.pcapng";
params.algo = OrtpJitterBufferRecursiveLeastSquare;
params.audio_clock_rate = payload_type_opus.clock_rate;
params.audio_payload = OPUS_PAYLOAD_TYPE;
params.ts_offset = 0x7ffffffc;
pcap_tester_audio_with_params(&params);
BC_ASSERT_GREATER((int)final_audio_rtp_stats.outoftime, 200, int, "%i");
BC_ASSERT_LOWER((int)final_audio_rtp_stats.outoftime, 240, int, "%i");
BC_ASSERT_EQUAL((int)final_audio_rtp_stats.discarded, 0, int, "%i");
BC_ASSERT_EQUAL((int)final_audio_rtp_stats.packet_recv, 7104, int, "%i");
}
static void chaotic_start_basic(void) {
pcap_tester_audio("./scenarios/opus-poor-quality.pcapng", OrtpJitterBufferBasic, 0
, payload_type_opus.clock_rate, OPUS_PAYLOAD_TYPE);
......@@ -497,6 +540,7 @@ static test_t tests[] = {
{ "Ideal network rls", ideal_network_rls },
{ "Burstly network basic", burstly_network_basic },
{ "Burstly network rls", burstly_network_rls },
{ "Burstly network rls with offset", burstly_network_rls_with_ts_offset },
{ "Chaotic start basic", chaotic_start_basic },
{ "Chaotic start rls", chaotic_start_rls },
#ifdef ENABLE_CONGESTION_TESTS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment