Nagram/TMessagesProj/jni/voip/tgcalls/VideoCaptureInterfaceImpl.h

80 lines
3.1 KiB
C
Raw Normal View History

2020-08-14 16:58:22 +00: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;
2021-03-19 10:25:58 +00:00
class Threads;
2020-08-14 16:58:22 +00:00
class VideoCaptureInterfaceObject {
public:
2021-08-31 19:06:39 +00:00
VideoCaptureInterfaceObject(std::string deviceId, bool isScreenCapture, std::shared_ptr<PlatformContext> platformContext, Threads &threads);
2020-08-14 16:58:22 +00:00
~VideoCaptureInterfaceObject();
2021-08-31 19:06:39 +00:00
void switchToDevice(std::string deviceId, bool isScreenCapture);
2021-06-25 00:43:10 +00:00
void withNativeImplementation(std::function<void(void *)> completion);
2020-08-14 16:58:22 +00: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);
2021-06-25 00:43:10 +00:00
void setRotationUpdated(std::function<void(int)> rotationUpdated);
void setOnFatalError(std::function<void()> error);
void setOnPause(std::function<void(bool)> pause);
void setOnIsActiveUpdated(std::function<void(bool)> onIsActiveUpdated);
2023-02-18 21:24:25 +00:00
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source();
2021-06-25 00:43:10 +00:00
int getRotation();
2021-08-31 19:06:39 +00:00
bool isScreenCapture();
2020-08-14 16:58:22 +00:00
private:
2020-10-01 01:59:32 +00:00
void updateAspectRateAdaptation();
2021-08-31 19:06:39 +00:00
2020-10-01 01:59:32 +00:00
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _videoSource;
2020-08-14 16:58:22 +00:00
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _currentUncroppedSink;
std::shared_ptr<PlatformContext> _platformContext;
2020-08-15 21:06:36 +00:00
std::pair<int, int> _videoCapturerResolution;
2020-08-14 16:58:22 +00:00
std::unique_ptr<VideoCapturerInterface> _videoCapturer;
std::function<void(VideoState)> _stateUpdated;
2021-06-25 00:43:10 +00:00
std::function<void()> _onFatalError;
std::function<void(bool)> _onPause;
std::function<void(bool)> _onIsActiveUpdated;
std::function<void(int)> _rotationUpdated;
2020-08-14 16:58:22 +00:00
VideoState _state = VideoState::Active;
2020-10-01 01:59:32 +00:00
float _preferredAspectRatio = 0.0f;
bool _shouldBeAdaptedToReceiverAspectRate = true;
2021-08-31 19:06:39 +00:00
bool _isScreenCapture = false;
2020-08-14 16:58:22 +00:00
};
class VideoCaptureInterfaceImpl : public VideoCaptureInterface {
public:
2021-07-30 14:49:55 +00:00
VideoCaptureInterfaceImpl(std::string deviceId, bool isScreenCapture, std::shared_ptr<PlatformContext> platformContext, std::shared_ptr<Threads> threads);
2020-08-14 16:58:22 +00:00
virtual ~VideoCaptureInterfaceImpl();
2021-08-31 19:06:39 +00:00
void switchToDevice(std::string deviceId, bool isScreenCapture) override;
2021-06-25 00:43:10 +00:00
void withNativeImplementation(std::function<void(void *)> completion) override;
2020-08-14 16:58:22 +00:00
void setState(VideoState state) override;
void setPreferredAspectRatio(float aspectRatio) override;
void setOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) override;
2021-06-25 00:43:10 +00:00
void setOnFatalError(std::function<void()> error) override;
void setOnPause(std::function<void(bool)> pause) override;
void setOnIsActiveUpdated(std::function<void(bool)> onIsActiveUpdated) override;
std::shared_ptr<PlatformContext> getPlatformContext() override;
2020-08-14 16:58:22 +00:00
ThreadLocalObject<VideoCaptureInterfaceObject> *object();
private:
ThreadLocalObject<VideoCaptureInterfaceObject> _impl;
2021-07-30 14:49:55 +00:00
std::shared_ptr<PlatformContext> _platformContext;
2020-08-14 16:58:22 +00:00
};
} // namespace tgcalls
#endif