From patchwork Mon Dec 4 01:32:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 6532 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp3843873jah; Sun, 3 Dec 2017 17:32:40 -0800 (PST) X-Google-Smtp-Source: AGs4zMZWuVLdO8pxxEJNDAQ912CrM4FbWqgQnfXLMtcNTYMj64Zb+Ame0ednINtvcxs/UveDrGMW X-Received: by 10.223.198.3 with SMTP id n3mr12595097wrg.73.1512351160005; Sun, 03 Dec 2017 17:32:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512351159; cv=none; d=google.com; s=arc-20160816; b=KklZig1iV19Hzott8F0IcAj5+myPsjYH9ftyt+cvtZwdCh4myakXkLfF4FEuV/jCxl w1O74d9S8bot/idsQU5TuUorBTOn3fymvmg358qo0rPlY+i42WrIsXYlHTxBu1PURhQ9 KFfOs+up60aeQDVBdjAQzNnWZTxnM+QNoNMQhDc4y22F15gnN+PaVTVRedfTeaxQTAB9 aSe9RuUfqzKBIGjMHborbOW9CBNT4rYbt5TSFPsXWWQlSk5jASsTq8AKbr0x9jMOzAcs 4vIzRHthrSxFbLkFAUnxwSFrDYJSBr9OMipJTat3Vue0Nq76qGyA8Ee5UuiMmQIjluUg NHVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=9gaKZkTbh7gOERT19AORq91AKwF19vL/MYbtgUgjMNc=; b=gSpB2Wa1Jqg9bJbnG/X7cfp8bRBYF1RHspyeUQmbuo61FtjaraDhd+rGeUufXNpO34 lhYl2A/zd/uvQYeaa5zv3zX6kSgpgqsyuaNzuREk8GSxyMmbMXWYL4h/P7P/v3Uy41Qn 2nLpj/ts2Q0OkmwHzUiK5l+lbCZWDUeWHZ092/k9peC1fzEm9m8oWc3hWhaAqV2uS1IT eEBBNY9dtGN1nbuDh6nkjj6sofSbB0uGxbaWSMU4/1dRVffHXa925BNsqNKSOhRHIe8l UetfeuOiEjPPnRJEyVv53h5PjOW8TmUFPhRki5qP6bghGAOF6RHB9UHPgBuv0aF2cjfv cHWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=mIoD9RyI; 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 t4si8989237wrb.289.2017.12.03.17.32.38; Sun, 03 Dec 2017 17:32:39 -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=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=mIoD9RyI; 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 DD0F068A338; Mon, 4 Dec 2017 03:32:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f67.google.com (mail-it0-f67.google.com [209.85.214.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 03C0868A2C7 for ; Mon, 4 Dec 2017 03:32:26 +0200 (EET) Received: by mail-it0-f67.google.com with SMTP id f143so2904504itb.0 for ; Sun, 03 Dec 2017 17:32:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=QcBipmlaYk0XYRNyB5PRAN9MV4rwNZYrnVvSJWtvRy0=; b=mIoD9RyIA9o5bOFl7hQyIhv4ELZZ6YsyR9kNBrwer9WADnXgy+o+t664xLgz1QqQDP 2KSTaP2ljyMag4lqellQE3r22WqpBixMU+YwBoe3Uo0pEB88C1aPznN35wGznocoWoWU zZ34zkK/qPx6E7YVGXlfkCE0wExYhMxjs7uaa61SyPKnmIsXgqTiNICOjT2Qe7ByeNyn +6yt5gmPCkOsl9ORUx1DXSXYYgu+tEs3zYQbNWJCYxOqO/gfmcuL9r0x9vtPwZYO3C/3 CssQoFAZlOVjJed4ZotXrloIxEdG+VGIBTe+ZimruL7CRTTNyHq5zX2qCro5edy9UvbT xCbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=QcBipmlaYk0XYRNyB5PRAN9MV4rwNZYrnVvSJWtvRy0=; b=pzXTL13MZSnYQW20YvseBrlk4ARQueStCafya6WuvQ3AYGWm/89D2nE9ldfrp9l0SF Zc3s6Hn+ExqeGXkLVM1aYJUMx+ieOdVQdn1VtD66eEh7O/9VCBLIkE1MKuPuD7QphGUA vTrr8mh4ReKfdbtljg1ZD7bh98Na0Is4UnLwlO2YIat+w/m60y9vU1T4n/mkrSFkdLqQ bHNueNQsPDj4yL72rIiu127Xlx18hyAuX1Z2e3HWlDKiN/qiSc2Sty/hrUttjQGDyH9/ /PI9L7kYT6VO8mGaeLPREtycrZxnZPQkcoUWOZ6Fb0wUXoRWXFt8/6HEsACsNFVIsIsG JoTw== X-Gm-Message-State: AJaThX6HQ+drzBJpyR3wgu6XHuWQ7fBcEu9OHc9iDN4rg45oeLx6p1a0 KwytQ4+gyVrR/1CboKjQtUWswPnS X-Received: by 10.107.144.136 with SMTP id s130mr21316588iod.29.1512351148762; Sun, 03 Dec 2017 17:32:28 -0800 (PST) Received: from localhost.localdomain (24-196-247-173.dhcp.reno.nv.charter.com. [24.196.247.173]) by smtp.gmail.com with ESMTPSA id m72sm5399819ioe.40.2017.12.03.17.32.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Dec 2017 17:32:27 -0800 (PST) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Sun, 3 Dec 2017 17:32:21 -0800 Message-Id: <20171204013222.36272-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.13.6 (Apple Git-96) In-Reply-To: <20171202231409.32371-1-ffmpeg@tmm1.net> References: <20171202231409.32371-1-ffmpeg@tmm1.net> Subject: [FFmpeg-devel] [PATCH v2 1/2] libavutil/hwcontext: add AV_HWDEVICE_TYPE_MEDIACODEC X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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@stupeflix.com, nfxjfg@googlemail.com, Aman Gupta , sw@jkqxz.net MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta --- libavutil/Makefile | 1 + libavutil/hwcontext.c | 4 ++++ libavutil/hwcontext.h | 1 + libavutil/hwcontext_mediacodec.c | 50 ++++++++++++++++++++++++++++++++++++++++ libavutil/hwcontext_mediacodec.h | 36 +++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 libavutil/hwcontext_mediacodec.c create mode 100644 libavutil/hwcontext_mediacodec.h diff --git a/libavutil/Makefile b/libavutil/Makefile index 721784086c..0b73a14f0b 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -166,6 +166,7 @@ OBJS-$(CONFIG_OPENCL) += hwcontext_opencl.o OBJS-$(CONFIG_VAAPI) += hwcontext_vaapi.o OBJS-$(CONFIG_VIDEOTOOLBOX) += hwcontext_videotoolbox.o OBJS-$(CONFIG_VDPAU) += hwcontext_vdpau.o +OBJS-$(CONFIG_MEDIACODEC) += hwcontext_mediacodec.o OBJS += $(COMPAT_OBJS:%=../compat/%) diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index f47158f811..31ac12807b 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -56,6 +56,9 @@ static const HWContextType * const hw_table[] = { #if CONFIG_VIDEOTOOLBOX &ff_hwcontext_type_videotoolbox, #endif +#if CONFIG_MEDIACODEC + &ff_hwcontext_type_mediacodec, +#endif NULL, }; @@ -69,6 +72,7 @@ static const char *const hw_type_names[] = { [AV_HWDEVICE_TYPE_VAAPI] = "vaapi", [AV_HWDEVICE_TYPE_VDPAU] = "vdpau", [AV_HWDEVICE_TYPE_VIDEOTOOLBOX] = "videotoolbox", + [AV_HWDEVICE_TYPE_MEDIACODEC] = "mediacodec", }; enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name) diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index 8d27b987df..f5a4b62387 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -35,6 +35,7 @@ enum AVHWDeviceType { AV_HWDEVICE_TYPE_D3D11VA, AV_HWDEVICE_TYPE_DRM, AV_HWDEVICE_TYPE_OPENCL, + AV_HWDEVICE_TYPE_MEDIACODEC, }; typedef struct AVHWDeviceInternal AVHWDeviceInternal; diff --git a/libavutil/hwcontext_mediacodec.c b/libavutil/hwcontext_mediacodec.c new file mode 100644 index 0000000000..b0d8993e15 --- /dev/null +++ b/libavutil/hwcontext_mediacodec.c @@ -0,0 +1,50 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "buffer.h" +#include "common.h" +#include "hwcontext.h" +#include "hwcontext_internal.h" +#include "hwcontext_mediacodec.h" + +static int mc_device_create(AVHWDeviceContext *ctx, const char *device, + AVDictionary *opts, int flags) +{ + if (device && device[0]) { + av_log(ctx, AV_LOG_ERROR, "Device selection unsupported.\n"); + return AVERROR_UNKNOWN; + } + + return 0; +} + +const HWContextType ff_hwcontext_type_mediacodec = { + .type = AV_HWDEVICE_TYPE_MEDIACODEC, + .name = "mediacodec", + + .device_hwctx_size = sizeof(AVMediaCodecDeviceContext), + + .device_create = mc_device_create, + + .pix_fmts = (const enum AVPixelFormat[]){ + AV_PIX_FMT_MEDIACODEC, + AV_PIX_FMT_NONE + }, +}; diff --git a/libavutil/hwcontext_mediacodec.h b/libavutil/hwcontext_mediacodec.h new file mode 100644 index 0000000000..101a9806d5 --- /dev/null +++ b/libavutil/hwcontext_mediacodec.h @@ -0,0 +1,36 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_HWCONTEXT_MEDIACODEC_H +#define AVUTIL_HWCONTEXT_MEDIACODEC_H + +/** + * MediaCodec details. + * + * Allocated as AVHWDeviceContext.hwctx + */ +typedef struct AVMediaCodecDeviceContext { + /** + * android/view/Surface handle, to be filled by the user. + * + * This is the default surface used by decoders on this device. + */ + void *surface; +} AVMediaCodecDeviceContext; + +#endif /* AVUTIL_HWCONTEXT_MEDIACODEC_H */