Skip to content

Commit

Permalink
remove circular dependencies between BufferController.js and Throughp…
Browse files Browse the repository at this point in the history
…utRule.js
  • Loading branch information
nicosang committed Oct 7, 2019
1 parent 3c11ca6 commit 11c8e62
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/streaming/constants/MetricsConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class MetricsConstants {
this.HTTP_REQUEST = 'HttpList';
this.TRACK_SWITCH = 'RepSwitchList';
this.BUFFER_LEVEL = 'BufferLevel';
this.BUFFER_LOADED = 'bufferLoaded';
this.BUFFER_EMPTY = 'bufferStalled';
this.BUFFER_STATE = 'BufferState';
this.DVR_INFO = 'DVRInfo';
this.DROPPED_FRAMES = 'DroppedFrames';
Expand Down
19 changes: 7 additions & 12 deletions src/streaming/controllers/BufferController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
import Constants from '../constants/Constants';
import MetricsConstants from '../constants/MetricsConstants';
import FragmentModel from '../models/FragmentModel';
import SourceBufferSink from '../SourceBufferSink';
import PreBufferSink from '../PreBufferSink';
Expand All @@ -44,8 +45,6 @@ import DashJSError from '../vo/DashJSError';
import Errors from '../../core/errors/Errors';
import { HTTPRequest } from '../vo/metrics/HTTPRequest';

const BUFFER_LOADED = 'bufferLoaded';
const BUFFER_EMPTY = 'bufferStalled';
const STALL_THRESHOLD = 0.5;
const BUFFER_END_THRESHOLD = 0.5;
const BUFFER_RANGE_CALCULATION_THRESHOLD = 0.01;
Expand Down Expand Up @@ -552,17 +551,17 @@ function BufferController(config) {
// So, when in low latency mode, change dash.js behavior so it notifies a stall just when
// buffer reach 0 seconds
if (((!settings.get().streaming.lowLatencyEnabled && bufferLevel < STALL_THRESHOLD) || bufferLevel === 0) && !isBufferingCompleted) {
notifyBufferStateChanged(BUFFER_EMPTY);
notifyBufferStateChanged(MetricsConstants.BUFFER_EMPTY);
} else {
if (isBufferingCompleted || bufferLevel >= streamProcessor.getStreamInfo().manifestInfo.minBufferTime) {
notifyBufferStateChanged(BUFFER_LOADED);
notifyBufferStateChanged(MetricsConstants.BUFFER_LOADED);
}
}
}

function notifyBufferStateChanged(state) {
if (bufferState === state ||
(state === BUFFER_EMPTY && playbackController.getTime() === 0) || // Don't trigger BUFFER_EMPTY if it's initial loading
(state === MetricsConstants.BUFFER_EMPTY && playbackController.getTime() === 0) || // Don't trigger BUFFER_EMPTY if it's initial loading
(type === Constants.FRAGMENTED_TEXT && !textController.isTextEnabled())) {
return;
}
Expand All @@ -571,8 +570,8 @@ function BufferController(config) {
addBufferMetrics();

eventBus.trigger(Events.BUFFER_LEVEL_STATE_CHANGED, { sender: instance, state: state, mediaType: type, streamInfo: streamProcessor.getStreamInfo() });
eventBus.trigger(state === BUFFER_LOADED ? Events.BUFFER_LOADED : Events.BUFFER_EMPTY, { mediaType: type });
logger.debug(state === BUFFER_LOADED ? 'Got enough buffer to start' : 'Waiting for more buffer before starting playback');
eventBus.trigger(state === MetricsConstants.BUFFER_LOADED ? Events.BUFFER_LOADED : Events.BUFFER_EMPTY, { mediaType: type });
logger.debug(state === MetricsConstants.BUFFER_LOADED ? 'Got enough buffer to start' : 'Waiting for more buffer before starting playback');
}

function handleInbandEvents(data, request, mediaInbandEvents, trackInbandEvents) {
Expand Down Expand Up @@ -928,8 +927,4 @@ function BufferController(config) {
}

BufferController.__dashjs_factory_name = BUFFER_CONTROLLER_TYPE;
const factory = FactoryMaker.getClassFactory(BufferController);
factory.BUFFER_LOADED = BUFFER_LOADED;
factory.BUFFER_EMPTY = BUFFER_EMPTY;
FactoryMaker.updateClassFactory(BufferController.__dashjs_factory_name, factory);
export default factory;
export default FactoryMaker.getClassFactory(BufferController);
6 changes: 3 additions & 3 deletions src/streaming/controllers/PlaybackController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
import Constants from '../constants/Constants';
import BufferController from './BufferController';
import MetricsConstants from '../constants/MetricsConstants';
import EventBus from '../../core/EventBus';
import Events from '../../core/events/Events';
import FactoryMaker from '../../core/FactoryMaker';
Expand Down Expand Up @@ -751,14 +751,14 @@ function PlaybackController() {
if (e.streamInfo.id !== streamInfo.id) return;

if (settings.get().streaming.lowLatencyEnabled) {
if (e.state === BufferController.BUFFER_EMPTY && !isSeeking()) {
if (e.state === MetricsConstants.BUFFER_EMPTY && !isSeeking()) {
if (!playbackStalled) {
playbackStalled = true;
stopPlaybackCatchUp();
}
}
} else {
videoModel.setStallState(e.mediaType, e.state === BufferController.BUFFER_EMPTY);
videoModel.setStallState(e.mediaType, e.state === MetricsConstants.BUFFER_EMPTY);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/streaming/controllers/ScheduleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import Constants from '../constants/Constants';
import { PlayListTrace } from '../vo/metrics/PlayList';
import AbrController from './AbrController';
import BufferController from './BufferController';
import BufferLevelRule from '../rules/scheduling/BufferLevelRule';
import NextFragmentRequestRule from '../rules/scheduling/NextFragmentRequestRule';
import FragmentModel from '../models/FragmentModel';
Expand Down Expand Up @@ -556,7 +555,7 @@ function ScheduleController(config) {
}

function onBufferLevelStateChanged(e) {
if ((e.sender.getStreamProcessor() === streamProcessor) && e.state === BufferController.BUFFER_EMPTY && !playbackController.isSeeking()) {
if ((e.sender.getStreamProcessor() === streamProcessor) && e.state === MetricsConstants.BUFFER_EMPTY && !playbackController.isSeeking()) {
logger.info('Buffer is empty! Stalling!');
clearPlayListTraceMetrics(new Date(), PlayListTrace.REBUFFERING_REASON);
}
Expand Down
5 changes: 2 additions & 3 deletions src/streaming/rules/abr/InsufficientBufferRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import BufferController from '../../controllers/BufferController';
import EventBus from '../../../core/EventBus';
import Events from '../../../core/events/Events';
import FactoryMaker from '../../../core/FactoryMaker';
Expand Down Expand Up @@ -91,7 +90,7 @@ function InsufficientBufferRule(config) {
return switchRequest;
}

if (lastBufferStateVO.state === BufferController.BUFFER_EMPTY) {
if (lastBufferStateVO.state === MetricsConstants.BUFFER_EMPTY) {
logger.debug('[' + mediaType + '] Switch to index 0; buffer is empty.');
switchRequest.quality = 0;
switchRequest.reason = 'InsufficientBufferRule: Buffer is empty';
Expand All @@ -118,7 +117,7 @@ function InsufficientBufferRule(config) {
let wasTriggered = false;
if (bufferStateDict[mediaType].firstBufferLoadedEvent) {
wasTriggered = true;
} else if (currentBufferState && currentBufferState.state === BufferController.BUFFER_LOADED) {
} else if (currentBufferState && currentBufferState.state === MetricsConstants.BUFFER_LOADED) {
bufferStateDict[mediaType].firstBufferLoadedEvent = true;
wasTriggered = true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/streaming/rules/abr/ThroughputRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import BufferController from '../../controllers/BufferController';
import AbrController from '../../controllers/AbrController';
import FactoryMaker from '../../../core/FactoryMaker';
import Debug from '../../../core/Debug';
Expand Down Expand Up @@ -83,7 +82,7 @@ function ThroughputRule(config) {
}

if (abrController.getAbandonmentStateFor(mediaType) !== AbrController.ABANDON_LOAD) {
if (bufferStateVO.state === BufferController.BUFFER_LOADED || isDynamic) {
if (bufferStateVO.state === MetricsConstants.BUFFER_LOADED || isDynamic) {
switchRequest.quality = abrController.getQualityForBitrate(mediaInfo, throughput, latency);
scheduleController.setTimeToLoadDelay(0);
logger.debug('[' + mediaType + '] requesting switch to index: ', switchRequest.quality, 'Average throughput', Math.round(throughput), 'kbps');
Expand Down
6 changes: 3 additions & 3 deletions src/streaming/vo/metrics/BufferState.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import BufferController from '../../controllers/BufferController';
import MetricsConstants from '../../constants/MetricsConstants';

/**
* @class
Expand All @@ -45,10 +45,10 @@ class BufferState {
*/
this.target = null;
/**
* Current buffer state. Will be BufferController.BUFFER_EMPTY or BufferController.BUFFER_LOADED.
* Current buffer state. Will be MetricsConstants.BUFFER_EMPTY or MetricsConstants.BUFFER_LOADED.
* @public
*/
this.state = BufferController.BUFFER_EMPTY;
this.state = MetricsConstants.BUFFER_EMPTY;
}
}

Expand Down

0 comments on commit 11c8e62

Please sign in to comment.