mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Support dropping h.264 SEI from NALUs. v5.0.213 v6.0.125 (#4057)
try to fix #4052. --------- Co-authored-by: winlin <winlinvip@gmail.com>
This commit is contained in:
parent
282d94d7bb
commit
1656391c67
12 changed files with 141 additions and 66 deletions
|
@ -739,6 +739,7 @@ SrsRtcRtpBuilder::SrsRtcRtpBuilder(SrsFrameToRtcBridge* bridge, uint32_t assrc,
|
|||
codec_ = new SrsAudioTranscoder();
|
||||
latest_codec_ = SrsAudioCodecIdForbidden;
|
||||
keep_bframe = false;
|
||||
keep_avc_nalu_sei = true;
|
||||
merge_nalus = false;
|
||||
meta = new SrsMetaCache();
|
||||
audio_sequence = 0;
|
||||
|
@ -771,8 +772,10 @@ srs_error_t SrsRtcRtpBuilder::initialize(SrsRequest* r)
|
|||
format->try_annexb_first = _srs_config->try_annexb_first(r->vhost);
|
||||
|
||||
keep_bframe = _srs_config->get_rtc_keep_bframe(req->vhost);
|
||||
keep_avc_nalu_sei = _srs_config->get_rtc_keep_avc_nalu_sei(req->vhost);
|
||||
merge_nalus = _srs_config->get_rtc_server_merge_nalus();
|
||||
srs_trace("RTC bridge from RTMP, keep_bframe=%d, merge_nalus=%d", keep_bframe, merge_nalus);
|
||||
srs_trace("RTC bridge from RTMP, keep_bframe=%d, keep_avc_nalu_sei=%d, merge_nalus=%d",
|
||||
keep_bframe, keep_avc_nalu_sei, merge_nalus);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -1013,12 +1016,6 @@ srs_error_t SrsRtcRtpBuilder::on_video(SrsSharedPtrMessage* msg)
|
|||
for (int i = 0; i < nn_samples; i++) {
|
||||
SrsSample* sample = samples[i];
|
||||
|
||||
// We always ignore bframe here, if config to discard bframe,
|
||||
// the bframe flag will not be set.
|
||||
if (sample->bframe) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sample->size <= kRtpMaxPayloadSize) {
|
||||
if ((err = package_single_nalu(msg, sample, pkts)) != srs_success) {
|
||||
return srs_error_wrap(err, "package single nalu");
|
||||
|
@ -1050,14 +1047,27 @@ srs_error_t SrsRtcRtpBuilder::filter(SrsSharedPtrMessage* msg, SrsFormat* format
|
|||
// Update samples to shared frame.
|
||||
for (int i = 0; i < format->video->nb_samples; ++i) {
|
||||
SrsSample* sample = &format->video->samples[i];
|
||||
|
||||
if (!keep_avc_nalu_sei && format->vcodec->id == SrsVideoCodecIdAVC) {
|
||||
SrsAvcNaluType avc_nalu_type;
|
||||
// TODO: FIXME use static method to parse avc nalu type.
|
||||
if ((err = SrsVideoFrame::parse_avc_nalu_type(sample, avc_nalu_type)) != srs_success) {
|
||||
return srs_error_wrap(err, "parse avc nalu_type");
|
||||
}
|
||||
if (avc_nalu_type == SrsAvcNaluTypeSEI) {
|
||||
// srs_warn("skip avc nalu type SEI, size=%d", sample->size);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Because RTC does not support B-frame, so we will drop them.
|
||||
// TODO: Drop B-frame in better way, which not cause picture corruption.
|
||||
if (!keep_bframe) {
|
||||
if ((err = sample->parse_bframe()) != srs_success) {
|
||||
if (!keep_bframe && format->vcodec->id == SrsVideoCodecIdAVC) {
|
||||
bool is_b_frame;
|
||||
if ((err = SrsVideoFrame::parse_avc_b_frame(sample, is_b_frame)) != srs_success) {
|
||||
return srs_error_wrap(err, "parse bframe");
|
||||
}
|
||||
if (sample->bframe) {
|
||||
if (is_b_frame) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -1137,12 +1147,6 @@ srs_error_t SrsRtcRtpBuilder::package_nalus(SrsSharedPtrMessage* msg, const vect
|
|||
for (int i = 0; i < (int)samples.size(); i++) {
|
||||
SrsSample* sample = samples[i];
|
||||
|
||||
// We always ignore bframe here, if config to discard bframe,
|
||||
// the bframe flag will not be set.
|
||||
if (sample->bframe) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!sample->size) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue