mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Refine stream/ssrc/sdp structure
This commit is contained in:
parent
426938cc8a
commit
991672bf41
11 changed files with 2204 additions and 563 deletions
|
@ -28,7 +28,12 @@
|
|||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <inttypes.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include <srs_app_rtc_sdp.hpp>
|
||||
#include <srs_service_st.hpp>
|
||||
#include <srs_app_source.hpp>
|
||||
|
||||
|
@ -43,6 +48,28 @@ class SrsRtcFromRtmpBridger;
|
|||
class SrsAudioRecode;
|
||||
class SrsRtpPacket2;
|
||||
class SrsSample;
|
||||
class SrsRtcStreamDescription;
|
||||
class SrsRtcTrackDescription;
|
||||
class SrsRtcConnection;
|
||||
class SrsRtpRingBuffer;
|
||||
class SrsRtpNackForReceiver;
|
||||
|
||||
class SrsNtp
|
||||
{
|
||||
public:
|
||||
uint64_t system_ms_;
|
||||
uint64_t ntp_;
|
||||
uint32_t ntp_second_;
|
||||
uint32_t ntp_fractions_;
|
||||
public:
|
||||
SrsNtp();
|
||||
virtual ~SrsNtp();
|
||||
public:
|
||||
static SrsNtp from_time_ms(uint64_t ms);
|
||||
static SrsNtp to_time_ms(uint64_t ntp);
|
||||
public:
|
||||
static uint64_t kMagicNtpFractionalUnit;
|
||||
};
|
||||
|
||||
class SrsRtcConsumer
|
||||
{
|
||||
|
@ -100,7 +127,7 @@ public:
|
|||
ISrsRtcPublishStream();
|
||||
virtual ~ISrsRtcPublishStream();
|
||||
public:
|
||||
virtual void request_keyframe() = 0;
|
||||
virtual void request_keyframe(uint32_t ssrc) = 0;
|
||||
};
|
||||
|
||||
// A Source is a stream, to publish and to play with, binding to SrsRtcPublishStream and SrsRtcPlayStream.
|
||||
|
@ -118,6 +145,8 @@ private:
|
|||
ISrsRtcPublishStream* publish_stream_;
|
||||
// Transmux RTMP to RTC.
|
||||
ISrsSourceBridger* bridger_;
|
||||
// Steam description for this steam.
|
||||
SrsRtcStreamDescription* stream_desc_;
|
||||
private:
|
||||
// To delivery stream to clients.
|
||||
std::vector<SrsRtcConsumer*> consumers;
|
||||
|
@ -159,6 +188,9 @@ public:
|
|||
void set_publish_stream(ISrsRtcPublishStream* v);
|
||||
// Consume the shared RTP packet, user must free it.
|
||||
srs_error_t on_rtp(SrsRtpPacket2* pkt);
|
||||
// Set and get stream description for souce
|
||||
void set_stream_desc(SrsRtcStreamDescription* stream_desc);
|
||||
std::vector<SrsRtcTrackDescription*> get_track_desc(std::string type, std::string media_type);
|
||||
};
|
||||
|
||||
#ifdef SRS_FFMPEG_FIT
|
||||
|
@ -214,5 +246,242 @@ public:
|
|||
virtual void on_unpublish();
|
||||
};
|
||||
|
||||
// TODO: FIXME: Rename it.
|
||||
class SrsCodecPayload
|
||||
{
|
||||
public:
|
||||
std::string type_;
|
||||
uint8_t pt_;
|
||||
std::string name_;
|
||||
int sample_;
|
||||
|
||||
std::vector<std::string> rtcp_fbs_;
|
||||
public:
|
||||
SrsCodecPayload();
|
||||
SrsCodecPayload(uint8_t pt, std::string encode_name, int sample);
|
||||
virtual ~SrsCodecPayload();
|
||||
public:
|
||||
virtual SrsCodecPayload* copy();
|
||||
virtual SrsMediaPayloadType generate_media_payload_type();
|
||||
};
|
||||
|
||||
// TODO: FIXME: Rename it.
|
||||
class SrsVideoPayload : public SrsCodecPayload
|
||||
{
|
||||
public:
|
||||
struct H264SpecificParameter
|
||||
{
|
||||
std::string profile_level_id;
|
||||
std::string packetization_mode;
|
||||
std::string level_asymmerty_allow;
|
||||
};
|
||||
H264SpecificParameter h264_param_;
|
||||
|
||||
public:
|
||||
SrsVideoPayload();
|
||||
SrsVideoPayload(uint8_t pt, std::string encode_name, int sample);
|
||||
virtual ~SrsVideoPayload();
|
||||
public:
|
||||
virtual SrsVideoPayload* copy();
|
||||
virtual SrsMediaPayloadType generate_media_payload_type();
|
||||
public:
|
||||
srs_error_t set_h264_param_desc(std::string fmtp);
|
||||
};
|
||||
|
||||
// TODO: FIXME: Rename it.
|
||||
class SrsAudioPayload : public SrsCodecPayload
|
||||
{
|
||||
struct SrsOpusParameter
|
||||
{
|
||||
int minptime;
|
||||
bool use_inband_fec;
|
||||
bool usedtx;
|
||||
};
|
||||
|
||||
public:
|
||||
int channel_;
|
||||
SrsOpusParameter opus_param_;
|
||||
public:
|
||||
SrsAudioPayload();
|
||||
SrsAudioPayload(uint8_t pt, std::string encode_name, int sample, int channel);
|
||||
virtual ~SrsAudioPayload();
|
||||
public:
|
||||
virtual SrsAudioPayload* copy();
|
||||
virtual SrsMediaPayloadType generate_media_payload_type();
|
||||
public:
|
||||
srs_error_t set_opus_param_desc(std::string fmtp);
|
||||
};
|
||||
|
||||
class SrsRtcTrackDescription
|
||||
{
|
||||
public:
|
||||
// type: audio, video
|
||||
std::string type_;
|
||||
// track_id
|
||||
std::string id_;
|
||||
// ssrc is the primary ssrc for this track,
|
||||
// if sdp has ssrc-group, it is the first ssrc of the ssrc-group
|
||||
uint32_t ssrc_;
|
||||
// rtx ssrc is the second ssrc of "FEC" src-group,
|
||||
// if no rtx ssrc, rtx_ssrc_ = 0.
|
||||
uint32_t fec_ssrc_;
|
||||
// rtx ssrc is the second ssrc of "FID" src-group,
|
||||
// if no rtx ssrc, rtx_ssrc_ = 0.
|
||||
uint32_t rtx_ssrc_;
|
||||
// key: rtp header extension id, value: rtp header extension uri.
|
||||
std::map<int, std::string> extmaps_;
|
||||
// Whether this track active. default: active.
|
||||
bool is_active_;
|
||||
// direction
|
||||
std::string direction_;
|
||||
// TODO: FIXME: whether mid is needed?
|
||||
std::string mid_;
|
||||
|
||||
// meida payload, such as opus, h264.
|
||||
SrsCodecPayload* media_;
|
||||
SrsCodecPayload* red_;
|
||||
SrsCodecPayload* rtx_;
|
||||
SrsCodecPayload* ulpfec_;
|
||||
SrsCodecPayload* rsfec_;
|
||||
public:
|
||||
SrsRtcTrackDescription();
|
||||
virtual ~SrsRtcTrackDescription();
|
||||
public:
|
||||
// whether or not the track has ssrc.
|
||||
// for example:
|
||||
// we need check track has the ssrc in the ssrc_group, then add ssrc_group to the track,
|
||||
bool has_ssrc(uint32_t ssrc);
|
||||
public:
|
||||
void add_rtp_extension_desc(int id, std::string uri);
|
||||
void set_direction(std::string direction);
|
||||
void set_codec_payload(SrsCodecPayload* payload);
|
||||
// auxiliary paylod include red, rtx, ulpfec, rsfec.
|
||||
void create_auxiliary_payload(const std::vector<SrsMediaPayloadType> payload_types);
|
||||
void set_rtx_ssrc(uint32_t ssrc);
|
||||
void set_fec_ssrc(uint32_t ssrc);
|
||||
void set_mid(std::string mid);
|
||||
int get_rtp_extension_id(std::string uri);
|
||||
public:
|
||||
SrsRtcTrackDescription* copy();
|
||||
public:
|
||||
// find media with payload type.
|
||||
SrsMediaPayloadType generate_media_payload_type(int payload_type);
|
||||
};
|
||||
|
||||
class SrsRtcStreamDescription
|
||||
{
|
||||
public:
|
||||
// the id for this stream;
|
||||
std::string id_;
|
||||
|
||||
SrsRtcTrackDescription* audio_track_desc_;
|
||||
std::vector<SrsRtcTrackDescription*> video_track_descs_;
|
||||
public:
|
||||
SrsRtcStreamDescription();
|
||||
virtual ~SrsRtcStreamDescription();
|
||||
|
||||
public:
|
||||
SrsRtcStreamDescription* copy();
|
||||
SrsRtcTrackDescription* find_track_description_by_ssrc(uint32_t ssrc);
|
||||
};
|
||||
|
||||
class ISrsRtcTrack
|
||||
{
|
||||
public:
|
||||
ISrsRtcTrack();
|
||||
virtual ~ISrsRtcTrack();
|
||||
public:
|
||||
virtual srs_error_t on_rtp(SrsRtpPacket2* pkt) = 0;
|
||||
};
|
||||
|
||||
class SrsRtcRecvTrack
|
||||
{
|
||||
protected:
|
||||
SrsRtcTrackDescription* track_desc_;
|
||||
|
||||
SrsRtcConnection* session_;
|
||||
SrsRtpRingBuffer* rtp_queue_;
|
||||
SrsRtpNackForReceiver* nack_receiver_;
|
||||
|
||||
// send report ntp and received time.
|
||||
SrsNtp last_sender_report_ntp;
|
||||
uint64_t last_sender_report_sys_time;
|
||||
public:
|
||||
SrsRtcRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* stream_descs, bool is_audio);
|
||||
virtual ~SrsRtcRecvTrack();
|
||||
public:
|
||||
bool has_ssrc(uint32_t ssrc);
|
||||
void update_rtt(int rtt);
|
||||
void update_send_report_time(const SrsNtp& ntp);
|
||||
srs_error_t send_rtcp_rr();
|
||||
srs_error_t send_rtcp_xr_rrtr();
|
||||
protected:
|
||||
srs_error_t on_nack(SrsRtpPacket2* pkt);
|
||||
public:
|
||||
virtual srs_error_t on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt);
|
||||
};
|
||||
|
||||
class SrsRtcAudioRecvTrack : public SrsRtcRecvTrack
|
||||
{
|
||||
public:
|
||||
SrsRtcAudioRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* track_desc);
|
||||
virtual ~SrsRtcAudioRecvTrack();
|
||||
public:
|
||||
virtual srs_error_t on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt);
|
||||
};
|
||||
|
||||
class SrsRtcVideoRecvTrack : public SrsRtcRecvTrack
|
||||
{
|
||||
private:
|
||||
bool request_key_frame_;
|
||||
public:
|
||||
SrsRtcVideoRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* stream_descs);
|
||||
virtual ~SrsRtcVideoRecvTrack();
|
||||
public:
|
||||
virtual srs_error_t on_rtp(SrsRtcStream* source, SrsRtpPacket2* pkt);
|
||||
public:
|
||||
void request_keyframe();
|
||||
};
|
||||
|
||||
class SrsRtcSendTrack
|
||||
{
|
||||
protected:
|
||||
// send track description
|
||||
SrsRtcTrackDescription* track_desc_;
|
||||
|
||||
SrsRtcConnection* session_;
|
||||
// NACK ARQ ring buffer.
|
||||
SrsRtpRingBuffer* rtp_queue_;
|
||||
public:
|
||||
SrsRtcSendTrack(SrsRtcConnection* session, SrsRtcTrackDescription* track_desc, bool is_audio);
|
||||
virtual ~SrsRtcSendTrack();
|
||||
public:
|
||||
bool has_ssrc(uint32_t ssrc);
|
||||
SrsRtpPacket2* fetch_rtp_packet(uint16_t seq);
|
||||
public:
|
||||
virtual srs_error_t on_rtp(std::vector<SrsRtpPacket2*>& send_packets, SrsRtpPacket2* pkt);
|
||||
virtual srs_error_t on_rtcp(SrsRtpPacket2* pkt);
|
||||
};
|
||||
|
||||
class SrsRtcAudioSendTrack : public SrsRtcSendTrack
|
||||
{
|
||||
public:
|
||||
SrsRtcAudioSendTrack(SrsRtcConnection* session, SrsRtcTrackDescription* track_desc);
|
||||
virtual ~SrsRtcAudioSendTrack();
|
||||
public:
|
||||
virtual srs_error_t on_rtp(std::vector<SrsRtpPacket2*>& send_packets, SrsRtpPacket2* pkt);
|
||||
virtual srs_error_t on_rtcp(SrsRtpPacket2* pkt);
|
||||
};
|
||||
|
||||
class SrsRtcVideoSendTrack : public SrsRtcSendTrack
|
||||
{
|
||||
public:
|
||||
SrsRtcVideoSendTrack(SrsRtcConnection* session, SrsRtcTrackDescription* track_desc);
|
||||
virtual ~SrsRtcVideoSendTrack();
|
||||
public:
|
||||
virtual srs_error_t on_rtp(std::vector<SrsRtpPacket2*>& send_packets, SrsRtpPacket2* pkt);
|
||||
virtual srs_error_t on_rtcp(SrsRtpPacket2* pkt);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue