1
1
sub init ()
2
- m .MUX_SDK_VERSION = "1.6 .0"
2
+ m .MUX_SDK_VERSION = "1.7 .0"
3
3
m .top .id = "mux"
4
4
m .top .functionName = "runBeaconLoop"
5
5
end sub
@@ -85,6 +85,11 @@ function runBeaconLoop()
85
85
end if
86
86
m .top .ObserveField ("useRenderStitchedStream" , m .messagePort )
87
87
88
+ if m .top .useSSAI <> Invalid
89
+ m .mxa .useSSAIHandler (m .top .useSSAI )
90
+ end if
91
+ m .top .ObserveField ("useSSAI" , m .messagePort )
92
+
88
93
if m .top .error <> Invalid
89
94
m .mxa .videoErrorHandler (m .top .error )
90
95
end if
@@ -102,7 +107,7 @@ function runBeaconLoop()
102
107
while running
103
108
exitMsg = wait (10 , m .exitPort )
104
109
msg = wait (40 , m .messagePort )
105
- if exitMsg <> invalid
110
+ if exitMsg <> Invalid
106
111
data = exitMsg .getData ()
107
112
if data = true
108
113
running = false
@@ -133,6 +138,8 @@ function runBeaconLoop()
133
138
m .mxa .configChangeHandler (msg .getData ())
134
139
else if field = "useRenderStitchedStream"
135
140
m .mxa .useRenderStitchedStreamHandler (msg .getData ())
141
+ else if field = "useSSAI"
142
+ m .mxa .useSSAIHandler (msg .getData ())
136
143
else if field = "error"
137
144
m .mxa .videoErrorHandler (msg .getData ())
138
145
else if field = "control"
@@ -386,6 +393,7 @@ function muxAnalytics() as Object
386
393
m ._Flag_isSeeking = false
387
394
m ._Flag_lastReportedPosition = 0
388
395
m ._Flag_FailedAdsErrorSet = false
396
+ m ._Flag_useSSAI = false
389
397
390
398
' Flags specifically for when renderStitchedStream is used
391
399
m ._Flag_useRenderStitchedStream = false
@@ -603,29 +611,33 @@ function muxAnalytics() as Object
603
611
604
612
prototype .videoStreamingSegmentChangeHandler = sub (videoSegment as object )
605
613
if videoSegment <> Invalid
606
- if m ._lastPlayerWidth <> Invalid AND m ._lastPlayerHeight <> Invalid AND m ._lastPlayheadPosition <> Invalid AND m ._lastSourceWidth <> Invalid AND m ._lastSourceHeight <> Invalid AND videoSegment .segStartTime <> Invalid
607
- player_playhead_time = Int (videoSegment .segStartTime * 1000 )
608
- if m ._lastPlayerWidth >= 0 AND m ._lastPlayerHeight >= 0 AND m ._lastPlayheadPosition >= 0 AND player_playhead_time >= 0 AND m ._lastSourceWidth > 0 AND m ._lastSourceHeight > 0
609
- timeDiff = player_playhead_time - m ._lastPlayheadPosition
610
- scale = m ._min (m ._lastPlayerWidth / m ._lastSourceWidth , m ._lastPlayerHeight / m ._lastSourceHeight )
611
- upscale = m ._max (0 , scale - 1 )
612
- downscale = m ._max (0 , 1 - scale )
613
- m ._viewMaxUpscalePercentage = m ._max (m ._viewMaxUpscalePercentage , upscale )
614
- m ._viewMaxDownscalePercentage = m ._max (m ._viewMaxDownscalePercentage , downscale )
615
- m ._viewTotalContentPlaybackTime = m ._safeAdd (m ._viewTotalContentPlaybackTime , timeDiff )
616
- m ._viewTotalUpscaling = m ._safeAdd (m ._viewTotalUpscaling , upscale * timeDiff )
617
- m ._viewTotalDownscaling = m ._safeAdd (m ._viewTotalDownscaling , downscale * timeDiff )
614
+ ' For now, we only listen for video or media segments for all of our calculations
615
+ if videoSegment .segType = 0 or videoSegment .segType = 2
616
+ if m ._lastPlayerWidth <> Invalid AND m ._lastPlayerHeight <> Invalid AND m ._lastPlayheadPosition <> Invalid AND m ._lastSourceWidth <> Invalid AND m ._lastSourceHeight <> Invalid AND videoSegment .segStartTime <> Invalid
617
+ player_playhead_time = Int (videoSegment .segStartTime * 1000 )
618
+ if m ._lastPlayerWidth >= 0 AND m ._lastPlayerHeight >= 0 AND m ._lastPlayheadPosition >= 0 AND player_playhead_time >= 0 AND m ._lastSourceWidth > 0 AND m ._lastSourceHeight > 0
619
+ timeDiff = player_playhead_time - m ._lastPlayheadPosition
620
+ scale = m ._min (m ._lastPlayerWidth / m ._lastSourceWidth , m ._lastPlayerHeight / m ._lastSourceHeight )
621
+ upscale = m ._max (0 , scale - 1 )
622
+ downscale = m ._max (0 , 1 - scale )
623
+ m ._viewMaxUpscalePercentage = m ._max (m ._viewMaxUpscalePercentage , upscale )
624
+ m ._viewMaxDownscalePercentage = m ._max (m ._viewMaxDownscalePercentage , downscale )
625
+ m ._viewTotalContentPlaybackTime = m ._safeAdd (m ._viewTotalContentPlaybackTime , timeDiff )
626
+ m ._viewTotalUpscaling = m ._safeAdd (m ._viewTotalUpscaling , upscale * timeDiff )
627
+ m ._viewTotalDownscaling = m ._safeAdd (m ._viewTotalDownscaling , downscale * timeDiff )
628
+ end if
618
629
end if
619
- end if
620
- if videoSegment .width <> Invalid AND videoSegment .height <> Invalid AND videoSegment .segBitrateBps <> Invalid
621
- if m ._lastSourceWidth <> Invalid AND m ._lastSourceWidth <> videoSegment .width OR m ._lastSourceHeight <> Invalid AND m ._lastSourceHeight <> videoSegment .height OR m ._lastVideoSegmentBitrate <> Invalid AND m ._lastVideoSegmentBitrate <> videoSegment .segBitrateBps
622
- m ._addEventToQueue (m ._createEvent ("renditionchange" , { video_source_width : videoSegment .width , video_source_height : videoSegment .height , video_source_bitrate : videoSegment .segBitrateBps }))
630
+ if videoSegment .width <> Invalid AND videoSegment .height <> Invalid AND videoSegment .segBitrateBps <> Invalid
631
+ if m ._lastSourceWidth <> Invalid AND m ._lastSourceWidth <> videoSegment .width OR m ._lastSourceHeight <> Invalid AND m ._lastSourceHeight <> videoSegment .height OR m ._lastVideoSegmentBitrate <> Invalid AND m ._lastVideoSegmentBitrate <> videoSegment .segBitrateBps
632
+ details = { video_source_width : videoSegment .width , video_source_height : videoSegment .height , video_source_bitrate : videoSegment .segBitrateBps }
633
+ m ._addEventToQueue (m ._createEvent ("renditionchange" , details ))
634
+ end if
623
635
end if
636
+ m ._lastSourceWidth = videoSegment .width
637
+ m ._lastSourceHeight = videoSegment .height
638
+ m ._lastVideoSegmentBitrate = videoSegment .segBitrateBps
639
+ m ._lastPlayheadPosition = Int (videoSegment .segStartTime * 1000 )
624
640
end if
625
- m ._lastSourceWidth = videoSegment .width
626
- m ._lastSourceHeight = videoSegment .height
627
- m ._lastVideoSegmentBitrate = videoSegment .segBitrateBps
628
- m ._lastPlayheadPosition = Int (videoSegment .segStartTime * 1000 )
629
641
end if
630
642
end sub
631
643
@@ -645,8 +657,10 @@ function muxAnalytics() as Object
645
657
props .request_type = "captions"
646
658
end if
647
659
end if
660
+ if videoSegment .segDuration <> Invalid
661
+ props .request_media_duration = videoSegment .segDuration
662
+ end if
648
663
if videoSegment .downloadDuration <> Invalid
649
- props .request_media_duration = videoSegment .downloadDuration
650
664
date = m ._getDateTime ()
651
665
now = 0 # + date .AsSeconds () * 1000.0 # + date .GetMilliseconds ()
652
666
props .request_response_end = FormatJson (now )
@@ -716,6 +730,12 @@ function muxAnalytics() as Object
716
730
end if
717
731
end sub
718
732
733
+ prototype .useSSAIHandler = sub (useSSAI as String )
734
+ if useSSAI <> Invalid
735
+ m ._Flag_useSSAI = (useSSAI = "true" )
736
+ end if
737
+ end sub
738
+
719
739
prototype .videoErrorHandler = sub (error as Object )
720
740
errorCode = "0"
721
741
errorMessage = "Unknown"
@@ -730,7 +750,7 @@ function muxAnalytics() as Object
730
750
if error .errorMessage <> Invalid
731
751
errorMessage = error .errorMessage
732
752
end if
733
- if error .errorContext <> invalid
753
+ if error .errorContext <> Invalid
734
754
errorContext = error .errorContext
735
755
end if
736
756
end if
@@ -740,24 +760,47 @@ function muxAnalytics() as Object
740
760
prototype .rafEventHandler = sub (rafEvent )
741
761
data = rafEvent .getData ()
742
762
eventType = data .eventType
763
+ obj = data .obj
764
+ ctx = data .ctx
765
+
766
+ ' Only pull the pieces of data we care about
767
+ ' Previous instructions passed the full adIface in, which has a circular reference in some cases
768
+ adMetadata = {}
769
+ if obj <> Invalid
770
+ if obj .adurl <> Invalid
771
+ adMetadata .adTagUrl = obj .adurl
772
+ end if
773
+ end if
774
+
743
775
m ._advertProperties = {}
744
776
745
777
' Special case to handle if `renderStitchedStream` is used or not
746
778
if m ._Flag_useRenderStitchedStream = true
747
- m ._renderStitchedStreamRafEventHandler (eventType , data )
779
+ m ._renderStitchedStreamRafEventHandler (eventType , ctx , adMetadata )
748
780
else
749
- m ._rafEventHandler (eventType , data )
781
+ m ._rafEventHandler (eventType , ctx , adMetadata )
750
782
end if
751
783
end sub
752
784
753
- prototype ._rafEventhandler = sub (eventType , data )
785
+ prototype ._rafEventhandler = sub (eventType , ctx , adMetadata )
754
786
m ._Flag_isPaused = (eventType = "Pause" )
755
787
if eventType = "PodStart"
756
- m ._advertProperties = m ._getAdvertProperites (data . obj )
788
+ m ._advertProperties = m ._getAdvertProperites (adMetadata )
757
789
m ._addEventToQueue (m ._createEvent ("adbreakstart" ))
790
+ ' In the case that this is SSAI, we need to signal an adplay and adplaying event
791
+ if m ._Flag_useSSAI = true
792
+ m ._addEventToQueue (m ._createEvent ("adplay" ))
793
+ m ._addEventToQueue (m ._createEvent ("adplaying" ))
794
+ end if
758
795
else if eventType = "PodComplete"
759
796
m ._addEventToQueue (m ._createEvent ("adbreakend" ))
760
797
m ._Flag_FailedAdsErrorSet = false
798
+ ' In the case that this is SSAI, we need to signal a play and playing event
799
+ if m ._Flag_useSSAI = true
800
+ m ._Flag_isPaused = false
801
+ m ._triggerPlayEvent ()
802
+ m ._addEventToQueue (m ._createEvent ("playing" ))
803
+ end if
761
804
else if eventType = "Impression"
762
805
m ._addEventToQueue (m ._createEvent ("adimpresion" ))
763
806
else if eventType = "Pause"
@@ -778,11 +821,11 @@ function muxAnalytics() as Object
778
821
' CHECK FOR PREROLL
779
822
m ._viewPrerollPlayedCount ++
780
823
end if
781
- m ._advertProperties = m ._getAdvertProperites (data . ctx )
824
+ m ._advertProperties = m ._getAdvertProperites (ctx )
782
825
m ._addEventToQueue (m ._createEvent ("adplay" ))
783
826
m ._addEventToQueue (m ._createEvent ("adplaying" ))
784
827
else if eventType = "Resume"
785
- m ._advertProperties = m ._getAdvertProperites (data . ctx )
828
+ m ._advertProperties = m ._getAdvertProperites (ctx )
786
829
m ._addEventToQueue (m ._createEvent ("adplay" ))
787
830
m ._addEventToQueue (m ._createEvent ("adplaying" ))
788
831
else if eventType = "Complete"
@@ -793,12 +836,12 @@ function muxAnalytics() as Object
793
836
' this here for now for context in the future
794
837
' errorCode = ""
795
838
' errorMessage = ""
796
- ' if data. ctx <> Invalid
797
- ' if data. ctx.errcode <> Invalid
798
- ' errorCode = data. ctx.errcode
839
+ ' if ctx <> Invalid
840
+ ' if ctx.errcode <> Invalid
841
+ ' errorCode = ctx.errcode
799
842
' end if
800
- ' if data. ctx.errmsg <> Invalid
801
- ' errorMessage = data. ctx.errmsg
843
+ ' if ctx.errmsg <> Invalid
844
+ ' errorMessage = ctx.errmsg
802
845
' end if
803
846
' end if
804
847
m ._addEventToQueue (m ._createEvent ("aderror" ))
@@ -816,10 +859,10 @@ function muxAnalytics() as Object
816
859
end if
817
860
end sub
818
861
819
- prototype ._renderStitchedStreamRafEventHandler = sub (eventType , data )
862
+ prototype ._renderStitchedStreamRafEventHandler = sub (eventType , ctx , adMetadata )
820
863
if eventType = "AdStateChange"
821
- state = data . ctx .state
822
- m ._advertProperties = m ._getAdvertProperites (data . obj )
864
+ state = ctx .state
865
+ m ._advertProperties = m ._getAdvertProperites (adMetadata )
823
866
if state = "buffering"
824
867
' the buffering state is the first event we get in a new ad pod, so start
825
868
' our ad break here if we're not already in one
@@ -882,7 +925,7 @@ function muxAnalytics() as Object
882
925
else if eventType = "ContentStateChange"
883
926
' We really only care about this if we're _not_ in an ad break
884
927
if not m ._Flag_rssInAdBreak
885
- state = data . ctx .state
928
+ state = ctx .state
886
929
if state = "buffering"
887
930
' if m._Flag_isPaused
888
931
m ._Flag_isPaused = false
@@ -907,6 +950,7 @@ function muxAnalytics() as Object
907
950
908
951
prototype .pollingIntervalHandler = sub (pollingIntervalEvent )
909
952
if m .video = Invalid then return
953
+ if m ._Flag_isPaused = true then return
910
954
911
955
m ._setBufferingMetrics ()
912
956
m ._updateContentPlaybackTime ()
@@ -1191,7 +1235,7 @@ function muxAnalytics() as Object
1191
1235
props .viewer_device_manufacturer = deviceInfo .GetModelDetails ()["VendorName" ]
1192
1236
' If GetModel() is invalid, try the specific model number
1193
1237
seriesModel = deviceInfo .GetModel ()
1194
- if seriesModel = invalid
1238
+ if seriesModel = Invalid
1195
1239
seriesModel = deviceInfo .GetModelDetails ()["ModelNumber" ]
1196
1240
end if
1197
1241
props .viewer_device_model = seriesModel
@@ -1238,7 +1282,7 @@ function muxAnalytics() as Object
1238
1282
' Set called per video content'
1239
1283
prototype ._getVideoContentProperties = function (incomingContent as Object ) as Object
1240
1284
props = {}
1241
- if incomingContent <> invalid
1285
+ if incomingContent <> Invalid
1242
1286
content = incomingContent .GetFields ()
1243
1287
if content .title <> Invalid AND (type (content .title ) = "String" OR type (content .title ) = "roString " ) AND content .title <> ""
1244
1288
props .video_title = content .title
@@ -1298,12 +1342,15 @@ function muxAnalytics() as Object
1298
1342
prototype ._getAdvertProperites = function (adData as Object ) as Object
1299
1343
props = {}
1300
1344
if adData <> Invalid
1301
- if adData .ad <> Invalid
1302
- if adData .adIndex <> Invalid AND adData .adIndex = 1 'preroll only'
1303
- if adData .ad .streams <> Invalid
1304
- if adData .ad .streams .count () > 0
1305
- if adData .ad .streams [0 ].url <> Invalid
1306
- adUrl = adData .ad .streams [0 ].url
1345
+ ad = adData .ad
1346
+ adIndex = adData .adIndex
1347
+ adTagUrl = adData .adTagUrl
1348
+ if ad <> Invalid
1349
+ if adIndex <> Invalid AND adIndex = 1 'preroll only'
1350
+ if ad .streams <> Invalid
1351
+ if ad .streams .count () > 0
1352
+ if ad .streams [0 ].url <> Invalid
1353
+ adUrl = ad .streams [0 ].url
1307
1354
if adUrl <> Invalid AND adUrl <> ""
1308
1355
props .view_preroll_ad_asset_hostname = m ._getHostname (adUrl )
1309
1356
props .view_preroll_ad_asset_domain = m ._getDomain (adUrl )
@@ -1313,9 +1360,9 @@ function muxAnalytics() as Object
1313
1360
end if
1314
1361
end if
1315
1362
end if
1316
- if adData . adurl <> Invalid AND adData . adurl <> ""
1317
- props .view_preroll_ad_tag_hostname = m ._getHostname (adData . adurl )
1318
- props .view_preroll_ad_tag_domain = m ._getDomain (adData . adurl )
1363
+ if adTagUrl <> Invalid AND adTagUrl <> ""
1364
+ props .view_preroll_ad_tag_hostname = m ._getHostname (adTagUrl )
1365
+ props .view_preroll_ad_tag_domain = m ._getDomain (adTagUrl )
1319
1366
end if
1320
1367
end if
1321
1368
return props
@@ -1436,7 +1483,7 @@ function muxAnalytics() as Object
1436
1483
playerInitTime = m ._configProperties .player_init_time
1437
1484
end if
1438
1485
1439
- if playerInitTime <> invalid
1486
+ if playerInitTime <> Invalid
1440
1487
if playerInitTime > 0
1441
1488
props .player_startup_time = Int (m ._startTimestamp - playerInitTime )
1442
1489
if m ._viewTimeToFirstFrame <> Invalid AND m ._viewTimeToFirstFrame <> 0
@@ -1930,8 +1977,8 @@ function muxAnalytics() as Object
1930
1977
' ' //////////////////////////////////////////////////////////////
1931
1978
1932
1979
prototype ._min = function (a , b ) as object
1933
- if a = invalid then a = 0
1934
- if b = invalid then b = 0
1980
+ if a = Invalid then a = 0
1981
+ if b = Invalid then b = 0
1935
1982
1936
1983
if a < b then
1937
1984
return a
@@ -1941,8 +1988,8 @@ function muxAnalytics() as Object
1941
1988
end function
1942
1989
1943
1990
prototype ._max = function (a , b ) as object
1944
- if a = invalid then a = 0
1945
- if b = invalid then b = 0
1991
+ if a = Invalid then a = 0
1992
+ if b = Invalid then b = 0
1946
1993
1947
1994
if a < b then
1948
1995
return b
@@ -1952,7 +1999,7 @@ function muxAnalytics() as Object
1952
1999
end function
1953
2000
1954
2001
prototype ._safeAdd = function (var , addValue ) as object
1955
- if var = invalid then
2002
+ if var = Invalid then
1956
2003
return addValue
1957
2004
else
1958
2005
return var + addValue
0 commit comments