1 #pragma once 2 3 #include <iostream> 4 #include <pangolin/platform.h> 5 #include <pangolin/utils/picojson.h> 6 7 namespace pangolin { 8 9 using PacketStreamSourceId = size_t; 10 11 struct PANGOLIN_EXPORT PacketStreamSource 12 { 13 struct PacketInfo 14 { 15 std::streampos pos; 16 int64_t capture_time; 17 }; 18 PacketStreamSourcePacketStreamSource19 PacketStreamSource() 20 : id(static_cast<PacketStreamSourceId>(-1)), 21 version(0), 22 data_alignment_bytes(1), 23 data_size_bytes(0), 24 next_packet_id(0) 25 { 26 } 27 FindSeekLocationPacketStreamSource28 std::streampos FindSeekLocation(size_t packet_id) 29 { 30 if(packet_id < index.size()) { 31 return index[packet_id].pos; 32 }else{ 33 return std::streampos(-1); 34 } 35 36 } 37 NextPacketTimePacketStreamSource38 int64_t NextPacketTime() const 39 { 40 if(next_packet_id < index.size()) { 41 return index[next_packet_id].capture_time; 42 }else{ 43 return 0; 44 } 45 } 46 47 std::string driver; 48 size_t id; 49 std::string uri; 50 picojson::value info; 51 int64_t version; 52 int64_t data_alignment_bytes; 53 std::string data_definitions; 54 int64_t data_size_bytes; 55 56 // Index keyed by packet_id 57 std::vector<PacketInfo> index; 58 59 // Based on current position in stream 60 size_t next_packet_id; 61 }; 62 63 } 64