You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. MediaMtx (C++) - WebRTC server, WHEP (MediaMTX: internal/servers/webrtc)
  3. POST /<path>/whep SDP offer -> 201 + SDP answer, Location /<path>/whep/<secret>
  4. PATCH /<path>/whep/<secret> trickle ICE (application/trickle-ice-sdpfrag)
  5. DELETE /<path>/whep/<secret> close the session
  6. OPTIONS CORS preflight
  7. GET /<path>/ a small player page
  8. */
  9. #pragma once
  10. #include <map>
  11. #include <memory>
  12. #include <mutex>
  13. #include <thread>
  14. #include "../../conf/serverConf.h"
  15. #include "../../core/mediaPath.h"
  16. #include "../../protocols/httpp/httpServer.h"
  17. #include "session.h"
  18. namespace mtx {
  19. class WebrtcServer : public LogParent
  20. {
  21. public:
  22. WebrtcServer(const ServerConf & global, PathProvider * paths);
  23. ~WebrtcServer();
  24. bool start(std::string & err);
  25. void stop();
  26. size_t sessionCount() const;
  27. private:
  28. void handle(const HttpRequest & req, HttpResponse & res);
  29. void janitor();
  30. ServerConf m_global;
  31. PathProvider * m_pPaths;
  32. HttpServer m_http;
  33. mutable std::mutex m_mutex;
  34. std::map<std::string, std::shared_ptr<WebrtcSession>> m_sessions;
  35. std::thread m_janitor;
  36. std::mutex m_stopMutex;
  37. std::condition_variable m_stopCond;
  38. bool m_bRun = false;
  39. };
  40. } // namespace mtx