1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Add 'None' video device

Fixes #1825
This commit is contained in:
tux3 2015-06-22 14:59:55 +02:00
parent 87ec98b111
commit 9c87d5ed2e
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
3 changed files with 32 additions and 3 deletions

View File

@ -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)
{

View File

@ -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";

View File

@ -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
};