From patchwork Tue Feb 27 14:50:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Bouron X-Patchwork-Id: 46571 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51b:b0:19e:cdac:8cce with SMTP id gm27csp2043653pzb; Tue, 27 Feb 2024 06:56:15 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUCDOfA0L5ePbRGvexQ+OfNQWRWkFQO98yKLfq41Pb4Ljz9rRyWjLfn21HukmuD6LVyZdTOZnoShfV6X9xTx1QSWo4FtOFi/Uhx/Q== X-Google-Smtp-Source: AGHT+IHkfMOBy9maU9BMC+meq3/kscKv4q0kVZ0h5HFR3DaFEb9WsmPbOHWQiZoWeOzS7k6ucmo8 X-Received: by 2002:a17:906:2b88:b0:a3f:2e6f:800e with SMTP id m8-20020a1709062b8800b00a3f2e6f800emr6670764ejg.24.1709045775602; Tue, 27 Feb 2024 06:56:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709045775; cv=none; d=google.com; s=arc-20160816; b=tvqEol/Em7cv3gGew48xZhBZyP4aNKIxW6WiPRIU1a99N8cn1aVkX0AmgcKLJ5sMQr PlgQQZEgXLEyX1PZQC0vne1MwR0cJDcN7S772e5AtZqV286vy82mTUIb7ECMYibIIo1d tAOGTkhtJxsGAG6HTRDpx7DOEBOPcpnRvZ9u6j/VpDlRxEhnPEbF9eovcCj5/39OeP0I /Dz9WmCKcZUdHTg1sas6rQN5Gl1He/s8ZgcHU4cVqvEhAIyLifxwsFwjp6b8gvpHT6wa UjDA5r+QDfLS59EsMskHxPNdCg5AgiC8Oh9cWol+Q2Q62ZP6E6Y0k3D2V5T1nmZq12f5 pIsA== 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 :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=DgbpW5QLheupjw17wDUFJn3fDUhyOtZzabKBZ3c3YKI=; fh=bsOL+ub9JEnfNazRgCdgjxJAChubFVskZxBzYcxeDLU=; b=Ktuks2bhpK3S/zFyax+OrEZ+jHQMnB7RTfcpdJG+dgwfd7Tio6TscXeTAdiavGgF9h X5XHIqgamiXKQFjc4l5UOmgK/2LGh4mvFH8QZyEvlP4oixRZjqUO9YGuOw7p+HTSHCuP hNCYqB1pwbtlRmp3eaQ3g0Im+OIk2HHTj7vmjyrz3xVMT3SUvchUAz69fj25USDGQ8qm 9RvyzDVD1EthAOBscz/WpfgBKRHNsPhb6IL6zW7UXeRoufL8tXp+Fv1yCH1Ey22+5mon 75AQf30yA7Vu0WVHaXVH3AbG1Bl9EB7JY31KkarKRO1edTDcVRqwzMKYxcFCSSb5IRui bDMQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=lVJruL45; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id oq2-20020a170906cc8200b00a438d35b117si757266ejb.521.2024.02.27.06.56.15; Tue, 27 Feb 2024 06:56:15 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=lVJruL45; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 33BEF68CC1D; Tue, 27 Feb 2024 16:56:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E075E68CBD7 for ; Tue, 27 Feb 2024 16:55:58 +0200 (EET) Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5101cd91017so6418327e87.2 for ; Tue, 27 Feb 2024 06:55:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709045758; x=1709650558; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RwW1CJQtfQILe+wiKC0hERGdn0Ju6cDDGRNPYfPybJo=; b=lVJruL453zS71iq+GdOZgpEXbVO6qKcI8pYRhqvtShf4ehpzl3ZfWmSC+9mm2SxncE ozGjOUiwpzyO1lMstWgWwCHWCQUtEOgct99bQhqakURe/x1YJ0sz7A9b7qkcrF8SRdNi JbpvWU4Tti6S+fO+8pzS8YLTY2QbOrd4C2QBEG4WVxku0FeFVLYWZVXJWv+e3162JO1O BBOXKc77wS5yVqSrj3VYXVoBhxbGuuRDpXNpkHhVM5DMS/I/IREvajY5PIJL4PvMQ0+O 3KaP0j5pdIeIcMniDk5csgMDlzup1ikyU9uC6h+vtLZzftbvtmodj/6j/wNVV9PGILy7 sQQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709045758; x=1709650558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RwW1CJQtfQILe+wiKC0hERGdn0Ju6cDDGRNPYfPybJo=; b=FYi4qQnp4clpDdtIqPvGWewYArYtgOe1jhY8C3yarycx9wPDwypjpcVG9J4ZX9Vysd 2k4vdgIZnKrhd583GWH8PHf3YGyvSeD0YU7IL1vBpsARv29B0wifxyhuUF+cagxLWe9I Cs5WMXo5wado5FbQ4XmxDoiH8WmIjKydkqQJgoMsLeZxVyOr8hexguAexbrgddD39jNr TL5r5HCAuicDuzDfwhlnEr4UoybJtSNLnWhyqD+p1rRipmmHVS7RLPNMtULNdEAXs2DY DUQe5mRE5ERq11N2mKEWbu10cNU6qx+w87zsRU9wbLTEismuDaSApEI5rFlqb2bbGvIe m8tA== X-Gm-Message-State: AOJu0YzFVTHCvwH6AkzkUHE76f1lTOSWXW9tUEnS5Qudt0HBbu9fOGB3 RFtq48swbVE+YP01nzVLPrANQJQZmTLOP6UPd2BG1AxcmVMCkvjg9ITtedSV X-Received: by 2002:a05:6512:48da:b0:511:88cc:4f00 with SMTP id er26-20020a05651248da00b0051188cc4f00mr5759203lfb.56.1709045757666; Tue, 27 Feb 2024 06:55:57 -0800 (PST) Received: from localhost.localdomain (2a01cb040b6872000000000000000afa.ipv6.abo.wanadoo.fr. [2a01:cb04:b68:7200::afa]) by smtp.gmail.com with ESMTPSA id o9-20020a5d4a89000000b0033df1dc39f0sm1859627wrq.4.2024.02.27.06.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 06:55:57 -0800 (PST) From: Matthieu Bouron To: ffmpeg-devel@ffmpeg.org Date: Tue, 27 Feb 2024 15:50:37 +0100 Message-ID: <20240227145536.281991-2-matthieu.bouron@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227145536.281991-1-matthieu.bouron@gmail.com> References: <20240213230418.457056-1-matthieu.bouron@gmail.com> <20240227145536.281991-1-matthieu.bouron@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/6] avcodec: add av_jni_{get, set}_android_app_ctx helper 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: , Reply-To: FFmpeg development discussions and patches Cc: Matthieu Bouron Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: beCOvu4bkhIF This will allow users to pass the Android ApplicationContext which is mandatory to retrieve the ContentResolver responsible to resolve/open Android content-uri. --- libavcodec/jni.c | 40 ++++++++++++++++++++++++++++++++++++++++ libavcodec/jni.h | 17 +++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/libavcodec/jni.c b/libavcodec/jni.c index ae6490de9d..7d04d0a268 100644 --- a/libavcodec/jni.c +++ b/libavcodec/jni.c @@ -64,6 +64,36 @@ void *av_jni_get_java_vm(void *log_ctx) return vm; } +int av_jni_set_android_app_ctx(void *app_ctx, void *log_ctx) +{ + JNIEnv *env = avpriv_jni_get_env(c); + if (!env) + return AVERROR(EINVAL); + + jobjectRefType type = (*env)->GetObjectRefType(env, app_ctx); + if (type != JNIGlobalRefType) { + av_log(log_ctx, AV_LOG_ERROR, "Application context must be passed as a global reference"); + return AVERROR(EINVAL); + } + + pthread_mutex_lock(&lock); + android_app_ctx = app_ctx; + pthread_mutex_unlock(&lock); + + return 0; +} + +void *av_jni_get_android_app_ctx(void) +{ + void *ctx; + + pthread_mutex_lock(&lock); + ctx = android_app_ctx; + pthread_mutex_unlock(&lock); + + return ctx; +} + #else int av_jni_set_java_vm(void *vm, void *log_ctx) @@ -76,4 +106,14 @@ void *av_jni_get_java_vm(void *log_ctx) return NULL; } +int av_jni_set_android_app_ctx(void *app_ctx, void *log_ctx) +{ + return AVERROR(ENOSYS); +} + +void *av_jni_get_android_app_ctx(void) +{ + return NULL; +} + #endif diff --git a/libavcodec/jni.h b/libavcodec/jni.h index dd99e92611..da8025f830 100644 --- a/libavcodec/jni.h +++ b/libavcodec/jni.h @@ -43,4 +43,21 @@ int av_jni_set_java_vm(void *vm, void *log_ctx); */ void *av_jni_get_java_vm(void *log_ctx); +/* + * Set the Android application context which will be used to retrieve the Android + * content resolver to resolve content uris. + * + * @param app_ctx global JNI reference to the Android application context + * @return 0 on success, < 0 otherwise + */ +int av_jni_set_android_app_ctx(void *app_ctx, void *log_ctx); + +/* + * Get the Android application context that has been set with + * av_jni_set_android_app_ctx. + * + * @return a pointer the the Android application context + */ +void *av_jni_get_android_app_ctx(void); + #endif /* AVCODEC_JNI_H */