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

Thilo Borgmann thilo.borgmann at mail.de
Mon Dec 4 15:55:23 EET 2023


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 at 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


More information about the ffmpeg-devel mailing list