@@ -77,8 +77,21 @@ RtpVp9RefFinder::FrameDecision RtpVp9RefFinder::ManageFrameInternal(
77
77
}
78
78
79
79
GofInfo* info;
80
- int64_t unwrapped_tl0 =
81
- tl0_unwrapper_.Unwrap (codec_header.tl0_pic_idx & 0xFF );
80
+
81
+ // The VP9 `tl0_pic_idx` is 8 bits and therefor wraps often. In the case of
82
+ // packet loss the next received frame could have a `tl0_pic_idx` that looks
83
+ // older than the previously received frame. Always wrap forward if |frame| is
84
+ // newer in RTP packet sequence number order.
85
+ int64_t unwrapped_tl0;
86
+ auto tl0_it = gof_info_.rbegin ();
87
+ if (tl0_it != gof_info_.rend () &&
88
+ AheadOf (frame->last_seq_num (), tl0_it->second .last_seq_num )) {
89
+ unwrapped_tl0 =
90
+ tl0_unwrapper_.UnwrapForward (codec_header.tl0_pic_idx & 0xFF );
91
+ } else {
92
+ unwrapped_tl0 = tl0_unwrapper_.Unwrap (codec_header.tl0_pic_idx & 0xFF );
93
+ }
94
+
82
95
if (codec_header.ss_data_available ) {
83
96
if (codec_header.temporal_idx != 0 ) {
84
97
RTC_LOG (LS_WARNING) << " Received scalability structure on a non base "
@@ -104,9 +117,9 @@ RtpVp9RefFinder::FrameDecision RtpVp9RefFinder::ManageFrameInternal(
104
117
current_ss_idx_ = Add<kMaxGofSaved >(current_ss_idx_, 1 );
105
118
scalability_structures_[current_ss_idx_] = gof;
106
119
scalability_structures_[current_ss_idx_].pid_start = frame->Id ();
107
- gof_info_.emplace (
108
- unwrapped_tl0 ,
109
- GofInfo (&scalability_structures_[current_ss_idx_] , frame->Id ()));
120
+ gof_info_.emplace (unwrapped_tl0,
121
+ GofInfo (&scalability_structures_[current_ss_idx_] ,
122
+ frame-> Id () , frame->last_seq_num ()));
110
123
}
111
124
112
125
const auto gof_info_it = gof_info_.find (unwrapped_tl0);
@@ -147,7 +160,8 @@ RtpVp9RefFinder::FrameDecision RtpVp9RefFinder::ManageFrameInternal(
147
160
if (codec_header.temporal_idx == 0 ) {
148
161
gof_info_it = gof_info_
149
162
.emplace (unwrapped_tl0,
150
- GofInfo (gof_info_it->second .gof , frame->Id ()))
163
+ GofInfo (gof_info_it->second .gof , frame->Id (),
164
+ frame->last_seq_num ()))
151
165
.first ;
152
166
}
153
167
0 commit comments