@@ -9,6 +9,12 @@ const DEFAULT_MAX_BUFFER_AHEAD = DEFAULT_VALUES.player.maxBufferAhead;
99const DEFAULT_MAX_BUFFER_BEHIND = DEFAULT_VALUES . player . maxBufferBehind ;
1010const DEFAULT_MAX_VIDEO_BUFFER_SIZE = DEFAULT_VALUES . player . maxVideoBufferSize ;
1111const DEFAULT_WANTED_BUFFER_AHEAD = DEFAULT_VALUES . player . wantedBufferAhead ;
12+ const DEFAULT_REBUFFERING_AVOIDANCE_BUFFER_GAP_SIZE =
13+ DEFAULT_VALUES . loadVideo . experimentalOptions
14+ . playbackRateBasedRebufferingAvoidanceSettings . onBufferGapSize ;
15+ const DEFAULT_REBUFFERING_AVOIDANCE_MIN_PLAYBACK_RATE =
16+ DEFAULT_VALUES . loadVideo . experimentalOptions
17+ . playbackRateBasedRebufferingAvoidanceSettings . minPlaybackRate ;
1218
1319/**
1420 * @param {Object } props
@@ -19,19 +25,27 @@ function BufferOptions({
1925 maxVideoBufferSize,
2026 maxBufferAhead,
2127 maxBufferBehind,
28+ rebufferingAvoidanceBufferGapSize,
29+ rebufferingAvoidanceMinPlaybackRate,
2230 onWantedBufferAheadChange,
2331 onMaxVideoBufferSizeChange,
2432 onMaxBufferAheadChange,
2533 onMaxBufferBehindChange,
34+ onRebufferingAvoidanceBufferGapSizeChange,
35+ onRebufferingAvoidanceMinPlaybackRateChange,
2636} : {
2737 wantedBufferAhead : number ;
2838 maxVideoBufferSize : number ;
2939 maxBufferAhead : number ;
3040 maxBufferBehind : number ;
41+ rebufferingAvoidanceBufferGapSize : number ;
42+ rebufferingAvoidanceMinPlaybackRate : number ;
3143 onWantedBufferAheadChange : ( newVal : number ) => void ;
3244 onMaxVideoBufferSizeChange : ( newVal : number ) => void ;
3345 onMaxBufferBehindChange : ( newVal : number ) => void ;
3446 onMaxBufferAheadChange : ( newVal : number ) => void ;
47+ onRebufferingAvoidanceBufferGapSizeChange : ( newVal : number ) => void ;
48+ onRebufferingAvoidanceMinPlaybackRateChange : ( newVal : number ) => void ;
3549} ) : React . JSX . Element {
3650 /* Value of the `wantedBufferAhead` input */
3751 const [ wantedBufferAheadStr , setWantedBufferAheadStr ] = useState (
@@ -45,6 +59,14 @@ function BufferOptions({
4559 const [ maxBufferBehindStr , setMaxBufferBehindStr ] = useState ( String ( maxBufferBehind ) ) ;
4660 /* Value of the `maxBufferAhead` input */
4761 const [ maxBufferAheadStr , setMaxBufferAheadStr ] = useState ( String ( maxBufferAhead ) ) ;
62+ /* Value of the `rebufferingAvoidanceBufferGapSize` input */
63+ const [ rebufferingAvoidanceBufferGapSizeStr , setRebufferingAvoidanceBufferGapSizeStr ] =
64+ useState ( String ( rebufferingAvoidanceBufferGapSize ) ) ;
65+ /* Value of the `rebufferingAvoidanceMinPlaybackRate` input */
66+ const [
67+ rebufferingAvoidanceMinPlaybackRateStr ,
68+ setRebufferingAvoidanceMinPlaybackRateStr ,
69+ ] = useState ( String ( rebufferingAvoidanceMinPlaybackRate ) ) ;
4870 /*
4971 * Keep track of the "limit maxBufferAhead" toggle:
5072 * `false` == checkbox enabled
@@ -66,6 +88,7 @@ function BufferOptions({
6688 const [ isMaxVideoBufferSizeLimited , setMaxVideoBufferSizeLimit ] = useState (
6789 maxVideoBufferSize !== Infinity ,
6890 ) ;
91+ const isRebufferingAvoidanceEnabled = rebufferingAvoidanceBufferGapSize !== 0 ;
6992
7093 // Update `wantedBufferAhead` when its linked text change
7194 useEffect ( ( ) => {
@@ -98,6 +121,26 @@ function BufferOptions({
98121 onMaxBufferBehindChange ( newVal ) ;
99122 } , [ maxBufferBehindStr ] ) ;
100123
124+ // Update `rebufferingAvoidanceBufferGapSize` when its linked text change
125+ useEffect ( ( ) => {
126+ // Note that this unnecessarily also run on first render - there seem to be
127+ // no quick and easy way to disable this in react.
128+ // This is not too problematic so I put up with it.
129+ let newVal = parseFloat ( rebufferingAvoidanceBufferGapSizeStr ) ;
130+ newVal = isNaN ( newVal ) ? DEFAULT_REBUFFERING_AVOIDANCE_BUFFER_GAP_SIZE : newVal ;
131+ onRebufferingAvoidanceBufferGapSizeChange ( newVal ) ;
132+ } , [ rebufferingAvoidanceBufferGapSizeStr ] ) ;
133+
134+ // Update `rebufferingAvoidanceMinPlaybackRate` when its linked text change
135+ useEffect ( ( ) => {
136+ // Note that this unnecessarily also run on first render - there seem to be
137+ // no quick and easy way to disable this in react.
138+ // This is not too problematic so I put up with it.
139+ let newVal = parseFloat ( rebufferingAvoidanceMinPlaybackRateStr ) ;
140+ newVal = isNaN ( newVal ) ? DEFAULT_REBUFFERING_AVOIDANCE_MIN_PLAYBACK_RATE : newVal ;
141+ onRebufferingAvoidanceMinPlaybackRateChange ( newVal ) ;
142+ } , [ rebufferingAvoidanceMinPlaybackRateStr ] ) ;
143+
101144 const onChangeLimitMaxBufferAhead = useCallback ( ( isNotLimited : boolean ) => {
102145 if ( isNotLimited ) {
103146 setMaxBufferAheadLimit ( false ) ;
@@ -128,6 +171,14 @@ function BufferOptions({
128171 }
129172 } , [ ] ) ;
130173
174+ const onRebufferingAvoidanceEnableClick = useCallback ( ( isEnabled : boolean ) => {
175+ if ( isEnabled ) {
176+ setRebufferingAvoidanceBufferGapSizeStr ( "0" ) ;
177+ } else {
178+ setRebufferingAvoidanceBufferGapSizeStr ( "1.5" ) ;
179+ }
180+ } , [ ] ) ;
181+
131182 const onWantedBufferAheadResetClick = React . useCallback ( ( ) => {
132183 setWantedBufferAheadStr ( String ( DEFAULT_WANTED_BUFFER_AHEAD ) ) ;
133184 } , [ ] ) ;
@@ -147,6 +198,18 @@ function BufferOptions({
147198 setMaxBufferBehindLimit ( DEFAULT_MAX_BUFFER_BEHIND !== Infinity ) ;
148199 } , [ ] ) ;
149200
201+ const onRebufferingAvoidanceBufferGapSizeResetClick = React . useCallback ( ( ) => {
202+ setRebufferingAvoidanceBufferGapSizeStr (
203+ String ( DEFAULT_REBUFFERING_AVOIDANCE_BUFFER_GAP_SIZE ) ,
204+ ) ;
205+ } , [ ] ) ;
206+
207+ const onRebufferingAvoidanceMinPlaybackRateResetClick = React . useCallback ( ( ) => {
208+ setRebufferingAvoidanceMinPlaybackRateStr (
209+ String ( DEFAULT_REBUFFERING_AVOIDANCE_MIN_PLAYBACK_RATE ) ,
210+ ) ;
211+ } , [ ] ) ;
212+
150213 return (
151214 < Fragment >
152215 < li >
@@ -242,6 +305,47 @@ function BufferOptions({
242305 : `Manually cleaning data ${ maxBufferBehind } second(s) behind the current position` }
243306 </ span >
244307 </ li >
308+ < li >
309+ < PlayerOptionNumberInput
310+ ariaLabel = "Playback Rate Based Rebuffering Avoidance Buffer Size option"
311+ label = "playbackRateBasedRebufferingAvoidanceBufferSize"
312+ title = "Rebuffering Avoidance: Buffer Size"
313+ valueAsString = { rebufferingAvoidanceBufferGapSizeStr }
314+ defaultValueAsNumber = { DEFAULT_REBUFFERING_AVOIDANCE_BUFFER_GAP_SIZE }
315+ isDisabled = { ! isRebufferingAvoidanceEnabled }
316+ onUpdateValue = { setRebufferingAvoidanceBufferGapSizeStr }
317+ onResetClick = { onRebufferingAvoidanceBufferGapSizeResetClick }
318+ />
319+ < Checkbox
320+ className = "playerOptionsCheckBox"
321+ ariaLabel = "Do not enable Playback Rate-Based Rebuffering Avoidance"
322+ name = "rebufferingAvoidanceEnable"
323+ checked = { ! isRebufferingAvoidanceEnabled }
324+ onChange = { onRebufferingAvoidanceEnableClick }
325+ >
326+ Disable
327+ </ Checkbox >
328+ < span className = "option-desc" >
329+ { rebufferingAvoidanceBufferGapSize <= 0 || ! isRebufferingAvoidanceEnabled
330+ ? "No triggering Playback-Rate-based rebuffering Avoidance"
331+ : `Starting rebuffering avoidance strategy once ${ rebufferingAvoidanceBufferGapSize } second(s) is left in the buffer` }
332+ </ span >
333+ < PlayerOptionNumberInput
334+ ariaLabel = "Playback Rate Based Rebuffering Avoidance Min Playback Rate option"
335+ label = "playbackRateBasedRebufferingAvoidanceMinPlaybackRate"
336+ title = "Rebuffering Avoidance: Playback Rate"
337+ valueAsString = { rebufferingAvoidanceMinPlaybackRateStr }
338+ defaultValueAsNumber = { DEFAULT_REBUFFERING_AVOIDANCE_MIN_PLAYBACK_RATE }
339+ isDisabled = { ! isRebufferingAvoidanceEnabled }
340+ onUpdateValue = { setRebufferingAvoidanceMinPlaybackRateStr }
341+ onResetClick = { onRebufferingAvoidanceMinPlaybackRateResetClick }
342+ />
343+ < span className = "option-desc" >
344+ { rebufferingAvoidanceBufferGapSize <= 0 || ! isRebufferingAvoidanceEnabled
345+ ? "No triggering Playback-Rate-based rebuffering Avoidance"
346+ : `Rebuffering avoidance strategies will play at ${ rebufferingAvoidanceMinPlaybackRate } x the speed once ${ rebufferingAvoidanceBufferGapSize } second(s) is left in the buffer` }
347+ </ span >
348+ </ li >
245349 </ Fragment >
246350 ) ;
247351}
0 commit comments