mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Rename methods in CameraSource
To make the method more correctly reflect the essence
This commit is contained in:
parent
3c21af200c
commit
3b2352a0ee
|
@ -130,8 +130,8 @@ ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av)
|
|||
videoSource = new CoreVideoSource;
|
||||
CameraSource& source = CameraSource::getInstance();
|
||||
|
||||
if (!source.isOpen())
|
||||
source.open();
|
||||
if (source.isNone())
|
||||
source.setupDefault();
|
||||
source.subscribe();
|
||||
QObject::connect(&source, &VideoSource::frameAvailable,
|
||||
[FriendNum, &av](shared_ptr<VideoFrame> frame) {
|
||||
|
|
|
@ -99,7 +99,7 @@ CameraSource::CameraSource()
|
|||
, cctxOrig{nullptr}
|
||||
#endif
|
||||
, videoStreamIndex{-1}
|
||||
, _isOpen{false}
|
||||
, _isNone{true}
|
||||
, streamBlocker{false}
|
||||
, subscriptions{0}
|
||||
{
|
||||
|
@ -129,17 +129,15 @@ void CameraSource::destroyInstance()
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Opens the source for the camera device.
|
||||
* @brief Setup default device
|
||||
* @note If a device is already open, the source will seamlessly switch to the new device.
|
||||
*
|
||||
* Opens the source for the camera device in argument, in the settings, or the system default.
|
||||
*/
|
||||
void CameraSource::open()
|
||||
void CameraSource::setupDefault()
|
||||
{
|
||||
open(CameraDevice::getDefaultDeviceName());
|
||||
setupDevice(CameraDevice::getDefaultDeviceName());
|
||||
}
|
||||
|
||||
void CameraSource::open(const QString& deviceName)
|
||||
void CameraSource::setupDevice(const QString& deviceName)
|
||||
{
|
||||
bool isScreen = CameraDevice::isScreen(deviceName);
|
||||
VideoMode mode = VideoMode(Settings::getInstance().getScreenRegion());
|
||||
|
@ -148,10 +146,14 @@ void CameraSource::open(const QString& deviceName)
|
|||
mode.FPS = Settings::getInstance().getCamVideoFPS();
|
||||
}
|
||||
|
||||
open(deviceName, mode);
|
||||
setupDevice(deviceName, mode);
|
||||
}
|
||||
|
||||
void CameraSource::open(const QString& DeviceName, const VideoMode& Mode)
|
||||
/**
|
||||
* @brief Change the device and mode.
|
||||
* @note If a device is already open, the source will seamlessly switch to the new device.
|
||||
*/
|
||||
void CameraSource::setupDevice(const QString& DeviceName, const VideoMode& Mode)
|
||||
{
|
||||
QWriteLocker locker{&streamMutex};
|
||||
|
||||
|
@ -164,32 +166,27 @@ void CameraSource::open(const QString& DeviceName, const VideoMode& Mode)
|
|||
|
||||
deviceName = DeviceName;
|
||||
mode = Mode;
|
||||
_isOpen = (deviceName != "none");
|
||||
_isNone = (deviceName == "none");
|
||||
|
||||
if (subscriptions && _isOpen)
|
||||
if (subscriptions && !_isNone)
|
||||
openDevice();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stops streaming.
|
||||
*
|
||||
* Equivalent to opening the source with the video device "none".
|
||||
*/
|
||||
void CameraSource::close()
|
||||
{
|
||||
open("none");
|
||||
setupDevice("none");
|
||||
}
|
||||
|
||||
bool CameraSource::isOpen()
|
||||
bool CameraSource::isNone() const
|
||||
{
|
||||
return _isOpen;
|
||||
return _isNone;
|
||||
}
|
||||
|
||||
CameraSource::~CameraSource()
|
||||
{
|
||||
QWriteLocker locker{&streamMutex};
|
||||
|
||||
if (!_isOpen) {
|
||||
if (_isNone) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -223,7 +220,7 @@ bool CameraSource::subscribe()
|
|||
{
|
||||
QWriteLocker locker{&streamMutex};
|
||||
|
||||
if (!_isOpen) {
|
||||
if (_isNone) {
|
||||
++subscriptions;
|
||||
return true;
|
||||
}
|
||||
|
@ -248,7 +245,7 @@ void CameraSource::unsubscribe()
|
|||
{
|
||||
QWriteLocker locker{&streamMutex};
|
||||
|
||||
if (!_isOpen) {
|
||||
if (_isNone) {
|
||||
--subscriptions;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -39,11 +39,11 @@ class CameraSource : public VideoSource
|
|||
public:
|
||||
static CameraSource& getInstance();
|
||||
static void destroyInstance();
|
||||
void open();
|
||||
void open(const QString& deviceName);
|
||||
void open(const QString& deviceName, const VideoMode& mode);
|
||||
void setupDefault();
|
||||
void setupDevice(const QString& deviceName);
|
||||
void setupDevice(const QString& deviceName, const VideoMode& mode);
|
||||
void close();
|
||||
bool isOpen();
|
||||
bool isNone() const;
|
||||
|
||||
// VideoSource interface
|
||||
virtual bool subscribe() override;
|
||||
|
@ -69,7 +69,8 @@ private:
|
|||
AVCodecContext* cctxOrig;
|
||||
int videoStreamIndex;
|
||||
QReadWriteLock streamMutex;
|
||||
std::atomic_bool _isOpen;
|
||||
|
||||
std::atomic_bool _isNone;
|
||||
std::atomic_bool streamBlocker;
|
||||
std::atomic_int subscriptions;
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ void AVForm::open(const QString& devName, const VideoMode& mode)
|
|||
QRect rect = mode.toRect();
|
||||
Settings::getInstance().setCamVideoRes(rect);
|
||||
Settings::getInstance().setCamVideoFPS(static_cast<quint16>(mode.FPS));
|
||||
camera.open(devName, mode);
|
||||
camera.setupDevice(devName, mode);
|
||||
}
|
||||
|
||||
void AVForm::rescanDevices()
|
||||
|
@ -393,7 +393,7 @@ void AVForm::on_videoDevCombobox_currentIndexChanged(int index)
|
|||
if (0 < modeIndex && modeIndex < videoModes.size())
|
||||
mode = videoModes[modeIndex];
|
||||
|
||||
camera.open(dev, mode);
|
||||
camera.setupDevice(dev, mode);
|
||||
if (dev == "none")
|
||||
Core::getInstance()->getAv()->sendNoVideo();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user