avfvideosrc: allow "capture-screen" mode to select which screen to capture via the "device-index" option
https://bugzilla.gnome.org/show_bug.cgi?id=745161
This commit is contained in:
parent
1172e2875d
commit
a8ae57480c
@ -24,6 +24,9 @@
|
|||||||
#include "avfvideosrc.h"
|
#include "avfvideosrc.h"
|
||||||
|
|
||||||
#import <AVFoundation/AVFoundation.h>
|
#import <AVFoundation/AVFoundation.h>
|
||||||
|
#if !HAVE_IOS
|
||||||
|
#import <AppKit/AppKit.h>
|
||||||
|
#endif
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
#include <gst/gl/gstglcontext.h>
|
#include <gst/gl/gstglcontext.h>
|
||||||
#include "coremediabuffer.h"
|
#include "coremediabuffer.h"
|
||||||
@ -75,9 +78,6 @@ G_DEFINE_TYPE (GstAVFVideoSrc, gst_avf_video_src, GST_TYPE_PUSH_SRC);
|
|||||||
|
|
||||||
gint deviceIndex;
|
gint deviceIndex;
|
||||||
BOOL doStats;
|
BOOL doStats;
|
||||||
#if !HAVE_IOS
|
|
||||||
CGDirectDisplayID displayId;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
AVCaptureSession *session;
|
AVCaptureSession *session;
|
||||||
AVCaptureInput *input;
|
AVCaptureInput *input;
|
||||||
@ -126,6 +126,9 @@ G_DEFINE_TYPE (GstAVFVideoSrc, gst_avf_video_src, GST_TYPE_PUSH_SRC);
|
|||||||
- (BOOL)openDevice;
|
- (BOOL)openDevice;
|
||||||
- (void)closeDevice;
|
- (void)closeDevice;
|
||||||
- (GstVideoFormat)getGstVideoFormat:(NSNumber *)pixel_format;
|
- (GstVideoFormat)getGstVideoFormat:(NSNumber *)pixel_format;
|
||||||
|
#if !HAVE_IOS
|
||||||
|
- (CGDirectDisplayID)getDisplayIdFromDeviceIndex;
|
||||||
|
#endif
|
||||||
- (BOOL)getDeviceCaps:(GstCaps *)result;
|
- (BOOL)getDeviceCaps:(GstCaps *)result;
|
||||||
- (BOOL)setDeviceCaps:(GstVideoInfo *)info;
|
- (BOOL)setDeviceCaps:(GstVideoInfo *)info;
|
||||||
- (BOOL)getSessionPresetCaps:(GstCaps *)result;
|
- (BOOL)getSessionPresetCaps:(GstCaps *)result;
|
||||||
@ -169,9 +172,6 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||||||
captureScreenMouseClicks = NO;
|
captureScreenMouseClicks = NO;
|
||||||
useVideoMeta = NO;
|
useVideoMeta = NO;
|
||||||
textureCache = NULL;
|
textureCache = NULL;
|
||||||
#if !HAVE_IOS
|
|
||||||
displayId = kCGDirectMainDisplay;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mainQueue =
|
mainQueue =
|
||||||
dispatch_queue_create ("org.freedesktop.gstreamer.avfvideosrc.main", NULL);
|
dispatch_queue_create ("org.freedesktop.gstreamer.avfvideosrc.main", NULL);
|
||||||
@ -200,7 +200,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||||||
NSString *mediaType = AVMediaTypeVideo;
|
NSString *mediaType = AVMediaTypeVideo;
|
||||||
NSError *err;
|
NSError *err;
|
||||||
|
|
||||||
if (deviceIndex == -1) {
|
if (deviceIndex == DEFAULT_DEVICE_INDEX) {
|
||||||
device = [AVCaptureDevice defaultDeviceWithMediaType:mediaType];
|
device = [AVCaptureDevice defaultDeviceWithMediaType:mediaType];
|
||||||
if (device == nil) {
|
if (device == nil) {
|
||||||
GST_ELEMENT_ERROR (element, RESOURCE, NOT_FOUND,
|
GST_ELEMENT_ERROR (element, RESOURCE, NOT_FOUND,
|
||||||
@ -241,8 +241,14 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||||||
#if HAVE_IOS
|
#if HAVE_IOS
|
||||||
return NO;
|
return NO;
|
||||||
#else
|
#else
|
||||||
|
CGDirectDisplayID displayId;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (element, "Opening screen input");
|
GST_DEBUG_OBJECT (element, "Opening screen input");
|
||||||
|
|
||||||
|
displayId = [self getDisplayIdFromDeviceIndex];
|
||||||
|
if (displayId == 0)
|
||||||
|
return NO;
|
||||||
|
|
||||||
AVCaptureScreenInput *screenInput =
|
AVCaptureScreenInput *screenInput =
|
||||||
[[AVCaptureScreenInput alloc] initWithDisplayID:displayId];
|
[[AVCaptureScreenInput alloc] initWithDisplayID:displayId];
|
||||||
|
|
||||||
@ -368,6 +374,26 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||||||
return gst_format;
|
return gst_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !HAVE_IOS
|
||||||
|
- (CGDirectDisplayID)getDisplayIdFromDeviceIndex
|
||||||
|
{
|
||||||
|
NSDictionary *description;
|
||||||
|
NSNumber *displayId;
|
||||||
|
NSArray *screens = [NSScreen screens];
|
||||||
|
|
||||||
|
if (deviceIndex == DEFAULT_DEVICE_INDEX)
|
||||||
|
return kCGDirectMainDisplay;
|
||||||
|
if (deviceIndex >= [screens count]) {
|
||||||
|
GST_ELEMENT_ERROR (element, RESOURCE, NOT_FOUND,
|
||||||
|
("Invalid screen capture device index"), (NULL));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
description = [[screens objectAtIndex:deviceIndex] deviceDescription];
|
||||||
|
displayId = [description objectForKey:@"NSScreenNumber"];
|
||||||
|
return [displayId unsignedIntegerValue];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
- (BOOL)getDeviceCaps:(GstCaps *)result
|
- (BOOL)getDeviceCaps:(GstCaps *)result
|
||||||
{
|
{
|
||||||
NSArray *formats = [device valueForKey:@"formats"];
|
NSArray *formats = [device valueForKey:@"formats"];
|
||||||
@ -547,7 +573,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||||||
|
|
||||||
if (captureScreen) {
|
if (captureScreen) {
|
||||||
#if !HAVE_IOS
|
#if !HAVE_IOS
|
||||||
CGRect rect = CGDisplayBounds (displayId);
|
CGRect rect = CGDisplayBounds ([self getDisplayIdFromDeviceIndex]);
|
||||||
for (NSNumber *pixel_format in pixel_formats) {
|
for (NSNumber *pixel_format in pixel_formats) {
|
||||||
GstVideoFormat gst_format = [self getGstVideoFormat:pixel_format];
|
GstVideoFormat gst_format = [self getGstVideoFormat:pixel_format];
|
||||||
if (gst_format != GST_VIDEO_FORMAT_UNKNOWN)
|
if (gst_format != GST_VIDEO_FORMAT_UNKNOWN)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user