MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / buffer_and_order

Function buffer_and_order

rtpose_wrapper/apps/rtpose.cpp:1730–1803  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1728}
1729
1730void* buffer_and_order(void* threadargs) { //only one thread can execute this
1731 FrameCompare comp;
1732 std::priority_queue<Frame, std::vector<Frame>, FrameCompare> buffer(comp);
1733 Frame frame;
1734
1735 int sleep_time = 10 * 1000;
1736
1737 int frame_waited = 1;
1738 while(1) {
1739 ROS_INFO_STREAM_COND(DEBUG > 1, "BFRORDER: Wait");
1740 std::unique_lock<std::mutex> lk(global.output_queue_mated_mutex);
1741 global.output_queue_mated_cond.wait(lk, [](){return
1742 global.output_queue_mated.size() > 0;});
1743 ROS_INFO_STREAM_COND(DEBUG > 1, "BFRORDER: Gooo");
1744 frame = global.output_queue_mated.pop();
1745 if (global.quit_threads or !ros::ok())
1746 break;
1747 frame.buffer_start_time = get_wall_time();
1748 VLOG(4) << "buffer getting " << frame.index << ", waiting for "
1749 << frame_waited;
1750 {
1751 std::lock_guard<std::mutex> lock{global.mutex};
1752
1753 while(global.dropped_index.size()!=0 && global.dropped_index.top() ==
1754 frame_waited and not (global.quit_threads or not ros::ok())) {
1755 frame_waited++;
1756 global.dropped_index.pop();
1757 }
1758 }
1759 //LOG(ERROR) << "while end";
1760
1761 if (frame.index == frame_waited) { // if this is the frame we want,
1762 // just push it
1763 frame.buffer_end_time = get_wall_time();
1764 global.output_queue_ordered.push(frame);
1765 frame_waited++;
1766 while(buffer.size() != 0 && buffer.top().index == frame_waited and not
1767 (global.quit_threads or not ros::ok())) {
1768 Frame next = buffer.top();
1769 buffer.pop();
1770 next.buffer_end_time = get_wall_time();
1771 global.output_queue_ordered.push(next);
1772 frame_waited++;
1773 }
1774 }
1775 else {
1776 buffer.push(frame);
1777 }
1778
1779 if (buffer.size() > BUFFER_SIZE) {
1780 //LOG(ERROR) << "buffer squeezed";
1781 Frame extra = buffer.top();
1782 buffer.pop();
1783 //LOG(ERROR) << "popping " << get<0>(extra);
1784 extra.buffer_end_time = get_wall_time();
1785 global.output_queue_ordered.push(extra);
1786 frame_waited = extra.index + 1;
1787 while(buffer.size() != 0 && buffer.top().index == frame_waited and not

Callers

nothing calls this directly

Calls 4

get_wall_timeFunction · 0.85
popMethod · 0.80
pushMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected