mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-30 09:56:14 -05:00
c6103b7535
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7463 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) ;
|
|
}
|
|
|