James Kuszmaul | 4a42b18 | 2021-01-17 11:32:46 -0800 | [diff] [blame^] | 1 | #pragma once |
| 2 | #include <rawrtc.h> |
| 3 | #include <rawrtcc.h> |
| 4 | #include <rawrtcdc.h> |
| 5 | #include <re.h> |
| 6 | |
| 7 | enum { |
| 8 | PARAMETERS_MAX_LENGTH = 8192, |
| 9 | }; |
| 10 | |
| 11 | /* |
| 12 | * SCTP parameters that need to be negotiated. |
| 13 | */ |
| 14 | struct sctp_parameters { |
| 15 | struct rawrtc_sctp_capabilities* capabilities; |
| 16 | uint16_t port; |
| 17 | }; |
| 18 | |
| 19 | /* |
| 20 | * Client structure. Can be extended. |
| 21 | */ |
| 22 | struct client { |
| 23 | char* name; |
| 24 | char** ice_candidate_types; |
| 25 | size_t n_ice_candidate_types; |
| 26 | }; |
| 27 | |
| 28 | /* |
| 29 | * Data channel helper structure. Can be extended. |
| 30 | */ |
| 31 | struct data_channel_helper { |
| 32 | struct le le; |
| 33 | struct rawrtc_data_channel* channel; |
| 34 | char* label; |
| 35 | struct client* client; |
| 36 | void* arg; |
| 37 | }; |
| 38 | |
| 39 | /* |
| 40 | * Ignore success code list. |
| 41 | */ |
| 42 | extern enum rawrtc_code const ignore_success[]; |
| 43 | extern size_t const ignore_success_length; |
| 44 | |
| 45 | /* |
| 46 | * Helper macros for exiting with error messages. |
| 47 | */ |
| 48 | #define EOE(code) exit_on_error(code, ignore_success, ignore_success_length, __FILE__, __LINE__) |
| 49 | #define EOEIGN(code, ignore) exit_on_error(code, ignore, ARRAY_SIZE(ignore), __FILE__, __LINE__) |
| 50 | #define EOR(code) exit_on_posix_error(code, __FILE__, __LINE__) |
| 51 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (__GNUC__ >= 3) |
| 52 | # define EWE(...) exit_with_error(__FILE__, __LINE__, __VA_ARGS__) |
| 53 | #elif defined(__GNUC__) |
| 54 | # define EWE(args...) exit_with_error(__FILE__, __LINE__, args) |
| 55 | #endif |
| 56 | |
| 57 | /* |
| 58 | * Function to be called before exiting. |
| 59 | */ |
| 60 | void before_exit(void); |
| 61 | |
| 62 | /* |
| 63 | * Exit on error code. |
| 64 | */ |
| 65 | void exit_on_error( |
| 66 | enum rawrtc_code const code, |
| 67 | enum rawrtc_code const ignore[], |
| 68 | size_t const n_ignore, |
| 69 | char const* const file, |
| 70 | uint32_t const line); |
| 71 | |
| 72 | /* |
| 73 | * Exit on POSIX error code. |
| 74 | */ |
| 75 | void exit_on_posix_error(int code, char const* const file, uint32_t line); |
| 76 | |
| 77 | /* |
| 78 | * Exit with a custom error message. |
| 79 | */ |
| 80 | void exit_with_error(char const* const file, uint32_t line, char const* const formatter, ...); |
| 81 | |
| 82 | /* |
| 83 | * Check if the ICE candidate type is enabled. |
| 84 | */ |
| 85 | bool ice_candidate_type_enabled( |
| 86 | struct client* const client, enum rawrtc_ice_candidate_type const type); |
| 87 | |
| 88 | /* |
| 89 | * Print ICE candidate information. |
| 90 | */ |
| 91 | void print_ice_candidate( |
| 92 | struct rawrtc_ice_candidate* const candidate, |
| 93 | char const* const url, // read-only |
| 94 | struct rawrtc_peer_connection_ice_candidate* const pc_candidate, // nullable |
| 95 | struct client* const client); |