summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormplayer-svn <svn@mplayerhq.hu>2011-11-09 02:26:58 +0000
committerwm4 <wm4@nowhere>2012-08-03 01:35:18 +0200
commit094acd6884e618aaf92bc53fcba8249224086389 (patch)
treee8839417805afa8db60a55a0d5f4f34a17ca8fa9
parentd9d80705e62c99e4a3d3dbc56684a66aa63b4412 (diff)
downloadmpv-094acd6884e618aaf92bc53fcba8249224086389.tar.bz2
mpv-094acd6884e618aaf92bc53fcba8249224086389.tar.xz
vo_caca: reformat and various fixes
Squashed commits by various authors. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34337 b3059339-0415-0410-9bf9-f77b7e298cf2 vo_caca: Port to libcaca 1.x API, which is widespread enough nowadays. patch by Paul B. Mahol, onemda gmail com git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34338 b3059339-0415-0410-9bf9-f77b7e298cf2 caca: support mouse events and more keys. Patch by Paul B. Mahol [onemda gmail com]. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34359 b3059339-0415-0410-9bf9-f77b7e298cf2 caca: for ordinary keys, send key events on press instead of release. This is consistent with how other vos behave. Patch by Paul B. Mahol [onemda gmail com]. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34360 b3059339-0415-0410-9bf9-f77b7e298cf2 caca: process all pending events instead of exactly one per check_events. Patch by Paul B. Mahol [onemda gmail com]. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34361 b3059339-0415-0410-9bf9-f77b7e298cf2 Reindent. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34362 b3059339-0415-0410-9bf9-f77b7e298cf2 Use lookup_keymap_table instead of a large number of switch cases. Patch by Paul B. Mahol [onemda gmail com]. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34363 b3059339-0415-0410-9bf9-f77b7e298cf2 Author: diego
-rw-r--r--libvo/vo_caca.c375
1 files changed, 201 insertions, 174 deletions
diff --git a/libvo/vo_caca.c b/libvo/vo_caca.c
index 74352397b3..e7850d8349 100644
--- a/libvo/vo_caca.c
+++ b/libvo/vo_caca.c
@@ -31,6 +31,7 @@
#include <string.h>
#include <time.h>
#include <errno.h>
+#include <caca.h>
#include "config.h"
#include "video_out.h"
@@ -38,30 +39,27 @@
#include "sub/sub.h"
#include "input/keycodes.h"
+#include "input/input.h"
#include "mp_msg.h"
#include "mp_fifo.h"
-#include <caca.h>
-#ifdef CACA_API_VERSION_1
- /* Include the pre-1.x compatibility header.
- * Once libcaca 1.x is widespread, vo_caca should be fully
- * converted to the new API. A patch exists:
- * http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2006-July/044669.html
- */
- #include <caca0.h>
-#endif
-
static const vo_info_t info = {
- "libcaca",
- "caca",
- "Pigeon <pigeon@pigeond.net>",
- ""
+ "libcaca",
+ "caca",
+ "Pigeon <pigeon@pigeond.net>",
+ ""
};
-const LIBVO_EXTERN (caca)
+const LIBVO_EXTERN(caca)
/* caca stuff */
-static struct caca_bitmap *cbitmap = NULL;
+static caca_canvas_t *canvas;
+static caca_display_t *display;
+static caca_dither_t *dither = NULL;
+static const char *dither_antialias = "default";
+static const char *dither_charset = "default";
+static const char *dither_color = "default";
+static const char *dither_algo = "none";
/* image infos */
static int image_format;
@@ -71,17 +69,17 @@ static int image_height;
static int screen_w, screen_h;
/* We want 24bpp always for now */
-static unsigned int bpp = 24;
+static unsigned int bpp = 24;
static unsigned int depth = 3;
static unsigned int rmask = 0xff0000;
static unsigned int gmask = 0x00ff00;
static unsigned int bmask = 0x0000ff;
static unsigned int amask = 0;
-#define MESSAGE_SIZE 512
-#define MESSAGE_DURATION 5
+#define MESSAGE_SIZE 512
+#define MESSAGE_DURATION 5
-static time_t stoposd = 0;
+static time_t stoposd = 0;
static int showosdmessage = 0;
static char osdmessagetext[MESSAGE_SIZE];
static char posbar[MESSAGE_SIZE];
@@ -91,10 +89,7 @@ static int posbary = 2;
static void osdmessage(int duration, const char *fmt, ...)
{
- /*
- * for outputting a centered string at the bottom
- * of our window for a while
- */
+ /* for outputting a centered string at the window bottom for a while */
va_list ar;
char m[MESSAGE_SIZE];
@@ -104,76 +99,81 @@ static void osdmessage(int duration, const char *fmt, ...)
strcpy(osdmessagetext, m);
showosdmessage = 1;
- stoposd = time(NULL) + duration;
- osdx = (screen_w - strlen (osdmessagetext)) / 2;
- posbar[0] = '\0';
+ stoposd = time(NULL) + duration;
+ osdx = (screen_w - strlen(osdmessagetext)) / 2;
+ posbar[0] = '\0';
}
-static void osdpercent(int duration, int min, int max, int val, const char *desc, const char *unit)
+static void osdpercent(int duration, int min, int max, int val,
+ const char *desc, const char *unit)
{
- /*
- * prints a bar for setting values
- */
+ /* prints a bar for setting values */
float step;
int where, i;
- step = (float)screen_w / (float)(max - min);
+ step = (float)screen_w / (float)(max - min);
where = (val - min) * step;
- osdmessage (duration, "%s: %i%s", desc, val, unit);
- posbar[0] = '|';
+ osdmessage(duration, "%s: %i%s", desc, val, unit);
+ posbar[0] = '|';
posbar[screen_w - 1] = '|';
- for (i = 0; i < screen_w; i++)
- {
- if (i == where)
- posbar[i] = '#';
- else
- posbar[i] = '-';
+ for (i = 0; i < screen_w; i++) {
+ if (i == where)
+ posbar[i] = '#';
+ else
+ posbar[i] = '-';
}
if (where != 0)
- posbar[0] = '|';
+ posbar[0] = '|';
if (where != (screen_w - 1))
- posbar[screen_w - 1] = '|';
+ posbar[screen_w - 1] = '|';
posbar[screen_w] = '\0';
}
static int resize(void)
{
- screen_w = caca_get_width();
- screen_h = caca_get_height();
+ screen_w = caca_get_canvas_width(canvas);
+ screen_h = caca_get_canvas_height(canvas);
- if (cbitmap)
- caca_free_bitmap(cbitmap);
+ caca_free_dither(dither);
- cbitmap = caca_create_bitmap(bpp, image_width, image_height,
- depth * image_width, rmask, gmask, bmask,
- amask);
+ dither = caca_create_dither(bpp, image_width, image_height,
+ depth * image_width,
+ rmask, gmask, bmask, amask);
+ if (dither == NULL) {
+ mp_msg(MSGT_VO, MSGL_FATAL, "vo_caca: caca_create_dither failed!\n");
+ return ENOSYS;
+ }
- if (!cbitmap)
- mp_msg(MSGT_VO, MSGL_FATAL, "vo_caca: caca_create_bitmap failed!\n");
+ /* Default libcaca features */
+ caca_set_dither_antialias(dither, dither_antialias);
+ caca_set_dither_charset(dither, dither_charset);
+ caca_set_dither_color(dither, dither_color);
+ caca_set_dither_algorithm(dither, dither_algo);
return 0;
}
static int config(uint32_t width, uint32_t height, uint32_t d_width,
- uint32_t d_height, uint32_t flags, char *title, uint32_t format)
+ uint32_t d_height, uint32_t flags, char *title,
+ uint32_t format)
{
image_height = height;
- image_width = width;
+ image_width = width;
image_format = format;
showosdmessage = 0;
- posbar[0] = '\0';
+ posbar[0] = '\0';
- return resize ();
+ return resize();
}
static int draw_frame(uint8_t *src[])
{
- caca_draw_bitmap(0, 0, screen_w, screen_h, cbitmap, src[0]);
+ caca_dither_bitmap(canvas, 0, 0, screen_w, screen_h, dither, src[0]);
return 0;
}
@@ -184,145 +184,173 @@ static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y)
static void flip_page(void)
{
+ if (showosdmessage) {
+ if (time(NULL) >= stoposd) {
+ showosdmessage = 0;
+ if (*posbar)
+ posbar[0] = '\0';
+ } else {
+ caca_put_str(canvas, osdx, osdy, osdmessagetext);
+ if (*posbar)
+ caca_put_str(canvas, 0, posbary, posbar);
+ }
+ }
+
+ caca_refresh_display(display);
+}
- if (showosdmessage)
- {
- if (time(NULL) >= stoposd)
- {
- showosdmessage = 0;
- if (*posbar)
- posbar[0] = '\0';
- } else {
- caca_putstr(osdx, osdy, osdmessagetext);
-
- if (*posbar)
- caca_putstr(0, posbary, posbar);
- }
+static void set_next_str(const char * const *list, const char **str,
+ const char **msg)
+{
+ int ind;
+ for (ind = 0; list[ind]; ind += 2) {
+ if (strcmp(list[ind], *str) == 0) {
+ if (list[ind + 2] == NULL)
+ ind = -2;
+ *str = list[ind + 2];
+ *msg = list[ind + 3];
+ return;
+ }
}
- caca_refresh();
+ *str = list[0];
+ *msg = list[1];
}
-static void check_events (void)
+static const struct mp_keymap keysym_map[] = {
+ {CACA_KEY_RETURN, KEY_ENTER}, {CACA_KEY_ESCAPE, KEY_ESC},
+ {CACA_KEY_UP, KEY_DOWN}, {CACA_KEY_DOWN, KEY_DOWN},
+ {CACA_KEY_LEFT, KEY_LEFT}, {CACA_KEY_RIGHT, KEY_RIGHT},
+ {CACA_KEY_PAGEUP, KEY_PAGE_UP}, {CACA_KEY_PAGEDOWN, KEY_PAGE_DOWN},
+ {CACA_KEY_HOME, KEY_HOME}, {CACA_KEY_END, KEY_END},
+ {CACA_KEY_INSERT, KEY_INSERT}, {CACA_KEY_DELETE, KEY_DELETE},
+ {CACA_KEY_BACKSPACE, KEY_BACKSPACE}, {CACA_KEY_TAB, KEY_TAB},
+ {CACA_KEY_PAUSE, KEY_PAUSE},
+ {CACA_KEY_F1, KEY_F+1}, {CACA_KEY_F2, KEY_F+2},
+ {CACA_KEY_F3, KEY_F+3}, {CACA_KEY_F4, KEY_F+4},
+ {CACA_KEY_F5, KEY_F+5}, {CACA_KEY_F6, KEY_F+6},
+ {CACA_KEY_F7, KEY_F+7}, {CACA_KEY_F8, KEY_F+8},
+ {CACA_KEY_F9, KEY_F+9}, {CACA_KEY_F10, KEY_F+10},
+ {CACA_KEY_F11, KEY_F+11}, {CACA_KEY_F12, KEY_F+12},
+ {CACA_KEY_F13, KEY_F+13}, {CACA_KEY_F14, KEY_F+14},
+ {CACA_KEY_F15, KEY_F+15},
+ {0, 0}
+};
+
+static void check_events(void)
{
- unsigned int cev;
-
- if ((cev = caca_get_event(CACA_EVENT_ANY)))
- {
- if (cev & CACA_EVENT_RESIZE)
- {
- caca_refresh();
- resize();
- } else if (cev & CACA_EVENT_KEY_RELEASE)
- {
- int key = (cev & 0x00ffffff);
- enum caca_feature cf;
-
- switch (key) {
- case 'd':
- case 'D':
- /* Toggle dithering method */
- cf = 1 + caca_get_feature(CACA_DITHERING);
- if (cf > CACA_DITHERING_MAX)
- cf = CACA_DITHERING_MIN;
- caca_set_feature(cf);
- osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf));
- break;
-
- case 'a':
- case 'A':
- /* Toggle antialiasing method */
- cf = 1 + caca_get_feature(CACA_ANTIALIASING);
- if (cf > CACA_ANTIALIASING_MAX)
- cf = CACA_ANTIALIASING_MIN;
- caca_set_feature(cf);
- osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf));
- break;
-
- case 'b':
- case 'B':
- /* Toggle background method */
- cf = 1 + caca_get_feature(CACA_BACKGROUND);
- if (cf > CACA_BACKGROUND_MAX)
- cf = CACA_BACKGROUND_MIN;
- caca_set_feature(cf);
- osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf));
- break;
-
- case CACA_KEY_UP:
- mplayer_put_key(KEY_UP);
- break;
- case CACA_KEY_DOWN:
- mplayer_put_key(KEY_DOWN);
- break;
- case CACA_KEY_LEFT:
- mplayer_put_key(KEY_LEFT);
- break;
- case CACA_KEY_RIGHT:
- mplayer_put_key(KEY_RIGHT);
- break;
- case CACA_KEY_ESCAPE:
- mplayer_put_key(KEY_ESC);
- break;
- case CACA_KEY_PAGEUP:
- mplayer_put_key(KEY_PAGE_UP);
- break;
- case CACA_KEY_PAGEDOWN:
- mplayer_put_key(KEY_PAGE_DOWN);
- break;
- case CACA_KEY_RETURN:
- mplayer_put_key(KEY_ENTER);
- break;
- case CACA_KEY_HOME:
- mplayer_put_key(KEY_HOME);
- break;
- case CACA_KEY_END:
- mplayer_put_key(KEY_END);
- break;
- default:
- if (key <= 255)
- mplayer_put_key (key);
- break;
- }
- }
+ caca_event_t cev;
+ while (caca_get_event(display, CACA_EVENT_ANY, &cev, 0)) {
+
+ switch (cev.type) {
+ case CACA_EVENT_RESIZE:
+ caca_refresh_display(display);
+ resize();
+ break;
+ case CACA_EVENT_QUIT:
+ mplayer_put_key(KEY_CLOSE_WIN);
+ break;
+ case CACA_EVENT_MOUSE_MOTION:
+ vo_mouse_movement(global_vo, cev.data.mouse.x, cev.data.mouse.y);
+ break;
+ case CACA_EVENT_MOUSE_PRESS:
+ if (!vo_nomouse_input)
+ mplayer_put_key((MOUSE_BTN0 + cev.data.mouse.button - 1) | MP_KEY_DOWN);
+ break;
+ case CACA_EVENT_MOUSE_RELEASE:
+ if (!vo_nomouse_input)
+ mplayer_put_key(MOUSE_BTN0 + cev.data.mouse.button - 1);
+ break;
+ case CACA_EVENT_KEY_PRESS:
+ {
+ int key = cev.data.key.ch;
+ int mpkey = lookup_keymap_table(keysym_map, key);
+ const char *msg_name;
+
+ if (mpkey)
+ mplayer_put_key(mpkey);
+ else
+ switch (key) {
+ case 'd':
+ case 'D':
+ /* Toggle dithering algorithm */
+ set_next_str(caca_get_dither_algorithm_list(dither), &dither_algo, &msg_name);
+ caca_set_dither_algorithm(dither, dither_algo);
+ osdmessage(MESSAGE_DURATION, "Using %s", msg_name);
+ break;
+
+ case 'a':
+ case 'A':
+ /* Toggle antialiasing method */
+ set_next_str(caca_get_dither_antialias_list(dither), &dither_antialias, &msg_name);
+ caca_set_dither_antialias(dither, dither_antialias);
+ osdmessage(MESSAGE_DURATION, "Using %s", msg_name);
+ break;
+
+ case 'h':
+ case 'H':
+ /* Toggle charset method */
+ set_next_str(caca_get_dither_charset_list(dither), &dither_charset, &msg_name);
+ caca_set_dither_charset(dither, dither_charset);
+ osdmessage(MESSAGE_DURATION, "Using %s", msg_name);
+ break;
+
+ case 'c':
+ case 'C':
+ /* Toggle color method */
+ set_next_str(caca_get_dither_color_list(dither), &dither_color, &msg_name);
+ caca_set_dither_color(dither, dither_color);
+ osdmessage(MESSAGE_DURATION, "Using %s", msg_name);
+ break;
+
+ default:
+ if (key <= 255)
+ mplayer_put_key(key);
+ break;
+ }
+ }
+ }
}
}
static void uninit(void)
{
- caca_free_bitmap(cbitmap);
- cbitmap = NULL;
- caca_end();
+ caca_free_dither(dither);
+ dither = NULL;
+ caca_free_display(display);
+ caca_free_canvas(canvas);
}
static void draw_osd(void)
{
if (vo_osd_progbar_type != -1)
- osdpercent(MESSAGE_DURATION, 0, 255,
- vo_osd_progbar_value, sub_osd_names[vo_osd_progbar_type],
- "");
+ osdpercent(MESSAGE_DURATION, 0, 255, vo_osd_progbar_value,
+ sub_osd_names[vo_osd_progbar_type], "");
}
static int preinit(const char *arg)
{
- if (arg)
- {
- mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: Unknown subdevice: %s\n", arg);
- return ENOSYS;
+ if (arg) {
+ mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: Unknown subdevice: %s\n", arg);
+ return ENOSYS;
}
- if (caca_init())
- {
- mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to initialize\n");
- return ENOSYS;
+ canvas = caca_create_canvas(0, 0);
+ if (canvas == NULL) {
+ mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to create canvas\n");
+ return ENOSYS;
}
- caca_set_window_title("MPlayer");
+ display = caca_create_display(canvas);
- /* Default libcaca features */
- caca_set_feature(CACA_ANTIALIASING_PREFILTER);
- caca_set_feature(CACA_DITHERING_RANDOM);
+ if (display == NULL) {
+ mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to create display\n");
+ caca_free_canvas(canvas);
+ return ENOSYS;
+ }
+
+ caca_set_display_title(display, "MPlayer");
return 0;
}
@@ -330,18 +358,17 @@ static int preinit(const char *arg)
static int query_format(uint32_t format)
{
if (format == IMGFMT_BGR24)
- return VFCAP_OSD | VFCAP_CSP_SUPPORTED;
+ return VFCAP_OSD | VFCAP_CSP_SUPPORTED;
return 0;
}
static int control(uint32_t request, void *data)
{
- switch(request)
- {
+ switch (request) {
case VOCTRL_QUERY_FORMAT:
- return query_format(*((uint32_t *)data));
+ return query_format(*((uint32_t *)data));
default:
- return VO_NOTIMPL;
+ return VO_NOTIMPL;
}
}