dtlssrtptransport.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Copyright (c) 2020 Paul-Louis Ageneau
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef RTC_IMPL_DTLS_SRTP_TRANSPORT_H
  19. #define RTC_IMPL_DTLS_SRTP_TRANSPORT_H
  20. #include "common.hpp"
  21. #include "dtlstransport.hpp"
  22. #if RTC_ENABLE_MEDIA
  23. #if RTC_SYSTEM_SRTP
  24. #include <srtp2/srtp.h>
  25. #else
  26. #include "srtp.h"
  27. #endif
  28. #include <atomic>
  29. namespace rtc::impl {
  30. class DtlsSrtpTransport final : public DtlsTransport {
  31. public:
  32. static void Init();
  33. static void Cleanup();
  34. DtlsSrtpTransport(shared_ptr<IceTransport> lower, certificate_ptr certificate,
  35. optional<size_t> mtu, verifier_callback verifierCallback,
  36. message_callback srtpRecvCallback, state_callback stateChangeCallback);
  37. ~DtlsSrtpTransport();
  38. bool sendMedia(message_ptr message);
  39. private:
  40. void incoming(message_ptr message) override;
  41. void postHandshake() override;
  42. message_callback mSrtpRecvCallback;
  43. srtp_t mSrtpIn, mSrtpOut;
  44. std::atomic<bool> mInitDone = false;
  45. unsigned char mClientSessionKey[SRTP_AES_ICM_128_KEY_LEN_WSALT];
  46. unsigned char mServerSessionKey[SRTP_AES_ICM_128_KEY_LEN_WSALT];
  47. std::mutex sendMutex;
  48. };
  49. } // namespace rtc::impl
  50. #endif
  51. #endif