mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Rtc2Rtmp: Using rtp timestamp to distinguish different video frame (#2721)
This commit is contained in:
parent
1f4dad024e
commit
878833bb95
2 changed files with 8 additions and 3 deletions
|
@ -1437,6 +1437,7 @@ srs_error_t SrsRtmpFromRtcBridger::packet_video(SrsRtpPacket* src)
|
||||||
cache_video_pkts_[index].pkt = pkt;
|
cache_video_pkts_[index].pkt = pkt;
|
||||||
cache_video_pkts_[index].sn = pkt->header.get_sequence();
|
cache_video_pkts_[index].sn = pkt->header.get_sequence();
|
||||||
cache_video_pkts_[index].ts = pkt->get_avsync_time();
|
cache_video_pkts_[index].ts = pkt->get_avsync_time();
|
||||||
|
cache_video_pkts_[index].rtp_ts = pkt->header.get_timestamp();
|
||||||
|
|
||||||
// check whether to recovery lost packet and can construct a video frame
|
// check whether to recovery lost packet and can construct a video frame
|
||||||
if (lost_sn_ == pkt->header.get_sequence()) {
|
if (lost_sn_ == pkt->header.get_sequence()) {
|
||||||
|
@ -1525,6 +1526,7 @@ srs_error_t SrsRtmpFromRtcBridger::packet_video_key_frame(SrsRtpPacket* pkt)
|
||||||
cache_video_pkts_[index].pkt = pkt;
|
cache_video_pkts_[index].pkt = pkt;
|
||||||
cache_video_pkts_[index].sn = pkt->header.get_sequence();
|
cache_video_pkts_[index].sn = pkt->header.get_sequence();
|
||||||
cache_video_pkts_[index].ts = pkt->get_avsync_time();
|
cache_video_pkts_[index].ts = pkt->get_avsync_time();
|
||||||
|
cache_video_pkts_[index].rtp_ts = pkt->header.get_timestamp();
|
||||||
|
|
||||||
int32_t sn = lost_sn_;
|
int32_t sn = lost_sn_;
|
||||||
uint16_t tail_sn = 0;
|
uint16_t tail_sn = 0;
|
||||||
|
@ -1622,6 +1624,7 @@ srs_error_t SrsRtmpFromRtcBridger::packet_video_rtmp(const uint16_t start, const
|
||||||
cache_video_pkts_[index].in_use = false;
|
cache_video_pkts_[index].in_use = false;
|
||||||
cache_video_pkts_[index].pkt = NULL;
|
cache_video_pkts_[index].pkt = NULL;
|
||||||
cache_video_pkts_[index].ts = 0;
|
cache_video_pkts_[index].ts = 0;
|
||||||
|
cache_video_pkts_[index].rtp_ts = 0;
|
||||||
cache_video_pkts_[index].sn = 0;
|
cache_video_pkts_[index].sn = 0;
|
||||||
|
|
||||||
SrsRtpFUAPayload2* fua_payload = dynamic_cast<SrsRtpFUAPayload2*>(pkt->payload());
|
SrsRtpFUAPayload2* fua_payload = dynamic_cast<SrsRtpFUAPayload2*>(pkt->payload());
|
||||||
|
@ -1692,7 +1695,7 @@ srs_error_t SrsRtmpFromRtcBridger::packet_video_rtmp(const uint16_t start, const
|
||||||
|
|
||||||
int32_t SrsRtmpFromRtcBridger::find_next_lost_sn(uint16_t current_sn, uint16_t& end_sn)
|
int32_t SrsRtmpFromRtcBridger::find_next_lost_sn(uint16_t current_sn, uint16_t& end_sn)
|
||||||
{
|
{
|
||||||
uint32_t last_ts = cache_video_pkts_[cache_index(header_sn_)].ts;
|
uint32_t last_rtp_ts = cache_video_pkts_[cache_index(header_sn_)].rtp_ts;
|
||||||
for (int i = 0; i < s_cache_size; ++i) {
|
for (int i = 0; i < s_cache_size; ++i) {
|
||||||
uint16_t lost_sn = current_sn + i;
|
uint16_t lost_sn = current_sn + i;
|
||||||
int index = cache_index(lost_sn);
|
int index = cache_index(lost_sn);
|
||||||
|
@ -1701,7 +1704,7 @@ int32_t SrsRtmpFromRtcBridger::find_next_lost_sn(uint16_t current_sn, uint16_t&
|
||||||
return lost_sn;
|
return lost_sn;
|
||||||
}
|
}
|
||||||
//check time first, avoid two small frame mixed case decode fail
|
//check time first, avoid two small frame mixed case decode fail
|
||||||
if (last_ts != cache_video_pkts_[index].ts) {
|
if (last_rtp_ts != cache_video_pkts_[index].rtp_ts) {
|
||||||
end_sn = lost_sn - 1;
|
end_sn = lost_sn - 1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1724,6 +1727,7 @@ void SrsRtmpFromRtcBridger::clear_cached_video()
|
||||||
srs_freep(cache_video_pkts_[i].pkt);
|
srs_freep(cache_video_pkts_[i].pkt);
|
||||||
cache_video_pkts_[i].sn = 0;
|
cache_video_pkts_[i].sn = 0;
|
||||||
cache_video_pkts_[i].ts = 0;
|
cache_video_pkts_[i].ts = 0;
|
||||||
|
cache_video_pkts_[i].rtp_ts = 0;
|
||||||
cache_video_pkts_[i].in_use = false;
|
cache_video_pkts_[i].in_use = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,6 +300,7 @@ private:
|
||||||
bool in_use;
|
bool in_use;
|
||||||
uint16_t sn;
|
uint16_t sn;
|
||||||
uint32_t ts;
|
uint32_t ts;
|
||||||
|
uint32_t rtp_ts;
|
||||||
SrsRtpPacket* pkt;
|
SrsRtpPacket* pkt;
|
||||||
};
|
};
|
||||||
const static uint16_t s_cache_size = 512;
|
const static uint16_t s_cache_size = 512;
|
||||||
|
@ -325,7 +326,7 @@ private:
|
||||||
int32_t find_next_lost_sn(uint16_t current_sn, uint16_t& end_sn);
|
int32_t find_next_lost_sn(uint16_t current_sn, uint16_t& end_sn);
|
||||||
void clear_cached_video();
|
void clear_cached_video();
|
||||||
inline uint16_t cache_index(uint16_t current_sn) {
|
inline uint16_t cache_index(uint16_t current_sn) {
|
||||||
return current_sn%s_cache_size;
|
return current_sn % s_cache_size;
|
||||||
}
|
}
|
||||||
bool check_frame_complete(const uint16_t start, const uint16_t end);
|
bool check_frame_complete(const uint16_t start, const uint16_t end);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue