Forum Discussion

360tv's avatar
360tv
Streaming Star
13 years ago

question about PositionNotificationPeriod

So, currently I have a roVideoPlayer that has a set PositionNotificationPeriod of 10 seconds, during which time it checks in with my servers for any status and instructions it needs. Sometimes it's instructed to sleep and or perform another function that lasts longer than the PositionNotificationPeriod. When the functions are complete, it runs any queued up PositionNotificationPeriod , shooting thru two or three instantaneously.

What I'd like is, if roVideoPlayer is told to sleep for 20 seconds, for it to drop any PositionNotificationPeriod that would have queued up during sleep.Is this possible?

7 Replies

  • Just setup and manage a flag in your event loop. Combined with a roTimespan you could easily do what you're describing.

    if msg.isPlaybackPosition()
    if not isSleeping
    ' do stuff
    if ' ordered to sleep for 20s
    isSleeping = true
    sleepPeriod = 20
    timer.Mark()
    end if
    else if timer.TotalSeconds() > sleepPeriod
    isSleeping = false
    end if
    end if
  • 360tv's avatar
    360tv
    Streaming Star
    it's more like I'm doing a loop that will sleep(39) 255 times

    it's a lot to explain as to why I have to do it, but sometimes during a 10 second notification period, it may be told to sleep 6 seconds, then perform a loop that takes a total of 15 seconds, and it won't be until then that it does another notification.

    So, basically, one notification period may have loops triggered within it that far exceed the notification period, in which case, putting a flag at the beginning of the notification won't work.

    I wish I could post all my code but the function it's contained in is 400 lines, with the msg.isplaybackposition loop about 300 lines. it's a lot to go thru to take out what I don't want to show.
  • If you want to do something 6s in the future, don't sleep for 6s within the event loop. Instead, save the target time and information about the task to memory and do it in some future iteration of the event loop. Build a queue of these tasks and each time through the loop, check each one to see if you've reached it's execution time. Similar to how tracking beacons get fired in the VAST sample.
  • 360tv's avatar
    360tv
    Streaming Star
    The next time notification period loop in many instances might be to late. it wont be until the current notification period will it know that it's got 6 seconds, or 2 seconds left...

    I have a Wowza Linux server receiving and broadcasting a stream from a windows server using VLC. VLC is playing two hour video files that is made up of different clips. There's a SQL server elsewhere that has recorded what clips start when in that two hour file down to the second.

    The Roku box is hitting the Windows to see where it is in it's play duration, hits the SQL server to see what that content is in that particular time, and what the video overlay should be and how long it should be displayed, among other features.

    I'll go ahead and post the majority of the code for a short time so you can see what I"m trying to do. I'm not sure that there's any other way to do what I want other than to sleep.



    while true
    msg = wait(0, port)
    if msg <> invalid

    '*******************************
    'Playback progress (in seconds):
    else if msg.isPlaybackPosition() then
    if not isSleeping
    nowpos = msg.GetIndex()
    print "Event type: "; msg.GetType()
    print "Playback position: " + nowpos.toStr()

    list.clear()
    device.clear()
    xml.clear()


    if (device.overlay <> "") and (device.nextoverlay <> device.overlay) and ((device.timeleft < url.PositionNotificationPeriod) or (device.timeleft - 5 < url.PositionNotificationPeriod)) then
    if device.overlayfontcolor <> ""
    fadelevel = CreateObject("roByteArray")
    fadelevel.fromhexstring(device.overlayfontcolor)
    end if
    'printaa(device)
    overlaytimer = CreateObject("roTimespan")
    overlaytimer.Mark()

    while true

    if overlaytimer.totalseconds() <= device.timeleft then
    '********************
    '***** Fade Out *****
    '********************

    if overlaytimer.totalseconds() > 4 then
    tempRect = {x: device.overlayX, y: device.overlayY, w: device.overlayW, h:device.overlayH}
    tempitems = {
    CompositionMode: "Source"
    Color: device.overlaycolor
    Text: device.overlaytext
    TextAttrs: { font: device.overlayfontsize, color: "#" + device.overlayfontcolor, HAlign : device.overlayfontHAlign, VAlign : device.overlayfontVAlign}
    TargetRect: tempRect
    }
    tempcanvas.SetLayer(0, { url: device.overlayurl, Color: "#" + device.overlaycolor, CompositionMode: "Source" })
    tempcanvas.SetLayer(1, tempitems)
    tempcanvas.show()
    'Print "Time left is " + device.timeleft.tostr()
    sleep(1000)
    elseif overlaytimer.totalseconds()<= 4 then
    while fadelevel[0] > 10
    'print "Fade level**********"
    'print fadelevel[0]
    'print "#" + fadelevel.tohexstring()
    tempRect = {x: device.overlayX, y: device.overlayY, w: device.overlayW, h:device.overlayH}
    tempitems = {
    CompositionMode: "Source"
    Color: "#" + fadelevel.tohexstring()
    Text: device.overlaytext
    TextAttrs: { font: device.overlayfontsize, color: "#" + fadelevel.tohexstring(), HAlign : device.overlayfontHAlign, VAlign : device.overlayfontVAlign}
    TargetRect: tempRect
    }
    tempcanvas.SetLayer(0, { url: device.overlayurl, Color: "#" + device.overlaycolor, CompositionMode: "Source" })
    tempcanvas.SetLayer(1, tempitems)
    tempcanvas.show()
    fadelevel[0] = fadelevel[0] - 4
    'Print "Time left is " + device.timeleft.tostr()
    sleep(39)
    end while
    sleep(1000)
    'exit while
    canvas.show()
    sleep(device.timeleft + 8 * 1000)
    end if
    else
    '********************
    '***** Fade In *****
    '********************
    print overlaytimer.totalseconds().tostr()
    if device.nextoverlay = ""
    exit while
    else 'if overlaytimer.totalseconds() >= device.timeleft + 3 then
    fadelevel = CreateObject("roByteArray")
    fadelevel.fromhexstring(device.nextoverlayfontcolor)
    i = fadelevel[0]
    fadelevel[0] = 0
    while fadelevel[0] < (i - 2)
    tempRect = {x: device.nextoverlayX, y: device.nextoverlayY, w: device.nextoverlayW, h:device.nextoverlayH}
    tempitems = {
    CompositionMode: "Source"
    Color: device.nextoverlaycolor
    Text: device.nextoverlaytext
    TextAttrs: { font: device.nextoverlayfontsize, color: "#" + fadelevel.tohexstring(), HAlign : device.nextoverlayfontHAlign, VAlign : device.nextoverlayfontVAlign}
    TargetRect: tempRect
    }
    tempcanvas.SetLayer(0, { url: device.nextoverlayurl, Color: device.nextoverlaycolor, CompositionMode: "Source" })
    tempcanvas.SetLayer(1, tempitems)
    tempcanvas.show()

    fadelevel[0] = fadelevel[0] + 2
    'i = i + 2
    sleep(39)
    end while
    exit while
    end if
    end if
    end while


    elseif device.overlay <> "" then
    tempRect = {x: device.overlayX, y: device.overlayY, w: device.overlayW, h:device.overlayH}
    tempitems = {
    CompositionMode: "Source"
    Color: device.overlaycolor
    Text: device.overlaytext
    TextAttrs: { font: device.overlayfontsize, color: "#" + device.overlayfontcolor, HAlign : device.overlayfontHAlign, VAlign : device.overlayfontVAlign}
    TargetRect: tempRect
    }

    tempcanvas.SetLayer(0, { url: device.overlayurl, Color: device.overlaycolor, CompositionMode: "Source" })
    tempcanvas.SetLayer(1, tempitems)
    tempcanvas.show()
    else
    tempcanvas.Clear()
    canvas.Show()
    end if

    if device.status <> "OK"
    Print "Status not OK. Stoping."
    viewpost = "...."
    http = NewHttp(viewpost)
    http.PostFromStringWithTimeout(viewpost, 10)
    'sleep(1000)
    result = false
    exit while
    end if
    end if
    end if

    end if
    endif
    end while

  • Well, one thing is you don't need to wait for the next position notification event to wake up. You can put a short timeout on the wait, or use ifMessagePort.GetMessage.

    --Mark
  • 360tv's avatar
    360tv
    Streaming Star
    I'm afraid I don't understand what you're referring to?
  • I didn't review all your code but I see at the top you're calling wait(0,port). This waits until the next message is sent to the port. If you replace the 0 with a timeout in milliseconds, the wait will return after that amount of time even if no message has been sent. GetMessagePort is even faster, it returns immediately whether or not there is a message. So you don't have to depend on the timing of the position notification events.

    --Mark