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
pull/2474/head
Haibo Chen 4 years ago committed by GitHub
parent 56310ffd9d
commit 7eee9aa598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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) {
@ -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;
}
@ -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);
@ -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
@ -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);

Loading…
Cancel
Save