Dash-Industry-Forum/dash.js — pull request #232 by kirkshoop (2014-09-16 17:07:04+00:00)
Title: Dash.js Refactor

1. Conversion the player architecture from Pull to Push model.
Q.js dependency has been removed, promises pattern has been replaced with Observer pattern. Now most of the dashjs objects 'inherit' subscribe/notify methods which allow them to notify observers about their state change.

2. Refactoring of classes.
Complex logic that was accumulated in BufferController has been separated into several new classes by functionality (buffering, scheduling, playback, updating manifest data etc. The goal was to increase understanding of logic, ease in reusing and maintaining the code.

3. Scheduling improvements
Scheduling logic has been moved into rules. How many segments, which segments and when they should be requested are now calculated in the competing rules. Live edge search logic also has been moved into rules.
Scheduling by timer has been removed. Segments are now requested in an response to events.
A request of each type (audio/video) waits for a request of the other type with the same presentation time before being loaded.
Initialization segments for dynamic mpds are loaded only once.
Pending requests are cancelled only when seeking.

4. ABR improvements
The number of quality switches per unit time has been restricted to prevent frequent switching.

5. Buffering improvements
Pending segments for a better quality are allowed to be appended to the buffer even if the quality has been changed to a low value, i.e. if there are several segments for a quality 4 which are already loaded and waiting in the queue for appending or even if they are being loaded and AbrController signals that the quality should change to 1, the player will complete appending and loading remaining segments for quality 4 w/o switching initialization segments. But at the same time the player starts requesting segments for a new quality.
Handling of QuotaExceededError - the value of acceptable buffer level is restricted to 80% of the buffer level which was at the moment the error occurred.

6. Removed duplicated code

7. Code complexity has been reduced
As a result of the improvements listed above the size of methods has been reduced as well as code nesting, number of conditional statements etc.

A new custom rules API. It adds support for adding and setting custom rules for both scheduling and abr rule types.
1. Added new public methods to MediaPlayer: setSchedulingRules, addSchedulingRules, setABRRules, addABRRules. They take a parameter - rules collection object.
2. Added RulesController class that is responsible for storing, setting, adding and applying the rules.
3. BaseRulesCollection has been renamed into ABRRulesCollection in order to correspond its purpose and moved into "../streaming/rules/ABRRules" directory together with abr-related rules.