VP9 RTP frame reference finder cleanup.

Bug: chromium:838402
Change-Id: Ib6117db5aeb83fc03f72759be2e42d0a4ceb94b6
Reviewed-on: https://webrtc-review.googlesource.com/60260
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23139}
This commit is contained in:
philipel 2018-05-03 16:14:13 +02:00 committed by Commit Bot
parent a5b903833f
commit 156436056e

View File

@ -309,8 +309,7 @@ RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp8(
// base layer frame. // base layer frame.
if (codec_header.temporalIdx == 0) { if (codec_header.temporalIdx == 0) {
layer_info_it = layer_info_it =
layer_info_ layer_info_.emplace(codec_header.tl0PicIdx, layer_info_it->second)
.insert(make_pair(codec_header.tl0PicIdx, layer_info_it->second))
.first; .first;
frame->num_references = 1; frame->num_references = 1;
frame->references[0] = layer_info_it->second[0]; frame->references[0] = layer_info_it->second[0];
@ -434,42 +433,39 @@ RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp9(
return kHandOff; return kHandOff;
} }
GofInfo* info;
if (codec_header.ss_data_available) { if (codec_header.ss_data_available) {
// Scalability structures can only be sent with tl0 frames.
if (codec_header.temporal_idx != 0) { if (codec_header.temporal_idx != 0) {
RTC_LOG(LS_WARNING) RTC_LOG(LS_WARNING) << "Received scalability structure on a non base "
<< "Received scalability structure on a non base layer" "layer frame. Scalability structure ignored.";
" frame. Scalability structure ignored.";
} else { } else {
current_ss_idx_ = Add<kMaxGofSaved>(current_ss_idx_, 1); current_ss_idx_ = Add<kMaxGofSaved>(current_ss_idx_, 1);
scalability_structures_[current_ss_idx_] = codec_header.gof; scalability_structures_[current_ss_idx_] = codec_header.gof;
scalability_structures_[current_ss_idx_].pid_start = frame->id.picture_id; scalability_structures_[current_ss_idx_].pid_start = frame->id.picture_id;
gof_info_.emplace(codec_header.tl0_pic_idx,
GofInfo info(&scalability_structures_[current_ss_idx_], GofInfo(&scalability_structures_[current_ss_idx_],
frame->id.picture_id); frame->id.picture_id));
gof_info_.insert(std::make_pair(codec_header.tl0_pic_idx, info));
}
} }
// Clean up info for base layers that are too old. const auto gof_info_it = gof_info_.find(codec_header.tl0_pic_idx);
uint8_t old_tl0_pic_idx = codec_header.tl0_pic_idx - kMaxGofSaved; if (gof_info_it == gof_info_.end())
auto clean_gof_info_to = gof_info_.lower_bound(old_tl0_pic_idx); return kStash;
gof_info_.erase(gof_info_.begin(), clean_gof_info_to);
info = &gof_info_it->second;
if (frame->frame_type() == kVideoFrameKey) { if (frame->frame_type() == kVideoFrameKey) {
// When using GOF all keyframes must include the scalability structure.
if (!codec_header.ss_data_available)
RTC_LOG(LS_WARNING) << "Received keyframe without scalability structure";
frame->num_references = 0; frame->num_references = 0;
GofInfo info = gof_info_.find(codec_header.tl0_pic_idx)->second; FrameReceivedVp9(frame->id.picture_id, info);
FrameReceivedVp9(frame->id.picture_id, &info);
UnwrapPictureIds(frame); UnwrapPictureIds(frame);
return kHandOff; return kHandOff;
} }
} else {
if (frame->frame_type() == kVideoFrameKey) {
RTC_LOG(LS_WARNING) << "Received keyframe without scalability structure";
return kDrop;
}
auto gof_info_it = gof_info_.find( auto gof_info_it = gof_info_.find((codec_header.temporal_idx == 0)
(codec_header.temporal_idx == 0 && !codec_header.ss_data_available)
? codec_header.tl0_pic_idx - 1 ? codec_header.tl0_pic_idx - 1
: codec_header.tl0_pic_idx); : codec_header.tl0_pic_idx);
@ -477,7 +473,22 @@ RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp9(
if (gof_info_it == gof_info_.end()) if (gof_info_it == gof_info_.end())
return kStash; return kStash;
GofInfo* info = &gof_info_it->second; if (codec_header.temporal_idx == 0) {
gof_info_it =
gof_info_
.emplace(codec_header.tl0_pic_idx,
GofInfo(gof_info_it->second.gof, frame->id.picture_id))
.first;
}
info = &gof_info_it->second;
}
// Clean up info for base layers that are too old.
uint8_t old_tl0_pic_idx = codec_header.tl0_pic_idx - kMaxGofSaved;
auto clean_gof_info_to = gof_info_.lower_bound(old_tl0_pic_idx);
gof_info_.erase(gof_info_.begin(), clean_gof_info_to);
FrameReceivedVp9(frame->id.picture_id, info); FrameReceivedVp9(frame->id.picture_id, info);
// Make sure we don't miss any frame that could potentially have the // Make sure we don't miss any frame that could potentially have the
@ -485,19 +496,8 @@ RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp9(
if (MissingRequiredFrameVp9(frame->id.picture_id, *info)) if (MissingRequiredFrameVp9(frame->id.picture_id, *info))
return kStash; return kStash;
if (codec_header.temporal_up_switch) { if (codec_header.temporal_up_switch)
auto pid_tidx = up_switch_.emplace(frame->id.picture_id, codec_header.temporal_idx);
std::make_pair(frame->id.picture_id, codec_header.temporal_idx);
up_switch_.insert(pid_tidx);
}
// If this is a base layer frame that contains a scalability structure
// then gof info has already been inserted earlier, so we only want to
// insert if we haven't done so already.
if (codec_header.temporal_idx == 0 && !codec_header.ss_data_available) {
GofInfo new_info(info->gof, frame->id.picture_id);
gof_info_.insert(std::make_pair(codec_header.tl0_pic_idx, new_info));
}
// Clean out old info about up switch frames. // Clean out old info about up switch frames.
uint16_t old_picture_id = Subtract<kPicIdLength>(frame->id.picture_id, 50); uint16_t old_picture_id = Subtract<kPicIdLength>(frame->id.picture_id, 50);