/* MediaMtx (C++) - WebRTC (WHEP) reader session (MediaMTX: internal/servers/webrtc/session.go) The browser POSTs its SDP offer (recvonly video); the answer contains one H264 send-only track and all local ICE candidates (the la_mojo dashboard does not trickle). The camera's H264 is sent as it is (no transcoding), starting at the next IDR. */ #pragma once #include #include #include #include #include #include #include "../../conf/serverConf.h" #include "../../core/mediaPath.h" #include "../../logger/logger.h" #include "../../stream/stream.h" namespace mtx { class WebrtcSession : public PathReader, public LogParent { public: WebrtcSession(const std::string & secret, std::shared_ptr path, const ServerConf & global, const std::string & remoteAddr); ~WebrtcSession() override; // Returns the answer SDP; on failure false + http status + error bool create(const std::string & offer, std::string & answer, int & status, std::string & err); bool addRemoteCandidates(const std::string & sdpFrag, std::string & err); void close(); // The server removes sessions that are closing, failed or never connected bool isClosing() const { return m_bClosing; } bool connectTimedOut(int64_t nowMsValue) const { return ! m_bConnected && nowMsValue - m_tCreated > 20000; } const std::string & secret() const { return m_sSecret; } const std::string & pathName() const { return m_pPath->name(); } // PathReader void push(const UnitPtr & unit) override { m_reader.push(unit); } void pathNotReady() override; private: void onUnit(const UnitPtr & unit); std::string m_sSecret; std::shared_ptr m_pPath; ServerConf m_global; std::string m_sRemote; AsyncReader m_reader; std::shared_ptr m_pPc; std::shared_ptr m_pTrack; std::shared_ptr m_pRtpConfig; std::shared_ptr m_pSrReporter; StreamDesc m_desc; std::mutex m_mutex; std::condition_variable m_cond; bool m_bGathered = false; std::atomic m_bTrackOpen{false}; std::atomic m_bConnected{false}; std::atomic m_bClosing{false}; bool m_bReading = false; bool m_bClosed = false; bool m_bStarted = false; // first IDR sent int64_t m_nFirstPts = 0; int64_t m_tCreated = 0; int64_t m_tLastSr = 0; uint64_t m_nBytesSent = 0; }; } // namespace mtx