diff --git a/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultPlaybackInfoProvider.java b/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultPlaybackInfoProvider.java index 3b47178..e8cab57 100644 --- a/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultPlaybackInfoProvider.java +++ b/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultPlaybackInfoProvider.java @@ -32,8 +32,11 @@ public HashMap getPlaybackVideoData() { VideoQuality playbackVideoData = player.getPlaybackVideoData(); if (playbackVideoData != null) { videoData.put(ConvivaSdkConstants.PLAYBACK.RESOLUTION, new Object[]{playbackVideoData.getWidth(), playbackVideoData.getHeight()}); - videoData.put(ConvivaSdkConstants.PLAYBACK.BITRATE, new Object[]{playbackVideoData.getBitrate() / 1000}); - int averageBitrate = playbackVideoData.getAverageBitrate(); + final int peakBitrate = playbackVideoData.getPeakBitrate(); + if (peakBitrate != VideoQuality.BITRATE_NO_VALUE) { + videoData.put(ConvivaSdkConstants.PLAYBACK.BITRATE, new Object[]{peakBitrate / 1000}); + } + final int averageBitrate = playbackVideoData.getAverageBitrate(); if (averageBitrate != VideoQuality.BITRATE_NO_VALUE) { videoData.put(ConvivaSdkConstants.PLAYBACK.AVG_BITRATE, new Object[]{averageBitrate / 1000}); } diff --git a/conviva/src/test/kotlin/com/bitmovin/analytics/conviva/ConvivaAnalyticsIntegrationTest.kt b/conviva/src/test/kotlin/com/bitmovin/analytics/conviva/ConvivaAnalyticsIntegrationTest.kt index f302f6e..38a19c3 100644 --- a/conviva/src/test/kotlin/com/bitmovin/analytics/conviva/ConvivaAnalyticsIntegrationTest.kt +++ b/conviva/src/test/kotlin/com/bitmovin/analytics/conviva/ConvivaAnalyticsIntegrationTest.kt @@ -10,6 +10,7 @@ import com.bitmovin.player.api.event.Event import com.bitmovin.player.api.event.EventListener import com.bitmovin.player.api.event.PlayerEvent import com.bitmovin.player.api.event.SourceEvent +import com.bitmovin.player.api.media.Quality import com.bitmovin.player.api.media.video.quality.VideoQuality import com.conviva.sdk.ConvivaAdAnalytics import com.conviva.sdk.ConvivaSdkConstants @@ -130,6 +131,35 @@ class ConvivaAnalyticsIntegrationTest { verify { adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RENDERED_FRAMERATE, 10) } } + @Test + fun `does not report bitrate, if not available`() { + every { ssaiApi.isAdBreakActive } returns true + Quality.Companion.BITRATE_NO_VALUE + val newVideoQuality = VideoQuality( + id = "id", + label = "label", + bitrate = Quality.Companion.BITRATE_NO_VALUE, + averageBitrate = Quality.Companion.BITRATE_NO_VALUE, + peakBitrate = Quality.Companion.BITRATE_NO_VALUE, + codec = "codec", + frameRate = 10.3F, + width = 400, + height = 300, + ) + every { mockedPlayer.playbackVideoData } returns newVideoQuality + + player.listeners[PlayerEvent.VideoPlaybackQualityChanged::class]?.forEach { onEvent -> + onEvent(PlayerEvent.VideoPlaybackQualityChanged(null, newVideoQuality)) + } + + verify(exactly = 0) { + adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.BITRATE, any()) + adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.AVG_BITRATE, any()) + } + verify { adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RESOLUTION, 400, 300) } + verify { adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RENDERED_FRAMERATE, 10) } + } + companion object { @JvmStatic @BeforeClass