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

Download Manager #40

Merged
merged 10 commits into from Apr 4, 2019
Merged

Download Manager #40

merged 10 commits into from Apr 4, 2019

Conversation

ChocolateFrogsNuts
Copy link
Contributor

Some bug fixes and a Download Manager to allow parallel background downloading of OSM tiles.
Really speeds up map display on high-latency connections (eg satellite internet)

Some minor bugfixes to prevent potential buffer overruns.

Use TransformImageColorspace on non-RGB OSM Tiles.
Changes for MagickLibVersion > 0x669
  GetImagePixels() -> GetAuthenticPixels()
  GetIndexes() -> GetAuthenticIndexQueue()
  SetImage() ->  SetImageBackgroundColor(), SetImageOpacity()
  DescribeImage() -> IdentifyImage()

Also newer versions of IM use double rather than int for certain colour values.
This required replacing <<8 with *256 in a number of places.
Also a cast to (int) in a few places.
The DownLoad Manager (DLM) will transfer up to 8 tiles at a time.
It can also be used as a generic file downloader.

OSM tiles are now downloaded to the cache in the background with
up to 8 tiles being transferred at a time. The most recently requested
tiles are downloaded first so that the area in view is updated in a
timely manner. We then go back to catch up on any remaining tiles.

As tiles become available, the map is updated on screen.

Tiles are cached for up to 7 days. If an older tile is in the cache,
a download is queued, and the old tile is used until the updated
version is available.
@tvrusso
Copy link
Member

tvrusso commented Jul 9, 2018

This looks like an interesting and exciting PR, and I will have to test it out a bit. You might also advertise it on the Xastir mailing list and let some other folks test it out while it's pending. I may not be able to get a look at it for a few weeks, and Curt is pretty busy, too.

It appears you may also have partially addressed issue report #23. Have you tested this set of code changes against GraphicsMagick, in which GetIndexes is also deprecated?

@tvrusso tvrusso requested a review from we7u July 9, 2018 02:04
@ChocolateFrogsNuts
Copy link
Contributor Author

I don't use GraphicsMagick, so it will need testing against that, but I only made the minimal changes to get a compile. The changes may well work with both.
Not much traffic on the mailing list recently but I'll announce it on there shortly anyway so we get some testers on board.

@we7u
Copy link
Member

we7u commented Jul 10, 2018

Merged into my own local git repo, on SUSE Leap 42.3 with all updates and GraphicsMagick installed:

map_OSM.o: In functiondraw_OSM_image':
/home/archer/xastir/src/map_OSM.c:726: undefined reference to GetAuthenticPixels' /home/archer/xastir/src/map_OSM.c:736: undefined reference to GetAuthenticIndexQueue'
map_OSM.o: In function draw_image': /home/archer/xastir/src/map_OSM.c:525: undefined reference to GetAuthenticPixels'
/home/archer/xastir/src/map_OSM.c:535: undefined reference to GetAuthenticIndexQueue' map_OSM.o: In function draw_OSM_tiles':
/home/archer/xastir/src/map_OSM.c:1212: undefined reference to SetImageBackgroundColor' /home/archer/xastir/src/map_OSM.c:1242: undefined reference to ClearMagickException'
/home/archer/xastir/src/map_OSM.c:1279: undefined reference to IdentifyImage' collect2: error: ld returned 1 exit status

@tvrusso
Copy link
Member

tvrusso commented Jul 10, 2018

It appears that GraphicsMagick uses "MagickLibVersion" exactly as named in ImageMagick, but uses a very different numbering scheme, so a simple comparison against a value from ImageMagick is no good. The code in question is testing against the value 0x669 but the recent GraphicsMagick I have has the value 0x211800.

There will have to be a test against HAVE_GRAPHICS_MAGICK in there, too.

We have tons of old ifdefs in there from ancient versions of Magick (for which there's a separate issue #25 calling for their removal). They are probably all broken as well, but don't matter because nobody has used those ancient versions for years.

This also means that the fixes here do not in fact address #23 either, since GraphicsMagick has a different function that is intended as the replacement for GetIndexes. When I opened #23, I checked and it seemed that ImageMagick had the same one as well, but a different, ImageMagick-specific one is being used here.

@we7u
Copy link
Member

we7u commented Jul 10, 2018

FYI: We have historically supported both GM and IM. GM has been more stable, originally a fork of IM. Some people only have IM available, some GM, so supporting both has worked well for us minus the struggles IM sometimes has. I run only GM, unless on a system that doesn't have it in its package manager.

Copy link
Member

@we7u we7u left a comment

Choose a reason for hiding this comment

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

Needs fixes to handle the GraphicsMagick library as well. Some of our users use GraphicsMagick, some use ImageMagick. Sometimes a bug in one forces the use of the other on any given Linux distribution.

@we7u
Copy link
Member

we7u commented Jul 10, 2018

A few more things (all minor stuff):

  • Changes to interface.c have nothing to do with the main reason for the PR. Would be better to do a separate PR for it so it's not hidden in the big patch.

  • Changing from "<< 8" to "* 256"" is slower. I suggest keeping the "<< 8" code in the map*.c files.

  • The headers on the two new files appear to have been copied from an existing file. They need Copyright dates updated at least. Should be only "Copyright (C) 2018 The Xastir Group" since they are new files. "dlm.h" says: "contributed by Jerry Dunmire, KA6HLD." which needs to be corrected as well. "dlm.c" has an $Id: message which is wrong, plus also has "This file derived from" message at the bottom of the header. Correct? Should be deleted?

I'm looking forward to trying this out when the GM stuff gets fixed!

Modify the changes for newer ImageMagick versions to accommodate GraphicsMagick.
@ChocolateFrogsNuts
Copy link
Contributor Author

ChocolateFrogsNuts commented Jul 14, 2018 via email

Created a new branch bugfix1 so this can be pulled separately.
This call is sort of redundant as the next call is to GetExceptionInfo which clears it anyway.
GraphicsMagick doesn't have it, but ImageMagick does, although it requires newer versions.
Now compatible with GraphicsMagick 1.3.30 and ImageMagick 6.9.10.
No more IM/GM related deprecation warnings (with the usual #if ugliness)

Fixed several mis-spellings of HAVE_GRAPHICSMAGICK (an extra underscore)
that I had introduced.
Change the MagickLibVersion checks.
These had been updated for newer ImageMagick, but produce warnings on GraphicsMagick.
Fixed by casting the args to int instead of updating the format string to %1.2f.
@ChocolateFrogsNuts
Copy link
Contributor Author

ChocolateFrogsNuts commented Jul 20, 2018 via email

@tvrusso
Copy link
Member

tvrusso commented Mar 16, 2019

It would probably be good to get this resolved soon. Curt: have your requested changes been addressed to your satisfaction? It's been over a year since we released Xastir 2.1.0, and maybe we should start thinking about releasing 2.1.2. We should not do so with all of those ImageMagick and GraphicsMagick deprecated function calls, lest we find Xastir unbuildable on some distro in short order.

@tvrusso tvrusso requested a review from we7u March 16, 2019 17:45
@we7u
Copy link
Member

we7u commented Apr 4, 2019

Letting you know I'm looking at this again and have part of it checked. I'm really liking the code so far. I hope to have the check completed by this weekend.

@tvrusso
Copy link
Member

tvrusso commented Apr 4, 2019

For what it's worth, while I'm not reviewing this code, I have just downloaded the branch and am at least compile and run testing it on my system. The graphicsmagick deprecation warnings are gone, and the code is running. I am delighted with the new speed of the updates as I pan the map with an online map source, which used to be quite slow.

@we7u
Copy link
Member

we7u commented Apr 4, 2019

Yep! You should probably read the comments at the top of dlm.c to see how he's doing it. Pretty impressive so far.

pthread_t DLM_queue_thread;

volatile int DLM_queue_progress_flag=0;
volatile int DLM_queue_state=DLM_Q_STOP;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should DLM_queue_state be protected by a mutex to ensure correct memory visibility? I don't believe volatile is enough.

Copy link
Member

Choose a reason for hiding this comment

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

Are you ok if I merge this while we wait on the answer? I'm good with the rest of the code and think this would be a step forward. If the variable needs protection one of us can add that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am OK with that, although it might be good to hold on a new release until we figure it out.

Copy link
Member

Choose a reason for hiding this comment

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

I'm confused as to how DLM_queue_state should be working. I could see it protected by a mutex and being an INT (for perhaps a count of download threads running), but I don't see how having multiple threads able to write specific values into it will work, mutex or not. It's a single variable but multiple threads can write STOP/RUN/QUIT/IDLE/STARTING values into it at any time. Perhaps make it a count variable with defined ALL-STOP value (-1) or something? It's also easily possible that I misunderstand what its purpose is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify what my concern is: I've been bitten in the past where only one thread is modifying a variable and the reading thread does not see the update. The variable was marked volatile. A mutex is needed to ensure changes are visible to other threads. Having the mutex inserts a memory barrier.

See https://en.wikipedia.org/wiki/Memory_barrier#Example for a bit of an explanation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can add in the mutexes if desired.

Copy link
Member

Choose a reason for hiding this comment

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

Feel free. Usual fork / modify(on a branch) / pull-request. I'd have to look deeper at the code to decide for sure that it's needed, but if one thread is writing and at least one other is reading - we need it. Thanks!

@we7u we7u merged commit 0cb9a07 into Xastir:master Apr 4, 2019
@ChocolateFrogsNuts
Copy link
Contributor Author

ChocolateFrogsNuts commented Apr 5, 2019 via email

@we7u
Copy link
Member

we7u commented Apr 5, 2019

Excellent! That means we shouldn't have to do anything to the code. It's been merged with master. Thanks for your contribution!

tvrusso added a commit to tvrusso/Xastir that referenced this pull request Apr 23, 2019
In commits b071954 and 7815dd9 (and possibly others associated with
PR Xastir#40), the GetIndexes function (present in both ImageMagick and
GraphicsMagick, and deprecated in both) was coded around so that if
we've got newer versions of the library, we use the new API, and if we
have an older version, we use the older API.

But Xastir#40 only fixed these deprecated uses in a few files, and mised the
one usage in map_geo.c

This commit copies over the fix verbatim from map_OSM.c, and shuts up
the deprecation warning.

Fixes Xastir#81.
@tvrusso tvrusso added this to Done in Release 2.1.2 May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Release 2.1.2
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants