Skip to content
Snippets Groups Projects
Commit f48473ae authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Add an ftl file player

parent 3d1abcb3
No related branches found
No related tags found
1 merge request!127Implements #196 stream capturing
Pipeline #15274 failed
...@@ -220,6 +220,7 @@ add_subdirectory(components/rgbd-sources) ...@@ -220,6 +220,7 @@ add_subdirectory(components/rgbd-sources)
add_subdirectory(components/control/cpp) add_subdirectory(components/control/cpp)
add_subdirectory(applications/calibration) add_subdirectory(applications/calibration)
add_subdirectory(applications/groupview) add_subdirectory(applications/groupview)
add_subdirectory(applications/player)
if (BUILD_RENDERER) if (BUILD_RENDERER)
add_subdirectory(components/renderers) add_subdirectory(components/renderers)
......
set(PLAYERSRC
src/main.cpp
)
add_executable(ftl-player ${PLAYERSRC})
target_include_directories(ftl-player PRIVATE src)
target_link_libraries(ftl-player ftlcommon ftlcodecs ftlrgbd Threads::Threads ${OpenCV_LIBS})
#include <loguru.hpp>
#include <ftl/configuration.hpp>
#include <ftl/codecs/reader.hpp>
#include <ftl/codecs/decoder.hpp>
#include <ftl/codecs/packet.hpp>
#include <fstream>
static ftl::codecs::Decoder *decoder;
static void createDecoder(const ftl::codecs::Packet &pkt) {
if (decoder) {
if (!decoder->accepts(pkt)) {
ftl::codecs::free(decoder);
} else {
return;
}
}
decoder = ftl::codecs::allocateDecoder(pkt);
}
int main(int argc, char **argv) {
std::string filename(argv[1]);
LOG(INFO) << "Playing: " << filename;
auto root = ftl::configure(argc, argv, "player_default");
std::ifstream f;
f.open(filename);
if (!f.is_open()) LOG(ERROR) << "Could not open file";
ftl::codecs::Reader r(f);
if (!r.begin()) LOG(ERROR) << "Bad ftl file";
LOG(INFO) << "Playing...";
bool res = r.read(90000000000000, [](const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt) {
if (spkt.channel & 0x1 > 0) return;
LOG(INFO) << "Reading packet: (" << (int)spkt.streamID << "," << (int)spkt.channel << ") " << (int)pkt.codec << ", " << (int)pkt.definition;
cv::Mat frame(cv::Size(ftl::codecs::getWidth(pkt.definition),ftl::codecs::getHeight(pkt.definition)), CV_8UC3);
createDecoder(pkt);
try {
decoder->decode(pkt, frame);
} catch (std::exception &e) {
LOG(INFO) << "Decoder exception: " << e.what();
}
if (!frame.empty()) {
cv::imshow("Player", frame);
cv::waitKey(20);
}
});
if (!res) LOG(ERROR) << "No frames left";
r.end();
ftl::running = false;
return 0;
}
#include <loguru.hpp>
#include <ftl/codecs/reader.hpp> #include <ftl/codecs/reader.hpp>
#include <tuple> #include <tuple>
...@@ -30,19 +31,26 @@ bool Reader::read(int64_t ts, const std::function<void(const ftl::codecs::Stream ...@@ -30,19 +31,26 @@ bool Reader::read(int64_t ts, const std::function<void(const ftl::codecs::Stream
return false; return false;
} }
bool partial = false;
while (stream_->good() || buffer_.nonparsed_size() > 0) { while (stream_->good() || buffer_.nonparsed_size() > 0) {
if (buffer_.nonparsed_size() == 0) { if (buffer_.nonparsed_size() == 0 || partial) {
buffer_.reserve_buffer(100000); buffer_.reserve_buffer(10000000);
stream_->read(buffer_.buffer(), 100000); stream_->read(buffer_.buffer(), 10000000);
//if (stream_->bad()) return false; //if (stream_->bad()) return false;
int bytes = stream_->gcount(); int bytes = stream_->gcount();
if (bytes == 0) return false; if (bytes == 0) return false;
buffer_.buffer_consumed(bytes); buffer_.buffer_consumed(bytes);
partial = false;
} }
msgpack::object_handle msg; msgpack::object_handle msg;
if (!buffer_.next(msg)) continue; if (!buffer_.next(msg)) {
LOG(INFO) << "NO Message: " << buffer_.nonparsed_size();
partial = true;
continue;
}
std::tuple<StreamPacket,Packet> data; std::tuple<StreamPacket,Packet> data;
msgpack::object obj = msg.get(); msgpack::object obj = msg.get();
...@@ -53,6 +61,7 @@ bool Reader::read(int64_t ts, const std::function<void(const ftl::codecs::Stream ...@@ -53,6 +61,7 @@ bool Reader::read(int64_t ts, const std::function<void(const ftl::codecs::Stream
} else { } else {
data_ = data; data_ = data;
has_data_ = true; has_data_ = true;
return true;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment