From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8A39249BF9 for ; Mon, 4 Mar 2024 19:36:32 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 488F268D494; Mon, 4 Mar 2024 21:36:29 +0200 (EET) Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 56E2D68BF87 for ; Mon, 4 Mar 2024 21:36:22 +0200 (EET) Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-33de4d3483eso2989682f8f.3 for ; Mon, 04 Mar 2024 11:36:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709580981; x=1710185781; darn=ffmpeg.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=7TM7kWeSJFe2oI192vtm36r+OByCWhiytpaT1Mt5EYo=; b=H3SjkaiQ4Dc3X4RagKNSIEj8N8pPf2Z/PvwufSwpppLFfJ7wW2eSJQwAHD6tNWjpLy mVRgWJoLGAGdiDXF/fX+2d/x00OkyXJ1j0yYZvWDpBriS81x6jM3CiKlKu9zqXE6HlL9 w7ZF32Q00BtrnoCqbVM+k1FHjwBOp0vczKZ4PDOVos7R+cXsGQfzLwcq8dlFPQ7eMid/ z/zUYydPfwK0UIGtTIsYvW6TujGfe6uJYKpPSXzks20En3LfLbHNNBOlmXmU+l0l6pxs K0VmxWrqiwStvwKEOhg4Qap6vjZESXrzkWPdGfgKsT0l7SYRO0rDMDByzjsNkeSEfQ8P cg3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709580981; x=1710185781; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7TM7kWeSJFe2oI192vtm36r+OByCWhiytpaT1Mt5EYo=; b=IYFLPxJUix3TblPACAVD31E9FCO0IAoB2OXAspLERUYNpKhA3QALlUm8NzaflXgwu3 IHXaacRhUBRIeJRL7I0NJw+aNaE4ajqEMzHik0P+FWViROyEi9lb7XwOwgfAIRtz5YlO UAsFZohFxUeoStNlrJ7tYdnOxEbkyLlZPKpGpNoOIe4aFHcmrg24OYQ+ZGZueFzA8OoH DjkvNA7yDpTLckJqi1bxcl95RzLwJTfMEvH+2CyP/wvowfvhz/2oVzOZ6GKou143Bv5q dqdr35laQhUiq5AjUi7HITdYjzju6KQ1zm7o71ne2DSYawSsLYV4N5XGkeQ4V++r5xzD 8rZg== X-Gm-Message-State: AOJu0Yy7Ix4xBuJinnnhmlKkC1HPdQj0YjtO5bhoz5tUKMEmZuN/VsbU AhopkLwBUm4GvBKTk8Rd7pWTcvoFWRl+EqDoRGDQ48BQAoL2pA0kWWMwRAIi X-Google-Smtp-Source: AGHT+IFSjlRQfmzyMpRzvA7cUeIk30PyVXRyS4eE2h0UTjDR3OFr9AeiSCigvYVqRo3RhFuQNZ5w/Q== X-Received: by 2002:a5d:4d01:0:b0:33d:69c1:dcc3 with SMTP id z1-20020a5d4d01000000b0033d69c1dcc3mr3497530wrt.56.1709580981337; Mon, 04 Mar 2024 11:36:21 -0800 (PST) Received: from kusa (2a01cb040b6872000000000000000afa.ipv6.abo.wanadoo.fr. [2a01:cb04:b68:7200::afa]) by smtp.gmail.com with ESMTPSA id v16-20020adfa1d0000000b0033e47512f2fsm415103wrv.3.2024.03.04.11.36.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 11:36:20 -0800 (PST) Date: Mon, 4 Mar 2024 20:36:19 +0100 From: Matthieu Bouron To: FFmpeg development discussions and patches Message-ID: References: <20240213230418.457056-1-matthieu.bouron@gmail.com> <20240227145536.281991-1-matthieu.bouron@gmail.com> <20240227145536.281991-2-matthieu.bouron@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="sHeL8jV3+0BAlTrv" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Subject: Re: [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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --sHeL8jV3+0BAlTrv Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Mon, Mar 04, 2024 at 05:35:36PM +0100, Matthieu Bouron wrote: > On Mon, Mar 4, 2024 at 4:11 PM Matthieu Bouron > wrote: > > > > On Mon, Mar 4, 2024 at 12:29 PM Andreas Rheinhardt > > wrote: [...] > > > > > > I am against adding stub functions on platforms where they are known to > > > be useless, i.e. everything except android. > > > > Ok. Will update the patch introducing a new header "jni_android.h". > > Unless we want to also scope avcodec/jni.h to Android only ? > > Or maybe you mean adding a ifdef guard to it ? > New patch attached. The functions are now only built for Android. [...] --sHeL8jV3+0BAlTrv Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="v3-0001-avcodec-add-av_jni_-get-set-_android_app_ctx-help.patch" >From 1b674e78c6a86090f5c9ed6fef5f47ae83ba98be Mon Sep 17 00:00:00 2001 From: Matthieu Bouron Date: Mon, 12 Feb 2024 23:13:09 +0100 Subject: [PATCH v3 1/6] avcodec: add av_jni_{get,set}_android_app_ctx helper 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 | 42 ++++++++++++++++++++++++++++++++++++++++++ libavcodec/jni.h | 17 +++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/libavcodec/jni.c b/libavcodec/jni.c index ae6490de9d..cfe95bd1ec 100644 --- a/libavcodec/jni.c +++ b/libavcodec/jni.c @@ -77,3 +77,45 @@ void *av_jni_get_java_vm(void *log_ctx) } #endif + +#if defined(__ANDROID__) + +int av_jni_set_android_app_ctx(void *app_ctx, void *log_ctx) +{ +#if CONFIG_JNI + JNIEnv *env = ff_jni_get_env(log_ctx); + 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; +#else + return AVERROR(ENOSYS); +#endif +} + +void *av_jni_get_android_app_ctx(void) +{ +#if CONFIG_JNI + void *ctx; + + pthread_mutex_lock(&lock); + ctx = android_app_ctx; + pthread_mutex_unlock(&lock); + + return ctx; +#else + return NULL; +#endif +} + +#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 */ -- 2.44.0 --sHeL8jV3+0BAlTrv Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --sHeL8jV3+0BAlTrv--