summaryrefslogtreecommitdiffstats
path: root/player/client.c
Commit message (Collapse)AuthorAgeFilesLines
* client API: disallow masking MPV_EVENT_SHUTDOWNwm42015-12-021-0/+2
| | | | | | | | | This makes no sense, because the client is obligated to react to this event. This also happens to fix a deadlock with JSON IPC clients sending "disable_event all", because MPV_EVENT_SHUTDOWN was used to stop the thread driving the socket connection (fixes #2558).
* client API: change error string if playback fails completelywm42015-10-261-1/+1
| | | | | It can print this if AO/VO initialization fails, which makes the wording a lie. Change it to something more diplomatically safe.
* client API: improve an error messagewm42015-08-281-1/+1
| | | | | This refers to media played by mpv, and these don't necessarily have to be files. They can be network resources or entirely abstract URLs too.
* client API: fix mpv_get_property_async() string casewm42015-07-101-1/+1
| | | | | | | The logic for this code didn't survive the previous refactor. It always crashed in async mode. Fixes #2121.
* client API: allow using msg-level option for log messageswm42015-06-201-0/+3
| | | | | | | | | | | | | | | | Client API users can enable log output with mpv_request_log_messages(). But you can enable only a single log level. This is normally enough, but the --msg-level option (which controls the terminal log level) provides more flexibility. Due to internal complexity, it would be hard to provide the same flexibility for each client API handle. But there's a simple way to achieve basically the same thing: add an option that sends log messages to the API handle, which would also be printed to the terminal as by --msg-level. The only change is that we don't disable this logic if the terminal is disabled. Instead we check for this before the message is output, which in theory can lower performance if messages are being spammed. It could be handled with some more effort, but the gain would be negligible.
* client API: fix logging memory leakwm42015-06-181-0/+1
| | | | | | Very stupid. Was pointed out in #2056.
* player: fix crashes when adding external tracks before loading main filewm42015-05-261-1/+1
| | | | | | | | | | | | | | | | Adding an external audio track before loading the main file didn't work right. For one, mp_switch_track() assumes it is called after the main file is loaded. (The difference is that decoders are only initialized once the main file is loaded, and we avoid doing this before that for whatever reason.) To avoid further messiness, just allow mp_switch_track() to be called at any time. Also make it do what mp_mark_user_track_selection() did, since the latter requires current_track to be set. (One could probably simply allow current_track to be set at this point, but it'd interfere with default track selection anyway and thus would be pointless.) Fixes #1984.
* threads: use utility+POSIX functions instead of weird wrapperswm42015-05-111-2/+4
| | | | | | | There is not much of a reason to have these wrappers around. Use POSIX standard functions directly, and use a separate utility function to take care of the timespec calculations. (Course POSIX for using this weird format for time values.)
* player: use profiles for libmpv and encoding defaultswm42015-05-071-14/+1
| | | | | | | | The client API (libmpv) and encoding (--o) have slightly different defaults from the command line player. Instead of doing a bunch of calls to set the options explicitly, use profiles. This is simpler and has the advantage that they can be listed on command line (instead of possibly forcing the user to find and read the code to know all the details).
* client API: add glue for making full use of mpv_command_node()wm42015-04-201-6/+9
| | | | | Until now, the return value was always MPV_FORMAT_NONE. Now a command can actually set it. This will be used in one of the following commits.
* vo_opengl_cb: deprecate mpv_opengl_cb_render()wm42015-04-091-1/+6
| | | | Its vp parameter made no sense anymore. Introduce a new one.
* vo_opengl_cb: add a function to report vsync timewm42015-04-091-0/+4
| | | | | | | And also let vo.c know of it. Currently, this does not help much, but will facilitate future improvements.
* client API: remove dead assignmentwm42015-03-231-1/+0
| | | | | Probably a leftover from an earlier refactoring. Now data is always in the format MPV_FORMAT_NODE.
* vo_opengl_cb: don't render OSD while VO is not createdwm42015-03-231-1/+1
| | | | | | | | | | | Unlike other VOs, this rendered OSD even while no VO was created (because the renderer lives as long as the API user wants). Change this, and refactor the code so that the OSD object is accessible only while the VO is created. (There is a short time where the OSD can still be accessed even after VO destruction - this is not a race condition, though it's inelegant and unfortunately unavoidable.)
* player, client API: refactor cplayer init, reduce client API differenceswm42015-03-051-3/+1
| | | | | | | | | | | | | Move the command line parsing and some other things to the common init routine shared between command line player and client API. This means they're using almost exactly the same code now. The main intended side effect is that the client API will load mpv.conf; though still only if config loading is enabled. (The cplayer still avoids creating an extra thread, passes a command line, and prints an exit status to the terminal. It also has some different defaults.)
* client API: add mpv_wait_async_requests()wm42015-02-021-8/+12
| | | | | | | | | | | | | | | | | | | | This does what it's documented to do. The implementation reuses the code in mpv_detach_destroy(). Due to the way async requests currently work, just sending a synchronous dummy request (like a "ignore" command) would be enough to ensure synchronization, but this code will continue to work even if this changes. The line "ctx->event_mask = 0;" is removed, but it shouldn't be needed. (If a client is somehow very slow to terminate, this could silence an annoying queue overflow message, but all in all it does nothing.) Calling mpv_wait_async_requests() and mpv_wait_event() concurrently is in theory allowed, so change pthread_cond_signal() to pthread_cond_broadcast() to avoid missed wakeups. As requested in issue #1542.
* client API: check locale, and reject anything other than "C" localewm42015-01-201-0/+16
| | | | | | | | | | | | | | | Sigh... The C locale system is incredibly shitty, and if used, breaks basic string functions. The locale can change the decimal mark from "." to ",", which affects conversion between floats and strings: snprintf() and strtod() respect the locale decimal mark, and change behavior. (What's even better, the behavior of these functions can change asynchronously, if setlocale() is called after threads were started.) So just check the locale in the client API, and refuse to work if it's wrong. This also makes the lib print to stderr, which I consider the lesser evil in this specific situation.
* client API: minor cleanupwm42015-01-191-17/+28
| | | | | Try not to put "everything" into mpv_wait_event: move out the code for generating log message events.
* client API: notify API user on event queue overflowwm42015-01-191-10/+22
| | | | | | | | | | | | | | | Before this, we merely printed a message to the terminal. Now the API user can determine this properly. This might be important for API users which somehow maintain complex state, which all has to be invalidated if (state-changing) events are missing due to an overflow. This also forces the client API user to empty the event queue, which is good, because otherwise the event queue would reach the "filled up" state immediately again due to further asynchronous events being added to the queue. Also add some minor improvements to mpv_wait_event() documentation, and some other minor cosmetic changes.
* client API: fix log buffer overflow casewm42015-01-131-3/+3
| | | | | | | It just crashed. The prefix and text fields point to static strings in this case. Oops. Fixes the issue mentioned in #838.
* client API, vo_opengl_cb: properly uninit videowm42015-01-041-0/+1
| | | | | | | | | | | | mpv_opengl_cb_uninit_gl() can be called at any time; but then the decoder must be destroyed due to complications with hardware decoding. This is why kill_video() exists. To make things easier, there is the invariant that while vo_opengl_cb is active, the OpenGL state must exist. But kill_video() didn't actually destroy the VO; only the video decoder. This could trigger an assertion (vo_opengl_cb.c:187). Actually, the video output is always destroyed lazily at a later point if the decoder is destroyed, but not early enough for out purposes.
* client API: add function to create new mpv_handles from existing oneswm42014-12-311-0/+14
| | | | | | | This may or may not be useful for client API users. Fold this API extension into the previous API bump. The previous bump was only yesterday, so it's ok.
* vo_opengl_cb: simplify API uninitializationwm42014-12-311-1/+10
| | | | | | | | | | | Until now, calling mpv_opengl_cb_uninit_gl() at a "bad moment" could make the whole thing to explode. The API user was asked to avoid such situations by calling it only in "good moments". But this was probably a bit too subtle and could easily be overlooked. Integrate the approach the qml example uses directly into the implementation. If the OpenGL context is to be unitialized, forcefully disable video, and block until this is done.
* client API: fix compiler warning if openglcb API is disabledwm42014-12-221-1/+0
| | | | | The function is void, and of course you can't return anything from it. (Why does C or gcc even allow this?)
* client API: fix mpv_wakeup()wm42014-12-221-2/+2
| | | | | | Of course this was going to get stuck in the retry loop. Fixes #1372.
* client API: be more lenient about mpv_suspend/resume mismatcheswm42014-12-151-2/+45
| | | | | | | | | | | | Before this commit, this was defined to trigger undefined behavior. This was nice because it required less code; but on the other hand, Lua as well as IPC support had to check these things manually. Do it directly in the API to avoid code duplication, and to make the API more robust. (The total code size still grows, though...) Since all of the failure cases were originally meant to ruin things forever, there is no way to return error codes. So just print the errors.
* client API: expose OpenGL rendererwm42014-12-091-0/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds API to libmpv that lets host applications use the mpv opengl renderer. This is a more flexible (and possibly more portable) option to foreign window embedding (via --wid). This assumes that methods like context sharing and multithreaded OpenGL rendering are infeasible, and that a way is needed to integrate it with an application that uses a single thread to render everything. Add an example that does this with QtQuick/qml. The example is relatively lazy, but still shows how relatively simple the integration is. The FBO indirection could probably be avoided, but would require more work (and would probably lead to worse QtQuick integration, because it would have to ignore transformations like rotation). Because this makes mpv directly use the host application's OpenGL context, there is no platform specific code involved in mpv, except for hw decoding interop. main.qml is derived from some Qt example. The following things are still missing: - a way to do better video timing - expose GL renderer options, allow changing them at runtime - support for color equalizer controls - support for screenshots
* client API: allow multiple mpv instances with terminal=yeswm42014-12-021-0/+1
| | | | | | | | | | | | | | | This is simply not allowed, and doing it triggered an assertion. It's still not allowed, because the terminal and related functionality is a global resource, and there doesn't seem to be a sane way to manage the signal handlers. But be a bit nicer, and just the terminal if it's already in use. Note that terminal _output_ happens anyway. This becomes usable with this commit. To facilitate logging-only usage further, also explicitly disable terminal input, so that "terminal=yes" can be used for logging without much interference with other things. (It'll still overwrite some signal handlers, though.)
* client API: print version on initializationwm42014-12-021-0/+2
| | | | | A rather big oversight, because a log produced with the client API will not contain the mpv version at all otherwise.
* client API: make sure youtube-dl is not used by defaultwm42014-11-251-0/+1
| | | | | | | Currently, --ytdl is off by default, but even if this is changed, never enable it by default for the client API. It would be inappropriate to start an intrusive external subprocess behind the host application's back.
* input, lua: redo input handlingwm42014-11-231-0/+24
| | | | | Much of it is the same, but now there's the possibility to distinguish key down/up events in the Lua API.
* client API: restrict client nameswm42014-11-231-20/+19
| | | | | | Use a fixed size array for the client name, which also limits the client name in size. Sanitize the client name string, and replace characters that are not in [A-Za-z0-9] with '_'.
* client: remove redundant assignmentwm42014-11-071-1/+0
| | | | This is set by send_reply().
* client API: silence silly clang warningwm42014-11-071-2/+2
| | | | | | | The values compared here happen to be of unsigned enum types - but the test is not supposed to break if we somehow force the enum to signed, or if the compiler happens to use a signed type (as far as I remember, the exact integer type the compiler can use is implementation-defined).
* command: make window-scale property observablewm42014-11-021-1/+1
| | | | | | | | | | | | Add a generic mechanism to the VO to relay "extra" events from VO to player. Use it to notify the core of window resizes, which in turn will be used to mark all affected properties ("window-scale" in this case) as changed. (I refrained from hacking this as internal command into input_ctx, or to poll the state change, etc. - but in the end, maybe it would be best to actually pass the client API context directly to the places where events can happen.)
* player: add an option to abort playback on partial init failureswm42014-10-281-0/+1
| | | | | | This is probably what libmpv users want; and it also improves error reporting (or we'd have to add a way to communicate such mid-playback failures as events).
* client API: better error reportingwm42014-10-281-0/+5
| | | | Give somewhat more information on playback failure.
* command: finish hook execution if client failswm42014-10-241-1/+10
| | | | | Translation: if the (to be added) youtube-dl Lua script crashes, don't wait forever when opening something.
* client API: print properties set with -vwm42014-10-231-0/+7
| | | | | Useful for debugging. Considered doing this in command.c, but it's easier here.
* Set thread name for debuggingwm42014-10-191-0/+2
| | | | | | | | | | Especially with other components (libavcodec, OSX stuff), the thread list can get quite populated. Setting the thread name helps when debugging. Since this is not portable, we check the OS variants in waf configure. old-configure just gets a special-case for glibc, since doing a full check here would probably be a waste of effort.
* command: add a mechanism to allow scripts to intercept file loadswm42014-10-161-0/+4
| | | | | | | | | | | | | | | | | | | | | | | A vague idea to get something similar what libquvi did. Undocumented because it might change a lot, or even be removed. To give an idea what it does, a Lua script could do the following: -- type ID priority mp.commandv("hook_add", "on_load", 0, 0) mp.register_script_message("hook_run", function(param, param2) -- param is "0", the user-chosen ID from the hook_add command -- param2 is the magic value that has to be passed to finish -- the hook mp.resume_all() -- do something, maybe set options that are reset on end: mp.set_property("file-local-options/name", "value") -- or change the URL that's being opened: local url = mp.get_property("stream-open-filename") mp.set_property("stream-open-filename", url .. ".png") -- let the player (or the next script) continue mp.commandv("hook_ack", param2) end)
* client API: allow returning float properties as integerswm42014-10-141-0/+4
| | | | | I'm starting to think that being type-strict with this interface actually sucks. This commit is a step towards being less strict.
* client API: check result ptr in mpv_command_nodeJames Ross-Gowan2014-10-121-1/+1
| | | | This follows the docs, which say the result parameter is optional.
* client API: add mpv_command_node[_async]wm42014-10-111-3/+19
| | | | | | | | | Allows passing native types as arguments. Also some minor doc improvements, including giving some (natural) improvements to mpv_free_node_contents(). Note: mpv_command_node_async() is completely untested.
* input: use mpv_node parser for char** command parserswm42014-10-101-3/+2
| | | | Minor simplification, also drops some useless stuff.
* libmpv/cocoa: don't start the event monitorStefano Pigozzi2014-10-091-1/+2
| | | | | | The event monitor is used to get keyboard events when there is no window, but since it is a global monitor to the current process, we don't want it in a library setting.
* libmpv/cocoa: make global events work and get rid of is_cplayerStefano Pigozzi2014-10-091-0/+2
| | | | | | | After @frau's split of macosx_events from macosx_application, `is_cplayer' is not needed anymore. At the moment only global events such as Media Keys and Apple Remote work, because the VO-level ones were hardcoded to be disabled. (that will be fix in a later commit ).
* client API: add an explanatory commentwm42014-10-091-1/+1
| | | | | So someone reading this at least has a chance to find out what this is needed for.
* client API: rename --input-x11-keyboard to --input-vo-keyboardwm42014-10-091-1/+1
| | | | | Apparently we need this for Cocoa too. (The option was X11 specific in the hope that only X11 would need this hack.)
* client API: introduce numeric log levelswm42014-10-081-0/+1
| | | | | | | | | | | | | | | | Maybe using strings for log levels was a mistake (too broad and too impractical), so I'm adding numeric log level at least for the receiver side. This makes it easier to map mpv log levels to other logging systems. I'm still too stingy to add a function to set the log level by a numeric value, though. The numeric values are not directly mapped to the internal mpv values, because then almost every file in mpv would have to include the client API header. Coalesce this into API version 1.6, since 1.6 was bumped just yesterday.
* client API, X11: change default keyboard input handling againwm42014-09-281-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Commit 64b7811c tried to do the "right thing" with respect to whether keyboard input should be enabled or not. It turns out that X11 does something stupid by design. All modern toolkits work around this native X11 behavior, but embedding breaks these workarounds. The only way to handle this correctly is the XEmbed protocol. It needs to be supported by the toolkit, and probably also some mpv support. But Qt has inconsistent support for it. In Qt 4, a X11 specific embedding widget was needed. Qt 5.0 doesn't support it at all. Qt 5.1 apparently supports it via QWindow, but if it really does, I couldn't get it to work. So add a hack instead. The new --input-x11-keyboard option controls whether mpv should enable keyboard input on the X11 window or not. In the command line player, it's enabled by default, but in libmpv it's disabled. This hack has the same problem as all previous embedding had: move the mouse outside of the window, and you don't get keyboard input anymore. Likewise, mpv will steal all keyboard input from the parent application as long as the mouse is inside of the mpv window. Also see issue #1090.
* client API: use playback abort mechanismwm42014-09-131-0/+5
| | | | | | If you send the "quit" or "stop" command with the client API, it will now attempt to kill network I/O immediately (same as normal input in the previous commits).
* lua: synchronously wait until scripts are loadedwm42014-09-061-0/+22
| | | | | | | | | | | | | | | | | This makes the player wait until each script is loaded. Do this to give the script a chance to setup all its event handlers. It might also be useful to allow a script to change options that matter for playback. While waiting for a script to be loaded, the player actually accepts input. This is needed because the scripts can execute player commands anyway while they are being "loaded". The player won't react to most commands though: it can't quit or navigate the playlist in this state. For deciding whether a script is finally loaded, we use a cheap hack: if mpv_wait_event() is called, it's considered loaded. Let's hope this is good enough. I think it's better than introducing explicit API for this. Although I'm sure this will turn out as too simplistic some time in the future, the same would probably happen with a more explicit API.
* client API: fix memory leak with rejected eventswm42014-08-311-35/+36
| | | | | | | | The event was copied early, and wasn't released if it was rejected instead of being added to the event queue. Fix by copying the event at a point when it's certainly added to the event queue. The dup_event_data() function is merely moved.
* player: update cache state only if requestedwm42014-08-281-1/+37
| | | | | | | | | Add a mechanism to the client API code, which allows the player core to query whether a client API event is needed at all. Use it for the cache update. In this case, this is probably a pure microoptimization; but the mechanism will be useful for other things too.
*