Last change
on this file since 827 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
|
Rev | Line | |
---|
[637] | 1 | #include "input_pin.hpp" |
---|
[639] | 2 | #include "garbage_collector.hpp" |
---|
[637] | 3 | #include "exception.hpp" |
---|
| 4 | |
---|
| 5 | namespace xios |
---|
| 6 | { |
---|
[639] | 7 | CInputPin::CInputPin(CGarbageCollector& gc, size_t slotsCount) |
---|
| 8 | : gc(gc) |
---|
| 9 | , slotsCount(slotsCount) |
---|
[637] | 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()) |
---|
[639] | 23 | { |
---|
[637] | 24 | it = inputs.insert(std::make_pair(packet->timestamp, InputBuffer(slotsCount))).first; |
---|
[639] | 25 | gc.registerFilter(this, packet->timestamp); |
---|
| 26 | } |
---|
[637] | 27 | it->second.slotsFilled++; |
---|
| 28 | it->second.packets[inputSlot] = packet; |
---|
| 29 | |
---|
| 30 | if (it->second.slotsFilled == slotsCount) |
---|
| 31 | { |
---|
[639] | 32 | // Unregister before calling onInputReady in case the filter registers again |
---|
| 33 | gc.unregisterFilter(this, packet->timestamp); |
---|
[637] | 34 | onInputReady(it->second.packets); |
---|
| 35 | inputs.erase(it); |
---|
| 36 | } |
---|
| 37 | } |
---|
[639] | 38 | |
---|
| 39 | void CInputPin::invalidate(Time timestamp) |
---|
| 40 | { |
---|
| 41 | inputs.erase(inputs.begin(), inputs.lower_bound(timestamp)); |
---|
| 42 | } |
---|
[637] | 43 | } // namespace xios |
---|
Note: See
TracBrowser
for help on using the repository browser.