vlc | branch: master | Rémi Denis-Courmont <r...@remlab.net> | Fri Feb 2 17:12:29 2018 +0200| [57151f6ba8ea1c73efab46c9ead03138dfeac87e] | committer: Rémi Denis-Courmont
caca: reorder to avoid forward declarations > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=57151f6ba8ea1c73efab46c9ead03138dfeac87e --- modules/video_output/caca.c | 439 +++++++++++++++++++++----------------------- 1 file changed, 211 insertions(+), 228 deletions(-) diff --git a/modules/video_output/caca.c b/modules/video_output/caca.c index 25e80f2f8e..23c5d4e675 100644 --- a/modules/video_output/caca.c +++ b/modules/video_output/caca.c @@ -115,34 +115,6 @@ static void VoutDisplayEventKillThread(vout_display_event_thread_t *vdet) free(vdet); } -/***************************************************************************** - * Module descriptor - *****************************************************************************/ -static int Open (vlc_object_t *); -static void Close(vlc_object_t *); - -vlc_module_begin() - set_shortname("Caca") - set_category(CAT_VIDEO) - set_subcategory(SUBCAT_VIDEO_VOUT) - set_description(N_("Color ASCII art video output")) - set_capability("vout display", 15) - set_callbacks(Open, Close) -vlc_module_end() - -/***************************************************************************** - * Local prototypes - *****************************************************************************/ -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 *); -static void Refresh(vout_display_t *); -static void Place(vout_display_t *, vout_display_place_t *); - /* */ struct vout_display_sys_t { cucul_canvas_t *cv; @@ -154,179 +126,61 @@ struct vout_display_sys_t { }; /** - * This function initializes libcaca vout method. + * Return a pool of direct buffers */ -static int Open(vlc_object_t *object) +static picture_pool_t *Pool(vout_display_t *vd, unsigned count) { - vout_display_t *vd = (vout_display_t *)object; - vout_display_sys_t *sys; - - if (vout_display_IsWindowed(vd)) - return VLC_EGENERIC; -#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; - HANDLE hstdout; - - if (!AllocConsole()) { - msg_Err(vd, "cannot create console"); - return VLC_EGENERIC; - } - - hstdout = - CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, CONSOLE_TEXTMODE_BUFFER, NULL); - if (!hstdout || hstdout == INVALID_HANDLE_VALUE) { - msg_Err(vd, "cannot create screen buffer"); - FreeConsole(); - return VLC_EGENERIC; - } - - if (!SetConsoleActiveScreenBuffer(hstdout)) { - msg_Err(vd, "cannot set active screen buffer"); - FreeConsole(); - return VLC_EGENERIC; - } - - coord = GetLargestConsoleWindowSize(hstdout); - msg_Dbg(vd, "SetConsoleWindowInfo: %ix%i", coord.X, coord.Y); - - /* Force size for now */ - coord.X = 100; - coord.Y = 40; - - if (!SetConsoleScreenBufferSize(hstdout, coord)) - msg_Warn(vd, "SetConsoleScreenBufferSize %i %i", - coord.X, coord.Y); - - /* Get the current screen buffer size and window position. */ - if (GetConsoleScreenBufferInfo(hstdout, &csbiInfo)) { - rect.Top = 0; rect.Left = 0; - rect.Right = csbiInfo.dwMaximumWindowSize.X - 1; - rect.Bottom = csbiInfo.dwMaximumWindowSize.Y - 1; - if (!SetConsoleWindowInfo(hstdout, TRUE, &rect)) - msg_Dbg(vd, "SetConsoleWindowInfo failed: %ix%i", - rect.Right, rect.Bottom); - } -#endif - - /* Allocate structure */ - vd->sys = sys = calloc(1, sizeof(*sys)); - if (!sys) - goto error; - - sys->cv = cucul_create_canvas(0, 0); - if (!sys->cv) { - msg_Err(vd, "cannot initialize libcucul"); - goto error; - } - - 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; - } - - if (vd->cfg->display.title) - caca_set_display_title(sys->dp, - vd->cfg->display.title); - else - caca_set_display_title(sys->dp, - VOUT_TITLE "(Colour AsCii Art)"); - - sys->et = VoutDisplayEventCreateThread(vd); - - /* Fix format */ - video_format_t fmt = vd->fmt; - if (fmt.i_chroma != VLC_CODEC_RGB32) { - fmt.i_chroma = VLC_CODEC_RGB32; - fmt.i_rmask = 0x00ff0000; - fmt.i_gmask = 0x0000ff00; - fmt.i_bmask = 0x000000ff; - } - - /* Setup vout_display now that everything is fine */ - vd->fmt = fmt; - vd->info.needs_hide_mouse = true; - - vd->pool = Pool; - vd->prepare = Prepare; - vd->display = PictureDisplay; - vd->control = Control; - vd->manage = Manage; - - /* Fix initial state */ - Refresh(vd); - - return VLC_SUCCESS; - -error: - if (sys) { - if (sys->pool) - picture_pool_Release(sys->pool); - if (sys->dither) - cucul_free_dither(sys->dither); - if (sys->dp) - caca_free_display(sys->dp); - if (sys->cv) - cucul_free_canvas(sys->cv); + vout_display_sys_t *sys = vd->sys; - free(sys); - } -#if defined(_WIN32) - FreeConsole(); -#endif - return VLC_EGENERIC; + if (!sys->pool) + sys->pool = picture_pool_NewFromFormat(&vd->fmt, count); + return sys->pool; } /** - * Close a libcaca video output + * Compute the place in canvas unit. */ -static void Close(vlc_object_t *object) +static void Place(vout_display_t *vd, vout_display_place_t *place) { - vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys = vd->sys; - VoutDisplayEventKillThread(sys->et); - if (sys->pool) - picture_pool_Release(sys->pool); - if (sys->dither) - cucul_free_dither(sys->dither); - caca_free_display(sys->dp); - cucul_free_canvas(sys->cv); + vout_display_PlacePicture(place, &vd->source, vd->cfg, false); -#if defined(_WIN32) - FreeConsole(); -#endif + const int canvas_width = cucul_get_canvas_width(sys->cv); + const int canvas_height = cucul_get_canvas_height(sys->cv); + const int display_width = caca_get_display_width(sys->dp); + const int display_height = caca_get_display_height(sys->dp); - free(sys); + if (display_width > 0 && display_height > 0) { + place->x = place->x * canvas_width / display_width; + place->y = place->y * canvas_height / display_height; + place->width = (place->width * canvas_width + display_width/2) / display_width; + place->height = (place->height * canvas_height + display_height/2) / display_height; + } else { + place->x = 0; + place->y = 0; + place->width = canvas_width; + place->height = display_height; + } } /** - * Return a pool of direct buffers + * Refresh the display and send resize event */ -static picture_pool_t *Pool(vout_display_t *vd, unsigned count) +static void Refresh(vout_display_t *vd) { vout_display_sys_t *sys = vd->sys; - if (!sys->pool) - sys->pool = picture_pool_NewFromFormat(&vd->fmt, count); - return sys->pool; + /* */ + caca_refresh_display(sys->dp); + + /* */ + const unsigned width = caca_get_display_width(sys->dp); + const unsigned height = caca_get_display_height(sys->dp); + + if (width != vd->cfg->display.width || + height != vd->cfg->display.height) + vout_display_SendEventDisplaySize(vd, width, height); } /** @@ -409,52 +263,6 @@ static int Control(vout_display_t *vd, int query, va_list args) } } -/** - * Refresh the display and send resize event - */ -static void Refresh(vout_display_t *vd) -{ - vout_display_sys_t *sys = vd->sys; - - /* */ - caca_refresh_display(sys->dp); - - /* */ - const unsigned width = caca_get_display_width(sys->dp); - const unsigned height = caca_get_display_height(sys->dp); - - if (width != vd->cfg->display.width || - height != vd->cfg->display.height) - vout_display_SendEventDisplaySize(vd, width, height); -} - -/** - * Compute the place in canvas unit. - */ -static void Place(vout_display_t *vd, vout_display_place_t *place) -{ - vout_display_sys_t *sys = vd->sys; - - vout_display_PlacePicture(place, &vd->source, vd->cfg, false); - - const int canvas_width = cucul_get_canvas_width(sys->cv); - const int canvas_height = cucul_get_canvas_height(sys->cv); - const int display_width = caca_get_display_width(sys->dp); - const int display_height = caca_get_display_height(sys->dp); - - if (display_width > 0 && display_height > 0) { - place->x = place->x * canvas_width / display_width; - place->y = place->y * canvas_height / display_height; - place->width = (place->width * canvas_width + display_width/2) / display_width; - place->height = (place->height * canvas_height + display_height/2) / display_height; - } else { - place->x = 0; - place->y = 0; - place->width = canvas_width; - place->height = display_height; - } -} - /* */ static const struct { int caca; @@ -609,3 +417,178 @@ static void Manage(vout_display_t *vd) } } +/** + * This function initializes libcaca vout method. + */ +static int Open(vlc_object_t *object) +{ + vout_display_t *vd = (vout_display_t *)object; + vout_display_sys_t *sys; + + if (vout_display_IsWindowed(vd)) + return VLC_EGENERIC; +#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; + HANDLE hstdout; + + if (!AllocConsole()) { + msg_Err(vd, "cannot create console"); + return VLC_EGENERIC; + } + + hstdout = + CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, CONSOLE_TEXTMODE_BUFFER, NULL); + if (!hstdout || hstdout == INVALID_HANDLE_VALUE) { + msg_Err(vd, "cannot create screen buffer"); + FreeConsole(); + return VLC_EGENERIC; + } + + if (!SetConsoleActiveScreenBuffer(hstdout)) { + msg_Err(vd, "cannot set active screen buffer"); + FreeConsole(); + return VLC_EGENERIC; + } + + coord = GetLargestConsoleWindowSize(hstdout); + msg_Dbg(vd, "SetConsoleWindowInfo: %ix%i", coord.X, coord.Y); + + /* Force size for now */ + coord.X = 100; + coord.Y = 40; + + if (!SetConsoleScreenBufferSize(hstdout, coord)) + msg_Warn(vd, "SetConsoleScreenBufferSize %i %i", + coord.X, coord.Y); + + /* Get the current screen buffer size and window position. */ + if (GetConsoleScreenBufferInfo(hstdout, &csbiInfo)) { + rect.Top = 0; rect.Left = 0; + rect.Right = csbiInfo.dwMaximumWindowSize.X - 1; + rect.Bottom = csbiInfo.dwMaximumWindowSize.Y - 1; + if (!SetConsoleWindowInfo(hstdout, TRUE, &rect)) + msg_Dbg(vd, "SetConsoleWindowInfo failed: %ix%i", + rect.Right, rect.Bottom); + } +#endif + + /* Allocate structure */ + vd->sys = sys = calloc(1, sizeof(*sys)); + if (!sys) + goto error; + + sys->cv = cucul_create_canvas(0, 0); + if (!sys->cv) { + msg_Err(vd, "cannot initialize libcucul"); + goto error; + } + + 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; + } + + if (vd->cfg->display.title) + caca_set_display_title(sys->dp, + vd->cfg->display.title); + else + caca_set_display_title(sys->dp, + VOUT_TITLE "(Colour AsCii Art)"); + + sys->et = VoutDisplayEventCreateThread(vd); + + /* Fix format */ + video_format_t fmt = vd->fmt; + if (fmt.i_chroma != VLC_CODEC_RGB32) { + fmt.i_chroma = VLC_CODEC_RGB32; + fmt.i_rmask = 0x00ff0000; + fmt.i_gmask = 0x0000ff00; + fmt.i_bmask = 0x000000ff; + } + + /* Setup vout_display now that everything is fine */ + vd->fmt = fmt; + vd->info.needs_hide_mouse = true; + + vd->pool = Pool; + vd->prepare = Prepare; + vd->display = PictureDisplay; + vd->control = Control; + vd->manage = Manage; + + /* Fix initial state */ + Refresh(vd); + + return VLC_SUCCESS; + +error: + if (sys) { + if (sys->pool) + picture_pool_Release(sys->pool); + if (sys->dither) + cucul_free_dither(sys->dither); + if (sys->dp) + caca_free_display(sys->dp); + if (sys->cv) + cucul_free_canvas(sys->cv); + + free(sys); + } +#if defined(_WIN32) + FreeConsole(); +#endif + return VLC_EGENERIC; +} + +/** + * Close a libcaca video output + */ +static void Close(vlc_object_t *object) +{ + vout_display_t *vd = (vout_display_t *)object; + vout_display_sys_t *sys = vd->sys; + + VoutDisplayEventKillThread(sys->et); + if (sys->pool) + picture_pool_Release(sys->pool); + if (sys->dither) + cucul_free_dither(sys->dither); + caca_free_display(sys->dp); + cucul_free_canvas(sys->cv); + +#if defined(_WIN32) + FreeConsole(); +#endif + + free(sys); +} + +/***************************************************************************** + * Module descriptor + *****************************************************************************/ +vlc_module_begin() + set_shortname("Caca") + set_category(CAT_VIDEO) + set_subcategory(SUBCAT_VIDEO_VOUT) + set_description(N_("Color ASCII art video output")) + set_capability("vout display", 15) + set_callbacks(Open, Close) +vlc_module_end() _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits