diff --git a/sdk/samples/recver_app.c b/sdk/samples/recver_app.c index 00f6348b..b1d6216f 100644 --- a/sdk/samples/recver_app.c +++ b/sdk/samples/recver_app.c @@ -326,8 +326,10 @@ int main(int argc, char** argv) // uint32_t frm_size = width * height * 3 / 2; //TODO:assume it's NV12 uint32_t frm_size = getFrameSize(PIX_FMT_YUV422P_10BIT_LE, width, height, false); - const uint32_t fps_interval = 30; + const uint32_t stat_interval = 10; double fps = 0.0; + double throughput_MB = 0; + double stat_period_s = 0; void *ptr = NULL; int timeout = -1; bool first_frame = true; @@ -382,22 +384,9 @@ int main(int argc, char** argv) ptr += sizeof(frame_count); ts_send = *(struct timespec *)ptr; - if (frame_count % fps_interval == 0) { - /* calculate FPS */ - clock_gettime(CLOCK_REALTIME, &ts_end); - - fps = 1e9 * (ts_end.tv_sec - ts_begin.tv_sec); - fps += (ts_end.tv_nsec - ts_begin.tv_nsec); - fps /= 1e9; - fps = (double)fps_interval / fps; - - clock_gettime(CLOCK_REALTIME, &ts_begin); - } - latency = 1000.0 * (ts_recv.tv_sec - ts_send.tv_sec); latency += (ts_recv.tv_nsec - ts_send.tv_nsec) / 1000000.0; - printf("RX frames: [%u], latency: %0.1f ms, FPS: %0.3f\n", frame_count, latency, fps); } } else { //TODO: rtsp receiver side test code if (dump_fp) { @@ -406,12 +395,27 @@ int main(int argc, char** argv) printf("RX package number:%d seq_num: %d, timestamp: %u, RX H264 NALU: %ld\n", frame_count, buf->metadata.seq_num, buf->metadata.timestamp, buf->len); } + if (frame_count % stat_interval == 0) { + /* calculate FPS */ + clock_gettime(CLOCK_REALTIME, &ts_end); + + stat_period_s = (ts_end.tv_sec - ts_begin.tv_sec); + stat_period_s += (ts_end.tv_nsec - ts_begin.tv_nsec) / 1e9; + fps = stat_interval / stat_period_s; + throughput_MB = fps * frm_size / 1000000; + + clock_gettime(CLOCK_REALTIME, &ts_begin); + } + printf("RX frames: [%u], latency: %0.1f ms, FPS: %0.3f\n", frame_count, latency, fps); + printf("Throughput: %.2lf MB/s, %.2lf Gb/s \n", throughput_MB, throughput_MB * 8 / 1000); + frame_count++; /* enqueue buffer */ if (mcm_enqueue_buffer(dp_ctx, buf) != 0) { break; } + printf("\n"); } /* Clean up */ diff --git a/sdk/samples/sender_app.c b/sdk/samples/sender_app.c index cc5a6024..3023d6d5 100644 --- a/sdk/samples/sender_app.c +++ b/sdk/samples/sender_app.c @@ -364,8 +364,10 @@ int main(int argc, char** argv) FILE* input_fp = NULL; uint32_t frame_count = 0; - const uint32_t fps_interval = 30; + const uint32_t stat_interval = 10; double fps = 0.0; + double throughput_MB = 0; + double stat_period_s = 0; struct timespec ts_begin = {}, ts_end = {}; struct timespec ts_frame_begin = {}, ts_frame_end = {}; @@ -422,19 +424,20 @@ int main(int argc, char** argv) break; } - if (frame_count % fps_interval == 0) { + if (frame_count % stat_interval == 0) { /* calculate FPS */ clock_gettime(CLOCK_REALTIME, &ts_end); - fps = 1e9 * (ts_end.tv_sec - ts_begin.tv_sec); - fps += (ts_end.tv_nsec - ts_begin.tv_nsec); - fps /= 1e9; - fps = (double)fps_interval / fps; + stat_period_s = (ts_end.tv_sec - ts_begin.tv_sec); + stat_period_s += (ts_end.tv_nsec - ts_begin.tv_nsec) / 1e9; + fps = stat_interval / stat_period_s; + throughput_MB = fps * frame_size / 1000000; clock_gettime(CLOCK_REALTIME, &ts_begin); } printf("TX frames: [%d], FPS: %0.2f [%0.2f]\n", frame_count, fps, vid_fps); + printf("Throughput: %.2lf MB/s, %.2lf Gb/s \n", throughput_MB, throughput_MB * 8 / 1000); frame_count++; @@ -450,6 +453,7 @@ int main(int argc, char** argv) printf("pacing: %d\n", pacing); printf("spend: %d\n", spend); + printf("\n"); } sleep(2);