Skip to content

Commit

Permalink
add lowLatency option
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Oct 24, 2023
1 parent 0201ba3 commit d886d08
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ registerWith(options: {'platforms': ['windows', 'macos', 'linux']}); // only the

To select [other decoders](https://github.com/wang-bin/mdk-sdk/wiki/Decoders), pass options like this
```dart
registerWith(options: {'video.decoders': ['D3D11', 'NVDEC', 'FFmpeg']}); // windows
registerWith(options: {
'video.decoders': ['D3D11', 'NVDEC', 'FFmpeg']
'lowLatency': 1, // optional for network streams
}); // windows
```

### Backend Player API
Expand Down
2 changes: 2 additions & 0 deletions lib/fvp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import 'src/video_player_mdk.dart'
///
/// "maxWidth", "maxHeight": texture max size. if not set, video frame size is used. a small value can reduce memory cost, but may result in lower image quality.
///
/// 'lowLatency': int. default is 0. reduce network stream latency. 1: for vod. 2: for live stream, may drop frames to ensure the latest content is displayed
///
/// "player": backend player properties of type Map<String, String>. See https://github.com/wang-bin/mdk-sdk/wiki/Player-APIs#void-setpropertyconst-stdstring-key-const-stdstring-value
///
/// "global": backend global options of type Map<String, Object>. See https://github.com/wang-bin/mdk-sdk/wiki/Global-Options
Expand Down
12 changes: 12 additions & 0 deletions lib/src/video_player_mdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class MdkVideoPlayerPlatform extends VideoPlayerPlatform {
static int? _maxWidth;
static int? _maxHeight;
static bool? _fitMaxSize;
static int _lowLatency = 0;
static int _seekFlags = mdk.SeekFlag.fromStart | mdk.SeekFlag.inCache;
static List<String>? _decoders;
static final _mdkLog = Logger('mdk');
Expand All @@ -118,6 +119,7 @@ class MdkVideoPlayerPlatform extends VideoPlayerPlatform {
if ((options['fastSeek'] ?? false) as bool) {
_seekFlags |= mdk.SeekFlag.keyFrame;
}
_lowLatency = (options['lowLatency'] ?? 0) as int;
_maxWidth = options["maxWidth"];
_maxHeight = options["maxHeight"];
_fitMaxSize = options["fitMaxSize"];
Expand Down Expand Up @@ -196,13 +198,23 @@ class MdkVideoPlayerPlatform extends VideoPlayerPlatform {
player.setProperty("keep_open", "1");
player.setProperty('avio.protocol_whitelist',
'file,rtmp,http,https,tls,rtp,tcp,udp,crypto,httpproxy,data,concatf,concat,subfile');
player.setProperty('avformat.rtsp_transport', 'tcp');
_playerOpts?.forEach((key, value) {
player.setProperty(key, value);
});

if (_decoders != null) {
player.videoDecoders = _decoders!;
}
if (_lowLatency > 0) {
player.setProperty('avformat.fflags', '+nobuffer');
player.setProperty('avformat.fpsprobesize', '0');
if (_lowLatency > 1) {
player.setBufferRange(min: 0, max: 1000, drop: true);
} else {
player.setBufferRange(min: 0);
}
}

if (dataSource.httpHeaders.isNotEmpty) {
String headers = '';
Expand Down

0 comments on commit d886d08

Please sign in to comment.