Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api
@ 2023-12-04 12:47 xufuji456 via ffmpeg-devel
  2023-12-04 13:55 ` Thilo Borgmann via ffmpeg-devel
  2023-12-04 14:25 ` epirat07
  0 siblings, 2 replies; 8+ messages in thread
From: xufuji456 via ffmpeg-devel @ 2023-12-04 12:47 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: xufuji456

Building with iOS platform, the compiler has a warning: "'devicesWithMediaType:' is deprecated: first deprecated in iOS 10.0 - Use AVCaptureDeviceDiscoverySession instead"

Signed-off-by: xufuji456 <839789740@qq.com>
---
 libavdevice/avfoundation.m | 81 +++++++++++++++++++++++++++++++++++---
 1 file changed, 76 insertions(+), 5 deletions(-)

diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
index 36ad834753..668c726eb7 100644
--- a/libavdevice/avfoundation.m
+++ b/libavdevice/avfoundation.m
@@ -770,8 +770,38 @@ static int avf_read_header(AVFormatContext *s)
     AVCaptureDevice *video_device = nil;
     AVCaptureDevice *audio_device = nil;
     // Find capture device
-    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
-    NSArray *devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
+    NSArray *devices = nil;
+    NSArray *devices_muxed = nil;
+
+    if (TARGET_OS_IPHONE) {
+        if (@available(iOS 10.0, *)) {
+            AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
+                        [AVCaptureDeviceDiscoverySession
+                        discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
+                                              mediaType:AVMediaTypeVideo
+                                               position:AVCaptureDevicePositionUnspecified];
+            devices = [captureDeviceDiscoverySession devices];
+        } else {
+            devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
+        }
+    } else {
+        devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
+    }
+
+    if (TARGET_OS_IPHONE) {
+        if (@available(iOS 10.0, *)) {
+            AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
+                        [AVCaptureDeviceDiscoverySession
+                        discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
+                                              mediaType:AVMediaTypeMuxed
+                                               position:AVCaptureDevicePositionUnspecified];
+            devices_muxed = [captureDeviceDiscoverySession devices];
+        } else {
+            devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
+        }
+    } else {
+        devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
+    }
 
     ctx->num_video_devices = [devices count] + [devices_muxed count];
 
@@ -806,7 +836,20 @@ static int avf_read_header(AVFormatContext *s)
 #endif
 
         av_log(ctx, AV_LOG_INFO, "AVFoundation audio devices:\n");
-        devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+        if (TARGET_OS_IPHONE) {
+            if (@available(iOS 10.0, *)) {
+                AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
+                            [AVCaptureDeviceDiscoverySession
+                            discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
+                                                  mediaType:AVMediaTypeAudio
+                                                   position:AVCaptureDevicePositionUnspecified];
+                devices = [captureDeviceDiscoverySession devices];
+            } else {
+                devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+            }
+        } else {
+            devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+        }
         for (AVCaptureDevice *device in devices) {
             const char *name = [[device localizedName] UTF8String];
             int index  = [devices indexOfObject:device];
@@ -930,7 +973,21 @@ static int avf_read_header(AVFormatContext *s)
 
     // get audio device
     if (ctx->audio_device_index >= 0) {
-        NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+        NSArray *devices = nil;
+        if (TARGET_OS_IPHONE) {
+            if (@available(iOS 10.0, *)) {
+                AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
+                            [AVCaptureDeviceDiscoverySession
+                            discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
+                                                  mediaType:AVMediaTypeAudio
+                                                   position:AVCaptureDevicePositionUnspecified];
+                devices = [captureDeviceDiscoverySession devices];
+            } else {
+                devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+            }
+        } else {
+            devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+        }
 
         if (ctx->audio_device_index >= [devices count]) {
             av_log(ctx, AV_LOG_ERROR, "Invalid audio device index\n");
@@ -943,7 +1000,21 @@ static int avf_read_header(AVFormatContext *s)
         if (!strncmp(ctx->audio_filename, "default", 7)) {
             audio_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
         } else {
-        NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+        NSArray *devices = nil;
+        if (TARGET_OS_IPHONE) {
+            if (@available(iOS 10.0, *)) {
+                AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
+                            [AVCaptureDeviceDiscoverySession
+                            discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
+                                                  mediaType:AVMediaTypeAudio
+                                                   position:AVCaptureDevicePositionUnspecified];
+                devices = [captureDeviceDiscoverySession devices];
+            } else {
+                devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+            }
+        } else {
+            devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+        }
 
         for (AVCaptureDevice *device in devices) {
             if (!strncmp(ctx->audio_filename, [[device localizedName] UTF8String], strlen(ctx->audio_filename))) {
-- 
2.32.0 (Apple Git-132)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api
  2023-12-04 12:47 [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api xufuji456 via ffmpeg-devel
@ 2023-12-04 13:55 ` Thilo Borgmann via ffmpeg-devel
  2023-12-05  9:42   ` 徐福隆 via ffmpeg-devel
  2023-12-04 14:25 ` epirat07
  1 sibling, 1 reply; 8+ messages in thread
From: Thilo Borgmann via ffmpeg-devel @ 2023-12-04 13:55 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Thilo Borgmann

Am 04.12.23 um 13:47 schrieb xufuji456 via ffmpeg-devel:
> Building with iOS platform, the compiler has a warning: "'devicesWithMediaType:' is deprecated: first deprecated in iOS 10.0 - Use AVCaptureDeviceDiscoverySession instead"
> 
> Signed-off-by: xufuji456 <839789740@qq.com>
> ---
>   libavdevice/avfoundation.m | 81 +++++++++++++++++++++++++++++++++++---
>   1 file changed, 76 insertions(+), 5 deletions(-)
> 
> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
> index 36ad834753..668c726eb7 100644
> --- a/libavdevice/avfoundation.m
> +++ b/libavdevice/avfoundation.m
> @@ -770,8 +770,38 @@ static int avf_read_header(AVFormatContext *s)
>       AVCaptureDevice *video_device = nil;
>       AVCaptureDevice *audio_device = nil;
>       // Find capture device
> -    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
> -    NSArray *devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
> +    NSArray *devices = nil;
> +    NSArray *devices_muxed = nil;
> +


> +    if (TARGET_OS_IPHONE) {
> +        if (@available(iOS 10.0, *)) {

The preprocessor directives should be more reliable especially on older machines.
See other parts of the code which are handled that way and adopt for your case.


> +            AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
> +                        [AVCaptureDeviceDiscoverySession
> +                        discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
> +                                              mediaType:AVMediaTypeVideo
> +                                               position:AVCaptureDevicePositionUnspecified];
> +            devices = [captureDeviceDiscoverySession devices];

> +        } else {
> +            devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
> +        }
> +    } else {
> +        devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
> +    }

Here and in other chunks you can join the if() conditions into one and avoid the duplication of the old code.


-Thilo
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api
  2023-12-04 12:47 [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api xufuji456 via ffmpeg-devel
  2023-12-04 13:55 ` Thilo Borgmann via ffmpeg-devel
@ 2023-12-04 14:25 ` epirat07
  1 sibling, 0 replies; 8+ messages in thread
From: epirat07 @ 2023-12-04 14:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On 4 Dec 2023, at 13:47, xufuji456 via ffmpeg-devel wrote:

> Building with iOS platform, the compiler has a warning: "'devicesWithMediaType:' is deprecated: first deprecated in iOS 10.0 - Use AVCaptureDeviceDiscoverySession instead"
>
> Signed-off-by: xufuji456 <839789740@qq.com>

Thanks for the patch, some remarks inline below:

> ---
>  libavdevice/avfoundation.m | 81 +++++++++++++++++++++++++++++++++++---
>  1 file changed, 76 insertions(+), 5 deletions(-)
>
> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
> index 36ad834753..668c726eb7 100644
> --- a/libavdevice/avfoundation.m
> +++ b/libavdevice/avfoundation.m
> @@ -770,8 +770,38 @@ static int avf_read_header(AVFormatContext *s)
>      AVCaptureDevice *video_device = nil;
>      AVCaptureDevice *audio_device = nil;
>      // Find capture device
> -    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
> -    NSArray *devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
> +    NSArray *devices = nil;
> +    NSArray *devices_muxed = nil;
> +
> +    if (TARGET_OS_IPHONE) {

This should use a SDK guard, like:

  #if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000) ||
       (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500))

(You can check https://epir.at/2019/10/30/api-availability-and-target-conditionals/ where
I provided a more details about these)

> +        if (@available(iOS 10.0, *)) {

This should be extended for other OSes too, the API is not just deprecated on iOS.

> +            AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
> +                        [AVCaptureDeviceDiscoverySession
> +                        discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
> +                                              mediaType:AVMediaTypeVideo
> +                                               position:AVCaptureDevicePositionUnspecified];
> +            devices = [captureDeviceDiscoverySession devices];
> +        } else {
> +            devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
> +        }
> +    } else {
> +        devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
> +    }
> +
> +    if (TARGET_OS_IPHONE) {
> +        if (@available(iOS 10.0, *)) {
> +            AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
> +                        [AVCaptureDeviceDiscoverySession
> +                        discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
> +                                              mediaType:AVMediaTypeMuxed
> +                                               position:AVCaptureDevicePositionUnspecified];
> +            devices_muxed = [captureDeviceDiscoverySession devices];
> +        } else {
> +            devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
> +        }
> +    } else {
> +        devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
> +    }
>
>      ctx->num_video_devices = [devices count] + [devices_muxed count];
>
> @@ -806,7 +836,20 @@ static int avf_read_header(AVFormatContext *s)
>  #endif
>
>          av_log(ctx, AV_LOG_INFO, "AVFoundation audio devices:\n");
> -        devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
> +        if (TARGET_OS_IPHONE) {
> +            if (@available(iOS 10.0, *)) {
> +                AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
> +                            [AVCaptureDeviceDiscoverySession
> +                            discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
> +                                                  mediaType:AVMediaTypeAudio
> +                                                   position:AVCaptureDevicePositionUnspecified];
> +                devices = [captureDeviceDiscoverySession devices];
> +            } else {
> +                devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
> +            }
> +        } else {
> +            devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
> +        }
>          for (AVCaptureDevice *device in devices) {
>              const char *name = [[device localizedName] UTF8String];
>              int index  = [devices indexOfObject:device];
> @@ -930,7 +973,21 @@ static int avf_read_header(AVFormatContext *s)
>
>      // get audio device
>      if (ctx->audio_device_index >= 0) {
> -        NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
> +        NSArray *devices = nil;
> +        if (TARGET_OS_IPHONE) {
> +            if (@available(iOS 10.0, *)) {
> +                AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
> +                            [AVCaptureDeviceDiscoverySession
> +                            discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
> +                                                  mediaType:AVMediaTypeAudio
> +                                                   position:AVCaptureDevicePositionUnspecified];
> +                devices = [captureDeviceDiscoverySession devices];
> +            } else {
> +                devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
> +            }
> +        } else {
> +            devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
> +        }
>
>          if (ctx->audio_device_index >= [devices count]) {
>              av_log(ctx, AV_LOG_ERROR, "Invalid audio device index\n");
> @@ -943,7 +1000,21 @@ static int avf_read_header(AVFormatContext *s)
>          if (!strncmp(ctx->audio_filename, "default", 7)) {
>              audio_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
>          } else {
> -        NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
> +        NSArray *devices = nil;
> +        if (TARGET_OS_IPHONE) {
> +            if (@available(iOS 10.0, *)) {
> +                AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
> +                            [AVCaptureDeviceDiscoverySession
> +                            discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
> +                                                  mediaType:AVMediaTypeAudio
> +                                                   position:AVCaptureDevicePositionUnspecified];
> +                devices = [captureDeviceDiscoverySession devices];
> +            } else {
> +                devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
> +            }
> +        } else {
> +            devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
> +        }
>
>          for (AVCaptureDevice *device in devices) {
>              if (!strncmp(ctx->audio_filename, [[device localizedName] UTF8String], strlen(ctx->audio_filename))) {
> -- 
> 2.32.0 (Apple Git-132)
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api
  2023-12-04 13:55 ` Thilo Borgmann via ffmpeg-devel
@ 2023-12-05  9:42   ` 徐福隆 via ffmpeg-devel
  0 siblings, 0 replies; 8+ messages in thread
From: 徐福隆 via ffmpeg-devel @ 2023-12-05  9:42 UTC (permalink / raw)
  To: =?gb18030?B?RkZtcGVnIGRldmVsb3BtZW50IGRpc2N1c3Npb25zIGFuZCBwYXRjaGVz?=
  Cc: =?gb18030?B?0Oy4o8Kh?=, =?gb18030?B?dGhpbG8uYm9yZ21hbm4=?=,
	=?gb18030?B?ZXBpcmF0MDc=?=

Thank you for your suggestion.
I will adapt the judgment condition, and submit again.


------------------&nbsp;Original&nbsp;------------------
From:                                                                                                                        "FFmpeg development discussions and patches"                                                                                    <ffmpeg-devel@ffmpeg.org&gt;;
Date:&nbsp;Mon, Dec 4, 2023 09:55 PM
To:&nbsp;"ffmpeg-devel"<ffmpeg-devel@ffmpeg.org&gt;;
Cc:&nbsp;"Thilo Borgmann"<thilo.borgmann@mail.de&gt;;
Subject:&nbsp;Re: [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api



Am 04.12.23 um 13:47 schrieb xufuji456 via ffmpeg-devel:
&gt; Building with iOS platform, the compiler has a warning: "'devicesWithMediaType:' is deprecated: first deprecated in iOS 10.0 - Use AVCaptureDeviceDiscoverySession instead"
&gt; 
&gt; Signed-off-by: xufuji456 <839789740@qq.com&gt;
&gt; ---
&gt;&nbsp;&nbsp; libavdevice/avfoundation.m | 81 +++++++++++++++++++++++++++++++++++---
&gt;&nbsp;&nbsp; 1 file changed, 76 insertions(+), 5 deletions(-)
&gt; 
&gt; diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
&gt; index 36ad834753..668c726eb7 100644
&gt; --- a/libavdevice/avfoundation.m
&gt; +++ b/libavdevice/avfoundation.m
&gt; @@ -770,8 +770,38 @@ static int avf_read_header(AVFormatContext *s)
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AVCaptureDevice *video_device = nil;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AVCaptureDevice *audio_device = nil;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Find capture device
&gt; -&nbsp;&nbsp;&nbsp; NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
&gt; -&nbsp;&nbsp;&nbsp; NSArray *devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
&gt; +&nbsp;&nbsp;&nbsp; NSArray *devices = nil;
&gt; +&nbsp;&nbsp;&nbsp; NSArray *devices_muxed = nil;
&gt; +


&gt; +&nbsp;&nbsp;&nbsp; if (TARGET_OS_IPHONE) {
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (@available(iOS 10.0, *)) {

The preprocessor directives should be more reliable especially on older machines.
See other parts of the code which are handled that way and adopt for your case.


&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [AVCaptureDeviceDiscoverySession
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mediaType:AVMediaTypeVideo
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; position:AVCaptureDevicePositionUnspecified];
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; devices = [captureDeviceDiscoverySession devices];

&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&gt; +&nbsp;&nbsp;&nbsp; } else {
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
&gt; +&nbsp;&nbsp;&nbsp; }

Here and in other chunks you can join the if() conditions into one and avoid the duplication of the old code.


-Thilo
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api
  2023-12-05 14:19   ` Thilo Borgmann via ffmpeg-devel
@ 2023-12-05 14:21     ` Thilo Borgmann via ffmpeg-devel
  0 siblings, 0 replies; 8+ messages in thread
From: Thilo Borgmann via ffmpeg-devel @ 2023-12-05 14:21 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Thilo Borgmann

Am 05.12.23 um 15:19 schrieb Thilo Borgmann via ffmpeg-devel:
> Am 05.12.23 um 15:16 schrieb Thilo Borgmann via ffmpeg-devel:
>> Hi,
>>
>> Am 05.12.23 um 14:33 schrieb xufuji456 via ffmpeg-devel:
>>> Building with iOS platform, the compiler has a warning: "'devicesWithMediaType:' is deprecated: first deprecated in iOS 10.0 - Use AVCaptureDeviceDiscoverySession instead"
>>>
>>> Signed-off-by: xufuji456 <839789740@qq.com>
>>> ---
>>>   libavdevice/avfoundation.m | 25 ++++++++++++++++++++-----
>>>   1 file changed, 20 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
>>> index 36ad834753..1bc99d543a 100644
>>> --- a/libavdevice/avfoundation.m
>>> +++ b/libavdevice/avfoundation.m
>>> @@ -761,6 +761,21 @@ static int get_audio_config(AVFormatContext *s)
>>>       return 0;
>>>   }
>>> +static NSArray* getDevicesWithMediaType(AVMediaType mediaType) {
>>
>>
>>> +#if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000) || (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500))
>>> +    if (@available(macOS 10.15, iOS 10.0, *)) {
>>
>> The preprocessor guard is meant to void the @available condition.
>>
>> Also something appears not yet to achieve what you want, as on MacOS 13.4 I still get the deprication warning:
>>
>> libavdevice/avfoundation.m:776:29: warning: 'devicesWithMediaType:' is deprecated: first deprecated in macOS 10.15 - Use AVCaptureDeviceDiscoverySession instead. [-Wdeprecated-declarations]
>>      return [AVCaptureDevice devicesWithMediaType:mediaType];
>>
>>
>>
>>> +        AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
>>> +            [AVCaptureDeviceDiscoverySession
>>> +            discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
>>> +                                  mediaType:mediaType
>>> +                                   position:AVCaptureDevicePositionUnspecified];
>>> +        return [captureDeviceDiscoverySession devices];
>>> +    }
>>
>>> +#endif
>>
>> why not #else... #endif ?
> 
> #elif
> ... of course.

#else
... writing faster than thinking is no good...


> 
> Also using it, would remove the deprication warning on capable systems. Otherwise it is still in the code and warned about.
> 
> 
>>> +    // fallback
>>> +    return [AVCaptureDevice devicesWithMediaType:mediaType];
>>> +}
>>> +

-Thilo

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api
  2023-12-05 14:16 ` Thilo Borgmann via ffmpeg-devel
@ 2023-12-05 14:19   ` Thilo Borgmann via ffmpeg-devel
  2023-12-05 14:21     ` Thilo Borgmann via ffmpeg-devel
  0 siblings, 1 reply; 8+ messages in thread
From: Thilo Borgmann via ffmpeg-devel @ 2023-12-05 14:19 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Thilo Borgmann

Am 05.12.23 um 15:16 schrieb Thilo Borgmann via ffmpeg-devel:
> Hi,
> 
> Am 05.12.23 um 14:33 schrieb xufuji456 via ffmpeg-devel:
>> Building with iOS platform, the compiler has a warning: "'devicesWithMediaType:' is deprecated: first deprecated in iOS 10.0 - Use AVCaptureDeviceDiscoverySession instead"
>>
>> Signed-off-by: xufuji456 <839789740@qq.com>
>> ---
>>   libavdevice/avfoundation.m | 25 ++++++++++++++++++++-----
>>   1 file changed, 20 insertions(+), 5 deletions(-)
>>
>> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
>> index 36ad834753..1bc99d543a 100644
>> --- a/libavdevice/avfoundation.m
>> +++ b/libavdevice/avfoundation.m
>> @@ -761,6 +761,21 @@ static int get_audio_config(AVFormatContext *s)
>>       return 0;
>>   }
>> +static NSArray* getDevicesWithMediaType(AVMediaType mediaType) {
> 
> 
>> +#if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000) || (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500))
>> +    if (@available(macOS 10.15, iOS 10.0, *)) {
> 
> The preprocessor guard is meant to void the @available condition.
> 
> Also something appears not yet to achieve what you want, as on MacOS 13.4 I still get the deprication warning:
> 
> libavdevice/avfoundation.m:776:29: warning: 'devicesWithMediaType:' is deprecated: first deprecated in macOS 10.15 - Use AVCaptureDeviceDiscoverySession instead. [-Wdeprecated-declarations]
>      return [AVCaptureDevice devicesWithMediaType:mediaType];
> 
> 
> 
>> +        AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
>> +            [AVCaptureDeviceDiscoverySession
>> +            discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
>> +                                  mediaType:mediaType
>> +                                   position:AVCaptureDevicePositionUnspecified];
>> +        return [captureDeviceDiscoverySession devices];
>> +    }
> 
>> +#endif
> 
> why not #else... #endif ?

#elif
... of course.

Also using it, would remove the deprication warning on capable systems. Otherwise it is still in the code and warned about.


>> +    // fallback
>> +    return [AVCaptureDevice devicesWithMediaType:mediaType];
>> +}
>> +
> 
> Thanks,
> Thilo

-Thilo

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api
  2023-12-05 13:33 xufuji456 via ffmpeg-devel
@ 2023-12-05 14:16 ` Thilo Borgmann via ffmpeg-devel
  2023-12-05 14:19   ` Thilo Borgmann via ffmpeg-devel
  0 siblings, 1 reply; 8+ messages in thread
From: Thilo Borgmann via ffmpeg-devel @ 2023-12-05 14:16 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Thilo Borgmann

Hi,

Am 05.12.23 um 14:33 schrieb xufuji456 via ffmpeg-devel:
> Building with iOS platform, the compiler has a warning: "'devicesWithMediaType:' is deprecated: first deprecated in iOS 10.0 - Use AVCaptureDeviceDiscoverySession instead"
> 
> Signed-off-by: xufuji456 <839789740@qq.com>
> ---
>   libavdevice/avfoundation.m | 25 ++++++++++++++++++++-----
>   1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
> index 36ad834753..1bc99d543a 100644
> --- a/libavdevice/avfoundation.m
> +++ b/libavdevice/avfoundation.m
> @@ -761,6 +761,21 @@ static int get_audio_config(AVFormatContext *s)
>       return 0;
>   }
>   
> +static NSArray* getDevicesWithMediaType(AVMediaType mediaType) {


> +#if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000) || (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500))
> +    if (@available(macOS 10.15, iOS 10.0, *)) {

The preprocessor guard is meant to void the @available condition.

Also something appears not yet to achieve what you want, as on MacOS 13.4 I still get the deprication warning:

libavdevice/avfoundation.m:776:29: warning: 'devicesWithMediaType:' is deprecated: first deprecated in macOS 10.15 - Use AVCaptureDeviceDiscoverySession instead. [-Wdeprecated-declarations]
     return [AVCaptureDevice devicesWithMediaType:mediaType];



> +        AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
> +            [AVCaptureDeviceDiscoverySession
> +            discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
> +                                  mediaType:mediaType
> +                                   position:AVCaptureDevicePositionUnspecified];
> +        return [captureDeviceDiscoverySession devices];
> +    }

> +#endif

why not #else... #endif ?

> +    // fallback
> +    return [AVCaptureDevice devicesWithMediaType:mediaType];
> +}
> +

Thanks,
Thilo
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api
@ 2023-12-05 13:33 xufuji456 via ffmpeg-devel
  2023-12-05 14:16 ` Thilo Borgmann via ffmpeg-devel
  0 siblings, 1 reply; 8+ messages in thread
From: xufuji456 via ffmpeg-devel @ 2023-12-05 13:33 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: xufuji456

Building with iOS platform, the compiler has a warning: "'devicesWithMediaType:' is deprecated: first deprecated in iOS 10.0 - Use AVCaptureDeviceDiscoverySession instead"

Signed-off-by: xufuji456 <839789740@qq.com>
---
 libavdevice/avfoundation.m | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
index 36ad834753..1bc99d543a 100644
--- a/libavdevice/avfoundation.m
+++ b/libavdevice/avfoundation.m
@@ -761,6 +761,21 @@ static int get_audio_config(AVFormatContext *s)
     return 0;
 }
 
+static NSArray* getDevicesWithMediaType(AVMediaType mediaType) {
+#if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000) || (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500))
+    if (@available(macOS 10.15, iOS 10.0, *)) {
+        AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession =
+            [AVCaptureDeviceDiscoverySession
+            discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
+                                  mediaType:mediaType
+                                   position:AVCaptureDevicePositionUnspecified];
+        return [captureDeviceDiscoverySession devices];
+    }
+#endif
+    // fallback
+    return [AVCaptureDevice devicesWithMediaType:mediaType];
+}
+
 static int avf_read_header(AVFormatContext *s)
 {
     int ret = 0;
@@ -770,8 +785,8 @@ static int avf_read_header(AVFormatContext *s)
     AVCaptureDevice *video_device = nil;
     AVCaptureDevice *audio_device = nil;
     // Find capture device
-    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
-    NSArray *devices_muxed = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
+    NSArray *devices       = getDevicesWithMediaType(AVMediaTypeVideo);
+    NSArray *devices_muxed = getDevicesWithMediaType(AVMediaTypeMuxed);
 
     ctx->num_video_devices = [devices count] + [devices_muxed count];
 
@@ -806,7 +821,7 @@ static int avf_read_header(AVFormatContext *s)
 #endif
 
         av_log(ctx, AV_LOG_INFO, "AVFoundation audio devices:\n");
-        devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+        devices = getDevicesWithMediaType(AVMediaTypeAudio);
         for (AVCaptureDevice *device in devices) {
             const char *name = [[device localizedName] UTF8String];
             int index  = [devices indexOfObject:device];
@@ -930,7 +945,7 @@ static int avf_read_header(AVFormatContext *s)
 
     // get audio device
     if (ctx->audio_device_index >= 0) {
-        NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+        NSArray *devices = getDevicesWithMediaType(AVMediaTypeAudio);
 
         if (ctx->audio_device_index >= [devices count]) {
             av_log(ctx, AV_LOG_ERROR, "Invalid audio device index\n");
@@ -943,7 +958,7 @@ static int avf_read_header(AVFormatContext *s)
         if (!strncmp(ctx->audio_filename, "default", 7)) {
             audio_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
         } else {
-        NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
+        NSArray *devices = getDevicesWithMediaType(AVMediaTypeAudio);
 
         for (AVCaptureDevice *device in devices) {
             if (!strncmp(ctx->audio_filename, [[device localizedName] UTF8String], strlen(ctx->audio_filename))) {
-- 
2.32.0 (Apple Git-132)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-12-05 14:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-04 12:47 [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api xufuji456 via ffmpeg-devel
2023-12-04 13:55 ` Thilo Borgmann via ffmpeg-devel
2023-12-05  9:42   ` 徐福隆 via ffmpeg-devel
2023-12-04 14:25 ` epirat07
2023-12-05 13:33 xufuji456 via ffmpeg-devel
2023-12-05 14:16 ` Thilo Borgmann via ffmpeg-devel
2023-12-05 14:19   ` Thilo Borgmann via ffmpeg-devel
2023-12-05 14:21     ` Thilo Borgmann via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git