Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
greubel
Visitor

roUrlTransfer Question

I’m trying to setup a roImageCanvas with multiple invisible layers. Each layer is a grid with 28 images. I have an unknown number of images to represent to the screen. My first attempt, just to see what would happen, was to fill all the layers with the URLs of 300 images. As expected, this took way too long to load. Monitoring the server and the Roku debug, each image was requested and transferred in sequence (no overlap). So I thought I could get some overlap by using an async roUrlTransfer to a file on disk and then use those in the layers. Did the same test and for some reason the loading did not start until the last image was requested and I did a wait() for message. The loading was the same, each image was transferred in sequence (no overlap). Did the test again but this time I put a short wait() for message after each roUrlTransfer request. Aha, this worked. I saw as many as 50 concurrent transfers during several tests. But varying the wait time too low and it goes back to the original problem.

Now the questions:
1. Shouldn’t the roUrlTransfer request be fired off immediately ?
2. Why are they queueing ?
3. Why does the amount of wait time matter ?
4. Does the Roku require a minimum / maximum amount of time for background processing ?
0 Kudos
7 REPLIES 7
TheEndless
Channel Surfer

Re: roUrlTransfer Question

If you call canvas.SetRequireAllImagesToDraw(False) on the image canvas, I believe it should load the images asynchronously, so that may be an easier option and give you better results than you're currently seeing.

As for the roUrlTransfer and the need for a wait/sleep, are you using the same roUrlTransfer object? I don't think you can do multiple async requests with a single roUrlTransfer object without it becoming synchronous. If you're using multiple roUrlTransfer objects then are you sure it's staying in scope as you create new ones? If you're not keeping a reference to it, then it's probably going out of scope before it has a chance to start the download.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
greubel
Visitor

Re: roUrlTransfer Question

I create a new roUrlTransfer object for each image and they are not going out of scope.
All the downloads complete correctly.
0 Kudos
TheEndless
Channel Surfer

Re: roUrlTransfer Question

"greubel" wrote:
I create a new roUrlTransfer object for each image and they are not going out of scope.
All the downloads complete correctly.

Hrmm.. something doesn't sound right. Could you share your code? I have a caching "class" that does asynchronous downloads like you describe without issue. It uses a different message port for every roUrlTransfer object, though, so I wonder, if you're using the same one, if it's not blocking somehow...?

Also, did you try the SetRequireAllImagesToDraw(False) call? I use that on the cover grid in my MainSqueeze channel, which displays 17 images at a time (admittedly not 300), and it definitely loads them asynchronously.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
greubel
Visitor

Re: roUrlTransfer Question

Sample code

Function Socket( url as string ) as object
sock = CreateObject( "roUrlTransfer" ) ' create socket
sock.SetUrl( url )
return sock
End Function

Function Load_Thumb( url as object, path as object, file as object )
sock = Socket( url )
sock.SetPort(m.port) <------------ global message port
if sock.AsyncGetToFile( path )
Set_Socket( sock, Clr_Socket, file ) <------------ to push socket to active queue
MyMsg( 3, "Wait for Me" ) <------------ "Wait for Me" is an invalid msg type so it just waits 3 ms
else
? "AsyncGetToFile failed"
end if
? "Load "+file+" from " url
End Function

Sub Clr_Socket()
idx = m.index
status = m.msg.GetResponseCode()
? "Clear Socket - " m.name " status = " status
m = GetGlobalAA()
m.sockets.Delete( idx ) <----------- delete socket from active queue
End Sub



The roUrlTransfer object remains visible until it's deleted in the Clr_Socket() routine.

I do have SetRequireAllImagesToDraw set to false.
But this shouldn't have any bearing on the transfers to the disk.

url is the network address
path is the full path to the file
file is just the filename
m.port is a global port that I retrieve all messages on.
MyMsg is a function that distributes the messages --- where ever.
Clr_Socket is the subroutine to call when a message of type roUrlTransfer for THIS socket is posted.
file is a name associated with this socket.
0 Kudos
TheEndless
Channel Surfer

Re: roUrlTransfer Question

"greubel" wrote:
I do have SetRequireAllImagesToDraw set to false.
But this shouldn't have any bearing on the transfers to the disk.

No, I was suggesting it as an alternative to you having to download them all to disk. If it accomplished what you needed (and it sounded like it should, if you weren't using it), then the issue you're having would be more or less moot.

So, are you saying that, without the 3ms wait, they seem to process synchronously, but with the wait, they process as expected? That certainly doesn't seem right, but I've found that having to add a delay isn't particularly uncommon in BrightScript. It could be, without the delay, the CPUs just being hit hard enough that it doesn't have any other choice but to process in the order the transfers are created. Maybe 3ms is the sweet spot that gives it just enough room to breathe...? Purely speculation, not much help, and probably starting to irritate you, so I'll leave it there, and see if an official Roku person can shed some light on it instead.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
greubel
Visitor

Re: roUrlTransfer Question

I was trying to achieve some overlap in the image loading to speed things up by prefetching them to disk.
The roImageCanvas still has a lot of overhead resizing the images to fit in my grid.
What I'm trying to load are iPhoto thumbnails. Which are usually 360x270 at 70+ K.
I'm just saying that the network request for AsyncGetToFile should be issued before returning to my code.
😄

Oh, do you know what the available storage on the disk is ?
0 Kudos
TheEndless
Channel Surfer

Re: roUrlTransfer Question

"greubel" wrote:
Oh, do you know what the available storage on the disk is ?

Roku would have to give specifics on that, as it probably differs depending on what model and how many channels a user has installed, but I reserve 10 megabytes for my aquarium screensaver and haven't run into any issues with it. I imagine that's probably pretty conservative for the Roku 2s.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.