UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
ipc_frame.cpp
Go to the documentation of this file.
1#include <stdint.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <string.h>
5#include "ipc_frame.h"
6
7namespace{
8int32_t read_int(const char *buf){
9 int32_t result = 0;
10 auto char_ptr = reinterpret_cast<char *>(&result);
11
12 char_ptr[0] = buf[0];
13 char_ptr[1] = buf[1];
14 char_ptr[2] = buf[2];
15 char_ptr[3] = buf[3];
16
17 return result;
18}
19
20void write_int(char *dst, uint32_t val){
21 auto src = reinterpret_cast<char *>(&val);
22 dst[0] = src[0];
23 dst[1] = src[1];
24 dst[2] = src[2];
25 dst[3] = src[3];
26}
27
28} //anon namespace
29
30
31bool ipc_frame_parse_header(Ipc_frame_header *hdr, const char *buf){
32 hdr->width = read_int(buf + 0);
33 hdr->height = read_int(buf + 4);
34 hdr->data_len = read_int(buf + 8);
35 hdr->color_spec = static_cast<Ipc_frame_color_spec>(read_int(buf + 12));
36
37 return true;
38}
39
40void ipc_frame_write_header(const struct Ipc_frame_header *hdr, char *dst){
41 memset(dst, 0, IPC_FRAME_HEADER_LEN);
42 write_int(dst + 0, hdr->width);
43 write_int(dst + 4, hdr->height);
44 write_int(dst + 8, hdr->data_len);
45 write_int(dst + 12, hdr->color_spec);
46}
47
49 auto frame = static_cast<Ipc_frame *>(malloc(sizeof(Ipc_frame)));
50 frame->header.width = 0;
51 frame->header.height = 0;
52 frame->header.data_len = 0;
54
55 frame->data = nullptr;
56 frame->alloc_size = 0;
57
58 return frame;
59}
60
62 free(frame->data);
63 free(frame);
64}
65
66bool ipc_frame_reserve(Ipc_frame *frame, size_t size){
67 if(size <= frame->alloc_size)
68 return true;
69
70 auto newbuf = static_cast<char *>(realloc(frame->data, size));
71 if(!newbuf)
72 return false;
73 frame->data = newbuf;
74 frame->alloc_size = size;
75
76 return true;
77}
int void * val
struct video_frame * frame
bool ipc_frame_parse_header(Ipc_frame_header *hdr, const char *buf)
Definition ipc_frame.cpp:31
void ipc_frame_free(Ipc_frame *frame)
Definition ipc_frame.cpp:61
void ipc_frame_write_header(const struct Ipc_frame_header *hdr, char *dst)
Definition ipc_frame.cpp:40
bool ipc_frame_reserve(Ipc_frame *frame, size_t size)
Definition ipc_frame.cpp:66
Ipc_frame * ipc_frame_new()
Definition ipc_frame.cpp:48
#define IPC_FRAME_HEADER_LEN
Definition ipc_frame.h:7
Ipc_frame_color_spec
Definition ipc_frame.h:9
@ IPC_FRAME_COLOR_NONE
Definition ipc_frame.h:10
enum Ipc_frame_color_spec color_spec
Definition ipc_frame.h:20
codec_t color_spec
Definition types.h:306