2019-02-24 13:15:14 +01:00
|
|
|
//
|
|
|
|
// libtgvoip is free and unencumbered public domain software.
|
|
|
|
// For more information, see http://unlicense.org or the UNLICENSE file
|
|
|
|
// you should have received with this source code distribution.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LIBTGVOIP_VIDEOTOOLBOXENCODERSOURCE
|
|
|
|
#define LIBTGVOIP_VIDEOTOOLBOXENCODERSOURCE
|
|
|
|
|
|
|
|
#include "../../video/VideoSource.h"
|
|
|
|
#include <CoreMedia/CoreMedia.h>
|
|
|
|
#include <VideoToolbox/VideoToolbox.h>
|
2019-03-10 23:12:09 +01:00
|
|
|
#include <vector>
|
2019-02-24 13:15:14 +01:00
|
|
|
|
2019-04-15 01:43:10 +02:00
|
|
|
#ifdef __OBJC__
|
|
|
|
@class TGVVideoSource;
|
|
|
|
#else
|
|
|
|
typedef struct objc_object TGVVideoSource;
|
|
|
|
#endif
|
|
|
|
|
2019-02-24 13:15:14 +01:00
|
|
|
namespace tgvoip{
|
|
|
|
namespace video{
|
|
|
|
class VideoToolboxEncoderSource : public VideoSource{
|
|
|
|
public:
|
2019-04-15 01:43:10 +02:00
|
|
|
VideoToolboxEncoderSource(TGVVideoSource* parent);
|
2019-02-24 13:15:14 +01:00
|
|
|
virtual ~VideoToolboxEncoderSource();
|
|
|
|
virtual void Start() override;
|
|
|
|
virtual void Stop() override;
|
|
|
|
virtual void Reset(uint32_t codec, int maxResolution) override;
|
|
|
|
virtual void RequestKeyFrame() override;
|
2019-03-10 23:12:09 +01:00
|
|
|
virtual void SetBitrate(uint32_t bitrate) override;
|
2019-02-24 13:15:14 +01:00
|
|
|
void EncodeFrame(CMSampleBufferRef frame);
|
2019-04-15 01:43:10 +02:00
|
|
|
void SetStreamPaused(bool paused);
|
2019-03-10 23:12:09 +01:00
|
|
|
static std::vector<uint32_t> GetAvailableEncoders();
|
2019-04-15 01:43:10 +02:00
|
|
|
static bool SupportsFullHD();
|
2019-03-10 23:12:09 +01:00
|
|
|
private:
|
|
|
|
void EncoderCallback(OSStatus status, CMSampleBufferRef buffer, VTEncodeInfoFlags flags);
|
|
|
|
void SetEncoderBitrateAndLimit(uint32_t bitrate);
|
|
|
|
bool needUpdateStreamParams=true;
|
|
|
|
uint32_t codec=0;
|
|
|
|
VTCompressionSessionRef session=NULL;
|
|
|
|
bool keyframeRequested=false;
|
|
|
|
uint32_t bitrateChangeRequested=0;
|
|
|
|
uint32_t lastBitrate=512*1024;
|
2019-04-15 01:43:10 +02:00
|
|
|
unsigned int lastFrameRate=0;
|
|
|
|
TGVVideoSource* objcObject;
|
2019-02-24 13:15:14 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LIBTGVOIP_VIDEOTOOLBOXENCODERSOURCE */
|