video : graphics : test : Advance video use case
[sitara-linux/video-graphics-test.git] / mainwindow.cpp
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include <QThread>
4 #include <QMutex>
5 #include "loopback.h"
6 #include <stdio.h>
7 #include <qpa/qplatformnativeinterface.h>
9 class MyThread : public QThread
10 {
11         Q_OBJECT
13 protected:
14         void run();
15 };
17 MyThread* loopback;
18 QMutex drm_resource;
20 MainWindow::MainWindow(QWidget *parent, QApplication *a) :
21 QMainWindow(parent),
22 ui(new Ui::MainWindow)
23 {
24         ui->setupUi(this);
25         this->setAttribute(Qt::WA_TranslucentBackground);
26         this->setWindowFlags(Qt::FramelessWindowHint);
28         platInf = a->platformNativeInterface();
29         status.drm_fd = (int) platInf->nativeResourceForIntegration("drm_fd");
30         status.drm_plane_sreq_handler = \
31                 (drm_plane_sreq)platInf->nativeResourceForIntegration("drm_plane_set_req");
33         loopback = new MyThread();
35         if(init_loopback() < 0) {
36                 /* TODO: make sure exit occurs properly */
37         }
39         /* Configure GUI */
40         this->setFixedSize(status.display_xres, status.display_yres);
41         ui->frame->setGeometry(0, 0, status.display_xres, status.display_yres);
43         /* Set the back ground color to black */
44         /* This is a workaround required when moving from Qt4 to QT5.  */
45         /* QT5 doesn't support QWSServer. This is causing the graphics */
46         /* windows not to clear up when being instructed to be hidden  */
47         /* Making the background color black solves the problem        */
48         ui->frame->setStyleSheet("background-color:black;");
49         ui->frame->show();
51         ui->frame_pip->setGeometry(25, 25, status.display_xres/3, status.display_yres/3);
52         ui->capture->setGeometry(status.display_xres/2 - 210,
53                 status.display_yres - 50,
54                 91, 41);
55         ui->switch_2->setGeometry(status.display_xres/2 - 100,
56                 status.display_yres - 50,
57                 91, 41);
58         ui->pip->setGeometry(status.display_xres/2 + 10,
59                 status.display_yres - 50,
60                 91, 41);
61         ui->exit->setGeometry(status.display_xres/2 + 120,
62                 status.display_yres - 50,
63                 91, 41);
65         if(status.num_cams == 1) {
66                 /* Reconfigure GUI to reflect single camera mode */
67                 ui->pip->setHidden(true);
68                 ui->pip->setDisabled(true);
69                 ui->switch_2->setHidden(true);
70                 ui->switch_2->setDisabled(true);
71                 ui->frame_pip->setHidden(true);
72                 ui->capture->setGeometry(status.display_xres/2 - 100,
73                         status.display_yres - 50,
74                         91, 41);
75                 ui->exit->setGeometry(status.display_xres/2 + 10,
76                         status.display_yres - 50,
77                         91, 41);
78         }
80         /* Start the camera loopback thread */
81         loopback->start();
82 }
84 MainWindow::~MainWindow()
85 {
86         delete ui;
87 }
89 void MainWindow::on_capture_clicked()
90 {
91 }
93 void MainWindow::on_switch_2_clicked()
94 {
95         /* While changing the drm display properties, make sure loopback thread */
96         /* isn't running thereby accessing drm properties  simultaneously, and  */ 
97         /* hence can cause system crash                                         */
98         drm_resource.lock();
100         if (status.num_cams==2){
101                 //switch the main camera by toggleing the main_cam value.
102                 status.main_cam = !status.main_cam;
103                 set_plane_properties();
104         }
106         drm_resource.unlock();
109 void MainWindow::on_pip_clicked()
111         /* While changing the drm display properties, make sure loopback thread */
112         /* isn't running thereby accessing drm properties  simultaneously, and  */ 
113         /* hence can cause system crash                                         */
114         drm_resource.lock();
116         if (status.pip==true) {
117                 status.pip=false;
118                 drm_disable_pip();
119                 ui->frame_pip->setHidden(true);
120         }
121         else {
122                 drm_enable_pip();
123                 ui->frame_pip->setHidden(false);
124                 status.pip=true;
125         }
127         drm_resource.unlock();
130 void MainWindow::on_exit_clicked()
132         status.exit=true;
133         loopback->wait(1000);
134         this->close();
137 void MyThread::run() {
139         while(status.exit == false) {
140                 drm_resource.lock();
141                 process_frame();
142                 drm_resource.unlock();  
143                 msleep(1);
144         }
145         end_streaming();
146         exit_devices();
150 #include "mainwindow.moc"