Giter Site home page Giter Site logo

bytestream's Introduction

What

A simple bytestream lib for interaction between our screenshare capture component and x264 encoder/rtmp streamer for licensing purposes.

API

Packet

Each packets consists of a header (struct), a body (tpl_bin) and a body size (int). The body is a tpl binary stream structure, which gets cast back into whatever form it originally took (usually mouse data or frame data).

Header

A header consists of an event type and a timestamp. The timestamp is simply the time the packet/header is created (using time()).

There are four types of events:

START, STOP. MOUSE, FRAME

Start/Stop take no params, they simply create a packet with a header

Data Types

  • sc_mouse_coords : contains a pair of uint16_t, x and y.

  • sc_frame_rect : simple c rect structure, x, y (origin) and width, height. all members are uint16_t.

  • sc_bytestream_header : type and timestamp (as described above)

  • sc_frame : byte pointer framePtr to addressable data, size int, the size of the data.

  • sc_bytestream_packet : header (the above) tpl_bin which holds the body of data (usually a sc_frame or sc_mouse_coords)

Functions

The following methods handle writing and reading the packets across a given file descriptor (fd). This could be a socket, a file handle, or other i/o stream. Each method takes the fd as its first parameter. start/stop do not take any other parameters. The mouse data writer takes an sc_mouse_coords struct and the frame writer takes an sc_frame. Each "put" method also returns the packet it created.

The get methods are really only used in the case of a mouse or frame event. They return their respective data structures. Start/stop will return a tpl_bin but the address (addr) is a NULL pointer and has a size (sz) of zero.

sc_bytestream_get_event/_header return the raw header or packet information.

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_mouse_coords sc_bytestream_get_mouse_data(int fd)
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)

The following methods are also available, but are not usually needed outside of the library, as they are all used to build or decode the packets.

sc_bytestream_header create_header(uint8_t event);
sc_bytestream_header create_header(uint8_t event, sc_time timestamp)
void serialize_packet(int fd, sc_bytestream_packet packet);
sc_bytestream_packet deserialize_packet(int fd);

Important

The create_header method gets the current unix time and converts it to milliseconds (SC_TimeBase) automatically. create_header_with_time does not convert the timestamp for you, it expects that you conver the time you are passing to it to milliseconds before you send it. This is so that if the date/time library you are using is already in milliseconds, we will not lose that precision.

Also Note

sc_bytestream_put_frame uses create_header_with_time. so please convert your timestamps properly before using _put_frame.

Testing

First compile the tpl.c file with gcc

gcc -c vendor/tpl.c

then you can simply run make to compile the test and run the tests using the script it builds.

./bytesream_spec

Dependencies

This library is tested via googletest (http://code.google.com/p/googletest/) and depends on the tpl serialization library (http://tpl.sourceforge.net/userguide.html).

bytestream's People

Contributors

plukevdh avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.