All files / dash.js/src/streaming/text TextController.js

48.95% Statements 117/239
28.02% Branches 44/157
52.77% Functions 19/36
49.15% Lines 117/238

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604                                                                                              48x   48x 48x 48x 48x 48x 48x 48x                                   48x 48x 48x   48x 48x 48x 48x 48x   48x       50x       50x 50x 50x 50x 50x 50x     50x       4x 4x         4x 4x   4x                           4x 4x   4x 4x               4x   4x     4x                     4x   4x     4x                       2x                                                                                       4x 4x 4x   4x   4x       4x 4x                                 4x     4x   4x             4x   4x     4x             4x                                                                                                                                                         4x 1x                                   1x       11x 11x     11x                         2x   2x 1x     2x     2x       2x   2x   2x 2x     2x 2x     2x   2x   2x   2x 1x     2x   2x 1x 1x 1x 1x     1x     1x                                                                   1x                 1x   1x 1x                                       1x 1x 12x 12x     12x                           2x                                                                       54x 54x 54x 54x 54x 54x       6x 4x 4x     6x 6x 6x 6x 6x 6x 6x 6x     6x     48x                                 48x 48x     1x    
/**
 * The copyright in this software is being made available under the BSD License,
 * included below. This software may be subject to other third party and contributor
 * rights, including patent rights, and no such rights are granted under this license.
 *
 * Copyright (c) 2013, Dash Industry Forum.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *  * Redistributions of source code must retain the above copyright notice, this
 *  list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice,
 *  this list of conditions and the following disclaimer in the documentation and/or
 *  other materials provided with the distribution.
 *  * Neither the name of Dash Industry Forum nor the names of its
 *  contributors may be used to endorse or promote products derived from this software
 *  without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
 *  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 *  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 *  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */
import Constants from '../constants/Constants.js';
import FactoryMaker from '../../core/FactoryMaker.js';
import TextSourceBuffer from './TextSourceBuffer.js';
import TextTracks from './TextTracks.js';
import VTTParser from '../utils/VTTParser.js';
import VttCustomRenderingParser from '../utils/VttCustomRenderingParser.js';
import TTMLParser from '../utils/TTMLParser.js';
import EventBus from '../../core/EventBus.js';
import Debug from '../../core/Debug.js';
import Events from '../../core/events/Events.js';
import MediaPlayerEvents from '../../streaming/MediaPlayerEvents.js';
import {checkParameterType} from '../utils/SupervisorTools.js';
import DVBFonts from './DVBFonts.js';
import DashConstants from '../../dash/constants/DashConstants.js';
 
function TextController(config) {
 
    let context = this.context;
 
    const adapter = config.adapter;
    const errHandler = config.errHandler;
    const manifestModel = config.manifestModel;
    const mediaController = config.mediaController;
    const baseURLController = config.baseURLController;
    const videoModel = config.videoModel;
    const settings = config.settings;
 
    let instance,
        streamData,
        textSourceBuffers,
        textTracks,
        vttParser,
        vttCustomRenderingParser,
        ttmlParser,
        eventBus,
        allTracksAreDisabled,
        forceTextStreaming,
        textTracksAdded,
        disableTextBeforeTextTracksAdded,
        dvbFonts,
        logger;
 
    function setup() {
        forceTextStreaming = false;
        textTracksAdded = false;
        disableTextBeforeTextTracksAdded = false;
 
        vttParser = VTTParser(context).getInstance();
        vttCustomRenderingParser = VttCustomRenderingParser(context).getInstance();
        ttmlParser = TTMLParser(context).getInstance();
        eventBus = EventBus(context).getInstance();
        logger = Debug(context).getInstance().getLogger(instance);
 
        resetInitialSettings();
    }
 
    function initialize() {
        dvbFonts = DVBFonts(context).create({
            adapter,
            baseURLController,
        });
        eventBus.on(Events.TEXT_TRACKS_QUEUE_INITIALIZED, _onTextTracksAdded, instance);
        eventBus.on(Events.DVB_FONT_DOWNLOAD_FAILED, _onFontDownloadFailure, instance);
        eventBus.on(Events.DVB_FONT_DOWNLOAD_COMPLETE, _onFontDownloadSuccess, instance);
        eventBus.on(Events.MEDIAINFO_UPDATED, _onMediaInfoUpdated, instance);
        eventBus.on(Events.PLAYBACK_TIME_UPDATED, _onPlaybackTimeUpdated, instance);
        Iif (settings.get().streaming.text.webvtt.customRenderingEnabled) {
            eventBus.on(Events.PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
        }
        eventBus.on(Events.PLAYBACK_SEEKED, _onPlaybackSeeked, instance);
    }
 
    function initializeForStream(streamInfo) {
        const streamId = streamInfo.id;
        const tracks = TextTracks(context).create({
            videoModel,
            settings,
            streamInfo
        });
        tracks.initialize();
        textTracks[streamId] = tracks;
 
        const textSourceBuffer = TextSourceBuffer(context).create({
            errHandler,
            adapter,
            dvbFonts,
            manifestModel,
            mediaController,
            videoModel,
            textTracks: tracks,
            vttParser,
            vttCustomRenderingParser,
            ttmlParser,
            streamInfo,
            settings
        });
        textSourceBuffer.initialize();
        textSourceBuffers[streamId] = textSourceBuffer;
 
        streamData[streamId] = {};
        streamData[streamId].lastEnabledIndex = -1;
    }
 
    /**
     * All media infos have been added. Start creating the track objects
     * @param {object} streamInfo
     */
    function createTracks(streamInfo) {
        const streamId = streamInfo.id;
 
        Iif (!textTracks[streamId]) {
            return;
        }
        textTracks[streamId].createTracks();
    }
 
    /**
     * Adds the new mediaInfo objects to the textSourceBuffer.
     * @param {object} streamInfo
     * @param {array} mInfos
     * @param {string|null} mimeType
     * @param {object} fragmentModel
     */
    function addMediaInfosToBuffer(streamInfo, type, mInfos, fragmentModel = null) {
        const streamId = streamInfo.id;
 
        Iif (!textSourceBuffers[streamId]) {
            return;
        }
        textSourceBuffers[streamId].addMediaInfos(type, mInfos, fragmentModel);
    }
 
    function getTextSourceBuffer(streamInfo) {
        const streamId = streamInfo.id;
 
        if (textSourceBuffers && textSourceBuffers[streamId]) {
            return textSourceBuffers[streamId];
        }
    }
 
    function getAllTracksAreDisabled() {
        return allTracksAreDisabled;
    }
 
    function addEmbeddedTrack(streamInfo, mediaInfo) {
        const streamId = streamInfo.id;
 
        if (!textSourceBuffers[streamId]) {
            return;
        }
 
        textSourceBuffers[streamId].addEmbeddedTrack(mediaInfo);
    }
 
    /**
     * Event that is triggered if a font download of a font described in an essential property descriptor
     * tag fails.
     * @param {FontInfo} font - font information
     * @private
     */
    function _onFontDownloadFailure(font) {
        logger.error(`Could not download ${font.isEssential ? 'an essential' : 'a'} font - fontFamily: ${font.fontFamily}, url: ${font.url}`);
        if (font.isEssential) {
            let idx = textTracks[font.streamId].getTrackIdxForId(font.trackId);
            textTracks[font.streamId].setModeForTrackIdx(idx, Constants.TEXT_DISABLED);
        }
    };
 
    /**
     * Set a font with an essential property
     * @private
     */
    function _onFontDownloadSuccess(font) {
        logger.debug(`Successfully downloaded ${font.isEssential ? 'an essential' : 'a'} font - fontFamily: ${font.fontFamily}, url: ${font.url}`);
        if (font.isEssential) {
            let idx = textTracks[font.streamId].getTrackIdxForId(font.trackId);
            if (idx === textTracks[font.streamId].getCurrentTrackIdx()) {
                textTracks[font.streamId].setModeForTrackIdx(idx, Constants.TEXT_SHOWING);
            } else {
                textTracks[font.streamId].setModeForTrackIdx(idx, Constants.TEXT_HIDDEN);
            }
        }
    }
 
    function _onTextTracksAdded(e) {
        let tracks = e.tracks;
        let index = e.index;
        const streamId = e.streamId;
 
        const textDefaultEnabled = settings.get().streaming.text.defaultEnabled;
 
        Iif ((textDefaultEnabled === false && !isTextEnabled()) || disableTextBeforeTextTracksAdded) {
            // disable text at startup if explicitly configured with setTextDefaultEnabled(false) or if there is no defaultSettings (configuration or from domStorage)
            setTextTrack(streamId, -1);
        } else {
            const currentTrack = mediaController.getCurrentTrackFor(Constants.TEXT, streamId);
            Iif (currentTrack) {
                const defaultSettings = {
                    lang: currentTrack.lang,
                    role: currentTrack.roles[0],
                    index: currentTrack.index,
                    codec: currentTrack.codec,
                    accessibility: currentTrack.accessibility[0]
                };
                tracks.some((item, idx) => {
                    // matchSettings is compatible with setTextDefaultLanguage and setInitialSettings
                    if (mediaController.matchSettings(defaultSettings, item)) {
                        setTextTrack(streamId, idx);
                        index = idx;
                        return true;
                    }
                });
            }
            allTracksAreDisabled = false;
        }
 
        streamData[streamId].lastEnabledIndex = index;
 
        eventBus.trigger(MediaPlayerEvents.TEXT_TRACKS_ADDED, {
            enabled: isTextEnabled(),
            index: index,
            tracks: tracks,
            streamId
        });
 
        textTracksAdded = true;
 
        dvbFonts.addFontsFromTracks(tracks, streamId);
 
        // Initially disable any tracks with essential property font downloads
        dvbFonts.getFonts().forEach(font => {
            if (font.isEssential) {
                let idx = textTracks[font.streamId].getTrackIdxForId(font.trackId);
                textTracks[font.streamId].setModeForTrackIdx(idx, Constants.TEXT_DISABLED);
            }
        });
 
        dvbFonts.downloadFonts();
    }
 
    function _onPlaybackTimeUpdated(e) {
        try {
            const streamId = e.streamId;
            const tracks = textTracks[streamId];
 
            if (!tracks || isNaN(e.time)) {
                return;
            }
 
            tracks.updateTextTrackWindow(e.time);
 
            if (settings.get().streaming.text.webvtt.customRenderingEnabled) {
                tracks.manualCueProcessing(e.time);
            }
        } catch (err) {
        }
    }
 
    function _onPlaybackSeeking(e) {
        try {
            const streamId = e.streamId;
 
            if (!textTracks[streamId]) {
                return;
            }
            textTracks[streamId].disableManualTracks();
        } catch (e) {
 
        }
    }
 
    function _onPlaybackSeeked(e) {
        try {
            const tracks = textTracks[e.streamId];
 
            if (!tracks) {
                return;
            }
 
            const currentTime = videoModel.getTime() || 0;
 
            tracks.updateTextTrackWindow(currentTime, true);
        } catch (e) {
            logger.error(e);
        }
    }
 
    function _onMediaInfoUpdated(e) {
        try {
            if (!e || !e.mediaType || e.mediaType !== Constants.AUDIO || !e.currentMediaInfo) {
                return
            }
 
            const currentTextTrackInfo = textTracks[e.streamId].getCurrentTextTrackInfo();
            let suitableForcedSubtitleIndex = NaN;
            if (allTracksAreDisabled) {
                suitableForcedSubtitleIndex = _getSuitableForceSubtitleTrackIndex(e.streamId);
            } else if (_isForcedSubtitleTrack(currentTextTrackInfo) && e.currentMediaInfo.lang && e.currentMediaInfo.lang !== currentTextTrackInfo.lang) {
                suitableForcedSubtitleIndex = _getSuitableForceSubtitleTrackIndex(e.streamId);
                if (isNaN(suitableForcedSubtitleIndex)) {
                    suitableForcedSubtitleIndex = -1;
                }
            }
 
            if (!isNaN(suitableForcedSubtitleIndex)) {
                setTextTrack(e.streamId, suitableForcedSubtitleIndex);
            }
 
        } catch (e) {
            logger.error(e);
        }
    }
 
    function enableText(streamId, enable) {
        checkParameterType(enable, 'boolean');
        Iif (isTextEnabled() !== enable) {
            // change track selection
            if (enable) {
                // apply last enabled track
                setTextTrack(streamId, streamData[streamId].lastEnabledIndex);
            }
 
            if (!enable) {
                // keep last index and disable text track
                streamData[streamId].lastEnabledIndex = getCurrentTrackIdx(streamId);
                if (!textTracksAdded) {
                    disableTextBeforeTextTracksAdded = true;
                } else {
                    setTextTrack(streamId, -1);
                }
            }
        }
 
        return true
    }
 
    function isTextEnabled() {
        let enabled = true;
        Iif (allTracksAreDisabled && !forceTextStreaming) {
            enabled = false;
        }
        return enabled;
    }
 
    // when set to true ScheduleController will allow schedule of chunks even if tracks are all disabled. Allowing streaming to hidden track for external players to work with.
    function enableForcedTextStreaming(enable) {
        checkParameterType(enable, 'boolean');
        forceTextStreaming = enable;
        return true
    }
 
    function setTextTrack(streamId, idx) {
        // For external time text file, the only action needed to change a track is marking the track mode to showing.
        // Fragmented text tracks need the additional step of calling TextController.setTextTrack();
        allTracksAreDisabled = idx === -1;
 
        if (allTracksAreDisabled && mediaController) {
            mediaController.saveTextSettingsDisabled();
        }
 
        let oldTrackIdx = getCurrentTrackIdx(streamId);
 
        // No change, no action required
        Iif (oldTrackIdx === idx || !textTracks[streamId]) {
            return;
        }
 
        textTracks[streamId].disableManualTracks();
 
        textTracks[streamId].invalidateCueWindow();
 
        let currentTrackInfo = textTracks[streamId].getCurrentTextTrackInfo();
        let currentNativeTrackInfo = (currentTrackInfo) ? videoModel.getTextTrack(currentTrackInfo.kind, currentTrackInfo.id, currentTrackInfo.lang, currentTrackInfo.isTTML, currentTrackInfo.isEmbedded) : null;
 
        // Don't change disabled tracks - dvb font download for essential property failed or not complete
        if (currentNativeTrackInfo && (currentNativeTrackInfo.mode !== Constants.TEXT_DISABLED)) {
            textTracks[streamId].setModeForTrackIdx(oldTrackIdx, Constants.TEXT_HIDDEN);
        }
 
        textTracks[streamId].setCurrentTrackIdx(idx);
 
        currentTrackInfo = textTracks[streamId].getCurrentTextTrackInfo();
 
        const dispatchForManualRendering = settings.get().streaming.text.dispatchForManualRendering;
 
        if (currentTrackInfo && !dispatchForManualRendering && (currentTrackInfo.mode !== Constants.TEXT_DISABLED)) {
            textTracks[streamId].setModeForTrackIdx(idx, Constants.TEXT_SHOWING);
        }
 
        Iif (currentTrackInfo && currentTrackInfo.isFragmented && !currentTrackInfo.isEmbedded) {
            _setFragmentedTextTrack(streamId, currentTrackInfo, oldTrackIdx);
        } else if (currentTrackInfo && !currentTrackInfo.isFragmented) {
            _setNonFragmentedTextTrack(streamId, currentTrackInfo);
        } else if (!currentTrackInfo && allTracksAreDisabled) {
            const forcedSubtitleTrackIndex = _getSuitableForceSubtitleTrackIndex(streamId)
            Iif (!isNaN(forcedSubtitleTrackIndex)) {
                setTextTrack(streamId, forcedSubtitleTrackIndex);
            }
            return
        }
 
        mediaController.setTrack(currentTrackInfo);
    }
 
    function _setFragmentedTextTrack(streamId, currentTrackInfo, oldTrackIdx) {
 
        if (!textSourceBuffers[streamId]) {
            return;
        }
 
        let config = textSourceBuffers[streamId].getConfig();
        let fragmentedTracks = config.fragmentedTracks;
 
        for (let i = 0; i < fragmentedTracks.length; i++) {
            let mediaInfo = fragmentedTracks[i];
            if (currentTrackInfo.lang === mediaInfo.lang &&
                (mediaInfo.id ? currentTrackInfo.id === mediaInfo.id : currentTrackInfo.index === mediaInfo.index)) {
                let currentFragTrack = mediaController.getCurrentTrackFor(Constants.TEXT, streamId);
                if (mediaInfo.id ? currentFragTrack.id !== mediaInfo.id : currentFragTrack.index !== mediaInfo.index) {
                    textTracks[streamId].deleteCuesFromTrackIdx(oldTrackIdx);
                    textSourceBuffers[streamId].setCurrentFragmentedTrackIdx(i);
                } else if (oldTrackIdx === -1) {
                    // in fragmented use case, if the user selects the older track (the one selected before disabled text track)
                    // no CURRENT_TRACK_CHANGED event will be triggered because the mediaInfo in the StreamProcessor is equal to the one we are selecting
                    // For that reason we reactivate the StreamProcessor and the ScheduleController
                    eventBus.trigger(Events.SET_FRAGMENTED_TEXT_AFTER_DISABLED, {}, {
                        streamId,
                        mediaType: Constants.TEXT
                    });
                }
            }
        }
    }
 
    function _setNonFragmentedTextTrack(streamId, currentTrackInfo) {
        eventBus.trigger(Events.SET_NON_FRAGMENTED_TEXT, {
            currentTrackInfo
        }, {
            streamId,
            mediaType: Constants.TEXT
        });
    }
 
    function _getSuitableForceSubtitleTrackIndex(streamId) {
        const forcedSubtitleTracks = _getForcedSubtitleTracks(streamId);
 
        if (!forcedSubtitleTracks || forcedSubtitleTracks.length <= 0) {
            return NaN
        }
 
        const currentAudioTrack = mediaController.getCurrentTrackFor(Constants.AUDIO, streamId);
        if (!currentAudioTrack) {
            return NaN
        }
 
        const suitableTrack = forcedSubtitleTracks.find((track) => {
            return currentAudioTrack.lang === track.lang
        })
 
        if (suitableTrack) {
            return suitableTrack._indexToSelect
        }
 
        return NaN
    }
 
    function _getForcedSubtitleTracks(streamId) {
        const textTrackInfos = textTracks[streamId].getTextTrackInfos();
        return textTrackInfos.filter((textTrackInfo, index) => {
            textTrackInfo._indexToSelect = index;
            Iif (textTrackInfo && textTrackInfo.roles && textTrackInfo.roles.length > 0) {
                return _isForcedSubtitleTrack(textTrackInfo);
            }
            return false
        });
    }
 
    function _isForcedSubtitleTrack(textTrackInfo) {
        if (!textTrackInfo || !textTrackInfo.roles || textTrackInfo.roles.length === 0) {
            return false
        }
        return textTrackInfo.roles.some((role) => {
            return role.schemeIdUri === Constants.DASH_ROLE_SCHEME_ID && role.value === DashConstants.FORCED_SUBTITLE
        })
    }
 
    function getCurrentTrackIdx(streamId) {
        return textTracks[streamId].getCurrentTrackIdx();
    }
 
    function deactivateStream(streamInfo) {
        if (!streamInfo) {
            return;
        }
        const streamId = streamInfo.id;
 
        if (textSourceBuffers[streamId]) {
            textSourceBuffers[streamId].resetMediaInfos();
        }
 
        if (textTracks[streamId]) {
            textTracks[streamId].deleteAllTextTracks();
        }
    }
 
    function clearDataForStream(streamId) {
        if (textSourceBuffers[streamId]) {
            textSourceBuffers[streamId].resetEmbedded();
            textSourceBuffers[streamId].reset();
            delete textSourceBuffers[streamId];
        }
 
        if (textTracks[streamId]) {
            textTracks[streamId].deleteAllTextTracks();
            delete textTracks[streamId];
        }
 
        if (streamData[streamId]) {
            delete streamData[streamId];
        }
    }
 
    function resetInitialSettings() {
        textSourceBuffers = {};
        textTracks = {};
        streamData = {};
        allTracksAreDisabled = true;
        textTracksAdded = false;
        disableTextBeforeTextTracksAdded = false;
    }
 
    function reset() {
        Object.keys(textSourceBuffers).forEach((key) => {
            textSourceBuffers[key].resetEmbedded();
            textSourceBuffers[key].reset();
        });
 
        dvbFonts.reset();
        resetInitialSettings();
        eventBus.off(Events.TEXT_TRACKS_QUEUE_INITIALIZED, _onTextTracksAdded, instance);
        eventBus.off(Events.DVB_FONT_DOWNLOAD_FAILED, _onFontDownloadFailure, instance);
        eventBus.off(Events.DVB_FONT_DOWNLOAD_COMPLETE, _onFontDownloadSuccess, instance);
        eventBus.off(Events.MEDIAINFO_UPDATED, _onMediaInfoUpdated, instance);
        eventBus.off(Events.PLAYBACK_TIME_UPDATED, _onPlaybackTimeUpdated, instance);
        Iif (settings.get().streaming.text.webvtt.customRenderingEnabled) {
            eventBus.off(Events.PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
        }
        eventBus.off(Events.PLAYBACK_SEEKED, _onPlaybackSeeked, instance);
    }
 
    instance = {
        addEmbeddedTrack,
        addMediaInfosToBuffer,
        createTracks,
        deactivateStream,
        enableForcedTextStreaming,
        enableText,
        getAllTracksAreDisabled,
        getCurrentTrackIdx,
        getTextSourceBuffer,
        initialize,
        initializeForStream,
        isTextEnabled,
        reset,
        setTextTrack,
        clearDataForStream,
    };
    setup();
    return instance;
}
 
TextController.__dashjs_factory_name = 'TextController';
export default FactoryMaker.getClassFactory(TextController);