Skip to content

Commit 4aac087

Browse files
authored
Merge pull request #106 from THEOplayer/bugfix/conviva/fix-encodingtype
Bugfix/conviva/fix encodingtype
2 parents 4b1978d + 02d781e commit 4aac087

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Conviva
2222
- Fixed an issue where the initial metadata passed to the convivaConnector was not persistent across Conviva sessions.
2323
- Fixed an issue where the session's assetName was not configurable by setContentInfo, which has higher precedence than source.metadata.title.
24+
- Fixed an issue with the encodingType, where sometimes the encodingType of the previous session was reported
2425

2526
## [10.7.0] - 2025-12-18
2627

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

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class PlayerHandler {
3535
private weak var endpoints: ConvivaEndpoints?
3636
private weak var storage: ConvivaStorage?
3737
private var playerState: PlayerState = .CONVIVA_UNKNOWN
38+
39+
private var unreportedEncodingType: String?
40+
private var encodingTypeIsPending = false
3841

3942
init(endpoints: ConvivaEndpoints, storage: ConvivaStorage, convivaMetadata: [String:Any]) {
4043
self.endpoints = endpoints
@@ -189,23 +192,35 @@ class PlayerHandler {
189192
func currentSourceChange(event: CurrentSourceChangeEvent) {
190193
log("handling currentSourceChange")
191194
guard let sourceType = event.currentSource?.type else {
195+
log("not processing currentSourceChange")
192196
return
193197
}
194-
var encodingType: String?
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
195202
switch sourceType.lowercased() {
196203
case "application/vnd.theo.hesp+json":
197-
encodingType = "HESP"
204+
calculatedEncodingType = "HESP"
198205
case "application/x-mpegurl",
199206
"application/vnd.apple.mpegurl",
200207
"video/mp2t":
201-
encodingType = "HLS"
208+
calculatedEncodingType = "HLS"
202209
default:
203-
encodingType = nil
210+
calculatedEncodingType = nil
204211
}
205212

206-
if self.storage?.metadataEntryForKey(ENCODING_TYPE) == nil,
207-
let encodingType = encodingType {
208-
self.setContentInfo([ENCODING_TYPE: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+
}
209224
}
210225
}
211226

@@ -251,6 +266,20 @@ class PlayerHandler {
251266

252267
let adDescriptionMetadata: [String: Any] = collectAdDescriptionMetadata(from: convivaSessionSource.description)
253268
metadata.merge(adDescriptionMetadata) { (_, new) in new }
269+
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+
*/
275+
if let encodingType = self.storage?.metadataEntryForKey(ENCODING_TYPE) as? String ?? self.unreportedEncodingType {
276+
log("reporting encodingType \(self.unreportedEncodingType ?? "nil")")
277+
metadata[ENCODING_TYPE] = encodingType
278+
self.unreportedEncodingType = nil
279+
} else {
280+
self.encodingTypeIsPending = true
281+
log("marked encodingType as pending")
282+
}
254283

255284
self.setContentInfo(metadata)
256285
}

0 commit comments

Comments
 (0)