LDLIBS=$(shell pkg-config --libs $(PKG_MODULES)) -pthread -lavformat -lavcodec -lavutil -lswscale
# Qt objects
-OBJS_WITH_MOC = mainwindow.o
+OBJS_WITH_MOC = mainwindow.o jpeg_frame_view.o
OBJS += $(OBJS_WITH_MOC)
OBJS += $(OBJS_WITH_MOC:.o=.moc.o)
--- /dev/null
+#include "jpeg_frame_view.h"
+
+#include <QGraphicsPixmapItem>
+#include <QPixmap>
+
+using namespace std;
+
+string filename_for_frame(unsigned stream_idx, int64_t pts);
+
+JPEGFrameView::JPEGFrameView(QWidget *parent)
+ : QGraphicsView(parent) {
+ scene.addItem(&item);
+ setScene(&scene);
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+}
+
+void JPEGFrameView::update()
+{
+ item.setPixmap(QPixmap(QString::fromStdString(filename_for_frame(stream_idx, pts))));
+ fitInView(&item, Qt::KeepAspectRatio);
+}
+
+void JPEGFrameView::resizeEvent(QResizeEvent *event)
+{
+ fitInView(&item, Qt::KeepAspectRatio);
+}
--- /dev/null
+#ifndef _JPEG_FRAME_VIEW_H
+#define _JPEG_FRAME_VIEW_H 1
+
+#include <QGraphicsView>
+#include <QGraphicsPixmapItem>
+#include <QGraphicsScene>
+
+#include <stdint.h>
+
+class JPEGFrameView : public QGraphicsView {
+ Q_OBJECT
+
+public:
+ JPEGFrameView(QWidget *parent);
+
+ void setFrame(unsigned stream_idx, int64_t pts)
+ {
+ this->stream_idx = stream_idx;
+ this->pts = pts;
+ update();
+ }
+
+protected:
+ void resizeEvent(QResizeEvent *event) override;
+
+private:
+ void update();
+
+ QGraphicsPixmapItem item;
+ QGraphicsScene scene;
+
+ unsigned stream_idx;
+ int64_t pts;
+};
+
+#endif // !defined(_JPEG_FRAME_VIEW_H)
#include "mainwindow.h"
#include "ffmpeg_raii.h"
+#include "post_to_main_thread.h"
+#include "ui_mainwindow.h"
#define MAX_STREAMS 16
fwrite(pkt.data, pkt.size, 1, fp);
fclose(fp);
+ post_to_main_thread([pkt] {
+ if (pkt.stream_index == 0) {
+ global_mainwindow->ui->input1_display->setFrame(pkt.stream_index, pkt.pts);
+ } else if (pkt.stream_index == 1) {
+ global_mainwindow->ui->input2_display->setFrame(pkt.stream_index, pkt.pts);
+ }
+ });
+
assert(pkt.stream_index < MAX_STREAMS);
frames[pkt.stream_index].push_back(pkt.pts);
public:
MainWindow();
-private:
+//private:
Ui::MainWindow *ui;
};
--- /dev/null
+#ifndef _POST_TO_MAIN_THREAD_H
+#define _POST_TO_MAIN_THREAD_H 1
+
+#include <QApplication>
+#include <QObject>
+#include <memory>
+
+// http://stackoverflow.com/questions/21646467/how-to-execute-a-functor-in-a-given-thread-in-qt-gcd-style
+template<typename F>
+static inline void post_to_main_thread(F &&fun)
+{
+ QObject signalSource;
+ QObject::connect(&signalSource, &QObject::destroyed, qApp, std::move(fun));
+}
+
+#endif // !defined(_POST_TO_MAIN_THREAD_H)
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
- <x>20</x>
+ <x>10</x>
<y>20</y>
- <width>381</width>
- <height>211</height>
+ <width>391</width>
+ <height>291</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
- <widget class="QGraphicsView" name="input2_display"/>
+ <widget class="JPEGFrameView" name="input2_display"/>
</item>
<item row="0" column="0">
- <widget class="QGraphicsView" name="input1_display"/>
+ <widget class="JPEGFrameView" name="input1_display"/>
</item>
<item row="1" column="0">
- <widget class="QGraphicsView" name="input3_display"/>
+ <widget class="JPEGFrameView" name="input3_display"/>
</item>
<item row="1" column="1">
- <widget class="QGraphicsView" name="input4_display"/>
+ <widget class="JPEGFrameView" name="input4_display"/>
</item>
</layout>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
- <x>90</x>
- <y>240</y>
+ <x>70</x>
+ <y>320</y>
<width>261</width>
<height>17</height>
</rect>
<widget class="QGraphicsView" name="preview_display">
<property name="geometry">
<rect>
- <x>410</x>
+ <x>430</x>
<y>20</y>
<width>281</width>
<height>192</height>
<widget class="QGraphicsView" name="live_display">
<property name="geometry">
<rect>
- <x>705</x>
+ <x>730</x>
<y>20</y>
<width>291</width>
<height>192</height>
<property name="geometry">
<rect>
<x>470</x>
- <y>240</y>
+ <y>230</y>
<width>191</width>
<height>17</height>
</rect>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
- <x>760</x>
+ <x>770</x>
<y>230</y>
<width>191</width>
<height>17</height>
</widget>
</widget>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>JPEGFrameView</class>
+ <extends>QGraphicsView</extends>
+ <header>jpeg_frame_view.h</header>
+ </customwidget>
+ </customwidgets>
<resources/>
<connections/>
</ui>