mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
parent
87ec98b111
commit
9c87d5ed2e
|
@ -97,6 +97,12 @@ CameraDevice* CameraDevice::open(QString devName, VideoMode mode)
|
||||||
if (!getDefaultInputFormat())
|
if (!getDefaultInputFormat())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
if (devName == "none")
|
||||||
|
{
|
||||||
|
qDebug() << "Tried to open the null device";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
AVDictionary* options = nullptr;
|
AVDictionary* options = nullptr;
|
||||||
if (false);
|
if (false);
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
|
@ -244,16 +250,18 @@ QVector<QPair<QString, QString>> CameraDevice::getDeviceList()
|
||||||
{
|
{
|
||||||
QVector<QPair<QString, QString>> devices;
|
QVector<QPair<QString, QString>> devices;
|
||||||
|
|
||||||
|
devices.append({"none", "None"});
|
||||||
|
|
||||||
if (!getDefaultInputFormat())
|
if (!getDefaultInputFormat())
|
||||||
return devices;
|
return devices;
|
||||||
|
|
||||||
if (false);
|
if (false);
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
else if (iformat->name == QString("dshow"))
|
else if (iformat->name == QString("dshow"))
|
||||||
devices = DirectShow::getDeviceList();
|
devices += DirectShow::getDeviceList();
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
devices = getRawDeviceListGeneric();
|
devices += getRawDeviceListGeneric();
|
||||||
|
|
||||||
if (idesktopFormat)
|
if (idesktopFormat)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,8 @@ CameraSource::CameraSource(const QString deviceName, VideoMode mode)
|
||||||
{
|
{
|
||||||
av_register_all();
|
av_register_all();
|
||||||
avdevice_register_all();
|
avdevice_register_all();
|
||||||
|
|
||||||
|
isNull = (deviceName == "none");
|
||||||
}
|
}
|
||||||
|
|
||||||
CameraSource::~CameraSource()
|
CameraSource::~CameraSource()
|
||||||
|
@ -60,6 +62,12 @@ CameraSource::~CameraSource()
|
||||||
expected = false;
|
expected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNull)
|
||||||
|
{
|
||||||
|
biglock = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Free all remaining VideoFrame
|
// Free all remaining VideoFrame
|
||||||
// Locking must be done precisely this way to avoid races
|
// Locking must be done precisely this way to avoid races
|
||||||
for (int i=0; i<freelist.size(); i++)
|
for (int i=0; i<freelist.size(); i++)
|
||||||
|
@ -94,6 +102,12 @@ bool CameraSource::subscribe()
|
||||||
expected = false;
|
expected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNull)
|
||||||
|
{
|
||||||
|
biglock = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (device)
|
if (device)
|
||||||
{
|
{
|
||||||
device->open();
|
device->open();
|
||||||
|
@ -111,6 +125,7 @@ bool CameraSource::subscribe()
|
||||||
if (!device)
|
if (!device)
|
||||||
{
|
{
|
||||||
biglock = false;
|
biglock = false;
|
||||||
|
qWarning() << "Failed to open device!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +188,12 @@ void CameraSource::unsubscribe()
|
||||||
expected = false;
|
expected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNull)
|
||||||
|
{
|
||||||
|
biglock = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!device)
|
if (!device)
|
||||||
{
|
{
|
||||||
qWarning() << "Unsubscribing with zero subscriber";
|
qWarning() << "Unsubscribing with zero subscriber";
|
||||||
|
|
|
@ -73,7 +73,7 @@ private:
|
||||||
VideoMode mode; ///< What mode we tried to open the device in, all zeros means default mode
|
VideoMode mode; ///< What mode we tried to open the device in, all zeros means default mode
|
||||||
AVCodecContext* cctx, *cctxOrig; ///< Codec context of the camera's selected video stream
|
AVCodecContext* cctx, *cctxOrig; ///< Codec context of the camera's selected video stream
|
||||||
int videoStreamIndex; ///< A camera can have multiple streams, this is the one we're decoding
|
int videoStreamIndex; ///< A camera can have multiple streams, this is the one we're decoding
|
||||||
std::atomic_bool biglock, freelistLock; ///< True when locked. Faster than mutexes for video decoding.
|
std::atomic_bool biglock, freelistLock, isNull; ///< True when locked. Faster than mutexes for video decoding.
|
||||||
std::atomic_int subscriptions; ///< Remember how many times we subscribed for RAII
|
std::atomic_int subscriptions; ///< Remember how many times we subscribed for RAII
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user