X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=mardrone%2Fdronelib%2Fvideo.cpp;h=7ba76adf3bcd08f4939a3e356894ac210216b173;hb=36cc6e25d56bca63eef76e0ef3569c9b78514496;hp=c8363caadf67b39ac4429a2be9f56db9a48283db;hpb=9810849a03cbb8f89bd3cbeb18c7b2005f846622;p=mardrone diff --git a/mardrone/dronelib/video.cpp b/mardrone/dronelib/video.cpp index c8363ca..7ba76ad 100644 --- a/mardrone/dronelib/video.cpp +++ b/mardrone/dronelib/video.cpp @@ -20,6 +20,8 @@ *===================================================================*/ #include "video.h" #include +#include +#include #ifdef QT_IOS #define NO_VIDEO @@ -29,19 +31,26 @@ DroneVideo::DroneVideo() { 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, @@ -61,10 +70,15 @@ 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()); @@ -76,6 +90,29 @@ QRectF DroneVideo::boundingRect() const } +/* + + 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 @@ -133,6 +170,62 @@ void VideoThread::sendVideoPort(QString cmd) 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; @@ -143,7 +236,13 @@ void VideoThread::videoDataReady() 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) @@ -159,6 +258,23 @@ 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 ); @@ -167,12 +283,19 @@ void VideoThread::decodeTransform(QByteArray &videoData) // 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; }