Skip to content

Commit

Permalink
fix video settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Joy1024 committed Feb 1, 2025
1 parent 1b97e32 commit 1e22c7e
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src/lib/video/cameradevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,16 @@ QVector<VideoMode> CameraDevice::getScreenModes() {
* @param devName Device name to get nodes from.
* @return Vector of available modes for the device.
*/
QVector<VideoMode> CameraDevice::getVideoModes() {
QVector<VideoMode> CameraDevice::getVideoModes() const {

auto devName = videoDevice.name;
auto iformat = getDefaultInputFormat(videoDevice.type);
if(!iformat){
return {};
}

qDebug() << "format name is" << iformat->name;

//如果是屏幕
if (isScreen(videoDevice.url))
return getScreenModes();
Expand All @@ -560,7 +562,7 @@ QVector<VideoMode> CameraDevice::getVideoModes() {
#endif
#if USING_V4L
if (iformat->name == QString("video4linux2,v4l2"))
return v4l2::getDeviceModes(devName);
return v4l2::getDeviceModes(videoDevice.url);
#endif
#ifdef Q_OS_OSX
if (iformat->name == QString("avfoundation"))
Expand Down
2 changes: 1 addition & 1 deletion src/lib/video/cameradevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CameraDevice {

static QVector<VideoDevice> getDeviceList();

QVector<VideoMode> getVideoModes();
QVector<VideoMode> getVideoModes() const;

static QString getPixelFormatString(uint32_t pixel_format);
static bool betterPixelFormat(uint32_t a, uint32_t b);
Expand Down
14 changes: 12 additions & 2 deletions src/lib/video/camerasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ CameraSource::CameraSource(const VideoDevice &dev)
{
qDebug() << __func__;

// Crate camera device
device = new CameraDevice(dev, this);

qRegisterMetaType<VideoMode>("VideoMode");
deviceThread->setObjectName("Device thread");
deviceThread->start();
Expand Down Expand Up @@ -92,6 +95,11 @@ void CameraSource::setupDefault() {
setupDevice(deviceName, mode);
}

void CameraSource::setup(const VideoMode &vm)
{
mode = vm;
}

void CameraSource::setupDevice(const QString& deviceName_, const VideoMode& Mode) {

}
Expand Down Expand Up @@ -139,9 +147,11 @@ void CameraSource::openDevice() {
auto deviceName = dev.name;
qDebug() << "Opening device" << deviceName;

if(!device){
// Crate camera device
device = new CameraDevice(dev, this);
}

// Crate camera device
device = new CameraDevice(dev, this);
// We need to create a new CameraDevice(Enable camera light)
bool opened = device->open(mode);
if (!opened) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/video/camerasource.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CameraSource : public VideoSource, public FrameHandler {


void setupDefault();
void setup(const VideoMode& mode);

// VideoSource interface
void subscribe() override;
Expand Down
14 changes: 11 additions & 3 deletions src/lib/video/videomode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/

#include "videomode.h"

#include "cameradevice.h"
namespace lib::video {

/**
Expand Down Expand Up @@ -49,15 +51,21 @@ uint32_t VideoMode::norm(const VideoMode& other) const {
// 容忍
uint32_t VideoMode::tolerance() const {
constexpr uint32_t minTolerance = 300; // keep wider tolerance for low res cameras
constexpr uint32_t toleranceFactor =
10; // video mode must be within 10% to be "close enough" to ideal
constexpr uint32_t toleranceFactor = 10; // video mode must be within 10% to be "close enough" to ideal
return std::max((width + height) / toleranceFactor, minTolerance);
}

std::string VideoMode::toString()
{
return std::format("w:{} h:{}, x:{} y:{} FPS:{} format:{}",
width, height, x, y, FPS,
CameraDevice::getPixelFormatString(pixel_format).toStdString());
}

/**
* @brief All zeros means a default/unspecified mode
*/
VideoMode::operator bool() const {
return width || height || static_cast<int>(FPS);
}
} // namespace lib::video
} // namespace lib::video
6 changes: 5 additions & 1 deletion src/lib/video/videomode.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#ifndef VIDEOMODE_H
#define VIDEOMODE_H

#include <cstdint>
#include <format>
#include <QString>
#include <QRect>
#include <cstdint>


namespace lib::video {

Expand Down Expand Up @@ -48,6 +50,8 @@ struct VideoMode {
bool operator==(const VideoMode& other) const;
uint32_t norm(const VideoMode& other) const;
uint32_t tolerance() const;

std::string toString();
};


Expand Down
11 changes: 4 additions & 7 deletions src/modules/im/src/widget/form/settings/avform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ void AVForm::open(const QString& devName, const lib::video::VideoMode& mode) {
QRect rect = mode.toRect();
videoSettings->setCamVideoRes(rect);
videoSettings->setCamVideoFPS(static_cast<float>(mode.FPS));
camera->setupDevice(devName, mode);
camera->setup(mode);
camera->openDevice();
}

void AVForm::trackNewScreenGeometry(QScreen* qScreen) {
Expand Down Expand Up @@ -320,15 +321,11 @@ void AVForm::fillCameraModesComboBox() {

for (int i = 0; i < videoModes.size(); ++i) {
lib::video::VideoMode mode = videoModes[i];
qDebug() << mode.toString().c_str();

QString str;
std::string pixelFormat =
lib::video::CameraDevice::getPixelFormatString(mode.pixel_format).toStdString();
qDebug("width: %d, height: %d, FPS: %f, pixel format: %s\n", mode.width, mode.height,
mode.FPS, pixelFormat.c_str());

if (mode.height && mode.width) {
str += QString("%1p").arg(mode.height);
str += QString("%1x%2p").arg(mode.width).arg(mode.height);
} else {
str += tr("Default resolution");
}
Expand Down
5 changes: 5 additions & 0 deletions src/modules/meet/src/MeetingOptionWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ void CameraVideoOutputWidget::render(const lib::video::VideoDevice& device) {
is_stop = false;
if(!_camera){
_camera = lib::video::CameraSource::CreateInstance(device);
auto modes = _camera->getVideoModes();
for(auto &m : modes){
qDebug() << "mode" << m.toString().c_str();
}

connect(_camera.get(), &lib::video::CameraSource::frameAvailable, this,
[this](std::shared_ptr<lib::video::VideoFrame> frame) {
lastFrame = std::move(frame);
Expand Down

0 comments on commit 1e22c7e

Please sign in to comment.