Skip to content

Commit 9666e7a

Browse files
committed
Simplify and clean-up code
1 parent 4c7c448 commit 9666e7a

File tree

3 files changed

+12
-251
lines changed

3 files changed

+12
-251
lines changed

src/FramePlayer.cpp

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
#include "FramePlayer.h"
1919
#include "utils.h"
2020

21+
#include <vrs/DataLayout.h>
22+
#include <vrs/utils/PixelFrame.h>
2123
#include <iostream>
24+
#include <memory>
2225
#include <sstream>
2326

24-
#include <vrs/IndexRecord.h>
25-
2627
namespace rerun_vrs {
2728
struct FrameNumberDataLayout : public vrs::AutoDataLayout {
2829
vrs::DataPieceValue<uint64_t> frameNumber{"frame_number"};
@@ -52,7 +53,6 @@ namespace rerun_vrs {
5253
(entityPath_ + "/configuration").c_str(),
5354
rerun::TextDocument(layout_str)
5455
);
55-
return false;
5656
}
5757

5858
if (record.recordType == vrs::Record::Type::DATA) {
@@ -65,7 +65,7 @@ namespace rerun_vrs {
6565
rec_.log((entityPath_ + "/data").c_str(), rerun::TextDocument(layout_str));
6666
}
6767

68-
return true; // read next blocks, if any
68+
return true;
6969
}
7070

7171
bool RerunFramePlayer::onImageRead(
@@ -95,69 +95,6 @@ namespace rerun_vrs {
9595
<< std::endl;
9696
enabled_ = false;
9797
}
98-
return true; // read next blocks, if any
99-
}
100-
101-
void RerunFramePlayer::convertFrame(std::shared_ptr<vrs::utils::PixelFrame>& frame) {
102-
/* if (blankMode_) { */
103-
/* makeBlankFrame(frame); */
104-
/* } else { */
105-
/* std::shared_ptr<vrs::utils::PixelFrame> convertedFrame = */
106-
/* needsConvertedFrame_ ? getFrame(false) : nullptr; */
107-
/* vrs::utils::PixelFrame::normalizeFrame(frame, convertedFrame, false); */
108-
/* needsConvertedFrame_ = (frame != convertedFrame); // for next time! */
109-
/* if (needsConvertedFrame_) { */
110-
/* recycle(frame, true); */
111-
/* frame = std::move(convertedFrame); */
112-
/* } */
113-
/* } */
98+
return true;
11499
}
115-
116-
void RerunFramePlayer::makeBlankFrame(std::shared_ptr<vrs::utils::PixelFrame>& frame) {
117-
frame->init(vrs::PixelFormat::GREY8, frame->getWidth(), frame->getHeight());
118-
frame->blankFrame();
119-
}
120-
121-
void RerunFramePlayer::recycle(
122-
std::shared_ptr<vrs::utils::PixelFrame>& frame, bool inputNotConvertedFrame
123-
) {
124-
/* if (frame) { */
125-
/* { */
126-
/* std::vector<std::shared_ptr<vrs::utils::PixelFrame>>& frames = */
127-
/* inputNotConvertedFrame ? inputFrames_ : convertedframes_; */
128-
/* if (frames.size() < 10) { */
129-
/* frames.emplace_back(std::move(frame)); */
130-
/* } */
131-
/* } */
132-
/* frame.reset(); */
133-
/* } */
134-
}
135-
136-
void RerunFramePlayer::imageJobsThreadActivity() {
137-
std::unique_ptr<ImageJob> job;
138-
while (imageJobs_.waitForJob(job)) {
139-
std::shared_ptr<vrs::utils::PixelFrame> frame = std::move(job->frame);
140-
// if we're behind, we just drop images except the last one!
141-
while (imageJobs_.getJob(job)) {
142-
recycle(frame, true);
143-
frame = std::move(job->frame);
144-
}
145-
bool frameValid = false;
146-
if (job->imageFormat == vrs::ImageFormat::RAW ||
147-
job->imageFormat == vrs::ImageFormat::VIDEO) {
148-
frameValid = (frame != nullptr);
149-
} else {
150-
if (!frame) {
151-
frame = std::make_shared<vrs::utils::PixelFrame>();
152-
}
153-
frameValid = frame->readCompressedFrame(job->buffer, job->imageFormat);
154-
}
155-
if (frameValid) {
156-
convertFrame(frame);
157-
/* widget_->swapImage(frame); */
158-
}
159-
recycle(frame, !frameValid || !needsConvertedFrame_);
160-
}
161-
}
162-
163100
} // namespace rerun_vrs

src/FramePlayer.h

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,64 +17,28 @@
1717

1818
#pragma once
1919

20-
#include <memory>
21-
22-
#include <vrs/helpers/JobQueue.h>
20+
#include <vrs/DataLayout.h>
2321
#include <vrs/RecordFormat.h>
24-
#include <vrs/utils/PixelFrame.h>
25-
#include <vrs/utils/VideoFrameHandler.h>
22+
#include <vrs/StreamId.h>
23+
#include <vrs/StreamPlayer.h>
2624
#include <vrs/utils/VideoRecordFormatStreamPlayer.h>
2725
#include <rerun.hpp>
2826

29-
/* #include "MetaDataCollector.h" */
30-
31-
enum class FileReaderState;
32-
3327
namespace rerun_vrs {
34-
35-
struct ImageJob {
36-
ImageJob(vrs::ImageFormat imageFormat) : imageFormat{imageFormat} {}
37-
38-
vrs::ImageFormat imageFormat;
39-
std::shared_ptr<vrs::utils::PixelFrame> frame;
40-
std::vector<uint8_t> buffer;
41-
};
42-
4328
class RerunFramePlayer : public vrs::utils::VideoRecordFormatStreamPlayer {
4429
public:
4530
explicit RerunFramePlayer(vrs::StreamId id, rerun::RecordingStream& rec);
4631

47-
bool onDataLayoutRead(const vrs::CurrentRecord& r, size_t blockIndex, vrs::DataLayout&) override;
48-
bool onImageRead(const vrs::CurrentRecord& r, size_t blockIndex, const vrs::ContentBlock&) override;
49-
50-
vrs::StreamId getId() const {
51-
return id_;
52-
}
53-
54-
void setEstimatedFps(int estimatedFps) {
55-
estimatedFps_ = estimatedFps;
56-
}
57-
58-
void imageJobsThreadActivity();
32+
bool onDataLayoutRead(const vrs::CurrentRecord& r, size_t blockIndex, vrs::DataLayout&)
33+
override;
34+
bool onImageRead(const vrs::CurrentRecord& r, size_t blockIndex, const vrs::ContentBlock&)
35+
override;
5936

6037
private:
6138
rerun::RecordingStream& rec_;
62-
bool needsConvertedFrame_{false};
6339
vrs::StreamId id_;
6440
std::string entityPath_;
65-
/* MetaDataCollector descriptions_; */
66-
bool blankMode_{true};
6741
bool enabled_{true};
68-
bool firstImage_{true};
69-
int estimatedFps_;
70-
/* Fps dataFps_; */
71-
FileReaderState state_{};
72-
73-
vrs::JobQueueWithThread<std::unique_ptr<ImageJob>> imageJobs_;
74-
75-
void convertFrame(std::shared_ptr<vrs::utils::PixelFrame>& frame);
76-
void makeBlankFrame(std::shared_ptr<vrs::utils::PixelFrame>& frame);
77-
void recycle(std::shared_ptr<vrs::utils::PixelFrame>& frame, bool inputNotConvertedFrame);
7842
};
7943

8044
} // namespace rerun_vrs

src/main.cpp

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -48,143 +48,3 @@ int main(int argc, const char* argv[]) {
4848

4949
return 0;
5050
}
51-
52-
/* template <> */
53-
/* struct rerun::ComponentBatchAdapter<rerun::components::Position3D,
54-
* std::vector<Eigen::Vector3f>> { */
55-
/* // Sanity check that this is binary compatible. */
56-
/* static_assert(sizeof(components::Position3D) == sizeof(Eigen::Vector3f));
57-
*/
58-
/* static_assert(alignof(components::Position3D) <=
59-
* alignof(Eigen::Vector3f)); */
60-
61-
/* ComponentBatch<components::Position3D> operator()(const
62-
* std::vector<Eigen::Vector3f> &container */
63-
/* ) { */
64-
/* return ComponentBatch<components::Position3D>::borrow( */
65-
/* reinterpret_cast<const components::Position3D
66-
* *>(container.data()), */
67-
/* container.size() */
68-
/* ); */
69-
/* } */
70-
71-
/* ComponentBatch<components::Position3D>
72-
* operator()(std::vector<Eigen::Vector3f> &&container) { */
73-
/* throw std::runtime_error("Not implemented for temporaries"); */
74-
/* } */
75-
/* }; */
76-
77-
/* template <> */
78-
/* struct rerun::ComponentBatchAdapter<rerun::components::Position3D,
79-
* Eigen::MatrixX3f> { */
80-
/* // Sanity check that this is binary compatible. */
81-
/* static_assert( */
82-
/* sizeof(components::Position3D) == */
83-
/* sizeof(Eigen::MatrixX3f::Scalar) *
84-
* Eigen::MatrixX3f::ColsAtCompileTime */
85-
/* ); */
86-
/* static_assert(alignof(components::Position3D) <=
87-
* alignof(Eigen::MatrixX3f)); */
88-
89-
/* ComponentBatch<components::Position3D> operator()(const Eigen::MatrixX3f
90-
* &matrix) { */
91-
/* return ComponentBatch<components::Position3D>::borrow( */
92-
/* reinterpret_cast<const components::Position3D *>(matrix.data()),
93-
*/
94-
/* matrix.rows() */
95-
/* ); */
96-
/* } */
97-
98-
/* ComponentBatch<components::Position3D>
99-
* operator()(std::vector<Eigen::MatrixX3f> &&container) { */
100-
/* throw std::runtime_error("Not implemented for temporaries"); */
101-
/* } */
102-
/* }; */
103-
104-
/* std::vector<Eigen::Vector3f> generate_random_points_vector(int num_points) {
105-
*/
106-
/* std::vector<Eigen::Vector3f> points(num_points); */
107-
/* for (auto &point : points) { */
108-
/* point.setRandom(); */
109-
/* } */
110-
/* return points; */
111-
/* } */
112-
113-
/* int main() { */
114-
/* auto rec = rerun::RecordingStream("rerun_cpp_example_opencv_eigen"); */
115-
/* rec.connect("127.0.0.1:9876").throw_on_failure(); */
116-
117-
/* const int num_points = 1000; */
118-
119-
/* // Points represented by std::vector<Eigen::Vector3f> */
120-
/* auto points3d_vector = generate_random_points_vector(1000); */
121-
/* rec.log("world/points_from_vector", rerun::Points3D(points3d_vector)); */
122-
123-
/* // Points represented by Eigen::MatX3f (Nx3 matrix) */
124-
/* Eigen::MatrixX3f points3d_matrix = Eigen::MatrixX3f::Random(num_points,
125-
* 3); */
126-
/* rec.log("world/points_from_matrix", rerun::Points3D(points3d_matrix)); */
127-
128-
/* // Posed pinhole camera */
129-
/* float width = 640.0f; */
130-
/* float height = 480.0f; */
131-
/* Eigen::Matrix3f projection_matrix = Eigen::Matrix3f::Identity(); */
132-
/* projection_matrix(0, 0) = 500.0f; */
133-
/* projection_matrix(1, 1) = 500.0f; */
134-
/* projection_matrix(0, 2) = (width - 1) / 2.0; */
135-
/* projection_matrix(1, 2) = (height - 1) / 2.0; */
136-
/* rec.log( */
137-
/* "world/camera", */
138-
/* rerun::Pinhole(rerun::components::PinholeProjection( */
139-
/* *reinterpret_cast<float(*)[9]>(projection_matrix.data())
140-
*/
141-
/* )) */
142-
/* .with_resolution(rerun::components::Resolution({width, height}))
143-
*/
144-
/* ); */
145-
/* Eigen::Vector3f camera_position{0.0, -1.0, 0.0}; */
146-
/* Eigen::Matrix3f camera_orientation; */
147-
/* // clang-format off */
148-
/* camera_orientation << */
149-
/* 0.0, 1.0, 0.0, */
150-
/* 0.0, 0.0, 1.0, */
151-
/* 1.0, 0.0, 0.0; */
152-
/* // clang-format on */
153-
/* rec.log( */
154-
/* "world/camera", */
155-
/* rerun::Transform3D( */
156-
/* rerun::datatypes::Vec3D(*reinterpret_cast<float(*)[3]>(camera_position.data())),
157-
*/
158-
/* rerun::datatypes::Mat3x3(*reinterpret_cast<float(*)[9]>(camera_orientation.data()))
159-
*/
160-
/* ) */
161-
/* ); */
162-
163-
/* // Read image */
164-
/* std::string image_path = "rerun-logo.png"; */
165-
/* cv::Mat img = imread(image_path, cv::IMREAD_COLOR); */
166-
/* if (img.empty()) { */
167-
/* std::cout << "Could not read the image: " << image_path << std::endl;
168-
*/
169-
/* return 1; */
170-
/* } */
171-
172-
/* // Log image to Rerun */
173-
/* cv::cvtColor(img, img, cv::COLOR_BGR2RGB); // Rerun expects RGB format */
174-
/* // NOTE currently we need to construct a vector to log an image, this
175-
* will change in the future */
176-
/* // see https://github.com/rerun-io/rerun/issues/3794 */
177-
/* std::vector<uint8_t> img_vec(img.total() * img.channels()); */
178-
/* img_vec.assign(img.data, img.data + img.total() * img.channels()); */
179-
/* rec.log( */
180-
/* "image", */
181-
/* rerun::Image( */
182-
/* {static_cast<size_t>(img.rows), */
183-
/* static_cast<size_t>(img.cols), */
184-
/* static_cast<size_t>(img.channels())}, */
185-
/* std::move(img_vec) */
186-
/* ) */
187-
/* ); */
188-
189-
/* return 0; */
190-
/* } */

0 commit comments

Comments
 (0)