OptiViewAds

OptiView Ads SDK for Roku, version 1.2.0

SceneGraph component that inserts OptiView Ads breaks into clear live HLS on Roku through one application-owned Video node: client-side stitching of Google Ad Manager pods (SGAI), or the channel's Google DAI live stream when the break manifest selects server-side ad insertion for TV devices (SSAI).

Fields

Bind and observe these SceneGraph fields on the OptiViewAds node.

FieldTypeUseDescription
videoNodenodewriteThe application's Video node. Bind it before startSession; changing it during a session requires a new session (ROKU-VIDEO-BINDING-CHANGED). The SDK never sets this node's source.
adUiNodenodewriteThe node Google IMA draws its ad UI into (for example the skip button or ad countdown).
operationResultassocarrayobserveResult of an asynchronous call: operationId, generation, status and an optional reason. A ready result of startSession carries playbackUrl, deliveryMode and, in SSAI, ssaiStream. See Operation results.
sdkEventassocarrayobserveAd, break and status events (see Events). Each event carries type, generation and a sequence; break events carry the break and its occurrence.
diagnosticEventassocarrayobserveDiagnostics with code, an optional reason and code-specific context (see Diagnostics).
gatewayRequestassocarrayobserveInterception and macro requests (kind: manifest-request, manifest-response or asset-parameter-macros) with requestId, generation, value and context. Answer each with resolveGateway within two seconds.
playerClockAnchorassocarraywriteOptional, externally verified clock anchor used only when native Video.positionInfo UTC is unavailable: generation, source: "program-date-time", verified: true, position (seconds on the Video) and pdt (source Program Date Time, epoch seconds). Set { generation, invalidate: true } to withdraw it. A rejected anchor reports ROKU-PLAYER-CLOCK-INVALID.

Functions

Call with CallFunc. Asynchronous calls return an operation ID and report on operationResult; getters return snapshots.

startSession

startSession(config as Object) as Integer

Starts a session for one channel and returns an operation ID. Results arrive on operationResult; on ready, load its playbackUrl into a ContentNode (streamFormat: "hls") on the bound Video. ready waits until the first break manifest has decided the delivery mode; if that manifest fails, the session continues content-first in SGAI. A new startSession supersedes the previous session.

Operation statuses: ready, error, cancelled

endSession

endSession() as Integer

Ends ad insertion. While playback is still attached it reports draining (playback-detach-required) and keeps the published stream available; stop and detach the Video, then the session reports ended.

Operation statuses: ended, draining

destroy

destroy() as Integer

Releases the component's workers. Refuses with playback-detach-required while the Video still uses the SDK's URL; stop and detach playback first.

Operation statuses: destroyed, error

updateAssetParameters

updateAssetParameters(parameters as Object) as Integer

Replaces the runtime ad tag parameters used for future breaks (merged with the start config and manifest parameters). A break already committed is not changed. Requires an active session.

Operation statuses: updated, error

updateAssetParameterMacros

updateAssetParameterMacros(update as Object) as Integer

Sets or removes macro values: { set: { NAME: value }, remove: ["NAME"] }. Requires an active session.

Operation statuses: updated, error

updateRafMetadata

updateRafMetadata(metadata as Object) as Integer

SSAI: updates the Roku Advertising Framework content metadata { contentId, contentGenre, kidsContent, contentLength }.

Operation statuses: updated, error

getAdBreakStatus

getAdBreakStatus() as Object

Snapshot of the break state: phase, state, generation, ticking, the selected break and its countdown, all known breaks (breakId, occurrence, state, reason, reasonDetail) and deliveryMode. When playback must be restarted it adds recoveryRequired, reloadRequired and reloadReason.

isSessionActive

isSessionActive() as Boolean

Whether ad insertion is starting or active. It does not report whether the Video is playing.

getSessionInfo

getSessionInfo() as Object

Snapshot of the session: generation, active, destroyed and, during a session, state, playbackEpoch, recoveryRequired, reloadRequired, channelId, deliveryMode, deliveryModeSource and publishedSourceEnd (UTC, ISO 8601) when available.

getCapabilities

getCapabilities() as Object

Describes what the installed version implements (see Capabilities). Check it instead of assuming a feature.

resolveGateway

resolveGateway(result as Object) as Boolean

Answers a gatewayRequest: { requestId, generation, status, value } with status "ok" or "error". Returns false for an unknown or stale request. Without an answer within two seconds the SDK uses the original request, response or registered macro values and reports a diagnostic.

Start configuration

Keys of the object passed to startSession. Built-in macros: $OPTIVIEW_USER_AGENT$, $OPTIVIEW_PLAYER_WIDTH$, $OPTIVIEW_PLAYER_HEIGHT$, $OPTIVIEW_BREAK_DURATION_SECONDS$, $OPTIVIEW_BREAK_DURATION_MS$.

KeyTypeDescription
contentUrl requiredStringLive HLS master playlist.
manifestUrl requiredStringBreak manifest URL. Network manifests must carry a valid detached signature.
contentHeadersObjectHTTP headers sent with content playlist and segment requests.
assetParametersObjectAd tag parameters added to Google Ad Manager requests, merged with the manifest's parameters.
assetParameterMacrosObjectInitial values for $NAME$ macros in asset parameters.
userAgentStringValue of the built-in $OPTIVIEW_USER_AGENT$ macro.
playerWidthIntegerValue of the built-in $OPTIVIEW_PLAYER_WIDTH$ macro.
playerHeightIntegerValue of the built-in $OPTIVIEW_PLAYER_HEIGHT$ macro.
requestInterceptorBooleanRoute each manifest request through gatewayRequest (manifest-request).
responseInterceptorBooleanRoute each manifest response through gatewayRequest (manifest-response).
macroResolverBooleanResolve macro values through gatewayRequest (asset-parameter-macros).
alignmentToleranceSecondsFloatAllowed alignment difference between renditions and at the return to content, 0.002 to 0.250 seconds. Default 0.250.
modeString"sgai" or "ssai": overrides the break manifest's delivery rules (DA-DELIVERY-MODE-OVERRIDDEN).
rafObjectSSAI: { contentId, contentGenre, kidsContent, contentLength } for Roku Advertising Framework measurement.
streamActivityMonitorIdStringSSAI: passed to the Google DAI stream request.

Operation results

StatusMeaning
readyThe session is ready; the result carries playbackUrl and deliveryMode.
errorThe call failed; reason names why (for example missing-session-url, invalid-configuration, invalid-video-binding, invalid-alignment-tolerance, invalid-delivery-mode, invalid-raf-metadata, invalid-stream-activity-monitor-id, invalid-parameters, invalid-macros, playback-detach-required, unsupported-state, no-session, destroyed).
cancelledSuperseded by a newer call or ended with the session (superseded, session-ended).
drainingendSession while playback is attached; detach to finish.
endedThe session ended.
destroyedThe component released its workers.
updatedA parameter, macro or RAF update was applied.

Events

Delivered on sdkEvent. Tracking events come only from genuine IMA callbacks.

TypeMeaning
adbreakbeginA break started playing at its actual splice point.
adbeginAn ad in the pod started (from a genuine IMA callback).
adfirstquartileFirst quartile of the current ad.
admidpointMidpoint of the current ad.
adthirdquartileThird quartile of the current ad.
adendThe current ad completed.
adbreakendThe break completed.
aderrorAn ad or break failed. A failure after publication also sets recoveryRequired; start a new session.
adbreakskippedA break was refused before anything was shown and content kept playing. reason: late, not-ready, preparation-failed, unsupported, overlap, start-delay, removed, insufficient-remaining or resource-limit; reasonDetail names the specific cause, with podEvidence or preparationEvidence where available.
adbreakstatusBreak state and countdown updates (same shape as getAdBreakStatus).
adchannelchangeThe break manifest moved to another ads channel; carries previousChannelId, channelId, previousDeliveryMode and deliveryMode.
playbackreloadrequiredPlayback must be restarted in a new session (for example delivery-mode-changed, ssai-stream-changed, or a viewer seek that fenced tracking).
adinteractiveexitSSAI: the viewer left a Roku Advertising Framework interactive ad; stop playback and restore focus.

Diagnostics

Delivered on diagnosticEvent.

Roku-only codes

CodeMeaning
ROKU-BREAK-START-SHIFTEDA break's start moved to a segment boundary. reason (earlier/later), signed shiftSeconds, requestedStart, spliceStart.
ROKU-RESUME-SHIFTEDThe return to content moved content by more than 1 ms. reason (delayed/advanced), signed shiftSeconds, nearestBoundary.
ROKU-BREAK-HELDPublication waited for a pod that was still preparing. reason (pod-ready/skipped), heldSeconds.
ROKU-PREPARATION-RETRYA failed pod download is being retried. reason, attempt.
ROKU-PREPARATION-FAILEDA pod could not be prepared; the break is skipped, or ends if it was already published. reason and optional evidence.
ROKU-MEDIA-FAILEDContent or ad publication failed. Before startup completes it fails the start; after publication it ends playback.
ROKU-PUBLICATION-FAILEDThe local playlist snapshot was invalid.
ROKU-PROXY-ERRORThe local HLS proxy failed or did not stop in time.
ROKU-SOURCE-EVIDENCEInformational: content verification is waiting for evidence (for example a slow segment). Playback continues.
ROKU-MANIFEST-FAILEDA break manifest request failed.
ROKU-MANIFEST-INVALIDA break manifest failed validation; it is not used and is polled again after 5 s.
ROKU-MANIFEST-UNSUPPORTEDThe manifest cannot be used for Roku insertion (for example its timebase is not wallclock).
ROKU-POLLING-INVALIDThe manifest's polling instructions were invalid; the manifest is polled again after 5 s.
ROKU-RESOURCE-LIMITToo many breaks: a manifest over the limit is not used; a full session ledger stops ad insertion for the session.
ROKU-IMA-FAILEDIMA pod serving could not be set up; it is retried after 10 s and breaks due meanwhile are skipped.
ROKU-IMA-STOP-TIMEOUTThe IMA pod-serving task did not stop in time during cleanup.
ROKU-DAI-STOP-TIMEOUTSSAI: the IMA DAI task did not stop in time during cleanup.
ROKU-PARAMETERS-FAILEDUpdating the ad tag parameters failed or timed out; the break is skipped.
ROKU-SSAI-PARAMETERS-FAILEDSSAI: updating the DAI ad tag parameters failed or timed out.
ROKU-SSAI-CLIENT-BREAKS-IGNOREDSSAI: event-triggered manifest breaks are not rendered.
ROKU-MACRO-FAILEDThe application's macro resolver failed or timed out; registered values are used.
ROKU-PLAYER-CLOCK-INVALIDA supplied playerClockAnchor was rejected; it needs a verified source Program Date Time.
ROKU-PLAYBACK-EPOCH-CHANGEDPlayback jumped (for example a viewer seek); old tracking is fenced and a reload is required.
ROKU-VIDEO-BINDING-CHANGEDvideoNode changed during a session; start a new session.

Shared codes emitted on Roku

CodeLevelMeaning
DA-MANIFEST-POLLEDinfoA manifest poll refresh succeeded (cadence follows the manifest polling config).
DA-MANIFEST-CHANNEL-CHANGEDinfoA polled manifest describes a different ads channel (channelId, GAM identity or timebase changed); the SDK re-aligned its ad setup and resolved delivery mode again while the session and content playback continued. context: previousChannelId, channelId, reason, manifestUrl.
DA-MANIFEST-INTERCEPT-FAILEDwarnThe customer manifest-response interceptor threw; the un-modified parsed manifest was used instead.
DA-MANIFEST-REQUEST-INTERCEPT-FAILEDwarnThe customer manifest-request interceptor threw; the normal network fetch of the original URL was used instead.
DA-DELIVERY-MODE-RESOLVEDinfoDelivery mode (sgai/ssai) resolved for the session at start and again on an ads-channel switch from the manifest's delivery rules (or the explicit client config), with the detected device profile.
DA-DELIVERY-MODE-UNKNOWNwarnThe matching delivery rule carried an unrecognized mode value; sgai is used (forward compatibility).
DA-DELIVERY-MODE-OVERRIDDENinfoThe manifest's delivery rules resolved a different mode, but the explicit client config takes precedence.
DA-DELIVERY-MODE-CHANGE-IGNOREDwarnAn ordinary manifest poll resolves a different delivery mode; the mode pinned for the session stays in force. An ads-channel switch resolves the mode again.
DA-GAM-CONFIG-MISSINGerrorThe break manifest carries no usable "gam" vendorConfiguration entry; GAM assets are skipped.
DA-GAM-START-DEFERREDinfoThe SGAI IMA stream request is deferred until the configured ad start delay has been played; context includes adStartDelaySec.
DA-ASSET-PARAMETERS-UPDATEDinfoThe break manifest's session-level asset parameters changed; the merged parameters were pushed to the active GAM stream. context: source ('manifest'), keys (parameter names only, never values).
DA-ASSET-MACRO-UNKNOWNwarnAn asset parameter value contained a macro the SDK has no value for (an unknown or unavailable OptiView macro, or a registered customer macro that returned no value); the parameter was still sent, with the macro kept as its literal token. Raised once per parameter key and macro. context: key, macro, breakId, assetId.
DA-SSAI-UNAVAILABLEerrorThe manifest selected ssai delivery but no vendor configuration can provide a stitched stream (no gam entry with an assetKey); at start the session fails, while on a channel switch the session stays in sgai.
DA-SSAI-SESSION-FAILEDerrorThe SSAI session failed to start (IMA stream init, stream id, or stitched-stream load).
DA-SSAI-IMA-ERRORerrorIMA reported an error during the SSAI stream session.
DA-BREAK-ABANDONEDwarnA break was still in flight when the session was torn down (endSession, destroy, or a startSession over an active session). context: breakId, cause, phase, unbalancedAdBegin, adIndex, totalAds, assetId.

Capabilities

Returned by getCapabilities() for this version.

KeyValueMeaning
deliveryModes["sgai", "ssai"]Supported delivery modes.
ssaiVendor"gam-dai-full-service"SSAI vendor integration.
ssaiStreamTypes["live"]SSAI stream types.
ssaiFormats["hls"]SSAI stream formats.
ssaiClientBreaksfalseWhether event-triggered manifest breaks render in SSAI.
rafMeasurementtrueRoku Advertising Framework measurement in SSAI.
rafInteractiveAdstrueRoku Advertising Framework interactive ads in SSAI.
readyAwaitsDeliveryModetrueready waits for the first manifest to decide the delivery mode.
timebase"wallclock"Break manifest timebase supported for insertion.
sourceProgramDateTimeRequiredtrueSGAI needs EXT-X-PROGRAM-DATE-TIME on the content.
insertionMode"replace"Ads replace content for their duration.
appOwnedVideotrueThe application owns the Video node.
signedManifeststrueNetwork break manifests must be signed.
clearMuxedTstrueClear muxed MPEG-TS content.
cmaftrueCMAF (fMP4) content and ads.
demuxedtrueSeparate audio and video renditions.
abrtrueAdaptive bitrate across several renditions.
maxRenditions8Maximum number of renditions stitched together.
compatibleTopologyRequiredtrueAd renditions must be compatible with the content.
drmfalseEncrypted content.
lowLatencyPartsfalseLow-latency HLS parts.
sourceHoldBacktruePublication honours the stream's HOLD-BACK.
unalignedBreakStart"nearest-segment-boundary"How a break start between segment boundaries is handled.
sourceChangesAtBreaksfalseWhether the Video source changes at ad boundaries.
shutdownRequiresDetachedPlaybacktruePlayback must be detached before destroy.
nativeUtcClocktrueNative Video.positionInfo UTC is used as the player clock.
externalClockAnchorSupportedtrueplayerClockAnchor is accepted as a fallback.
initialTuneInPolicy"content-until-prepared"Content plays first; ads join once prepared.
lateOpportunityPolicy"skip"Breaks already exposed without a ready pod are skipped.
alignmentToleranceSeconds0.250Default alignmentToleranceSeconds.
supportedAlignmentToleranceSeconds[0.002, 0.250]Accepted range of alignmentToleranceSeconds.