1 /** 2 * @file stream.h GNU ZRTP: Stream class 3 * 4 * Copyright (C) 2010 - 2017 Creytiv.com 5 */ 6 #ifndef __STREAM_H 7 #define __STREAM_H 8 9 10 #include <libzrtpcpp/ZRtp.h> 11 12 13 enum StreamMediaType { 14 MT_UNKNOWN = 0, 15 MT_AUDIO, 16 MT_VIDEO, 17 MT_TEXT, 18 MT_APPLICATION, 19 MT_MESSAGE 20 }; 21 22 23 class ZRTPConfig { 24 public: 25 ZRTPConfig(const struct conf *conf, const char *conf_dir); 26 private: 27 friend class Stream; 28 friend class Session; 29 30 ZrtpConfigure zrtp; 31 32 char client_id[CLIENT_ID_SIZE + 1]; 33 char zid_filename[256]; 34 35 bool start_parallel; 36 }; 37 38 39 class Stream; 40 41 class SRTPStat { 42 public: 43 SRTPStat(const Stream *st, bool srtcp, uint64_t threshold); 44 void update(int ret_code, bool quiet = false); 45 void reset(); ok()46 uint64_t ok() { return m_ok; } 47 private: 48 const Stream *m_stream; 49 const bool m_control; 50 const uint64_t m_threshold; 51 uint64_t m_ok, m_decode, m_auth, m_replay; 52 uint64_t m_decode_burst, m_auth_burst, m_replay_burst; 53 }; 54 55 56 class Session; 57 class Srtp; 58 59 class Stream : public ZrtpCallback { 60 public: 61 Stream(int& err, const ZRTPConfig& config, Session *session, 62 udp_sock *rtpsock, udp_sock *rtcpsock, 63 uint32_t local_ssrc, StreamMediaType media_type); 64 65 virtual ~Stream(); 66 67 int start(Stream *master); 68 void stop(); started()69 bool started() { return m_started; } 70 71 int sdp_encode(struct sdp_media *sdpm); 72 int sdp_decode(const struct sdp_media *sdpm); 73 74 const char *media_name() const; 75 get_sas()76 const char *get_sas() const { return m_sas.c_str(); } get_ciphers()77 const char *get_ciphers() const { return m_ciphers.c_str(); } 78 bool sas_verified(); 79 void verify_sas(bool verify); 80 81 private: 82 static void zrtp_timer_cb(void *arg); 83 static bool udp_helper_send_cb(int *err, struct sa *src, 84 struct mbuf *mb, void *arg); 85 static bool udp_helper_recv_cb(struct sa *src, struct mbuf *mb, 86 void *arg); 87 88 bool udp_helper_send(int *err, struct sa *src, struct mbuf *mb); 89 bool udp_helper_recv(struct sa *src, struct mbuf *mb); 90 bool recv_zrtp(struct mbuf *mb); 91 92 void print_message(GnuZrtpCodes::MessageSeverity severity, 93 int32_t subcode); 94 95 Session *m_session; 96 ZRtp *m_zrtp; 97 bool m_started; 98 struct tmr m_zrtp_timer; 99 pthread_mutex_t m_zrtp_mutex; 100 uint16_t m_zrtp_seq; 101 uint32_t m_local_ssrc, m_peer_ssrc; 102 struct sa m_raddr; 103 struct udp_sock *m_rtpsock, *m_rtcpsock; 104 struct udp_helper *m_uh_rtp; 105 struct udp_helper *m_uh_rtcp; 106 StreamMediaType m_media_type; 107 Srtp *m_send_srtp, *m_recv_srtp; 108 pthread_mutex_t m_send_mutex; 109 SRTPStat m_srtp_stat, m_srtcp_stat; 110 std::string m_sas, m_ciphers; 111 112 protected: 113 virtual int32_t sendDataZRTP(const uint8_t* data, int32_t length); 114 virtual int32_t activateTimer(int32_t time); 115 virtual int32_t cancelTimer(); 116 virtual void sendInfo(GnuZrtpCodes::MessageSeverity severity, 117 int32_t subCode); 118 virtual bool srtpSecretsReady(SrtpSecret_t* secrets, 119 EnableSecurity part); 120 virtual void srtpSecretsOff(EnableSecurity part); 121 virtual void srtpSecretsOn(std::string c, std::string s, 122 bool verified); 123 virtual void handleGoClear(); 124 virtual void zrtpNegotiationFailed( 125 GnuZrtpCodes::MessageSeverity severity, 126 int32_t subCode); 127 virtual void zrtpNotSuppOther(); 128 virtual void synchEnter(); 129 virtual void synchLeave(); 130 virtual void zrtpAskEnrollment(GnuZrtpCodes::InfoEnrollment info); 131 virtual void zrtpInformEnrollment(GnuZrtpCodes::InfoEnrollment info); 132 virtual void signSAS(uint8_t* sasHash); 133 virtual bool checkSASSignature(uint8_t* sasHash); 134 }; 135 136 137 #endif // __STREAM_H 138 139