| 6 |
| 7 | #ifndef LIBTGVOIP_VIDEOTOOLBOXENCODERSOURCE |
| 8 | #define LIBTGVOIP_VIDEOTOOLBOXENCODERSOURCE |
| 9 |
| 10 | #include "../../video/VideoSource.h" |
| 11 | #include <CoreMedia/CoreMedia.h> |
| 12 | #include <VideoToolbox/VideoToolbox.h> |
| 13 | #include <vector> |
| 14 |
| 15 | #ifdef __OBJC__ |
| 16 | @class TGVVideoSource; |
| 17 | #else |
| 18 | typedef struct objc_object TGVVideoSource; |
| 19 | #endif |
| 20 |
| 21 | namespace tgvoip{ |
| 22 | namespace video{ |
| 23 | class VideoToolboxEncoderSource : public VideoSource{ |
| 24 | public: |
| 25 | VideoToolboxEncoderSource(TGVVideoSource* parent); |
| 26 | virtual ~VideoToolboxEncoderSource(); |
| 27 | virtual void Start() override; |
| 28 | virtual void Stop() override; |
| 29 | virtual void Reset(uint32_t codec, int maxResolution) override; |
| 30 | virtual void RequestKeyFrame() override; |
| 31 | virtual void SetBitrate(uint32_t bitrate) override; |
| 32 | void EncodeFrame(CMSampleBufferRef frame); |
| 33 | void SetStreamPaused(bool paused); |
| 34 | static std::vector<uint32_t> GetAvailableEncoders(); |
| 35 | static bool SupportsFullHD(); |
| 36 | private: |
| 37 | void EncoderCallback(OSStatus status, CMSampleBufferRef buffer, VTEncodeInfoFlags flags); |
| 38 | void SetEncoderBitrateAndLimit(uint32_t bitrate); |
| 39 | bool needUpdateStreamParams=true; |
| 40 | uint32_t codec=0; |
| 41 | VTCompressionSessionRef session=NULL; |
| 42 | bool keyframeRequested=false; |
| 43 | uint32_t bitrateChangeRequested=0; |
| 44 | uint32_t lastBitrate=512*1024; |
| 45 | unsigned int lastFrameRate=0; |
| 46 | TGVVideoSource* objcObject; |
| 47 | }; |
| 48 | } |
| 49 | } |
| 50 |
| 51 | #endif /* LIBTGVOIP_VIDEOTOOLBOXENCODERSOURCE */ |
| 52 |