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

Implements extended API for creating RtcRtpTransceivers #125

Merged
merged 24 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 21 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ All user visible changes to this project will be documented in this file. This p

[Diff](https://github.com/instrumentisto/medea-flutter-webrtc/compare/0.8.2...0.8.3)

### Added

- `RtpTransceiverInit.sendEncodings` field with `SendEncodingParameters`s. ([#125])

### Changed

- Refactor Audio Device Module to use [OpenAL] library for playout. ([#117])
Expand All @@ -21,6 +25,7 @@ All user visible changes to this project will be documented in this file. This p
[#119]: https://github.com/instrumentisto/medea-flutter-webrtc/pull/119
[#120]: https://github.com/instrumentisto/medea-flutter-webrtc/pull/120
[#123]: https://github.com/instrumentisto/medea-flutter-webrtc/pull/123
[#125]: https://github.com/instrumentisto/medea-flutter-webrtc/pull/125
[116.0.5845.110]: https://github.com/instrumentisto/libwebrtc-bin/releases/tag/116.0.5845.110


Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ flutter.run:
# Run Flutter plugin integration tests on the current host as desktop.
#
# Usage:
# make flutter.test [debug=(no|yes)]
# make flutter.test.desktop [debug=(no|yes)]

flutter.test.desktop:
cd example/ && \
Expand Down Expand Up @@ -302,7 +302,8 @@ endif
--dart-output=lib/src/api/bridge.g.dart \
--skip-add-mod-to-lib \
--no-build-runner \
--dart-format-line-length=80
--dart-enums-style \
--inline-rust
flutter pub run build_runner build --delete-conflicting-outputs


Expand Down Expand Up @@ -392,6 +393,7 @@ endif
swift.fmt:
ifeq ($(dockerized),yes)
docker run --rm -v "$(PWD)":/app -w /app \
-u $(shell id -u):$(shell id -g) \
ghcr.io/nicklockwood/swiftformat:latest \
$(if $(call eq,$(check),yes),--lint,) ios/Classes/
else
Expand Down
3 changes: 2 additions & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
#Thu Sep 28 10:50:19 CEST 2023
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.instrumentisto.medea_flutter_webrtc.model

import org.webrtc.RtpParameters.Encoding as WEncoding

/**
* Representation of an [org.webrtc.RtpParameters.Encoding].
*
* @property rid 'rid' of this encoding parameters, created from this config.
* @property active Indicates whether this parameters are active.
* @property maxBitrate Maximum bitrate for this parameters.
* @property maxFramerate Maximum framerate for this parameters.
* @property scaleResolutionDownBy Resolution will be scaled down for this parameters.
*/
data class Encoding(
var rid: String,
var active: Boolean,
var maxBitrate: Int?,
var maxFramerate: Double?,
var scaleResolutionDownBy: Double?,
) {
companion object {
/**
* Creates a new [Encoding] object based on the method call received from the Flutter side.
*
* @return [Encoding] created from the provided [Map].
*/
fun fromMap(map: Map<String, Any>): Encoding {
return Encoding(
map["rid"] as String,
map["active"] as Boolean,
map["maxBitrate"] as Int?,
map["maxFramerate"] as Double?,
map["scaleResolutionDownBy"] as Double?)
}
}

/**
* Converts this [Encoding] into an [org.webrtc.RtpParameters.Encoding].
*
* @return [org.webrtc.RtpParameters.Encoding] created based on this [Encoding].
*/
fun intoWebRtc(): WEncoding {
var encoding: WEncoding = WEncoding(rid, active, scaleResolutionDownBy)
encoding.maxBitrateBps = maxBitrate
encoding.maxFramerate = maxFramerate?.toInt()
return encoding
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import org.webrtc.RtpTransceiver.RtpTransceiverInit as WRtpTransceiverInit
* Representation of an [org.webrtc.RtpTransceiver.RtpTransceiverInit].
*
* @property direction Direction of the transceiver, created from this config.
* @property encodings [List] of the [Encoding]s, created from this config.
*/
data class RtpTransceiverInit(val direction: RtpTransceiverDirection) {
data class RtpTransceiverInit(
val direction: RtpTransceiverDirection,
var encodings: List<Encoding>
) {
companion object {
/**
* Creates a new [RtpTransceiverInit] object based on the method call received from the Flutter
Expand All @@ -16,7 +20,11 @@ data class RtpTransceiverInit(val direction: RtpTransceiverDirection) {
* @return [RtpTransceiverInit] created from the provided [Map].
*/
fun fromMap(map: Map<String, Any>): RtpTransceiverInit {
return RtpTransceiverInit(RtpTransceiverDirection.fromInt(map["direction"] as Int))
return RtpTransceiverInit(
RtpTransceiverDirection.fromInt(map["direction"] as Int),
(map["sendEncodings"] as List<Map<String, Map<String, Any>>>).map { encoding ->
Encoding.fromMap(encoding)
})
}
}

Expand All @@ -27,6 +35,7 @@ data class RtpTransceiverInit(val direction: RtpTransceiverDirection) {
* [RtpTransceiverInit].
*/
fun intoWebRtc(): WRtpTransceiverInit {
return WRtpTransceiverInit(direction.intoWebRtc())
return WRtpTransceiverInit(
direction.intoWebRtc(), listOf(), encodings.map { e -> e.intoWebRtc() })
}
}
30 changes: 23 additions & 7 deletions crates/libwebrtc-sys/include/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include "api/video_codecs/builtin_video_encoder_factory.h"
#include "api/video_track_source_proxy_factory.h"
#if __APPLE__
#include "libwebrtc-sys/include/device_info_mac.h"
#include "mac_capturer.h"
#include "device_info_mac.h"
#include "device_info_mac.h"
#include "libwebrtc-sys/include/device_info_mac.h"
#include "mac_capturer.h"
#else
#include "device_video_capturer.h"
#include "device_video_capturer.h"
#endif
#include "modules/audio_device/include/audio_device.h"
#include "modules/video_capture/video_capture_factory.h"
Expand All @@ -30,8 +30,8 @@
#include "adm_proxy.h"

#include "media/base/fake_frame_source.h"
#include "pc/test/fake_video_track_source.h"
#include "modules/audio_device/include/test_audio_device.h"
#include "pc/test/fake_video_track_source.h"

namespace bridge {

Expand Down Expand Up @@ -172,8 +172,9 @@ int32_t set_audio_recording_device(const AudioDeviceModule& audio_device_module,
int32_t stop_playout(const AudioDeviceModule& audio_device_module);

// Sets stereo availability of the specified playout device.
int32_t stereo_playout_is_available(const AudioDeviceModule& audio_device_module,
bool available);
int32_t stereo_playout_is_available(
const AudioDeviceModule& audio_device_module,
bool available);

// Initializes the specified audio playout device.
int32_t init_playout(const AudioDeviceModule& audio_device_module);
Expand Down Expand Up @@ -383,6 +384,21 @@ std::unique_ptr<RTCOfferAnswerOptions> create_rtc_offer_answer_options(
bool ice_restart,
bool use_rtp_mux);

// Creates a new default `RtpTransceiverInit`.
std::unique_ptr<RtpTransceiverInit> create_default_rtp_transceiver_init();

// Sets a `RtpTransceiverDirection` for the provided `RtpTransceiverInit`.
void set_rtp_transceiver_init_direction(RtpTransceiverInit& init,
RtpTransceiverDirection direction);

// Adds a `RtpEncodingParameters` into the provided `RtpTransceiverInit`.
void add_rtp_transceiver_init_send_encoding(
RtpTransceiverInit& init,
const RtpEncodingParametersContainer& params);

// Creates a new default `RtpEncodingParameters`.
RtpEncodingParametersContainer create_rtp_encoding_parameters();

// Creates a new `CreateSessionDescriptionObserver` from the provided
// `bridge::DynCreateSdpCallback`.
std::unique_ptr<CreateSessionDescriptionObserver>
Expand Down
3 changes: 2 additions & 1 deletion crates/libwebrtc-sys/include/peer_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using SessionDescriptionInterface = webrtc::SessionDescriptionInterface;
using RtpTransceiverInterface =
rtc::scoped_refptr<webrtc::RtpTransceiverInterface>;
using RtpTransceiverDirection = webrtc::RtpTransceiverDirection;
using RtpTransceiverInit = webrtc::RtpTransceiverInit;

struct TransceiverContainer;
struct DynPeerConnectionEventsHandler;
Expand Down Expand Up @@ -214,7 +215,7 @@ void set_remote_description(PeerConnectionInterface& peer,
std::unique_ptr<RtpTransceiverInterface> add_transceiver(
PeerConnectionInterface& peer,
cricket::MediaType media_type,
RtpTransceiverDirection direction);
const RtpTransceiverInit& init);

// Returns a list of `RtpTransceiverInterface`s attached to the provided
// `PeerConnectionInterface`.
Expand Down
35 changes: 32 additions & 3 deletions crates/libwebrtc-sys/include/rtp_encoding_parameters.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
#pragma once

#include "bridge.h"
#include "rust/cxx.h"

namespace bridge {

// Sets the `RtpEncodingParameters.rid` field value.
void set_rtp_encoding_parameters_rid(webrtc::RtpEncodingParameters& encoding,
rust::String rid);

// Returns the `RtpEncodingParameters.active` field value.
bool rtp_encoding_parameters_active(
const webrtc::RtpEncodingParameters& encoding);

// Sets the `RtpEncodingParameters.active` field value.
void set_rtp_encoding_parameters_active(webrtc::RtpEncodingParameters& encoding,
bool active);

// Returns the `RtpEncodingParameters.maxBitrate` field value.
int32_t rtp_encoding_parameters_maxBitrate(
int32_t rtp_encoding_parameters_max_bitrate(
const webrtc::RtpEncodingParameters& encoding);

// Returns the `RtpEncodingParameters.maxBitrate` field value.
void set_rtp_encoding_parameters_max_bitrate(
webrtc::RtpEncodingParameters& encoding,
int32_t max_bitrate);

// Returns the `RtpEncodingParameters.minBitrate` field value.
int32_t rtp_encoding_parameters_minBitrate(
int32_t rtp_encoding_parameters_min_bitrate(
const webrtc::RtpEncodingParameters& encoding);

// Returns the `RtpEncodingParameters.maxFramerate` field value.
double rtp_encoding_parameters_maxFramerate(
double rtp_encoding_parameters_max_framerate(
const webrtc::RtpEncodingParameters& encoding);

// Sets the `RtpEncodingParameters.maxFramerate` field value.
void set_rtp_encoding_parameters_max_framerate(
webrtc::RtpEncodingParameters& encoding,
double max_framrate);

// Returns the `RtpEncodingParameters.ssrc` field value.
int64_t rtp_encoding_parameters_ssrc(
const webrtc::RtpEncodingParameters& encoding);
Expand All @@ -28,4 +47,14 @@ int64_t rtp_encoding_parameters_ssrc(
double rtp_encoding_parameters_scale_resolution_down_by(
const webrtc::RtpEncodingParameters& encoding);

// Sets the `RtpEncodingParameters.scale_resolution_down_by` field value.
void set_rtp_encoding_parameters_scale_resolution_down_by(
webrtc::RtpEncodingParameters& encoding,
double scale_resolution_down_by);

// Sets the `RtpEncodingParameters.scalability_mode` field value.
void set_rtp_encoding_parameters_scalability_mode(
webrtc::RtpEncodingParameters& encoding,
rust::String scalability_mode);

} // namespace bridge
71 changes: 67 additions & 4 deletions crates/libwebrtc-sys/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1519,41 +1519,90 @@ pub(crate) mod webrtc {
) -> bool;
}

#[rustfmt::skip]
unsafe extern "C++" {
pub type RtpTransceiverInit;

/// Creates a new default [`RtpTransceiverInit`].
#[must_use]
pub fn create_default_rtp_transceiver_init() -> UniquePtr<RtpTransceiverInit>;

/// Sets a [`RtpTransceiverDirection`] for the provided [`RtpTransceiverInit`].
pub fn set_rtp_transceiver_init_direction(
init: Pin<&mut RtpTransceiverInit>,
direction: RtpTransceiverDirection
);

/// Adds a [`RtpEncodingParameters`] into the provided [`RtpTransceiverInit`].
pub fn add_rtp_transceiver_init_send_encoding(
init: Pin<&mut RtpTransceiverInit>,
encoding: &RtpEncodingParametersContainer
);

/// Creates a new default [`RtpEncodingParameters`].
#[must_use]
pub fn create_rtp_encoding_parameters() -> RtpEncodingParametersContainer;
}

#[rustfmt::skip]
unsafe extern "C++" {
include!("libwebrtc-sys/include/rtp_encoding_parameters.h");

#[namespace = "webrtc"]
pub type RtpEncodingParameters;

/// Sets the `rid` of the provided [`RtpEncodingParameters`].
pub fn set_rtp_encoding_parameters_rid(
encoding: Pin<&mut RtpEncodingParameters>,
rid: String
);

/// Returns the `active` of the provided [`RtpEncodingParameters`].
#[must_use]
pub fn rtp_encoding_parameters_active(
encoding: &RtpEncodingParameters,
) -> bool;

/// Sets the `active` of the provided [`RtpEncodingParameters`].
pub fn set_rtp_encoding_parameters_active(
encoding: Pin<&mut RtpEncodingParameters>,
active: bool
);

/// Returns the `maxBitrate` of the provided [`RtpEncodingParameters`].
///
/// [`Result::Err`] means [`None`].
pub fn rtp_encoding_parameters_maxBitrate(
pub fn rtp_encoding_parameters_max_bitrate(
encoding: &RtpEncodingParameters,
) -> Result<i32>;

/// Sets the `maxBitrate` of the provided [`RtpEncodingParameters`].
pub fn set_rtp_encoding_parameters_max_bitrate(
encoding: Pin<&mut RtpEncodingParameters>,
max_bitrate: i32
);

/// Returns the `minBitrate` of the provided [`RtpEncodingParameters`].
///
/// [`Result::Err`] means [`None`].
pub fn rtp_encoding_parameters_minBitrate(
pub fn rtp_encoding_parameters_min_bitrate(
encoding: &RtpEncodingParameters,
) -> Result<i32>;

/// Returns the `maxFramerate` of the provided
/// [`RtpEncodingParameters`].
///
/// [`Result::Err`] means [`None`].
pub fn rtp_encoding_parameters_maxFramerate(
pub fn rtp_encoding_parameters_max_framerate(
encoding: &RtpEncodingParameters,
) -> Result<f64>;

/// Sets the `maxFramerate` of the provided [`RtpEncodingParameters`].
pub fn set_rtp_encoding_parameters_max_framerate(
encoding: Pin<&mut RtpEncodingParameters>,
max_framrate: f64
);

/// Returns the `ssrc` of the provided [`RtpEncodingParameters`].
///
/// [`Result::Err`] means [`None`].
Expand All @@ -1568,6 +1617,20 @@ pub(crate) mod webrtc {
pub fn rtp_encoding_parameters_scale_resolution_down_by(
encoding: &RtpEncodingParameters,
) -> Result<f64>;

/// Sets the `scale_resolution_down_by` of the provided
/// [`RtpEncodingParameters`].
pub fn set_rtp_encoding_parameters_scale_resolution_down_by(
encoding: Pin<&mut RtpEncodingParameters>,
scale_resolution_down_by: f64
);

/// Sets the `scalability_mode` of the provided
/// [`RtpEncodingParameters`].
pub fn set_rtp_encoding_parameters_scalability_mode(
encoding: Pin<&mut RtpEncodingParameters>,
scalability_mode: String
);
}

#[rustfmt::skip]
Expand Down Expand Up @@ -2031,7 +2094,7 @@ pub(crate) mod webrtc {
pub fn add_transceiver(
peer_connection_interface: Pin<&mut PeerConnectionInterface>,
media_type: MediaType,
direction: RtpTransceiverDirection
init: &RtpTransceiverInit
) -> UniquePtr<RtpTransceiverInterface>;

/// Returns a sequence of [`RtpTransceiverInterface`] objects
Expand Down
Loading
Loading