Skip to content

Commit

Permalink
move the timer for Consumption Report to MSH, in line with Metric Report
Browse files Browse the repository at this point in the history
  • Loading branch information
Shilin Ding committed Sep 15, 2023
1 parent 7e40dc9 commit 87d9c2b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import retrofit2.Call
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

import java.util.Timer
import java.util.Date
import java.util.TimerTask

import kotlin.math.abs
Expand Down Expand Up @@ -133,8 +135,9 @@ class MediaSessionHandlerMessengerService() : Service() {
val resource =
handleServiceAccessResponse(response, sendingUid, provisioningSessionId)

// create Retrofit for ConsumptionReporting
// create Retrofit for ConsumptionReporting, and start ConsumptionReport Timer
createRetrofitForConsumpReport(sendingUid)
startConsumptionReportTimer(sendingUid)

// Trigger the playback by providing all available entry points
val msgResponse: Message = Message.obtain(
Expand Down Expand Up @@ -266,7 +269,7 @@ class MediaSessionHandlerMessengerService() : Service() {

/**
* Reset a client session once a new playback session is started. Remove the ServiceAccessInformation
* for the corresponding client id and reset all metric reporting timers.
* for the corresponding client id and reset all metric/comsumption reporting timers.
*
* @param clientId
*/
Expand All @@ -276,6 +279,8 @@ class MediaSessionHandlerMessengerService() : Service() {
clientsSessionData[clientId]?.serviceAccessInformation = null
clientsSessionData[clientId]?.serviceAccessInformationRequestTimer?.cancel()
clientsSessionData[clientId]?.serviceAccessInformationRequestTimer = null
clientsSessionData[clientId]?.consumptionReportingTimer?.cancel()
clientsSessionData[clientId]?.consumptionReportingTimer = null
clientsSessionData[clientId]?.serviceAccessInformationResponseHeaders = null
}
}
Expand Down Expand Up @@ -327,21 +332,22 @@ class MediaSessionHandlerMessengerService() : Service() {
return false
}

// validate samplePercentage in ServiceAccessInformation.clientConsumptionReportingConfiguration
// check if the samplePercentage in ServiceAccessInformation.clientConsumptionReportingConfiguration is valid
var samplePercentage: Float = clientsSessionData[clientId]?.serviceAccessInformation!!.clientConsumptionReportingConfiguration.samplePercentage;
if(samplePercentage > SamplePercentageMax || samplePercentage < 0)
{
Log.i(TAG, "[ConsumptionReporting] Invaild samplePercentage[$samplePercentage] in ServiceAccessInformation.clientConsumptionReportingConfiguration")
return false;
}

// if samplePercentage == 100, always report
// if samplePercentage is 100, MSH shall activate the consumption reporting procedure
if(abs(SamplePercentageMax - samplePercentage) < EPSILON)
{
Log.i(TAG, "[ConsumptionReporting] SamplePercentage==SamplePercentageMax, always report")
return true;
}

// if the generated random number is of a lower value than the samplePercentage value
val randomFloat:Float = Random.nextFloat()
val randomInt:Int = Random.nextInt(0, SamplePercentageMax.toInt())
val randomValue:Float = randomInt - 1 + randomFloat
Expand All @@ -359,25 +365,31 @@ class MediaSessionHandlerMessengerService() : Service() {
if (!isConsumptionReportingActivated(clientId))
{
Log.i(TAG, "[ConsumptionReporting] IsConsumptionReportingActivated is 【FALSE】")
return false;
return false
}

// Condition 1/2: Start/stop of consumption of a downlink streaming session
// In Media Stream handler, when condition 1/2 occur, reportConsumption
//// to check, need return

// Condition 3: check clientConsumptionReportingConfiguration.reportingInterval, timer trigger
// In Media Stream handler, reportConsumptionTimer()
//// to check, need return
if (clientsSessionData[clientId]!!.isConsumptionReport)
{
Log.i(TAG, "[ConsumptionReporting] IsConsumptionReportingActivated: report triggered by timer v2")

clientsSessionData[clientId]!!.isConsumptionReport = false
return true
}

// Condition 4/5:check clientConsumptionReportingConfiguration.locationReporting and clientConsumptionReportingConfiguration.accessReporting
if(clientsSessionData[clientId]?.serviceAccessInformation!!.clientConsumptionReportingConfiguration.locationReporting
|| clientsSessionData[clientId]?.serviceAccessInformation!!.clientConsumptionReportingConfiguration.accessReporting)
{
return true;
Log.i(TAG, "[ConsumptionReporting] IsConsumptionReportingActivated: report triggered by locationReporting/accessReporting")
return true
}

return false;
return false
}

private fun reportConsumption(msg: Message) {
Expand Down Expand Up @@ -405,7 +417,7 @@ class MediaSessionHandlerMessengerService() : Service() {
if(consumptionReportingApi == null)
{
Log.i(TAG, "[ConsumptionReporting] consumptionReportingApi is 【NULL】")
return;
return
}

val provisisioningSessionId: String = "2";
Expand Down Expand Up @@ -446,4 +458,26 @@ class MediaSessionHandlerMessengerService() : Service() {
}
}

fun startConsumptionReportTimer(clientId: Int) {
val timer = Timer()
clientsSessionData[clientId]?.serviceAccessInformationRequestTimer = timer

if(clientsSessionData[clientId]?.serviceAccessInformation?.clientConsumptionReportingConfiguration?.reportingInterval != null) {
var periodSec: UInt? =
clientsSessionData[clientId]?.serviceAccessInformation?.clientConsumptionReportingConfiguration!!.reportingInterval

timer.schedule(
object : TimerTask() {
override fun run() {
clientsSessionData[clientId]?.isConsumptionReport = true
}
},
Date(),
(periodSec?.times(1000u))!!.toLong()
)
}

//// todo: support cacheControlHeader related flow
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ data class ClientSessionModel(
var serviceAccessInformationApi: ServiceAccessInformationApi? = null,
var consumptionReportingApi: ConsumptionReportingApi? = null,
var serviceAccessInformationResponseHeaders: Headers? = null,
var serviceAccessInformationRequestTimer: Timer? = null
var serviceAccessInformationRequestTimer: Timer? = null,
var consumptionReportingTimer: Timer? = null,
var isConsumptionReport: Boolean = false
)

0 comments on commit 87d9c2b

Please sign in to comment.