I have very simple code that loads libvlc at runtime and plays an mp4 file:
Code: Select all
void* load_fn(char* func) {
void *res=dlsym(vlc_lib, func);
if (!res) exit(1);
return res;
}
int main() {
char* path = "/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib"; // libvlc.dll on Windows
vlc_lib = dlopen(path, RTLD_LAZY);
if (!vlc_lib) {
printf("dl not loaded: %s\n", path);
exit(1);
}
_libvlc_new=load_fn("libvlc_new");
_libvlc_media_new_location=load_fn("libvlc_media_new_location");
// a couple of other necessary functions are loaded
// .....
vlc = _libvlc_new(0, 0);
libvlc_media_t *m = _libvlc_media_new_path (vlc, "video.mp4");
mp = _libvlc_media_player_new_from_media (m);
_libvlc_media_release (m);
_libvlc_media_player_set_nsobject (mp, ns_video_view); // on Windows I call set_hwnd()
_libvlc_media_player_play (mp);
}
On Windows it works like a charm. But on macOS I get a crash in libvlc_media_player_new_from_media:
Code: Select all
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x28)
frame #0: 0x000000010d610a7d libvlccore.dylib`config_GetPsz + 61
libvlccore.dylib`config_GetPsz:
-> 0x10d610a7d <+61>: mov rdi, qword ptr [rbx + 0x28]
0x10d610a81 <+65>: test rdi, rdi
0x10d610a84 <+68>: je 0x10d610a90 ; <+80>
0x10d610a86 <+70>: call 0x10d6998a8 ; symbol stub for: strdup
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x28)
* frame #0: 0x000000010d610a7d libvlccore.dylib`config_GetPsz + 61
frame #1: 0x000000010d67d3c7 libvlccore.dylib`var_Inherit + 247
frame #2: 0x000000010d67d232 libvlccore.dylib`var_Create + 354
frame #3: 0x000000010d4d727c libvlc.dylib`libvlc_media_player_new + 316
frame #4: 0x000000010d4d7be0 libvlc.dylib`libvlc_media_player_new_from_media + 16
I had to modify the library file because of macOS @rpath shenanigans:
Code: Select all
install_name_tool -change @rpath/libvlccore.dylib /Applications/VLC.app/Contents/MacOS/lib/libvlccore.dylib /Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib
Does any one have experience with linking to libvlc.dylib?
Thanks a lot