mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-04-27 18:36:15 -04:00
added the possiblity to choose which camera to use
This commit is contained in:
parent
7b5be347bf
commit
b78f7f11de
@ -28,6 +28,8 @@
|
|||||||
#include "QVideoDevice.h"
|
#include "QVideoDevice.h"
|
||||||
#include "VideoProcessor.h"
|
#include "VideoProcessor.h"
|
||||||
|
|
||||||
|
// #define DEBUG_QVIDEODEVICE 1
|
||||||
|
|
||||||
QVideoInputDevice::QVideoInputDevice(QWidget *parent)
|
QVideoInputDevice::QVideoInputDevice(QWidget *parent)
|
||||||
:QObject(parent)
|
:QObject(parent)
|
||||||
{
|
{
|
||||||
@ -54,6 +56,8 @@ bool QVideoInputDevice::stopped()
|
|||||||
|
|
||||||
void QVideoInputDevice::stop()
|
void QVideoInputDevice::stop()
|
||||||
{
|
{
|
||||||
|
_capture_device_info = QCameraInfo();
|
||||||
|
|
||||||
if(_timer != NULL)
|
if(_timer != NULL)
|
||||||
{
|
{
|
||||||
_capture_device->stop();
|
_capture_device->stop();
|
||||||
@ -70,6 +74,8 @@ void QVideoInputDevice::stop()
|
|||||||
_capture_device = NULL ;
|
_capture_device = NULL ;
|
||||||
_image_capture = NULL ;
|
_image_capture = NULL ;
|
||||||
}
|
}
|
||||||
|
if(_echo_output_device != NULL)
|
||||||
|
_echo_output_device->showFrameOff() ;
|
||||||
}
|
}
|
||||||
void QVideoInputDevice::getAvailableDevices(QList<QString>& device_desc)
|
void QVideoInputDevice::getAvailableDevices(QList<QString>& device_desc)
|
||||||
{
|
{
|
||||||
@ -105,6 +111,7 @@ void QVideoInputDevice::start(const QString& description)
|
|||||||
std::cerr << "No video camera available in this system!" << std::endl;
|
std::cerr << "No video camera available in this system!" << std::endl;
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
_capture_device_info = caminfo;
|
||||||
_capture_device = new QCamera(caminfo);
|
_capture_device = new QCamera(caminfo);
|
||||||
|
|
||||||
if(_capture_device->error() != QCamera::NoError)
|
if(_capture_device->error() != QCamera::NoError)
|
||||||
@ -144,8 +151,9 @@ void QVideoInputDevice::start(const QString& description)
|
|||||||
|
|
||||||
void QVideoInputDevice::errorHandling(CameraStatus status,QCamera::Error error)
|
void QVideoInputDevice::errorHandling(CameraStatus status,QCamera::Error error)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_QVIDEODEVICE
|
||||||
std::cerr << "Received msg from camera capture: status=" << (int)status << " error=" << (int)error << std::endl;
|
std::cerr << "Received msg from camera capture: status=" << (int)status << " error=" << (int)error << std::endl;
|
||||||
|
#endif
|
||||||
if(status == CANNOT_INITIALIZE_CAMERA)
|
if(status == CANNOT_INITIALIZE_CAMERA)
|
||||||
{
|
{
|
||||||
std::cerr << "Cannot initialize camera. Make sure to install package libqt5multimedia5-plugins, as this is a common cause for camera not being found." << std::endl;
|
std::cerr << "Cannot initialize camera. Make sure to install package libqt5multimedia5-plugins, as this is a common cause for camera not being found." << std::endl;
|
||||||
@ -169,7 +177,9 @@ void QVideoInputDevice::grabFrame(int id,QVideoFrame frame)
|
|||||||
reader.setScaledSize(QSize(640,480));
|
reader.setScaledSize(QSize(640,480));
|
||||||
QImage image(reader.read());
|
QImage image(reader.read());
|
||||||
|
|
||||||
|
#ifdef DEBUG_QVIDEODEVICE
|
||||||
std::cerr << "Frame " << id << ". Pixel format: " << frame.pixelFormat() << ". Size: " << image.size().width() << " x " << image.size().height() << std::endl; // if(frame.pixelFormat() != QVideoFrame::Format_Jpeg)
|
std::cerr << "Frame " << id << ". Pixel format: " << frame.pixelFormat() << ". Size: " << image.size().width() << " x " << image.size().height() << std::endl; // if(frame.pixelFormat() != QVideoFrame::Format_Jpeg)
|
||||||
|
#endif
|
||||||
|
|
||||||
if(_video_processor != NULL)
|
if(_video_processor != NULL)
|
||||||
{
|
{
|
||||||
@ -211,7 +221,9 @@ void QVideoOutputDevice::showFrameOff()
|
|||||||
|
|
||||||
void QVideoOutputDevice::showFrame(const QImage& img)
|
void QVideoOutputDevice::showFrame(const QImage& img)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_QVIDEODEVICE
|
||||||
std::cerr << "img.size = " << img.width() << " x " << img.height() << std::endl;
|
std::cerr << "img.size = " << img.width() << " x " << img.height() << std::endl;
|
||||||
|
#endif
|
||||||
setPixmap(QPixmap::fromImage(img).scaled( QSize(height()*4/3,height()),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)) ;
|
setPixmap(QPixmap::fromImage(img).scaled( QSize(height()*4/3,height()),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QCamera>
|
#include <QCamera>
|
||||||
|
#include <QCameraInfo>
|
||||||
#include "interface/rsVOIP.h"
|
#include "interface/rsVOIP.h"
|
||||||
|
|
||||||
#include "gui/VideoProcessor.h"
|
#include "gui/VideoProcessor.h"
|
||||||
@ -85,6 +86,7 @@ class QVideoInputDevice: public QObject
|
|||||||
|
|
||||||
static void getAvailableDevices(QList<QString>& device_desc);
|
static void getAvailableDevices(QList<QString>& device_desc);
|
||||||
|
|
||||||
|
QString currentCameraDescriptionString() const { return _capture_device_info.deviceName(); }
|
||||||
protected slots:
|
protected slots:
|
||||||
void grabFrame(int id, QVideoFrame f) ;
|
void grabFrame(int id, QVideoFrame f) ;
|
||||||
void errorHandling(CameraStatus status,QCamera::Error error);
|
void errorHandling(CameraStatus status,QCamera::Error error);
|
||||||
@ -98,6 +100,7 @@ protected slots:
|
|||||||
QTimer *_timer ;
|
QTimer *_timer ;
|
||||||
QCamera *_capture_device;
|
QCamera *_capture_device;
|
||||||
QCameraImageCapture *_image_capture;
|
QCameraImageCapture *_image_capture;
|
||||||
|
QCameraInfo _capture_device_info;
|
||||||
|
|
||||||
QVideoOutputDevice *_echo_output_device ;
|
QVideoOutputDevice *_echo_output_device ;
|
||||||
|
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
#include "audiodevicehelper.h"
|
#include "audiodevicehelper.h"
|
||||||
#include "AudioWizard.h"
|
#include "AudioWizard.h"
|
||||||
#include "gui/VideoProcessor.h"
|
#include "gui/VideoProcessor.h"
|
||||||
#include "gui/common/RSGraphWidget.h"
|
#include "gui/VideoProcessor.h"
|
||||||
|
#include "util/misc.h"
|
||||||
#include "util/RsProtectedTimer.h"
|
#include "util/RsProtectedTimer.h"
|
||||||
|
|
||||||
#include <interface/rsVOIP.h>
|
#include <interface/rsVOIP.h>
|
||||||
@ -104,9 +105,13 @@ VOIPConfigPanel::VOIPConfigPanel(QWidget * parent, Qt::WindowFlags flags)
|
|||||||
QList<QString> input_devices;
|
QList<QString> input_devices;
|
||||||
QVideoInputDevice::getAvailableDevices(input_devices);
|
QVideoInputDevice::getAvailableDevices(input_devices);
|
||||||
ui.inputDevice_CB->clear();
|
ui.inputDevice_CB->clear();
|
||||||
|
ui.inputDevice_CB->addItem(tr("[No video]"),QString(""));
|
||||||
for(auto& s:input_devices)
|
for(auto& s:input_devices)
|
||||||
ui.inputDevice_CB->addItem(s,QVariant(s));
|
ui.inputDevice_CB->addItem(s,QVariant(s));
|
||||||
|
|
||||||
|
if(!input_devices.empty())
|
||||||
|
whileBlocking(ui.inputDevice_CB)->setCurrentIndex(1); // select default cam
|
||||||
|
|
||||||
connect( ui.qsTransmitHold, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsTransmitHold_valueChanged(int) ) );
|
connect( ui.qsTransmitHold, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsTransmitHold_valueChanged(int) ) );
|
||||||
connect( ui.qsNoise, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsNoise_valueChanged(int) ) );
|
connect( ui.qsNoise, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsNoise_valueChanged(int) ) );
|
||||||
connect( ui.qsAmp, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsAmp_valueChanged(int) ) );
|
connect( ui.qsAmp, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsAmp_valueChanged(int) ) );
|
||||||
@ -367,3 +372,92 @@ void VOIPConfigPanel::on_qpbAudioWizard_clicked() {
|
|||||||
aw.exec();
|
aw.exec();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VOIPConfigPanel::on_changedCurrentInputDevice(int i)
|
||||||
|
{
|
||||||
|
QString s = dynamic_cast<QComboBox*>(sender())->itemData(i).toString();
|
||||||
|
|
||||||
|
videoInput->stop();
|
||||||
|
|
||||||
|
// check that the camera still exists
|
||||||
|
|
||||||
|
QList<QString> input_devices;
|
||||||
|
QVideoInputDevice::getAvailableDevices(input_devices);
|
||||||
|
|
||||||
|
for(const QString& cams:input_devices)
|
||||||
|
if(s == cams)
|
||||||
|
{
|
||||||
|
std::cerr << "Switching to camera \"" << s.toStdString() << "\"" << std::endl;
|
||||||
|
|
||||||
|
videoInput->start(s);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if not, re-create the ComboBox
|
||||||
|
|
||||||
|
checkAvailableCameras();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VOIPConfigPanel::checkAvailableCameras()
|
||||||
|
{
|
||||||
|
// save current camera
|
||||||
|
QString current_cam = videoInput->currentCameraDescriptionString();
|
||||||
|
|
||||||
|
// Check that the list of cams we had previously is the same than the list of available camera.
|
||||||
|
|
||||||
|
QList<QString> input_devices;
|
||||||
|
QVideoInputDevice::getAvailableDevices(input_devices);
|
||||||
|
|
||||||
|
bool same = true;
|
||||||
|
if(input_devices.size() != ui.inputDevice_CB->count())
|
||||||
|
same = false;
|
||||||
|
|
||||||
|
if(same)
|
||||||
|
{
|
||||||
|
int n=0;
|
||||||
|
for(auto& s:input_devices)
|
||||||
|
{
|
||||||
|
if(ui.inputDevice_CB->itemData(n).toString() != s)
|
||||||
|
{
|
||||||
|
same = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not, re-add them to the comboBox and make sure to re-select the same camera.
|
||||||
|
|
||||||
|
if(!same)
|
||||||
|
{
|
||||||
|
whileBlocking(ui.inputDevice_CB)->clear(); // remove existing entries
|
||||||
|
whileBlocking(ui.inputDevice_CB)->addItem(tr("[No video]"),QString(""));
|
||||||
|
int n=0;
|
||||||
|
int found_index = -1;
|
||||||
|
|
||||||
|
for(auto& s:input_devices)
|
||||||
|
{
|
||||||
|
whileBlocking(ui.inputDevice_CB)->addItem(s,QVariant(s));
|
||||||
|
|
||||||
|
if(s == current_cam)
|
||||||
|
found_index = n;
|
||||||
|
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(found_index >= 0)
|
||||||
|
ui.inputDevice_CB->setCurrentIndex(found_index);
|
||||||
|
else
|
||||||
|
ui.inputDevice_CB->setCurrentIndex(0); // no video
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ class VOIPConfigPanel : public ConfigPage
|
|||||||
QVideoInputDevice *videoInput ;
|
QVideoInputDevice *videoInput ;
|
||||||
VideoProcessor *videoProcessor ;
|
VideoProcessor *videoProcessor ;
|
||||||
bool loaded;
|
bool loaded;
|
||||||
|
QString currentCameraDescription;
|
||||||
|
|
||||||
voipGraphSource *graph_source ;
|
voipGraphSource *graph_source ;
|
||||||
|
|
||||||
@ -86,6 +87,8 @@ class VOIPConfigPanel : public ConfigPage
|
|||||||
virtual void showEvent(QShowEvent *) override;
|
virtual void showEvent(QShowEvent *) override;
|
||||||
virtual void hideEvent(QHideEvent *event) override;
|
virtual void hideEvent(QHideEvent *event) override;
|
||||||
private slots:
|
private slots:
|
||||||
|
void on_changedCurrentInputDevice(int i);
|
||||||
|
void checkAvailableCameras();
|
||||||
void updateAvailableBW(double r);
|
void updateAvailableBW(double r);
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void emptyBuffer();
|
void emptyBuffer();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user