Skip to content

Commit 33c5142

Browse files
committed
Add comments to explain encodingType reporting flows for HLS and HESP based streams
1 parent c284e6d commit 33c5142

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

Code/Conviva/Source/Base/Events/ConvivaHandlers/PlayerHandler.swift

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,32 @@ class PlayerHandler {
195195
log("not processing currentSourceChange")
196196
return
197197
}
198-
self.unreportedEncodingType = nil
198+
199+
/* EncodingType reporting: The currentSourceChange event is used to extract the encoding type of the internally selected source. For HLS, this event is dispatched right before the sourceChange event. For HESP sources, it is dispatched after the play event, when a valid endpoint has been selected.*/
200+
201+
var calculatedEncodingType: String? = nil
199202
switch sourceType.lowercased() {
200203
case "application/vnd.theo.hesp+json":
201-
self.unreportedEncodingType = "HESP"
204+
calculatedEncodingType = "HESP"
202205
case "application/x-mpegurl",
203206
"application/vnd.apple.mpegurl",
204207
"video/mp2t":
205-
self.unreportedEncodingType = "HLS"
208+
calculatedEncodingType = "HLS"
206209
default:
207-
self.unreportedEncodingType = nil
210+
calculatedEncodingType = nil
208211
}
209212

210-
if self.encodingTypeIsPending,
211-
let encodingType = self.storage?.metadataEntryForKey(ENCODING_TYPE) as? String ?? self.unreportedEncodingType {
212-
// report the pending encodingType and reset the pending state
213-
self.setContentInfo([ENCODING_TYPE:encodingType])
214-
self.unreportedEncodingType = nil
215-
self.encodingTypeIsPending = false
216-
log("unreportedEncodingType reset after processing pending encodingtype")
213+
if let encodingType = self.storage?.metadataEntryForKey(ENCODING_TYPE) as? String ?? calculatedEncodingType {
214+
/* For HESP sources the encodingType is not available at session startup (play event) and encodingType will have been marked as pending. Once the currentSourceChange event is dispatched, this mark indicates the calculated encodingType can be pushed immediately to conviva and the mark can be reset. */
215+
if self.encodingTypeIsPending {
216+
self.setContentInfo([ENCODING_TYPE:encodingType])
217+
self.unreportedEncodingType = nil
218+
self.encodingTypeIsPending = false
219+
}
220+
/* For HLS sources we cache the encoding type till the play event (Conviva session creation), at which the cached value will be pushed to conviva and the caching is reset to prevent further reporting. */
221+
else {
222+
self.unreportedEncodingType = encodingType
223+
}
217224
}
218225
}
219226

@@ -260,15 +267,18 @@ class PlayerHandler {
260267
let adDescriptionMetadata: [String: Any] = collectAdDescriptionMetadata(from: convivaSessionSource.description)
261268
metadata.merge(adDescriptionMetadata) { (_, new) in new }
262269

263-
// Do not override `encoding_type` value if already set by the customer.
270+
/* EncodingType reporting:
271+
1. A customer set encodingType always has precedence over the calculated encodingtype
272+
2. For HLS sources (unreportedEncodingType is set on earlier currentSourceChange event) we can now report the encodingType.
273+
3. For HESP sources (unreportedEncodingType is still nil) we mark the encodingType as pending, because the currentSourceChange event will be dispatched after the play event).
274+
*/
264275
if let encodingType = self.storage?.metadataEntryForKey(ENCODING_TYPE) as? String ?? self.unreportedEncodingType {
265276
log("reporting encodingType \(self.unreportedEncodingType ?? "nil")")
266277
metadata[ENCODING_TYPE] = encodingType
267278
self.unreportedEncodingType = nil
268-
log("unreportedEncodingType reset")
269279
} else {
270280
self.encodingTypeIsPending = true
271-
log("mark encodingType as pending")
281+
log("marked encodingType as pending")
272282
}
273283

274284
self.setContentInfo(metadata)

0 commit comments

Comments
 (0)