2014-07-13 09:57:25 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <QImage>
|
2014-07-15 16:04:31 -04:00
|
|
|
#include "interface/rsvoip.h"
|
2014-07-13 09:57:25 -04:00
|
|
|
|
|
|
|
class QVideoOutputDevice ;
|
|
|
|
|
|
|
|
// This class decodes video from a stream. It keeps a queue of
|
|
|
|
// decoded frame that needs to be retrieved using the getNextImage() method.
|
|
|
|
//
|
|
|
|
class VideoDecoder
|
|
|
|
{
|
|
|
|
public:
|
2014-07-20 16:50:36 -04:00
|
|
|
VideoDecoder() ;
|
2014-07-13 09:57:25 -04:00
|
|
|
|
|
|
|
// Gets the next image to be displayed. Once returned, the image should
|
|
|
|
// be cleared from the incoming queue.
|
|
|
|
//
|
|
|
|
void setDisplayTarget(QVideoOutputDevice *odev) { _output_device = odev ; }
|
|
|
|
|
|
|
|
virtual void receiveEncodedData(const unsigned char *data,uint32_t size) ;
|
|
|
|
|
2014-07-20 16:50:36 -04:00
|
|
|
// returns the current (measured) frame rate in bytes per second.
|
|
|
|
//
|
|
|
|
uint32_t currentFrameRate() const;
|
|
|
|
|
2014-07-13 09:57:25 -04:00
|
|
|
private:
|
|
|
|
QVideoOutputDevice *_output_device ;
|
|
|
|
|
|
|
|
std::list<QImage> _image_queue ;
|
|
|
|
|
|
|
|
// Incoming data is processed by a video codec and converted into images.
|
|
|
|
//
|
|
|
|
virtual QImage decodeData(const unsigned char *encoded_image,uint32_t encoded_image_size) = 0 ;
|
|
|
|
|
2014-07-20 16:50:36 -04:00
|
|
|
// // This buffer accumulated incoming encoded data, until a full packet is obtained,
|
|
|
|
// // since the stream might not send images at once. When incoming images are decoded, the
|
|
|
|
// // data is removed from the buffer.
|
|
|
|
// //
|
|
|
|
// unsigned char *buffer ;
|
|
|
|
// uint32_t buffer_size ;
|
2014-07-13 09:57:25 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// This class encodes video using a video codec (possibly homemade, or based on existing codecs)
|
|
|
|
// and produces a data stream that is sent to the network transfer service (e.g. p3VoRs).
|
|
|
|
//
|
|
|
|
class VideoEncoder
|
|
|
|
{
|
|
|
|
public:
|
2014-07-15 16:04:31 -04:00
|
|
|
VideoEncoder() {}
|
2014-07-13 09:57:25 -04:00
|
|
|
|
|
|
|
// Takes the next image to be encoded.
|
|
|
|
//
|
2014-07-15 16:04:31 -04:00
|
|
|
bool addImage(const QImage& Image) ;
|
2014-07-13 09:57:25 -04:00
|
|
|
|
2014-07-15 16:04:31 -04:00
|
|
|
bool packetReady() const { return !_out_queue.empty() ; }
|
|
|
|
bool nextPacket(RsVoipDataChunk& ) ;
|
2014-07-20 16:50:36 -04:00
|
|
|
|
|
|
|
// Used to tweak the compression ratio so that the video can stream ok.
|
|
|
|
//
|
|
|
|
void setMaximumFrameRate(uint32_t bytes_per_second) ;
|
|
|
|
|
2014-07-13 09:57:25 -04:00
|
|
|
protected:
|
|
|
|
//virtual bool sendEncodedData(unsigned char *mem,uint32_t size) = 0 ;
|
|
|
|
virtual void encodeData(const QImage& image) = 0 ;
|
|
|
|
|
2014-07-15 16:04:31 -04:00
|
|
|
std::list<RsVoipDataChunk> _out_queue ;
|
2014-07-13 09:57:25 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Now derive various image encoding/decoding algorithms.
|
|
|
|
//
|
|
|
|
|
|
|
|
class JPEGVideoDecoder: public VideoDecoder
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual QImage decodeData(const unsigned char *encoded_image,uint32_t encoded_image_size) ;
|
|
|
|
};
|
|
|
|
|
|
|
|
class JPEGVideoEncoder: public VideoEncoder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
JPEGVideoEncoder() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void encodeData(const QImage& Image) ;
|
|
|
|
};
|
|
|
|
|