Skip to content

Commit

Permalink
live stream duration.inMicroseconds is int max
Browse files Browse the repository at this point in the history
9223372036854775807
  • Loading branch information
wang-bin committed May 26, 2024
1 parent 12a832f commit caad171
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
12 changes: 10 additions & 2 deletions lib/src/callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ FVP_EXPORT void MdkCallbacksUnregisterPort(int64_t handle)

sp->onEvent(nullptr);
sp->onStateChanged(nullptr);
sp->onMediaStatusChanged(nullptr);
sp->onMediaStatus(nullptr);
players.erase(it);
}

Expand Down Expand Up @@ -338,6 +338,7 @@ FVP_EXPORT bool MdkPrepare(int64_t handle, int64_t pos, int64_t seekFlags, void*
if (!sp)
return false;
auto p = sp.get();
const auto info = p->mediaInfo();
const auto type = int(CallbackType::Prepared);
unique_lock lock(p->mtx[type]);
p->dataReady[type] = false;
Expand All @@ -353,7 +354,14 @@ FVP_EXPORT bool MdkPrepare(int64_t handle, int64_t pos, int64_t seekFlags, void*
.as_int64 = position,
}
};
Dart_CObject* arr[] = { &t, &v };
// live video duration is 0 when prepared, and then increases to max read time
Dart_CObject live{
.type = Dart_CObject_kBool,
.value = {
.as_bool = info.duration <= 0,
}
};
Dart_CObject* arr[] = { &t, &v, &live };
Dart_CObject msg {
.type = Dart_CObject_kArray,
.value = {
Expand Down
13 changes: 12 additions & 1 deletion lib/src/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Player {
{
// prepared
final pos = message[1] as int;
_live = message[2] as bool;
if (!_prepared.isCompleted) {
_prepared.complete(pos);
}
Expand Down Expand Up @@ -307,6 +308,9 @@ class Player {
/// Playback speed set by user.
double get playbackRate => _playbackRate;

/// It's a live stream or not.
bool get isLive => _live;

/// Media information.
MediaInfo get mediaInfo {
_mediaInfoC = _player.ref.mediaInfo
Expand All @@ -319,6 +323,12 @@ class Player {
/// If error occurs, will be [PlaybackState.stopped].
/// Return the result position, or a negative value if failed.
/// https://github.com/wang-bin/mdk-sdk/wiki/Player-APIs#void-prepareint64_t-startposition--0-functionboolint64_t-position-bool-boost-cb--nullptr-seekflag-flags--seekflagfromstart
///
/// Return
/// 0: if mediaInfo.streams == 0, invalid media. otherwise success
/// -1: already loading or loaded
/// -4: requested position out of range
/// -10: internal error
Future<int> prepare(
{int position = 0,
SeekFlag flags = const SeekFlag(SeekFlag.defaultFlags),
Expand All @@ -328,7 +338,7 @@ class Player {
_prepareCb = callback;
if (!Libfvp.prepare(nativeHandle, position, flags.rawValue,
NativeApi.postCObject.cast(), _receivePort.sendPort.nativePort)) {
_prepared.complete(-1);
_prepared.complete(-10);
}
return _prepared.future;
}
Expand Down Expand Up @@ -652,6 +662,7 @@ class Player {
final _player = Libmdk.instance.mdkPlayerAPI_new();
var _pp = calloc<Pointer<mdkPlayerAPI>>();

bool _live = false;
int _texId = -1;
var _videoSize = Completer<ui.Size?>();
var _prepared = Completer<int>();
Expand Down
7 changes: 3 additions & 4 deletions lib/src/video_player_mdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ class MdkVideoPlayer extends mdk.Player {
streamCtl.add(VideoEvent(
eventType: VideoEventType.initialized,
duration: Duration(
milliseconds: info.duration <= 0
microseconds: isLive
// int max for live streams, duration.inMicroseconds == 9223372036854775807
? double.maxFinite.toInt()
: info
.duration) // FIXME: live stream info.duraiton == 0 and result a seekTo(0) in play()
,
: info.duration * 1000),
size: size));
} else if (!oldValue.test(mdk.MediaStatus.buffering) &&
newValue.test(mdk.MediaStatus.buffering)) {
Expand Down

0 comments on commit caad171

Please sign in to comment.