Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moar functions for working with better timestamps

  • Loading branch information...
commit 4b94f9c92f5f14d951efd388c9888e84da0cbe3f 1 parent f148951
@plukevdh plukevdh authored
View
10 bytestream.c
@@ -7,7 +7,11 @@
#include "bytestream.h"
sc_bytestream_header create_header(uint8_t type) {
- sc_bytestream_header header = {(uint16_t)type, (time(NULL) * SC_TimeBase)};
+ return create_header_with_time(type, time(NULL) * SC_TimeBase);
+}
+
+sc_bytestream_header create_header_with_time(uint8_t type, sc_time timestamp) {
+ sc_bytestream_header header = {(uint16_t)type, timestamp};
return header;
}
@@ -47,8 +51,8 @@ sc_mouse_coords sc_bytestream_get_mouse_data(int fd) {
return parse_mouse_coords(packet);
}
-sc_bytestream_packet sc_bytestream_put_frame(int fd, sc_frame frame) {
- sc_bytestream_packet packet = {create_header(VIDEO), create_body(frame.framePtr, frame.size)};
+sc_bytestream_packet sc_bytestream_put_frame(int fd, sc_frame frame, sc_time timestamp) {
+ sc_bytestream_packet packet = {create_header_with_time(VIDEO, timestamp), create_body(frame.framePtr, frame.size)};
serialize_packet(fd, packet);
return packet;
View
10 bytestream.h
@@ -22,8 +22,8 @@
#define VIDEO 0x04
#define NO_DATA 0xFF
-typedef uint32_t sc_time;
-static char TPL_STRUCTURE[] = "S(vu)B";
+typedef uint64_t sc_time;
+static char TPL_STRUCTURE[] = "S(vU)B";
typedef struct {
uint16_t x, y;
@@ -54,7 +54,7 @@ typedef struct {
sc_bytestream_packet sc_bytestream_put_start(int fd);
sc_bytestream_packet sc_bytestream_put_stop(int fd);
sc_bytestream_packet sc_bytestream_put_mouse_data(int fd, sc_mouse_coords coords);
-sc_bytestream_packet sc_bytestream_put_frame(int fd, sc_frame frame);
+sc_bytestream_packet sc_bytestream_put_frame(int fd, sc_frame frame, sc_time timestamp);
sc_mouse_coords sc_bytestream_get_mouse_data(int fd);
sc_frame sc_bytestream_get_frame(int fd);
@@ -62,7 +62,9 @@ sc_frame sc_bytestream_get_frame(int fd);
sc_bytestream_packet sc_bytestream_get_event(int fd);
sc_bytestream_header sc_bytestream_get_event_header(int fd);
-sc_bytestream_header create_header(uint8_t event);
+sc_bytestream_header create_header(uint8_t type);
+sc_bytestream_header create_header_with_time(uint8_t type, sc_time timestamp);
+
void serialize_packet(int fd, sc_bytestream_packet packet);
sc_bytestream_packet deserialize_packet(int fd);
sc_frame parse_frame(sc_bytestream_packet packet);
View
BIN  bytestream_spec
Binary file not shown
View
6 bytestream_spec.cpp
@@ -60,13 +60,13 @@ TEST_F(BytestreamTest, EncodeMouseData) {
};
TEST_F(BytestreamTest, EncodeFrameData) {
- int frameData = 0x499602D2123456;
+ int frameData = 0x499602D2;
uint8_t *framePtr = (uint8_t *) &frameData;
int frameSize = sizeof(frameData);
sc_frame frame = {framePtr, frameSize};
- sc_bytestream_packet packet = sc_bytestream_put_frame(tmp, frame);
+ sc_bytestream_packet packet = sc_bytestream_put_frame(tmp, frame, time(NULL));
lseek(tmp, 0, 0); // rewind tempfile
sc_frame decode_frame = sc_bytestream_get_frame(tmp);
@@ -111,7 +111,7 @@ TEST_F(BytestreamTest, MultiplePackets) {
sc_mouse_coords coords = {440, 99};
sc_bytestream_put_start(tmp);
- sc_bytestream_put_frame(tmp, frame);
+ sc_bytestream_put_frame(tmp, frame, time(NULL));
sc_bytestream_put_mouse_data(tmp, coords);
sc_bytestream_put_stop(tmp);
Please sign in to comment.
Something went wrong with that request. Please try again.