feat: (for now android only!) dscp retrieval and configuration methods

This commit is contained in:
Andrew 2026-04-28 15:08:25 +07:00
parent 02cc6ad612
commit 82c1a3f96c
6 changed files with 104 additions and 6 deletions

View file

@ -242,6 +242,23 @@ class LiblinphoneFlutterPlugin : FlutterPlugin, ActivityAware, MethodCallHandler
result.success(linphoneBridge.getPlaybackGain()) result.success(linphoneBridge.getPlaybackGain())
} }
"setDscp" -> {
try {
val sipDscp = call.argument<Int>("sipDscp")
val audioDscp = call.argument<Int>("audioDscp")
val videoDscp = call.argument<Int>("videoDscp")
linphoneBridge.setDscp(sipDscp, audioDscp, videoDscp)
result.success(true)
} catch (e: Exception) {
Log.e(TAG, "setDscp: ${e.message}")
result.error("error", e.message, e)
}
}
"getDscp" -> {
result.success(linphoneBridge.getDscp().toMap())
}
else -> { else -> {
result.notImplemented() result.notImplemented()
} }

View file

@ -393,4 +393,24 @@ class LinphoneBridge(
fun getPlaybackGain(): Float { fun getPlaybackGain(): Float {
return core.getPlaybackGainDb() return core.getPlaybackGainDb()
} }
data class DscpValues(val sipDscp: Int, val audioDscp: Int, val videoDscp: Int) {
fun toMap(): Map<String, Any?> {
return mapOf(
"sipDscp" to sipDscp,
"audioDscp" to audioDscp,
"videoDscp" to videoDscp,
);
}
}
fun setDscp(sipDscp: Int?, audioDscp: Int?, videoDscp: Int?) {
sipDscp?.let { core.sipDscp = it }
audioDscp?.let { core.audioDscp = it }
videoDscp?.let { core.videoDscp = it }
}
fun getDscp(): DscpValues {
return DscpValues(core.sipDscp, core.audioDscp, core.videoDscp)
}
} }

View file

@ -2,6 +2,7 @@ import 'package:flutter/services.dart' show EventChannel;
import 'liblinphone_flutter_platform_interface.dart'; import 'liblinphone_flutter_platform_interface.dart';
import 'models/call_type.dart'; import 'models/call_type.dart';
import 'models/dscp_values.dart';
import 'models/registration_state.dart'; import 'models/registration_state.dart';
import 'models/call_state.dart'; import 'models/call_state.dart';
@ -102,4 +103,14 @@ class LiblinphoneFlutter {
Future<double> getPlaybackGain() async => Future<double> getPlaybackGain() async =>
LiblinphoneFlutterPlatform.instance.getPlaybackGain(); LiblinphoneFlutterPlatform.instance.getPlaybackGain();
Future<bool> setDscp(int sipDscp, int audioDscp, int videoDscp) async =>
LiblinphoneFlutterPlatform.instance.setDscp(
sipDscp,
audioDscp,
videoDscp,
);
Future<DscpValues> getDscp() async =>
LiblinphoneFlutterPlatform.instance.getDscp();
} }

View file

@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'liblinphone_flutter_platform_interface.dart'; import 'liblinphone_flutter_platform_interface.dart';
import 'models/call_type.dart'; import 'models/call_type.dart';
import 'models/dscp_values.dart';
/// An implementation of [LiblinphoneFlutterPlatform] that uses method channels. /// An implementation of [LiblinphoneFlutterPlatform] that uses method channels.
class MethodChannelLiblinphoneFlutter extends LiblinphoneFlutterPlatform { class MethodChannelLiblinphoneFlutter extends LiblinphoneFlutterPlatform {
@ -143,4 +144,22 @@ class MethodChannelLiblinphoneFlutter extends LiblinphoneFlutterPlatform {
Future<double> getPlaybackGain() async { Future<double> getPlaybackGain() async {
return (await methodChannel.invokeMethod<double>('getPlaybackGain'))!; return (await methodChannel.invokeMethod<double>('getPlaybackGain'))!;
} }
@override
Future<bool> setDscp(int sipDscp, int audioDscp, int videoDscp) async {
return (await methodChannel.invokeMethod<bool>('setDscp', <String, dynamic>{
'sipDscp': sipDscp,
'audioDscp': audioDscp,
'videoDscp': videoDscp,
}))!;
}
@override
Future<DscpValues> getDscp() async {
final data = (await methodChannel.invokeMethod<Map<dynamic, dynamic>>(
'getDscp',
))!;
final values = DscpValues.fromJson(data);
return values;
}
} }

View file

@ -2,6 +2,7 @@ import 'package:liblinphone_flutter/models/call_type.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'liblinphone_flutter_method_channel.dart'; import 'liblinphone_flutter_method_channel.dart';
import 'models/dscp_values.dart';
abstract class LiblinphoneFlutterPlatform extends PlatformInterface { abstract class LiblinphoneFlutterPlatform extends PlatformInterface {
/// Constructs a LiblinphoneFlutterPlatform. /// Constructs a LiblinphoneFlutterPlatform.
@ -39,7 +40,9 @@ abstract class LiblinphoneFlutterPlatform extends PlatformInterface {
String serverIp, String serverIp,
int serverPort, int serverPort,
) { ) {
throw UnimplementedError('register() has not been implemented.'); throw UnimplementedError(
'register(String username, String password, String serverIp, int serverPort) has not been implemented.',
);
} }
Future<bool> unregister() { Future<bool> unregister() {
@ -52,14 +55,18 @@ abstract class LiblinphoneFlutterPlatform extends PlatformInterface {
String notificationTitle, String notificationTitle,
String notificationMessage, String notificationMessage,
) { ) {
throw UnimplementedError('makeCall() has not been implemented.'); throw UnimplementedError(
'makeCall(String callTo, bool isVideoEnabled, String notificationTitle, String notificationMessage) has not been implemented.',
);
} }
Future<bool> answerCall( Future<bool> answerCall(
String notificationTitle, String notificationTitle,
String notificationMessage, String notificationMessage,
) { ) {
throw UnimplementedError('answerCall() has not been implemented.'); throw UnimplementedError(
'answerCall(String notificationTitle, String notificationMessage) has not been implemented.',
);
} }
Future<bool> hangupCall() { Future<bool> hangupCall() {
@ -91,7 +98,7 @@ abstract class LiblinphoneFlutterPlatform extends PlatformInterface {
} }
Future<bool> sendDtmf(String tone) { Future<bool> sendDtmf(String tone) {
throw UnimplementedError('sendDtmf() has not been implemented.'); throw UnimplementedError('sendDtmf(String tone) has not been implemented.');
} }
Future<bool> stopCallService() async { Future<bool> stopCallService() async {
@ -99,7 +106,9 @@ abstract class LiblinphoneFlutterPlatform extends PlatformInterface {
} }
Future<bool> setMicGain(double level) async { Future<bool> setMicGain(double level) async {
throw UnimplementedError('setMicGain() has not been implemented.'); throw UnimplementedError(
'setMicGain(double level) has not been implemented.',
);
} }
Future<double> getMicGain() async { Future<double> getMicGain() async {
@ -107,10 +116,22 @@ abstract class LiblinphoneFlutterPlatform extends PlatformInterface {
} }
Future<bool> setPlaybackGain(double level) async { Future<bool> setPlaybackGain(double level) async {
throw UnimplementedError('setPlaybackGain() has not been implemented.'); throw UnimplementedError(
'setPlaybackGain(double level) has not been implemented.',
);
} }
Future<double> getPlaybackGain() async { Future<double> getPlaybackGain() async {
throw UnimplementedError('getPlaybackGain() has not been implemented.'); throw UnimplementedError('getPlaybackGain() has not been implemented.');
} }
Future<bool> setDscp(int sipDscp, int audioDscp, int videoDscp) async {
throw UnimplementedError(
'setDscp(int sipDscp, int audioDscp, int videoDscp) has not been implemented.',
);
}
Future<DscpValues> getDscp() async {
throw UnimplementedError('getDscp() has not been implemented.');
}
} }

View file

@ -0,0 +1,10 @@
final class DscpValues {
final int sipDscp;
final int audioDscp;
final int videoDscp;
const DscpValues(this.sipDscp, this.audioDscp, this.videoDscp);
factory DscpValues.fromJson(Map<dynamic, dynamic> json) =>
DscpValues(json["sipDscp"], json["audioDscp"], json["videoDscp"]);
}