mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
b5bf3ce130
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8231 b45a01b8-16f6-495d-af2f-9b41ad6348cc
74 lines
1.5 KiB
C++
74 lines
1.5 KiB
C++
#include <iostream>
|
|
|
|
#include <QByteArray>
|
|
#include <QBuffer>
|
|
#include <QImage>
|
|
|
|
#include "VideoProcessor.h"
|
|
#include "QVideoDevice.h"
|
|
|
|
VideoDecoder::VideoDecoder()
|
|
{
|
|
_output_device = NULL ;
|
|
}
|
|
|
|
bool VideoEncoder::addImage(const QImage& img)
|
|
{
|
|
encodeData(img) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
bool VideoEncoder::nextPacket(RsVOIPDataChunk& chunk)
|
|
{
|
|
if(_out_queue.empty())
|
|
return false ;
|
|
|
|
chunk = _out_queue.front() ;
|
|
_out_queue.pop_front() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
void VideoDecoder::receiveEncodedData(const unsigned char *data,uint32_t size)
|
|
{
|
|
_output_device->showFrame(decodeData(data,size)) ;
|
|
}
|
|
|
|
QImage JPEGVideoDecoder::decodeData(const unsigned char *encoded_image_data,uint32_t size)
|
|
{
|
|
QByteArray qb((char*)encoded_image_data,size) ;
|
|
QImage image ;
|
|
if(image.loadFromData(qb,"JPEG"))
|
|
return image ;
|
|
else
|
|
{
|
|
std::cerr << "image.loadFromData(): returned an error.: " << std::endl;
|
|
return QImage() ;
|
|
}
|
|
}
|
|
|
|
void VideoEncoder::setMaximumFrameRate(uint32_t bytes_per_sec)
|
|
{
|
|
std::cerr << "Video Encoder: maximum frame rate is set to " << bytes_per_sec << " Bps" << std::endl;
|
|
}
|
|
|
|
|
|
void JPEGVideoEncoder::encodeData(const QImage& image)
|
|
{
|
|
QByteArray qb ;
|
|
|
|
QBuffer buffer(&qb) ;
|
|
buffer.open(QIODevice::WriteOnly) ;
|
|
image.save(&buffer,"JPEG") ;
|
|
|
|
RsVOIPDataChunk voip_chunk ;
|
|
voip_chunk.data = malloc(qb.size());
|
|
memcpy(voip_chunk.data,qb.data(),qb.size()) ;
|
|
voip_chunk.size = qb.size() ;
|
|
voip_chunk.type = RsVOIPDataChunk::RS_VOIP_DATA_TYPE_VIDEO ;
|
|
|
|
_out_queue.push_back(voip_chunk) ;
|
|
}
|
|
|