From patchwork Sat Sep 17 22:30:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Dekker X-Patchwork-Id: 610 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp354822vsd; Sat, 17 Sep 2016 15:30:51 -0700 (PDT) X-Received: by 10.28.46.204 with SMTP id u195mr3484076wmu.57.1474151451686; Sat, 17 Sep 2016 15:30:51 -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 13si13207250wme.99.2016.09.17.15.30.50; Sat, 17 Sep 2016 15:30:51 -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 EAD76689F16; Sun, 18 Sep 2016 01:30:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F4DD689EFA for ; Sun, 18 Sep 2016 01:30:28 +0300 (EEST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 3BFEF204FB for ; Sat, 17 Sep 2016 18:30:41 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Sat, 17 Sep 2016 18:30:41 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=itanimul.li; h= date:from:message-id:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=b/4MGJCOgvQtyMDX+cmmgAXbWlc=; b=W+SD7nFTvwj89deWMrhgM0JzK1iU NvVG+bxhqvA+QIEU7Ns/GPLcuJLkIO/Y32oB59zq7mhS4YwQiMrsnWo7MU+Kekn3 40Kbo2zWZLE37j/rPD4BahsVlwhnbfK3DhtJkyzpSGsOxM5CPe0Bdq6H3RinjxwK vU+pAjjfq09Z0Cg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=date:from:message-id:subject:to :x-sasl-enc:x-sasl-enc; s=smtpout; bh=b/4MGJCOgvQtyMDX+cmmgAXbWl c=; b=J9/2GZbwV9CODCIV+8SS0o1k2Cy2ojAiMlGb9cXAF4tpRp4e3lIs8qE4Ex ST6vT59Beb6ChQeL+po/FKiiZ4ruhlrP5mdWX+xDsyE34fDsM1jvZV0MSvpi77/e 5lkADo2IsnPEL+bJZL82AxpuFrrQK+UlJFFUUq9y2Bfwrk+lU= X-Sasl-enc: Q3u0mqsIN7RjLq8iV8FhjWbXFuvOWOjR54sBIx5sPWcw 1474151440 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 AE591F2D29 for ; Sat, 17 Sep 2016 18:30:40 -0400 (EDT) From: Josh de Kock To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Sep 2016 23:30:43 +0100 Message-Id: <20160917223043.52603-1-josh@itanimul.li> X-Mailer: git-send-email 2.8.4 (Apple Git-73) Subject: [FFmpeg-devel] [PATCH] lavd/opengl: use SDL2 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" I did this in about 5 minutes, and only tested it with one sample (on OSX using the cocoa opengl renderer). Seems to work, but probably won't for all cases. Would like some feedback where it doesnt work etc Signed-off-by: Josh de Kock --- libavdevice/opengl_enc.c | 87 +++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c index 1dbbb80..1917459 100644 --- a/libavdevice/opengl_enc.c +++ b/libavdevice/opengl_enc.c @@ -46,7 +46,7 @@ #include #endif -#if HAVE_SDL +#if HAVE_SDL2 #include #endif @@ -174,8 +174,10 @@ static const GLushort g_index[6] = typedef struct OpenGLContext { AVClass *class; ///< class for private options -#if HAVE_SDL - SDL_Surface *surface; +#if HAVE_SDL2 + SDL_Texture *texture; + SDL_Window *window; + SDL_Renderer *renderer; #endif FFOpenGLFunctions glprocs; @@ -341,12 +343,18 @@ static int opengl_control_message(AVFormatContext *h, int type, void *data, size return AVERROR(ENOSYS); } -#if HAVE_SDL +#if HAVE_SDL2 static int opengl_sdl_recreate_window(OpenGLContext *opengl, int width, int height) { - opengl->surface = SDL_SetVideoMode(width, height, - 32, SDL_OPENGL | SDL_RESIZABLE); - if (!opengl->surface) { + int ret; + if ((ret = SDL_CreateWindowAndRenderer(width, height, 0, &opengl->window, + &opengl->renderer)) < 0) + return ret; + + opengl->texture = SDL_CreateTexture(opengl->renderer, SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, width, height); + + if (!opengl->texture) { av_log(opengl, AV_LOG_ERROR, "Unable to set video mode: %s\n", SDL_GetError()); return AVERROR_EXTERNAL; } @@ -363,8 +371,7 @@ static int opengl_sdl_process_events(AVFormatContext *h) int ret; OpenGLContext *opengl = h->priv_data; SDL_Event event; - SDL_PumpEvents(); - while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS) > 0) { + while (SDL_PollEvent(&event) > 0) { switch (event.type) { case SDL_QUIT: return AVERROR(EIO); @@ -375,24 +382,23 @@ static int opengl_sdl_process_events(AVFormatContext *h) return AVERROR(EIO); } return 0; - case SDL_VIDEORESIZE: { - char buffer[100]; - int reinit; - AVDeviceRect message; - /* clean up old context because SDL_SetVideoMode may lose its state. */ - SDL_VideoDriverName(buffer, sizeof(buffer)); - reinit = !av_strncasecmp(buffer, "quartz", sizeof(buffer)); - if (reinit) { - opengl_deinit_context(opengl); - } - if ((ret = opengl_sdl_recreate_window(opengl, event.resize.w, event.resize.h)) < 0) - return ret; - if (reinit && (ret = opengl_init_context(opengl)) < 0) - return ret; - message.width = opengl->surface->w; - message.height = opengl->surface->h; - return opengl_control_message(h, AV_APP_TO_DEV_WINDOW_SIZE, &message, sizeof(AVDeviceRect)); + case SDL_WINDOWEVENT: + switch(event.window.event){ + case SDL_WINDOWEVENT_SIZE_CHANGED: + case SDL_WINDOWEVENT_RESIZED: { + AVDeviceRect message; + if ((ret = opengl_sdl_recreate_window(opengl, event.window.data1, event.window.data2)) < 0) + return ret; + if ((SDL_QueryTexture(opengl->texture, NULL, NULL, &message.width, &message.height)) < 0) + return ret; + return opengl_control_message(h, AV_APP_TO_DEV_WINDOW_SIZE, &message, sizeof(AVDeviceRect)); + } + default: + break; } + break; + default: + break; } } return 0; @@ -401,7 +407,6 @@ static int opengl_sdl_process_events(AVFormatContext *h) static int av_cold opengl_sdl_create_window(AVFormatContext *h) { int ret; - char buffer[100]; OpenGLContext *opengl = h->priv_data; AVDeviceRect message; if (SDL_Init(SDL_INIT_VIDEO)) { @@ -411,10 +416,10 @@ static int av_cold opengl_sdl_create_window(AVFormatContext *h) if ((ret = opengl_sdl_recreate_window(opengl, opengl->window_width, opengl->window_height)) < 0) return ret; - av_log(opengl, AV_LOG_INFO, "SDL driver: '%s'.\n", SDL_VideoDriverName(buffer, sizeof(buffer))); - message.width = opengl->surface->w; - message.height = opengl->surface->h; - SDL_WM_SetCaption(opengl->window_title, NULL); + av_log(opengl, AV_LOG_INFO, "SDL driver: '%s'.\n", SDL_GetCurrentVideoDriver()); + if ((ret = SDL_QueryTexture(opengl->texture, NULL, NULL, &message.width, &message.height)) < 0) + return ret; + SDL_SetWindowTitle(opengl->window, opengl->window_title); opengl_control_message(h, AV_APP_TO_DEV_WINDOW_SIZE, &message, sizeof(AVDeviceRect)); return 0; } @@ -460,14 +465,14 @@ static int av_cold opengl_sdl_load_procedures(OpenGLContext *opengl) #undef LOAD_OPENGL_FUN } -#endif /* HAVE_SDL */ +#endif /* HAVE_SDL2 */ #if defined(__APPLE__) static int av_cold opengl_load_procedures(OpenGLContext *opengl) { FFOpenGLFunctions *procs = &opengl->glprocs; -#if HAVE_SDL +#if HAVE_SDL2 if (!opengl->no_window) return opengl_sdl_load_procedures(opengl); #endif @@ -517,7 +522,7 @@ static int av_cold opengl_load_procedures(OpenGLContext *opengl) return AVERROR(ENOSYS); \ } -#if HAVE_SDL +#if HAVE_SDL2 if (!opengl->no_window) return opengl_sdl_load_procedures(opengl); #endif @@ -943,7 +948,7 @@ static int opengl_create_window(AVFormatContext *h) int ret; if (!opengl->no_window) { -#if HAVE_SDL +#if HAVE_SDL2 if ((ret = opengl_sdl_create_window(h)) < 0) { av_log(opengl, AV_LOG_ERROR, "Cannot create default SDL window.\n"); return ret; @@ -975,7 +980,7 @@ static int opengl_release_window(AVFormatContext *h) int ret; OpenGLContext *opengl = h->priv_data; if (!opengl->no_window) { -#if HAVE_SDL +#if HAVE_SDL2 SDL_Quit(); #endif } else if ((ret = avdevice_dev_to_app_control_message(h, AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER, NULL , 0)) < 0) { @@ -1109,9 +1114,9 @@ static av_cold int opengl_write_header(AVFormatContext *h) glClear(GL_COLOR_BUFFER_BIT); -#if HAVE_SDL +#if HAVE_SDL2 if (!opengl->no_window) - SDL_GL_SwapBuffers(); + SDL_GL_SwapWindow(opengl->window); #endif if (opengl->no_window && (ret = avdevice_dev_to_app_control_message(h, AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER, NULL , 0)) < 0) { @@ -1204,7 +1209,7 @@ static int opengl_draw(AVFormatContext *h, void *input, int repaint, int is_pkt) const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); int ret; -#if HAVE_SDL +#if HAVE_SDL2 if (!opengl->no_window && (ret = opengl_sdl_process_events(h)) < 0) goto fail; #endif @@ -1245,9 +1250,9 @@ static int opengl_draw(AVFormatContext *h, void *input, int repaint, int is_pkt) ret = AVERROR_EXTERNAL; OPENGL_ERROR_CHECK(opengl); -#if HAVE_SDL +#if HAVE_SDL2 if (!opengl->no_window) - SDL_GL_SwapBuffers(); + SDL_GL_SwapWindow(opengl->window); #endif if (opengl->no_window && (ret = avdevice_dev_to_app_control_message(h, AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER, NULL , 0)) < 0) {