Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from builtin video sink to qmlglsink #8093

Closed
wants to merge 19 commits into from

Conversation

andrewvoznytsa
Copy link
Contributor

This patch switches QGC from using builtin video sink to qmlglsink (part of GStreamer Good Plug-ins).

This change is part of my work to lower QGC maintenance efforts and to implement standalone test app for video receiver.

Code was tested on Linux (Ubuntu 18.04/Qt 12.6/Gstreamer 1.14.5/qmlglsink - git/master, local build).

Next few days I'll be testing this code on all QGC platforms. So please expect updates (at least for platforms which require static gst linking). Right now it is more like early preview for Linux users - I'd like to hear comments and tweak some parts if there are good reasons.

Copy link
Contributor

@tcanabrava tcanabrava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are overstepping eachother - there's two patches already opened that do the same thing.

@andrewvoznytsa
Copy link
Contributor Author

In some context - yes.

I'd not do so and save my time but unfortunately - I can't. My problem is that your patch changes some places that are not related to video sink replacement (like noticeable .qml changes), disables/does not implement existing major features (video stream watchdog for example) and keeps object hierarchy still over-complicated (VideoSurface for example - why would we need that with qmlglsink?). I'm trying to simplify VideoReceiver and keep all existing features working as before.

Right now I'm trying to make it working on all QGC platforms and looking to start working on standalone test tool for VideoReceiver - that's annoying to see many video issues and have no instrument for quick automated testing.

As for me it looks like that my patch is much closer to release candidate than yours. I propose to use it as basis for qmlglsink integration. If you see any problems with my code - let me know and I'll fix ASAP.

@tcanabrava
Copy link
Contributor

tcanabrava commented Dec 9, 2019

I don't mind working in a feature together with others, please don't think I'm complaining. My idea with my patch series is not just to remove the QtGstreamer code but also so simplify the whole architecture. You can see for instance that I managed to get multiple video streams working with it while the original architecture for video in QGC makes this quite difficult.

The VideoSurface is an abomination that I created to be able to start / stop the video streams in the Qml rendering thread, as I was not having videos with a pipeline started outside of it. It's probably something uneeded and that I could rewrite in a better way, I just need to found out how. And checking your code you have done the same thing (with the difference that you created a class that extends QRunnable and a schedule render job)

On your side, you used the example code for the qmlsink that uses "objectName" on the Qml - that's one thing that I did not want to do on my code as it's quite unusual for Qml objects to have a name, and feels wrong.

I'm not really familiar with GStreamer - I can see that you know your way around it.

@andrewvoznytsa
Copy link
Contributor Author

Yes, I see your multiple video streams feature and I think that it is something that maintainers would adopt. From your past communications with them it sounds like they prefer smooth transition from existing code to full featured multiple view support (i.e. small step increments keeping QGC not worse than it was before). I think I'm finishing one of these small steps (qmlglsink support) and probably it is where multiple video stream support can start from.

Regarding object names - I agree. Adding extra field is not very nice solution. But since it requires two extra lines only I think that it is not so bad for current stage. If you see some nice way to workaround this requirement then drop me a message (you can email me directly) and I'll be happy to add it to my patch.

@tcanabrava
Copy link
Contributor

I just did a revamp of the "qmlglsink" also changing a few bits, I would really appreciate a review from somebody that knows more of GStreamer than I do. Even if we ship your version instead of mine first - as mine deals with more changes in the code architecture.

I believe I can transform the VideoSurface code into the VideoReceiver (the only difference is that I would need to remove the VideoReceiver from the VideoManager, and initialize it directly in Qml for the threading issue I commented about) - would will also make things better: VideoManager is bloated and tries to manage things outside of it's scope, so getting rid of it seems a plus.

#8071

About the "objectName" - it does not only changes two lines in code, you also need to get the rootWindow() and walk thru the object hierarchy to find the ones you are looking for (mostly making impossible to transform the video code in a single app for testing purposes) - that can be problematic if two QObjects have the same name.

@andrewvoznytsa
Copy link
Contributor Author

I'll look on objectName after finishing with non-Linux supports - qmlglsink is not as smooth as it looks on first sight.

@andrewvoznytsa
Copy link
Contributor Author

andrewvoznytsa commented Dec 12, 2019

Latest changes to this PR are adding prebuilt and statically linked qmlglsink to the QGC. It makes QGC working* on Linux, Windows**, macOS, iOS and Android. NOTE that QGC tries to use qmlglsink installed on your system. If qmlglsink is not present - app will fallback to statically linked qmlglsink and will use it.

*working - I mean good enough for development use. QGC still misses a few small fixes here and there. One of them - after initial app setup and first time video streaming configuring you need to restart app to make streaming working. It should be trivial to fix and I'll do that shortly. iOS build sometimes crashes during startup. I'm not sure that it is related to qmlglsink. But I'm also not sure that it is not related to that.

**Windows - qmlglsink depends on Open GL which was never simple to use on Windows. There is some long lasting bug related to multiple video sink support (see https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/issues/477#note_361958). You need to disable #if at libs/gst-plugins-good/ext/qt/gstqtglutility.cc@224 if you experience issues with video on Windows. I'll continue working on this issue and fix it.

9e0eb77 flvmux: Use the last DTS for the metadata timestamp

git-subtree-dir: libs/gst-plugins-good
git-subtree-split: 9e0eb7781076441c9704d2383708e49399e7da9d
…as not created because videoBackgroundComponent was not loaded on startup if video was disabled
@andrewvoznytsa
Copy link
Contributor Author

andrewvoznytsa commented Dec 13, 2019

Fixed video initialization on first startup. I'd ask someone with deep QGC/QML understanding to look on that fix (see andrewvoznytsa@886c968) - basically videoBackgroundComponent has the same life cycle as thermalItem and there should be no any problems. I had to do that to keep qmlglsink initialization simple, in single place on startup.

Fixed qmlglsink multiple instances support on Windows. PR sent to upstream (see https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/merge_requests/432) and is under review. I'll continue working on that until it will be fully accepted.

From now I expect that this patch makes QGC not worse (from features point of view) than it was before qmlglsink switch and it is in good shape to be considered for merge.

Future plans - I plant to remove objectName dependecy as @tcanabrava suggested. It will make video receiver easier to use in different use cases, including multiple video stream support. Also I'll try to improve videoBackgroundComponent initialization and make it on demand, to better manage resources, probably improve startup time and make things right. But it all depends on my other work related to VideoReceiver improvements. I expect to refactor VideoReceiver a bit (and probably VideoManager). And I think that these objectName and intializations improvements will land into repo as separate PRs, during future work.

@tcanabrava
Copy link
Contributor

Andrew, I'm trying to follow the commits but it's quite hard with the way you use git, can you perhaps clear the commits and use git rebase? The current state of the commits is not really easy to follow.

@andrewvoznytsa
Copy link
Contributor Author

One of private 'quick' commits escaped to public repo some time ago and rebasing is not trivial at this point :( Will see what can I do after fixing CI issues.

@jaxxzer
Copy link
Collaborator

jaxxzer commented Dec 16, 2019

I expect to refactor VideoReceiver a bit (and probably VideoManager).

Hi @andrewvoznytsa. Please consider coordinating with our efforts to refactor the video code by elaborating your plans and ideas at #7842.

@andrewvoznytsa
Copy link
Contributor Author

Hi @jaxxzer - sure, before starting to work on next massive update I'll post details at #7842. Basically I'm working according to your list, +-.

@rollysing
Copy link

@rollysing would it be possible to install WinDBG https://docs.microsoft.com/ru-ru/windows-hardware/drivers/debugger/debugger-download-tools, run QGC and do a few simple steps to get us back trace (I'll describe steps if WinDBG is something that you can do)?

I've downloaded the app. Please provide me step-by-step on what to do and will get it done as soon as I could.

@DonLakeFlyer
Copy link
Contributor

DonLakeFlyer commented Feb 6, 2020

FYI: Windows builds installed using the standard installer already set windows up to capture crash mini dumps. The docs here: https://docs.qgroundcontrol.com/en/Support/Support.html explain where the dump files are stored. You can then load these in visual studio debugger and get a stack track of where the crash is. If you need a full dump (which allows you to inspect memory variables and so forth) you'll need to tweak the crash dumpr registry setting to switch from mini to full dump.

@andrewvoznytsa andrewvoznytsa deleted the PR-qmlglsink branch February 7, 2020 19:49
@andrewvoznytsa
Copy link
Contributor Author

@rollysing could you please do what @DonLakeFlyer suggest in #8093 (comment) ? I was not aware of that. Please send me these dump files (*.dmp) and I'll check them here. If we don't get enough information then we'll continue with WinDBG. To find dumps - please look for 'Reporting Crashes from Windows Builds' on https://docs.qgroundcontrol.com/en/Support/Support.html page.

@DonLakeFlyer
Copy link
Contributor

If we don't get enough information then we'll continue with WinDBG.

With a dump file you'll get way more than what you could get remotely getting rolly to follow steps. If a mini-dump doesn't get you enough information. You can ask rolly to futz the registry to get a full dump. A full dump will get you the same thing as if you had captured the crash in the debugger on your own machine. Move around the stack, examine variable and so forth.

@DonLakeFlyer
Copy link
Contributor

The Windows installer write the following reg keys:

  WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpCount" 5 
  WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpType" 1
  WriteRegExpandStr HKLM "SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\${EXENAME}.exe" "DumpFolder" "%LOCALAPPDATA%\QGCCrashDumps"

If you change DumpType in the registry to 2 you get a full dump. Start with a mini which is default though since full dumps are huge.

@rollysing
Copy link

@andrewvoznytsa Sorry. I've been out of town. Here are the crash dumps of a 02/20/2020 Daily Build. It opened up fine after initial installation. The moment I changed the video option to H.264, it crashed.
https://1drv.ms/u/s!Ar66Lk6yrxscgyTSNd6KuslMDDNT?e=Ct4pmx

Hope this helps. Let me know if there's anything you want me to do.

Thanks.

@andrewvoznytsa
Copy link
Contributor Author

andrewvoznytsa commented Feb 10, 2020

Thanks for update @rollysing ! That moment, related to video codec change, was probably fixed and merged into master. If you get Daily build dated later than this comment then you can expect that there is no crash anymore (I hope very much). Could you please check? In the mean time I'll look on crash dump.

@rollysing
Copy link

@andrewvoznytsa The crash dumps I referenced are from a Daily Build I just downloaded and installed 2 hours ago. So the merge is still crashing once I opted to enable the video option.

@andrewvoznytsa
Copy link
Contributor Author

andrewvoznytsa commented Feb 11, 2020

image

It crashes somewhere inside g_slice_alloc() (malloc() equivalent, part of glib which is part of gstreamer). Everything was built without debug info - that's piece of work to rebuild all things with debug info to get something more useful than what I've found (manual stack walking is possible of course, but IMO it has no sense in our case).

In all 3 cases it crashed exactly in the same place.

If we want to save time then local debugging via Teamviewer can help.

@rollysing
Copy link

@andrewvoznytsa I'm UTC -05:00 US Eastern Time. Let me know when you'd be available and I'll have it setup and available for you to remote in.

Thanks.

@andrewvoznytsa
Copy link
Contributor Author

@rollysing I'll prepare for this test and let you know (if we do this immediately I'll need to setup all dev tools which I usually use - this does not sound for me as right path to ask you install all these things - will need to see how can I debug that with minimal debug tool set and quickly).

In the mean time, we can continue our lottery. I just pushed #8318 which sounds close to what you were reporting. I've doubts that it is also your issue but we can try - it sounds close. I expect that it will be merged shortly and you can try that tomorrow.

@DonLakeFlyer
Copy link
Contributor

A full dump instead of a mini-dump won't provide you enough information? That is about the same as getting it in the debugger yourself.

@andrewvoznytsa
Copy link
Contributor Author

andrewvoznytsa commented Feb 12, 2020 via email

@andrewvoznytsa
Copy link
Contributor Author

andrewvoznytsa commented Feb 26, 2020

@rollysing here is debug build for you - https://drive.google.com/open?id=1eGWe-X6fv7n5fW_elpA13on-GqUEClfM

It is latest master built in debug mode with symbols.

You'll need to unpack that to C:\. After all you'll have C:\lenovo folder with build-qgroundcontrol-Desktop_Qt_5_12_6_MSVC2017_64bit-Debug and qgroundcontrol subfolders. This is large stuff - uses about 2 Gb.

As first step we can try naive approach - let's run c:\lenovo\build-qgroundcontrol-Desktop_Qt_5_12_6_MSVC2017_64bit-Debug\debug\QGroundControl.exe and try to catch dump. Then send it to me - hopefully I'll be able to find all info there.

If no - we'll need to continue with teamviewer.

I'm here for next 4-6 hours - should be enough to fix that. If you are busy today - we can continue any other day.

@rollysing
Copy link

Getting this error almost immediately after starting installation:
image

@dogmaphobic
Copy link
Contributor

Debug builds only run on a system with all the debug DLLs loaded.

@andrewvoznytsa
Copy link
Contributor Author

Sigh. I'll prepare better build - will setup clean VM, collect all required DLLs and post it here.

@andrewvoznytsa
Copy link
Contributor Author

andrewvoznytsa commented Feb 27, 2020

@rollysing please find missing dll there https://drive.google.com/open?id=1AQYHg3CX7rIj7V-RJpNmkHPM-4riyHUG
You need to unpack it into c:\lenovo\build-qgroundcontrol-Desktop_Qt_5_12_6_MSVC2017_64bit-Debug\debug, next to QGroundControl.exe
Then it should work - at least worked for me on fresh Windows system.

Next step would be to run WinDBG for AMD64
Windows 10 x64-2020-02-27-20-59-52
Then open open executable QGroundControl.exe like there
Windows 10 x64-2020-02-27-21-00-24
After that you'll see something like to this screen
Windows 10 x64-2020-02-27-21-00-44
This is time to run app pressing F5 and get to next point
Windows 10 x64-2020-02-27-21-01-29
That screen tells us that app crashed so we need to look at call stack (Alt+6)
Windows 10 x64-2020-02-27-21-01-52
Finally we see call stack and can examine what was wrong. So I'm double clicking on the most reasonable line (first QGroundControl entry) and looking for code which caused that crash
Windows 10 x64-2020-02-27-21-02-07
and it tells me obvious thing - someone like me modified _pipeline pointer to point to the middle of nowhere to simulate crash, to be able to write that short guide and verify everything.

Now it is your turn :)

If this looks like alien technology - give me please teamviewer access and I'll debug it myself (perhaps we can use @DonLakeFlyer as man in the middle to send login details or other contact information).

@DonLakeFlyer
Copy link
Contributor

Don't see why crash dump file isn't the simplest way to go where. With a full crash dump for example you get everything you could do with WinDbg. See the stack trace at crash, move around the stack, look at variables/memory at each point in the stack, link to the source.

@andrewvoznytsa
Copy link
Contributor Author

@rollysing you can simply send crash dump after unpacking that missing dll if that is easier for you - did not wanted to throw all that WinDbg stuff on your head - it just looked safer for me to get needed crash information via WinDbg and finally fix that issue. We can always return to WinDbg if I'll be unable to find required debug info from crash dump because of some unforeseen problem (most likely everything will be good this time).

@DonLakeFlyer
Copy link
Contributor

By default the QGC Windows installer will set up the registry to collect mini dumps. That is the way to start. If from that you don't get enough information you can switch to full dumps (they are huge).

I uploaded some reg files to S3 which will switch between the QGC default and full dumps:

@rollysing
Copy link

@andrewvoznytsa @DonLakeFlyer Good news! That QGC didn't crash! More importantly, I'm able to open a video overlay and the USB VTx is showing it! There's no crash dump to send so is there a log in this that you want? So, the next step is to incorporate what you have here into the stable version?Let me know.

Thanks.

@andrewvoznytsa
Copy link
Contributor Author

@rollysing don't know if I should be happy or worried even more - let's try latest 4.0 daily build on your side and see if video is still working for you.

There are possible two kind of problems:

  1. there is some difference in debug and release builds (what works for you was debug build) - it will be hard to fix (actually just time consuming and this is what worries me)
  2. one of latest changes fixed that issue on your side - in this case we'll live with current code until you see this bug again. If we reproduce it once more we'll have to do binary search between commits that is known to work and this which is crashing to find change that fixes it.

@rollysing
Copy link

@andrewvoznytsa Good news! I just downloaded the daily build and it installed with no problem, opens and am able to have the USB 2.0 Camera show on the overlay.

@andrewvoznytsa
Copy link
Contributor Author

andrewvoznytsa commented Mar 3, 2020

@rollysing Perfect! Please let me know ASAP when I'll break that :)

BTW, did you update something on your system recently? Perhaps older builds work too?

@rollysing
Copy link

rollysing commented Mar 3, 2020

@andrewvoznytsa Good news again! Installed stable 4.0 and it's working! So it looks like she's good from this stable version and on. Next step would be a field test to see how she does. One thing, though, when the USB connection of the PC camera is interrupted and comes back online, the view doesn't come back unless QGC is closed and restarted.

Any updates would've been the usual Windows patch Tuesday stuff. So if there's anything from the past ones that you think might have contributed to this success would be it.

In the meantime, will report back (don't know when) on the field test. Thank you very much for all the patience and assistance.

@andrewvoznytsa
Copy link
Contributor Author

@rollysing Good luck with your field test!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants