Page 1 of 1

LuaJIT and libvlc_audio/video_set_callbacks crashing

Posted: 05 May 2014 17:28
by CapsAdmin
LuaJIT 2.1 and LuaJIT 2.0.3 keeps crashing when trying to use the libvlc_audio/video_set_callbacks callbacks from LuaJIT. I also crash sometimes when trying to use the log callback without calling libvlc_media_player_play(media_player).

I've tested this on latest stable and latest nightly. (32bit)

I have a feeling my Lua state and VLC's Lua state are crashing. In my Lua framework (which is kind of big) I sometimes (but rarely) get absurd Lua errors just before exit.

Here's a log from when running my test script from CMD a few times:

Code: Select all

C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [02f0092c] logger interface: VLC media player - 2.1.3 Rincewind [02f0092c] logger interface: Copyright c 1996-2014 the VideoLAN team [02f0092c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [02f0092c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00dd042c] logger interface: VLC media player - 2.1.3 Rincewind [00dd042c] logger interface: Copyright c 1996-2014 the VideoLAN team [00dd042c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00dd042c] logger interface: using logger. PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [029a07ac] logger interface: VLC media player - 2.1.3 Rincewind [029a07ac] logger interface: Copyright c 1996-2014 the VideoLAN team [029a07ac] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [029a07ac] logger interface: using logger. PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00e0092c] logger interface: VLC media player - 2.1.3 Rincewind [00e0092c] logger interface: Copyright c 1996-2014 the VideoLAN team [00e0092c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00e0092c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [02d9062c] logger interface: VLC media player - 2.1.3 Rincewind [02d9062c] logger interface: Copyright c 1996-2014 the VideoLAN team [02d9062c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [02d9062c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [01410eac] logger interface: VLC media player - 2.1.3 Rincewind [01410eac] logger interface: Copyright c 1996-2014 the VideoLAN team [01410eac] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [01410eac] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00650dac] logger interface: VLC media player - 2.1.3 Rincewind [00650dac] logger interface: Copyright c 1996-2014 the VideoLAN team [00650dac] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00650dac] logger interface: using logger. PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [0129032c] logger interface: VLC media player - 2.1.3 Rincewind [0129032c] logger interface: Copyright c 1996-2014 the VideoLAN team [0129032c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [0129032c] logger interface: using logger. PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [02b3042c] logger interface: VLC media player - 2.1.3 Rincewind [02b3042c] logger interface: Copyright c 1996-2014 the VideoLAN team [02b3042c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [02b3042c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [029a0b2c] logger interface: VLC media player - 2.1.3 Rincewind [029a0b2c] logger interface: Copyright c 1996-2014 the VideoLAN team [029a0b2c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [029a0b2c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00cf0b2c] logger interface: VLC media player - 2.1.3 Rincewind [00cf0b2c] logger interface: Copyright c 1996-2014 the VideoLAN team [00cf0b2c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00cf0b2c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00720b2c] logger interface: VLC media player - 2.1.3 Rincewind [00720b2c] logger interface: Copyright c 1996-2014 the VideoLAN team [00720b2c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00720b2c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00520b2c] logger interface: VLC media player - 2.1.3 Rincewind [00520b2c] logger interface: Copyright c 1996-2014 the VideoLAN team [00520b2c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00520b2c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [008f0d2c] logger interface: VLC media player - 2.1.3 Rincewind [008f0d2c] logger interface: Copyright c 1996-2014 the VideoLAN team [008f0d2c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [008f0d2c] logger interface: using logger. PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00ea072c] logger interface: VLC media player - 2.1.3 Rincewind [00ea072c] logger interface: Copyright c 1996-2014 the VideoLAN team [00ea072c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00ea072c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00d804ac] logger interface: VLC media player - 2.1.3 Rincewind [00d804ac] logger interface: Copyright c 1996-2014 the VideoLAN team [00d804ac] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00d804ac] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [02410a2c] logger interface: VLC media player - 2.1.3 Rincewind [02410a2c] logger interface: Copyright c 1996-2014 the VideoLAN team [02410a2c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [02410a2c] logger interface: using logger. PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00ba0a2c] logger interface: VLC media player - 2.1.3 Rincewind [00ba0a2c] logger interface: Copyright c 1996-2014 the VideoLAN team [00ba0a2c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00ba0a2c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00a70d2c] logger interface: VLC media player - 2.1.3 Rincewind [00a70d2c] logger interface: Copyright c 1996-2014 the VideoLAN team [00a70d2c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00a70d2c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [02f4102c] logger interface: VLC media player - 2.1.3 Rincewind [02f4102c] logger interface: Copyright c 1996-2014 the VideoLAN team [02f4102c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [02f4102c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00890aac] logger interface: VLC media player - 2.1.3 Rincewind [00890aac] logger interface: Copyright c 1996-2014 the VideoLAN team [00890aac] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00890aac] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00cf10ac] logger interface: VLC media player - 2.1.3 Rincewind [00cf10ac] logger interface: Copyright c 1996-2014 the VideoLAN team [00cf10ac] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00cf10ac] logger interface: using logger. PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>luajit vlc_test.lua [00d2112c] logger interface: VLC media player - 2.1.3 Rincewind [00d2112c] logger interface: Copyright c 1996-2014 the VideoLAN team [00d2112c] logger interface: Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt" [00d2112c] logger interface: using logger. 2.1.3 Rincewind gcc version 4.8.2 (GCC) 2.1.3-0-ge6a71cc PANIC: unprotected error in call to Lua API (bad callback) C:\Program Files (x86)\VideoLAN\VLC>
Here's relevant code:

Code: Select all

local options = { "-Idummy", "--ignore-config", "--extraintf=logger", "--verbose=4", } ffi.cdef[[int _putenv_s(const char *var_name, const char *new_value)]] ffi.C._putenv_s("VLC_PLUGIN_PATH", "./plugins") -- is there an options field for this? local argv = ffi.new("const char*["..#options.."]", options) local instance = vlc.new(#options-1, argv) if instance == nil then print("failed to initialize vlc") return end print(ffi.string(vlc.get_version())) print(ffi.string(vlc.get_compiler())) print(ffi.string(vlc.get_changeset())) if false then -- crashes randomly ffi.cdef[[int _vsnprintf(char *buffer, size_t count, const char *format, va_list args);]] vlc.set_log_verbosity(instance, 10) vlc.log_set(instance, function(data, level, ctx, fmt, args) local buffer = ffi.new("char[1024]") ffi.C._vsnprintf(buffer, 1024, fmt, args) local str = ffi.string(buffer) print("[vlc] ", str) end, nil) end local path = ("C:/goluwa/tests/videos/casiopea.webm"):gsub("/", "\\") -- vlc doesn't replace forward with backward slashes on windows local media = vlc.media_new_path(instance, path) if media == nil then print("failed to open file " .. path) return end local media_player = vlc.media_player_new_from_media(media) vlc.media_release(media) if true then vlc.audio_set_format(media_player, "S16N", 44100, 2) vlc.audio_set_callbacks( media_player, function(data, samples, count, pts) print("play ", data, samples, count, pts) end, function(data, pts) print("pause ", data, pts) end, function(data, pts) print("resume ", data, pts) end, function(data, pts) print("flush ", data, pts) end, function(data) print("drain ", data) end, nil ) end if true then vlc.video_set_format(media_player, "RV16", 512, 512, 512*2) vlc.video_set_callbacks( media_player, function(udata, planes) print("lock", planes) end, function(udata, id, pixels) print("upload", id, pixels) end, function(id) print("display", id) end, nil ) end vlc.media_player_play(media_player) while true do end -- keep the state alive
full code is here https://gist.github.com/CapsAdmin/aba53fe3b1871541baae

Other concerns:
  • I could not use "sprintf" on the log callback's va_list. I had to use _vsnprintf instead or else the buffer output would end up with random characters where the % symbols were.. (LuaJIT does not support "..." in callbacks properly so that's why you have to do that) In other libraries such as ffmpeg which also has a log callback printf works fine. As I'm typing this maybe it's because ffmpeg was compiled with mingw and vlc wasnt?
  • libvlc_media_new_path() does not convert forward slashes to backward slashes, is this intentional? for a while it had me confused as to why my file didn't exist.

Re: LuaJIT and libvlc_audio/video_set_callbacks crashing

Posted: 15 May 2014 17:20
by CapsAdmin
It turned out this was a luajit issue.

http://www.freelists.org/post/luajit/li ... s-crashing

Re: LuaJIT and libvlc_audio/video_set_callbacks crashing

Posted: 16 May 2014 04:41
by RĂ©mi Denis-Courmont
Last I checked, Lua did not support threading. Yet VLC callbacks are invoked from different threads and asynchronously.

So I think you need native glue code in any case.