Skip to content

Commit

Permalink
Merge pull request #308 from bitmovin/minTimeshiftBufferDepth
Browse files Browse the repository at this point in the history
Implement `LiveConfig`: `minTimeshiftBufferDepth`
  • Loading branch information
123mpozzi authored Oct 25, 2023
2 parents d756543 + 613cc6a commit c965354
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Added

- `LiveConfig.minTimeshiftBufferDepth` to control the minimum buffer depth of a stream needed to enable time shifting.

## [0.13.0] (2023-10-20)

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.bitmovin.player.api.event.PlayerEvent
import com.bitmovin.player.api.event.SourceEvent
import com.bitmovin.player.api.event.data.CastPayload
import com.bitmovin.player.api.event.data.SeekPosition
import com.bitmovin.player.api.live.LiveConfig
import com.bitmovin.player.api.media.AdaptationConfig
import com.bitmovin.player.api.media.audio.AudioTrack
import com.bitmovin.player.api.media.subtitle.SubtitleTrack
Expand Down Expand Up @@ -116,6 +117,11 @@ class JsonConverter {
playerConfig.bufferConfig = it
}
}
if (json.hasKey("liveConfig")) {
toLiveConfig(json.getMap("liveConfig"))?.let {
playerConfig.liveConfig = it
}
}
return playerConfig
}

Expand Down Expand Up @@ -1169,6 +1175,23 @@ class JsonConverter {
playerViewConfig = toPlayerViewConfig(json),
pictureInPictureConfig = toPictureInPictureConfig(json.getMap("pictureInPictureConfig")),
)

/**
* Converts any JS object into a [LiveConfig] object.
* @param json JS object representing the [LiveConfig].
* @return The generated [LiveConfig] if successful, `null` otherwise.
*/
@JvmStatic
fun toLiveConfig(json: ReadableMap?): LiveConfig? {
if (json == null) {
return null
}
val liveConfig = LiveConfig()
if (json.hasKey("minTimeshiftBufferDepth")) {
liveConfig.minTimeShiftBufferDepth = json.getDouble("minTimeshiftBufferDepth")
}
return liveConfig
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions ios/RCTConvert+BitmovinPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ extension RCTConvert {
if let bufferConfig = RCTConvert.bufferConfig(json["bufferConfig"]) {
playerConfig.bufferConfig = bufferConfig
}
if let liveConfig = RCTConvert.liveConfig(json["liveConfig"]) {
playerConfig.liveConfig = liveConfig
}
#if os(iOS)
if let remoteControlConfig = RCTConvert.remoteControlConfig(json["remoteControlConfig"]) {
playerConfig.remoteControlConfig = remoteControlConfig
Expand Down Expand Up @@ -191,6 +194,22 @@ extension RCTConvert {
return bufferConfig
}

/**
Utility method to instantiate a `LiveConfig` from a JS object.
- Parameter json: JS object.
- Returns: The produced `LiveConfig` object, or `nil` if `json` is not valid.
*/
static func liveConfig(_ json: Any?) -> LiveConfig? {
guard let json = json as? [String: Any?] else {
return nil
}
let liveConfig = LiveConfig()
if let minTimeshiftBufferDepth = json["minTimeshiftBufferDepth"] as? NSNumber {
liveConfig.minTimeshiftBufferDepth = minTimeshiftBufferDepth.doubleValue
}
return liveConfig
}

/**
Utility method to instantiate an `AdvertisingConfig` from a JS object.
- Parameter json: JS object.
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * from './tweaksConfig';
export * from './bufferConfig';
export * from './playbackConfig';
export * from './playerConfig';
export * from './liveConfig';
12 changes: 12 additions & 0 deletions src/liveConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Contains config values regarding the behaviour when playing live streams.
*/
export interface LiveConfig {
/**
* The minimum buffer depth of a stream needed to enable time shifting.
* When the internal value for the maximal possible timeshift is lower than this value,
* timeshifting should be disabled. That means `Player.maxTimeShift` returns `0` in that case.
* This value should always be non-positive value, default value is `-40`.
*/
minTimeshiftBufferDepth?: number;
}
5 changes: 5 additions & 0 deletions src/playerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RemoteControlConfig } from './remoteControlConfig';
import { BufferConfig } from './bufferConfig';
import { NativeInstanceConfig } from './nativeInstance';
import { PlaybackConfig } from './playbackConfig';
import { LiveConfig } from './liveConfig';

/**
* Object used to configure a new `Player` instance.
Expand Down Expand Up @@ -63,4 +64,8 @@ export interface PlayerConfig extends NativeInstanceConfig {
* Configures buffer settings. A default {@link BufferConfig} is set initially.
*/
bufferConfig?: BufferConfig;
/**
* Configures behaviour when playing live content. A default {@link LiveConfig} is set initially.
*/
liveConfig?: LiveConfig;
}

0 comments on commit c965354

Please sign in to comment.