Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix: Update video API usage for newer libavcodec
Browse files Browse the repository at this point in the history
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.

Backported from 15673a5
  • Loading branch information
anthonybilinski committed Mar 5, 2022
1 parent f0e82c3 commit f5fabc2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/video/cameradevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ extern "C" {
#include "cameradevice.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)
#define USING_V4L 1
#else
Expand Down Expand Up @@ -68,8 +71,8 @@ extern "C" {

QHash<QString, CameraDevice*> CameraDevice::openDevices;
QMutex CameraDevice::openDeviceLock, CameraDevice::iformatLock;
AVInputFormat* CameraDevice::iformat{nullptr};
AVInputFormat* CameraDevice::idesktopFormat{nullptr};
static AvFindInputFormatRet idesktopFormat{nullptr};
static AvFindInputFormatRet iformat{nullptr};

CameraDevice::CameraDevice(const QString& devName, AVFormatContext* context)
: devName{devName}
Expand All @@ -89,7 +92,7 @@ CameraDevice* CameraDevice::open(QString devName, AVDictionary** options)
goto out;
}

AVInputFormat* format;
AvFindInputFormatRet format;
if (devName.startsWith("x11grab#")) {
devName = devName.mid(8);
format = idesktopFormat;
Expand Down
1 change: 0 additions & 1 deletion src/video/cameradevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class CameraDevice
std::atomic_int refcount;
static QHash<QString, CameraDevice*> openDevices;
static QMutex openDeviceLock, iformatLock;
static AVInputFormat *iformat, *idesktopFormat;
};

#endif // CAMERADEVICE_H
3 changes: 1 addition & 2 deletions src/video/camerasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ void CameraSource::openDevice()
}

// We need to create a new CameraDevice
AVCodec* codec;
device = CameraDevice::open(deviceName, mode);

if (!device) {
Expand Down Expand Up @@ -321,7 +320,7 @@ void CameraSource::openDevice()
AVCodecParameters* cparams = device->context->streams[videoStreamIndex]->codecpar;
codecId = cparams->codec_id;
#endif
codec = avcodec_find_decoder(codecId);
const AVCodec* codec = avcodec_find_decoder(codecId);
if (!codec) {
qWarning() << "Codec not found";
emit openFailed();
Expand Down

0 comments on commit f5fabc2

Please sign in to comment.