Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[video_player_avplay] Add setStreamingProperty API #735

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/video_player_avplay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## NEXT
## 0.4.8

* Call the open before calling the SetStreamingProperty.
* Change getStreamingProperty API return type from StreamingPropertyMessage to String.
* Add setStreamingProperty API.

## 0.4.7

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.7
video_player_avplay: ^0.4.8
```

Then you can import `video_player_avplay` in your Dart code:
Expand Down
73 changes: 66 additions & 7 deletions packages/video_player_avplay/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,37 @@ class StreamingPropertyTypeMessage {
}
}

class StreamingPropertyMessage {
StreamingPropertyMessage({
required this.playerId,
required this.streamingPropertyType,
required this.streamingPropertyValue,
});

int playerId;

String streamingPropertyType;

String streamingPropertyValue;

Object encode() {
return <Object?>[
playerId,
streamingPropertyType,
streamingPropertyValue,
];
}

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

class BufferConfigMessage {
BufferConfigMessage({
required this.playerId,
Expand Down Expand Up @@ -455,18 +486,21 @@ class _VideoPlayerAvplayApiCodec extends StandardMessageCodec {
} 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 Down Expand Up @@ -496,12 +530,14 @@ class _VideoPlayerAvplayApiCodec extends StandardMessageCodec {
case 137:
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 @@ -1000,4 +1036,27 @@ class VideoPlayerAvplayApi {
return (replyList[0] as bool?)!;
}
}

Future<void> setStreamingProperty(StreamingPropertyMessage arg_msg) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.video_player_avplay.VideoPlayerAvplayApi.setStreamingProperty',
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 {
return;
}
}
}
12 changes: 11 additions & 1 deletion packages/video_player_avplay/lib/src/video_player_tizen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,23 @@ class VideoPlayerTizen extends VideoPlayerPlatform {
}

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

@override
Future<void> setStreamingProperty(
int playerId, StreamingPropertyType type, String value) async {
await _api.setStreamingProperty(StreamingPropertyMessage(
playerId: playerId,
streamingPropertyType: _streamingPropertyType[type]!,
streamingPropertyValue: value));
}

@override
Stream<VideoEvent> videoEventsFor(int playerId) {
return _eventChannelFor(playerId)
Expand Down
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 specific feature values for HTTP, MMS, or specific streaming engine (Smooth Streaming, HLS, DASH, DivX Plus Streaming, or Widevine).
/// The available streaming properties depend on the streaming protocol or engine.
/// Use the CUSTOM_MESSAGE property for streaming engine or CP-specific settings.
JSUYA marked this conversation as resolved.
Show resolved Hide resolved
Future<void> setStreamingProperty(
StreamingPropertyType type, String value) async {
if (_isDisposedOrNotInitialized) {
return;
}
return _videoPlayerPlatform.setStreamingProperty(_playerId, type, value);
}

/// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
throw UnimplementedError('setBufferConfig() has not been implemented.');
}

/// Set streamingengine property.
Future<void> setStreamingProperty(
int playerId, StreamingPropertyType type, String value) {
throw UnimplementedError(
'setStreamingProperty() 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
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 @@ -95,6 +95,14 @@ class StreamingPropertyTypeMessage {
String streamingPropertyType;
}

class StreamingPropertyMessage {
StreamingPropertyMessage(
this.playerId, this.streamingPropertyType, this.streamingPropertyValue);
int playerId;
String streamingPropertyType;
String streamingPropertyValue;
}

class BufferConfigMessage {
BufferConfigMessage(
this.playerId, this.bufferConfigType, this.bufferConfigValue);
Expand Down Expand Up @@ -125,4 +133,5 @@ abstract class VideoPlayerAvplayApi {
void setDisplayGeometry(GeometryMessage msg);
String getStreamingProperty(StreamingPropertyTypeMessage msg);
bool setBufferConfig(BufferConfigMessage msg);
void setStreamingProperty(StreamingPropertyMessage 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.7
version: 0.4.8

environment:
sdk: ">=3.1.0 <4.0.0"
Expand Down
112 changes: 105 additions & 7 deletions packages/video_player_avplay/tizen/src/messages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,56 @@ StreamingPropertyTypeMessage StreamingPropertyTypeMessage::FromEncodableList(
return decoded;
}

// StreamingPropertyMessage

StreamingPropertyMessage::StreamingPropertyMessage(
int64_t player_id, const std::string& streaming_property_type,
const std::string& streaming_property_value)
: player_id_(player_id),
streaming_property_type_(streaming_property_type),
streaming_property_value_(streaming_property_value) {}

int64_t StreamingPropertyMessage::player_id() const { return player_id_; }

void StreamingPropertyMessage::set_player_id(int64_t value_arg) {
player_id_ = value_arg;
}

const std::string& StreamingPropertyMessage::streaming_property_type() const {
return streaming_property_type_;
}

void StreamingPropertyMessage::set_streaming_property_type(
std::string_view value_arg) {
streaming_property_type_ = value_arg;
}

const std::string& StreamingPropertyMessage::streaming_property_value() const {
return streaming_property_value_;
}

void StreamingPropertyMessage::set_streaming_property_value(
std::string_view value_arg) {
streaming_property_value_ = value_arg;
}

EncodableList StreamingPropertyMessage::ToEncodableList() const {
EncodableList list;
list.reserve(3);
list.push_back(EncodableValue(player_id_));
list.push_back(EncodableValue(streaming_property_type_));
list.push_back(EncodableValue(streaming_property_value_));
return list;
}

StreamingPropertyMessage StreamingPropertyMessage::FromEncodableList(
const EncodableList& list) {
StreamingPropertyMessage decoded(list[0].LongValue(),
std::get<std::string>(list[1]),
std::get<std::string>(list[2]));
return decoded;
}

// BufferConfigMessage

BufferConfigMessage::BufferConfigMessage(int64_t player_id,
Expand Down Expand Up @@ -681,16 +731,19 @@ EncodableValue VideoPlayerAvplayApiCodecSerializer::ReadValueOfType(
return CustomEncodableValue(SelectedTracksMessage::FromEncodableList(
std::get<EncodableList>(ReadValue(stream))));
case 138:
return CustomEncodableValue(StreamingPropertyMessage::FromEncodableList(
std::get<EncodableList>(ReadValue(stream))));
case 139:
return CustomEncodableValue(
StreamingPropertyTypeMessage::FromEncodableList(
std::get<EncodableList>(ReadValue(stream))));
case 139:
case 140:
return CustomEncodableValue(TrackMessage::FromEncodableList(
std::get<EncodableList>(ReadValue(stream))));
case 140:
case 141:
return CustomEncodableValue(TrackTypeMessage::FromEncodableList(
std::get<EncodableList>(ReadValue(stream))));
case 141:
case 142:
return CustomEncodableValue(VolumeMessage::FromEncodableList(
std::get<EncodableList>(ReadValue(stream))));
default:
Expand Down Expand Up @@ -782,32 +835,40 @@ void VideoPlayerAvplayApiCodecSerializer::WriteValue(
stream);
return;
}
if (custom_value->type() == typeid(StreamingPropertyTypeMessage)) {
if (custom_value->type() == typeid(StreamingPropertyMessage)) {
stream->WriteByte(138);
WriteValue(
EncodableValue(std::any_cast<StreamingPropertyMessage>(*custom_value)
.ToEncodableList()),
stream);
return;
}
if (custom_value->type() == typeid(StreamingPropertyTypeMessage)) {
stream->WriteByte(139);
WriteValue(EncodableValue(
std::any_cast<StreamingPropertyTypeMessage>(*custom_value)
.ToEncodableList()),
stream);
return;
}
if (custom_value->type() == typeid(TrackMessage)) {
stream->WriteByte(139);
stream->WriteByte(140);
WriteValue(
EncodableValue(
std::any_cast<TrackMessage>(*custom_value).ToEncodableList()),
stream);
return;
}
if (custom_value->type() == typeid(TrackTypeMessage)) {
stream->WriteByte(140);
stream->WriteByte(141);
WriteValue(
EncodableValue(
std::any_cast<TrackTypeMessage>(*custom_value).ToEncodableList()),
stream);
return;
}
if (custom_value->type() == typeid(VolumeMessage)) {
stream->WriteByte(141);
stream->WriteByte(142);
WriteValue(
EncodableValue(
std::any_cast<VolumeMessage>(*custom_value).ToEncodableList()),
Expand Down Expand Up @@ -1486,6 +1547,43 @@ void VideoPlayerAvplayApi::SetUp(flutter::BinaryMessenger* binary_messenger,
channel->SetMessageHandler(nullptr);
}
}
{
auto channel = std::make_unique<BasicMessageChannel<>>(
binary_messenger,
"dev.flutter.pigeon.video_player_avplay.VideoPlayerAvplayApi."
"setStreamingProperty",
&GetCodec());
if (api != nullptr) {
channel->SetMessageHandler(
[api](const EncodableValue& message,
const flutter::MessageReply<EncodableValue>& reply) {
try {
const auto& args = std::get<EncodableList>(message);
const auto& encodable_msg_arg = args.at(0);
if (encodable_msg_arg.IsNull()) {
reply(WrapError("msg_arg unexpectedly null."));
return;
}
const auto& msg_arg =
std::any_cast<const StreamingPropertyMessage&>(
std::get<CustomEncodableValue>(encodable_msg_arg));
std::optional<FlutterError> output =
api->SetStreamingProperty(msg_arg);
if (output.has_value()) {
reply(WrapError(output.value()));
return;
}
EncodableList wrapped;
wrapped.push_back(EncodableValue());
reply(EncodableValue(std::move(wrapped)));
} catch (const std::exception& exception) {
reply(WrapError(exception.what()));
}
});
} else {
channel->SetMessageHandler(nullptr);
}
}
}

EncodableValue VideoPlayerAvplayApi::WrapError(std::string_view error_message) {
Expand Down
Loading
Loading