Video record function added
[mardrone] / mardrone / dronelib / video.h
1 #ifndef VIDEO_H
2 #define VIDEO_H
3
4 #include <QGraphicsWidget>
5 #include <QGraphicsItem>
6 #include <QPainter>
7 #include <QUdpSocket>
8 #include <QTcpSocket>
9 #include <QThread>
10 #include <QTimer>
11 #include "dronecontrol.h"
12 #undef _GNU_SOURCE // just get rid of error message double definition
13 #define TARGET_CPU_ARM 1
14 #include <navdata.h>
15 #include <VP_Os/vp_os_malloc.h>
16 #include <VP_Os/vp_os_print.h>
17 extern "C"
18 {
19 #include <VLIB/Stages/vlib_stage_decode.h>
20 void vp_stages_YUV420P_to_RGB565(void *cfg, vp_api_picture_t *picture, uint8_t *dst, uint32_t dst_rbytes);
21 void vp_stages_YUV420P_to_ARGB32(void *cfg, vp_api_picture_t *picture, uint8_t *dst, uint32_t dst_rbytes);
22 }
23
24
25 class VideoThread;
26 class DroneVideo;
27
28 class VideoThread:public QThread {
29     Q_OBJECT
30 public:
31     VideoThread(DroneVideo *parentp,QHostAddress host,QImage *_image);
32
33  //   ~DroneThread ();
34     void run();
35     void sendVideoPort(QString cmd);
36     void decodeTransform(QByteArray &videoData);
37     unsigned int getFrameSeq();
38     bool getVideoRec();
39     bool getVideoPlay();
40     QString getVideoFileName();
41     void setVideoFileName(QString name);
42
43 signals:
44     void frameSeqChanged();
45 public slots:
46     void videoDataReady();
47     void setVideoRec(bool rec);
48
49     void setVideoPlay(bool play);
50     void timer();
51
52
53
54 private:
55     QImage *image;
56     video_controller_t controller;
57     vp_api_picture_t picture;
58     int pictureWidth;
59     int pictureHeight;
60     bool luma_only;
61     bool videoRec;
62     bool videoPlay;
63     QFile *videoFile;
64     QString videoFileName;
65     unsigned int frameSeq;
66     unsigned int num_picture_decoded;
67     QHostAddress droneHost;  // Ip address of the drone
68     QTimer *stateTimer;
69     volatile bool stopped;
70     DroneVideo *parent;
71     QUdpSocket *videoSock;  // Navigation data receive socket port 5554
72
73 };
74
75 class DroneVideo:public QGraphicsWidget
76 {
77     Q_OBJECT
78 public:
79
80     DroneVideo();
81     void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,
82                     QWidget *widget);
83     QRectF boundingRect() const;
84     Q_PROPERTY(QImage* idleImage READ idleImage WRITE setIdleImage )
85     Q_PROPERTY(bool recVideo READ recVideo WRITE setRecVideo )
86     Q_PROPERTY(bool playVideo READ playVideo WRITE setPlayVideo )
87     Q_PROPERTY(QString videoFileName READ videoFileName WRITE setVideoFileName NOTIFY frameSeqChanged)
88     Q_PROPERTY(unsigned int  frameSeq READ frameSeq NOTIFY frameSeqChanged)
89
90
91     QImage* idleImage(); void setIdleImage(QImage *);
92     void setRecVideo(bool val_) { if(videoThread) videoThread->setVideoRec(val_);};
93     bool recVideo() {return videoThread ? videoThread->getVideoRec():false;};
94
95     void setPlayVideo(bool val_) { if(videoThread) videoThread->setVideoPlay(val_);};
96     bool playVideo() {return videoThread ? videoThread->getVideoPlay():false;};
97
98     int  frameSeq() {return videoThread ? videoThread->getFrameSeq():0;};
99
100     QString videoFileName() const { return videoThread ? videoThread->getVideoFileName():"";};
101     void setVideoFileName(const QString &name_) {if(videoThread) videoThread->setVideoFileName(name_);}
102 signals:
103     void frameSeqChanged();
104
105 public slots:
106     void frameSeqUpdated();
107 private:
108     QHostAddress droneHost;  // Ip address of the drone
109
110     VideoThread *videoThread;
111     QImage *image;
112     QImage *m_idleImage;
113     int depth;
114     bool initialized;
115 };
116
117
118 #endif // VIDEO_H