X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_output%2Fcaca.c;h=2958abd9a6d431bc4f1a5d5560e9853d361577cc;hb=2f85ce3036d94b40ba3e72eb22bf5f6fb2f341b8;hp=abded93e890b7cc7596fb5b9e5d1f1f102bf0bb7;hpb=abfdb004517b5828a9d40d2d32af59d03e717920;p=vlc diff --git a/modules/video_output/caca.c b/modules/video_output/caca.c index abded93e89..2958abd9a6 100644 --- a/modules/video_output/caca.c +++ b/modules/video_output/caca.c @@ -1,25 +1,25 @@ /***************************************************************************** * caca.c: Color ASCII Art "vout display" module using libcaca ***************************************************************************** - * Copyright (C) 2003-2009 the VideoLAN team + * Copyright (C) 2003-2009 VLC authors and VideoLAN * $Id$ * * Authors: Sam Hocevar * Laurent Aimar * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * This program 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. * * This program 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 General Public License for more details. + * 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 General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -34,6 +34,12 @@ #include #include #include +#if !defined(_WIN32) && !defined(__APPLE__) +# ifdef X_DISPLAY_MISSING +# error Xlib required due to XInitThreads +# endif +# include +#endif #include @@ -48,17 +54,17 @@ vlc_module_begin() set_category(CAT_VIDEO) set_subcategory(SUBCAT_VIDEO_VOUT) set_description(N_("Color ASCII art video output")) - set_capability("vout display", 12) + set_capability("vout display", 15) set_callbacks(Open, Close) vlc_module_end() /***************************************************************************** * Local prototypes *****************************************************************************/ -static picture_t *Get (vout_display_t *); -static void Prepare(vout_display_t *, picture_t *); -static void Display(vout_display_t *, picture_t *); -static int Control(vout_display_t *, int, va_list); +static picture_pool_t *Pool (vout_display_t *, unsigned); +static void Prepare(vout_display_t *, picture_t *, subpicture_t *); +static void PictureDisplay(vout_display_t *, picture_t *, subpicture_t *); +static int Control(vout_display_t *, int, va_list); /* */ static void Manage(vout_display_t *); @@ -82,7 +88,14 @@ static int Open(vlc_object_t *object) vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; -#if defined(WIN32) && !defined(UNDER_CE) +#if !defined(__APPLE__) && !defined(_WIN32) +# ifndef X_DISPLAY_MISSING + if (!vlc_xlib_init(object)) + return VLC_EGENERIC; +# endif +#endif + +#if defined(_WIN32) CONSOLE_SCREEN_BUFFER_INFO csbiInfo; SMALL_RECT rect; COORD coord; @@ -142,11 +155,18 @@ static int Open(vlc_object_t *object) goto error; } - sys->dp = caca_create_display(sys->cv); + const char *driver = NULL; +#ifdef __APPLE__ + // Make sure we don't try to open a window. + driver = "ncurses"; +#endif + + sys->dp = caca_create_display_with_driver(sys->cv, driver); if (!sys->dp) { msg_Err(vd, "cannot initialize libcaca"); goto error; } + vout_display_DeleteWindow(vd, NULL); if (vd->cfg->display.title) caca_set_display_title(sys->dp, @@ -164,11 +184,6 @@ static int Open(vlc_object_t *object) fmt.i_bmask = 0x000000ff; } - /* */ - sys->pool = picture_pool_NewFromFormat(&fmt, 1); - if (!sys->pool) - goto error; - /* TODO */ vout_display_info_t info = vd->info; @@ -176,11 +191,11 @@ static int Open(vlc_object_t *object) vd->fmt = fmt; vd->info = info; - vd->get = Get; + vd->pool = Pool; vd->prepare = Prepare; - vd->display = Display; + vd->display = PictureDisplay; vd->control = Control; - vd->manage = Manage; + vd->manage = Manage; /* Fix initial state */ vout_display_SendEventFullscreen(vd, false); @@ -201,7 +216,7 @@ error: free(sys); } -#if defined(WIN32) && !defined(UNDER_CE) +#if defined(_WIN32) FreeConsole(); #endif return VLC_EGENERIC; @@ -215,13 +230,14 @@ static void Close(vlc_object_t *object) vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys = vd->sys; - picture_pool_Delete(sys->pool); + if (sys->pool) + picture_pool_Delete(sys->pool); if (sys->dither) cucul_free_dither(sys->dither); caca_free_display(sys->dp); cucul_free_canvas(sys->cv); -#if defined(WIN32) && !defined(UNDER_CE) +#if defined(_WIN32) FreeConsole(); #endif @@ -229,18 +245,20 @@ static void Close(vlc_object_t *object) } /** - * Return a direct buffer + * Return a pool of direct buffers */ -static picture_t *Get(vout_display_t *vd) +static picture_pool_t *Pool(vout_display_t *vd, unsigned count) { vout_display_sys_t *sys = vd->sys; - return picture_pool_Get(sys->pool); + if (!sys->pool) + sys->pool = picture_pool_NewFromFormat(&vd->fmt, count); + return sys->pool; } /** * Prepare a picture for display */ -static void Prepare(vout_display_t *vd, picture_t *picture) +static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture) { vout_display_sys_t *sys = vd->sys; @@ -273,15 +291,17 @@ static void Prepare(vout_display_t *vd, picture_t *picture) place.width, place.height, sys->dither, &picture->p->p_pixels[crop_offset]); + VLC_UNUSED(subpicture); } /** * Display a picture */ -static void Display(vout_display_t *vd, picture_t *picture) +static void PictureDisplay(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture) { Refresh(vd); picture_Release(picture); + VLC_UNUSED(subpicture); } /** @@ -302,8 +322,8 @@ static int Control(vout_display_t *vd, int query, va_list args) caca_refresh_display(sys->dp); /* Not quite good but not sure how to resize it */ - if (cfg->display.width != caca_get_display_width(sys->dp) || - cfg->display.height != caca_get_display_height(sys->dp)) + if ((int)cfg->display.width != caca_get_display_width(sys->dp) || + (int)cfg->display.height != caca_get_display_height(sys->dp)) return VLC_EGENERIC; return VLC_SUCCESS; } @@ -341,7 +361,7 @@ static void Refresh(vout_display_t *vd) if (width != vd->cfg->display.width || height != vd->cfg->display.height) - vout_display_SendEventDisplaySize(vd, width, height); + vout_display_SendEventDisplaySize(vd, width, height, false); } /** @@ -436,8 +456,6 @@ static const struct { { CACA_KEY_PAGEUP, KEY_PAGEUP }, { CACA_KEY_PAGEDOWN,KEY_PAGEDOWN }, - { ' ', KEY_SPACE }, - /* */ { -1, -1 } }; @@ -486,7 +504,7 @@ static void Manage(vout_display_t *vd) } case CACA_EVENT_RESIZE: vout_display_SendEventDisplaySize(vd, caca_get_event_resize_width(&ev), - caca_get_event_resize_height(&ev)); + caca_get_event_resize_height(&ev), false); break; case CACA_EVENT_MOUSE_MOTION: { vout_display_place_t place; @@ -500,10 +518,7 @@ static void Manage(vout_display_t *vd) vd->source.i_visible_height / place.height; caca_set_mouse(sys->dp, 1); - if (x >= vd->source.i_x_offset && x < vd->source.i_x_offset + vd->source.i_visible_width && - y >= vd->source.i_y_offset && y < vd->source.i_y_offset + vd->source.i_visible_height) { - vout_display_SendEventMouseMoved(vd, x, y); - } + vout_display_SendEventMouseMoved(vd, x, y); break; } case CACA_EVENT_MOUSE_PRESS: