Skip to content

Display and control your Android device

Move buffer reader functions to buffer_util.h

Romain Vimontebe998cf784a
diff --git a/app/src/buffer_util.h b/app/src/buffer_util.h
index 8b2ee279..cfb3fa12 100644
--- a/app/src/buffer_util.h
+++ b/app/src/buffer_util.h
@@ -15,4 +15,14 @@ static inline void buffer_write32be(Uint8 *buf, Uint32 value) {
buf[3] = value;
}
+static inline Uint32 buffer_read32be(Uint8 *buf) {
+ return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
+}
+
+static inline Uint64 buffer_read64be(Uint8 *buf) {
+ Uint32 msb = buffer_read32be(buf);
+ Uint32 lsb = buffer_read32be(&buf[4]);
+ return ((Uint64) msb << 32) | lsb;
+}
+
#endif
diff --git a/app/src/decoder.c b/app/src/decoder.c
index d03ec3e6..309ddce2 100644
--- a/app/src/decoder.c
+++ b/app/src/decoder.c
@@ -8,6 +8,7 @@
#include <unistd.h>
#include "config.h"
+#include "buffer_util.h"
#include "events.h"
#include "frames.h"
#include "lock_util.h"
@@ -16,19 +17,6 @@
#define BUFSIZE 0x10000
-static inline uint64_t from_be(uint8_t *b, int size)
-{
- uint64_t x = 0;
- int i;
-
- for (i = 0; i < size; i += 1) {
- x <<= 8;
- x |= b[i];
- }
-
- return x;
-}
-
#define HEADER_SIZE 12
static int read_packet(void *opaque, uint8_t *buf, int buf_size) {
@@ -48,8 +36,8 @@ static int read_packet(void *opaque, uint8_t *buf, int buf_size) {
return ret;
// read the PTS for the next frame
- decoder->next_pts = from_be(header, 8);
- remaining = from_be(header + 8, 4);
+ decoder->next_pts = buffer_read64be(header);
+ remaining = buffer_read32be(&header[8]);
}
if (buf_size > remaining)