From 0a58b6906096d32f8d588ee18e898d487c06072b Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 5 Jun 2018 22:53:28 +0200 Subject: [PATCH] Throw up some widgets. --- .gitignore | 2 + Makefile | 4 +- main.cpp | 51 ++++++++++++++++++--- mainwindow.cpp | 12 +++++ mainwindow.h | 26 +++++++++++ ui_mainwindow.ui | 113 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 202 insertions(+), 6 deletions(-) create mode 100644 mainwindow.cpp create mode 100644 mainwindow.h create mode 100644 ui_mainwindow.ui diff --git a/.gitignore b/.gitignore index e90caef..bffc070 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,7 @@ *.pb.h *.pb.cc *.moc.cpp +ui_*.h futatabi frames/*.jpeg +.ycm_extra_conf.py diff --git a/Makefile b/Makefile index 05a6085..379a0a6 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ CXXFLAGS += -std=gnu++11 -fPIC $(shell pkg-config --cflags $(PKG_MODULES)) -pthr LDLIBS=$(shell pkg-config --libs $(PKG_MODULES)) -pthread -lavformat -lavcodec -lavutil -lswscale # Qt objects -OBJS_WITH_MOC = +OBJS_WITH_MOC = mainwindow.o OBJS += $(OBJS_WITH_MOC) OBJS += $(OBJS_WITH_MOC:.o=.moc.o) @@ -27,6 +27,8 @@ OBJS += ffmpeg_raii.o main.o all: futatabi +mainwindow.o: ui_mainwindow.h + futatabi: $(OBJS) $(CEF_LIBS) $(CXX) -o $@ $^ $(LDFLAGS) $(LDLIBS) diff --git a/main.cpp b/main.cpp index 810bcf3..17431aa 100644 --- a/main.cpp +++ b/main.cpp @@ -1,19 +1,56 @@ +#include #include +#include + +#include #include +#include +#include +#include +#include extern "C" { #include } +#include + +#include "mainwindow.h" #include "ffmpeg_raii.h" +#define MAX_STREAMS 16 + using namespace std; +using namespace std::chrono; + +string filename_for_frame(unsigned stream_idx, int64_t pts) +{ + char filename[256]; + snprintf(filename, sizeof(filename), "frames/cam%d-pts%09ld.jpeg", stream_idx, pts); + return filename; +} + +mutex frame_mu; +vector frames[MAX_STREAMS]; + +int thread_func(); -int main(void) +int main(int argc, char **argv) { av_register_all(); avformat_network_init(); + QApplication app(argc, argv); + MainWindow mainWindow; + mainWindow.show(); + + thread(thread_func).detach(); + + return app.exec(); +} + +int thread_func() +{ auto format_ctx = avformat_open_input_unique("example.mp4", nullptr, nullptr); if (format_ctx == nullptr) { fprintf(stderr, "%s: Error opening file\n", "example.mp4"); @@ -32,15 +69,19 @@ int main(void) } fprintf(stderr, "Got a frame from camera %d, pts = %ld, size = %d\n", pkt.stream_index, pkt.pts, pkt.size); - char filename[256]; - snprintf(filename, sizeof(filename), "frames/cam%d-pts%09ld.jpeg", pkt.stream_index, pkt.pts); - FILE *fp = fopen(filename, "wb"); + string filename = filename_for_frame(pkt.stream_index, pkt.pts); + FILE *fp = fopen(filename.c_str(), "wb"); if (fp == nullptr) { - perror(filename); + perror(filename.c_str()); exit(1); } fwrite(pkt.data, pkt.size, 1, fp); fclose(fp); + + assert(pkt.stream_index < MAX_STREAMS); + frames[pkt.stream_index].push_back(pkt.pts); + + this_thread::sleep_for(milliseconds(1000) / 120); } return 0; diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..5432408 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,12 @@ +#include "mainwindow.h" + +#include "ui_mainwindow.h" + +MainWindow *global_mainwindow = nullptr; + +MainWindow::MainWindow() + : ui(new Ui::MainWindow) +{ + global_mainwindow = this; + ui->setupUi(this); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..4ee3bd9 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,26 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +namespace Ui { +class MainWindow; +} // namespace Ui + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +private: + Ui::MainWindow *ui; +}; + +extern MainWindow *global_mainwindow; + +#endif + diff --git a/ui_mainwindow.ui b/ui_mainwindow.ui new file mode 100644 index 0000000..aeff6cb --- /dev/null +++ b/ui_mainwindow.ui @@ -0,0 +1,113 @@ + + + MainWindow + + + + 0 + 0 + 1038 + 600 + + + + MainWindow + + + + + + 20 + 20 + 381 + 211 + + + + + + + + + + + + + + + + + + + + + 90 + 240 + 261 + 17 + + + + Current inputs + + + Qt::AlignCenter + + + + + + 410 + 20 + 281 + 192 + + + + + + + 705 + 20 + 291 + 192 + + + + + + + 470 + 240 + 191 + 17 + + + + Preview output + + + Qt::AlignCenter + + + + + + 760 + 230 + 191 + 17 + + + + Current output + + + Qt::AlignCenter + + + + + + + -- 2.39.2