Open3D (C++ API)  0.17.0
RSBagReader.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <atomic>
11 #include <condition_variable>
12 #include <string>
13 #include <thread>
14 #include <unordered_map>
15 #include <vector>
16 
20 
21 // Forward declarations for librealsense classes
22 namespace rs2 {
23 class pipeline;
24 } // namespace rs2
25 
26 namespace open3d {
27 namespace t {
28 namespace io {
29 
48 class RSBagReader : public RGBDVideoReader {
49 public:
50  static const size_t DEFAULT_BUFFER_SIZE = 32;
51 
56  explicit RSBagReader(size_t buffer_size = DEFAULT_BUFFER_SIZE);
57 
58  RSBagReader(const RSBagReader &) = delete;
59  RSBagReader &operator=(const RSBagReader &) = delete;
60  virtual ~RSBagReader();
61 
63  virtual bool IsOpened() const override { return is_opened_; }
64 
66  virtual bool IsEOF() const override;
67 
71  virtual bool Open(const std::string &filename) override;
72 
74  virtual void Close() override;
75 
77  virtual const RGBDVideoMetadata &GetMetadata() const override {
78  return metadata_;
79  }
80 
82  virtual RGBDVideoMetadata &GetMetadata() override { return metadata_; }
83 
87  virtual bool SeekTimestamp(uint64_t timestamp) override;
88 
90  virtual uint64_t GetTimestamp() const override;
91 
93  virtual t::geometry::RGBDImage NextFrame() override;
94 
96  virtual std::string GetFilename() const override { return filename_; };
97 
100 
101 private:
102  std::string filename_;
103  RGBDVideoMetadata metadata_;
104 
105  std::atomic<bool> is_eof_{false}; // Write by frame_reader_thread.
106  std::atomic<bool> is_opened_{false}; // Read by frame_reader_thread.
116  std::vector<t::geometry::RGBDImage> frame_buffer_;
117  std::vector<uint64_t>
118  frame_position_us_;
119  static const size_t BUFFER_REFILL_FACTOR =
120  4;
121  std::atomic<uint64_t> head_fid_{
122  0};
123  std::atomic<uint64_t> tail_fid_{0};
124  std::atomic<uint64_t> seek_to_{UINT64_MAX};
125  std::condition_variable need_frames_;
131  void fill_frame_buffer();
132  std::thread frame_reader_thread_;
133 
134  std::unique_ptr<rs2::pipeline> pipe_;
135 
136  Json::Value GetMetadataJson();
137  std::string GetTagInMetadata(const std::string &tag_name);
138 };
139 } // namespace io
140 } // namespace t
141 } // namespace open3d
RGBDImage A pair of color and depth images.
Definition: RGBDImage.h:21
RGBD video metadata.
Definition: RGBDVideoMetadata.h:26
Definition: RGBDVideoReader.h:18
virtual void SaveFrames(const std::string &frame_path, uint64_t start_time_us=0, uint64_t end_time_us=UINT64_MAX)
Definition: RGBDVideoReader.cpp:33
virtual std::string ToString() const
Text description.
Definition: RGBDVideoReader.cpp:22
Definition: RSBagReader.h:48
virtual bool Open(const std::string &filename) override
Definition: RSBagReader.cpp:41
RSBagReader & operator=(const RSBagReader &)=delete
virtual bool IsEOF() const override
Check if the RSBag file is all read.
Definition: RSBagReader.cpp:164
RSBagReader(size_t buffer_size=DEFAULT_BUFFER_SIZE)
Definition: RSBagReader.cpp:32
static const size_t DEFAULT_BUFFER_SIZE
Definition: RSBagReader.h:50
virtual RGBDVideoMetadata & GetMetadata() override
Get reference to the metadata of the RGBD video playback.
Definition: RSBagReader.h:82
virtual bool IsOpened() const override
Check If the RSBag file is opened.
Definition: RSBagReader.h:63
virtual ~RSBagReader()
Definition: RSBagReader.cpp:37
virtual t::geometry::RGBDImage NextFrame() override
Copy next frame from the bag file and return the RGBDImage object.
Definition: RSBagReader.cpp:166
virtual uint64_t GetTimestamp() const override
Get current timestamp (in us).
Definition: RSBagReader.cpp:208
virtual void Close() override
Close the opened RSBag playback.
Definition: RSBagReader.cpp:74
virtual bool SeekTimestamp(uint64_t timestamp) override
Definition: RSBagReader.cpp:189
virtual std::string GetFilename() const override
Return filename being read.
Definition: RSBagReader.h:96
RSBagReader(const RSBagReader &)=delete
virtual const RGBDVideoMetadata & GetMetadata() const override
Get (read-only) metadata of the playback.
Definition: RSBagReader.h:77
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample uint64_t
Definition: K4aPlugin.cpp:343
Definition: PinholeCameraIntrinsic.cpp:16
Definition: RealSenseSensor.h:17