Skip to content

Commit ccdbaef

Browse files
chore: playlist selector logging (#921)
1 parent 9138cab commit ccdbaef

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

src/playlist-selectors.js

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@ import window from 'global/window';
22
import Config from './config';
33
import Playlist from './playlist';
44
import { codecsForPlaylist } from './util/codecs.js';
5+
import logger from './util/logger';
6+
7+
const logFn = logger('PlaylistSelector');
8+
const representationToString = function(representation) {
9+
if (!representation || !representation.playlist) {
10+
return;
11+
}
12+
const playlist = representation.playlist;
13+
14+
return JSON.stringify({
15+
id: playlist.id,
16+
bandwidth: representation.bandwidth,
17+
width: representation.width,
18+
height: representation.height,
19+
codecs: playlist.attributes && playlist.attributes.CODECS || ''
20+
});
21+
};
522

623
// Utilities
724

@@ -137,6 +154,13 @@ export const simpleSelector = function(
137154
playerHeight,
138155
limitRenditionByPlayerDimensions
139156
) {
157+
158+
const options = {
159+
bandwidth: playerBandwidth,
160+
width: playerWidth,
161+
height: playerHeight,
162+
limitRenditionByPlayerDimensions
163+
};
140164
// convert the playlists to an intermediary representation to make comparisons easier
141165
let sortedPlaylistReps = master.playlists.map((playlist) => {
142166
let bandwidth;
@@ -191,7 +215,22 @@ export const simpleSelector = function(
191215
sortedPlaylistReps[0]
192216
);
193217

194-
return chosenRep ? chosenRep.playlist : null;
218+
if (chosenRep && chosenRep.playlist) {
219+
let type = 'sortedPlaylistReps';
220+
221+
if (bandwidthBestRep) {
222+
type = 'bandwidthBestRep';
223+
}
224+
if (enabledPlaylistReps[0]) {
225+
type = 'enabledPlaylistReps';
226+
}
227+
logFn(`choosing ${representationToString(chosenRep)} using ${type} with options`, options);
228+
229+
return chosenRep.playlist;
230+
}
231+
232+
logFn('could not choose a playlist with options', options);
233+
return null;
195234
}
196235

197236
// filter out playlists without resolution information
@@ -236,7 +275,24 @@ export const simpleSelector = function(
236275
sortedPlaylistReps[0]
237276
);
238277

239-
return chosenRep ? chosenRep.playlist : null;
278+
if (chosenRep && chosenRep.playlist) {
279+
let type = 'sortedPlaylistReps';
280+
281+
if (resolutionPlusOneRep) {
282+
type = 'resolutionPlusOneRep';
283+
} else if (resolutionBestRep) {
284+
type = 'resolutionBestRep';
285+
} else if (bandwidthBestRep) {
286+
type = 'bandwidthBestRep';
287+
} else if (enabledPlaylistReps[0]) {
288+
type = 'enabledPlaylistReps';
289+
}
290+
291+
logFn(`choosing ${representationToString(chosenRep)} using ${type} with options`, options);
292+
return chosenRep.playlist;
293+
}
294+
logFn('could not choose a playlist with options', options);
295+
return null;
240296
};
241297

242298
// Playlist Selectors

0 commit comments

Comments
 (0)