From patchwork Sun Sep 11 15:38:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Dekker X-Patchwork-Id: 544 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp1217510vsd; Sun, 11 Sep 2016 08:38:40 -0700 (PDT) X-Received: by 10.194.94.138 with SMTP id dc10mr13157150wjb.40.1473608320659; Sun, 11 Sep 2016 08:38:40 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dt3si3736466wjb.231.2016.09.11.08.38.40; Sun, 11 Sep 2016 08:38:40 -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=@itanimul.li; dkim=neutral (body hash did not verify) header.i=@messagingengine.com; 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 D097D689EB1; Sun, 11 Sep 2016 18:38:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 89DE2689D3E for ; Sun, 11 Sep 2016 18:38:19 +0300 (EEST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 4A112203EE for ; Sun, 11 Sep 2016 11:38:30 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Sun, 11 Sep 2016 11:38:30 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=itanimul.li; h= date:from:in-reply-to:message-id:references:subject:to :x-sasl-enc:x-sasl-enc; s=mesmtp; bh=FczlFWSx+k/EqpsaWFiBU4blZ/Y =; b=IawUu14b9o6+nBJCeeYjg2+/SzpTGK/+mn1obnRA3SSbnGoD4w64dyeNKp2 HTlF9Klx3nv1H2ehX6p+ksad668SRhr6esu/fylAVNqgFLarO45vP8Zvo2sYSjBR Je6G6kQph1/Kv5kbGjW2rhi5VsA4YV3IU5cnOsQ1ecaPCsd4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=date:from:in-reply-to:message-id :references:subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=Fczl FWSx+k/EqpsaWFiBU4blZ/Y=; b=iUANglwmzutE/Nf7uteGLaUP76N3PmImCeXg omaMAuYQK7IdbipRgLCAlmgZxUND3GBUgGdawZHmtwsxX1ZMiNvQgpse6ycCjsVt sfi/iTHF0k0hLrt092auJMX8nIFNv7ZVnT3VaSBgMo7Ao1ldsrS1NcD1yAfbYSLy +6/zN7g= X-Sasl-enc: GtGeUsrjORU1n0L2FlBqoGTem4jjwMa8fmZa59XYrl/t 1473608309 Received: from localhost (cpc75394-sotn16-2-0-cust168.15-1.cable.virginm.net [82.22.8.169]) by mail.messagingengine.com (Postfix) with ESMTPA id 97D85CCE88 for ; Sun, 11 Sep 2016 11:38:29 -0400 (EDT) From: Josh de Kock To: ffmpeg-devel@ffmpeg.org Date: Sun, 11 Sep 2016 16:38:12 +0100 Message-Id: <1473608292-70980-1-git-send-email-josh@itanimul.li> X-Mailer: git-send-email 2.7.4 (Apple Git-66) In-Reply-To: <20160911141031.GA1049270@phare.normalesup.org> References: <20160911141031.GA1049270@phare.normalesup.org> Subject: [FFmpeg-devel] [PATCH] avdev: Add SDL2 output device 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This actually seems to work now, it didn't in the past, so maybe SDL2 was patched or something changed in FFmpeg. I will make an avfilter of this as well as the outdev. Signed-off-by: Josh de Kock Acked-by: Michael --- configure | 24 ++- libavdevice/Makefile | 1 + libavdevice/alldevices.c | 1 + libavdevice/sdl2.c | 373 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 398 insertions(+), 1 deletion(-) create mode 100644 libavdevice/sdl2.c diff --git a/configure b/configure index b11ca7f..b3b43a9 100755 --- a/configure +++ b/configure @@ -292,6 +292,7 @@ External library support: --disable-schannel disable SChannel SSP, needed for TLS support on Windows if openssl and gnutls are not used [autodetect] --disable-sdl disable sdl [autodetect] + --disable-sdl2 disable sdl2 [autodetect] --disable-securetransport disable Secure Transport, needed for TLS support on OSX if openssl and gnutls are not used [autodetect] --enable-x11grab enable X11 grabbing (legacy) [no] @@ -1548,6 +1549,7 @@ EXTERNAL_LIBRARY_LIST=" openssl schannel sdl + sdl2 securetransport videotoolbox x11grab @@ -2022,6 +2024,7 @@ HAVE_LIST=" perl pod2man sdl + sdl2 section_data_rel_ro texi2html threads @@ -2945,6 +2948,7 @@ pulse_outdev_deps="libpulse" qtkit_indev_extralibs="-framework QTKit -framework Foundation -framework QuartzCore" qtkit_indev_select="qtkit" sdl_outdev_deps="sdl" +sdl2_outdev_deps="sdl2" sndio_indev_deps="sndio_h" sndio_outdev_deps="sndio_h" v4l_indev_deps="linux_videodev_h" @@ -5850,7 +5854,24 @@ if enabled gcrypt; then fi fi -if ! disabled sdl; then + +SDL2_CONFIG="${cross_prefix}sdl2-config" +if check_pkg_config sdl2 SDL_events.h SDL_PollEvent; then + check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x020001" $sdl2_cflags && + check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x020100" $sdl2_cflags && + enable sdl2 +else + if "${SDL2_CONFIG}" --version > /dev/null 2>&1; then + sdl2_cflags=$("${SDL2_CONFIG}" --cflags) + sdl2_libs=$("${SDL2_CONFIG}" --libs) + check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x020001" $sdl2_cflags && + check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x020100" $sdl2_cflags && + enable sdl2 + fi +fi +enabled sdl2 && add_cflags $sdl2_cflags && add_extralibs $sdl2_libs + +if ! disabled sdl && ! enabled sdl2; then SDL_CONFIG="${cross_prefix}sdl-config" if check_pkg_config sdl SDL_events.h SDL_PollEvent; then check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags && @@ -6480,6 +6501,7 @@ echo "network support ${network-no}" echo "threading support ${thread_type-no}" echo "safe bitstream reader ${safe_bitstream_reader-no}" echo "SDL support ${sdl-no}" +echo "SDL2 support ${sdl2-no}" echo "opencl enabled ${opencl-no}" echo "JNI support ${jni-no}" echo "texi2html enabled ${texi2html-no}" diff --git a/libavdevice/Makefile b/libavdevice/Makefile index 585827b..1c4b4d3 100644 --- a/libavdevice/Makefile +++ b/libavdevice/Makefile @@ -41,6 +41,7 @@ OBJS-$(CONFIG_PULSE_OUTDEV) += pulse_audio_enc.o \ pulse_audio_common.o OBJS-$(CONFIG_QTKIT_INDEV) += qtkit.o OBJS-$(CONFIG_SDL_OUTDEV) += sdl.o +OBJS-$(CONFIG_SDL2_OUTDEV) += sdl2.o OBJS-$(CONFIG_SNDIO_INDEV) += sndio_dec.o sndio.o OBJS-$(CONFIG_SNDIO_OUTDEV) += sndio_enc.o sndio.o OBJS-$(CONFIG_V4L2_INDEV) += v4l2.o v4l2-common.o timefilter.o diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c index 26aecf2..c0a9d9a 100644 --- a/libavdevice/alldevices.c +++ b/libavdevice/alldevices.c @@ -64,6 +64,7 @@ void avdevice_register_all(void) REGISTER_INOUTDEV(PULSE, pulse); REGISTER_INDEV (QTKIT, qtkit); REGISTER_OUTDEV (SDL, sdl); + REGISTER_OUTDEV (SDL2, sdl2); REGISTER_INOUTDEV(SNDIO, sndio); REGISTER_INOUTDEV(V4L2, v4l2); // REGISTER_INDEV (V4L, v4l diff --git a/libavdevice/sdl2.c b/libavdevice/sdl2.c new file mode 100644 index 0000000..8959ebc --- /dev/null +++ b/libavdevice/sdl2.c @@ -0,0 +1,373 @@ +/* + * Copyright (c) 2011 Stefano Sabatini + * + * 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 + */ + +/** + * @file + * libSDL output device + */ + +#include +#include + +#include "libavutil/avstring.h" +#include "libavutil/imgutils.h" +#include "libavutil/opt.h" +#include "libavutil/parseutils.h" +#include "libavutil/pixdesc.h" +#include "libavutil/time.h" +#include "avdevice.h" + +typedef struct { + AVClass *class; + SDL_Window *window; + SDL_Renderer *renderer; + char *window_title; + int window_width, window_height; /**< size of the window */ + int window_fullscreen; + int window_borderless; + + SDL_Texture *texture; + int texture_fmt; + SDL_Rect texture_rect; + + int inited; + SDL_Thread *event_thread; + SDL_mutex *mutex; + SDL_cond *init_cond; + int quit; +} SDLContext; + +static const struct sdl_texture_format_entry { + enum AVPixelFormat format; int texture_fmt; +} sdl_texture_format_map[] = { + { AV_PIX_FMT_RGB8, SDL_PIXELFORMAT_RGB332 }, + { AV_PIX_FMT_RGB444, SDL_PIXELFORMAT_RGB444 }, + { AV_PIX_FMT_RGB555, SDL_PIXELFORMAT_RGB555 }, + { AV_PIX_FMT_BGR555, SDL_PIXELFORMAT_BGR555 }, + // { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ARGB4444 }, // these aren't implemented in FFmpeg + // { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_RGBA4444 }, // but keeping them here in-case they + // { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ABGR4444 }, // are + // { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_BGRA4444 }, + // { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ARGB1555 }, + // { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_RGBA5551 }, + // { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ABGR1555 }, + // { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_BGRA5551 }, + { AV_PIX_FMT_RGB565, SDL_PIXELFORMAT_RGB565 }, + { AV_PIX_FMT_BGR565, SDL_PIXELFORMAT_BGR565 }, + { AV_PIX_FMT_RGB24, SDL_PIXELFORMAT_RGB24 }, + { AV_PIX_FMT_BGR24, SDL_PIXELFORMAT_BGR24 }, + { AV_PIX_FMT_RGB24, SDL_PIXELFORMAT_RGB888 }, // is this right? + { AV_PIX_FMT_RGB0, SDL_PIXELFORMAT_RGBX8888 }, + { AV_PIX_FMT_BGR24, SDL_PIXELFORMAT_BGR888 }, // is this right? + { AV_PIX_FMT_BGR0, SDL_PIXELFORMAT_BGRX8888 }, + { AV_PIX_FMT_ARGB, SDL_PIXELFORMAT_ARGB8888 }, + { AV_PIX_FMT_RGBA, SDL_PIXELFORMAT_RGBA8888 }, + { AV_PIX_FMT_ABGR, SDL_PIXELFORMAT_ABGR8888 }, + { AV_PIX_FMT_BGRA, SDL_PIXELFORMAT_BGRA8888 }, + // { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_ARGB2101010 }, // not implemented + { AV_PIX_FMT_YUV420P, SDL_PIXELFORMAT_IYUV }, + { AV_PIX_FMT_YUYV422, SDL_PIXELFORMAT_YUY2 }, + { AV_PIX_FMT_UYVY422, SDL_PIXELFORMAT_UYVY }, + { AV_PIX_FMT_NONE, 0 }, +}; + +static void compute_texture_rect(AVFormatContext *s) +{ + AVRational sar, dar; /* sample and display aspect ratios */ + SDLContext *sdl = s->priv_data; + AVStream *st = s->streams[0]; + AVCodecParameters *codecpar = st->codecpar; + SDL_Rect *texture_rect = &sdl->texture_rect; + + /* compute texture width and height from the codec context information */ + sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 }; + dar = av_mul_q(sar, (AVRational){ codecpar->width, codecpar->height }); + + /* we suppose the screen has a 1/1 sample aspect ratio */ + if (sdl->window_width && sdl->window_height) { + /* fit in the window */ + if (av_cmp_q(dar, (AVRational){ sdl->window_width, sdl->window_height }) > 0) { + /* fit in width */ + texture_rect->w = sdl->window_width; + texture_rect->h = av_rescale(texture_rect->w, dar.den, dar.num); + } else { + /* fit in height */ + texture_rect->h = sdl->window_height; + texture_rect->w = av_rescale(texture_rect->h, dar.num, dar.den); + } + } else { + if (sar.num > sar.den) { + texture_rect->w = codecpar->width; + texture_rect->h = av_rescale(texture_rect->w, dar.den, dar.num); + } else { + texture_rect->h = codecpar->height; + texture_rect->w = av_rescale(texture_rect->h, dar.num, dar.den); + } + sdl->window_width = texture_rect->w; + sdl->window_height = texture_rect->h; + } + + texture_rect->x = (sdl->window_width - texture_rect->w) / 2; + texture_rect->y = (sdl->window_height - texture_rect->h) / 2; +} + +static int sdl2_write_trailer(AVFormatContext *s) +{ + SDLContext *sdl = s->priv_data; + + sdl->quit = 1; + + if (sdl->texture) + SDL_DestroyTexture(sdl->texture); + sdl->texture = NULL; + if (sdl->event_thread) + SDL_WaitThread(sdl->event_thread, NULL); + sdl->event_thread = NULL; + if (sdl->mutex) + SDL_DestroyMutex(sdl->mutex); + sdl->mutex = NULL; + if (sdl->init_cond) + SDL_DestroyCond(sdl->init_cond); + sdl->init_cond = NULL; + + if (sdl->renderer) + SDL_DestroyRenderer(sdl->renderer); + sdl->renderer = NULL; + + if (sdl->window) + SDL_DestroyWindow(sdl->window); + sdl->window = NULL; + + if (!sdl->inited) + SDL_Quit(); + + return 0; +} + +#define SDL_BASE_FLAGS (SDL_SWSURFACE|SDL_WINDOW_RESIZABLE) + +static int sdl2_write_header(AVFormatContext *s) +{ + SDLContext *sdl = s->priv_data; + AVStream *st = s->streams[0]; + AVCodecParameters *codecpar = st->codecpar; + int i, ret = 0; + + if (!sdl->window_title) + sdl->window_title = av_strdup(s->filename); + + if (SDL_WasInit(SDL_INIT_VIDEO)) { + av_log(s, AV_LOG_WARNING, + "SDL video subsystem was already inited, you could have multiple SDL outputs. This may cause unknown behaviour.\n"); + sdl->inited = 1; + } + + if ( s->nb_streams > 1 + || codecpar->codec_type != AVMEDIA_TYPE_VIDEO + || codecpar->codec_id != AV_CODEC_ID_RAWVIDEO) { + av_log(s, AV_LOG_ERROR, "Only supports one rawvideo stream\n"); + goto fail; + } + + for (i = 0; sdl_texture_format_map[i].format != AV_PIX_FMT_NONE; i++) { + if (sdl_texture_format_map[i].format == codecpar->format) { + sdl->texture_fmt = sdl_texture_format_map[i].texture_fmt; + break; + } + } + + if (!sdl->texture_fmt) { + av_log(s, AV_LOG_ERROR, + "Unsupported pixel format '%s', choose one of yuv420p, yuyv422, uyvy422, BGRA\n", + av_get_pix_fmt_name(codecpar->format)); + goto fail; + } + + /* resize texture to width and height from the codec context information */ + + int flags = SDL_BASE_FLAGS | (sdl->window_fullscreen ? SDL_WINDOW_FULLSCREEN : 0) | + (sdl->window_borderless ? SDL_WINDOW_BORDERLESS : 0); + + /* initialization */ + if (!sdl->inited){ + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + av_log(s, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError()); + goto fail; + } + } + + sdl->window_width = sdl->texture_rect.w = codecpar->width; + sdl->window_height = sdl->texture_rect.h = codecpar->height; + sdl->texture_rect.x = sdl->texture_rect.y = 0; + + if (SDL_CreateWindowAndRenderer(sdl->window_width, sdl->window_height, + flags, &sdl->window, &sdl->renderer) != 0){ + av_log(sdl, AV_LOG_ERROR, "Couldn't create window and renderer: %s\n", SDL_GetError()); + goto fail; + } + + SDL_SetWindowTitle(sdl->window, sdl->window_title); + + sdl->texture = SDL_CreateTexture(sdl->renderer, sdl->texture_fmt, SDL_TEXTUREACCESS_STREAMING, + sdl->window_width, sdl->window_height); + + if (!sdl->texture) { + av_log(sdl, AV_LOG_ERROR, "Unable to set create mode: %s\n", SDL_GetError()); + goto fail; + } + + av_log(s, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s -> w:%d h:%d\n", + codecpar->width, codecpar->height, av_get_pix_fmt_name(codecpar->format), + sdl->window_width, sdl->window_height); + + sdl->inited = 1; + + return 0; +fail: + sdl2_write_trailer(s); + return ret; +} + +static int sdl2_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + int ret = 0; + SDLContext *sdl = s->priv_data; + AVCodecParameters *codecpar = s->streams[0]->codecpar; + uint8_t *data[4]; + int linesize[4]; + + SDL_Event event; + if (SDL_PollEvent(&event)){ + switch (event.type) { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) { + case SDLK_ESCAPE: + case SDLK_q: + sdl->quit = 1; + break; + default: + break; + } + break; + case SDL_QUIT: + sdl->quit = 1; + break; + case SDL_WINDOWEVENT: + switch(event.window.event){ + case SDL_WINDOWEVENT_RESIZED: + case SDL_WINDOWEVENT_SIZE_CHANGED: + sdl->window_width = event.window.data1; + sdl->window_height = event.window.data2; + compute_texture_rect(s); + break; + default: + break; + } + break; + default: + break; + } + } + + if (sdl->quit) { + sdl2_write_trailer(s); + return AVERROR(EIO); + } + + av_image_fill_arrays(data, linesize, pkt->data, codecpar->format, codecpar->width, codecpar->height, 1); + SDL_LockMutex(sdl->mutex); + switch (sdl->texture_fmt) { + case SDL_PIXELFORMAT_IYUV: + case SDL_PIXELFORMAT_YUY2: + case SDL_PIXELFORMAT_UYVY: + ret = SDL_UpdateYUVTexture(sdl->texture, NULL, + data[0], linesize[0], + data[1], linesize[1], + data[2], linesize[2]); + break; + case SDL_PIXELFORMAT_RGB332: + case SDL_PIXELFORMAT_RGB444: + case SDL_PIXELFORMAT_RGB555: + case SDL_PIXELFORMAT_BGR555: + // case SDL_PIXELFORMAT_ARGB4444: + // case SDL_PIXELFORMAT_RGBA4444: + // case SDL_PIXELFORMAT_ABGR4444: + // case SDL_PIXELFORMAT_BGRA4444: + // case SDL_PIXELFORMAT_ARGB1555: + // case SDL_PIXELFORMAT_RGBA5551: + // case SDL_PIXELFORMAT_ABGR1555: + // case SDL_PIXELFORMAT_BGRA5551: + case SDL_PIXELFORMAT_RGB565: + case SDL_PIXELFORMAT_BGR565: + case SDL_PIXELFORMAT_RGB24: + case SDL_PIXELFORMAT_BGR24: + case SDL_PIXELFORMAT_RGB888: // is this right? + case SDL_PIXELFORMAT_RGBX8888: + case SDL_PIXELFORMAT_BGR888: // is this right? + case SDL_PIXELFORMAT_BGRX8888: + case SDL_PIXELFORMAT_ARGB8888: + case SDL_PIXELFORMAT_RGBA8888: + case SDL_PIXELFORMAT_ABGR8888: + case SDL_PIXELFORMAT_BGRA8888: + // case SDL_PIXELFORMAT_ARGB2101010: + ret = SDL_UpdateTexture(sdl->texture, NULL, data[0], linesize[0]); + break; + default: + av_log(NULL, AV_LOG_FATAL, "Unsupported pixel format\n"); + ret = -1; + break; + } + SDL_RenderClear(sdl->renderer); + SDL_RenderCopy(sdl->renderer, sdl->texture, NULL, &sdl->texture_rect); + SDL_RenderPresent(sdl->renderer); + SDL_UnlockMutex(sdl->mutex); + return ret; +} + +#define OFFSET(x) offsetof(SDLContext,x) + +static const AVOption options[] = { + { "window_title", "set SDL window title", OFFSET(window_title), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM }, + { "window_size", "set SDL window forced size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM }, + { "window_fullscreen", "set SDL window fullscreen", OFFSET(window_fullscreen), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM }, + { "window_borderless", "set SDL window border off", OFFSET(window_fullscreen), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM }, + { NULL }, +}; + +static const AVClass sdl2_class = { + .class_name = "sdl2 outdev", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, + .category = AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT, +}; + +AVOutputFormat ff_sdl2_muxer = { + .name = "sdl2", + .long_name = NULL_IF_CONFIG_SMALL("SDL2 output device"), + .priv_data_size = sizeof(SDLContext), + .audio_codec = AV_CODEC_ID_NONE, + .video_codec = AV_CODEC_ID_RAWVIDEO, + .write_header = sdl2_write_header, + .write_packet = sdl2_write_packet, + .write_trailer = sdl2_write_trailer, + .flags = AVFMT_NOFILE | AVFMT_VARIABLE_FPS | AVFMT_NOTIMESTAMPS, + .priv_class = &sdl2_class, +};