Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature flag to enlarge player pool #2031

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ jobs:

- name: Install libvips package for image processing
run: |
sudo apt-get update
sudo apt-get install libvips-dev

- name: Install audiowaveform package
Expand Down
1 change: 1 addition & 0 deletions config/initializers/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
config.features.register('webp_images')
config.features.register('highdef_video_encoding')
config.features.register('force_fullhd_video_quality')
config.features.register('large_player_pool')
config.features.register('selectable_themes')
end
21 changes: 21 additions & 0 deletions package/spec/frontend/media/MediaPool_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ describe('MediaPool', function() {
expect(reusedPlayer).toBe(player);
expect(player.textTracks().length).toEqual(0);
});

it('supports supplying player count via function', () => {
const pool = new MediaPool({playerCount: playerType => {
if (playerType === MediaType.AUDIO) {
return 2;
}
else {
return 5;
}
}});

const audioPlayers = new Set(Array(10).fill().map(() =>
pool.allocatePlayer({playerType: MediaType.AUDIO})
));
const videoPlayers = new Set(Array(10).fill().map(() =>
pool.allocatePlayer({playerType: MediaType.VIDEO})
));

expect(audioPlayers.size).toEqual(2);
expect(videoPlayers.size).toEqual(5);
});
});

describe('#unallocatePlayer', function() {
Expand Down
6 changes: 5 additions & 1 deletion package/src/frontend/media/MediaPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ export class MediaPool {
return player;
}
initializeMediaPool_(type, mediaElSeed){
while ( this.allPlayersForType(type).length<this.playerCount ) {
const playerCount = typeof this.playerCount === 'function' ?
this.playerCount(type) :
this.playerCount;

while (this.allPlayersForType(type).length < playerCount ) {
this.createPlayer_(type, mediaElSeed.cloneNode(true));
}
}
Expand Down
5 changes: 4 additions & 1 deletion package/src/frontend/media/media.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {MediaPool, MediaType} from './MediaPool';
import BackboneEvents from 'backbone-events-standalone';
import {features} from '../features';

export const media = {
playerPool: new MediaPool(),
playerPool: new MediaPool({
playerCount: () => features.isEnabled('large_player_pool') ? 10 : 4
}),
muteState: true,
get muted(){ return this.muteState; },
mute: function (value) {
Expand Down
Loading