Last change
on this file since 687 was
639,
checked in by rlacroix, 9 years ago
|
Add a basic garbage collector to ensure no packets linger in the filter graph.
|
File size:
1.3 KB
|
Line | |
---|
1 | #include "input_pin.hpp" |
---|
2 | #include "garbage_collector.hpp" |
---|
3 | #include "exception.hpp" |
---|
4 | |
---|
5 | namespace xios |
---|
6 | { |
---|
7 | CInputPin::CInputPin(CGarbageCollector& gc, size_t slotsCount) |
---|
8 | : gc(gc) |
---|
9 | , slotsCount(slotsCount) |
---|
10 | { /* Nothing to do */ } |
---|
11 | |
---|
12 | void CInputPin::setInput(size_t inputSlot, CDataPacketPtr packet) |
---|
13 | { |
---|
14 | if (inputSlot >= slotsCount) |
---|
15 | ERROR("void CInputPin::setInput(size_t inputSlot, CDataPacketPtr packet)", |
---|
16 | "The input slot " << inputSlot << " does not exist."); |
---|
17 | if (!packet) |
---|
18 | ERROR("void CInputPin::setInput(size_t inputSlot, CDataPacketPtr packet)", |
---|
19 | "The packet cannot be null."); |
---|
20 | |
---|
21 | std::map<Time, InputBuffer>::iterator it = inputs.find(packet->timestamp); |
---|
22 | if (it == inputs.end()) |
---|
23 | { |
---|
24 | it = inputs.insert(std::make_pair(packet->timestamp, InputBuffer(slotsCount))).first; |
---|
25 | gc.registerFilter(this, packet->timestamp); |
---|
26 | } |
---|
27 | it->second.slotsFilled++; |
---|
28 | it->second.packets[inputSlot] = packet; |
---|
29 | |
---|
30 | if (it->second.slotsFilled == slotsCount) |
---|
31 | { |
---|
32 | // Unregister before calling onInputReady in case the filter registers again |
---|
33 | gc.unregisterFilter(this, packet->timestamp); |
---|
34 | onInputReady(it->second.packets); |
---|
35 | inputs.erase(it); |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | void CInputPin::invalidate(Time timestamp) |
---|
40 | { |
---|
41 | inputs.erase(inputs.begin(), inputs.lower_bound(timestamp)); |
---|
42 | } |
---|
43 | } // namespace xios |
---|
Note: See
TracBrowser
for help on using the repository browser.