Fix FFmpeg latency test code

This commit is contained in:
Aaro Altonen 2020-05-15 08:01:07 +03:00
parent a2d68b6d15
commit e86205a308
3 changed files with 29 additions and 26 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@ benchmarks/*/results
benchmarks/*/*data benchmarks/*/*data
benchmarks/*/receiver benchmarks/*/receiver
benchmarks/*/sender benchmarks/*/sender
benchmarks/*/latency
*.prof *.prof
tags tags
*a.out *a.out

View File

@ -20,6 +20,10 @@ ffmpeg_receiver:
$(CXX) $(CXXFLAGS) -o ffmpeg/receiver ffmpeg/receiver.cc util/util.cc -lkvazaar `pkg-config --libs libavformat` \ $(CXX) $(CXXFLAGS) -o ffmpeg/receiver ffmpeg/receiver.cc util/util.cc -lkvazaar `pkg-config --libs libavformat` \
-Wno-unused -Wno-deprecated-declarations -Wno-unused-result -Wno-unused -Wno-deprecated-declarations -Wno-unused-result
ffmpeg_latency:
$(CXX) $(CXXFLAGS) -o ffmpeg/latency ffmpeg/latency.cc util/util.cc -lkvazaar `pkg-config --libs libavformat` \
-Wno-unused -Wno-deprecated-declarations -Wno-unused-result
clean: clean:
rm -f uvgrtp/receiver uvgrtp/sender ffmpeg/sender ffmpeg/receiver rm -f uvgrtp/receiver uvgrtp/sender ffmpeg/sender ffmpeg/receiver

View File

@ -13,6 +13,7 @@ extern "C" {
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include <atomic>
extern void *get_mem(int argc, char **argv, size_t& len); extern void *get_mem(int argc, char **argv, size_t& len);
@ -21,9 +22,8 @@ extern void *get_mem(int argc, char **argv, size_t& len);
#define FPS 120 #define FPS 120
#define SLEEP 8 #define SLEEP 8
#define CNT_VAL 1 std::chrono::high_resolution_clock::time_point fs, fe;
std::atomic<bool> received(false);
std::chrono::high_resolution_clock::time_point latency_start, latency_end;
void receiver() void receiver()
{ {
@ -55,7 +55,7 @@ void receiver()
* *
* A higher value will enable detecting more information in case it is dispersed into the stream, * A higher value will enable detecting more information in case it is dispersed into the stream,
* but will increase latency. Must be an integer not lesser than 32. It is 5000000 by default. */ * but will increase latency. Must be an integer not lesser than 32. It is 5000000 by default. */
snprintf(buf, sizeof(buf), "%d", 256); snprintf(buf, sizeof(buf), "%d", 32);
av_dict_set(&d, "probesize", buf, 32); av_dict_set(&d, "probesize", buf, 32);
/* Set number of frames used to probe fps. */ /* Set number of frames used to probe fps. */
@ -85,13 +85,8 @@ void receiver()
av_read_play(format_ctx); //play RTSP av_read_play(format_ctx); //play RTSP
while (av_read_frame(format_ctx, &packet) >= 0) { while (av_read_frame(format_ctx, &packet) >= 0) {
if (++cnt == CNT_VAL) { fe = std::chrono::high_resolution_clock::now();
latency_end = std::chrono::high_resolution_clock::now(); received = true;
uint64_t diff = std::chrono::duration_cast<std::chrono::microseconds>(latency_end - latency_start).count();
fprintf(stdout, "%u + ", diff);
exit(EXIT_SUCCESS);
}
} }
} }
@ -187,31 +182,34 @@ int main() {
(void)avformat_write_header(avfctx, &d); (void)avformat_write_header(avfctx, &d);
size_t len = 0; size_t len = 0;
void *mem = get_mem(NULL, NULL, len); void *mem = get_mem(0, NULL, len);
uint64_t chunk_size = 0, diff = 0, counter = 0; uint64_t chunk_size = 0;
uint64_t diff = 0;
uint64_t counter = 0;
uint64_t total = 0;
std::chrono::high_resolution_clock::time_point start, fpt_start, fpt_end, end; std::chrono::high_resolution_clock::time_point start, fpt_start, fpt_end, end;
start = std::chrono::high_resolution_clock::now(); start = std::chrono::high_resolution_clock::now();
for (size_t rounds = 0; rounds < 1; ++rounds) { for (size_t i = 0; i < len; ) {
for (size_t i = 0; i < len; ) { memcpy(&chunk_size, (uint8_t *)mem + i, sizeof(uint64_t));
memcpy(&chunk_size, (uint8_t *)mem + i, sizeof(uint64_t)); i += sizeof(uint64_t);
i += sizeof(uint64_t); fs = std::chrono::high_resolution_clock::now();
if (++counter == CNT_VAL) { av_init_packet(&pkt);
latency_start = std::chrono::high_resolution_clock::now(); pkt.data = (uint8_t *)mem + i;
} pkt.size = chunk_size;
av_init_packet(&pkt); av_write_frame(avfctx, &pkt);
pkt.data = (uint8_t *)mem + i;
pkt.size = chunk_size;
av_write_frame(avfctx, &pkt); while (!received.load())
;
i += chunk_size; received = false;
} total += std::chrono::duration_cast<std::chrono::microseconds>(fe - fs).count();
i += chunk_size;
} }
while (true) { while (true) {