1 /* 2 * Copyright 2019 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #include "logging/rtc_event_log/rtc_event_processor.h" 11 12 namespace webrtc { 13 14 RtcEventProcessor::RtcEventProcessor() = default; 15 16 RtcEventProcessor::~RtcEventProcessor() = default; ProcessEventsInOrder()17void RtcEventProcessor::ProcessEventsInOrder() { 18 // |event_lists_| is a min-heap of lists ordered by the timestamp of the 19 // first element in the list. We therefore process the first element of the 20 // first list, then reinsert the remainder of that list into the heap 21 // if the list still contains unprocessed elements. 22 while (!event_lists_.empty()) { 23 event_lists_.front()->ProcessNext(); 24 std::pop_heap(event_lists_.begin(), event_lists_.end(), Cmp); 25 if (event_lists_.back()->IsEmpty()) { 26 event_lists_.pop_back(); 27 } else { 28 std::push_heap(event_lists_.begin(), event_lists_.end(), Cmp); 29 } 30 } 31 } 32 Cmp(const RtcEventProcessor::ListPtrType & a,const RtcEventProcessor::ListPtrType & b)33bool RtcEventProcessor::Cmp(const RtcEventProcessor::ListPtrType& a, 34 const RtcEventProcessor::ListPtrType& b) { 35 int64_t time_diff = a->GetNextTime() - b->GetNextTime(); 36 if (time_diff == 0) 37 return a->GetTieBreaker() > b->GetTieBreaker(); 38 return time_diff > 0; 39 } 40 41 } // namespace webrtc 42