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

Allow player to select stream

parent b990b97a
No related branches found
No related tags found
1 merge request!127Implements #196 stream capturing
Pipeline #15310 passed
...@@ -37,7 +37,7 @@ int main(int argc, char **argv) { ...@@ -37,7 +37,7 @@ int main(int argc, char **argv) {
int current_stream = 0; int current_stream = 0;
bool res = r.read(90000000000000, [&current_stream](const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt) { bool res = r.read(90000000000000, [&current_stream,&r](const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt) {
if (spkt.channel & 0x1 > 0) return; if (spkt.channel & 0x1 > 0) return;
if (spkt.streamID == current_stream) { if (spkt.streamID == current_stream) {
...@@ -55,7 +55,12 @@ int main(int argc, char **argv) { ...@@ -55,7 +55,12 @@ int main(int argc, char **argv) {
if (!frame.empty()) { if (!frame.empty()) {
cv::imshow("Player", frame); cv::imshow("Player", frame);
} }
cv::waitKey(20); int key = cv::waitKey(20);
if (key >= 48 && key <= 57) {
current_stream = key - 48;
} else if (key == 27) {
r.end();
}
} }
}); });
......
...@@ -45,6 +45,7 @@ class Reader { ...@@ -45,6 +45,7 @@ class Reader {
std::tuple<StreamPacket,Packet> data_; std::tuple<StreamPacket,Packet> data_;
bool has_data_; bool has_data_;
int64_t timestart_; int64_t timestart_;
bool playing_;
std::vector<std::function<void(const ftl::codecs::StreamPacket &, const ftl::codecs::Packet &)>> handlers_; std::vector<std::function<void(const ftl::codecs::StreamPacket &, const ftl::codecs::Packet &)>> handlers_;
}; };
......
...@@ -9,7 +9,7 @@ using ftl::codecs::StreamPacket; ...@@ -9,7 +9,7 @@ using ftl::codecs::StreamPacket;
using ftl::codecs::Packet; using ftl::codecs::Packet;
using std::get; using std::get;
Reader::Reader(std::istream &s) : stream_(&s), has_data_(false) { Reader::Reader(std::istream &s) : stream_(&s), has_data_(false), playing_(false) {
} }
...@@ -24,6 +24,7 @@ bool Reader::begin() { ...@@ -24,6 +24,7 @@ bool Reader::begin() {
// Capture current time to adjust timestamps // Capture current time to adjust timestamps
timestart_ = ftl::timer::get_time(); timestart_ = ftl::timer::get_time();
playing_ = true;
return true; return true;
} }
...@@ -38,7 +39,7 @@ bool Reader::read(int64_t ts, const std::function<void(const ftl::codecs::Stream ...@@ -38,7 +39,7 @@ bool Reader::read(int64_t ts, const std::function<void(const ftl::codecs::Stream
bool partial = false; bool partial = false;
while (stream_->good() || buffer_.nonparsed_size() > 0) { while (playing_ && stream_->good() || buffer_.nonparsed_size() > 0) {
if (buffer_.nonparsed_size() == 0 || (partial && buffer_.nonparsed_size() < 10000000)) { if (buffer_.nonparsed_size() == 0 || (partial && buffer_.nonparsed_size() < 10000000)) {
buffer_.reserve_buffer(10000000); buffer_.reserve_buffer(10000000);
stream_->read(buffer_.buffer(), buffer_.buffer_capacity()); stream_->read(buffer_.buffer(), buffer_.buffer_capacity());
...@@ -97,5 +98,6 @@ void Reader::onPacket(int streamID, const std::function<void(const ftl::codecs:: ...@@ -97,5 +98,6 @@ void Reader::onPacket(int streamID, const std::function<void(const ftl::codecs::
} }
bool Reader::end() { bool Reader::end() {
playing_ = false;
return true; return true;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment