Skip to content

Commit

Permalink
Reduce video latency
Browse files Browse the repository at this point in the history
  • Loading branch information
silverchris committed Jul 23, 2022
1 parent 4c8bc61 commit 8f3cfe1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
1 change: 0 additions & 1 deletion include/autoapp/Projection/GSTVideoOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ class GSTVideoOutput : public IVideoOutput {
void message_handler(asio::error_code ec, size_t bytes_transferred);

void spawn_gst();
static bool CheckReverse();
};
}
34 changes: 4 additions & 30 deletions src/autoapp/Projection/GSTVideoOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ void GSTVideoOutput::spawn_gst() {
char *const launch[] = {
(char *) "sh",
(char *) "-c",
(char *) "gst-launch fdsrc fd=0 timeout=1000 do-timestamp=true ! queue max-size-buffers=600 ! h264parse " \
"! vpudec low-latency=true framedrop=true framedrop-level-mask=0x200 frame-plus=1 "\
(char *) "gst-launch fdsrc fd=0 timeout=1000 do-timestamp=true ! queue " \
"! capsfilter caps=video/x-h264,framerate=30 " \
"! vpudec low-latency=true framedrop=true framedrop-level-mask=0x200 frame-plus=2 "\
"! mfw_v4lsink name=aavideo 2>&1",
nullptr};

Expand All @@ -63,7 +64,7 @@ void GSTVideoOutput::spawn_gst() {
(char *) "XDG_RUNTIME_DIR=/tmp",
(char *) "SHELL=/bin/sh",
(char *) "PWD=/tmp/root",
(char *) "GST_PLUGIN_PATH=/mnt/data_persist/dev/bin/headunit_libs:/usr/lib/gstreamer-0.10",
(char *) "GST_PLUGIN_PATH=/usr/lib/gstreamer-0.10",
nullptr
};

Expand Down Expand Up @@ -91,11 +92,6 @@ bool GSTVideoOutput::open() {
std::ofstream ofs("/proc/sys/vm/drop_caches");
ofs << "3" << std::endl;

if (CheckReverse()) {
running = true;
return true;
}

if (gstpid == -1) {
spawn_gst();

Expand All @@ -113,14 +109,6 @@ bool GSTVideoOutput::init() {

void GSTVideoOutput::write(__attribute__((unused)) uint64_t timestamp,
const aasdk::common::DataConstBuffer &buf) {
if (CheckReverse()) {
running = true;
stop();
} else {
if (running && gstpid == -1) {
open();
}
}
if (gstpid != -1) {
fwrite(buf.cdata, sizeof(buf.cdata[0]), buf.size, gst_file);
}
Expand All @@ -136,20 +124,6 @@ void GSTVideoOutput::stop() {
}
}

bool GSTVideoOutput::CheckReverse() {
bool reverse = false;
char gpio_value[3];
FILE *fd = fopen("/sys/class/gpio/Reverse/value", "r");
if (fd == nullptr) {
LOG(ERROR) << "Failed to open Reverse gpio value for reading";
} else {
fread(gpio_value, 1, 2, fd);
reverse = (gpio_value[0] == '0');
}
fclose(fd);
return reverse;
}

GSTVideoOutput::~GSTVideoOutput() = default;

VideoMargins GSTVideoOutput::getVideoMargins() const {
Expand Down
1 change: 1 addition & 0 deletions src/autoapp/Service/VideoService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ void VideoService::sendVideoFocusIndication() {

void VideoService::sendVideoFocusLost() {
LOG(INFO) << "[VideoService] video focus indication.";
videoOutput_->stop();

aasdk::proto::messages::VideoFocusIndication videoFocusIndication;
videoFocusIndication.set_focus_mode(aasdk::proto::enums::VideoFocusMode::UNFOCUSED);
Expand Down

0 comments on commit 8f3cfe1

Please sign in to comment.