diff --git a/api-extractor/report/hls.js.api.md b/api-extractor/report/hls.js.api.md index aa400f8c550..b8721be1bd2 100644 --- a/api-extractor/report/hls.js.api.md +++ b/api-extractor/report/hls.js.api.md @@ -466,7 +466,7 @@ export class BaseStreamController extends TaskLoop implements NetworkComponentAP // (undocumented) protected loadingParts: boolean; // (undocumented) - protected _loadInitSegment(frag: Fragment, level: Level): void; + protected _loadInitSegment(fragment: Fragment, level: Level): void; // (undocumented) mapToInitFragWhenRequired(frag: Fragment | null): typeof frag; // (undocumented) diff --git a/src/controller/base-stream-controller.ts b/src/controller/base-stream-controller.ts index 0fbb4aad5d0..c8bc0938a6a 100644 --- a/src/controller/base-stream-controller.ts +++ b/src/controller/base-stream-controller.ts @@ -477,18 +477,19 @@ export default class BaseStreamController } private _loadFragForPlayback( - frag: Fragment, + fragment: Fragment, level: Level, targetBufferTime: number, ) { const progressCallback: FragmentLoadProgressCallback = ( data: FragLoadedData, ) => { + const frag = data.frag; if (this.fragContextChanged(frag)) { this.warn( - `Fragment ${frag.sn}${ - data.part ? ' p: ' + data.part.index : '' - } of level ${frag.level} was dropped during download.`, + `${frag.type} sn: ${frag.sn}${ + data.part ? ' part: ' + data.part.index : '' + } of ${this.fragInfo(frag, false, data.part)}) was dropped during download.`, ); this.fragmentTracker.removeFragment(frag); return; @@ -497,13 +498,14 @@ export default class BaseStreamController this._handleFragmentLoadProgress(data); }; - this._doFragLoad(frag, level, targetBufferTime, progressCallback) + this._doFragLoad(fragment, level, targetBufferTime, progressCallback) .then((data) => { if (!data) { // if we're here we probably needed to backtrack or are waiting for more parts return; } const state = this.state; + const frag = data.frag; if (this.fragContextChanged(frag)) { if ( state === State.FRAG_LOADING || @@ -530,7 +532,7 @@ export default class BaseStreamController return; } this.warn(`Frag error: ${reason?.message || reason}`); - this.resetFragmentLoading(frag); + this.resetFragmentLoading(fragment); }); } @@ -608,10 +610,11 @@ export default class BaseStreamController this.hls.trigger(Events.BUFFER_FLUSHING, flushScope); } - protected _loadInitSegment(frag: Fragment, level: Level) { - this._doFragLoad(frag, level) + protected _loadInitSegment(fragment: Fragment, level: Level) { + this._doFragLoad(fragment, level) .then((data) => { - if (!data || this.fragContextChanged(frag) || !this.levels) { + const frag = data?.frag; + if (!frag || this.fragContextChanged(frag) || !this.levels) { throw new Error('init load aborted'); } @@ -619,7 +622,7 @@ export default class BaseStreamController }) .then((data: FragLoadedData) => { const { hls } = this; - const { payload } = data; + const { frag, payload } = data; const decryptData = frag.decryptdata; // check to see if the payload needs to be decrypted @@ -671,7 +674,7 @@ export default class BaseStreamController return; } this.warn(reason); - this.resetFragmentLoading(frag); + this.resetFragmentLoading(fragment); }); } @@ -705,7 +708,7 @@ export default class BaseStreamController this.log( `Buffered ${frag.type} sn: ${frag.sn}${ part ? ' part: ' + part.index : '' - } of ${this.fragInfo(frag)} > buffer:${ + } of ${this.fragInfo(frag, false, part)} > buffer:${ media ? TimeRanges.toString(BufferHelper.getBuffered(media)) : '(detached)' @@ -823,12 +826,11 @@ export default class BaseStreamController const partIndex = this.getNextPart(partList, frag, targetBufferTime); if (partIndex > -1) { const part = partList[partIndex]; + frag = this.fragCurrent = part.fragment; this.log( - `Loading part sn: ${frag.sn} p: ${part.index} cc: ${ + `Loading ${frag.type} sn: ${frag.sn} part: ${part.index} (${partIndex}/${partList.length - 1}) of ${this.fragInfo(frag, false, part)}) cc: ${ frag.cc - } of playlist [${details.startSN}-${ - details.endSN - }] parts [0-${partIndex}-${partList.length - 1}] ${this.playlistLabel()}: ${frag.level}, target: ${parseFloat( + } [${details.startSN}-${details.endSN}], target: ${parseFloat( targetBufferTime.toFixed(3), )}`, ); @@ -1947,7 +1949,7 @@ export default class BaseStreamController this.log( `Parsed ${frag.type} sn: ${frag.sn}${ part ? ' part: ' + part.index : '' - } of ${this.fragInfo(frag)})`, + } of ${this.fragInfo(frag, false, part)})`, ); this.hls.trigger(Events.FRAG_PARSED, { frag, part }); } @@ -1956,10 +1958,16 @@ export default class BaseStreamController return this.playlistType === PlaylistLevelType.MAIN ? 'level' : 'track'; } - private fragInfo(frag: Fragment, pts: boolean = true): string { - return `${this.playlistLabel()} ${frag.level} (frag:[${((pts ? frag.startPTS : frag.start) ?? NaN).toFixed(3)}-${( - (pts ? frag.endPTS : frag.end) ?? NaN - ).toFixed(3)}]`; + private fragInfo( + frag: Fragment, + pts: boolean = true, + part?: Part | null, + ): string { + return `${this.playlistLabel()} ${frag.level} (${part ? 'part' : 'frag'}:[${((pts && !part ? frag.startPTS : (part || frag).start) ?? NaN).toFixed(3)}-${( + (pts && !part ? frag.endPTS : (part || frag).end) ?? NaN + ).toFixed( + 3, + )}]${part && frag.type === 'main' ? 'INDEPENDENT=' + (part.independent ? 'YES' : 'NO') : ''}`; } protected resetTransmuxer() { diff --git a/src/controller/stream-controller.ts b/src/controller/stream-controller.ts index 638b8f921b1..abd26c815d1 100644 --- a/src/controller/stream-controller.ts +++ b/src/controller/stream-controller.ts @@ -1151,11 +1151,12 @@ export default class StreamController return audioCodec; } - private _loadBitrateTestFrag(frag: Fragment, level: Level) { - frag.bitrateTest = true; - this._doFragLoad(frag, level).then((data) => { + private _loadBitrateTestFrag(fragment: Fragment, level: Level) { + fragment.bitrateTest = true; + this._doFragLoad(fragment, level).then((data) => { const { hls } = this; - if (!data || this.fragContextChanged(frag)) { + const frag = data?.frag; + if (!frag || this.fragContextChanged(frag)) { return; } level.fragmentError = 0; diff --git a/src/demux/transmuxer-interface.ts b/src/demux/transmuxer-interface.ts index 6c923f60a9a..40671565edc 100644 --- a/src/demux/transmuxer-interface.ts +++ b/src/demux/transmuxer-interface.ts @@ -12,13 +12,13 @@ import Transmuxer, { } from '../demux/transmuxer'; import { ErrorDetails, ErrorTypes } from '../errors'; import { Events } from '../events'; +import { PlaylistLevelType } from '../types/loader'; import { getM2TSSupportedAudioTypes } from '../utils/codecs'; import type { WorkerContext } from './inject-worker'; import type { HlsEventEmitter, HlsListeners } from '../events'; import type Hls from '../hls'; import type { MediaFragment, Part } from '../loader/fragment'; import type { ErrorData, FragDecryptedData } from '../types/events'; -import type { PlaylistLevelType } from '../types/loader'; import type { ChunkMetadata, TransmuxerResult } from '../types/transmuxer'; import type { RationalTimestamp } from '../utils/timescale-conversion'; @@ -234,7 +234,9 @@ export default class TransmuxerInterface { ); if (!contiguous || discontinuity || initSegmentChange) { this.hls.logger - .log(`[transmuxer-interface, ${frag.type}]: Starting new transmux session for sn: ${chunkMeta.sn} p: ${chunkMeta.part} level: ${chunkMeta.level} id: ${chunkMeta.id} + .log(`[transmuxer-interface]: Starting new transmux session for ${frag.type} sn: ${chunkMeta.sn}${ + chunkMeta.part > -1 ? ' part: ' + chunkMeta.part : '' + } ${this.id === PlaylistLevelType.MAIN ? 'level' : 'track'}: ${chunkMeta.level} id: ${chunkMeta.id} discontinuity: ${discontinuity} trackSwitch: ${trackSwitch} contiguous: ${contiguous} diff --git a/src/demux/transmuxer.ts b/src/demux/transmuxer.ts index a1c11283239..7c0eab857d8 100644 --- a/src/demux/transmuxer.ts +++ b/src/demux/transmuxer.ts @@ -290,7 +290,7 @@ export default class Transmuxer { const { accurateTimeOffset, timeOffset } = this.currentTransmuxState; this.logger.log( `[transmuxer.ts]: Flushed ${this.id} sn: ${chunkMeta.sn}${ - chunkMeta.part > -1 ? ' p: ' + chunkMeta.part : '' + chunkMeta.part > -1 ? ' part: ' + chunkMeta.part : '' } of ${this.id === PlaylistLevelType.MAIN ? 'level' : 'track'} ${chunkMeta.level}`, ); const remuxResult = this.remuxer!.remux(