Skip to content

Commit

Permalink
chore: Stop using "Object" in DASH (#7947)
Browse files Browse the repository at this point in the history
Related to #1672
  • Loading branch information
tykus160 authored Jan 24, 2025
1 parent 6fe041c commit 97832b7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
50 changes: 25 additions & 25 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,22 @@ shaka.dash.DashParser = class {
* A map of IDs to Stream objects.
* ID: Period@id,Representation@id
* e.g.: '1,23'
* @private {!Object<string, !shaka.extern.Stream>}
* @private {!Map<string, !shaka.extern.Stream>}
*/
this.streamMap_ = {};
this.streamMap_ = new Map();

/**
* A map of Period IDs to Stream Map IDs.
* Use to have direct access to streamMap key.
* @private {!Object<string, !Array<string>>}
* @private {!Map<string, !Array<string>>}
*/
this.indexStreamMap_ = {};
this.indexStreamMap_ = new Map();

/**
* A map of period ids to their durations
* @private {!Object<string, number>}
* @private {!Map<string, number>}
*/
this.periodDurations_ = {};
this.periodDurations_ = new Map();

/** @private {shaka.util.PeriodCombiner} */
this.periodCombiner_ = new shaka.util.PeriodCombiner();
Expand Down Expand Up @@ -265,7 +265,7 @@ shaka.dash.DashParser = class {
stop() {
// When the parser stops, release all segment indexes, which stops their
// timers, as well.
for (const stream of Object.values(this.streamMap_)) {
for (const stream of this.streamMap_.values()) {
if (stream.segmentIndex) {
stream.segmentIndex.release();
}
Expand All @@ -279,8 +279,8 @@ shaka.dash.DashParser = class {
this.config_ = null;
this.manifestUris_ = [];
this.manifest_ = null;
this.streamMap_ = {};
this.indexStreamMap_ = {};
this.streamMap_.clear();
this.indexStreamMap_.clear();
this.contextCache_.clear();
this.manifestPatchContext_ = {
mpdId: '',
Expand Down Expand Up @@ -690,7 +690,7 @@ shaka.dash.DashParser = class {
// https://github.com/shaka-project/shaka-player/issues/3169#issuecomment-823580634
const availabilityStart =
presentationTimeline.getSegmentAvailabilityStart();
for (const stream of Object.values(this.streamMap_)) {
for (const stream of this.streamMap_.values()) {
if (stream.segmentIndex) {
stream.segmentIndex.evict(availabilityStart);
}
Expand Down Expand Up @@ -1178,7 +1178,7 @@ shaka.dash.DashParser = class {
/** @type {shaka.dash.DashParser.Context} */
const context = this.contextCache_.get(contextId);

const currentStream = this.streamMap_[contextId];
const currentStream = this.streamMap_.get(contextId);
goog.asserts.assert(currentStream, 'stream should exist');

if (currentStream.segmentIndex) {
Expand Down Expand Up @@ -1426,7 +1426,7 @@ shaka.dash.DashParser = class {
periods.push(period);

if (context.period.id && periodDuration) {
this.periodDurations_[context.period.id] = periodDuration;
this.periodDurations_.set(context.period.id, periodDuration);
}

if (periodDuration == null) {
Expand Down Expand Up @@ -1490,14 +1490,14 @@ shaka.dash.DashParser = class {
* @private
*/
cleanStreamMap_() {
const oldPeriodIds = Object.keys(this.indexStreamMap_);
const oldPeriodIds = Array.from(this.indexStreamMap_.keys());
const diffPeriodsIDs = oldPeriodIds.filter((pId) => {
return !this.lastManifestUpdatePeriodIds_.includes(pId);
});
for (const pId of diffPeriodsIDs) {
let shouldDeleteIndex = true;
for (const contextId of this.indexStreamMap_[pId]) {
const stream = this.streamMap_[contextId];
for (const contextId of this.indexStreamMap_.get(pId)) {
const stream = this.streamMap_.get(contextId);
if (!stream) {
continue;
}
Expand All @@ -1506,12 +1506,12 @@ shaka.dash.DashParser = class {
continue;
}
if (this.periodCombiner_) {
this.periodCombiner_.deleteStream(this.streamMap_[contextId], pId);
this.periodCombiner_.deleteStream(stream, pId);
}
delete this.streamMap_[contextId];
this.streamMap_.delete(contextId);
}
if (shouldDeleteIndex) {
delete this.indexStreamMap_[pId];
this.indexStreamMap_.delete(pId);
}
}
}
Expand Down Expand Up @@ -2357,8 +2357,8 @@ shaka.dash.DashParser = class {
/** @type {shaka.extern.Stream} */
let stream;

if (contextId && this.streamMap_[contextId]) {
stream = this.streamMap_[contextId];
if (contextId && this.streamMap_.has(contextId)) {
stream = this.streamMap_.get(contextId);
} else {
stream = {
id: this.globalId_++,
Expand Down Expand Up @@ -2416,13 +2416,13 @@ shaka.dash.DashParser = class {
}
};

if (contextId && context.dynamic && !this.streamMap_[contextId]) {
if (contextId && context.dynamic && !this.streamMap_.has(contextId)) {
const periodId = context.period.id || '';
if (!this.indexStreamMap_[periodId]) {
this.indexStreamMap_[periodId] = [];
if (!this.indexStreamMap_.has(periodId)) {
this.indexStreamMap_.set(periodId, []);
}
this.streamMap_[contextId] = stream;
this.indexStreamMap_[periodId].push(contextId);
this.streamMap_.set(contextId, stream);
this.indexStreamMap_.get(periodId).push(contextId);
}

return stream;
Expand Down
17 changes: 8 additions & 9 deletions lib/dash/mpd_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ shaka.dash.MpdUtils = class {
*/
static fillUriTemplate(
uriTemplate, representationId, number, subNumber, bandwidth, time) {
/** @type {!Object<string, ?number | ?string>} */
const valueTable = {
'RepresentationID': representationId,
'Number': number,
'SubNumber': subNumber,
'Bandwidth': bandwidth,
'Time': time,
};
/** @type {!Map<string, ?number | ?string>} */
const valueTable = new Map()
.set('RepresentationID', representationId)
.set('Number', number)
.set('SubNumber', subNumber)
.set('Bandwidth', bandwidth)
.set('Time', time);

// cspell: disable-next-line
const re = /\$(RepresentationID|Number|SubNumber|Bandwidth|Time)?(?:%0([0-9]+)([diouxX]))?\$/g; // eslint-disable-line max-len
Expand All @@ -53,7 +52,7 @@ shaka.dash.MpdUtils = class {
return '$';
}

let value = valueTable[name];
let value = valueTable.get(name);
goog.asserts.assert(value !== undefined, 'Unrecognized identifier');

// Note that |value| may be 0 or ''.
Expand Down
4 changes: 2 additions & 2 deletions lib/dash/segment_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ shaka.dash.SegmentList = class {
* Updates the existing SegmentIndex, if any.
*
* @param {shaka.dash.DashParser.Context} context
* @param {!Object<string, !shaka.extern.Stream>} streamMap
* @param {!Map<string, !shaka.extern.Stream>} streamMap
* @param {shaka.extern.aesKey|undefined} aesKey
* @return {shaka.dash.DashParser.StreamInfo}
*/
Expand All @@ -52,7 +52,7 @@ shaka.dash.SegmentList = class {
if (context.period.id && context.representation.id) {
// Only check/store the index if period and representation IDs are set.
const id = context.period.id + ',' + context.representation.id;
stream = streamMap[id];
stream = streamMap.get(id);
if (stream) {
segmentIndex = stream.segmentIndex;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/dash/segment_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ shaka.dash.SegmentTemplate = class {
*
* @param {shaka.dash.DashParser.Context} context
* @param {shaka.dash.DashParser.RequestSegmentCallback} requestSegment
* @param {!Object<string, !shaka.extern.Stream>} streamMap
* @param {!Map<string, !shaka.extern.Stream>} streamMap
* @param {boolean} isUpdate True if the manifest is being updated.
* @param {number} segmentLimit The maximum number of segments to generate for
* a SegmentTemplate with fixed duration.
* @param {!Object<string, number>} periodDurationMap
* @param {!Map<string, number>} periodDurationMap
* @param {shaka.extern.aesKey|undefined} aesKey
* @param {?number} lastSegmentNumber
* @param {boolean} isPatchUpdate
Expand Down Expand Up @@ -92,7 +92,7 @@ shaka.dash.SegmentTemplate = class {
const periodId = context.period.id;
const initialPeriodDuration = context.periodInfo.duration;
const periodDuration =
(periodId != null && periodDurationMap[periodId]) ||
(periodId != null && periodDurationMap.get(periodId)) ||
initialPeriodDuration;
const periodEnd = periodDuration ?
(periodStart + periodDuration) : Infinity;
Expand All @@ -119,7 +119,7 @@ shaka.dash.SegmentTemplate = class {
if (context.period.id && context.representation.id) {
// Only check/store the index if period and representation IDs are set.
id = context.period.id + ',' + context.representation.id;
stream = streamMap[id];
stream = streamMap.get(id);
if (stream) {
segmentIndex = stream.segmentIndex;
}
Expand Down Expand Up @@ -366,7 +366,7 @@ shaka.dash.SegmentTemplate = class {
* @param {shaka.dash.SegmentTemplate.SegmentTemplateInfo} info
* @param {number} segmentLimit The maximum number of segments to generate.
* @param {shaka.media.InitSegmentReference} initSegmentReference
* @param {!Object<string, number>} periodDurationMap
* @param {!Map<string, number>} periodDurationMap
* @param {shaka.extern.aesKey|undefined} aesKey
* @param {?number} lastSegmentNumber
* @param {number} segmentSequenceCadence
Expand Down Expand Up @@ -395,7 +395,7 @@ shaka.dash.SegmentTemplate = class {
// provides the updated period duration.
const getPeriodEnd = () => {
const periodDuration =
(periodId != null && periodDurationMap[periodId]) ||
(periodId != null && periodDurationMap.get(periodId)) ||
initialPeriodDuration;
const periodEnd = periodDuration ?
(periodStart + periodDuration) : Infinity;
Expand Down

0 comments on commit 97832b7

Please sign in to comment.