summaryrefslogtreecommitdiff
path: root/encode.c
diff options
context:
space:
mode:
authorMikhail Burakov <mburakov@mailbox.org>2024-05-12 15:05:50 +0200
committerMikhail Burakov <mburakov@mailbox.org>2024-05-12 15:05:50 +0200
commitd511fae02fba6f6c8ea2896d5a6cefd8d3337ca3 (patch)
tree966f39c3fe988c96f75e5220cd10e4a8b6fdf0e5 /encode.c
parent918682faa29197fe3b0a544906638e02785a6b17 (diff)
Add generic proto writing method
Diffstat (limited to 'encode.c')
-rw-r--r--encode.c27
1 files changed, 2 insertions, 25 deletions
diff --git a/encode.c b/encode.c
index 9ee7ddd..5975efc 100644
--- a/encode.c
+++ b/encode.c
@@ -23,7 +23,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/uio.h>
#include <unistd.h>
#include <va/va.h>
#include <va/va_drm.h>
@@ -761,24 +760,6 @@ static void UpdatePicHeader(struct EncodeContext* encode_context, bool idr) {
}
}
-static bool DrainBuffers(int fd, struct iovec* iovec, int count) {
- for (;;) {
- ssize_t result = writev(fd, iovec, count);
- if (result < 0) {
- if (errno == EINTR) continue;
- LOG("Failed to write (%s)", strerror(errno));
- return false;
- }
- for (int i = 0; i < count; i++) {
- size_t delta = MIN((size_t)result, iovec[i].iov_len);
- iovec[i].iov_base = (uint8_t*)iovec[i].iov_base + delta;
- iovec[i].iov_len -= delta;
- result -= delta;
- }
- if (!result) return true;
- }
-}
-
bool EncodeContextEncodeFrame(struct EncodeContext* encode_context, int fd,
unsigned long long timestamp) {
bool result = false;
@@ -931,12 +912,8 @@ bool EncodeContextEncodeFrame(struct EncodeContext* encode_context, int fd,
.flags = idr ? PROTO_FLAG_KEYFRAME : 0,
.latency = (uint16_t)(MicrosNow() - timestamp),
};
- struct iovec iovec[] = {
- {.iov_base = &proto, .iov_len = sizeof(proto)},
- {.iov_base = segment->buf, .iov_len = segment->size},
- };
- if (!DrainBuffers(fd, iovec, LENGTH(iovec))) {
- LOG("Failed to drain encoded frame");
+ if (!WriteProto(fd, &proto, segment->buf)) {
+ LOG("Failed to write encoded frame");
goto rollback_segment;
}