Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: webrtc/modules/video_coding/rtp_frame_reference_finder.cc

Issue 2304723004: Added ClearTo(seq_num) to RtpFrameReferenceFinder. (Closed)
Patch Set: Added comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/video_coding/rtp_frame_reference_finder.h" 11 #include "webrtc/modules/video_coding/rtp_frame_reference_finder.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <limits> 14 #include <limits>
15 15
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
18 #include "webrtc/modules/video_coding/frame_object.h" 18 #include "webrtc/modules/video_coding/frame_object.h"
19 #include "webrtc/modules/video_coding/packet_buffer.h" 19 #include "webrtc/modules/video_coding/packet_buffer.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 namespace video_coding { 22 namespace video_coding {
23 23
24 RtpFrameReferenceFinder::RtpFrameReferenceFinder( 24 RtpFrameReferenceFinder::RtpFrameReferenceFinder(
25 OnCompleteFrameCallback* frame_callback) 25 OnCompleteFrameCallback* frame_callback)
26 : last_picture_id_(-1), 26 : last_picture_id_(-1),
27 last_unwrap_(-1), 27 last_unwrap_(-1),
28 current_ss_idx_(0), 28 current_ss_idx_(0),
29 cleared_to_seq_num_(-1),
29 frame_callback_(frame_callback) {} 30 frame_callback_(frame_callback) {}
30 31
31 void RtpFrameReferenceFinder::ManageFrame( 32 void RtpFrameReferenceFinder::ManageFrame(
32 std::unique_ptr<RtpFrameObject> frame) { 33 std::unique_ptr<RtpFrameObject> frame) {
33 rtc::CritScope lock(&crit_); 34 rtc::CritScope lock(&crit_);
35
36 // If we have cleared past this frame, drop it.
37 if (cleared_to_seq_num_ != -1 &&
38 AheadOf<uint16_t>(cleared_to_seq_num_, frame->first_seq_num())) {
39 return;
40 }
41
34 switch (frame->codec_type()) { 42 switch (frame->codec_type()) {
35 case kVideoCodecULPFEC: 43 case kVideoCodecULPFEC:
36 case kVideoCodecRED: 44 case kVideoCodecRED:
37 case kVideoCodecUnknown: 45 case kVideoCodecUnknown:
38 RTC_NOTREACHED(); 46 RTC_NOTREACHED();
39 break; 47 break;
40 case kVideoCodecVP8: 48 case kVideoCodecVP8:
41 ManageFrameVp8(std::move(frame)); 49 ManageFrameVp8(std::move(frame));
42 break; 50 break;
43 case kVideoCodecVP9: 51 case kVideoCodecVP9:
(...skipping 10 matching lines...) Expand all
54 void RtpFrameReferenceFinder::PaddingReceived(uint16_t seq_num) { 62 void RtpFrameReferenceFinder::PaddingReceived(uint16_t seq_num) {
55 rtc::CritScope lock(&crit_); 63 rtc::CritScope lock(&crit_);
56 auto clean_padding_to = 64 auto clean_padding_to =
57 stashed_padding_.lower_bound(seq_num - kMaxPaddingAge); 65 stashed_padding_.lower_bound(seq_num - kMaxPaddingAge);
58 stashed_padding_.erase(stashed_padding_.begin(), clean_padding_to); 66 stashed_padding_.erase(stashed_padding_.begin(), clean_padding_to);
59 stashed_padding_.insert(seq_num); 67 stashed_padding_.insert(seq_num);
60 UpdateLastPictureIdWithPadding(seq_num); 68 UpdateLastPictureIdWithPadding(seq_num);
61 RetryStashedFrames(); 69 RetryStashedFrames();
62 } 70 }
63 71
72 void RtpFrameReferenceFinder::ClearTo(uint16_t seq_num) {
73 rtc::CritScope lock(&crit_);
74 cleared_to_seq_num_ = seq_num;
75 size_t num_stashed_frames = stashed_frames_.size();
76
77 for (size_t i = 0; i < num_stashed_frames; ++i) {
stefan-webrtc 2016/09/07 13:29:57 Isn't it simpler to write this: while (AheadOf<ui
philipel 2016/09/08 11:27:19 Frames might be inserted out of order, so we don't
stefan-webrtc 2016/09/08 11:51:30 Ok, but what about: for (it = stashed_frames_.beg
philipel 2016/09/08 12:16:03 Changed to deque
78 std::unique_ptr<RtpFrameObject> frame = std::move(stashed_frames_.front());
79 stashed_frames_.pop();
80
81 if (AheadOf<uint16_t>(cleared_to_seq_num_, frame->first_seq_num()))
82 continue;
83
84 stashed_frames_.emplace(std::move(frame));
85 }
86 }
87
64 void RtpFrameReferenceFinder::UpdateLastPictureIdWithPadding(uint16_t seq_num) { 88 void RtpFrameReferenceFinder::UpdateLastPictureIdWithPadding(uint16_t seq_num) {
65 auto gop_seq_num_it = last_seq_num_gop_.upper_bound(seq_num); 89 auto gop_seq_num_it = last_seq_num_gop_.upper_bound(seq_num);
66 90
67 // If this padding packet "belongs" to a group of pictures that we don't track 91 // If this padding packet "belongs" to a group of pictures that we don't track
68 // anymore, do nothing. 92 // anymore, do nothing.
69 if (gop_seq_num_it == last_seq_num_gop_.begin()) 93 if (gop_seq_num_it == last_seq_num_gop_.begin())
70 return; 94 return;
71 --gop_seq_num_it; 95 --gop_seq_num_it;
72 96
73 // Calculate the next contiuous sequence number and search for it in 97 // Calculate the next contiuous sequence number and search for it in
(...skipping 16 matching lines...) Expand all
90 void RtpFrameReferenceFinder::RetryStashedFrames() { 114 void RtpFrameReferenceFinder::RetryStashedFrames() {
91 size_t num_stashed_frames = stashed_frames_.size(); 115 size_t num_stashed_frames = stashed_frames_.size();
92 116
93 // Clean up stashed frames if there are too many. 117 // Clean up stashed frames if there are too many.
94 while (stashed_frames_.size() > kMaxStashedFrames) 118 while (stashed_frames_.size() > kMaxStashedFrames)
95 stashed_frames_.pop(); 119 stashed_frames_.pop();
96 120
97 // Since frames are stashed if there is not enough data to determine their 121 // Since frames are stashed if there is not enough data to determine their
98 // frame references we should at most check |stashed_frames_.size()| in 122 // frame references we should at most check |stashed_frames_.size()| in
99 // order to not pop and push frames in and endless loop. 123 // order to not pop and push frames in and endless loop.
124 // NOTE! This function may be called recursively, hence the
125 // "!stashed_frames_.empty()" condition.
100 for (size_t i = 0; i < num_stashed_frames && !stashed_frames_.empty(); ++i) { 126 for (size_t i = 0; i < num_stashed_frames && !stashed_frames_.empty(); ++i) {
101 std::unique_ptr<RtpFrameObject> frame = std::move(stashed_frames_.front()); 127 std::unique_ptr<RtpFrameObject> frame = std::move(stashed_frames_.front());
102 stashed_frames_.pop(); 128 stashed_frames_.pop();
103 ManageFrame(std::move(frame)); 129 ManageFrame(std::move(frame));
104 } 130 }
105 } 131 }
106 132
107 void RtpFrameReferenceFinder::ManageFrameGeneric( 133 void RtpFrameReferenceFinder::ManageFrameGeneric(
108 std::unique_ptr<RtpFrameObject> frame, 134 std::unique_ptr<RtpFrameObject> frame,
109 int picture_id) { 135 int picture_id) {
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 if (AheadOf<uint16_t, kPicIdLength>(picture_id, unwrap_truncated)) 566 if (AheadOf<uint16_t, kPicIdLength>(picture_id, unwrap_truncated))
541 last_unwrap_ = Add<1 << 16>(last_unwrap_, diff); 567 last_unwrap_ = Add<1 << 16>(last_unwrap_, diff);
542 else 568 else
543 last_unwrap_ = Subtract<1 << 16>(last_unwrap_, diff); 569 last_unwrap_ = Subtract<1 << 16>(last_unwrap_, diff);
544 570
545 return last_unwrap_; 571 return last_unwrap_;
546 } 572 }
547 573
548 } // namespace video_coding 574 } // namespace video_coding
549 } // namespace webrtc 575 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698