2014-07-13 09:57:25 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <QImage>
|
2015-05-11 15:40:07 -04:00
|
|
|
#include "interface/rsVOIP.h"
|
2014-07-13 09:57:25 -04:00
|
|
|
|
2015-08-23 22:39:16 -04:00
|
|
|
extern "C" {
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
}
|
|
|
|
|
2014-07-13 09:57:25 -04:00
|
|
|
class QVideoOutputDevice ;
|
|
|
|
|
2015-08-14 16:44:20 -04:00
|
|
|
class VideoCodec
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool encodeData(const QImage& Image, uint32_t size_hint, RsVOIPDataChunk& chunk) = 0;
|
|
|
|
virtual bool decodeData(const RsVOIPDataChunk& chunk,QImage& image) = 0;
|
2015-08-16 22:59:49 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static const uint32_t HEADER_SIZE = 0x04 ;
|
2015-08-14 16:44:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Now derive various image encoding/decoding algorithms.
|
|
|
|
//
|
|
|
|
|
|
|
|
class JPEGVideo: public VideoCodec
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
JPEGVideo() ;
|
|
|
|
|
|
|
|
protected:
|
2015-08-29 21:48:58 -04:00
|
|
|
virtual bool encodeData(const QImage& Image, uint32_t target_encoding_bitrate, RsVOIPDataChunk& chunk) ;
|
2015-08-14 16:44:20 -04:00
|
|
|
virtual bool decodeData(const RsVOIPDataChunk& chunk,QImage& image) ;
|
|
|
|
|
|
|
|
static const uint32_t JPEG_VIDEO_FLAGS_DIFFERENTIAL_FRAME = 0x0001 ;
|
|
|
|
private:
|
|
|
|
QImage _decoded_reference_frame ;
|
|
|
|
QImage _encoded_reference_frame ;
|
|
|
|
|
|
|
|
uint32_t _encoded_ref_frame_max_distance ; // max distance between two reference frames.
|
|
|
|
uint32_t _encoded_ref_frame_count ;
|
|
|
|
};
|
|
|
|
|
2015-08-19 21:50:51 -04:00
|
|
|
struct AVCodec ;
|
|
|
|
struct AVCodecContext ;
|
|
|
|
struct AVFrame ;
|
2015-08-23 22:39:16 -04:00
|
|
|
struct AVPacket ;
|
2015-08-19 21:50:51 -04:00
|
|
|
|
|
|
|
class FFmpegVideo: public VideoCodec
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FFmpegVideo() ;
|
|
|
|
~FFmpegVideo() ;
|
|
|
|
|
|
|
|
protected:
|
2015-08-29 21:48:58 -04:00
|
|
|
virtual bool encodeData(const QImage& Image, uint32_t target_encoding_bitrate, RsVOIPDataChunk& chunk) ;
|
2015-08-19 21:50:51 -04:00
|
|
|
virtual bool decodeData(const RsVOIPDataChunk& chunk,QImage& image) ;
|
|
|
|
|
|
|
|
private:
|
2015-08-19 22:17:50 -04:00
|
|
|
AVCodec *encoding_codec;
|
|
|
|
AVCodec *decoding_codec;
|
|
|
|
AVCodecContext *encoding_context;
|
|
|
|
AVCodecContext *decoding_context;
|
|
|
|
AVFrame *encoding_frame_buffer ;
|
|
|
|
AVFrame *decoding_frame_buffer ;
|
2015-08-23 22:39:16 -04:00
|
|
|
AVPacket decoding_buffer;
|
2015-08-19 22:17:50 -04:00
|
|
|
uint64_t encoding_frame_count ;
|
2015-08-20 22:59:51 -04:00
|
|
|
|
|
|
|
FILE *encoding_debug_file ;
|
2015-08-19 21:50:51 -04:00
|
|
|
};
|
|
|
|
|
2014-07-13 09:57:25 -04:00
|
|
|
// This class decodes video from a stream. It keeps a queue of
|
|
|
|
// decoded frame that needs to be retrieved using the getNextImage() method.
|
|
|
|
//
|
2015-08-14 16:44:20 -04:00
|
|
|
class VideoProcessor
|
2014-07-13 09:57:25 -04:00
|
|
|
{
|
|
|
|
public:
|
2015-08-14 16:44:20 -04:00
|
|
|
VideoProcessor() ;
|
2015-08-24 21:42:01 -04:00
|
|
|
virtual ~VideoProcessor() ;
|
2015-08-14 16:44:20 -04:00
|
|
|
|
|
|
|
enum CodecId {
|
|
|
|
VIDEO_PROCESSOR_CODEC_ID_UNKNOWN = 0x0000,
|
|
|
|
VIDEO_PROCESSOR_CODEC_ID_JPEG_VIDEO = 0x0001,
|
2015-08-19 21:50:51 -04:00
|
|
|
VIDEO_PROCESSOR_CODEC_ID_DDWT_VIDEO = 0x0002,
|
|
|
|
VIDEO_PROCESSOR_CODEC_ID_MPEG_VIDEO = 0x0003
|
2015-08-14 16:44:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// =====================================================================================
|
|
|
|
// =------------------------------------ DECODING -------------------------------------=
|
|
|
|
// =====================================================================================
|
|
|
|
|
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.
|
|
|
|
//
|
2015-08-14 16:44:20 -04:00
|
|
|
void setDisplayTarget(QVideoOutputDevice *odev) { _decoded_output_device = odev ; }
|
|
|
|
virtual void receiveEncodedData(const RsVOIPDataChunk& chunk) ;
|
2014-07-13 09:57:25 -04:00
|
|
|
|
2014-07-20 16:50:36 -04:00
|
|
|
// returns the current (measured) frame rate in bytes per second.
|
|
|
|
//
|
2015-08-24 21:15:33 -04:00
|
|
|
uint32_t currentBandwidthIn() const { return _estimated_bandwidth_in ; }
|
2014-07-20 16:50:36 -04:00
|
|
|
|
2014-07-13 09:57:25 -04:00
|
|
|
private:
|
2015-08-14 16:44:20 -04:00
|
|
|
QVideoOutputDevice *_decoded_output_device ;
|
|
|
|
std::list<QImage> _decoded_image_queue ;
|
2014-07-13 09:57:25 -04:00
|
|
|
|
2015-08-14 16:44:20 -04:00
|
|
|
// =====================================================================================
|
|
|
|
// =------------------------------------ ENCODING -------------------------------------=
|
|
|
|
// =====================================================================================
|
|
|
|
|
2014-07-13 09:57:25 -04:00
|
|
|
public:
|
|
|
|
// Takes the next image to be encoded.
|
|
|
|
//
|
2015-08-29 21:48:58 -04:00
|
|
|
bool processImage(const QImage& Image) ;
|
2015-08-14 16:44:20 -04:00
|
|
|
bool encodedPacketReady() const { return !_encoded_out_queue.empty() ; }
|
|
|
|
bool nextEncodedPacket(RsVOIPDataChunk& ) ;
|
2014-07-20 16:50:36 -04:00
|
|
|
|
|
|
|
// Used to tweak the compression ratio so that the video can stream ok.
|
|
|
|
//
|
2015-08-24 21:15:33 -04:00
|
|
|
void setMaximumBandwidth(uint32_t bytes_per_second) ;
|
2015-08-09 18:09:17 -04:00
|
|
|
void setInternalFrameSize(QSize) ;
|
|
|
|
|
2015-08-24 21:15:33 -04:00
|
|
|
// returns the current encoding frame rate in bytes per second.
|
|
|
|
//
|
|
|
|
uint32_t currentBandwidthOut() const { return _estimated_bandwidth_out ; }
|
|
|
|
|
2014-07-13 09:57:25 -04:00
|
|
|
protected:
|
2015-08-14 16:44:20 -04:00
|
|
|
std::list<RsVOIPDataChunk> _encoded_out_queue ;
|
|
|
|
QSize _encoded_frame_size ;
|
|
|
|
|
|
|
|
// =====================================================================================
|
|
|
|
// =------------------------------------- Codecs --------------------------------------=
|
|
|
|
// =====================================================================================
|
2015-08-10 22:13:50 -04:00
|
|
|
|
2015-08-19 21:50:51 -04:00
|
|
|
JPEGVideo _jpeg_video_codec ;
|
|
|
|
FFmpegVideo _mpeg_video_codec ;
|
2015-08-14 16:44:20 -04:00
|
|
|
|
|
|
|
uint16_t _encoding_current_codec ;
|
2015-08-24 21:15:33 -04:00
|
|
|
|
|
|
|
time_t _last_bw_estimate_in_TS;
|
|
|
|
time_t _last_bw_estimate_out_TS;
|
|
|
|
|
|
|
|
uint32_t _total_encoded_size_in ;
|
|
|
|
uint32_t _total_encoded_size_out ;
|
|
|
|
|
|
|
|
float _estimated_bandwidth_in ;
|
|
|
|
float _estimated_bandwidth_out ;
|
|
|
|
|
|
|
|
float _target_bandwidth_out ;
|
2015-08-24 21:42:01 -04:00
|
|
|
|
|
|
|
RsMutex vpMtx ;
|
2014-07-13 09:57:25 -04:00
|
|
|
};
|
|
|
|
|