Skip to content

Commit 4b5b217

Browse files
daytime-emweb-flow
andauthored
Releases/v1.4.4
## Improvements * fix: dropped frames not reported (#74) Co-authored-by: Emily Dixon <[email protected]> Co-authored-by: GitHub <[email protected]>
1 parent 34a1b9c commit 4b5b217

File tree

4 files changed

+71
-5
lines changed

4 files changed

+71
-5
lines changed

library/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,5 @@ dependencies {
8181
testImplementation 'junit:junit:4.13.2'
8282
testImplementation 'androidx.test.ext:junit:1.2.1'
8383
testImplementation "io.mockk:mockk:1.13.9"
84-
// hm, seems like they got rid of API 16 at some point, so we'd have to handle that.
85-
// Robolectric doesn't need updated for anything in particular tho, test deps aren't exported
86-
//noinspection GradleDependency
87-
testImplementation 'org.robolectric:robolectric:4.8.1'
84+
testImplementation 'org.robolectric:robolectric:4.11.1'
8885
}

library/src/main/java/com/mux/stats/sdk/muxstats/MuxStateCollector.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ open class MuxStateCollector(
135135
*/
136136
@Suppress("MemberVisibilityCanBePrivate")
137137
var droppedFrames = 0
138+
set(value) {
139+
field = value
140+
muxStats.setDroppedFramesCount(field.toLong())
141+
// note - in the current implementation, we rely on a subsequent playback event to send this.
142+
// this is probably better, as we may not want to cause beacons while the device is struggling
143+
}
138144

139145
/**
140146
* The list of renditions currently available as part of an HLS, DASH, etc stream
@@ -360,6 +366,8 @@ open class MuxStateCollector(
360366
@Suppress("unused")
361367
fun incrementDroppedFrames(droppedFrames: Int) {
362368
this.droppedFrames += droppedFrames
369+
// note - in the current implementation, we rely on a subsequent playback event to send this.
370+
// this is probably better, as we may not want to cause beacons while the device is struggling
363371
}
364372

365373
/**
@@ -537,6 +545,8 @@ open class MuxStateCollector(
537545
firstFrameRenderedAtMillis = FIRST_FRAME_NOT_RENDERED
538546
playbackPositionMills = TIME_UNKNOWN
539547
allowedHeaders.clear()
548+
droppedFrames = 0
549+
muxStats.setDroppedFramesCount(0)
540550
}
541551

542552
@JvmSynthetic

library/src/test/java/com/mux/core_android/AndroidDeviceTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import org.junit.Test
1717
import org.robolectric.annotation.Config
1818

1919
@Config(
20-
sdk = [Build.VERSION_CODES.JELLY_BEAN, Build.VERSION_CODES.M]
20+
sdk = [Build.VERSION_CODES.KITKAT, Build.VERSION_CODES.M]
2121
)
2222
class AndroidDeviceTests : AbsRobolectricTest() {
2323

library/src/test/java/com/mux/core_android/StateCollectorTests.kt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import com.mux.stats.sdk.muxstats.MuxPlayerState
99
import com.mux.stats.sdk.muxstats.MuxStateCollector
1010
import com.mux.stats.sdk.muxstats.MuxStats
1111
import io.mockk.every
12+
import io.mockk.just
1213
import io.mockk.mockk
14+
import io.mockk.runs
1315
import io.mockk.slot
16+
import io.mockk.verify
1417
import org.junit.Assert.assertEquals
1518
import org.junit.Assert.assertNotEquals
1619
import org.junit.Before
@@ -293,4 +296,60 @@ class StateCollectorTests : AbsRobolectricTest() {
293296
stateCollector.muxPlayerState
294297
)
295298
}
299+
300+
@Test
301+
fun testIncrementDroppedFrames() {
302+
val incrementSlot = slot<Long>()
303+
val mockMuxStats = mockk<MuxStats> {
304+
// MuxStats has its own test for this so we can just mock it here
305+
every { setDroppedFramesCount(capture(incrementSlot)) } just runs
306+
}
307+
stateCollector = MuxStateCollector(
308+
muxStats = mockMuxStats,
309+
dispatcher = FakeEventDispatcher(),
310+
)
311+
312+
val randomFrames1 = (0..100).random()
313+
val randomFrames2 = (0..100).random()
314+
stateCollector.incrementDroppedFrames(randomFrames1)
315+
stateCollector.incrementDroppedFrames(randomFrames2)
316+
317+
verify {
318+
mockMuxStats.setDroppedFramesCount(randomFrames1.toLong())
319+
mockMuxStats.setDroppedFramesCount(randomFrames2 + randomFrames1.toLong())
320+
}
321+
322+
stateCollector.resetState()
323+
verify {
324+
mockMuxStats.setDroppedFramesCount(0)
325+
}
326+
}
327+
328+
@Test
329+
fun testSetDroppedFrames() {
330+
val incrementSlot = slot<Long>()
331+
val mockMuxStats = mockk<MuxStats> {
332+
// MuxStats has its own test for this so we can just mock it here
333+
every { setDroppedFramesCount(capture(incrementSlot)) } just runs
334+
}
335+
stateCollector = MuxStateCollector(
336+
muxStats = mockMuxStats,
337+
dispatcher = FakeEventDispatcher(),
338+
)
339+
340+
val randomFrames1 = (0..100).random()
341+
val randomFrames2 = (0..100).random()
342+
stateCollector.droppedFrames = randomFrames1
343+
stateCollector.droppedFrames = randomFrames2
344+
345+
verify {
346+
mockMuxStats.setDroppedFramesCount(randomFrames1.toLong())
347+
mockMuxStats.setDroppedFramesCount(randomFrames2.toLong())
348+
}
349+
350+
stateCollector.resetState()
351+
verify {
352+
mockMuxStats.setDroppedFramesCount(0)
353+
}
354+
}
296355
}

0 commit comments

Comments
 (0)