Skip to content

Commit

Permalink
For #2403, fix padding packets for RTMP2RTC. 4.0.140.
Browse files Browse the repository at this point in the history
Calculate the correct payload_size which pure padding data, in the process of rtc2rtmp, make Chrome happy (#2461)

* Calculate the correct payload_size which pure padding data, in the process of rtc2rtmp, make Chrome happy

* make clear for magic number

make clear for magic number

* Update srs_app_rtc_source.cpp
  • Loading branch information
duiniuluantanqin authored and winlinvip committed Jul 8, 2021
1 parent 10b9a81 commit 90b7933
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The changelog for SRS.

## SRS 4.0 Changelog

* v4.0, 2021-07-08, For [#2403](https://github.com/ossrs/srs/issues/2403), fix padding packets for RTMP2RTC. 4.0.140
* v4.0, 2021-07-04, For [#2424](https://github.com/ossrs/srs/issues/2424), use srandom/random to generate. 4.0.139
* v4.0, 2021-07-01, Merge [#2452](https://github.com/ossrs/srs/pull/2452), fix FFmpeg bug by updating channel_layout. 4.0.138
* v4.0, 2021-06-30, Merge [#2440](https://github.com/ossrs/srs/pull/2440), fix [#2390](https://github.com/ossrs/srs/issues/2390), SRT bug for zerolatency. 4.0.137
Expand Down
29 changes: 20 additions & 9 deletions trunk/src/app/srs_app_rtc_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1517,8 +1517,7 @@ srs_error_t SrsRtmpFromRtcBridger::packet_video_rtmp(const uint16_t start, const
{
srs_error_t err = srs_success;

//type_codec1 + avc_type + composition time + nalu size + nalu
int nb_payload = 1 + 1 + 3;
int nb_payload = 0;
uint16_t cnt = end - start + 1;

for (uint16_t i = 0; i < cnt; ++i) {
Expand All @@ -1527,7 +1526,7 @@ srs_error_t SrsRtmpFromRtcBridger::packet_video_rtmp(const uint16_t start, const
SrsRtpPacket* pkt = cache_video_pkts_[index].pkt;
// calculate nalu len
SrsRtpFUAPayload2* fua_payload = dynamic_cast<SrsRtpFUAPayload2*>(pkt->payload());
if (fua_payload) {
if (fua_payload && fua_payload->size > 0) {
if (fua_payload->start) {
nb_payload += 1 + 4;
}
Expand All @@ -1539,18 +1538,28 @@ srs_error_t SrsRtmpFromRtcBridger::packet_video_rtmp(const uint16_t start, const
if (stap_payload) {
for (int j = 0; j < (int)stap_payload->nalus.size(); ++j) {
SrsSample* sample = stap_payload->nalus.at(j);
nb_payload += 4 + sample->size;
if (sample->size > 0) {
nb_payload += 4 + sample->size;
}
}
continue;
}

SrsRtpRawPayload* raw_payload = dynamic_cast<SrsRtpRawPayload*>(pkt->payload());
if (raw_payload) {
if (raw_payload && raw_payload->nn_payload > 0) {
nb_payload += 4 + raw_payload->nn_payload;
continue;
}
}

if (0 == nb_payload) {
srs_warn("empty nalu");
return err;
}

//type_codec1 + avc_type + composition time + nalu size + nalu
nb_payload += 1 + 1 + 3;

SrsCommonMessage rtmp;
SrsRtpPacket* header = cache_video_pkts_[cache_index(start)].pkt;
rtmp.header.initialize_video(nb_payload, header->header.get_timestamp() / 90, 1);
Expand Down Expand Up @@ -1578,7 +1587,7 @@ srs_error_t SrsRtmpFromRtcBridger::packet_video_rtmp(const uint16_t start, const
cache_video_pkts_[index].sn = 0;

SrsRtpFUAPayload2* fua_payload = dynamic_cast<SrsRtpFUAPayload2*>(pkt->payload());
if (fua_payload) {
if (fua_payload && fua_payload->size > 0) {
if (fua_payload->start) {
nalu_len = fua_payload->size + 1;
//skip 4 bytes to write nalu_len future
Expand All @@ -1603,15 +1612,17 @@ srs_error_t SrsRtmpFromRtcBridger::packet_video_rtmp(const uint16_t start, const
if (stap_payload) {
for (int j = 0; j < (int)stap_payload->nalus.size(); ++j) {
SrsSample* sample = stap_payload->nalus.at(j);
payload.write_4bytes(sample->size);
payload.write_bytes(sample->bytes, sample->size);
if (sample->size > 0) {
payload.write_4bytes(sample->size);
payload.write_bytes(sample->bytes, sample->size);
}
}
srs_freep(pkt);
continue;
}

SrsRtpRawPayload* raw_payload = dynamic_cast<SrsRtpRawPayload*>(pkt->payload());
if (raw_payload) {
if (raw_payload && raw_payload->nn_payload > 0) {
payload.write_4bytes(raw_payload->nn_payload);
payload.write_bytes(raw_payload->payload, raw_payload->nn_payload);
srs_freep(pkt);
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 4
#define VERSION_MINOR 0
#define VERSION_REVISION 139
#define VERSION_REVISION 140

#endif

0 comments on commit 90b7933

Please sign in to comment.