From: xufuji456 via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: xufuji456 <839789740@qq.com>
Subject: [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api
Date: Tue, 5 Dec 2023 21:33:34 +0800
Message-ID: <tencent_E2BA969D84A4B285630019DDC167B27DF309@qq.com> (raw)
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".
next reply other threads:[~2023-12-05 13:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-05 13:33 xufuji456 via ffmpeg-devel [this message]
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
-- strict thread matches above, loose matches on Subject: below --
2023-12-04 12:47 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_E2BA969D84A4B285630019DDC167B27DF309@qq.com \
--to=ffmpeg-devel@ffmpeg.org \
--cc=839789740@qq.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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