vlc/vlc-3.0 | branch: master | David Fuhrmann <[email protected]> | Sun 
Oct 21 16:11:44 2018 +0200| [5d29acc826cf5874c3ed8b7aeaa62b63a866fb6f] | 
committer: David Fuhrmann

avcapture: Explicitly ask for consent before using the video device

On 10.14, the system asks the user for consent for using the video
device. But by default, it does not block the initialization, but
just outputs black frames before user consent is given.

This gives a bad experience for the user, also because the module
is not terminated if the user actually declines.

Instead, ask for consent explicitly, and block the open call to
wait for the response. On decline, Open directly returns with an
error, and the log contains the reason.

(cherry picked from commit ad372574e5e3ce5562dc10eedbb7e2a55de93ac4)
Signed-off-by: David Fuhrmann <[email protected]>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=5d29acc826cf5874c3ed8b7aeaa62b63a866fb6f
---

 modules/access/avcapture.m | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/modules/access/avcapture.m b/modules/access/avcapture.m
index 6580000a35..c46ca6d69c 100644
--- a/modules/access/avcapture.m
+++ b/modules/access/avcapture.m
@@ -325,14 +325,32 @@ static int Open(vlc_object_t *p_this)
             goto error;
         }
 
+        if (@available(macOS 10.14, *)) {
+            msg_Dbg(p_demux, "Check user consent for access to the video 
device");
+
+            dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+            __block bool accessGranted = NO;
+            [AVCaptureDevice requestAccessForMediaType: AVMediaTypeVideo 
completionHandler:^(BOOL granted) {
+                accessGranted = granted;
+                dispatch_semaphore_signal(sema);
+            } ];
+            dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
+            dispatch_release(sema);
+            if (!accessGranted) {
+                msg_Err(p_demux, "Can't use the video device as access has not 
been granted by the user");
+                goto error;
+            }
+        }
+
         input = [AVCaptureDeviceInput deviceInputWithDevice:(__bridge 
AVCaptureDevice *)p_sys->device error:&o_returnedError];
 
         if ( !input )
         {
-            msg_Err(p_demux, "can't create a valid capture input facility 
(%ld)", [o_returnedError code]);
+            msg_Err(p_demux, "can't create a valid capture input facility: %s 
(%ld)",[[o_returnedError localizedDescription] UTF8String], [o_returnedError 
code]);
             goto error;
         }
 
+
         int chroma = VLC_CODEC_RGB32;
 
         memset(&p_sys->fmt, 0, sizeof(es_format_t));

_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to