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