Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3763,6 +3763,22 @@ Window
specially, and mpv will draw on top of the desktop wallpaper and below
desktop icons.

On macOS/Cocoa, the ID is interpreted as ``NSView*``. Pass it as value cast
to ``intptr_t``. mpv will create its own sub-view.
The following constraints apply:

- This is only supported with libmpv. Specifying a wid with mpv cli will
end with an error
- The supplied NSView pointer must be from the same process into which
libmpv is loaded. Since macOS does not support cross-process window
access, attempts trying to do so will always crash
- The process needs to have an NSApplication with event loop running
on the main thread
- The wid must be set after mpv_create() and before mpv_initialize()
and cannot be changed afterwards
- The only supported vo is libmpv, which will be automatically set when
a wid is provided

On Android, the ID is interpreted as ``android.view.Surface``. Pass it as a
value cast to ``intptr_t``. Use with ``--vo=mediacodec_embed`` and
``--hwdec=mediacodec`` for direct rendering using MediaCodec, or with
Expand Down
1 change: 1 addition & 0 deletions osdep/mac/app_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void cocoa_uninit_media_keys(void);
void cocoa_set_input_context(struct input_ctx *input_context);
void cocoa_set_mpv_handle(struct mpv_handle *ctx);
void cocoa_init_cocoa_cb(void);
void cocoa_init_embedded_view(int64_t wid);
// multithreaded wrapper for mpv_main
int cocoa_main(int argc, char *argv[]);

Expand Down
5 changes: 5 additions & 0 deletions osdep/mac/app_bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ void cocoa_init_cocoa_cb(void)
[[AppHub shared] initCocoaCb];
}

void cocoa_init_embedded_view(int64_t wid)
{
[[AppHub shared] initCocoaCbWithView:(__bridge NSView *)(void *)wid];
}

int cocoa_main(int argc, char *argv[])
{
return [(Application *)[Application sharedApplication] main:argc :argv];
Expand Down
15 changes: 14 additions & 1 deletion osdep/mac/app_hub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ class AppHub: NSObject {
}

@objc func initMpv(_ mpv: OpaquePointer) {

log.log = mp_log_new(nil, mp_client_get_log(mpv), "app")
log.verbose("AppHub: initMpv enter")

event = EventHelper(self, mpv)
if let mpv = event?.mpv {
self.mpv = mpv
log.log = mp_log_new(nil, mp_client_get_log(mpv), "app")
option = OptionHelper(UnsafeMutablePointer(mpv), mp_client_get_global(mpv))
input.option = option
DispatchQueue.main.sync { menu = MenuBar(self) }
Expand All @@ -76,6 +79,7 @@ class AppHub: NSObject {
}

@objc func initInput(_ input: OpaquePointer?) {
if !isApplication { return }
log.verbose("Initialising Input")
self.input.signal(input: input)
}
Expand All @@ -90,6 +94,15 @@ class AppHub: NSObject {
#endif
}

@objc func initCocoaCbWithView(_ view: NSView) {
#if HAVE_MACOS_COCOA_CB
log.verbose("Initialising CocoaCB (embedded view)")
DispatchQueue.main.sync {
self.cocoaCb = CocoaCB(mpv_create_client(mpv, "cocoacb"), view)
}
#endif
}

@objc func startRemote() {
#if HAVE_MACOS_MEDIA_PLAYER
log.verbose("Starting RemoteCommandCenter")
Expand Down
5 changes: 0 additions & 5 deletions osdep/mac/event_helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ class EventHelper {
var events: [String: [Int: EventSubscriber]] = [:]

init?(_ appHub: AppHub, _ mpv: OpaquePointer) {
if !appHub.isApplication {
mpv_destroy(mpv)
return nil
}

self.appHub = appHub
self.mpv = mpv
mpv_set_wakeup_callback(mpv, wakeup, TypeHelper.bridge(obj: self))
Expand Down
26 changes: 24 additions & 2 deletions player/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "common/codecs.h"
#include "common/encode.h"
#include "options/m_config.h"
#include "options/m_config_frontend.h"
#include "options/m_option.h"
#include "options/m_property.h"
#include "common/common.h"
Expand Down Expand Up @@ -366,6 +367,25 @@ int mp_initialize(struct MPContext *mpctx, char **options)
return r == M_OPT_EXIT ? 1 : -1;
}

#if HAVE_COCOA

if (mpctx->is_cli && opts->vo->WinID > 0)
{
MP_FATAL(mpctx, "On macOS, window embedding via 'wid' parameter is not supported from the CLI.\n");
return -1;
}

if (!mpctx->is_cli && opts->vo->WinID > 0)
{
MP_INFO(mpctx, "A 'wid' for window embedding is specified. Setting vo=libmpv, which is the only supported way on macOS.\n");

int r = m_config_set_option_cli(mpctx->mconfig, bstr0("vo"), bstr0("libmpv"), 0);
if (r < 0) {
MP_WARN(mpctx, "Failed to force vo=libmpv for wid embedding (err=%d)\n", r);
}
}
#endif

if (opts->operation_mode == 1) {
m_config_set_profile(mpctx->mconfig, "builtin-pseudo-gui",
M_SETOPT_NO_OVERWRITE);
Expand Down Expand Up @@ -410,8 +430,10 @@ int mp_initialize(struct MPContext *mpctx, char **options)
MP_STATS(mpctx, "start init");

#if HAVE_COCOA
mpv_handle *ctx = mp_new_client(mpctx->clients, "mac");
cocoa_set_mpv_handle(ctx);
if (mpctx->is_cli || opts->vo->WinID > 0) {
mpv_handle *ctx = mp_new_client(mpctx->clients, "mac");
cocoa_set_mpv_handle(ctx);
}
#endif

#if HAVE_WIN32_SMTC
Expand Down
Loading