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

Implemented screen capturing support for Mac OS X

This commit is contained in:
Andrew Novikov 2015-12-23 15:31:28 +03:00
parent bd8a2c84ef
commit 985def25ff
4 changed files with 46 additions and 19 deletions

View File

@ -160,7 +160,7 @@ win32 {
QMAKE_INFO_PLIST = osx/info.plist
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
LIBS += -L$$PWD/libs/lib/ -ltoxcore -ltoxav -ltoxencryptsave -ltoxdns -lsodium -lvpx -lopus -framework OpenAL -lavformat -lavdevice -lavcodec -lavutil -lswscale -mmacosx-version-min=10.7
LIBS += -framework AVFoundation -framework Foundation -framework CoreMedia
LIBS += -framework AVFoundation -framework Foundation -framework CoreMedia -framework ApplicationServices
LIBS += -lqrencode -lsqlcipher
contains(DEFINES, QTOX_PLATFORM_EXT) { LIBS += -framework IOKit -framework CoreFoundation }
contains(DEFINES, QTOX_FILTER_AUDIO) { LIBS += -lfilteraudio }

View File

@ -30,6 +30,8 @@
namespace avfoundation
{
const QString CAPTURE_SCREEN{"Capture screen"};
QVector<VideoMode> getDeviceModes(QString devName);
QVector<QPair<QString, QString>> getDeviceList();
}

View File

@ -19,6 +19,7 @@
*/
#include "avfoundation.h"
#include <QObject>
#import <AVFoundation/AVFoundation.h>
@ -31,6 +32,16 @@ QVector<QPair<QString, QString> > avfoundation::getDeviceList()
result.append({ QString::fromNSString([device uniqueID]), QString::fromNSString([device localizedName]) });
}
uint32_t numScreens = 0;
CGGetActiveDisplayList(0, NULL, &numScreens);
if (numScreens > 0) {
CGDirectDisplayID screens[numScreens];
CGGetActiveDisplayList(numScreens, screens, &numScreens);
for (uint32_t i = 0; i < numScreens; i++) {
result.append({ QString("%1 %2").arg(CAPTURE_SCREEN).arg(i), QObject::tr("Capture screen %1").arg(i) });
}
}
return result;
}
@ -38,25 +49,30 @@ QVector<VideoMode> avfoundation::getDeviceModes(QString devName)
{
QVector<VideoMode> result;
NSString* deviceName = [NSString stringWithCString:devName.toUtf8() encoding:NSUTF8StringEncoding];
AVCaptureDevice* device = [AVCaptureDevice deviceWithUniqueID:deviceName];
if (device == nil) {
if (devName.startsWith(CAPTURE_SCREEN)) {
return result;
}
else {
NSString* deviceName = [NSString stringWithCString:devName.toUtf8() encoding:NSUTF8StringEncoding];
AVCaptureDevice* device = [AVCaptureDevice deviceWithUniqueID:deviceName];
for (AVCaptureDeviceFormat* format in [device formats]) {
CMFormatDescriptionRef formatDescription;
CMVideoDimensions dimensions;
formatDescription = (CMFormatDescriptionRef)[format performSelector:@selector(formatDescription)];
dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
if (device == nil) {
return result;
}
for (AVFrameRateRange* range in format.videoSupportedFrameRateRanges) {
VideoMode mode;
mode.width = dimensions.width;
mode.height = dimensions.height;
mode.FPS = range.maxFrameRate;
result.append(mode);
for (AVCaptureDeviceFormat* format in [device formats]) {
CMFormatDescriptionRef formatDescription;
CMVideoDimensions dimensions;
formatDescription = (CMFormatDescriptionRef)[format performSelector:@selector(formatDescription)];
dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
for (AVFrameRateRange* range in format.videoSupportedFrameRateRanges) {
VideoMode mode;
mode.width = dimensions.width;
mode.height = dimensions.height;
mode.FPS = range.maxFrameRate;
result.append(mode);
}
}
}

View File

@ -167,10 +167,19 @@ CameraDevice* CameraDevice::open(QString devName, VideoMode mode)
}
#endif
#ifdef Q_OS_OSX
else if (iformat->name == QString("avfoundation") && mode)
else if (iformat->name == QString("avfoundation"))
{
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);
if (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);
}
else if (devName.startsWith(avfoundation::CAPTURE_SCREEN))
{
av_dict_set(&options, "framerate", QString().setNum(5).toStdString().c_str(), 0);
av_dict_set_int(&options, "capture_cursor", 1, 0);
av_dict_set_int(&options, "capture_mouse_clicks", 1, 0);
}
}
#endif
else if (mode)