1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/signaling/src/mediapipeline/SrtpFlow.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// Original author: ekr@rtfm.com 1.9 + 1.10 +#ifndef srtpflow_h__ 1.11 +#define srtpflow_h__ 1.12 + 1.13 +#include "ssl.h" 1.14 +#include "sslproto.h" 1.15 +#include "mozilla/RefPtr.h" 1.16 +#include "nsISupportsImpl.h" 1.17 + 1.18 +typedef struct srtp_policy_t srtp_policy_t; 1.19 +typedef struct srtp_ctx_t *srtp_t; 1.20 +typedef struct srtp_event_data_t srtp_event_data_t; 1.21 + 1.22 +namespace mozilla { 1.23 + 1.24 +#define SRTP_MASTER_KEY_LENGTH 16 1.25 +#define SRTP_MASTER_SALT_LENGTH 14 1.26 +#define SRTP_TOTAL_KEY_LENGTH (SRTP_MASTER_KEY_LENGTH + SRTP_MASTER_SALT_LENGTH) 1.27 + 1.28 +// For some reason libsrtp increases packet size by > 12 for RTCP even though 1.29 +// the doc claims otherwise. 1.30 +#define SRTP_MAX_EXPANSION 20 1.31 + 1.32 + 1.33 +class SrtpFlow { 1.34 + public: 1.35 + ~SrtpFlow(); 1.36 + 1.37 + 1.38 + static mozilla::RefPtr<SrtpFlow> Create(int cipher_suite, 1.39 + bool inbound, 1.40 + const void *key, 1.41 + size_t key_len); 1.42 + 1.43 + nsresult ProtectRtp(void *in, int in_len, 1.44 + int max_len, int *out_len); 1.45 + nsresult UnprotectRtp(void *in, int in_len, 1.46 + int max_len, int *out_len); 1.47 + nsresult ProtectRtcp(void *in, int in_len, 1.48 + int max_len, int *out_len); 1.49 + nsresult UnprotectRtcp(void *in, int in_len, 1.50 + int max_len, int *out_len); 1.51 + 1.52 + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SrtpFlow) 1.53 + 1.54 + static void srtp_event_handler(srtp_event_data_t *data); 1.55 + 1.56 + 1.57 + private: 1.58 + SrtpFlow() : session_(nullptr) {} 1.59 + 1.60 + nsresult CheckInputs(bool protect, void *in, int in_len, 1.61 + int max_len, int *out_len); 1.62 + 1.63 + static nsresult Init(); 1.64 + static bool initialized; // Was libsrtp initialized? Only happens once. 1.65 + 1.66 + srtp_t session_; 1.67 +}; 1.68 + 1.69 +} // End of namespace 1.70 +#endif 1.71 +