diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-09-01 05:09:07 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-09-01 19:10:22 +0200 |
commit | fbbd3950c82195e4d1b7d681aea0a9bd2fa67f4b (patch) | |
tree | ec04565f8a54f32b11871e7806af1484fc916df2 /modules/webrtc | |
parent | 8c7be63588bf3e4ef4b780ff57936c68db5939c7 (diff) |
Simplify network GDExtension bindings using EXBIND macros.
Simplify StreamPeer, PacketPeer, MultiplayerPeer extension.
Simplify and update WebRTC*Extension with newly supported types.
Diffstat (limited to 'modules/webrtc')
-rw-r--r-- | modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml | 12 | ||||
-rw-r--r-- | modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml | 14 | ||||
-rw-r--r-- | modules/webrtc/webrtc_data_channel_extension.cpp | 148 | ||||
-rw-r--r-- | modules/webrtc/webrtc_data_channel_extension.h | 59 | ||||
-rw-r--r-- | modules/webrtc/webrtc_peer_connection_extension.cpp | 70 | ||||
-rw-r--r-- | modules/webrtc/webrtc_peer_connection_extension.h | 31 |
6 files changed, 50 insertions, 284 deletions
diff --git a/modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml b/modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml index 5387deaa47..a10ea25b8c 100644 --- a/modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml +++ b/modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml @@ -48,7 +48,7 @@ </description> </method> <method name="_get_packet" qualifiers="virtual"> - <return type="int" /> + <return type="int" enum="Error" /> <param index="0" name="r_buffer" type="const uint8_t **" /> <param index="1" name="r_buffer_size" type="int32_t*" /> <description> @@ -60,12 +60,12 @@ </description> </method> <method name="_get_ready_state" qualifiers="virtual const"> - <return type="int" /> + <return type="int" enum="WebRTCDataChannel.ChannelState" /> <description> </description> </method> <method name="_get_write_mode" qualifiers="virtual const"> - <return type="int" /> + <return type="int" enum="WebRTCDataChannel.WriteMode" /> <description> </description> </method> @@ -80,12 +80,12 @@ </description> </method> <method name="_poll" qualifiers="virtual"> - <return type="int" /> + <return type="int" enum="Error" /> <description> </description> </method> <method name="_put_packet" qualifiers="virtual"> - <return type="int" /> + <return type="int" enum="Error" /> <param index="0" name="p_buffer" type="const uint8_t*" /> <param index="1" name="p_buffer_size" type="int" /> <description> @@ -93,7 +93,7 @@ </method> <method name="_set_write_mode" qualifiers="virtual"> <return type="void" /> - <param index="0" name="p_write_mode" type="int" /> + <param index="0" name="p_write_mode" type="int" enum="WebRTCDataChannel.WriteMode" /> <description> </description> </method> diff --git a/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml b/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml index e22e939a66..3c4bf18a76 100644 --- a/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml +++ b/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml @@ -8,7 +8,7 @@ </tutorials> <methods> <method name="_add_ice_candidate" qualifiers="virtual"> - <return type="int" /> + <return type="int" enum="Error" /> <param index="0" name="p_sdp_mid_name" type="String" /> <param index="1" name="p_sdp_mline_index" type="int" /> <param index="2" name="p_sdp_name" type="String" /> @@ -28,35 +28,35 @@ </description> </method> <method name="_create_offer" qualifiers="virtual"> - <return type="int" /> + <return type="int" enum="Error" /> <description> </description> </method> <method name="_get_connection_state" qualifiers="virtual const"> - <return type="int" /> + <return type="int" enum="WebRTCPeerConnection.ConnectionState" /> <description> </description> </method> <method name="_initialize" qualifiers="virtual"> - <return type="int" /> + <return type="int" enum="Error" /> <param index="0" name="p_config" type="Dictionary" /> <description> </description> </method> <method name="_poll" qualifiers="virtual"> - <return type="int" /> + <return type="int" enum="Error" /> <description> </description> </method> <method name="_set_local_description" qualifiers="virtual"> - <return type="int" /> + <return type="int" enum="Error" /> <param index="0" name="p_type" type="String" /> <param index="1" name="p_sdp" type="String" /> <description> </description> </method> <method name="_set_remote_description" qualifiers="virtual"> - <return type="int" /> + <return type="int" enum="Error" /> <param index="0" name="p_type" type="String" /> <param index="1" name="p_sdp" type="String" /> <description> diff --git a/modules/webrtc/webrtc_data_channel_extension.cpp b/modules/webrtc/webrtc_data_channel_extension.cpp index b7ea8d22bb..4e16b77e81 100644 --- a/modules/webrtc/webrtc_data_channel_extension.cpp +++ b/modules/webrtc/webrtc_data_channel_extension.cpp @@ -56,160 +56,20 @@ void WebRTCDataChannelExtension::_bind_methods() { GDVIRTUAL_BIND(_get_buffered_amount); } -int WebRTCDataChannelExtension::get_available_packet_count() const { - int count; - if (GDVIRTUAL_CALL(_get_available_packet_count, count)) { - return count; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_available_packet_count is unimplemented!"); - return -1; -} - Error WebRTCDataChannelExtension::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - int err; + Error err; if (GDVIRTUAL_CALL(_get_packet, r_buffer, &r_buffer_size, err)) { - return (Error)err; + return err; } WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_packet_native is unimplemented!"); return FAILED; } Error WebRTCDataChannelExtension::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - int err; + Error err; if (GDVIRTUAL_CALL(_put_packet, p_buffer, p_buffer_size, err)) { - return (Error)err; + return err; } WARN_PRINT_ONCE("WebRTCDataChannelExtension::_put_packet_native is unimplemented!"); return FAILED; } - -int WebRTCDataChannelExtension::get_max_packet_size() const { - int size; - if (GDVIRTUAL_CALL(_get_max_packet_size, size)) { - return size; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_size is unimplemented!"); - return 0; -} - -Error WebRTCDataChannelExtension::poll() { - int err; - if (GDVIRTUAL_CALL(_poll, err)) { - return (Error)err; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_poll is unimplemented!"); - return ERR_UNCONFIGURED; -} - -void WebRTCDataChannelExtension::close() { - if (GDVIRTUAL_CALL(_close)) { - return; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_close is unimplemented!"); -} - -void WebRTCDataChannelExtension::set_write_mode(WriteMode p_mode) { - if (GDVIRTUAL_CALL(_set_write_mode, p_mode)) { - return; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_set_write_mode is unimplemented!"); -} - -WebRTCDataChannel::WriteMode WebRTCDataChannelExtension::get_write_mode() const { - int mode; - if (GDVIRTUAL_CALL(_get_write_mode, mode)) { - return (WriteMode)mode; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_write_mode is unimplemented!"); - return WRITE_MODE_BINARY; -} - -bool WebRTCDataChannelExtension::was_string_packet() const { - bool was_string; - if (GDVIRTUAL_CALL(_was_string_packet, was_string)) { - return was_string; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_was_string_packet is unimplemented!"); - return false; -} - -WebRTCDataChannel::ChannelState WebRTCDataChannelExtension::get_ready_state() const { - int state; - if (GDVIRTUAL_CALL(_get_ready_state, state)) { - return (ChannelState)state; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_ready_state is unimplemented!"); - return STATE_CLOSED; -} - -String WebRTCDataChannelExtension::get_label() const { - String label; - if (GDVIRTUAL_CALL(_get_label, label)) { - return label; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_label is unimplemented!"); - return label; -} - -bool WebRTCDataChannelExtension::is_ordered() const { - bool ordered; - if (GDVIRTUAL_CALL(_is_ordered, ordered)) { - return ordered; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_ordered is unimplemented!"); - return false; -} - -int WebRTCDataChannelExtension::get_id() const { - int id; - if (GDVIRTUAL_CALL(_get_id, id)) { - return id; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_id is unimplemented!"); - return -1; -} - -int WebRTCDataChannelExtension::get_max_packet_life_time() const { - int lifetime; - if (GDVIRTUAL_CALL(_get_max_packet_life_time, lifetime)) { - return lifetime; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_life_time is unimplemented!"); - return -1; -} - -int WebRTCDataChannelExtension::get_max_retransmits() const { - int retransmits; - if (GDVIRTUAL_CALL(_get_max_retransmits, retransmits)) { - return retransmits; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_retransmits is unimplemented!"); - return -1; -} - -String WebRTCDataChannelExtension::get_protocol() const { - String protocol; - if (GDVIRTUAL_CALL(_get_protocol, protocol)) { - return protocol; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_protocol is unimplemented!"); - return protocol; -} - -bool WebRTCDataChannelExtension::is_negotiated() const { - bool negotiated; - if (GDVIRTUAL_CALL(_is_negotiated, negotiated)) { - return negotiated; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_negotiated is unimplemented!"); - return false; -} - -int WebRTCDataChannelExtension::get_buffered_amount() const { - int amount; - if (GDVIRTUAL_CALL(_get_buffered_amount, amount)) { - return amount; - } - WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_buffered_amount is unimplemented!"); - return -1; -} diff --git a/modules/webrtc/webrtc_data_channel_extension.h b/modules/webrtc/webrtc_data_channel_extension.h index 83bb627815..467163ed93 100644 --- a/modules/webrtc/webrtc_data_channel_extension.h +++ b/modules/webrtc/webrtc_data_channel_extension.h @@ -33,6 +33,7 @@ #include "webrtc_data_channel.h" +#include "core/extension/ext_wrappers.gen.inc" #include "core/object/gdvirtual.gen.inc" #include "core/object/script_language.h" #include "core/variant/native_ptr.h" @@ -44,53 +45,33 @@ protected: static void _bind_methods(); public: - virtual void set_write_mode(WriteMode mode) override; - virtual WriteMode get_write_mode() const override; - virtual bool was_string_packet() const override; + EXBIND0R(Error, poll); + EXBIND0(close); - virtual ChannelState get_ready_state() const override; - virtual String get_label() const override; - virtual bool is_ordered() const override; - virtual int get_id() const override; - virtual int get_max_packet_life_time() const override; - virtual int get_max_retransmits() const override; - virtual String get_protocol() const override; - virtual bool is_negotiated() const override; - virtual int get_buffered_amount() const override; + EXBIND1(set_write_mode, WriteMode); + EXBIND0RC(WriteMode, get_write_mode); - virtual Error poll() override; - virtual void close() override; + EXBIND0RC(bool, was_string_packet); + + EXBIND0RC(ChannelState, get_ready_state); + EXBIND0RC(String, get_label); + EXBIND0RC(bool, is_ordered); + EXBIND0RC(int, get_id); + EXBIND0RC(int, get_max_packet_life_time); + EXBIND0RC(int, get_max_retransmits); + EXBIND0RC(String, get_protocol); + EXBIND0RC(bool, is_negotiated); + EXBIND0RC(int, get_buffered_amount); /** Inherited from PacketPeer: **/ - virtual int get_available_packet_count() const override; + EXBIND0RC(int, get_available_packet_count); + EXBIND0RC(int, get_max_packet_size); virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual int get_max_packet_size() const override; - /** GDExtension **/ - GDVIRTUAL0RC(int, _get_available_packet_count); - GDVIRTUAL2R(int, _get_packet, GDNativeConstPtr<const uint8_t *>, GDNativePtr<int>); - GDVIRTUAL2R(int, _put_packet, GDNativeConstPtr<const uint8_t>, int); - GDVIRTUAL0RC(int, _get_max_packet_size); - - GDVIRTUAL0R(int, _poll); - GDVIRTUAL0(_close); - - GDVIRTUAL1(_set_write_mode, int); - GDVIRTUAL0RC(int, _get_write_mode); - - GDVIRTUAL0RC(bool, _was_string_packet); - - GDVIRTUAL0RC(int, _get_ready_state); - GDVIRTUAL0RC(String, _get_label); - GDVIRTUAL0RC(bool, _is_ordered); - GDVIRTUAL0RC(int, _get_id); - GDVIRTUAL0RC(int, _get_max_packet_life_time); - GDVIRTUAL0RC(int, _get_max_retransmits); - GDVIRTUAL0RC(String, _get_protocol); - GDVIRTUAL0RC(bool, _is_negotiated); - GDVIRTUAL0RC(int, _get_buffered_amount); + GDVIRTUAL2R(Error, _get_packet, GDNativeConstPtr<const uint8_t *>, GDNativePtr<int>); + GDVIRTUAL2R(Error, _put_packet, GDNativeConstPtr<const uint8_t>, int); WebRTCDataChannelExtension() {} }; diff --git a/modules/webrtc/webrtc_peer_connection_extension.cpp b/modules/webrtc/webrtc_peer_connection_extension.cpp index 85c04b3b19..54143e4b79 100644 --- a/modules/webrtc/webrtc_peer_connection_extension.cpp +++ b/modules/webrtc/webrtc_peer_connection_extension.cpp @@ -42,24 +42,6 @@ void WebRTCPeerConnectionExtension::_bind_methods() { GDVIRTUAL_BIND(_close); } -WebRTCPeerConnection::ConnectionState WebRTCPeerConnectionExtension::get_connection_state() const { - int state; - if (GDVIRTUAL_CALL(_get_connection_state, state)) { - return (ConnectionState)state; - } - WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_get_connection_state is unimplemented!"); - return STATE_DISCONNECTED; -} - -Error WebRTCPeerConnectionExtension::initialize(Dictionary p_config) { - int err; - if (GDVIRTUAL_CALL(_initialize, p_config, err)) { - return (Error)err; - } - WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_initialize is unimplemented!"); - return ERR_UNCONFIGURED; -} - Ref<WebRTCDataChannel> WebRTCPeerConnectionExtension::create_data_channel(String p_label, Dictionary p_options) { Object *ret = nullptr; if (GDVIRTUAL_CALL(_create_data_channel, p_label, p_options, ret)) { @@ -70,55 +52,3 @@ Ref<WebRTCDataChannel> WebRTCPeerConnectionExtension::create_data_channel(String WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_data_channel is unimplemented!"); return nullptr; } - -Error WebRTCPeerConnectionExtension::create_offer() { - int err; - if (GDVIRTUAL_CALL(_create_offer, err)) { - return (Error)err; - } - WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_offer is unimplemented!"); - return ERR_UNCONFIGURED; -} - -Error WebRTCPeerConnectionExtension::set_local_description(String p_type, String p_sdp) { - int err; - if (GDVIRTUAL_CALL(_set_local_description, p_type, p_sdp, err)) { - return (Error)err; - } - WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_local_description is unimplemented!"); - return ERR_UNCONFIGURED; -} - -Error WebRTCPeerConnectionExtension::set_remote_description(String p_type, String p_sdp) { - int err; - if (GDVIRTUAL_CALL(_set_remote_description, p_type, p_sdp, err)) { - return (Error)err; - } - WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_remote_description is unimplemented!"); - return ERR_UNCONFIGURED; -} - -Error WebRTCPeerConnectionExtension::add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) { - int err; - if (GDVIRTUAL_CALL(_add_ice_candidate, p_sdp_mid_name, p_sdp_mline_index, p_sdp_name, err)) { - return (Error)err; - } - WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_add_ice_candidate is unimplemented!"); - return ERR_UNCONFIGURED; -} - -Error WebRTCPeerConnectionExtension::poll() { - int err; - if (GDVIRTUAL_CALL(_poll, err)) { - return (Error)err; - } - WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_poll is unimplemented!"); - return ERR_UNCONFIGURED; -} - -void WebRTCPeerConnectionExtension::close() { - if (GDVIRTUAL_CALL(_close)) { - return; - } - WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_close is unimplemented!"); -} diff --git a/modules/webrtc/webrtc_peer_connection_extension.h b/modules/webrtc/webrtc_peer_connection_extension.h index bde19c173b..0c324ca45f 100644 --- a/modules/webrtc/webrtc_peer_connection_extension.h +++ b/modules/webrtc/webrtc_peer_connection_extension.h @@ -33,6 +33,7 @@ #include "webrtc_peer_connection.h" +#include "core/extension/ext_wrappers.gen.inc" #include "core/object/gdvirtual.gen.inc" #include "core/object/script_language.h" #include "core/variant/native_ptr.h" @@ -44,27 +45,21 @@ protected: static void _bind_methods(); public: - virtual ConnectionState get_connection_state() const override; - - virtual Error initialize(Dictionary p_config = Dictionary()) override; + // FIXME Can't be directly exposed due to issues in exchanging Ref(s) between godot and extensions. + // See godot-cpp GH-652 . virtual Ref<WebRTCDataChannel> create_data_channel(String p_label, Dictionary p_options = Dictionary()) override; - virtual Error create_offer() override; - virtual Error set_remote_description(String type, String sdp) override; - virtual Error set_local_description(String type, String sdp) override; - virtual Error add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) override; - virtual Error poll() override; - virtual void close() override; + GDVIRTUAL2R(Object *, _create_data_channel, String, Dictionary); + // EXBIND2R(Ref<WebRTCDataChannel>, create_data_channel, String, Dictionary); /** GDExtension **/ - GDVIRTUAL0RC(int, _get_connection_state); - GDVIRTUAL1R(int, _initialize, Dictionary); - GDVIRTUAL2R(Object *, _create_data_channel, String, Dictionary); - GDVIRTUAL0R(int, _create_offer); - GDVIRTUAL2R(int, _set_remote_description, String, String); - GDVIRTUAL2R(int, _set_local_description, String, String); - GDVIRTUAL3R(int, _add_ice_candidate, String, int, String); - GDVIRTUAL0R(int, _poll); - GDVIRTUAL0(_close); + EXBIND0RC(ConnectionState, get_connection_state); + EXBIND1R(Error, initialize, Dictionary); + EXBIND0R(Error, create_offer); + EXBIND2R(Error, set_remote_description, String, String); + EXBIND2R(Error, set_local_description, String, String); + EXBIND3R(Error, add_ice_candidate, String, int, String); + EXBIND0R(Error, poll); + EXBIND0(close); WebRTCPeerConnectionExtension() {} }; |