PDA

View Full Version : Render LibVLC video into QWidget on Android



mentalmushroom
13th June 2016, 07:37
I have been trying to create a simple Qt-based Android application to play video files using LibVLC. It partially works: files are opened and played, I can hear the sound, but no video is displayed.

I tried it different ways:

libvlc_media_player_set_xwindow(player, widget->winId())
Simply does nothing.


libvlc_media_player_set_hwnd(player, (void*)widget->winId())
Seems to work only on Windows OS.


libvlc_media_player_set_android_context(player, (void*)widget->winId())
Crashes with the following:


E art : JNI ERROR (app bug): attempt to use stale weak global reference 0x3 (should be 0x100003)
F art : art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: use of deleted weak global reference 0x3
F art : art/runtime/java_vm_ext.cc:410] "AWindowHandler" prio=5 tid=16 Runnable
F art : art/runtime/java_vm_ext.cc:410] | group="main" sCount=0 dsCount=0 obj=0x1326a0a0 self=0x9d7cfc00
F art : art/runtime/java_vm_ext.cc:410] | sysTid=16347 nice=0 cgrp=default sched=0/0 handle=0x97cc1930
F art : art/runtime/java_vm_ext.cc:410] | state=R schedstat=( 1138230 0 1 ) utm=0 stm=0 core=0 HZ=100
F art : art/runtime/java_vm_ext.cc:410] | stack=0x97bc5000-0x97bc7000 stackSize=1014KB
F art : art/runtime/java_vm_ext.cc:410] | held mutexes= "mutator lock"(shared held)
F art : art/runtime/java_vm_ext.cc:410] native: #00 pc 00371839 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::ArtMethod*, void*)+160)
F art : art/runtime/java_vm_ext.cc:410] native: #01 pc 00350ea7 /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+150)
F art : art/runtime/java_vm_ext.cc:410] native: #02 pc 0025a8a5 /system/lib/libart.so (art::JavaVMExt::JniAbort(char const*, char const*)+740)
F art : art/runtime/java_vm_ext.cc:410] native: #03 pc 0025affb /system/lib/libart.so (art::JavaVMExt::JniAbortF(char const*, char const*, ...)+74)
F art : art/runtime/java_vm_ext.cc:410] native: #04 pc 00351c69 /system/lib/libart.so (art::Thread::DecodeJObject(_jobject*) const+708)
F art : art/runtime/java_vm_ext.cc:410] native: #05 pc 001013c1 /system/lib/libart.so (art::ScopedCheck::Check(art::ScopedObjectAccess&, bool, char const*, art::JniValueType*) (.constprop.95)+908)
F art : art/runtime/java_vm_ext.cc:410] native: #06 pc 00108f6f /system/lib/libart.so (art::CheckJNI::GetObjectClass(_JNIEnv*, _jobject*)+386)
F art : art/runtime/java_vm_ext.cc:410] native: #07 pc 001fb3c5 /data/app/org.qtproject.example.testvlc-1/lib/arm/libvlc.so (???)
F art : art/runtime/java_vm_ext.cc:410] (no managed stack frames)
F art : art/runtime/java_vm_ext.cc:410]
F art : art/runtime/runtime.cc:370] Runtime aborting...
F art : art/runtime/runtime.cc:370] Aborting thread:
F art : art/runtime/runtime.cc:370] "AWindowHandler" prio=5 tid=16 Native
F art : art/runtime/runtime.cc:370] | group="" sCount=0 dsCount=0 obj=0x1326a0a0 self=0x9d7cfc00
F art : art/runtime/runtime.cc:370] | sysTid=16347 nice=0 cgrp=default sched=0/0 handle=0x97cc1930
F art : art/runtime/runtime.cc:370] | state=R schedstat=( 23070571 3691459 17 ) utm=1 stm=1 core=3 HZ=100
F art : art/runtime/runtime.cc:370] | stack=0x97bc5000-0x97bc7000 stackSize=1014KB
F art : art/runtime/runtime.cc:370] | held mutexes= "abort lock"
F art : art/runtime/runtime.cc:370] native: #00 pc 00371839 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::ArtMethod*, void*)+160)
F art : art/runtime/runtime.cc:370] native: #01 pc 00350ea7 /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+150)
F art : art/runtime/runtime.cc:370] native: #02 pc 00333ad7 /system/lib/libart.so (art::AbortState::DumpThread(std::__1::basic_ostre am<char, std::__1::char_traits<char> >&, art::Thread*) const+26)
F art : art/runtime/runtime.cc:370] native: #03 pc 00333d6f /system/lib/libart.so (art::Runtime::Abort()+562)
F art : art/runtime/runtime.cc:370] native: #04 pc 000f471b /system/lib/libart.so (art::LogMessage::~LogMessage()+2226)
F art : art/runtime/runtime.cc:370] native: #05 pc 0025abcf /system/lib/libart.so (art::JavaVMExt::JniAbort(char const*, char const*)+1550)
F art : art/runtime/runtime.cc:370] native: #06 pc 0025affb /system/lib/libart.so (art::JavaVMExt::JniAbortF(char const*, char const*, ...)+74)
F art : art/runtime/runtime.cc:370] native: #07 pc 00351c69 /system/lib/libart.so (art::Thread::DecodeJObject(_jobject*) const+708)
F art : art/runtime/runtime.cc:370] native: #08 pc 001013c1 /system/lib/libart.so (art::ScopedCheck::Check(art::ScopedObjectAccess&, bool, char const*, art::JniValueType*) (.constprop.95)+908)
F art : art/runtime/runtime.cc:370] native: #09 pc 00108f6f /system/lib/libart.so (art::CheckJNI::GetObjectClass(_JNIEnv*, _jobject*)+386)
F art : art/runtime/runtime.cc:370] native: #10 pc 001fb3c5 /data/app/org.qtproject.example.testvlc-1/lib/arm/libvlc.so (???)
F art : art/runtime/runtime.cc:370] (no managed stack frames)
F art : art/runtime/runtime.cc:370] Dumping all threads without appropriate locks held: thread list lock mutator lock
F art : art/runtime/runtime.cc:370] All threads:
F art : art/runtime/runtime.cc:370] DALVIK THREADS (16):
F art : art/runtime/runtime.cc:370] "AWindowHandler" prio=5 tid=16 Runnable
F art : art/runtime/runtime.cc:370] | group="" sCount=0 dsCount=0 obj=0x1326a0a0 self=0x9d7cfc00
F art : art/runtime/runtime.cc:370] | sysTid=16347 nice=0 cgrp=default sched=0/0 handle=0x97cc1930
F art : art/runtime/runtime.cc:370] | state=R schedstat=( 46021872 5266408 44 ) utm=1 stm=3 core=3 HZ=100
F art : art/runtime/runtime.cc:370] | stack=0x97bc5000-0x97bc7000 stackSize=1014KB
F art : art/runtime/runtime.cc:370] | held mutexes= "abort lock" "mutator lock"(shared held)
F art : art/runtime/runtime.cc:370] native: #00 pc 00371839 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::ArtMethod*, void*)+160)
F art : art/runtime/runtime.cc:370] native: #01 pc 00350ea7 /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+150)
F art : art/runtime/runtime.cc:370] native: #02 pc 0035adab /system/lib/libart.so (art::DumpCheckpoint::Run(art::Thread*)+442)
F art : art/runtime/runtime.cc:370] native: #03 pc 0035b969 /system/lib/libart.so (art::ThreadList::RunCheckpoint(art::Closure*)+212 )
F art : art/runtime/runtime.cc:370] native: #04 pc 0035be97 /system/lib/libart.so (art::ThreadList::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)+142)
F art : art/runtime/runtime.cc:370] native: #05 pc 00333ce5 /system/lib/libart.so (art::Runtime::Abort()+424)
F art : art/runtime/runtime.cc:370] native: #06 pc 000f471b /system/lib/libart.so (art::LogMessage::~LogMessage()+2226)
F art : art/runtime/runtime.cc:370] native: #07 pc 0025abcf /system/lib/libart.so (art::JavaVMExt::JniAbort(char const*, char const*)+1550)
F art : art/runtime/runtime.cc:370] native: #08 pc 0025affb /system/lib/libart.so (art::JavaVMExt::JniAbortF(char const*, char const*, ...)+74)
F art : art/runtime/runtime.cc:370] native: #09 pc 00351c69 /system/lib/libart.so (art::Thread::DecodeJObject(_jobject*) const+708)
F art : art/runtime/runtime.cc:370] native: #10 pc 001013c1 /system/lib/libart.so (art::ScopedCheck::Check(art::ScopedObjectAccess&, bool, char const*, art::JniValueType*) (.constprop.95)+908)
F art : art/runtime/runtime.cc:370] native: #11 pc 00108f6f /system/lib/libart.so (art::CheckJNI::GetObjectClass(_JNIEnv*, _jobject*)+386)
F art : art/runtime/runtime.cc:370] native: #12 pc 001fb3c5 /data/app/org.qtproject.example.testvlc-1/lib/arm/libvlc.so (???)
F art : art/runtime/runtime.cc:370] (no managed stack frames)
F art : art/runtime/runtime.cc:370]
...
F libc : Fatal signal 6 (SIGABRT), code -6 in tid 16347 (AWindowHandler)


I guess, that is because it expects some Java window.

Does anybody know how to set up video output using Qt Widget?

anda_skoa
13th June 2016, 09:17
I have been trying to create a simple Qt-based Android application to play video files using LibVLC. It partially works: files are opened and played, I can hear the sound, but no video is displayed.

Have you tried using QtMultimedia instead and letting it handle the system integration?



I tried it different ways:

libvlc_media_player_set_xwindow(player, widget->winId())
Simply does nothing.

This is for an X Window, a window on an X11 system. Android does not run X11.




libvlc_media_player_set_hwnd(player, (void*)widget->winId())
Seems to work only on Windows OS.

Yes, as this is for a Windows window, a window on a Windows system. Android does not run Windows.




libvlc_media_player_set_android_context(player, (void*)widget->winId())

"android_context" might not be a window handle.
Have you had a look at the VLC code? As far as I know it uses Qt for its UI, so it should have code that calls this.



Does anybody know how to set up video output using Qt Widget?
QVideoWidget?

Cheers,
_

mentalmushroom
14th June 2016, 08:13
Have you tried using QtMultimedia instead and letting it handle the system integration?
I'll consider using QtMultimedia instead of LibVLC. For this sample it would be enough. But I have a quite big project based on VLC API and in future I'm planning to create the android version. At least I'm curious how to do that with Libvlc+Qt.


"android_context" might not be a window handle.
Yep, you are right. After digging into libvlc-android-demo code, I realized that it's an object of AWindowNativeHandler class. Unfortunately, it is in Java and the implementation relies on Surface/SurfaceView and SurfaceHolder classes, so I don't have any idea how to do that in C++/Qt.


Have you had a look at the VLC code? As far as I know it uses Qt for its UI, so it should have code that calls this.
VLC source is complicated, but it seems they use Qt only for desktop GUI.


QVideoWidget?
How do I pass it to libvlc?

anda_skoa
14th June 2016, 09:35
I'll consider using QtMultimedia instead of LibVLC. For this sample it would be enough. But I have a quite big project based on VLC API and in future I'm planning to create the android version. At least I'm curious how to do that with Libvlc+Qt.

I see, that's a different use case then than simply playing video files.



Yep, you are right. After digging into libvlc-android-demo code, I realized that it's an object of AWindowNativeHandler class. Unfortunately, it is in Java and the implementation relies on Surface/SurfaceView and SurfaceHolder classes, so I don't have any idea how to do that in C++/Qt.

Then you might have to provide the necessary adapters in Java.
Probably a good idea to look at the code of the Qt Android platform module to see how it deals with native surface types.



VLC source is complicated, but it seems they use Qt only for desktop GUI.

I see, I thought they were using it across platforms.

https://quality.kdab.com/browse/AVIBIT-703
How do I pass it to libvlc?[/QUOTE]
The Android backend is probably using something other than VLC.

Cheers,
_