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: 
ioan
Roku Guru

Is it possible to have an event loop inside a Scene?

I'm working on a motion-jpeg decoder and I need to redraw a Poster as fast as I can, is it possible to have an event loop inside a Scene?
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
11 REPLIES 11
EnTerr
Roku Guru

Re: Is it possible to have an event loop inside a Scene?

Good grief, no!
Thou shalt not hog the render thread (where RSG events and functions customarily run) - for it is for real the render thread. Meaning it re-draws the screen 30 or 60 times per second and if you take more than a few milliseconds to handle a call or event, you are making the player skip frames. Instead you are expected to run the loopy loops in a Task, i believe.
0 Kudos
ioan
Roku Guru

Re: Is it possible to have an event loop inside a Scene?

"EnTerr" wrote:
Good grief, no!
 Instead you are expected to run the loopy loops in a Task, i believe.

So I can have the following in a Task and redraw a Poster as fast as I can from there?

while true
'... waste time
end while
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
EnTerr
Roku Guru

Re: Is it possible to have an event loop inside a Scene?

"ioan" wrote:
So I can have the following in a Task and redraw a Poster as fast as I can from there?

Ha-haa, no - you don't get to draw the Poster. I am tempted to explain in quips, take your pick:
[spoiler=Yakov Smirnoff style:2kvqwwv8]In Soviet Russia, Scene Graph draws you![/spoiler:2kvqwwv8]
[spoiler=Chuck Norris style:2kvqwwv8]You don't draw Scene Graph - SCENE GRAPH DRAWS YOU![/spoiler:2kvqwwv8]
The way to do it with a poster - i imagine - is to set it's .uri field every time you get a new image downloaded. And then it should download and display that image. I am quite curious to see how fast or well that works with a sequence of images, like in your mjpeg...
0 Kudos
ioan
Roku Guru

Re: Is it possible to have an event loop inside a Scene?

"EnTerr" wrote:
Ha-haa, no - you don't get to draw the Poster. I am tempted to explain in quips, take your pick:
The way to do it with a poster - i imagine - is to set it's .uri field every time you get a new image downloaded. And then it should download and display that image. I am quite curious to see how fast or well that works with a sequence of images, like in your mjpeg...

Ha! You are right... and you know what sucks? You can't (at least I don't know how) to force a redraw. I have to provide images with different names to be able to redraw, so I have to always delete the prev. image saved, save the current image with a new name, pass it to the poster. I would save some time if I could just reuse the same name, I wouldn't have to delete prev. image. Anyway, it's not that bad. I was able to get about 10fps decoding a stream coming from a remote location. On the PC, using the exactly same code I get 30fps here, but the roku has slow roByteArray operations so I waste a lot of time when I move bytes from the receiving buffer to the image array. 
I have to thank you for the progress I made today, you pointed me in the right direction and I was able to figure it out from the sample channels:

Thank you!
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
EnTerr
Roku Guru

Re: Is it possible to have an event loop inside a Scene?

"ioan" wrote:
Ha! You are right... and you know what sucks? You can't (at least I don't know how) to force a redraw. I have to provide images with different names to be able to redraw, so I have to always delete the prev. image saved, save the current image with a new name, pass it to the poster. I would save some time if I could just reuse the same name, I wouldn't have to delete prev. image. Anyway, it's not that bad. I was able to get about 10fps decoding a stream coming from a remote location. On the PC, using the exactly same code I get 30fps here, but the roku has slow roByteArray operations so I waste a lot of time when I move bytes from the receiving buffer to the image array. 
I have to thank you for the progress I made today, you pointed me in the right direction and I was able to figure it out from the sample channels:

Thank you!

Sure thing. Implementing mjpeg actually has been on my "to do" list of ideas (which is +inf in 8-bit float long).

In theory you could use only 2 files and flip-flop between them. Or a circular buffer of size small N. It bears the risk of out-smarting yourself though, if say RSG did not notice the URL change last time - or had no time to decode/redraw - and now sees the URLs the old one again. I don't know how it's implemented - maybe there is observer on the .uri field which forces re-load on every assignment. The better-safe-than-sorry approach would be to include an always increasing counter in the name and delete the file two steps behind.

Btw, for your special purpose here you might be better off using roScreen and leaving RSG alone. With that one you are in full control in the redrawing, in fact nothing will draw itself.

PS. assigning field value between threads has a perhaps unexpected sync effect - last i checked (last year) you could do only 1 cross-thread assignment per frame (as in, max 60 per second)
0 Kudos
ioan
Roku Guru

Re: Is it possible to have an event loop inside a Scene?

"EnTerr" wrote:
Btw, for your special purpose here you might be better off using roScreen and leaving RSG alone. With that one you are in full control in the redrawing, in fact nothing will draw itself

I made the mjpeg decoder using roScreen but what options do I have to make an interface with roScreen if most of the "the old stuff" is deprecated and as of July 1st 2017 Roku won't accept any channels using it? What options are still available for creating a user interface using roScreen?
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
EnTerr
Roku Guru

Re: Is it possible to have an event loop inside a Scene?

"ioan" wrote:
"EnTerr" wrote:
Btw, for your special purpose here you might be better off using roScreen and leaving RSG alone. With that one you are in full control in the redrawing, in fact nothing will draw itself

I made the mjpeg decoder using roScreen but what options do I have to make an interface with roScreen if most of the  "the old stuff" is deprecated and as of July 1st 2017 Roku won't accept any channels using it? What options are still available for creating a user interface using roScreen?

My understanding is that roScreen (AKA "2D API") would remain available for special purposes like games - or in your case milking webcams. The components that are planned for sunset are the ones with "old look&feel" UI elements on them - roSpringboardScreen, roPosterScreen et al. roScreen on the other hand is a blank canvas you have to paint everything on by yourself, including buttons, menus and animations for them.
0 Kudos
ioan
Roku Guru

Re: Is it possible to have an event loop inside a Scene?

"EnTerr" wrote:
on the other hand is a blank canvas you have to paint everything on by yourself, including buttons, menus and animations for them.


THAT doesn't sound fun at all 🙂
Off topic: can I save a jpg on the roku's storage for future use (AKA not in tmp:/ so it's there when I start the app again) as thumbnail? 
One more off topic: can I have a "myutils.brs" file with common functions? I tried putting it in "components" in "source" but none of the functions can be found when I call them in code
https://github.com/e1ioan/
http://rokucam.com
0 Kudos
EnTerr
Roku Guru

Re: Is it possible to have an event loop inside a Scene?

"ioan" wrote:
"EnTerr" wrote:
on the other hand is a blank canvas you have to paint everything on by yourself, including buttons, menus and animations for them.

THAT doesn't sound fun at all 🙂

No, it does not - but that's what most games already do. I suppose the lack of UI elements would incentivize people into converting into RSG, which is not necessarily easier for your purposes - but seems would be slower for mjpeg-ing.

Off topic: can I save a jpg on the roku's storage for future use (AKA not in tmp:/ so it's there when I start the app again) as thumbnail? 
One more off topic: can I have a "myutils.brs" file with common functions? I tried putting it in "components" in "source" but none of the functions can be found when I call them in code

Nope. Using the public SDK, the only perma-storage you get is the Registry and that's limited at 8k or so. You could cloud store it, if you must...
0 Kudos