You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					65 lines
				
				2.0 KiB
			
		
		
			
		
	
	
					65 lines
				
				2.0 KiB
			| 
								 
											5 years ago
										 
									 | 
							
								#pragma once
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#if __has_include(<memory_resource>)
							 | 
						||
| 
								 | 
							
								#define HAS_MEMORY_RESOURCE 1
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#include <memory_resource>
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#endif
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#include "cereal/gen/cpp/log.capnp.h"
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								#include "system/camerad/cameras/camera_common.h"
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								#include "tools/replay/filereader.h"
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								const CameraType ALL_CAMERAS[] = {RoadCam, DriverCam, WideRoadCam};
							 | 
						||
| 
								 | 
							
								const int MAX_CAMERAS = std::size(ALL_CAMERAS);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								const int DEFAULT_EVENT_MEMORY_POOL_BLOCK_SIZE = 65000;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								class Event {
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								public:
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  Event(cereal::Event::Which which, uint64_t mono_time) : reader(kj::ArrayPtr<capnp::word>{}) {
							 | 
						||
| 
								 | 
							
								    // construct a dummy Event for binary search, e.g std::upper_bound
							 | 
						||
| 
								 | 
							
								    this->which = which;
							 | 
						||
| 
								 | 
							
								    this->mono_time = mono_time;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  Event(const kj::ArrayPtr<const capnp::word> &amsg, bool frame = false);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  inline kj::ArrayPtr<const capnp::byte> bytes() const { return words.asBytes(); }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  struct lessThan {
							 | 
						||
| 
								 | 
							
								    inline bool operator()(const Event *l, const Event *r) {
							 | 
						||
| 
								 | 
							
								      return l->mono_time < r->mono_time || (l->mono_time == r->mono_time && l->which < r->which);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#if HAS_MEMORY_RESOURCE
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  void *operator new(size_t size, std::pmr::monotonic_buffer_resource *mbr) {
							 | 
						||
| 
								 | 
							
								    return mbr->allocate(size);
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  void operator delete(void *ptr) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    // No-op. memory used by EventMemoryPool increases monotonically until the logReader is destroyed.
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#endif
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  uint64_t mono_time;
							 | 
						||
| 
								 | 
							
								  cereal::Event::Which which;
							 | 
						||
| 
								 | 
							
								  cereal::Event::Reader event;
							 | 
						||
| 
								 | 
							
								  capnp::FlatArrayMessageReader reader;
							 | 
						||
| 
								 | 
							
								  kj::ArrayPtr<const capnp::word> words;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  bool frame;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								class LogReader {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								public:
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  LogReader(size_t memory_pool_block_size = DEFAULT_EVENT_MEMORY_POOL_BLOCK_SIZE);
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  ~LogReader();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  bool load(const std::string &url, std::atomic<bool> *abort = nullptr, bool local_cache = false, int chunk_size = -1, int retries = 0);
							 | 
						||
| 
								 | 
							
								  bool load(const std::byte *data, size_t size, std::atomic<bool> *abort = nullptr);
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  std::vector<Event*> events;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								private:
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  std::string raw_;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#ifdef HAS_MEMORY_RESOURCE
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  std::pmr::monotonic_buffer_resource *mbr_ = nullptr;
							 | 
						||
| 
								 | 
							
								  void *pool_buffer_ = nullptr;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#endif
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								};
							 |