From patchwork Mon Dec 4 12:47:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5b6Q56aP6ZqG?= <839789740@qq.com> X-Patchwork-Id: 44901 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a301:b0:181:818d:5e7f with SMTP id x1csp2738595pzk; Mon, 4 Dec 2023 04:47:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4rDTSi8bc6fs9TQco7VWWtdm0+nTVKua+v3yIVxJ7bZQfCX0+gVFQq6cuKKg7J2Vej5IP X-Received: by 2002:a50:950e:0:b0:54c:4837:8b85 with SMTP id u14-20020a50950e000000b0054c48378b85mr3158084eda.83.1701694071566; Mon, 04 Dec 2023 04:47:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701694071; cv=none; d=google.com; s=arc-20160816; b=ugZwnPyYgPle96kj8V8g4Chg5jRtron507dG45beSQRiDQNuju90jrJGS75oVqA7Xo VPj16jXKRKw4DSK4vyzEr9w33yGfoG9CLolglLsjElX/wtoE8lcuEysOW75uC6PcWy6+ NpdOEmSYMwHz6+H5nz2l4Tg+Es6zX88p37dZmCts6MCTnufrvXDleq+yVUPtyWYzXEok eYjp3OMggBx6DPNdc8DJc5VXBnGAdSxO8lFJ5VJ7UebrTKUZuiIMZDhcOjTwet7d7lf+ hgCoCW745+w6AxvhJmhz+M62cvfxt34IlSVy1lX9vL23djnbZTwYlipqRHNSS0MbwrOe B/Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:date:to:message-id :delivered-to; bh=lewy+mA0JTIDiCGrZBCBOs0LTfRiW4TGscos0kcfwUM=; fh=/QvfVIDcib8YPugs5q/sxqF0zCx8M9migilS77PcQx8=; b=JRa2m/ffKz1ObIO9g3qcZfz2O4kVO5EVGRQpTBZsr9U7opLkQNHdGnFRYm5aupKs5J ZNaSQdUZJ7ujzd3JXVgwGfEQH6oO938zmYMViBnaOxIxYBelSEv9aMs0nsfPDHoKqmTf sm6QEoouYejxiSLBtgQpo+CPrwx6//+PTXv96HvAfpOyCCSXpYcsf4RZlLnHgJuVUlgH ow7FIw92wt1yI2H7HdlS2liLg0RgyIgsfF5wTw9RzxKKQBiGC59L2WWhRcrWNAN66j5z FMU4Crsn57o7Sah8bGAkxhY0pIXeQyBK/3iAhXSI0bGmcaP2wXYS8TRfPdsjnAt8Qrod cKHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v12-20020a50d08c000000b0054cfc6ddd02si39582edd.91.2023.12.04.04.47.50; Mon, 04 Dec 2023 04:47:51 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C265F68C9FD; Mon, 4 Dec 2023 14:47:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-221-210.mail.qq.com (out203-205-221-210.mail.qq.com [203.205.221.210]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 09DA368C867 for ; Mon, 4 Dec 2023 14:47:38 +0200 (EET) Received: from localhost.localdomain ([14.145.2.241]) by newxmesmtplogicsvrszc5-2.qq.com (NewEsmtp) with SMTP id BE237CAB; Mon, 04 Dec 2023 20:47:34 +0800 X-QQ-mid: xmsmtpt1701694054t3jmrkvbg Message-ID: X-QQ-XMAILINFO: MyIXMys/8kCtdGxRSwqB2Vd01GpdkWbz+T4HEsD4bqaNfNLTrv0uaOX60H1U8I 4PokjdOIk/3htrD+2E/nT42ePkFf0tckevKcZUVA4jJojq6jm9616Bi4bYj/fumbQhrJ/4qw1zfL 022aXLDwqCQa+GruJPjM9tJnjT/ngqXfAvsqDI6RCnkXiFwdgQS346t4M5Ux+OYfztML2Xvr2JiV fZH2duPOb05B2pirQWz1y0stlXjMbXdUlo2F154rNHkFBEclfuR7Pq5eMgW31s3yJ+BFjoG+kkK1 M17pcPk5HMXvD0Gf825OZ+HaXzdhP4uBbQiKTiLag3Pu/BBxBv7poZyNIKU5w+Y9Cs7V+y2CD9Yc 3aUx/rFLPV9sN+dkaqH3szv1ZW2EDpYUuiJmIbZHw2jl2TxTDvsBgWHJzBXF3XbvLqMBBWmUp+rM Pf9gAcRmQLEsauvzD9foADVvtL9ZhLWTfIYYbCOF0VaMqXadlhyOHHztSQCShgE7j90N7aymZVBO PLO7GdmvmK9YhFSFej8y4oqhC7flMZ2nvpq44xic/oyhq5ro2BUbRD7XO4AglF0vAPemv7p9Qu43 15Ok+84YihOYBRB1bWYA73wfT4RVFZF06ug5jV7J18XXq8jEetrqltLoDm0If3vhufqpv7IXthHr /yCNqdFrUObERC+VtGcCcD2NUMn5ZbKxPVQLGhvQbX73gRkhaK2m7R+sxqZfmCRVMTf+KB//bM1b uK6eRFMFKFjCMLpoDNnM1M1LLCfZxl8vGqhEg9ZHDBtSTz+79dQBljyPj6nWTDtqYSMZxtx/9I4b 007eiJkydbVM3z8rkHqSCYSwc63Vqqor7KqpYm+DeunByyFU05KL9TJfZ4M85JFS3NBz0j5ayL3q Am7HM3zcRcIztD+sWhOgytp+ynQ+CN/WdCNOmeCzIrx/oHnkMwRFAGFjSnBLwkMfJDcjUBk1zcly l6+ugvW9RhWyHEmdg/RaAdc68AG4/QVNvrPE333/Y= X-QQ-XMRINFO: OWPUhxQsoeAVDbp3OJHYyFg= To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Dec 2023 20:47:31 +0800 X-OQ-MSGID: <20231204124731.56360-1-839789740@qq.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avdevice/avfoundation: replace AVCaptureDevice with new api X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: xufuji456 via ffmpeg-devel From: =?utf-8?b?5b6Q56aP6ZqG?= <839789740@qq.com> Reply-To: FFmpeg development discussions and patches Cc: xufuji456 <839789740@qq.com> Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: USNPRs7oPjmw 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))) {