| 1 |
import sys |
| 2 |
|
| 3 |
from cffi import FFI |
| 4 |
|
| 5 |
libraries = ["srtp2"] |
| 6 |
if sys.platform == "win32": |
| 7 |
libraries += ["libcrypto", "advapi32", "crypt32", "gdi32", "user32", "ws2_32"] |
| 8 |
else: |
| 9 |
libraries += ["crypto"] |
| 10 |
|
| 11 |
ffibuilder = FFI() |
| 12 |
ffibuilder.set_source( |
| 13 |
"pylibsrtp._binding", "#include <srtp2/srtp.h>", libraries=libraries |
| 14 |
) |
| 15 |
|
| 16 |
ffibuilder.cdef( |
| 17 |
""" |
| 18 |
typedef enum { |
| 19 |
srtp_err_status_ok = 0, |
| 20 |
... |
| 21 |
} srtp_err_status_t; |
| 22 |
|
| 23 |
typedef enum { |
| 24 |
srtp_profile_aes128_cm_sha1_80 = 1, |
| 25 |
srtp_profile_aes128_cm_sha1_32 = 2, |
| 26 |
srtp_profile_aead_aes_128_gcm = 7, |
| 27 |
srtp_profile_aead_aes_256_gcm = 8, |
| 28 |
... |
| 29 |
} srtp_profile_t; |
| 30 |
|
| 31 |
typedef enum { |
| 32 |
ssrc_undefined = 0, |
| 33 |
ssrc_specific = 1, |
| 34 |
ssrc_any_inbound = 2, |
| 35 |
ssrc_any_outbound = 3 |
| 36 |
} srtp_ssrc_type_t; |
| 37 |
|
| 38 |
typedef struct srtp_crypto_policy_t { |
| 39 |
...; |
| 40 |
} srtp_crypto_policy_t; |
| 41 |
|
| 42 |
typedef struct { |
| 43 |
srtp_ssrc_type_t type; |
| 44 |
unsigned int value; |
| 45 |
} srtp_ssrc_t; |
| 46 |
|
| 47 |
typedef struct srtp_ctx_t_ srtp_ctx_t; |
| 48 |
typedef srtp_ctx_t *srtp_t; |
| 49 |
|
| 50 |
typedef struct srtp_policy_t { |
| 51 |
srtp_ssrc_t ssrc; |
| 52 |
srtp_crypto_policy_t rtp; |
| 53 |
srtp_crypto_policy_t rtcp; |
| 54 |
unsigned char *key; |
| 55 |
unsigned long window_size; |
| 56 |
int allow_repeat_tx; |
| 57 |
...; |
| 58 |
} srtp_policy_t; |
| 59 |
|
| 60 |
srtp_err_status_t srtp_init(void); |
| 61 |
|
| 62 |
srtp_err_status_t srtp_create(srtp_t *session, const srtp_policy_t *policy); |
| 63 |
srtp_err_status_t srtp_dealloc(srtp_t s); |
| 64 |
|
| 65 |
void srtp_crypto_policy_set_rtp_default(srtp_crypto_policy_t *p); |
| 66 |
void srtp_crypto_policy_set_rtcp_default(srtp_crypto_policy_t *p); |
| 67 |
|
| 68 |
srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtp( |
| 69 |
srtp_crypto_policy_t *policy, srtp_profile_t profile); |
| 70 |
srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtcp( |
| 71 |
srtp_crypto_policy_t *policy, srtp_profile_t profile); |
| 72 |
|
| 73 |
unsigned int srtp_profile_get_master_key_length(srtp_profile_t profile); |
| 74 |
unsigned int srtp_profile_get_master_salt_length(srtp_profile_t profile); |
| 75 |
|
| 76 |
srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy); |
| 77 |
srtp_err_status_t srtp_remove_stream(srtp_t session, unsigned int ssrc); |
| 78 |
|
| 79 |
srtp_err_status_t srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr); |
| 80 |
srtp_err_status_t srtp_protect_rtcp(srtp_t ctx, void *rtcp_hdr, int *pkt_octet_len); |
| 81 |
|
| 82 |
srtp_err_status_t srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr); |
| 83 |
srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx, void *srtcp_hdr, int *pkt_octet_len); |
| 84 |
""" |
| 85 |
) |
| 86 |
|
| 87 |
if __name__ == "__main__": |
| 88 |
ffibuilder.compile(verbose=True) |