| #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 |
| 14 | class VideoCaptureInterfaceObject { |
| 15 | public: |
| 16 | VideoCaptureInterfaceObject(std::shared_ptr<PlatformContext> platformContext); |
| 17 | ~VideoCaptureInterfaceObject(); |
| 18 |
| 19 | void switchCamera(); |
| 20 | void setState(VideoState state); |
| 21 | void setPreferredAspectRatio(float aspectRatio); |
| 22 | void setOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink); |
| 23 | void setStateUpdated(std::function<void(VideoState)> stateUpdated); |
| 24 |
| 25 | public: |
| 26 | rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _videoSource; |
| 27 |
| 28 | private: |
| 29 | std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _currentUncroppedSink; |
| 30 | std::shared_ptr<PlatformContext> _platformContext; |
| 31 | std::pair<int, int> _videoCapturerResolution; |
| 32 | std::unique_ptr<VideoCapturerInterface> _videoCapturer; |
| 33 | std::function<void(VideoState)> _stateUpdated; |
| 34 | bool _useFrontCamera = true; |
| 35 | VideoState _state = VideoState::Active; |
| 36 | }; |
| 37 |
| 38 | class VideoCaptureInterfaceImpl : public VideoCaptureInterface { |
| 39 | public: |
| 40 | VideoCaptureInterfaceImpl(std::shared_ptr<PlatformContext> platformContext); |
| 41 | virtual ~VideoCaptureInterfaceImpl(); |
| 42 |
| 43 | void switchCamera() override; |
| 44 | void setState(VideoState state) override; |
| 45 | void setPreferredAspectRatio(float aspectRatio) override; |
| 46 | void setOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) override; |
| 47 | std::shared_ptr<PlatformContext> getPlatformContext() override; |
| 48 |
| 49 | ThreadLocalObject<VideoCaptureInterfaceObject> *object(); |
| 50 |
| 51 | private: |
| 52 | ThreadLocalObject<VideoCaptureInterfaceObject> _impl; |
| 53 | std::shared_ptr<PlatformContext> _platformContext; |
| 54 |
| 55 | }; |
| 56 |
| 57 | } // namespace tgcalls |
| 58 |
| 59 | #endif |
| 60 |