*===================================================================*/
#include "video.h"
#include <QGraphicsView>
+#include <QDateTime>
+#include <QDir>
#ifdef QT_IOS
#define NO_VIDEO
{
droneHost.setAddress("192.168.1.1");
initialized=false;
+ m_idleImage=NULL;
+ videoThread=NULL;
}
-VideoThread::VideoThread(DroneVideo *parentp,QHostAddress host,QImage *_image)
+
+void DroneVideo::frameSeqUpdated()
{
- image=_image;
- qDebug() << "videoThread::videoThread";
- stopped=false;
- parent=parentp;
- videoSock=new QUdpSocket();
- videoSock->bind(QHostAddress::Any,5555);
- droneHost=host;
- start();
+ emit frameSeqChanged();
+}
+
+QImage* DroneVideo::idleImage() { return m_idleImage; }
+void DroneVideo::setIdleImage(QImage *img)
+{
+ m_idleImage=img;
+ if(m_idleImage && image) {
+ QPainter p(image);
+ p.drawImage(0,0,*m_idleImage);
+ update(boundingRect());
+ }
};
void DroneVideo::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,
image->fill(0x5555);
}
QPainter p(image);
- p.drawLine(0,0,image->width(),image->height());
- p.drawLine(image->width(),0,0,image->height());
+ if(m_idleImage) {
+ p.drawImage(0,0,*m_idleImage);
+ } else {
+ p.drawLine(0,0,image->width(),image->height());
+ p.drawLine(image->width(),0,0,image->height());
+ }
update(boundingRect());
videoThread=new VideoThread(this,droneHost,image);
+ connect(videoThread,SIGNAL(frameSeqChanged()),this,SLOT(frameSeqUpdated()));
initialized=true;
} else
painter->drawImage(boundingRect(),*image,image->rect());
}
+/*
+
+ VideoThread
+
+ */
+
+
+VideoThread::VideoThread(DroneVideo *parentp,QHostAddress host,QImage *_image)
+{
+ image=_image;
+ qDebug() << "videoThread::videoThread";
+ stopped=false;
+ parent=parentp;
+ videoSock=new QUdpSocket();
+ videoSock->bind(QHostAddress::Any,5555);
+ droneHost=host;
+ videoRec=FALSE;
+ videoFile=NULL;
+ start();
+
+};
+
+
void VideoThread::run()
{
#define ACQ_WIDTH 320
videoSock->writeDatagram(dgram.data(),dgram.size(),droneHost,5555);
}
+unsigned int VideoThread::getFrameSeq()
+{
+ return frameSeq;
+}
+
+void VideoThread::setVideoRec(bool rec)
+{
+ qDebug() << "VideoThread::setVideoRec" << rec;
+ QDateTime fileDate=QDateTime::currentDateTime();
+ if(!videoRec && rec) {
+ frameSeq=0;
+ videoFileName="dronerec"+fileDate.toString("yyyyMMddhhmm");
+ qDebug() << "videoFileName=" << videoFileName;
+ emit frameSeqChanged();
+ }
+ videoRec=rec;
+ if(!videoRec && videoFile) { // Stop recording
+ videoFile->close();
+ videoFile->~QFile();
+ videoFile=NULL;
+ videoFileName="";
+ }
+
+
+}
+
+bool VideoThread::getVideoRec()
+{
+ return videoRec;
+}
+
+QString VideoThread::getVideoFileName()
+{
+ return videoFileName;
+}
+
+void VideoThread::setVideoFileName(QString name)
+{
+ videoFileName=name;
+}
+
+void VideoThread::setVideoPlay(bool play)
+{
+ if(!videoPlay && play) frameSeq=0;
+ videoPlay=true;
+ videoRec=false;
+}
+
+bool VideoThread::getVideoPlay()
+{
+ return videoPlay;
+}
+
+
+
+
void VideoThread::videoDataReady()
{
qint64 l;
videoData.resize(videoSock->pendingDatagramSize ());
l=videoSock->readDatagram(videoData.data(),videoData.size(),&host,&port);
// qDebug() << "videoThread::videoDataReady" <<" l=" << l << "from" << host ;
+
+ if(videoRec && videoFile==NULL) {
+ // Open Video File
+ }
+
decodeTransform(videoData);
+
}
void VideoThread::decodeTransform(QByteArray &videoData)
//qDebug() <<"VideoThread::decodeTransform" << controller.video_codec;
#ifndef NO_VIDEO
if(controller.video_codec!=NULL) video_decode_blockline( &controller, &picture, &got_image );
+ if(videoRec && !videoFile) {// Start recording
+ qDebug() << "Record Video to " << QDir::current().absolutePath() << videoFileName+".yuv" << " at " << picture.width << "x" << picture.height;
+ videoFile=new QFile(videoFileName+".yuv");
+ videoFile->open(QIODevice::WriteOnly);
+ if(videoFile->error()!=QFile::NoError) {
+ qDebug() << "Can't open Video file " << videoFileName << ".yuv" << videoFile->errorString();
+ videoFile->~QFile();
+ videoFile=NULL;
+ videoRec=false;
+ }
+ }
+ if(!videoRec && videoFile) { // Stop recording
+ videoFile->close();
+ videoFile->~QFile();
+ videoFile=NULL;
+ videoFileName="";
+ }
//else qDebug() << "No video controller";
//qDebug() <<"VideoThread::decodeTransform 2";
//video_decode_picture( &controller, &picture, &stream, &got_image );
// qDebug() <<"VideoThread::decodeTransform got image" << picture.width << picture.height << image->byteCount() << image->bytesPerLine();
// we got one picture
// out->size = 1;
+ frameSeq++;
picture.complete = 1;
num_picture_decoded++;
+ if(videoFile && videoRec) {
+ videoFile->write((char*)picture.y_buf,picture.width*picture.height);
+ videoFile->write((char*)picture.cb_buf,picture.width*picture.height>>2);
+ videoFile->write((char*)picture.cr_buf,picture.width*picture.height>>2);
+ };
if(image->depth()<24)
vp_stages_YUV420P_to_RGB565(NULL,&picture,image->bits(),image->bytesPerLine());
else
vp_stages_YUV420P_to_ARGB32(NULL,&picture,image->bits(),image->bytesPerLine());
+ emit frameSeqChanged();
// qDebug() << "pic " << num_picture_decoded;
}