| #include <memory> |
| 6 | #include "ThreadLocalObject.h" |
| 7 | #include "api/media_stream_interface.h" |
| 8 | #include "platform/PlatformInterface.h" |
| 9 |
| 10 | namespace tgcalls { |
| 11 |
| 12 | class VideoCapturerInterface; |
| 13 | class Threads; |
| 14 |
| 15 | class VideoCaptureInterfaceObject { |
| 16 | public: |
| 17 | VideoCaptureInterfaceObject(std::string deviceId, bool isScreenCapture, std::shared_ptr<PlatformContext> platformContext, Threads &threads); |
| 18 | ~VideoCaptureInterfaceObject(); |
| 19 |
| 20 | void switchToDevice(std::string deviceId, bool isScreenCapture); |
| 21 | void withNativeImplementation(std::function<void(void *)> completion); |
| 22 | void setState(VideoState state); |
| 23 | void setPreferredAspectRatio(float aspectRatio); |
| 24 | void setOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink); |
| 25 | void setStateUpdated(std::function<void(VideoState)> stateUpdated); |
| 26 | void setRotationUpdated(std::function<void(int)> rotationUpdated); |
| 27 | void setOnFatalError(std::function<void()> error); |
| 28 | void setOnPause(std::function<void(bool)> pause); |
| 29 | void setOnIsActiveUpdated(std::function<void(bool)> onIsActiveUpdated); |
| 30 | webrtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source(); |
| 31 | int getRotation(); |
| 32 | bool isScreenCapture(); |
| 33 |
| 34 | private: |
| 35 | void updateAspectRateAdaptation(); |
| 36 |
| 37 | webrtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _videoSource; |
| 38 | std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _currentUncroppedSink; |
| 39 | std::shared_ptr<PlatformContext> _platformContext; |
| 40 | std::pair<int, int> _videoCapturerResolution; |
| 41 | std::unique_ptr<VideoCapturerInterface> _videoCapturer; |
| 42 | std::function<void(VideoState)> _stateUpdated; |
| 43 | std::function<void()> _onFatalError; |
| 44 | std::function<void(bool)> _onPause; |
| 45 | std::function<void(bool)> _onIsActiveUpdated; |
| 46 | std::function<void(int)> _rotationUpdated; |
| 47 | VideoState _state = VideoState::Active; |
| 48 | float _preferredAspectRatio = 0.0f; |
| 49 | bool _shouldBeAdaptedToReceiverAspectRate = true; |
| 50 | bool _isScreenCapture = false; |
| 51 | }; |
| 52 |
| 53 | class VideoCaptureInterfaceImpl : public VideoCaptureInterface { |
| 54 | public: |
| 55 | VideoCaptureInterfaceImpl(std::string deviceId, bool isScreenCapture, std::shared_ptr<PlatformContext> platformContext, std::shared_ptr<Threads> threads); |
| 56 | virtual ~VideoCaptureInterfaceImpl(); |
| 57 |
| 58 | void switchToDevice(std::string deviceId, bool isScreenCapture) override; |
| 59 | void withNativeImplementation(std::function<void(void *)> completion) override; |
| 60 | void setState(VideoState state) override; |
| 61 | void setPreferredAspectRatio(float aspectRatio) override; |
| 62 | void setOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) override; |
| 63 | void setOnFatalError(std::function<void()> error) override; |
| 64 | void setOnPause(std::function<void(bool)> pause) override; |
| 65 | void setOnIsActiveUpdated(std::function<void(bool)> onIsActiveUpdated) override; |
| 66 | std::shared_ptr<PlatformContext> getPlatformContext() override; |
| 67 |
| 68 | ThreadLocalObject<VideoCaptureInterfaceObject> *object(); |
| 69 |
| 70 | private: |
| 71 | ThreadLocalObject<VideoCaptureInterfaceObject> _impl; |
| 72 |
| 73 | std::shared_ptr<PlatformContext> _platformContext; |
| 74 |
| 75 | }; |
| 76 |
| 77 | } // namespace tgcalls |
| 78 |
| 79 | #endif |
| 80 |