Skip to content

Commit

Permalink
Enable ping scheduler only if ping feature is requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegRyz committed Sep 6, 2024
1 parent 82305b6 commit 0d77e3c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ internal class PingScheduler(
}
}

fun onStart() =
performPing(uplynkDescriptionConverter.buildStartPingUrl(prefix, sessionId, Duration.ZERO))
fun onStart(time: Duration) =
performPing(uplynkDescriptionConverter.buildStartPingUrl(prefix, sessionId, time))


fun onSeeking(time: Duration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ internal class UplynkAdIntegration(
player.addEventListener(PlayerEventTypes.SEEKED) {
pingScheduler?.onSeeked(it.currentTime.toDuration(DurationUnit.SECONDS))
}

player.addEventListener(PlayerEventTypes.PLAY) {
pingScheduler?.onStart(it.currentTime.toDuration(DurationUnit.SECONDS))
}
}

override suspend fun resetSource() {
Expand Down Expand Up @@ -80,15 +84,16 @@ internal class UplynkAdIntegration(
add(0, newUplynkSource)
})

pingScheduler = PingScheduler(
uplynkApi,
uplynkDescriptionConverter,
minimalResponse.prefix,
minimalResponse.sid,
eventDispatcher,
adScheduler!!
)
pingScheduler?.onStart()
if (UplynkPingFeatures.from(ssaiDescription) != UplynkPingFeatures.NO_PING) {
pingScheduler = PingScheduler(
uplynkApi,
uplynkDescriptionConverter,
minimalResponse.prefix,
minimalResponse.sid,
eventDispatcher,
adScheduler!!
)
}

if (ssaiDescription.assetInfo) {
uplynkDescriptionConverter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.theoplayer.android.connector.uplynk.internal

import com.theoplayer.android.connector.uplynk.UplynkAssetType
import com.theoplayer.android.connector.uplynk.UplynkSsaiDescription

enum class UplynkPingFeatures(val pingfValue: Int) {
NO_PING(0),
AD_IMPRESSIONS(1),
FW_VIDEO_VIEWS(2),
AD_IMPRESSIONS_AND_FW_VIDEO_VIEWS(3),
LINEAR_AD_DATA(4);

companion object {
fun from(ssaiDescription: UplynkSsaiDescription): UplynkPingFeatures {
val isVod = ssaiDescription.assetType == UplynkAssetType.ASSET
with(ssaiDescription.pingConfiguration) {
return when {
isVod && adImpressions && freeWheelVideoViews -> AD_IMPRESSIONS_AND_FW_VIDEO_VIEWS
isVod && adImpressions -> AD_IMPRESSIONS
isVod && freeWheelVideoViews -> FW_VIDEO_VIEWS
!isVod && linearAdData -> LINEAR_AD_DATA
else -> NO_PING
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import com.theoplayer.android.connector.uplynk.UplynkAssetType
import com.theoplayer.android.connector.uplynk.UplynkSsaiDescription
import kotlin.time.Duration

private const val AD_IMPRESSIONS = 1
private const val FW_VIDEO_VIEWS = 2
private const val LINEAR_AD_DATA = 4

internal class UplynkSsaiDescriptionConverter {
private val DEFAULT_PREFIX = "https://content.uplynk.com"

Expand Down Expand Up @@ -44,17 +40,11 @@ internal class UplynkSsaiDescriptionConverter {

private val UplynkSsaiDescription.pingParameters: String
get() {
val isLive = assetType == UplynkAssetType.ASSET

val features = with(pingConfiguration) {
(AD_IMPRESSIONS.takeIf { !isLive && adImpressions } ?: 0) +
(FW_VIDEO_VIEWS.takeIf { !isLive && freeWheelVideoViews } ?: 0) +
(LINEAR_AD_DATA.takeIf { isLive && linearAdData } ?: 0)
}
return if (features == 0) {
val feature = UplynkPingFeatures.from(this)
return if (feature == UplynkPingFeatures.NO_PING) {
"ad.pingc=0"
} else {
"ad.pingc=1&ad.pingf=$features"
"ad.pingc=1&ad.pingf=${feature.pingfValue}"
}
}

Expand Down

0 comments on commit 0d77e3c

Please sign in to comment.