Parameter setSegmentStatListener
Description
The setSegmentStatListener method in TeleportConfiguration.Builder allows you to set a listener for receiving detailed statistics for each loaded video segment by the Teleport SDK.
Purpose
This listener provides valuable information about the segment loading process, including source, size, load time, and other metrics. With it, you can collect and analyze data on the performance of the P2P network in your application.
Function Requirements
- The listener accepts a
SegmentStatobject, which contains all collected statistics for the segment. - Called on the main thread (Main-thread).
SegmentStat Class Structure
The SegmentStat class encapsulates data about a loaded segment and consists of the following components:
data class SegmentStat(
val timestamp: Long, // UNIX timestamp of segment load time
val result: SegmentStatResult, // Segment load result
val request: SegmentRequestData, // Segment request data
val timings: RequestTimings, // Measured load timings
)SegmentStatResult
Represents the result of loading a segment.
data class SegmentStatResult(
val segmentId: String, // Segment identifier
val sourceId: String, // Source from which the segment was downloaded (CDN | PDN)
val targetId: String?, // Peer identifier if sourceId = PDN
val waitTimeout: Long, // Timeout for waiting from Teleport PDN
val downloadTimeout: Long, // Timeout for downloading from Teleport PDN
val size: Long, // Segment size in bytes
val connected: Boolean, // Flag indicating active connection to the Teleport signaling server
val mode: PeeringMode // Current peering mode
)PeeringMode (enum)
Enumeration of peering modes.
enum class PeeringMode {
OFF, DOWNLOAD, UPLOAD, FULL
}SegmentRequestData
Data about the requested segment.
data class SegmentRequestData(
val url: String, // Original URL of the segment
val uri: String, // Unified URI of the segment (after urlCleaner)
val quality: SegmentQuality, // Video stream quality (SegmentQuality)
val type: SegmentType, // Segment type (SegmentType)
val duration: Long, // Segment duration, in seconds
val bufferSize: Float, // Player buffer size, in seconds
val timeout: Long // Request timeout
)RequestTimings
Measured timings of request execution.
data class RequestTimings(
val requestStartTimestamp: Long, // UNIX timestamp of segment request time by player (request start)
val timeToHave: Long, // Delta of segment waiting from Teleport PDN (time until first peer response)
val timeToSent: Long, // Delta of load initialization time (time until request sent)
val timeToFirstByte: Long, // Delta of first chunk waiting (Time To First Byte)
val timeToLastByte: Long, // Delta of segment load completion (Time To Last Byte)
val timeToFinish: Long // Delta of segment processing completion and data transfer to player
)Key Parameters for Statistics Collection
When collecting client-side statistics, special attention should be paid to the following parameters:
sizeinSegmentStatResult- size of the downloaded segment in bytes.sourceIdinSegmentStatResult- source of segment download (CDNorPDN).timeToFinishinRequestTimings- total time to process the request from the player in ms.
(Please contact developers for a description of other parameters that may be relevant for your analysis).
Example Usage
TeleportConfiguration.Builder("YOUR_API_KEY")
.setSegmentStatListener { stat: SegmentStat ->
// Here, the collected statistics are processed
println("Segment loaded: ID=${stat.result.segmentId}, Source=${stat.result.sourceId}, Size=${stat.result.size} bytes, Time=${stat.timings.timeToFinish} ms")
// Send statistics to an analytics server
}
.build()