diff mbox series

[FFmpeg-devel] avdevice/avfoundation: replace AVCaptureDevice with new api

Message ID tencent_E2BA969D84A4B285630019DDC167B27DF309@qq.com
State New
Headers show
Series [FFmpeg-devel] avdevice/avfoundation: replace AVCaptureDevice with new api | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

徐福隆 Dec. 5, 2023, 1:33 p.m. UTC
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(-)

Comments

Thilo Borgmann Dec. 5, 2023, 2:16 p.m. UTC | #1
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
Thilo Borgmann Dec. 5, 2023, 2:19 p.m. UTC | #2
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
Thilo Borgmann Dec. 5, 2023, 2:21 p.m. UTC | #3
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
diff mbox series

Patch

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))) {