Skip to content

Commit

Permalink
[video_player_avplay] Add setBufferConfig interface (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaowei-guan authored Aug 30, 2024
1 parent 473c0c6 commit c368cef
Show file tree
Hide file tree
Showing 14 changed files with 346 additions and 56 deletions.
4 changes: 4 additions & 0 deletions packages/video_player_avplay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.7

* Add SetBufferConfig interface.

## 0.4.6

* Upgrade plusplayer
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_avplay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To use this package, add `video_player_avplay` as a dependency in your `pubspec.

```yaml
dependencies:
video_player_avplay: ^0.4.6
video_player_avplay: ^0.4.7
```
Then you can import `video_player_avplay` in your Dart code:
Expand Down
118 changes: 91 additions & 27 deletions packages/video_player_avplay/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,52 +416,86 @@ class StreamingPropertyTypeMessage {
}
}

class BufferConfigMessage {
BufferConfigMessage({
required this.playerId,
required this.bufferConfigType,
required this.bufferConfigValue,
});

int playerId;

String bufferConfigType;

int bufferConfigValue;

Object encode() {
return <Object?>[
playerId,
bufferConfigType,
bufferConfigValue,
];
}

static BufferConfigMessage decode(Object result) {
result as List<Object?>;
return BufferConfigMessage(
playerId: result[0]! as int,
bufferConfigType: result[1]! as String,
bufferConfigValue: result[2]! as int,
);
}
}

class _VideoPlayerAvplayApiCodec extends StandardMessageCodec {
const _VideoPlayerAvplayApiCodec();
@override
void writeValue(WriteBuffer buffer, Object? value) {
if (value is CreateMessage) {
if (value is BufferConfigMessage) {
buffer.putUint8(128);
writeValue(buffer, value.encode());
} else if (value is DurationMessage) {
} else if (value is CreateMessage) {
buffer.putUint8(129);
writeValue(buffer, value.encode());
} else if (value is GeometryMessage) {
} else if (value is DurationMessage) {
buffer.putUint8(130);
writeValue(buffer, value.encode());
} else if (value is LoopingMessage) {
} else if (value is GeometryMessage) {
buffer.putUint8(131);
writeValue(buffer, value.encode());
} else if (value is MixWithOthersMessage) {
} else if (value is LoopingMessage) {
buffer.putUint8(132);
writeValue(buffer, value.encode());
} else if (value is PlaybackSpeedMessage) {
} else if (value is MixWithOthersMessage) {
buffer.putUint8(133);
writeValue(buffer, value.encode());
} else if (value is PlayerMessage) {
} else if (value is PlaybackSpeedMessage) {
buffer.putUint8(134);
writeValue(buffer, value.encode());
} else if (value is PositionMessage) {
} else if (value is PlayerMessage) {
buffer.putUint8(135);
writeValue(buffer, value.encode());
} else if (value is SelectedTracksMessage) {
} else if (value is PositionMessage) {
buffer.putUint8(136);
writeValue(buffer, value.encode());
} else if (value is StreamingPropertyMessage) {
} else if (value is SelectedTracksMessage) {
buffer.putUint8(137);
writeValue(buffer, value.encode());
} else if (value is StreamingPropertyTypeMessage) {
} else if (value is StreamingPropertyMessage) {
buffer.putUint8(138);
writeValue(buffer, value.encode());
} else if (value is TrackMessage) {
} else if (value is StreamingPropertyTypeMessage) {
buffer.putUint8(139);
writeValue(buffer, value.encode());
} else if (value is TrackTypeMessage) {
} else if (value is TrackMessage) {
buffer.putUint8(140);
writeValue(buffer, value.encode());
} else if (value is VolumeMessage) {
} else if (value is TrackTypeMessage) {
buffer.putUint8(141);
writeValue(buffer, value.encode());
} else if (value is VolumeMessage) {
buffer.putUint8(142);
writeValue(buffer, value.encode());
} else {
super.writeValue(buffer, value);
}
Expand All @@ -471,32 +505,34 @@ class _VideoPlayerAvplayApiCodec extends StandardMessageCodec {
Object? readValueOfType(int type, ReadBuffer buffer) {
switch (type) {
case 128:
return CreateMessage.decode(readValue(buffer)!);
return BufferConfigMessage.decode(readValue(buffer)!);
case 129:
return DurationMessage.decode(readValue(buffer)!);
return CreateMessage.decode(readValue(buffer)!);
case 130:
return GeometryMessage.decode(readValue(buffer)!);
return DurationMessage.decode(readValue(buffer)!);
case 131:
return LoopingMessage.decode(readValue(buffer)!);
return GeometryMessage.decode(readValue(buffer)!);
case 132:
return MixWithOthersMessage.decode(readValue(buffer)!);
return LoopingMessage.decode(readValue(buffer)!);
case 133:
return PlaybackSpeedMessage.decode(readValue(buffer)!);
return MixWithOthersMessage.decode(readValue(buffer)!);
case 134:
return PlayerMessage.decode(readValue(buffer)!);
return PlaybackSpeedMessage.decode(readValue(buffer)!);
case 135:
return PositionMessage.decode(readValue(buffer)!);
return PlayerMessage.decode(readValue(buffer)!);
case 136:
return SelectedTracksMessage.decode(readValue(buffer)!);
return PositionMessage.decode(readValue(buffer)!);
case 137:
return StreamingPropertyMessage.decode(readValue(buffer)!);
return SelectedTracksMessage.decode(readValue(buffer)!);
case 138:
return StreamingPropertyTypeMessage.decode(readValue(buffer)!);
return StreamingPropertyMessage.decode(readValue(buffer)!);
case 139:
return TrackMessage.decode(readValue(buffer)!);
return StreamingPropertyTypeMessage.decode(readValue(buffer)!);
case 140:
return TrackTypeMessage.decode(readValue(buffer)!);
return TrackMessage.decode(readValue(buffer)!);
case 141:
return TrackTypeMessage.decode(readValue(buffer)!);
case 142:
return VolumeMessage.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
Expand Down Expand Up @@ -967,4 +1003,32 @@ class VideoPlayerAvplayApi {
return (replyList[0] as StreamingPropertyMessage?)!;
}
}

Future<bool> setBufferConfig(BufferConfigMessage arg_msg) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.video_player_avplay.VideoPlayerAvplayApi.setBufferConfig',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_msg]) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyList.length > 1) {
throw PlatformException(
code: replyList[0]! as String,
message: replyList[1] as String?,
details: replyList[2],
);
} else if (replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (replyList[0] as bool?)!;
}
}
}
21 changes: 21 additions & 0 deletions packages/video_player_avplay/lib/src/video_player_tizen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ class VideoPlayerTizen extends VideoPlayerPlatform {
return streamingPropertyMessage.streamingProperty;
}

@override
Future<bool> setBufferConfig(int playerId, BufferConfigType type, int value) {
return _api.setBufferConfig(BufferConfigMessage(
playerId: playerId,
bufferConfigType: _bufferConfigTypeMap[type]!,
bufferConfigValue: value));
}

@override
Stream<VideoEvent> videoEventsFor(int playerId) {
return _eventChannelFor(playerId)
Expand Down Expand Up @@ -314,4 +322,17 @@ class VideoPlayerTizen extends VideoPlayerPlatform {
StreamingPropertyType.userAgent: 'USER_AGENT',
StreamingPropertyType.useVideoMixer: 'USE_VIDEOMIXER',
};

static const Map<BufferConfigType, String> _bufferConfigTypeMap =
<BufferConfigType, String>{
BufferConfigType.totalBufferSizeInByte: 'total_buffer_size_in_byte',
BufferConfigType.totalBufferSizeInTime: 'total_buffer_size_in_time',
BufferConfigType.bufferSizeInByteForPlay: 'buffer_size_in_byte_for_play',
BufferConfigType.bufferSizeInSecForPlay: 'buffer_size_in_sec_for_play',
BufferConfigType.bufferSizeInByteForResume:
'buffer_size_in_byte_for_resume',
BufferConfigType.bufferSizeInSecForResume: 'buffer_size_in_sec_for_resume',
BufferConfigType.bufferingTimeoutInSecForPlay:
'buffering_timeout_in_sec_for_play',
};
}
11 changes: 11 additions & 0 deletions packages/video_player_avplay/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,17 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
return _videoPlayerPlatform.getStreamingProperty(_playerId, type);
}

/// Sets the buffer size for the play and resume scenarios. The time buffer size must be at least 4 seconds.
/// For example, if a 10 second buffer size is set, playback can only start or resume after 10 seconds of media has accumulated in the buffer.
/// Play scenarios include user-initiated streaming playback and whenever media playback is starting for the first time.
/// Resume scenarios include resuming playback after pause or seek operations, or when lack of data causes playback rebuffering.
Future<bool> setBufferConfig(BufferConfigType type, int value) async {
if (_isDisposedOrNotInitialized) {
return false;
}
return _videoPlayerPlatform.setBufferConfig(_playerId, type, value);
}

/// Sets the playback speed of [this].
///
/// [speed] indicates a speed value with different platforms accepting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
'getStreamingProperty() has not been implemented.');
}

/// Sets the buffer size for the player.
Future<bool> setBufferConfig(int playerId, BufferConfigType type, int value) {
throw UnimplementedError('setBufferConfig() has not been implemented.');
}

/// Returns a widget displaying the video with a given playerId.
Widget buildView(int playerId) {
throw UnimplementedError('buildView() has not been implemented.');
Expand Down Expand Up @@ -317,6 +322,30 @@ enum StreamingPropertyType {
inAppMultiView,
}

/// The different types of buffer configurations that can be set on the player.
enum BufferConfigType {
/// Total buffer size in byte.
totalBufferSizeInByte,

/// Total buffer size in time.
totalBufferSizeInTime,

/// Buffer size for play in byte.
bufferSizeInByteForPlay,

/// Buffer size for play in time.
bufferSizeInSecForPlay,

/// Buffer size for resume in byte.
bufferSizeInByteForResume,

/// Buffer size for resume in time.
bufferSizeInSecForResume,

/// Buffering timeout for play in seconds.
bufferingTimeoutInSecForPlay,
}

/// Event emitted from the platform implementation.
@immutable
class VideoEvent {
Expand Down
9 changes: 9 additions & 0 deletions packages/video_player_avplay/pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ class StreamingPropertyTypeMessage {
String streamingPropertyType;
}

class BufferConfigMessage {
BufferConfigMessage(
this.playerId, this.bufferConfigType, this.bufferConfigValue);
int playerId;
String bufferConfigType;
int bufferConfigValue;
}

@HostApi()
abstract class VideoPlayerAvplayApi {
void initialize();
Expand All @@ -123,4 +131,5 @@ abstract class VideoPlayerAvplayApi {
void setDisplayGeometry(GeometryMessage msg);
StreamingPropertyMessage getStreamingProperty(
StreamingPropertyTypeMessage msg);
bool setBufferConfig(BufferConfigMessage msg);
}
2 changes: 1 addition & 1 deletion packages/video_player_avplay/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_avplay
description: Flutter plugin for displaying inline video on Tizen TV devices.
homepage: https://github.com/flutter-tizen/plugins
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/video_player_avplay
version: 0.4.6
version: 0.4.7

environment:
sdk: ">=3.1.0 <4.0.0"
Expand Down
Loading

0 comments on commit c368cef

Please sign in to comment.