Your Digital Media Has Never Looked So Good

 
JohnBasedow
Topic Author
Posts: 45
Joined: Sun Sep 22, 2013 8:38 pm

Transitioning to Scene Graph's Video Component - Improper Use?

Mon Feb 06, 2017 11:08 am

After seeing the deprecation notice for the roVideo* components, and having playback issues with HLS and DASH streams, I've been trying to slowly migrate my channel to use the Scene Graph Video element for playing videos rather than the roVideoScreen.

So, this means that I'm trying to integrate my existing channel's workflow with the Scene Graph API.

So, where I had previously called my function to create an roVideoScreen, I just replaced the function call with one that calls into my function to show the Scene Graph video. 

The problem is this: I can only show the Scene Graph Video one time, and any attempts to show it again cause my channel to hang up.  
I've checked the Scene Graph debugging information, and all nodes get cleaned up except for one, which leads me to think something in the Scene Graph application is not cleaning up completely. 
I'm exiting the Scene Graph scene via the back button, and I'm getting the "scene closed" event from the MessagePort, so I'm assuming I'm "cleaning up" properly. 

Workflow:
BrightScript: User chooses video from roPosterScreen (works)
BrightScript: Create scene for Video and play video     (works) 
Scene Graph: Play video                                               (works)
Scene Graph: Exit Scene back to BrightScript-land       (works?)
BrightScript: User chooses another video from roPosterScreen (works) 
BrightScript: Create scene for Video and play video      (Locks up on calls into Scene Graph application)

Questions:
  • Is the Scene Graph application intended to only be displayed once, and once the scene is exited, should not be shown again?
  • Am I trying to use this improperly?  
I'm trying to slowly migrate to all Scene Graph components since so much code has to be migrated over, and I thought it would be simpler to just "call-into" Scene Graph versus trying to migrate my entire channel at once.
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Mon Feb 06, 2017 3:05 pm

Hmmm... how do you "exit a scene"?
Can you be more specific. And what happens to roSgScreen?
 
JohnBasedow
Topic Author
Posts: 45
Joined: Sun Sep 22, 2013 8:38 pm

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Mon Feb 06, 2017 5:13 pm

In my onKeyEvent in my SceneGraph component's .brs file, I detect the back button, and return false, so the event is delegated to the scene instead. (Like here: https://sdkdocs.roku.com/pages/viewpage ... Id=1608547)
The 'backExitsScene' field also remains true in the Scene. (https://sdkdocs.roku.com/display/sdkdoc/Scene)

In the code where I create the Screen and Scene, I have a message listener that listens for the roSGScreenEvent (https://sdkdocs.roku.com/display/sdkdoc/roSGScreenEvent) and it detects the 'msg.isScreenClosed()' being true, so it appears the Screen is closed when I hit the back button.

The only thing I do differently from the examples on creating a SG Screen and Scene like the one here: https://sdkdocs.roku.com/display/sdkdoc/roSGScreenEvent, is that I get the global node and set some field values for my Video scene to use to play the video, since passing parameters to the Screen/Scene isn't supported. 

Again, this works one time just fine, so I know that code works in some form, I just don't know if I'm trying to use the Scene Graph components like they're intended to be used.  

It almost seems like they're intended to be created once from BrightScript, not multiple times.
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Mon Feb 06, 2017 6:00 pm

So you don't do anything actively regarding roSgScreen and the Scene roSgNode - just making user exit via Back button?
(and what if they never press Back?)

What are your steps afterwards - returned to main, using "classic" component to select video and then ...? Do you create a new roSgScreen or what?
 
JohnBasedow
Topic Author
Posts: 45
Joined: Sun Sep 22, 2013 8:38 pm

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Mon Feb 06, 2017 8:00 pm

I'm just trying to proof-of-concept this code before I flesh out exact workflows, but yes, right now you have to hit the back button to exit the video.

Here's some of my code snippets showing the pertinent functions:
VideoScene.xml:
<?xml version="1.0" encoding="utf-8" ?>

<component name="VideoScene" extends="Scene" >

<script type="text/brightscript" uri="pkg:/components/VideoScene.brs" />
<children>
    <Video id="myVideo" width="1280" height="720" visible="false" />
</children>
</component>


VideoScene.brs:
function init()
    m.video = m.top.findNode("myVideo")
    if ( m.global.title <> invalid ) then
        print "Have video content!"
        playVideo( m.global.title, m.global.streamformat, m.global.url )
    else
        print "No content!!!!!"
    end if
end function

function playVideo(title as String, streamformat as String, url as String) as void
    m.video.visible = true
    vidContent = createObject("RoSGNode", "ContentNode")
    vidContent.title = title
    vidContent.streamformat = streamformat
    vidContent.url = url
    m.video.content = vidContent
    m.video.setFocus(true)
    m.video.control = "play"
end function

' Called when a key on the remote is pressed
function onKeyEvent(key as String, press as Boolean) as Boolean
  'print "in VideoScene.brs onKeyEvent ";key;" "; press
  if press then
    if key = "back"
        print "------ [back pressed] ------"
        m.video.control = "stop"
        m.video.content = invalid
        m.video.setFocus(false)
        m.top.setFocus(true)
        print "Exiting scene??"
        return false
    else if key = "OK"
      print "------- [ok pressed] -------"
    else if key = "left"
      print "Left pressed"
    else if key = "right"
      print "Right pressed"
    else
      return false
    end if
  end if
  return false
end function


Brightscript that creates scene:
Sub DoVideo(metaData as Object)
    print "DoVideo called!"
    if (m.sgScreen = invalid) then
        m.sgScreen = CreateObject("roSGScreen")
        m.sgMessagePort = CreateObject("roMessagePort")
        m.sgScreen.setMessagePort(m.sgMessagePort)
    end if
    scene = m.sgScreen.CreateScene("VideoScene")
    'stop 'Uncomment here if you want to step through
    print "Setting global data"
    if (m.globalNode = invalid) then
        m.globalNode = m.sgScreen.getGlobalNode()
    end if
    print "Create ContentNode"
    if (metaData.url <> invalid) then
        m.globalNode.addFields({ title: metaData["Title"], streamformat: metaData["StreamFormat"], url: metaData["URL"] })
    else if (metaData.Streams <> invalid) then
        m.globalNode.addFields({ title: metaData["Title"], streamformat: metaData["StreamFormat"], url: metaData["Streams"][0].url })
    end if
    print "Showing screen"
    m.sgScreen.show()

    while(true)
        msg = wait(0, m.sgMessagePort)
        msgType = type(msg)
        print "SG event: " + msgType
        if msgType = "roSGScreenEvent" then
            if msg.isScreenClosed() then
                print "Leave DoVideo"
                return
            end if
        end if
    end while
End Sub

Some of the code in there is just there from me trying to try different things.
An odd thing I've noticed in the final function's code, is that if I step through the code, and try to print different things, they end up locking up the channel as well.
If I do 'p scene' it works fine, but if I do 'p scene.id', it locks up.
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Tue Feb 07, 2017 3:15 am

JohnBasedow wrote:
An odd thing I've noticed in the final function's code, is that if I step through the code, and try to print different things, they end up locking up the channel as well.
If I do 'p scene' it works fine, but if I do 'p scene.id', it locks up.

Yep, that's the "new normal" :? since unleashing the "unified" (multiplexed) console. I complained repeatedly about it during the 7.5 beta but apparently there is no rush fixing it. Happens only with scene graph...
 
Veeta
Posts: 126
Joined: Tue Aug 12, 2014 4:44 am
Location: http://www.veeta.tv
Contact:

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Tue Feb 07, 2017 6:54 am

I've had some odd cases of channels locking up as well.  Each circumstance was unique and it was something seemingly random which fixed it.  Here are some things to try.

- Remove the call to `m.video.setFocus(false)`.  Docs say setFocus(false) has bad effects and I've had problems with focus going away and never coming back
- Don't reuse m.sgScreen.  It could be that the object is flagged as "closed" because you exited that scene/screen and the roSGScreen object is not able to be reused.  When you get isScreenClosed(), set `m.sgScreen = invalid` to force it to be unreferenced and garbage collected.

Finally, from a general app design perspective, it's kind of unique to be mixing SDK1 screens with SceneGraph video player.  From the SceneGraph examples and docs there are a few mentions of main.brs being a very simple function that launches the Scene and the app stays in that context for the duration.  There are also some SG layouts which mimic the old postergrid.  See https://github.com/rokudev/videoplayer-channel and specifically the main.brs there.
 
JohnBasedow
Topic Author
Posts: 45
Joined: Sun Sep 22, 2013 8:38 pm

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Tue Feb 07, 2017 9:08 am

Don't reuse m.sgScreen.

I only did that to try not creating it multiple times, my initial code re-created the Screen every time.  (and still locked up)

Finally, from a general app design perspective, it's kind of unique to be mixing SDK1 screens with SceneGraph video player.

That's kinda the point of this post.
I wanted to be able to slowly transition to a full Scene Graph solution, not go "whole-hog" the first time.
For one thing, switching to the Scene Graph Video player, it has fixed an issue I was having with HLS streams, so I was planning on delivering this as a fix for the HLS part of my channel, while leaving the rest alone since it still works for the most part.

I feel like I'm getting the impression that the SG code isn't intended to be re-run multiple times in a single execution of a channel.
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Tue Feb 07, 2017 11:18 am

Veeta wrote:
- Don't reuse m.sgScreen.  It could be that the object is flagged as "closed" because you exited that scene/screen and the roSGScreen object is not able to be reused.

This seems the most problematic item here and likely the cause. Once received isScreenClosed(), i wouldn't trust a ro-component being re-usable. I don't remember seeing it written down but i think i have experienced it in the past
 
JohnBasedow
Topic Author
Posts: 45
Joined: Sun Sep 22, 2013 8:38 pm

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Tue Feb 07, 2017 11:37 am

You missed my response. I didn't originally do this, and it still locked up then.
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Tue Feb 07, 2017 12:38 pm

JohnBasedow wrote:
You missed my response. I didn't originally do this, and it still locked up then.

I saw what you said - i just think that is another issue.
There are >1 ways to hang oneself with RSG  8)
 
shess
Posts: 9
Joined: Sat Sep 09, 2017 9:55 pm

Re: Transitioning to Scene Graph's Video Component - Improper Use?

Sat Sep 09, 2017 9:59 pm

Hello - I'm in the same situation and having the same lockup.  Was there ever a solution to this found?  If not, is it just not possible to mix and match SDK1 and RSG?

Thanks!

Who is online

Users browsing this forum: No registered users and 2 guests