mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(macOS): Update video API usage for newer libavcodec
Newer version of avformat_open_input, av_find_input_format, avcodec_find_decoder previously used non-const pointers that are now const. Support both version for compatibiltiy with other platforms.
This commit is contained in:
parent
90484a1fdf
commit
15673a52b6
|
@ -31,6 +31,9 @@ extern "C" {
|
||||||
#include "cameradevice.h"
|
#include "cameradevice.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
|
|
||||||
|
// no longer needed when avformat version < 59 is no longer supported
|
||||||
|
using AvFindInputFormatRet = decltype(av_find_input_format(""));
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
||||||
#define USING_V4L 1
|
#define USING_V4L 1
|
||||||
#else
|
#else
|
||||||
|
@ -71,8 +74,8 @@ extern "C" {
|
||||||
|
|
||||||
QHash<QString, CameraDevice*> CameraDevice::openDevices;
|
QHash<QString, CameraDevice*> CameraDevice::openDevices;
|
||||||
QMutex CameraDevice::openDeviceLock, CameraDevice::iformatLock;
|
QMutex CameraDevice::openDeviceLock, CameraDevice::iformatLock;
|
||||||
AVInputFormat* CameraDevice::iformat{nullptr};
|
static AvFindInputFormatRet idesktopFormat{nullptr};
|
||||||
AVInputFormat* CameraDevice::idesktopFormat{nullptr};
|
static AvFindInputFormatRet iformat{nullptr};
|
||||||
|
|
||||||
CameraDevice::CameraDevice(const QString& devName, AVFormatContext* context)
|
CameraDevice::CameraDevice(const QString& devName, AVFormatContext* context)
|
||||||
: devName{devName}
|
: devName{devName}
|
||||||
|
@ -92,7 +95,7 @@ CameraDevice* CameraDevice::open(QString devName, AVDictionary** options)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVInputFormat* format;
|
AvFindInputFormatRet format;
|
||||||
if (devName.startsWith("x11grab#")) {
|
if (devName.startsWith("x11grab#")) {
|
||||||
devName = devName.mid(8);
|
devName = devName.mid(8);
|
||||||
format = idesktopFormat;
|
format = idesktopFormat;
|
||||||
|
|
|
@ -64,5 +64,4 @@ private:
|
||||||
std::atomic_int refcount;
|
std::atomic_int refcount;
|
||||||
static QHash<QString, CameraDevice*> openDevices;
|
static QHash<QString, CameraDevice*> openDevices;
|
||||||
static QMutex openDeviceLock, iformatLock;
|
static QMutex openDeviceLock, iformatLock;
|
||||||
static AVInputFormat *iformat, *idesktopFormat;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -278,7 +278,6 @@ void CameraSource::openDevice()
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to create a new CameraDevice
|
// We need to create a new CameraDevice
|
||||||
AVCodec* codec;
|
|
||||||
device = CameraDevice::open(deviceName, mode);
|
device = CameraDevice::open(deviceName, mode);
|
||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
|
@ -322,7 +321,7 @@ void CameraSource::openDevice()
|
||||||
AVCodecParameters* cparams = device->context->streams[videoStreamIndex]->codecpar;
|
AVCodecParameters* cparams = device->context->streams[videoStreamIndex]->codecpar;
|
||||||
codecId = cparams->codec_id;
|
codecId = cparams->codec_id;
|
||||||
#endif
|
#endif
|
||||||
codec = avcodec_find_decoder(codecId);
|
const AVCodec* codec = avcodec_find_decoder(codecId);
|
||||||
if (!codec) {
|
if (!codec) {
|
||||||
qWarning() << "Codec not found";
|
qWarning() << "Codec not found";
|
||||||
emit openFailed();
|
emit openFailed();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user