1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Bridger: Support RTC2RTMP bridger and shared FastTimer. 4.0.95

This commit is contained in:
winlin 2021-04-23 10:42:15 +08:00 committed by Winlin
parent c770e6d7bc
commit 3d225973ef
12 changed files with 700 additions and 4 deletions

View file

@ -163,8 +163,20 @@ public:
virtual void on_consumers_finished() = 0;
};
// SrsRtcStream bridge to SrsSource
class ISrsRtcSourceBridger
{
public:
ISrsRtcSourceBridger();
virtual ~ISrsRtcSourceBridger();
public:
virtual srs_error_t on_publish() = 0;
virtual srs_error_t on_rtp(SrsRtpPacket2 *pkt) = 0;
virtual void on_unpublish() = 0;
};
// A Source is a stream, to publish and to play with, binding to SrsRtcPublishStream and SrsRtcPlayStream.
class SrsRtcStream
class SrsRtcStream : public ISrsFastTimer
{
private:
// For publish, it's the publish client id.
@ -178,6 +190,8 @@ private:
ISrsRtcPublishStream* publish_stream_;
// Steam description for this steam.
SrsRtcStreamDescription* stream_desc_;
// The Source bridger, bridger stream to other source.
ISrsRtcSourceBridger* bridger_;
private:
// To delivery stream to clients.
std::vector<SrsRtcConsumer*> consumers;
@ -201,6 +215,8 @@ public:
// Get current source id.
virtual SrsContextId source_id();
virtual SrsContextId pre_source_id();
public:
void set_bridger(ISrsRtcSourceBridger *bridger);
public:
// Create consumer
// @param consumer, output the create consumer.
@ -234,6 +250,9 @@ public:
bool has_stream_desc();
void set_stream_desc(SrsRtcStreamDescription* stream_desc);
std::vector<SrsRtcTrackDescription*> get_track_desc(std::string type, std::string media_type);
// interface ISrsFastTimer
private:
srs_error_t on_timer(srs_utime_t interval, srs_utime_t tick);
};
// A helper class, to release the packet to cache.
@ -286,6 +305,52 @@ private:
srs_error_t package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, std::vector<SrsRtpPacketCacheHelper*>& helpers);
srs_error_t consume_packets(std::vector<SrsRtpPacketCacheHelper*>& helpers);
};
class SrsRtmpFromRtcBridger : public ISrsRtcSourceBridger
{
private:
SrsSource *source_;
SrsAudioTranscoder *codec_;
bool is_first_audio;
bool is_first_video;
// The format, codec information.
SrsRtmpFormat* format;
//TODO:use SrsRtpRingBuffer
//TODO:jitter buffer class
struct RtcPacketCache {
bool in_use;
uint16_t sn;
uint32_t ts;
SrsRtpPacket2* pkt;
};
const static uint16_t s_cache_size = 512;
RtcPacketCache cache_video_pkts_[s_cache_size];
uint16_t header_sn_;
uint16_t lost_sn_;
int64_t key_frame_ts_;
public:
SrsRtmpFromRtcBridger(SrsSource *src);
virtual ~SrsRtmpFromRtcBridger();
public:
srs_error_t initialize(SrsRequest* r);
public:
virtual srs_error_t on_publish();
virtual srs_error_t on_rtp(SrsRtpPacket2 *pkt);
virtual void on_unpublish();
private:
srs_error_t trancode_audio(SrsRtpPacket2 *pkt);
void packet_aac(SrsCommonMessage* audio, char* data, int len, uint32_t pts, bool is_header);
srs_error_t packet_video(SrsRtpPacket2* pkt);
srs_error_t packet_video_key_frame(SrsRtpPacket2* pkt);
srs_error_t packet_video_rtmp(const uint16_t start, const uint16_t end);
int32_t find_next_lost_sn(uint16_t current_sn, uint16_t& end_sn);
void clear_cached_video();
inline uint16_t cache_index(uint16_t current_sn) {
return current_sn%s_cache_size;
}
bool check_frame_complete(const uint16_t start, const uint16_t end);
};
#endif
// TODO: FIXME: Rename it.