]> git.sesse.net Git - nageru/commitdiff
Actually start showing JPEGs on the screen.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 5 Jun 2018 22:01:50 +0000 (00:01 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 5 Jun 2018 22:01:50 +0000 (00:01 +0200)
Makefile
jpeg_frame_view.cpp [new file with mode: 0644]
jpeg_frame_view.h [new file with mode: 0644]
main.cpp
mainwindow.h
post_to_main_thread.h [new file with mode: 0644]
ui_mainwindow.ui

index 379a0a6503d01b6c83619611627d9cb8801a1823..2608903245524df9dc936e1fb7d737f8e4e81d23 100644 (file)
--- 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 = mainwindow.o
+OBJS_WITH_MOC = mainwindow.o jpeg_frame_view.o
 OBJS += $(OBJS_WITH_MOC)
 OBJS += $(OBJS_WITH_MOC:.o=.moc.o) 
 
diff --git a/jpeg_frame_view.cpp b/jpeg_frame_view.cpp
new file mode 100644 (file)
index 0000000..55a4857
--- /dev/null
@@ -0,0 +1,27 @@
+#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);
+}
diff --git a/jpeg_frame_view.h b/jpeg_frame_view.h
new file mode 100644 (file)
index 0000000..219ee58
--- /dev/null
@@ -0,0 +1,36 @@
+#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)
index 17431aa46f127bb06fb33cd0dc9ec705bdcfc430..0a976c3d438994e6c95dce9faabc4556cf766715 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -17,6 +17,8 @@ extern "C" {
 
 #include "mainwindow.h"
 #include "ffmpeg_raii.h"
+#include "post_to_main_thread.h"
+#include "ui_mainwindow.h"
 
 #define MAX_STREAMS 16
 
@@ -78,6 +80,14 @@ int thread_func()
                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);
 
index 4ee3bd9902607fdf33aea36cd06776e2f76999a8..f17757fe335859be1b1e49d25116c4a89f9a8614 100644 (file)
@@ -16,7 +16,7 @@ class MainWindow : public QMainWindow
 public:
        MainWindow();
 
-private:
+//private:
        Ui::MainWindow *ui;
 };
 
diff --git a/post_to_main_thread.h b/post_to_main_thread.h
new file mode 100644 (file)
index 0000000..0462c7b
--- /dev/null
@@ -0,0 +1,16 @@
+#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)
index aeff6cbf4827e91350983ddc7e9e7838d7ee6a7d..17ff6703b1bcf1e9d2546cd89d1d7dc77095e718 100644 (file)
    <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>
@@ -57,7 +57,7 @@
    <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>
@@ -67,7 +67,7 @@
    <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>
@@ -78,7 +78,7 @@
     <property name="geometry">
      <rect>
       <x>470</x>
-      <y>240</y>
+      <y>230</y>
       <width>191</width>
       <height>17</height>
      </rect>
@@ -93,7 +93,7 @@
    <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>