| 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 | namespace tgvoip{ |
| 16 | namespace video{ |
| 17 | class VideoToolboxEncoderSource : public VideoSource{ |
| 18 | public: |
| 19 | VideoToolboxEncoderSource(); |
| 20 | virtual ~VideoToolboxEncoderSource(); |
| 21 | virtual void Start() override; |
| 22 | virtual void Stop() override; |
| 23 | virtual void Reset(uint32_t codec, int maxResolution) override; |
| 24 | virtual void RequestKeyFrame() override; |
| 25 | virtual void SetBitrate(uint32_t bitrate) override; |
| 26 | void EncodeFrame(CMSampleBufferRef frame); |
| 27 | static std::vector<uint32_t> GetAvailableEncoders(); |
| 28 | private: |
| 29 | void EncoderCallback(OSStatus status, CMSampleBufferRef buffer, VTEncodeInfoFlags flags); |
| 30 | void SetEncoderBitrateAndLimit(uint32_t bitrate); |
| 31 | bool needUpdateStreamParams=true; |
| 32 | uint32_t codec=0; |
| 33 | VTCompressionSessionRef session=NULL; |
| 34 | bool keyframeRequested=false; |
| 35 | uint32_t bitrateChangeRequested=0; |
| 36 | uint32_t lastBitrate=512*1024; |
| 37 | }; |
| 38 | } |
| 39 | } |
| 40 |
| 41 | #endif /* LIBTGVOIP_VIDEOTOOLBOXENCODERSOURCE */ |
| 42 |