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