1 | import { isIncompatible, isEnabled, isAudioOnly } from './playlist.js';
|
2 | import { codecsForPlaylist } from './util/codecs.js';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | const enableFunction = (loader, playlistID, changePlaylistFn) => (enable) => {
|
17 | const playlist = loader.master.playlists[playlistID];
|
18 | const incompatible = isIncompatible(playlist);
|
19 | const currentlyEnabled = isEnabled(playlist);
|
20 |
|
21 | if (typeof enable === 'undefined') {
|
22 | return currentlyEnabled;
|
23 | }
|
24 |
|
25 | if (enable) {
|
26 | delete playlist.disabled;
|
27 | } else {
|
28 | playlist.disabled = true;
|
29 | }
|
30 |
|
31 | if (enable !== currentlyEnabled && !incompatible) {
|
32 |
|
33 | changePlaylistFn();
|
34 | if (enable) {
|
35 | loader.trigger('renditionenabled');
|
36 | } else {
|
37 | loader.trigger('renditiondisabled');
|
38 | }
|
39 | }
|
40 | return enable;
|
41 | };
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | class Representation {
|
51 | constructor(vhsHandler, playlist, id) {
|
52 | const {
|
53 | masterPlaylistController_: mpc,
|
54 | options_: { smoothQualityChange }
|
55 | } = vhsHandler;
|
56 |
|
57 | const changeType = smoothQualityChange ? 'smooth' : 'fast';
|
58 | const qualityChangeFunction = mpc[`${changeType}QualityChange_`].bind(mpc);
|
59 |
|
60 |
|
61 | if (playlist.attributes) {
|
62 | const resolution = playlist.attributes.RESOLUTION;
|
63 |
|
64 | this.width = resolution && resolution.width;
|
65 | this.height = resolution && resolution.height;
|
66 |
|
67 | this.bandwidth = playlist.attributes.BANDWIDTH;
|
68 | }
|
69 |
|
70 | this.codecs = codecsForPlaylist(mpc.master(), playlist);
|
71 |
|
72 | this.playlist = playlist;
|
73 |
|
74 |
|
75 |
|
76 | this.id = id;
|
77 |
|
78 |
|
79 |
|
80 | this.enabled = enableFunction(
|
81 | vhsHandler.playlists,
|
82 | playlist.id,
|
83 | qualityChangeFunction
|
84 | );
|
85 | }
|
86 | }
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | const renditionSelectionMixin = function(vhsHandler) {
|
96 |
|
97 |
|
98 | vhsHandler.representations = () => {
|
99 | const master = vhsHandler.masterPlaylistController_.master();
|
100 | const playlists = isAudioOnly(master) ?
|
101 | vhsHandler.masterPlaylistController_.getAudioTrackPlaylists_() :
|
102 | master.playlists;
|
103 |
|
104 | if (!playlists) {
|
105 | return [];
|
106 | }
|
107 | return playlists
|
108 | .filter((media) => !isIncompatible(media))
|
109 | .map((e, i) => new Representation(vhsHandler, e, e.id));
|
110 | };
|
111 | };
|
112 |
|
113 | export default renditionSelectionMixin;
|