Skip to content

Commit

Permalink
Preserve preferred aspect through camera change.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Aug 20, 2020
1 parent 0da5f13 commit b221a08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 5 additions & 7 deletions tgcalls/VideoCaptureInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ VideoCaptureInterfaceObject::VideoCaptureInterfaceObject(std::string deviceId, s
: _videoSource(PlatformInterface::SharedInstance()->makeVideoSource(Manager::getMediaThread(), MediaManager::getWorkerThread())) {
_platformContext = platformContext;
//this should outlive the capturer
if (_videoSource) {
_videoCapturer = PlatformInterface::SharedInstance()->makeVideoCapturer(_videoSource, deviceId, [this](VideoState state) {
if (this->_stateUpdated) {
this->_stateUpdated(state);
}
}, platformContext);
}
switchToDevice(deviceId);
}

VideoCaptureInterfaceObject::~VideoCaptureInterfaceObject() {
Expand All @@ -43,6 +37,9 @@ void VideoCaptureInterfaceObject::switchToDevice(std::string deviceId) {
}, _platformContext);
}
if (_videoCapturer) {
if (_preferredAspectRatio > 0) {
_videoCapturer->setPreferredCaptureAspectRatio(_preferredAspectRatio);
}
if (_currentUncroppedSink) {
_videoCapturer->setUncroppedOutput(_currentUncroppedSink);
}
Expand All @@ -60,6 +57,7 @@ void VideoCaptureInterfaceObject::setState(VideoState state) {
}

void VideoCaptureInterfaceObject::setPreferredAspectRatio(float aspectRatio) {
_preferredAspectRatio = aspectRatio;
if (_videoCapturer) {
_videoCapturer->setPreferredCaptureAspectRatio(aspectRatio);
}
Expand Down
1 change: 1 addition & 0 deletions tgcalls/VideoCaptureInterfaceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class VideoCaptureInterfaceObject {
std::unique_ptr<VideoCapturerInterface> _videoCapturer;
std::function<void(VideoState)> _stateUpdated;
VideoState _state = VideoState::Active;
float _preferredAspectRatio = 0.;
};

class VideoCaptureInterfaceImpl : public VideoCaptureInterface {
Expand Down

0 comments on commit b221a08

Please sign in to comment.