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())
|
||||
return nullptr;
|
||||
|
||||
if (devName == "none")
|
||||
{
|
||||
qDebug() << "Tried to open the null device";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AVDictionary* options = nullptr;
|
||||
if (false);
|
||||
#ifdef Q_OS_LINUX
|
||||
|
@ -244,16 +250,18 @@ QVector<QPair<QString, QString>> CameraDevice::getDeviceList()
|
|||
{
|
||||
QVector<QPair<QString, QString>> devices;
|
||||
|
||||
devices.append({"none", "None"});
|
||||
|
||||
if (!getDefaultInputFormat())
|
||||
return devices;
|
||||
|
||||
if (false);
|
||||
#ifdef Q_OS_WIN
|
||||
else if (iformat->name == QString("dshow"))
|
||||
devices = DirectShow::getDeviceList();
|
||||
devices += DirectShow::getDeviceList();
|
||||
#endif
|
||||
else
|
||||
devices = getRawDeviceListGeneric();
|
||||
devices += getRawDeviceListGeneric();
|
||||
|
||||
if (idesktopFormat)
|
||||
{
|
||||
|
|
|
@ -49,6 +49,8 @@ CameraSource::CameraSource(const QString deviceName, VideoMode mode)
|
|||
{
|
||||
av_register_all();
|
||||
avdevice_register_all();
|
||||
|
||||
isNull = (deviceName == "none");
|
||||
}
|
||||
|
||||
CameraSource::~CameraSource()
|
||||
|
@ -60,6 +62,12 @@ CameraSource::~CameraSource()
|
|||
expected = false;
|
||||
}
|
||||
|
||||
if (isNull)
|
||||
{
|
||||
biglock = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Free all remaining VideoFrame
|
||||
// Locking must be done precisely this way to avoid races
|
||||
for (int i=0; i<freelist.size(); i++)
|
||||
|
@ -94,6 +102,12 @@ bool CameraSource::subscribe()
|
|||
expected = false;
|
||||
}
|
||||
|
||||
if (isNull)
|
||||
{
|
||||
biglock = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (device)
|
||||
{
|
||||
device->open();
|
||||
|
@ -111,6 +125,7 @@ bool CameraSource::subscribe()
|
|||
if (!device)
|
||||
{
|
||||
biglock = false;
|
||||
qWarning() << "Failed to open device!";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -173,6 +188,12 @@ void CameraSource::unsubscribe()
|
|||
expected = false;
|
||||
}
|
||||
|
||||
if (isNull)
|
||||
{
|
||||
biglock = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!device)
|
||||
{
|
||||
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
|
||||
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
|
||||
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
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user