AiCPlayer
Interface of aic vm - for rendering aspect, sensors, video records
grabber.h
Go to the documentation of this file.
1 
9 #ifndef __GRABBER_H_
10 #define __GRABBER_H_
11 
12 #include <libavformat/avformat.h> // for AVStream
13 #include <libavutil/frame.h> // for AVFrame
14 #include <libswscale/swscale.h> // for SWS_BICUBIC
15 #include <pthread.h> // for pthread_mutex_t, pthread_cond_t
16 #include <stdint.h> // for uint8_t
17 #include <X11/Xlib.h>
18 #include "buffer_sizes.h" // for BUF_SIZE
19 #include "socket.h" // for socket_t
20 
22 #define PORT_GRAB 32500
23 
25 #define STREAM_DURATION 60.0
26 
27 #define STREAM_FRAME_RATE 60
28 
29 #define STREAM_PIX_FMT AV_PIX_FMT_YUV420P
30 
31 #define SCALE_FLAGS SWS_BICUBIC
32 
34 #define CLIP(X) ((X) > 255 ? 255 : (X) < 0 ? 0 : X)
35 
36 // RGB -> YUV
37 #define RGB2Y(R, G, B) CLIP(((66 * (R) + 129 * (G) + 25 * (B) + 128) >> 8) + 16)
38 #define RGB2U(R, G, B) CLIP(((-38 * (R) -74 * (G) + 112 * (B) + 128) >> 8) + 128)
39 #define RGB2V(R, G, B) CLIP(((112 * (R) -94 * (G) -18 * (B) + 128) >> 8) + 128)
40 
42 
46 typedef struct read_args
47 {
48  pthread_mutex_t mtx;
49  pthread_cond_t cond;
50  uint8_t* buffer;
52  int len;
55 } s_read_args;
56 
60 typedef struct thread_args
61 {
62  pthread_mutex_t mtx;
65 
66 void grab_snapshot(char* snap_filename);
67 
69 typedef struct OutputStream
70 {
71  AVStream* st;
72 
73  /* pts of the next frame that will be generated */
74  int64_t next_pts;
76 
77  AVFrame* frame;
78  AVFrame* tmp_frame;
79 
80  float t, tincr, tincr2;
81 
82  struct SwsContext* sws_ctx;
83  struct SwrContext* swr_ctx;
84 } OutputStream;
85 
91 int ffmpeg_grabber(void* arg);
92 
93 unsigned char* xgrabber();
94 
99 void* grab_handler_sock();
100 
101 void* grab_handler_amqp(void* args);
102 
106 void grabber_set_path_results(char* results);
107 
111 void grabber_set_display(Display* display);
112 #endif
A wrapper around a single output AVStream.
Definition: grabber.h:69
uint8_t * buffer
Definition: grabber.h:50
void grabber_set_path_results(char *results)
Set the static path to the screenshots/movies dir.
Definition: grabber.c:73
float t
Definition: grabber.h:80
#define BUF_SIZE
Small, fixed-size buffers.
Definition: buffer_sizes.h:9
float tincr
Definition: grabber.h:80
Struct holding the state of a recording (filename/lock)
Definition: grabber.h:60
pthread_mutex_t mtx
Definition: grabber.h:48
AVFrame * frame
Definition: grabber.h:77
int len
Definition: grabber.h:52
int socket_t
Alias to differenciate between regular ints and socket fds.
Definition: socket.h:13
socket_t sock
Definition: grabber.h:51
void grab_snapshot(char *snap_filename)
Definition: grabber.c:584
int samples_count
Definition: grabber.h:75
Shared structure between recv thread and grabber thread.
Definition: grabber.h:46
void grabber_set_display(Display *display)
Set the static X display pointer.
Definition: grabber.c:68
struct read_args s_read_args
Shared structure between recv thread and grabber thread.
void * grab_handler_amqp(void *args)
Definition: grabber.c:804
struct OutputStream OutputStream
A wrapper around a single output AVStream.
pthread_cond_t cond
Definition: grabber.h:49
int flagRecording
Definition: grabber.h:54
float tincr2
Definition: grabber.h:80
struct SwrContext * swr_ctx
Definition: grabber.h:83
int ffmpeg_grabber(void *arg)
Function passed to a thread in order to detect format encoding - encode frame- and write in a file...
Definition: grabber.c:420
unsigned char * xgrabber()
Definition: grabber.c:510
char record_filename[BUF_SIZE]
Definition: grabber.h:63
struct thread_args s_thread_args
Struct holding the state of a recording (filename/lock)
AVFrame * tmp_frame
Definition: grabber.h:78
void * grab_handler_sock()
Start/Stop from socket connection via protobuf message.
Define common buffer sizes.
Define socket utilities to simplify networking.
int64_t next_pts
Definition: grabber.h:74
pthread_mutex_t mtx
Definition: grabber.h:62
struct SwsContext * sws_ctx
Definition: grabber.h:82
int flagSnapRec
Definition: grabber.h:53
AVStream * st
Definition: grabber.h:71