1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
#ifndef _TYPES_H_
#define _TYPES_H_
#include <pthread.h>
#include <sys/types.h>
#include <glib.h>
#include <libavutil/frame.h>
#include <libavformat/avformat.h>
#include <libavutil/channel_layout.h>
#include <libavutil/samplefmt.h>
#include <libavutil/audio_fifo.h>
#include <openssl/ssl.h>
#include "str.h"
#include "codeclib.h"
#include "custom_poller.h"
#include "socket.h"
#include "containers.h"
#include "obj.h"
struct iphdr;
struct ip6_hdr;
struct udphdr;
struct rtp_header;
struct streambuf;
typedef struct handler_s handler_t;
typedef struct metafile_s metafile_t;
typedef struct output_s output_t;
typedef struct mix_s mix_t;
typedef struct decode_s decode_t;
typedef struct packet_s packet_t;
typedef struct stream_s stream_t;
typedef struct ssrc_s ssrc_t;
typedef struct sink_s sink_t;
typedef struct tls_fwd_s tls_fwd_t;
typedef struct content_s content_t;
typedef struct notif_action_s notif_action_t;
typedef struct notif_req_s notif_req_t;
typedef void handler_func(handler_t *);
struct handler_s {
handler_func *func;
void *ptr;
};
struct sink_s {
bool (*add)(sink_t *, AVFrame *);
bool (*config)(sink_t *, const format_t *requested_format, format_t *actual_format);
union {
output_t *output;
ssrc_t *ssrc;
tls_fwd_t **tls_fwd;
};
union {
mix_t **mix;
};
resample_t resampler;
format_t format;
union {
unsigned int mixer_idx;
};
};
struct stream_s {
pthread_mutex_t lock;
char *name;
metafile_t *metafile;
unsigned long id;
unsigned long tag;
int fd;
handler_t handler;
unsigned int forwarding_on:1;
int64_t start_time_us;
unsigned int media_sdp_id;
unsigned int channel_slot;
};
struct packet_s {
seq_packet_t p; // must be first
void *buffer;
// pointers into buffer
struct iphdr *ip;
struct ip6_hdr *ip6;
struct udphdr *udp;
struct rtp_header *rtp;
str payload;
};
struct tls_fwd_s {
sink_t sink;
format_t format;
socket_t sock;
uint64_t in_pts;
AVFrame *silence_frame;
SSL_CTX *ssl_ctx;
SSL *ssl;
struct streambuf *stream;
struct poller poller;
ssrc_t *ssrc;
metafile_t *metafile;
unsigned int sent_intro:1;
};
struct ssrc_s {
pthread_mutex_t lock;
stream_t *stream;
metafile_t *metafile;
unsigned long ssrc;
packet_sequencer_t sequencer;
decode_t *decoders[128];
output_t *output;
tls_fwd_t *tls_fwd;
};
struct tag_s {
unsigned long id;
char *name;
char *label;
char *metadata;
};
typedef struct tag_s tag_t;
INLINE void str_q_free(str_q *q) {
t_queue_clear_full(q, str_free);
t_queue_free(q);
}
TYPED_GHASHTABLE(metadata_ht, str, str_q, str_hash, str_equal, str_free, str_q_free)
struct metafile_s {
pthread_mutex_t lock;
char *name;
char *parent;
char *call_id;
char *random_tag;
char *metadata;
metadata_ht metadata_parsed;
char *output_dest;
char *output_path;
char *output_pattern;
off_t pos;
unsigned long long db_id;
unsigned int db_streams;
int64_t start_time_us;
unsigned int media_rec_slots;
GStringChunk *gsc; // XXX limit max size
GPtrArray *streams;
GPtrArray *tags;
GHashTable *ssrc_hash; // contains ssrc_t objects
pthread_mutex_t mix_lock;
mix_t *mix;
output_t *mix_out;
mix_t *tls_mix;
tls_fwd_t *mix_tls_fwd;
int forward_fd;
int forward_count;
int forward_failed;
pthread_mutex_t payloads_lock;
char *payload_types[128];
char *payload_formats[128];
int payload_ptimes[128];
int media_ptimes[4];
unsigned int recording_on:1;
unsigned int forwarding_on:1;
unsigned int discard:1;
unsigned int db_metadata_done:1;
unsigned int skip_db:1;
unsigned int started:1;
};
struct output_s {
sink_t sink;
char *full_filename, // path + filename
*file_path,
*file_name,
*filename; // path + filename + suffix
const char *file_format;
const char *kind; // "mixed" or "single"
unsigned long long db_id;
gboolean skip_filename_extension;
int64_t start_time_us;
FILE *fp;
char *iobuf;
GString *membuf;
size_t mempos;
AVIOContext *avioctx;
AVFormatContext *fmtctx;
AVStream *avst;
encoder_t *encoder;
format_t requested_format,
actual_format;
content_t *content;
};
struct decode_s {
decoder_t *dec;
sink_t mix_sink;
sink_t tls_mix_sink;
};
struct content_s {
struct obj obj;
GString *s;
char *name;
unsigned int failed;
};
struct notif_action_s {
const char *name;
void (*setup)(notif_req_t *, output_t *o, metafile_t *mf, tag_t *tag);
bool (*perform)(notif_req_t *);
void (*failed)(notif_req_t *);
void (*cleanup)(notif_req_t *);
};
struct notif_req_s {
char *name; // just for logging
union {
// generic HTTP req
struct {
struct curl_slist *headers;
};
// notify command
struct {
char **argv;
};
// db writer
struct {
int64_t end_time;
};
// S3
struct {
GString *content_sha256;
};
};
// used by multiple actions
unsigned long long db_id;
content_t *content;
char *object_name;
const notif_action_t *action;
int64_t retry_time;
unsigned int retries;
int64_t falloff_us;
};
#endif
|