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

Remove usused RTP shared packet.

This commit is contained in:
winlin 2020-05-02 10:24:31 +08:00
parent 42ee52fa29
commit 5c43037190
9 changed files with 16 additions and 534 deletions

View file

@ -212,103 +212,6 @@ srs_error_t SrsRtpOpusMuxer::transcode(SrsSharedPtrMessage* shared_audio, char*
return err;
}
SrsRtpH264Demuxer::SrsRtpH264Demuxer()
{
}
SrsRtpH264Demuxer::~SrsRtpH264Demuxer()
{
}
srs_error_t SrsRtpH264Demuxer::parse(SrsRtpSharedPacket* rtp_pkt)
{
srs_error_t err = srs_success;
SrsRtpH264Header* rtp_h264_header = dynamic_cast<SrsRtpH264Header*>(rtp_pkt->rtp_payload_header);
if (rtp_h264_header == NULL) {
return srs_error_new(ERROR_RTC_RTP_MUXER, "invalid rtp packet");
}
uint8_t* rtp_payload = reinterpret_cast<uint8_t*>(rtp_pkt->rtp_payload());
int rtp_payload_size = rtp_pkt->rtp_payload_size();
if (rtp_payload_size == 0) {
srs_verbose("seq=%u, empty payload", rtp_pkt->rtp_header.get_sequence());
return err;
}
uint8_t nal_type = rtp_payload[0] & kNalTypeMask;
if (nal_type == SrsAvcNaluTypeIDR) {
rtp_h264_header->is_key_frame = true;
}
if (nal_type >= 1 && nal_type <= 23) {
rtp_h264_header->is_first_packet_of_frame = true;
rtp_h264_header->is_last_packet_of_frame = true;
rtp_h264_header->nalu_type = nal_type;
rtp_h264_header->nalu_header = rtp_payload[0];
rtp_h264_header->nalu_offset.push_back(make_pair(0, rtp_payload_size));
} else if (nal_type == kFuA) {
if ((rtp_payload[1] & kStart)) {
rtp_h264_header->is_first_packet_of_frame = true;
}
if ((rtp_payload[1] & kEnd)) {
rtp_h264_header->is_last_packet_of_frame = true;
}
rtp_h264_header->nalu_type = nal_type;
rtp_h264_header->nalu_header = (rtp_payload[0] & (~kNalTypeMask)) | (rtp_payload[1] & kNalTypeMask);
rtp_h264_header->nalu_offset.push_back(make_pair(2, rtp_payload_size - 2));
} else if (nal_type == kStapA) {
int i = 1;
rtp_h264_header->is_first_packet_of_frame = true;
rtp_h264_header->is_last_packet_of_frame = true;
rtp_h264_header->nalu_type = nal_type;
while (i < rtp_payload_size) {
uint16_t nal_len = (rtp_payload[i]) << 8 | rtp_payload[i + 1];
if (nal_len > rtp_payload_size - i) {
return srs_error_new(ERROR_RTC_RTP_MUXER, "invalid stap-a packet, nal len=%u, i=%d, rtp_payload_size=%d", nal_len, i, rtp_payload_size);
}
rtp_h264_header->nalu_offset.push_back(make_pair(i + 2, nal_len));
i += nal_len + 2;
}
if (i != rtp_payload_size) {
return srs_error_new(ERROR_RTC_RTP_MUXER, "invalid stap-a packet");
}
} else {
srs_verbose("payload size=%d, payload=%s", rtp_payload_size, srs_string_dumps_hex(rtp_pkt->payload, rtp_pkt->size).c_str());
return srs_error_new(ERROR_RTC_RTP_MUXER, "invalid h264 rtp packet");
}
return err;
}
SrsRtpOpusDemuxer::SrsRtpOpusDemuxer()
{
}
SrsRtpOpusDemuxer::~SrsRtpOpusDemuxer()
{
}
srs_error_t SrsRtpOpusDemuxer::parse(SrsRtpSharedPacket* rtp_pkt)
{
srs_error_t err = srs_success;
SrsRtpOpusHeader* rtp_opus_header = dynamic_cast<SrsRtpOpusHeader*>(rtp_pkt->rtp_payload_header);
if (rtp_opus_header == NULL) {
return srs_error_new(ERROR_RTC_RTP_MUXER, "invalid rtp packet");
}
rtp_opus_header->is_first_packet_of_frame = true;
rtp_opus_header->is_last_packet_of_frame = true;
rtp_opus_header->is_key_frame = true;
return err;
}
SrsRtc::SrsRtc()
{
req = NULL;

View file

@ -33,7 +33,6 @@
class SrsFormat;
class SrsSample;
class SrsSharedPtrMessage;
class SrsRtpSharedPacket;
class SrsRequest;
class SrsOriginHub;
class SrsAudioRecode;
@ -78,24 +77,6 @@ public:
srs_error_t transcode(SrsSharedPtrMessage* shared_audio, char* adts_audio, int nn_adts_audio);
};
class SrsRtpH264Demuxer
{
public:
SrsRtpH264Demuxer();
virtual ~SrsRtpH264Demuxer();
public:
srs_error_t parse(SrsRtpSharedPacket* rtp_pkt);
};
class SrsRtpOpusDemuxer
{
public:
SrsRtpOpusDemuxer();
virtual ~SrsRtpOpusDemuxer();
public:
srs_error_t parse(SrsRtpSharedPacket* rtp_pkt);
};
class SrsRtc
{
private:

View file

@ -449,6 +449,7 @@ srs_error_t SrsDtlsSession::protect_rtp(char* out_buf, const char* in_buf, int&
return srs_error_new(ERROR_RTC_SRTP_PROTECT, "rtp protect failed");
}
// TODO: FIXME: Merge with protect_rtp.
srs_error_t SrsDtlsSession::protect_rtp2(void* rtp_hdr, int* len_ptr)
{
srs_error_t err = srs_success;
@ -1921,11 +1922,6 @@ srs_error_t SrsRtcPublisher::on_audio(SrsRtpPacket2* pkt)
// TODO: FIXME: Error check.
audio_queue_->consume(audio_nack_, pkt);
if (audio_queue_->should_request_key_frame()) {
// TODO: FIXME: Check error.
send_rtcp_fb_pli(audio_ssrc);
}
check_send_nacks(audio_nack_, audio_ssrc);
return collect_audio_frames();
@ -2684,6 +2680,10 @@ srs_error_t SrsRtcSession::on_rtcp_feedback(char* buf, int nb_buf)
{
srs_error_t err = srs_success;
if (!dtls_session) {
return err;
}
if (nb_buf < 12) {
return srs_error_new(ERROR_RTC_RTCP_CHECK, "invalid rtp feedback packet, nb_buf=%d", nb_buf);
}
@ -2728,12 +2728,8 @@ srs_error_t SrsRtcSession::on_rtcp_feedback(char* buf, int nb_buf)
srs_verbose("pid=%u, blp=%d", pid, blp);
vector<SrsRtpSharedPacket*> resend_pkts;
// TODO: FIXME: Support ARQ.
SrsRtpSharedPacket* pkt = NULL; // source->find_rtp_packet(pid);
if (pkt) {
resend_pkts.push_back(pkt);
}
vector<SrsRtpPacket2*> resend_pkts;
uint16_t mask = 0x01;
for (int i = 1; i < 16 && blp; ++i, mask <<= 1) {
@ -2745,25 +2741,21 @@ srs_error_t SrsRtcSession::on_rtcp_feedback(char* buf, int nb_buf)
// TODO: FIXME: Support ARQ.
(void)loss_seq;
SrsRtpSharedPacket* pkt = NULL; // source->find_rtp_packet(loss_seq);
if (!pkt) {
continue;
}
resend_pkts.push_back(pkt);
}
for (int i = 0; i < (int)resend_pkts.size(); ++i) {
if (dtls_session) {
char* protected_buf = new char[kRtpPacketSize];
int nb_protected_buf = resend_pkts[i]->size;
SrsRtpPacket2* pkt = resend_pkts[i];
srs_verbose("resend pkt sequence=%u", resend_pkts[i]->rtp_header.get_sequence());
char* protected_buf = new char[kRtpPacketSize];
SrsAutoFreeA(char, protected_buf);
// TODO: FIXME: Check error.
dtls_session->protect_rtp(protected_buf, resend_pkts[i]->payload, nb_protected_buf);
sendonly_skt->sendto(protected_buf, nb_protected_buf, 0);
}
int nb_protected_buf = resend_pkts[i]->nb_bytes();
SrsBuffer buf(protected_buf, nb_protected_buf);
// TODO: FIXME: Check error.
pkt->encode(&buf);
dtls_session->protect_rtp(protected_buf, protected_buf, nb_protected_buf);
sendonly_skt->sendto(protected_buf, nb_protected_buf, 0);
}
return err;

View file

@ -268,8 +268,6 @@ private:
private:
SrsRequest* req;
SrsSource* source;
std::string sps;
std::string pps;
private:
std::map<uint32_t, uint64_t> last_sender_report_sys_time;
std::map<uint32_t, SrsNtp> last_sender_report_ntp;

View file

@ -849,58 +849,6 @@ SrsSharedPtrMessage* SrsMixQueue::pop()
return msg;
}
#ifdef SRS_RTC
SrsRtpPacketQueue::SrsRtpPacketQueue()
{
}
SrsRtpPacketQueue::~SrsRtpPacketQueue()
{
clear();
}
void SrsRtpPacketQueue::clear()
{
map<uint16_t, SrsRtpSharedPacket*>::iterator iter = pkt_queue.begin();
while (iter != pkt_queue.end()) {
srs_freep(iter->second);
pkt_queue.erase(iter++);
}
}
void SrsRtpPacketQueue::push(std::vector<SrsRtpSharedPacket*>& pkts)
{
for (int i = 0; i < (int)pkts.size(); ++i) {
insert(pkts[i]->rtp_header.get_sequence(), pkts[i]);
}
}
void SrsRtpPacketQueue::insert(const uint16_t& sequence, SrsRtpSharedPacket* pkt)
{
pkt_queue.insert(make_pair(sequence, pkt->copy()));
// TODO: 3000 is magic number.
if (pkt_queue.size() >= 3000) {
srs_freep(pkt_queue.begin()->second);
pkt_queue.erase(pkt_queue.begin());
}
}
SrsRtpSharedPacket* SrsRtpPacketQueue::find(const uint16_t& sequence)
{
if (pkt_queue.empty()) {
return NULL;
}
SrsRtpSharedPacket* pkt = NULL;
map<uint16_t, SrsRtpSharedPacket*>::iterator iter = pkt_queue.find(sequence);
if (iter != pkt_queue.end()) {
pkt = iter->second->copy();
}
return pkt;
}
#endif
SrsOriginHub::SrsOriginHub()
{
source = NULL;
@ -1955,9 +1903,6 @@ SrsSource::SrsSource()
jitter_algorithm = SrsRtmpJitterAlgorithmOFF;
mix_correct = false;
mix_queue = new SrsMixQueue();
#ifdef SRS_RTC
rtp_queue = new SrsRtpPacketQueue();
#endif
_can_publish = true;
_pre_source_id = _source_id = -1;
@ -1991,9 +1936,6 @@ SrsSource::~SrsSource()
srs_freep(hub);
srs_freep(meta);
srs_freep(mix_queue);
#ifdef SRS_RTC
srs_freep(rtp_queue);
#endif
srs_freep(play_edge);
srs_freep(publish_edge);
@ -2752,11 +2694,6 @@ string SrsSource::get_curr_origin()
}
#ifdef SRS_RTC
SrsRtpSharedPacket* SrsSource::find_rtp_packet(const uint16_t& seq)
{
return rtp_queue->find(seq);
}
SrsMetaCache* SrsSource::cached_meta()
{
return meta;

View file

@ -62,7 +62,6 @@ class SrsBuffer;
#ifdef SRS_HDS
class SrsHds;
#endif
class SrsRtpSharedPacket;
#ifdef SRS_RTC
class SrsRtcPublisher;
#endif
@ -336,32 +335,6 @@ public:
virtual SrsSharedPtrMessage* pop();
};
#ifdef SRS_RTC
// To find the RTP packet for RTX or restore.
// TODO: FIXME: Should queue RTP packets in connection level.
class SrsRtpPacketQueue
{
private:
struct SeqComp
{
bool operator()(const uint16_t& l, const uint16_t& r) const
{
return ((int16_t)(r - l)) > 0;
}
};
private:
std::map<uint16_t, SrsRtpSharedPacket*, SeqComp> pkt_queue;
public:
SrsRtpPacketQueue();
virtual ~SrsRtpPacketQueue();
public:
void clear();
void push(std::vector<SrsRtpSharedPacket*>& pkts);
void insert(const uint16_t& sequence, SrsRtpSharedPacket* pkt);
SrsRtpSharedPacket* find(const uint16_t& sequence);
};
#endif
// The hub for origin is a collection of utilities for origin only,
// For example, DVR, HLS, Forward and Transcode are only available for origin,
// they are meanless for edge server.
@ -550,10 +523,6 @@ private:
bool mix_correct;
// The mix queue to implements the mix correct algorithm.
SrsMixQueue* mix_queue;
#ifdef SRS_RTC
// rtp packet queue
SrsRtpPacketQueue* rtp_queue;
#endif
// For play, whether enabled atc.
// The atc(use absolute time and donot adjust time),
// directly use msg time and donot adjust if atc is true,
@ -650,8 +619,6 @@ public:
virtual std::string get_curr_origin();
#ifdef SRS_RTC
public:
// Find rtp packet by sequence
SrsRtpSharedPacket* find_rtp_packet(const uint16_t& seq);
// Get the cached meta, as such the sps/pps.
SrsMetaCache* cached_meta();
// Request keyframe for new client.