diff --git a/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultPlaybackStateProvider.java b/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultPlaybackInfoProvider.java similarity index 67% rename from conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultPlaybackStateProvider.java rename to conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultPlaybackInfoProvider.java index 865f27f..3034990 100644 --- a/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultPlaybackStateProvider.java +++ b/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultPlaybackInfoProvider.java @@ -1,12 +1,13 @@ package com.bitmovin.analytics.conviva.ssai; import com.bitmovin.player.api.Player; +import com.bitmovin.player.api.media.video.quality.VideoQuality; import com.conviva.sdk.ConvivaSdkConstants; -public class DefaultPlaybackStateProvider implements PlaybackStateProvider { +public class DefaultPlaybackInfoProvider implements PlaybackInfoProvider { private final Player player; - public DefaultPlaybackStateProvider(Player player) { + public DefaultPlaybackInfoProvider(Player player) { this.player = player; } @@ -22,4 +23,9 @@ public ConvivaSdkConstants.PlayerState getPlayerState() { } return state; } + + @Override + public VideoQuality getPlaybackVideoData() { + return player.getPlaybackVideoData(); + } } diff --git a/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultSsaiApi.java b/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultSsaiApi.java index 7246925..2c65e37 100644 --- a/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultSsaiApi.java +++ b/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/DefaultSsaiApi.java @@ -2,6 +2,7 @@ import android.util.Log; +import com.bitmovin.player.api.media.video.quality.VideoQuality; import com.conviva.sdk.ConvivaAdAnalytics; import com.conviva.sdk.ConvivaSdkConstants; import com.conviva.sdk.ConvivaVideoAnalytics; @@ -14,9 +15,9 @@ public class DefaultSsaiApi implements SsaiApi { private static final String TAG = "DefaultSsaiApi"; private final ConvivaVideoAnalytics convivaVideoAnalytics; private final ConvivaAdAnalytics convivaAdAnalytics; - private final PlaybackStateProvider player; + private final PlaybackInfoProvider player; - public DefaultSsaiApi(ConvivaVideoAnalytics convivaVideoAnalytics, ConvivaAdAnalytics convivaAdAnalytics, PlaybackStateProvider player) { + public DefaultSsaiApi(ConvivaVideoAnalytics convivaVideoAnalytics, ConvivaAdAnalytics convivaAdAnalytics, PlaybackInfoProvider player) { this.convivaVideoAnalytics = convivaVideoAnalytics; this.convivaAdAnalytics = convivaAdAnalytics; this.player = player; @@ -70,7 +71,17 @@ public void reportAdStarted(AdInfo adInfo) { } Log.d(TAG, "Server side ad started"); convivaAdAnalytics.reportAdStarted(convertToConvivaAdInfo(adInfo)); + reportInitialAdMetrics(); + } + + private void reportInitialAdMetrics() { convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAYER_STATE, player.getPlayerState()); + VideoQuality videoQuality = player.getPlaybackVideoData(); + if (videoQuality != null) { + convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RESOLUTION, videoQuality.getHeight(), videoQuality.getWidth()); + convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.BITRATE, videoQuality.getBitrate() / 1000); + convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RENDERED_FRAMERATE, Math.round(videoQuality.getFrameRate())); + } } @Override diff --git a/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/PlaybackStateProvider.java b/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/PlaybackInfoProvider.java similarity index 50% rename from conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/PlaybackStateProvider.java rename to conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/PlaybackInfoProvider.java index 13969e9..2891669 100644 --- a/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/PlaybackStateProvider.java +++ b/conviva/src/main/java/com/bitmovin/analytics/conviva/ssai/PlaybackInfoProvider.java @@ -1,7 +1,9 @@ package com.bitmovin.analytics.conviva.ssai; +import com.bitmovin.player.api.media.video.quality.VideoQuality; import com.conviva.sdk.ConvivaSdkConstants; -public interface PlaybackStateProvider { +public interface PlaybackInfoProvider { ConvivaSdkConstants.PlayerState getPlayerState(); + VideoQuality getPlaybackVideoData(); } diff --git a/conviva/src/test/kotlin/com/bitmovin/analytics/conviva/ssai/DefaultSsaiApiTest.kt b/conviva/src/test/kotlin/com/bitmovin/analytics/conviva/ssai/DefaultSsaiApiTest.kt index 61f8af6..39835fd 100644 --- a/conviva/src/test/kotlin/com/bitmovin/analytics/conviva/ssai/DefaultSsaiApiTest.kt +++ b/conviva/src/test/kotlin/com/bitmovin/analytics/conviva/ssai/DefaultSsaiApiTest.kt @@ -1,6 +1,7 @@ package com.bitmovin.analytics.conviva.ssai import android.util.Log +import com.bitmovin.player.api.media.video.quality.VideoQuality import com.conviva.sdk.ConvivaAdAnalytics import com.conviva.sdk.ConvivaSdkConstants import com.conviva.sdk.ConvivaVideoAnalytics @@ -29,29 +30,42 @@ import strikt.assertions.isTrue class DefaultSsaiApiTest { private val videoAnalytics: ConvivaVideoAnalytics = mockk(relaxed = true) private val adAnalytics: ConvivaAdAnalytics = mockk() - private val playbackStateProvider = mockk() - private val ssaiApi = DefaultSsaiApi( - videoAnalytics, - adAnalytics, - playbackStateProvider, - ) + private val playbackInfoProvider = mockk() + private lateinit var ssaiApi: DefaultSsaiApi @Before fun beforeTest() { - every { playbackStateProvider.playerState } returns ConvivaSdkConstants.PlayerState.PLAYING + every { playbackInfoProvider.playerState } returns ConvivaSdkConstants.PlayerState.PLAYING + every { playbackInfoProvider.playbackVideoData } returns VideoQuality( + "videoQualityId", + "videoQualityLabel", + 1000, + "codec", + 60.1F, + 1600, + 800, + ) with(adAnalytics) { every { reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAYER_STATE, any()) } just runs + every { reportAdMetric(ConvivaSdkConstants.PLAYBACK.RESOLUTION, any(), any()) } just runs + every { reportAdMetric(ConvivaSdkConstants.PLAYBACK.BITRATE, any()) } just runs + every { reportAdMetric(ConvivaSdkConstants.PLAYBACK.RENDERED_FRAMERATE, any()) } just runs every { reportAdStarted(any()) } just runs every { reportAdEnded() } just runs every { reportAdSkipped() } just runs every { setAdInfo(any()) } just runs } + + ssaiApi = DefaultSsaiApi( + videoAnalytics, + adAnalytics, + playbackInfoProvider, + ) } @After fun afterTest() { - clearMocks(videoAnalytics, adAnalytics, playbackStateProvider) - ssaiApi.reset() + clearMocks(videoAnalytics, adAnalytics, playbackInfoProvider) } @@ -122,7 +136,7 @@ class DefaultSsaiApiTest { @Test fun `reports ad playback state playing to conviva when ad starts while paused`() { - every { playbackStateProvider.playerState } returns ConvivaSdkConstants.PlayerState.PAUSED + every { playbackInfoProvider.playerState } returns ConvivaSdkConstants.PlayerState.PAUSED ssaiApi.reportAdBreakStarted() ssaiApi.reportAdStarted(SsaiApi.AdInfo()) @@ -137,7 +151,7 @@ class DefaultSsaiApiTest { @Test fun `reports ad playback state buffering to conviva when ad starts while stalling`() { - every { playbackStateProvider.playerState } returns + every { playbackInfoProvider.playerState } returns ConvivaSdkConstants.PlayerState.BUFFERING ssaiApi.reportAdBreakStarted() @@ -151,6 +165,18 @@ class DefaultSsaiApiTest { } } + @Test + fun `reports current playback video quality to conviva on ad start`() { + ssaiApi.reportAdBreakStarted() + ssaiApi.reportAdStarted(SsaiApi.AdInfo()) + + verify { + adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.BITRATE, 1) + adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RESOLUTION, 800, 1600) + adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RENDERED_FRAMERATE, 60) + } + } + @Test fun `reports ad start with overwritten metadata when ad starts with additional metadata`() { ssaiApi.reportAdBreakStarted()