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.
 
 
 
 
 
 

74 lines
2.5 KiB

/*
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 <atomic>
#include <condition_variable>
#include <memory>
#include <mutex>
#include <string>
#include <rtc/rtc.hpp>
#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<MediaPath> 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<MediaPath> m_pPath;
ServerConf m_global;
std::string m_sRemote;
AsyncReader m_reader;
std::shared_ptr<rtc::PeerConnection> m_pPc;
std::shared_ptr<rtc::Track> m_pTrack;
std::shared_ptr<rtc::RtpPacketizationConfig> m_pRtpConfig;
std::shared_ptr<rtc::RtcpSrReporter> m_pSrReporter;
StreamDesc m_desc;
std::mutex m_mutex;
std::condition_variable m_cond;
bool m_bGathered = false;
std::atomic<bool> m_bTrackOpen{false};
std::atomic<bool> m_bConnected{false};
std::atomic<bool> 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