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 B0977485DE for ; Thu, 6 Jun 2024 11:51:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 61AB068D6B9; Thu, 6 Jun 2024 14:51:15 +0300 (EEST) 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-Google-Smtp-Source: AGHT+IF6/yXJAHSR60zh+AHyas/MBnBRuem76Vg8v91AfM8Fm90dMmI5qJqqZ9f6mUwE77x0o/u26w== 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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), +}; -- 2.34.1 _______________________________________________ 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".