summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-21 23:15:32 +0100
committerwm4 <wm4@nowhere>2013-12-21 23:15:32 +0100
commit0a3e9a9ac3a90da831b497e0613dfb66bc14f3d2 (patch)
treeb70f214f8c3fc802d6d6edbf8395273c854ac0fd /osdep
parenta4fe95b0d8d339ba5afbdb5346ad8fd367a4a1c1 (diff)
parent245e5b844177e9ad9a9c07eff5efab7c3fccdebc (diff)
downloadmpv-0a3e9a9ac3a90da831b497e0613dfb66bc14f3d2.tar.bz2
mpv-0a3e9a9ac3a90da831b497e0613dfb66bc14f3d2.tar.xz
Merge branch 'msg_refactor'
This branch changes mp_msg() so that it doesn't require global context. The changes are pretty violent.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/macosx_application.m7
-rw-r--r--osdep/path-macosx.m5
-rw-r--r--osdep/path.h5
-rw-r--r--osdep/priority.c2
-rw-r--r--osdep/terminal-unix.c41
-rw-r--r--osdep/terminal-win.c75
-rw-r--r--osdep/terminal.h36
7 files changed, 134 insertions, 37 deletions
diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m
index ba801f412a..1ae1752bf1 100644
--- a/osdep/macosx_application.m
+++ b/osdep/macosx_application.m
@@ -16,6 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <stdio.h>
#include <pthread.h>
#include "talloc.h"
@@ -336,9 +337,9 @@ int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[])
// This should never be reached: cocoa_run_runloop blocks until the
// process is quit
- mp_msg(MSGT_CPLAYER, MSGL_ERR, "There was either a problem "
- "initializing Cocoa or the Runloop was stopped unexpectedly. "
- "Please report this issues to a developer.\n");
+ fprintf(stderr, "There was either a problem "
+ "initializing Cocoa or the Runloop was stopped unexpectedly. "
+ "Please report this issues to a developer.\n");
pthread_join(playback_thread_id, NULL);
return 1;
}
diff --git a/osdep/path-macosx.m b/osdep/path-macosx.m
index d4c5020da1..543b248c14 100644
--- a/osdep/path-macosx.m
+++ b/osdep/path-macosx.m
@@ -20,11 +20,12 @@
#include "options/path.h"
#include "osdep/path.h"
-char *mp_get_macosx_bundled_path(const char *file)
+char *mp_get_macosx_bundled_path(void *talloc_ctx, struct mpv_global *global,
+ const char *filename)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *path = [[NSBundle mainBundle] resourcePath];
- char *rv = mp_path_join(NULL, bstr0([path UTF8String]), bstr0(file));
+ char *rv = mp_path_join(talloc_ctx, bstr0([path UTF8String]), bstr0(file));
[pool release];
return rv;
}
diff --git a/osdep/path.h b/osdep/path.h
index 6ad4ebad8a..91afbce604 100644
--- a/osdep/path.h
+++ b/osdep/path.h
@@ -1,9 +1,12 @@
#ifndef OSDEP_PATH_H
#define OSDEP_PATH_H
+struct mpv_global;
+
char *mp_get_win_config_path(const char *filename);
// Returns absolute path of a resource file in a Mac OS X application bundle.
-char *mp_get_macosx_bundled_path(const char *filename);
+char *mp_get_macosx_bundled_path(void *talloc_ctx, struct mpv_global *global,
+ const char *filename);
#endif
diff --git a/osdep/priority.c b/osdep/priority.c
index 3868f09078..3fe1ee415e 100644
--- a/osdep/priority.c
+++ b/osdep/priority.c
@@ -58,8 +58,6 @@ void set_priority(void)
if (strcasecmp(priority_presets_defs[i].name, proc_priority) == 0)
break;
}
- mp_msg(MSGT_CPLAYER, MSGL_STATUS, "Setting process priority: %s\n",
- priority_presets_defs[i].name);
SetPriorityClass(GetCurrentProcess(), priority_presets_defs[i].prio);
}
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index 050b97b9d1..03f2360916 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -227,7 +227,7 @@ static void termcap_add_extra_f_keys(void) {
#endif
-int load_termcap(char *termtype){
+static int load_termcap(char *termtype){
#if HAVE_TERMINFO || HAVE_TERMCAP
#if HAVE_TERMINFO
@@ -358,7 +358,7 @@ static void walk_buf(unsigned int count) {
getch2_pos = 0;
}
-bool getch2(struct input_ctx *input_ctx)
+static bool getch2(struct input_ctx *input_ctx)
{
int retval = read(0, &getch2_buf[getch2_pos], BUF_LEN - getch2_len - getch2_pos);
/* Return false on EOF to stop running select() on the FD, as it'd
@@ -437,6 +437,18 @@ bool getch2(struct input_ctx *input_ctx)
return true;
}
+static int read_keys(void *ctx, int fd)
+{
+ if (getch2(ctx))
+ return MP_INPUT_NOTHING;
+ return MP_INPUT_DEAD;
+}
+
+void terminal_setup_getch(struct input_ctx *ictx)
+{
+ mp_input_add_fd(ictx, 0, 1, NULL, read_keys, NULL, ictx);
+}
+
static volatile int getch2_active = 0;
static volatile int getch2_enabled = 0;
@@ -578,3 +590,28 @@ void getch2_disable(void){
getch2_enabled = 0;
}
+
+bool terminal_in_background(void)
+{
+ return isatty(2) && tcgetpgrp(2) != getpgrp();
+}
+
+void terminal_set_foreground_color(FILE *stream, int c)
+{
+ if (c == -1) {
+ fprintf(stream, "\033[0m");
+ } else {
+ fprintf(stream, "\033[%d;3%dm", c >> 3, c & 7);
+ }
+}
+
+void terminal_setup_stdin_cmd_input(struct input_ctx *ictx)
+{
+ mp_input_add_fd(ictx, 0, 1, input_default_read_cmd, NULL, NULL, NULL);
+}
+
+int terminal_init(void)
+{
+ load_termcap(NULL);
+ return 0;
+}
diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c
index a56d1a409c..5186c301f2 100644
--- a/osdep/terminal-win.c
+++ b/osdep/terminal-win.c
@@ -28,11 +28,30 @@
#include <stdint.h>
#include <string.h>
#include <windows.h>
+#include <io.h>
#include "input/keycodes.h"
#include "input/input.h"
#include "terminal.h"
-int mp_input_slave_cmd_func(int fd, char *dest, int size)
+int screen_width = 80;
+int screen_height = 24;
+char *erase_to_end_of_line = NULL;
+
+#define hSTDOUT GetStdHandle(STD_OUTPUT_HANDLE)
+#define hSTDERR GetStdHandle(STD_ERROR_HANDLE)
+static short stdoutAttrs = 0;
+static const unsigned char ansi2win32[8] = {
+ 0,
+ FOREGROUND_RED,
+ FOREGROUND_GREEN,
+ FOREGROUND_GREEN | FOREGROUND_RED,
+ FOREGROUND_BLUE,
+ FOREGROUND_BLUE | FOREGROUND_RED,
+ FOREGROUND_BLUE | FOREGROUND_GREEN,
+ FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED,
+};
+
+static int mp_input_slave_cmd_func(void *ctx, int fd, char *dest, int size)
{
DWORD retval;
HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
@@ -51,9 +70,10 @@ int mp_input_slave_cmd_func(int fd, char *dest, int size)
return MP_INPUT_NOTHING;
}
-int screen_width = 80;
-int screen_height = 24;
-char *erase_to_end_of_line = NULL;
+void terminal_setup_stdin_cmd_input(struct input_ctx *ictx)
+{
+ mp_input_add_fd(ictx, 0, 0, mp_input_slave_cmd_func, NULL, NULL, NULL);
+}
void get_screen_size(void)
{
@@ -64,11 +84,6 @@ void get_screen_size(void)
}
}
-int load_termcap(char *termtype)
-{
- return 0;
-}
-
static HANDLE in;
static int getch2_status = 0;
@@ -162,7 +177,7 @@ static int getch2_internal(void)
return -1;
}
-bool getch2(struct input_ctx *ctx)
+static bool getch2(struct input_ctx *ctx)
{
int r = getch2_internal();
if (r >= 0)
@@ -170,6 +185,18 @@ bool getch2(struct input_ctx *ctx)
return true;
}
+static int read_keys(void *ctx, int fd)
+{
+ if (getch2(ctx))
+ return MP_INPUT_NOTHING;
+ return MP_INPUT_DEAD;
+}
+
+void terminal_setup_getch(struct input_ctx *ictx)
+{
+ mp_input_add_fd(ictx, 0, 1, NULL, read_keys, NULL, ictx);
+}
+
void getch2_poll(void)
{
}
@@ -192,3 +219,31 @@ void getch2_disable(void)
return; // already disabled / never enabled
getch2_status = 0;
}
+
+bool terminal_in_background(void)
+{
+ return false;
+}
+
+void terminal_set_foreground_color(FILE *stream, int c)
+{
+ HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT;
+ if (c < 0 || c >= 8) { // reset or invalid
+ SetConsoleTextAttribute(wstream, stdoutAttrs);
+ } else {
+ SetConsoleTextAttribute(wstream, ansi2win32[c] | FOREGROUND_INTENSITY);
+ }
+}
+
+int terminal_init(void)
+{
+ CONSOLE_SCREEN_BUFFER_INFO cinfo;
+ DWORD cmode = 0;
+ GetConsoleMode(hSTDOUT, &cmode);
+ cmode |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
+ SetConsoleMode(hSTDOUT, cmode);
+ SetConsoleMode(hSTDERR, cmode);
+ GetConsoleScreenBufferInfo(hSTDOUT, &cinfo);
+ stdoutAttrs = cinfo.wAttributes;
+ return 0;
+}
diff --git a/osdep/terminal.h b/osdep/terminal.h
index 76cedd9928..c524adbc2b 100644
--- a/osdep/terminal.h
+++ b/osdep/terminal.h
@@ -25,6 +25,9 @@
#define MPLAYER_GETCH2_H
#include <stdbool.h>
+#include <stdio.h>
+
+struct input_ctx;
/* Screen size. Initialized by load_termcap() and get_screen_size() */
extern int screen_width;
@@ -33,12 +36,25 @@ extern int screen_height;
/* Termcap code to erase to end of line */
extern char * erase_to_end_of_line;
+/* Global initialization for terminal output. */
+int terminal_init(void);
+
+/* Setup ictx to read input commands from stdin (slave mode) */
+void terminal_setup_stdin_cmd_input(struct input_ctx *ictx);
+
+/* Setup ictx to read keys from the terminal */
+void terminal_setup_getch(struct input_ctx *ictx);
+
+/* Return whether the process has been backgrounded. */
+bool terminal_in_background(void);
+
+/* Set ANSI text foreground color. c is [-1, 7], where 0-7 are colors, and
+ * -1 means reset to default. stream is either stdout or stderr. */
+void terminal_set_foreground_color(FILE *stream, int c);
+
/* Get screen-size using IOCTL call. */
void get_screen_size(void);
-/* Load key definitions from the TERMCAP database. 'termtype' can be NULL */
-int load_termcap(char *termtype);
-
/* Initialize getch2 */
void getch2_enable(void);
void getch2_disable(void);
@@ -46,18 +62,4 @@ void getch2_disable(void);
/* Enable and disable STDIN line-buffering */
void getch2_poll(void);
-/* Read a character or a special key code (see keycodes.h) */
-struct input_ctx;
-bool getch2(struct input_ctx *ictx);
-
-#if defined(__MINGW32__)
-// slave cmd function for Windows
-int mp_input_slave_cmd_func(int fd,char* dest,int size);
-#define USE_FD0_CMD_SELECT 0
-#define MP_INPUT_SLAVE_CMD_FUNC mp_input_slave_cmd_func
-#else
-#define USE_FD0_CMD_SELECT 1
-#define MP_INPUT_SLAVE_CMD_FUNC NULL
-#endif
-
#endif /* MPLAYER_GETCH2_H */