1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

generic pixel format selection

This commit is contained in:
Sean 2016-01-26 13:14:58 -06:00
parent c82e41ff6f
commit ded8d87ba8
7 changed files with 46 additions and 6 deletions

View File

@ -113,6 +113,7 @@ QVector<VideoMode> v4l2::getDeviceModes(QString devName)
while(!ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &vfse)) {
VideoMode mode;
mode.pixel_format = vfse.pixel_format;
switch (vfse.type) {
case V4L2_FRMSIZE_TYPE_DISCRETE:
mode.width = vfse.discrete.width;
@ -169,3 +170,23 @@ QVector<QPair<QString, QString>> v4l2::getDeviceList()
}
return devices;
}
QString v4l2::getPixelFormatString(uint32_t pixel_format)
{
if (pixel_format == V4L2_PIX_FMT_H264)
{
return QString("h264");
}
if (pixel_format == V4L2_PIX_FMT_MJPEG)
{
return QString("mjpeg");
}
else if (pixel_format == V4L2_PIX_FMT_YUYV)
{
return QString("yuyv422");
}
else {
return QString("unknown");
}
}

View File

@ -32,6 +32,7 @@ namespace v4l2
{
QVector<VideoMode> getDeviceModes(QString devName);
QVector<QPair<QString, QString>> getDeviceList();
QString getPixelFormatString(uint32_t pixel_format);
}
#endif // V4L2_H

View File

@ -17,7 +17,6 @@
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QApplication>
#include <QDesktopWidget>
@ -105,7 +104,7 @@ out:
CameraDevice* CameraDevice::open(QString devName)
{
VideoMode mode{0,0,0};
VideoMode mode{0,0,0,0};
return open(devName, mode);
}
@ -164,7 +163,11 @@ CameraDevice* CameraDevice::open(QString devName, VideoMode mode)
{
av_dict_set(&options, "video_size", QString("%1x%2").arg(mode.width).arg(mode.height).toStdString().c_str(), 0);
av_dict_set(&options, "framerate", QString().setNum(mode.FPS).toStdString().c_str(), 0);
av_dict_set(&options, "pixel_format", "mjpeg", 0);
const char *pixel_format = v4l2::getPixelFormatString(mode.pixel_format).toStdString().c_str();
if (strncmp(pixel_format, "unknown", 7) != 0)
{
av_dict_set(&options, "pixel_format", pixel_format, 0);
}
}
#endif
#ifdef Q_OS_OSX
@ -360,6 +363,15 @@ QVector<VideoMode> CameraDevice::getVideoModes(QString devName)
return {};
}
QString CameraDevice::getPixelFormatString(uint32_t pixel_format)
{
#ifdef Q_OS_LINUX
return v4l2::getPixelFormatString(pixel_format);
#else
return QString("unknown");
#endif
}
bool CameraDevice::getDefaultInputFormat()
{
QMutexLocker locker(&iformatLock);

View File

@ -59,6 +59,8 @@ public:
/// Get the list of video modes for a device
static QVector<VideoMode> getVideoModes(QString devName);
/// Get the name of the pixel format of a video mode
static QString getPixelFormatString(uint32_t pixel_format);
/// Returns the short name of the default defice
/// This is either the device in the settings

View File

@ -35,7 +35,7 @@ extern "C" {
CameraSource* CameraSource::instance{nullptr};
CameraSource::CameraSource()
: deviceName{"none"}, device{nullptr}, mode(VideoMode{0,0,0}),
: deviceName{"none"}, device{nullptr}, mode(VideoMode{0,0,0,0}),
cctx{nullptr}, cctxOrig{nullptr}, videoStreamIndex{-1},
_isOpen{false}, streamBlocker{false}, subscriptions{0}
{
@ -67,7 +67,7 @@ void CameraSource::open()
void CameraSource::open(const QString deviceName)
{
open(deviceName, VideoMode{0,0,0});
open(deviceName, VideoMode{0,0,0,0});
}
void CameraSource::open(const QString DeviceName, VideoMode Mode)

View File

@ -26,6 +26,7 @@ struct VideoMode
{
unsigned short width, height; ///< Displayed video resolution (NOT frame resolution)
float FPS; ///< Max frames per second supported by the device at this resolution
uint32_t pixel_format;
/// All zeros means a default/unspecified mode
operator bool() const
@ -37,7 +38,8 @@ struct VideoMode
{
return width == other.width
&& height == other.height
&& FPS == other.FPS;
&& FPS == other.FPS
&& pixel_format == other.pixel_format;
}
};

View File

@ -187,6 +187,8 @@ void AVForm::updateVideoModes(int curIndex)
str += tr("Default resolution");
if (mode.FPS)
str += tr(" at %1 FPS").arg(mode.FPS);
if (mode.pixel_format)
str += tr(" using %1").arg(CameraDevice::getPixelFormatString(mode.pixel_format));
bodyUI->videoModescomboBox->addItem(str);
}
if (videoModes.isEmpty())