Message ID | tencent_2C0E70D0ECB1BC8A6559A1B9ECAD983E4607@qq.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel] avdevice/avfoundation: replace AVCaptureDevice with new api | expand |
Context | Check | Description |
---|---|---|
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
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
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".
Thank you for your suggestion.
I will adapt the judgment condition, and submit again.
------------------ Original ------------------
From: "FFmpeg development discussions and patches" <ffmpeg-devel@ffmpeg.org>;
Date: Mon, Dec 4, 2023 09:55 PM
To: "ffmpeg-devel"<ffmpeg-devel@ffmpeg.org>;
Cc: "Thilo Borgmann"<thilo.borgmann@mail.de>;
Subject: Re: [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api
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
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))) {
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(-)