mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-12-10 14:25:50 -05:00
added serialisation/transmission of video data
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7452 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9006c567a1
commit
01c467c4c0
11 changed files with 149 additions and 46 deletions
|
|
@ -24,31 +24,42 @@ void PluginGUIHandler::ReceivedVoipAccept(const QString& /*peer_id*/)
|
|||
|
||||
void PluginGUIHandler::ReceivedVoipData(const QString& qpeer_id)
|
||||
{
|
||||
std::cerr << "****** Plugin GUI handler: received VoipData!" << std::endl;
|
||||
std::cerr << "****** Plugin GUI handler: received VoipData!" << std::endl;
|
||||
|
||||
RsPeerId peer_id(qpeer_id.toStdString()) ;
|
||||
RsPeerId peer_id(qpeer_id.toStdString()) ;
|
||||
std::vector<RsVoipDataChunk> chunks ;
|
||||
|
||||
if(!rsVoip->getIncomingData(peer_id,chunks))
|
||||
if(!rsVoip->getIncomingData(peer_id,chunks))
|
||||
{
|
||||
std::cerr << "PluginGUIHandler::ReceivedVoipData(): No data chunks to get. Weird!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
ChatDialog *di = ChatDialog::getExistingChat(peer_id) ;
|
||||
ChatDialog *di = ChatDialog::getExistingChat(peer_id) ;
|
||||
if (di) {
|
||||
ChatWidget *cw = di->getChatWidget();
|
||||
if (cw) {
|
||||
const QList<ChatWidgetHolder*> &chatWidgetHolderList = cw->chatWidgetHolderList();
|
||||
|
||||
foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList) {
|
||||
foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList)
|
||||
{
|
||||
VOIPChatWidgetHolder *acwh = dynamic_cast<VOIPChatWidgetHolder*>(chatWidgetHolder) ;
|
||||
|
||||
if (acwh) {
|
||||
for (unsigned int i = 0; i < chunks.size(); ++i) {
|
||||
for (unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++){
|
||||
for (unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++)
|
||||
{
|
||||
QByteArray qb(reinterpret_cast<const char *>(chunks[chunkIndex].data),chunks[chunkIndex].size);
|
||||
acwh->addAudioData(QString::fromStdString(peer_id.toStdString()),&qb);
|
||||
|
||||
if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_AUDIO)
|
||||
acwh->addAudioData(QString::fromStdString(peer_id.toStdString()),&qb);
|
||||
else if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO)
|
||||
{
|
||||
acwh->addVideoData(QString::fromStdString(peer_id.toStdString()),&qb);
|
||||
std::cerr << "data triaged as video." << std::endl;
|
||||
}
|
||||
else
|
||||
std::cerr << "Unknown data type received. type=" << chunks[chunkIndex].type << std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -74,10 +74,19 @@ void QVideoInputDevice::grabFrame()
|
|||
|
||||
QImage image = QImage((uchar*)img->imageData,img->width,img->height,QImage::Format_RGB888).scaled(QSize(_encoded_width,_encoded_height),Qt::IgnoreAspectRatio,Qt::SmoothTransformation) ;
|
||||
|
||||
if(_video_encoder != NULL) _video_encoder->addImage(image) ;
|
||||
if(_video_encoder != NULL)
|
||||
{
|
||||
_video_encoder->addImage(image) ;
|
||||
emit networkPacketReady() ;
|
||||
}
|
||||
if(_echo_output_device != NULL) _echo_output_device->showFrame(image) ;
|
||||
}
|
||||
|
||||
bool QVideoInputDevice::getNextEncodedPacket(RsVoipDataChunk& chunk)
|
||||
{
|
||||
return _video_encoder->nextPacket(chunk) ;
|
||||
}
|
||||
|
||||
QVideoInputDevice::~QVideoInputDevice()
|
||||
{
|
||||
stop() ;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
#include "interface/rsvoip.h"
|
||||
|
||||
class VideoEncoder ;
|
||||
class CvCapture ;
|
||||
|
|
@ -36,17 +37,26 @@ class QVideoInputDevice: public QObject
|
|||
//
|
||||
void setEchoVideoTarget(QVideoOutputDevice *odev) { _echo_output_device = odev ; }
|
||||
|
||||
// get the next encoded video data chunk.
|
||||
//
|
||||
bool getNextEncodedPacket(RsVoipDataChunk&) ;
|
||||
|
||||
void start() ;
|
||||
void stop() ;
|
||||
|
||||
protected slots:
|
||||
void grabFrame() ;
|
||||
|
||||
signals:
|
||||
void networkPacketReady() ;
|
||||
|
||||
private:
|
||||
VideoEncoder *_video_encoder ;
|
||||
QTimer *_timer ;
|
||||
CvCapture *_capture_device ;
|
||||
|
||||
QVideoOutputDevice *_echo_output_device ;
|
||||
|
||||
std::list<RsVoipDataChunk> _out_queue ;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -112,12 +112,15 @@ VOIPChatWidgetHolder::VOIPChatWidgetHolder(ChatWidget *chatWidget)
|
|||
videoWidget->layout()->addWidget(echoVideoDevice = new QVideoOutputDevice(videoWidget)) ;
|
||||
videoWidget->layout()->addWidget(outputVideoDevice = new QVideoOutputDevice(videoWidget)) ;
|
||||
|
||||
connect(inputVideoDevice, SIGNAL(networkPacketReady()), this, SLOT(sendVideoData()));
|
||||
|
||||
echoVideoDevice->setMinimumSize(128,95) ;
|
||||
outputVideoDevice->setMinimumSize(128,95) ;
|
||||
|
||||
mChatWidget->addChatHorizontalWidget(videoWidget) ;
|
||||
|
||||
inputVideoDevice->setEchoVideoTarget(echoVideoDevice) ;
|
||||
inputVideoDevice->setVideoEncoder(inputVideoProcessor) ;
|
||||
outputVideoProcessor->setDisplayTarget(outputVideoDevice) ;
|
||||
}
|
||||
|
||||
|
|
@ -221,6 +224,11 @@ void VOIPChatWidgetHolder::toggleVideoCapture()
|
|||
}
|
||||
}
|
||||
|
||||
void VOIPChatWidgetHolder::addVideoData(const QString name, QByteArray* array)
|
||||
{
|
||||
outputVideoProcessor->receiveEncodedData((unsigned char *)array->data(),array->size()) ;
|
||||
}
|
||||
|
||||
void VOIPChatWidgetHolder::addAudioData(const QString name, QByteArray* array)
|
||||
{
|
||||
if (!audioCaptureToggleButton->isChecked()) {
|
||||
|
|
@ -280,6 +288,17 @@ void VOIPChatWidgetHolder::addAudioData(const QString name, QByteArray* array)
|
|||
}
|
||||
}
|
||||
|
||||
void VOIPChatWidgetHolder::sendVideoData()
|
||||
{
|
||||
RsVoipDataChunk chunk ;
|
||||
|
||||
while(inputVideoDevice && inputVideoDevice->getNextEncodedPacket(chunk))
|
||||
{
|
||||
std::cerr << "Video data ready: sending it" << std::endl;
|
||||
rsVoip->sendVoipData(mChatWidget->getPeerId(),chunk) ;
|
||||
}
|
||||
}
|
||||
|
||||
void VOIPChatWidgetHolder::sendAudioData()
|
||||
{
|
||||
while(inputAudioProcessor && inputAudioProcessor->hasPendingPackets()) {
|
||||
|
|
@ -287,6 +306,7 @@ void VOIPChatWidgetHolder::sendAudioData()
|
|||
RsVoipDataChunk chunk;
|
||||
chunk.size = qbarray.size();
|
||||
chunk.data = (void*)qbarray.constData();
|
||||
chunk.type = RsVoipDataChunk::RS_VOIP_DATA_TYPE_AUDIO ;
|
||||
rsVoip->sendVoipData(mChatWidget->getPeerId(),chunk);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ private slots:
|
|||
|
||||
public slots:
|
||||
void sendAudioData();
|
||||
void sendVideoData();
|
||||
|
||||
protected:
|
||||
// Audio input/output
|
||||
|
|
|
|||
|
|
@ -24,8 +24,16 @@ bool VideoEncoder::addImage(const QImage& img)
|
|||
|
||||
encodeData(img) ;
|
||||
|
||||
if(_echo_output_device != NULL)
|
||||
_echo_output_device->showFrame(img) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool VideoEncoder::nextPacket(RsVoipDataChunk& chunk)
|
||||
{
|
||||
if(_out_queue.empty())
|
||||
return false ;
|
||||
|
||||
chunk = _out_queue.front() ;
|
||||
_out_queue.pop_front() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
|
@ -40,7 +48,10 @@ QImage JPEGVideoDecoder::decodeData(const unsigned char *encoded_image_data,uint
|
|||
QByteArray qb((char*)encoded_image_data,size) ;
|
||||
QImage image ;
|
||||
if(image.loadFromData(qb))
|
||||
{
|
||||
std::cerr << "image decoded successfully" << std::endl;
|
||||
return image ;
|
||||
}
|
||||
else
|
||||
return QImage() ;
|
||||
}
|
||||
|
|
@ -55,6 +66,13 @@ void JPEGVideoEncoder::encodeData(const QImage& image)
|
|||
|
||||
//destination_decoder->receiveEncodedData((unsigned char *)qb.data(),qb.size()) ;
|
||||
|
||||
std::cerr <<"sending encoded data. size = " << qb.size() << std::endl;
|
||||
RsVoipDataChunk voip_chunk ;
|
||||
voip_chunk.data = malloc(qb.size());
|
||||
voip_chunk.size = qb.size() ;
|
||||
voip_chunk.type = RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO ;
|
||||
|
||||
_out_queue.push_back(voip_chunk) ;
|
||||
|
||||
std::cerr << "sending encoded data. size = " << qb.size() << std::endl;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <QImage>
|
||||
#include "interface/rsvoip.h"
|
||||
|
||||
class QVideoOutputDevice ;
|
||||
|
||||
|
|
@ -43,20 +44,19 @@ class VideoDecoder
|
|||
class VideoEncoder
|
||||
{
|
||||
public:
|
||||
VideoEncoder() { _echo_output_device = NULL ;}
|
||||
VideoEncoder() {}
|
||||
|
||||
// Takes the next image to be encoded.
|
||||
//
|
||||
virtual bool addImage(const QImage& Image) ;
|
||||
bool addImage(const QImage& Image) ;
|
||||
|
||||
bool packetReady() const { return !_out_queue.empty() ; }
|
||||
bool nextPacket(RsVoipDataChunk& ) ;
|
||||
protected:
|
||||
//virtual bool sendEncodedData(unsigned char *mem,uint32_t size) = 0 ;
|
||||
virtual void encodeData(const QImage& image) = 0 ;
|
||||
|
||||
unsigned char *buffer ;
|
||||
uint32_t buffer_size ;
|
||||
|
||||
QVideoOutputDevice *_echo_output_device ;
|
||||
std::list<RsVoipDataChunk> _out_queue ;
|
||||
};
|
||||
|
||||
// Now derive various image encoding/decoding algorithms.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue