Telegram-Android/TMessagesProj/jni/voip/tgcalls/VideoCaptureInterfaceImpl.h

81 lines
3 KiB
C
Raw Normal View History

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;
2021-03-19 11:25:58 +01:00
class Threads;
2020-08-14 18:58:22 +02:00
class VideoCaptureInterfaceObject {
public:
2021-03-19 11:25:58 +01:00
VideoCaptureInterfaceObject(std::string deviceId, std::shared_ptr<PlatformContext> platformContext, Threads &threads);
2020-08-14 18:58:22 +02:00
~VideoCaptureInterfaceObject();
2020-10-01 03:59:32 +02:00
void switchToDevice(std::string deviceId);
2021-06-25 02:43:10 +02:00
void withNativeImplementation(std::function<void(void *)> completion);
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);
2021-06-25 02:43:10 +02: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);
2020-10-01 03:59:32 +02:00
webrtc::VideoTrackSourceInterface *source();
2021-06-25 02:43:10 +02:00
int getRotation();
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;
2021-06-25 02:43:10 +02:00
std::function<void()> _onFatalError;
std::function<void(bool)> _onPause;
std::function<void(bool)> _onIsActiveUpdated;
std::function<void(int)> _rotationUpdated;
2020-08-14 18:58:22 +02:00
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:
2021-07-30 16:49:55 +02:00
VideoCaptureInterfaceImpl(std::string deviceId, bool isScreenCapture, std::shared_ptr<PlatformContext> platformContext, std::shared_ptr<Threads> threads);
2020-08-14 18:58:22 +02:00
virtual ~VideoCaptureInterfaceImpl();
2021-07-30 16:49:55 +02:00
bool isScreenCapture() override;
2020-10-01 03:59:32 +02:00
void switchToDevice(std::string deviceId) override;
2021-06-25 02:43:10 +02:00
void withNativeImplementation(std::function<void(void *)> completion) 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;
2021-06-25 02:43:10 +02: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 18:58:22 +02:00
ThreadLocalObject<VideoCaptureInterfaceObject> *object();
private:
ThreadLocalObject<VideoCaptureInterfaceObject> _impl;
2021-07-30 16:49:55 +02:00
bool _isScreenCapture = false;
std::shared_ptr<PlatformContext> _platformContext;
2020-08-14 18:58:22 +02:00
};
} // namespace tgcalls
#endif