| 1549 | } |
| 1550 | |
| 1551 | void Freenect2ReplayDevice::run() |
| 1552 | { |
| 1553 | size_t timestamp_sequence[2] = {0}; |
| 1554 | |
| 1555 | for (size_t i = 0; i < frame_filenames_.size() && running_; i++) |
| 1556 | { |
| 1557 | std::string frame = frame_filenames_[i]; |
| 1558 | |
| 1559 | if(parseFrameFilename(frame, timestamp_sequence) == false) |
| 1560 | { |
| 1561 | LOG_ERROR << "could not parse replay frame filename " << frame << ", skipping..."; |
| 1562 | continue; |
| 1563 | } |
| 1564 | |
| 1565 | if (hasSuffix(frame, ".depth")) |
| 1566 | { |
| 1567 | std::ifstream fd(frame.c_str()); |
| 1568 | |
| 1569 | if(!fd) |
| 1570 | { |
| 1571 | LOG_ERROR << "failed to open replay frame: " << frame << ", skipping..."; |
| 1572 | continue; |
| 1573 | } |
| 1574 | |
| 1575 | fd.seekg(0, fd.end); |
| 1576 | size_t length = fd.tellg(); |
| 1577 | fd.seekg(0, fd.beg); |
| 1578 | |
| 1579 | if(length != buffer_size_) |
| 1580 | { |
| 1581 | LOG_ERROR << "file length: " << length |
| 1582 | << "exceeds depth image buffer size: " |
| 1583 | << buffer_size_ << "; skipping..."; |
| 1584 | continue; |
| 1585 | } |
| 1586 | |
| 1587 | fd.read(reinterpret_cast<char*>(packet_.memory->data), length); |
| 1588 | if(!fd || (size_t)fd.gcount() != length) |
| 1589 | { |
| 1590 | LOG_ERROR << "failed to read replay frame: " << frame << ": " |
| 1591 | << fd.gcount() << " vs. " << length << " bytes"; |
| 1592 | continue; |
| 1593 | } |
| 1594 | |
| 1595 | if(pipeline_->getDepthPacketProcessor()->ready()) |
| 1596 | { |
| 1597 | packet_.timestamp = timestamp_sequence[0]; |
| 1598 | packet_.sequence = timestamp_sequence[1]; |
| 1599 | packet_.buffer = packet_.memory->data; |
| 1600 | packet_.buffer_length = length; |
| 1601 | |
| 1602 | pipeline_->getDepthPacketProcessor()->process(packet_); |
| 1603 | pipeline_->getDepthPacketProcessor()->allocateBuffer(packet_, buffer_size_); |
| 1604 | } |
| 1605 | else |
| 1606 | { |
| 1607 | LOG_DEBUG |
| 1608 | << "skipping a replay depth packet for " << frame |
no test coverage detected