2020-08-14 18:58:22 +02:00
|
|
|
#ifndef TGCALLS_VIDEO_CAPTURE_INTERFACE_IMPL_H
|
|
|
|
#define TGCALLS_VIDEO_CAPTURE_INTERFACE_IMPL_H
|
|
|
|
|
|
|
|
#include "VideoCaptureInterface.h"
|
|
|
|
#include <memory>
|
|
|
|
#include "ThreadLocalObject.h"
|
|
|
|
#include "api/media_stream_interface.h"
|
|
|
|
#include "platform/PlatformInterface.h"
|
|
|
|
|
|
|
|
namespace tgcalls {
|
|
|
|
|
|
|
|
class VideoCapturerInterface;
|
|
|
|
|
|
|
|
class VideoCaptureInterfaceObject {
|
|
|
|
public:
|
2020-10-01 03:59:32 +02:00
|
|
|
VideoCaptureInterfaceObject(std::string deviceId, std::shared_ptr<PlatformContext> platformContext);
|
2020-08-14 18:58:22 +02:00
|
|
|
~VideoCaptureInterfaceObject();
|
|
|
|
|
2020-10-01 03:59:32 +02:00
|
|
|
void switchToDevice(std::string deviceId);
|
2020-08-14 18:58:22 +02:00
|
|
|
void setState(VideoState state);
|
|
|
|
void setPreferredAspectRatio(float aspectRatio);
|
|
|
|
void setOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
|
|
|
|
void setStateUpdated(std::function<void(VideoState)> stateUpdated);
|
2020-10-01 03:59:32 +02:00
|
|
|
webrtc::VideoTrackSourceInterface *source();
|
2020-08-14 18:58:22 +02:00
|
|
|
|
|
|
|
private:
|
2020-10-01 03:59:32 +02:00
|
|
|
void updateAspectRateAdaptation();
|
|
|
|
|
|
|
|
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _videoSource;
|
2020-08-14 18:58:22 +02:00
|
|
|
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _currentUncroppedSink;
|
|
|
|
std::shared_ptr<PlatformContext> _platformContext;
|
2020-08-15 23:06:36 +02:00
|
|
|
std::pair<int, int> _videoCapturerResolution;
|
2020-08-14 18:58:22 +02:00
|
|
|
std::unique_ptr<VideoCapturerInterface> _videoCapturer;
|
|
|
|
std::function<void(VideoState)> _stateUpdated;
|
|
|
|
VideoState _state = VideoState::Active;
|
2020-10-01 03:59:32 +02:00
|
|
|
float _preferredAspectRatio = 0.0f;
|
|
|
|
bool _shouldBeAdaptedToReceiverAspectRate = true;
|
2020-08-14 18:58:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class VideoCaptureInterfaceImpl : public VideoCaptureInterface {
|
|
|
|
public:
|
2020-10-01 03:59:32 +02:00
|
|
|
VideoCaptureInterfaceImpl(std::string deviceId, std::shared_ptr<PlatformContext> platformContext);
|
2020-08-14 18:58:22 +02:00
|
|
|
virtual ~VideoCaptureInterfaceImpl();
|
|
|
|
|
2020-10-01 03:59:32 +02:00
|
|
|
void switchToDevice(std::string deviceId) override;
|
2020-08-14 18:58:22 +02:00
|
|
|
void setState(VideoState state) override;
|
|
|
|
void setPreferredAspectRatio(float aspectRatio) override;
|
|
|
|
void setOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) override;
|
2020-08-22 01:59:49 +02:00
|
|
|
std::shared_ptr<PlatformContext> getPlatformContext() override;
|
2020-08-14 18:58:22 +02:00
|
|
|
|
|
|
|
ThreadLocalObject<VideoCaptureInterfaceObject> *object();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ThreadLocalObject<VideoCaptureInterfaceObject> _impl;
|
2020-08-22 01:59:49 +02:00
|
|
|
std::shared_ptr<PlatformContext> _platformContext;
|
2020-08-14 18:58:22 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace tgcalls
|
|
|
|
|
|
|
|
#endif
|