summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Burakov <mburakov@mailbox.org>2023-10-14 15:31:14 +0200
committerMikhail Burakov <mburakov@mailbox.org>2023-10-14 15:31:14 +0200
commit0e3c61abed24e2fec2148b22fe204e28074f1e90 (patch)
tree8c750d88499d21257fd93ffde557640482439417
parent96840adcdc592d82a55f62c947786f0117fbcd67 (diff)
Track video frame encoding latencyv4
-rw-r--r--encode.c6
-rw-r--r--encode.h3
-rw-r--r--main.c6
-rw-r--r--makefile3
4 files changed, 12 insertions, 6 deletions
diff --git a/encode.c b/encode.c
index 1c45e63..9ee7ddd 100644
--- a/encode.c
+++ b/encode.c
@@ -33,6 +33,7 @@
#include "gpu.h"
#include "hevc.h"
#include "proto.h"
+#include "toolbox/perf.h"
#include "toolbox/utils.h"
struct EncodeContext {
@@ -778,7 +779,8 @@ static bool DrainBuffers(int fd, struct iovec* iovec, int count) {
}
}
-bool EncodeContextEncodeFrame(struct EncodeContext* encode_context, int fd) {
+bool EncodeContextEncodeFrame(struct EncodeContext* encode_context, int fd,
+ unsigned long long timestamp) {
bool result = false;
VABufferID buffers[8];
VABufferID* buffer_ptr = buffers;
@@ -927,7 +929,7 @@ bool EncodeContextEncodeFrame(struct EncodeContext* encode_context, int fd) {
.size = segment->size,
.type = PROTO_TYPE_VIDEO,
.flags = idr ? PROTO_FLAG_KEYFRAME : 0,
- .latency = 0,
+ .latency = (uint16_t)(MicrosNow() - timestamp),
};
struct iovec iovec[] = {
{.iov_base = &proto, .iov_len = sizeof(proto)},
diff --git a/encode.h b/encode.h
index fe76012..1612fc2 100644
--- a/encode.h
+++ b/encode.h
@@ -33,7 +33,8 @@ struct EncodeContext* EncodeContextCreate(struct GpuContext* gpu_context,
enum YuvRange range);
const struct GpuFrame* EncodeContextGetFrame(
struct EncodeContext* encode_context);
-bool EncodeContextEncodeFrame(struct EncodeContext* encode_context, int fd);
+bool EncodeContextEncodeFrame(struct EncodeContext* encode_context, int fd,
+ unsigned long long timestamp);
void EncodeContextDestroy(struct EncodeContext* encode_context);
#endif // STREAMER_ENCODE_H_
diff --git a/main.c b/main.c
index aa5a493..bc737fc 100644
--- a/main.c
+++ b/main.c
@@ -32,6 +32,7 @@
#include "gpu.h"
#include "input.h"
#include "toolbox/io_muxer.h"
+#include "toolbox/perf.h"
#include "toolbox/utils.h"
// TODO(mburakov): Currently zwp_linux_dmabuf_v1 has no way to provide
@@ -135,6 +136,7 @@ static void OnTimerExpire(void* user) {
return;
}
+ unsigned long long timestamp = MicrosNow();
const struct GpuFrame* captured_frame =
CaptureContextGetFrame(contexts->capture_context);
if (!captured_frame) {
@@ -163,8 +165,8 @@ static void OnTimerExpire(void* user) {
LOG("Failed to convert frame");
goto drop_client;
}
- if (!EncodeContextEncodeFrame(contexts->encode_context,
- contexts->client_fd)) {
+ if (!EncodeContextEncodeFrame(contexts->encode_context, contexts->client_fd,
+ timestamp)) {
LOG("Failed to encode frame");
goto drop_client;
}
diff --git a/makefile b/makefile
index ea20b3a..8a920d2 100644
--- a/makefile
+++ b/makefile
@@ -4,7 +4,8 @@ obj:=$(src:.c=.o)
obj+=\
toolbox/buffer.o \
- toolbox/io_muxer.o
+ toolbox/io_muxer.o \
+ toolbox/perf.o
libs:=\
egl \