From 95e4a20f05888fc893afd431ada032f8c2dfbc00 Mon Sep 17 00:00:00 2001 From: tux3 Date: Thu, 14 May 2015 18:40:12 +0200 Subject: [PATCH] Compatibility with older libavdevice By not using avdevice_list_input_sources --- src/video/cameradevice.cpp | 43 ++++++++++++++++++++++++++++++++++++-- src/video/camerasource.cpp | 1 + src/video/videoframe.cpp | 2 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/video/cameradevice.cpp b/src/video/cameradevice.cpp index 713698f4a..290b206cd 100644 --- a/src/video/cameradevice.cpp +++ b/src/video/cameradevice.cpp @@ -70,9 +70,47 @@ QVector> CameraDevice::getDeviceList() if (!getDefaultInputFormat()) return devices; - AVDeviceInfoList* devlist; - avdevice_list_input_sources(iformat, nullptr, nullptr, &devlist); + // Alloc an input device context + AVFormatContext *s; + if (!(s = avformat_alloc_context())) + return devices; + if (!iformat->priv_class || !AV_IS_INPUT_DEVICE(iformat->priv_class->category)) + { + avformat_free_context(s); + return devices; + } + s->iformat = iformat; + if (s->iformat->priv_data_size > 0) + { + s->priv_data = av_mallocz(s->iformat->priv_data_size); + if (!s->priv_data) + { + avformat_free_context(s); + return devices; + } + if (s->iformat->priv_class) + { + *(const AVClass**)s->priv_data= s->iformat->priv_class; + av_opt_set_defaults(s->priv_data); + } + } + else + { + s->priv_data = NULL; + } + // List the devices for this context + AVDeviceInfoList* devlist; + AVDictionary *tmp = nullptr; + av_dict_copy(&tmp, nullptr, 0); + if (av_opt_set_dict2(s, &tmp, AV_OPT_SEARCH_CHILDREN) < 0) + { + av_dict_free(&tmp); + avformat_free_context(s); + } + avdevice_list_devices(s, &devlist); + + // Convert the list to a QVector devices.resize(devlist->nb_devices); for (int i=0; inb_devices; i++) { @@ -80,6 +118,7 @@ QVector> CameraDevice::getDeviceList() devices[i].first = dev->device_name; devices[i].second = dev->device_description; } + avdevice_free_list_devices(&devlist); return devices; } diff --git a/src/video/camerasource.cpp b/src/video/camerasource.cpp index 51d8ff8a2..7079410b3 100644 --- a/src/video/camerasource.cpp +++ b/src/video/camerasource.cpp @@ -216,6 +216,7 @@ void CameraSource::stream() while (!freelistLock.compare_exchange_weak(expected, true)) expected = false; } + int freeFreelistSlot = getFreelistSlotLockless(); auto frameFreeCb = std::bind(&CameraSource::freelistCallback, this, freeFreelistSlot); std::shared_ptr vframe = std::make_shared(frame, frameFreeCb); diff --git a/src/video/videoframe.cpp b/src/video/videoframe.cpp index 541d7bafd..84e64ff9b 100644 --- a/src/video/videoframe.cpp +++ b/src/video/videoframe.cpp @@ -151,7 +151,7 @@ bool VideoFrame::convertToYUV420() } else if (frameRGB24) { - sourceFrame = frameOther; + sourceFrame = frameRGB24; } else {