3DRX

// post

Dash.js source code reading: ABR triggering logic

My notes while working with Dash.js

Updated

For each ABR rule in Dash.js, the function getMaxIndex() is the entry point, which is called when ever the program needs to decide the bit rate of next chunk to fetch.

Such as:

function getMaxIndex(rulesContext) {
  const switchRequest = SwitchRequest(context).create();

  if (
    !rulesContext ||
    !rulesContext.hasOwnProperty("getMediaInfo") ||
    !rulesContext.hasOwnProperty("getMediaType") ||
    !rulesContext.hasOwnProperty("getScheduleController") ||
    !rulesContext.hasOwnProperty("getStreamInfo") ||
    !rulesContext.hasOwnProperty("getAbrController") ||
    !rulesContext.hasOwnProperty("useBufferOccupancyABR")
  ) {
    return switchRequest;
  }

  const mediaInfo = rulesContext.getMediaInfo();
  const mediaType = rulesContext.getMediaType();
  const abrController = rulesContext.getAbrController();
  const throughputHistory = abrController.getThroughputHistory();
  const traceHistory = throughputHistory.getTraceHistory();
  const bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType);
  const ladders = abrController.getBitrateList(mediaInfo);

  let choose_quality = -1;
  let estimate_throughput = -1;
  // some ABR algorithm logic

  switchRequest.quality = choose_quality;
  switchRequest.reason = {};
  switchRequest.reason.throughput = estimate_throughput;

  return switchRequest;
}

The call stack is as following:

  • MediaPlayer
    • StreamController
      • Stream
        • StreamProcessor
          • scheduleController.startScheduleTimer()
            • ScheduleController.schedule()
              • abrController.checkPlaybackQuality()
                • abrRulesCollection.getMaxQuality()
                  • *rule.getMaxIndex()

Related posts: PAR paper reading, Computer Networking: Application Layer