Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit 839b4a1

Browse files
committed
source code robustness
1 parent 1f4c808 commit 839b4a1

File tree

3 files changed

+35
-30
lines changed

3 files changed

+35
-30
lines changed

app/js/streaming/MediaPlayer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,9 @@ MediaPlayer = function () {
11411141
*/
11421142
getVideoBitrates: function () {
11431143
_isPlayerInitialized();
1144+
if (!videoBitrates) {
1145+
return [];
1146+
}
11441147
return videoBitrates.slice();
11451148
},
11461149

app/js/streaming/MetricsExtensions.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ MediaPlayer.dependencies.MetricsExtensions = function() {
104104
i = 0,
105105
adaptation;
106106

107+
if (!manifest) {
108+
return null;
109+
}
110+
107111
for (i = 0; i < manifest.Period.AdaptationSet.length; i++) {
108112
adaptation = manifest.Period.AdaptationSet[i];
109113
if (adaptation.type === type) {
@@ -120,6 +124,10 @@ MediaPlayer.dependencies.MetricsExtensions = function() {
120124
i = 0,
121125
adaptation;
122126

127+
if (!manifest) {
128+
return null;
129+
}
130+
123131
for (i = 0; i < manifest.Period.AdaptationSet.length; i++) {
124132
adaptation = manifest.Period.AdaptationSet[i];
125133
if (adaptation.type === type || adaptation.contentType === type) {
@@ -137,19 +145,16 @@ MediaPlayer.dependencies.MetricsExtensions = function() {
137145
representation,
138146
periodArray;
139147

140-
if (manifest) {
141-
periodArray = manifest.Period_asArray;
142-
143-
representation = findRepresentionInPeriodArray.call(self, periodArray, representationId);
144-
145-
if (representation === null) {
146-
return null;
147-
}
148+
if (!manifest) {
149+
return null;
150+
}
148151

149-
return representation.width;
150-
} else {
152+
periodArray = manifest.Period_asArray;
153+
representation = findRepresentionInPeriodArray.call(self, periodArray, representationId);
154+
if (representation === null) {
151155
return null;
152156
}
157+
return representation.width;
153158
};
154159

155160
rslt.getVideoHeightForRepresentation = function(representationId) {
@@ -158,19 +163,16 @@ MediaPlayer.dependencies.MetricsExtensions = function() {
158163
representation,
159164
periodArray;
160165

161-
if (manifest) {
162-
periodArray = manifest.Period_asArray;
163-
164-
representation = findRepresentionInPeriodArray.call(self, periodArray, representationId);
165-
166-
if (representation === null) {
167-
return null;
168-
}
166+
if (!manifest) {
167+
return null;
168+
}
169169

170-
return representation.height;
171-
} else {
170+
periodArray = manifest.Period_asArray;
171+
representation = findRepresentionInPeriodArray.call(self, periodArray, representationId);
172+
if (representation === null) {
172173
return null;
173174
}
175+
return representation.height;
174176
};
175177

176178
rslt.getCodecsForRepresentation = function(representationId) {
@@ -179,12 +181,14 @@ MediaPlayer.dependencies.MetricsExtensions = function() {
179181
representation,
180182
periodArray = manifest.Period_asArray;
181183

182-
representation = findRepresentionInPeriodArray.call(self, periodArray, representationId);
184+
if (!manifest) {
185+
return null;
186+
}
183187

188+
representation = findRepresentionInPeriodArray.call(self, periodArray, representationId);
184189
if (representation === null) {
185190
return null;
186191
}
187-
188192
return representation.codecs;
189193
};
190194

@@ -213,7 +217,7 @@ MediaPlayer.dependencies.MetricsExtensions = function() {
213217
representationArrayIndex,
214218
bitrateArray = [];
215219

216-
if (((manifest === null) || (manifest === undefined)) && ((data === null) || (data === undefined))) {
220+
if (!manifest) {
217221
return null;
218222
}
219223

@@ -262,7 +266,7 @@ MediaPlayer.dependencies.MetricsExtensions = function() {
262266
representationArrayIndex,
263267
bitrateArray = [];
264268

265-
if ((manifest === null) || (manifest === undefined)) {
269+
if (!manifest) {
266270
return null;
267271
}
268272

app/js/streaming/protection/drm/KeySystem_Widevine.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ MediaPlayer.dependencies.protection.KeySystem_Widevine = function() {
4040

4141
var keySystemStr = "com.widevine.alpha",
4242
keySystemUUID = "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed",
43-
protData = null,
43+
protData,
4444

4545
doGetInitData = function(cpData) {
4646
return MediaPlayer.dependencies.protection.CommonEncryption.parseInitDataFromContentProtection(cpData);
@@ -74,11 +74,9 @@ MediaPlayer.dependencies.protection.KeySystem_Widevine = function() {
7474
sessionType: "temporary",
7575

7676
init: function(protectionData) {
77-
if (protectionData) {
78-
protData = protectionData;
79-
if (protData.sessionType) {
80-
this.sessionType = protData.sessionType;
81-
}
77+
protData = protectionData;
78+
if (protData && protData.sessionType) {
79+
this.sessionType = protData.sessionType;
8280
}
8381
},
8482

0 commit comments

Comments
 (0)