From patchwork Thu Jun 6 11:51:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiqi Zhu X-Patchwork-Id: 49619 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:c209:0:b0:460:55fa:d5ed with SMTP id d9csp318511vqo; Thu, 6 Jun 2024 04:51:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUcE3/rSUGcGpicqrlOIoBBGyf/ckhHwcBQwI4KXCD0Pg+VYKWectJYa81IpSnoHx2O+5dDQtxT4vS5U0suh705NzwBiFVkmzCkSA== X-Google-Smtp-Source: AGHT+IFTEeksqVsyTzUmdkBfrhi97x/02yY9Sj5ASLI1R0EUtMf87TkqIseDy9Geip1nUSi9z55/ X-Received: by 2002:a50:cdd3:0:b0:579:c471:dbd0 with SMTP id 4fb4d7f45d1cf-57a8b6f18e2mr3143364a12.21.1717674680632; Thu, 06 Jun 2024 04:51:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717674680; cv=none; d=google.com; s=arc-20160816; b=qLxAGUM4JqxUmB9FAhqHkPImQ5xbZpB7h2pDrmCrSJhjM+SjaAybyHvwL8II2qqqbD 3mpUnSC7bTswZyAidb0n7vm85ys8ycXBR8hhL5gvaaaJ/RoUR0dBWPbbNI4BwRB0ovdz +FfJ0iGt+4al5aX3EtDn3LAndlf7YM5c2iXpdpdJl7BysuRaVC/0/Wqh+XTAYE3R1IMb ByD5ZOB8AWYrLvLgJz1I0FoD6enQTLfp46DgoFDL63Dp+IqoXCmcvfUhql7WEyIapTrL MxdxCzoWu3/229ZKTMUi6k9BPL01AVpgFPf8Drhei/jn7QE+YE9vR2xIK2SN3NOIehKJ KDGA== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=/JVZWIlHY9Ot2MZ6tF7f9n3CAVCTe3gIt7/CaDzqaZk=; fh=jGeylq5Cq8cixZoV2Zp7uaY6E5GFel41JHto3Y2hIBs=; b=WEFW1qIiZwmVyX2W+0V4Zmqy06CveBvXn7JFDYbZgXTMGAwBOf9v+zOZb/PUQs6SX5 isJgLOQ1XAlnRUOm9ShRpW2KGuP9Pqy1ufD2YUy2xuqYnX+cYezXpB+HTxnQAvnXxove wh9T6JqT5dfHCG2hWdYlBg+Kaw8ceAIQdl4ZiyF0I4A+6Tl60NYWu0mM8OlfIjCMvRrt RJBemzjihJgT3/WCUP4miKF90d589sQIMLuG+nOmCmE3b9kGteuJcm7qd+zY2R/8D6VP Mw1hLcRCC/iRq6L4Sv8daLRjNaGAv4FLh02l4xuhjOWn//UokF0nhRt+aynfRGwB9U54 pg+w==; 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=Lat2YuSr; 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 4fb4d7f45d1cf-57aae262fddsi633187a12.551.2024.06.06.04.51.18; Thu, 06 Jun 2024 04:51:20 -0700 (PDT) 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=Lat2YuSr; 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 995DC68D222; Thu, 6 Jun 2024 14:51:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1CDFC68D3C5 for ; Thu, 6 Jun 2024 14:51:09 +0300 (EEST) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70260814b2dso668007b3a.1 for ; Thu, 06 Jun 2024 04:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717674666; x=1718279466; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BwWgHczkkUrzMZ4EzbfxItFxTXmxI0jAAWl1PBL9EiQ=; b=Lat2YuSrX2C1g7ewUZ9mJERgexCqyYiOTtdkgTKI8Y3OkqaUJCjBnODfZela91NsZ0 KvxuYdQv0c9aoIXC/zRG0ztQOBmiFOQ7ytmS6EQrzUmeltRW2hTEfUBeSjn73R/sRCM0 SHZg/yKGTJKyWNPS0te4V/VxJJ0hfxYsuLANzV/iCemOOl0dxIK6hrNfXjOO3xP3T7Sk xvJ37KSFhGGu3VxBhJwnXlvqKYF5xR1M6LocHhixA6ECUskffDM8PpkIC0GhuS9JGVKv x4bXJjFdnJmFQYr5/5qNLRP8MX6Ufd1MED1EMab2bKBdb8rlPjzDObaBGbVMHRN58c8i F1og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717674666; x=1718279466; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BwWgHczkkUrzMZ4EzbfxItFxTXmxI0jAAWl1PBL9EiQ=; b=JH7mDUovyCDv3tF2ki/KC/5LV/NwP53fq0dGS8557xMFMt7i2eZpAMYbdNgtPGtcLE CQ/n88e4J9lwpy8JE/CEzGM9N/bsQIMv+beitWl6aRqXJ78aYqHiWCcaTWAKcw3TBZ9M NQa0BzLHb8lt7CijY2Z8+RjEoJvd6siPBUqeVuFVm71NN/Um/gpHS/lLcpI+g9slW/53 7j53CSMJkRGcvrEQgdfE5q/aQFTtZ+rUqcRrKTNzYTUHkujlG4m5f+3eVgAaBJmUfeMw kT77etlDEdqe87w3woIhPEVOPgSHG7kQ3ZcDXzNHjDPEac67hiPZ26cNZQjkJ0KTZieN y20A== X-Gm-Message-State: AOJu0Ywyg7UyCvzMo9DvX7vYOsRYAuAQraW2kSlQ738+xqxCUuBFFd8q pk2FiJWlDP42ffsfe1evulZuSaijeTTPTKI9UrPGiNt7RJ1RnimIRZZrGQ== X-Received: by 2002:a05:6a00:3c84:b0:702:5643:9504 with SMTP id d2e1a72fcca58-703f883736fmr3826702b3a.9.1717674665707; Thu, 06 Jun 2024 04:51:05 -0700 (PDT) Received: from PC.mioffice.cn ([43.224.245.231]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-703fd397469sm965692b3a.77.2024.06.06.04.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 04:51:05 -0700 (PDT) From: Shiqi Zhu To: ffmpeg-devel@ffmpeg.org Date: Thu, 6 Jun 2024 19:51:00 +0800 Message-Id: <20240606115100.44233-1-hiccupzhu@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter: add sdlvsink for video display 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: Shiqi Zhu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 9r/vBNaFWikc Signed-off-by: Shiqi Zhu --- configure | 1 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vsink_sdlvsink.c | 142 +++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 libavfilter/vsink_sdlvsink.c diff --git a/configure b/configure index 6c5b8aab9a..968b5c8912 100755 --- a/configure +++ b/configure @@ -3977,6 +3977,7 @@ xstack_qsv_filter_deps="libmfx" xstack_qsv_filter_select="qsvvpp" pad_vaapi_filter_deps="vaapi_1" drawbox_vaapi_filter_deps="vaapi_1" +sdlvsink_filter_deps="sdl2" # examples avio_http_serve_files_deps="avformat avutil fork" diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 5992fd161f..feac6b464d 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -616,6 +616,7 @@ OBJS-$(CONFIG_YUVTESTSRC_FILTER) += vsrc_testsrc.o OBJS-$(CONFIG_ZONEPLATE_FILTER) += vsrc_testsrc.o OBJS-$(CONFIG_NULLSINK_FILTER) += vsink_nullsink.o +OBJS-$(CONFIG_SDLVSINK_FILTER) += vsink_sdlvsink.o # multimedia filters OBJS-$(CONFIG_A3DSCOPE_FILTER) += avf_a3dscope.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index c532682fc2..d5f942ffb5 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -579,6 +579,7 @@ extern const AVFilter ff_vsrc_yuvtestsrc; extern const AVFilter ff_vsrc_zoneplate; extern const AVFilter ff_vsink_nullsink; +extern const AVFilter ff_vsink_sdlvsink; /* multimedia filters */ extern const AVFilter ff_avf_a3dscope; diff --git a/libavfilter/vsink_sdlvsink.c b/libavfilter/vsink_sdlvsink.c new file mode 100644 index 0000000000..630f719c7e --- /dev/null +++ b/libavfilter/vsink_sdlvsink.c @@ -0,0 +1,142 @@ +/* + * 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 "avfilter.h" +#include "internal.h" +#include "libavutil/internal.h" +#include +#include + +typedef struct { + SDL_Window *window; + SDL_Renderer *render; + SDL_Texture *texture; +} SDLVideoContext; + +static int init(AVFilterContext *ctx) +{ + if (SDL_Init(SDL_INIT_VIDEO) < 0) + { + av_log(ctx, AV_LOG_ERROR, "SDL2 could not initialize! %s\n", SDL_GetError()); + return -ENOMEM; + } + + SDL_PollEvent(NULL); + SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0"); + + return 0; +} + +static void uninit(AVFilterContext *ctx) +{ + SDLVideoContext *sink = ctx->priv; + + if (sink->texture) { + SDL_DestroyTexture(sink->texture); + sink->texture = NULL; + } + + if (sink->render) { + SDL_DestroyRenderer(sink->render); + sink->render = NULL; + } + + if (sink->window) { + SDL_DestroyWindow(sink->window); + sink->window = NULL; + } + + SDL_Quit(); +} + +static int filter_frame(AVFilterLink *link, AVFrame *frame) +{ + AVFilterContext *ctx = link->dst; + SDLVideoContext *sink = ctx->priv; + SDL_RendererInfo renderer_info; + + if (!sink->window) { + sink->window = SDL_CreateWindow("YUV Player", + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + frame->width, frame->height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); + if (!sink->window) { + av_log(ctx, AV_LOG_ERROR, "SDL2 could not create window %s\n", SDL_GetError()); + return -ENOMEM; + } + } + + if (!sink->render) { + sink->render = SDL_CreateRenderer(sink->window, -1, 0); + if (!sink->render) { + av_log(ctx, AV_LOG_ERROR, "SDL2 could not create render %s\n", SDL_GetError()); + return -ENOMEM; + } + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); + + SDL_GetRendererInfo(sink->render, &renderer_info); + av_log(ctx, AV_LOG_INFO, "sdl2 renderer name:%s\n", renderer_info.name); + } + + if (!sink->texture) { + sink->texture = SDL_CreateTexture(sink->render, SDL_PIXELFORMAT_IYUV, + SDL_TEXTUREACCESS_STREAMING, frame->width, frame->height); + if (!sink->texture) { + av_log(ctx, AV_LOG_ERROR, "create texture failed %s\n", SDL_GetError()); + return -EINVAL; + } + } + + SDL_UpdateYUVTexture(sink->texture, NULL, + frame->data[0], frame->linesize[0], + frame->data[1], frame->linesize[1], + frame->data[2], frame->linesize[2]); + + SDL_RenderClear(sink->render); + + SDL_RenderCopy(sink->render, sink->texture, NULL, NULL); + SDL_RenderPresent(sink->render); + + av_frame_free(&frame); + + return 0; +} + +static const AVFilterPad avfilter_vsink_sdlvsink_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .filter_frame = filter_frame, + }, +}; + +static const AVFilterPad avfilter_vsink_sdlvsink_outputs[] = { + { + .name = NULL, + .type = AVMEDIA_TYPE_VIDEO, + }, +}; + +const AVFilter ff_vsink_sdlvsink = { + .name = "sdlvsink", + .description = NULL_IF_CONFIG_SMALL("Do absolutely nothing with the input video."), + .priv_size = sizeof(SDLVideoContext), + .init = init, + .uninit = uninit, + FILTER_INPUTS(avfilter_vsink_sdlvsink_inputs), + FILTER_OUTPUTS(avfilter_vsink_sdlvsink_outputs), +};