diff --git a/server/src/client/web/VoiceBridge.cpp b/server/src/client/web/VoiceBridge.cpp index 42c4244..e791ae5 100644 --- a/server/src/client/web/VoiceBridge.cpp +++ b/server/src/client/web/VoiceBridge.cpp @@ -77,18 +77,16 @@ std::shared_ptr VoiceBridge::owner() { bool VoiceBridge::initialize(std::string &error) { if(!this->connection->initialize(error)) return false; - this->connection->callback_ice_candidate = [&](const rtc::IceCandidate& candidate, bool last_candidate) { - auto function_callback = this->callback_ice_candidate; - - if(function_callback) - function_callback(candidate); - if(last_candidate) { - auto function_callback_end = this->callback_ice_candidate_finished; - this->negotiation_possible = true; - if(function_callback_end) - function_callback_end(); + this->connection->callback_ice_candidate = [&](const rtc::IceCandidate& candidate) { + if(candidate.is_finished_candidate()) { + if(auto callback{this->callback_ice_candidate}; callback) + callback(candidate); + } else { + if(auto callback{this->callback_ice_candidate_finished}; callback) + callback(); } }; + this->connection->callback_new_stream = [&](const std::shared_ptr &channel) { this->handle_media_stream(channel); }; //bind(&VoiceBridge::handle_media_stream, this, placeholders::_1); => crash this->connection->callback_setup_fail = [&](rtc::PeerConnection::ConnectionComponent comp, const std::string& reason) { debugMessage(this->server_id(), "{} WebRTC setup failed! Component {} ({})", CLIENT_STR_LOG_PREFIX_(this->owner()), comp, reason); @@ -109,12 +107,7 @@ int VoiceBridge::apply_ice(const std::deque>& } void VoiceBridge::remote_ice_finished() { - if(negotiation_possible) { - this->connection->execute_negotiation(); - negotiation_required = false; - } else { - negotiation_required = true; - } + this->connection->remote_candidates_finished(); } std::string VoiceBridge::generate_answer() { @@ -128,10 +121,6 @@ void VoiceBridge::execute_tick() { this->connection->callback_setup_fail(rtc::PeerConnection::ConnectionComponent::BASE, "setup timeout"); } } - if(this->negotiation_required && this->negotiation_possible) { - this->connection->execute_negotiation(); - negotiation_required = false; - } } void VoiceBridge::handle_media_stream(const std::shared_ptr &undefined_stream) { @@ -174,40 +163,6 @@ void VoiceBridge::handle_data_channel(const std::shared_ptr &c }; } -/* - ssize_t sample_count = 960; - ssize_t sample_length = sample_count * 2; - opus_int16 samples[sample_length]; - - if(!this->decoder) { - int error; - this->decoder = opus_decoder_create(48000, 2, &error); - assert(error == 0 && this->decoder); - } - if(!this->encoder) { - int error; - this->encoder = opus_encoder_create(48000, 2, OPUS_APPLICATION_AUDIO, &error); - assert(error == 0 && this->encoder); - } - - { - sample_count = opus_decode(this->decoder, (u_char*) &data.data()[payload_offset], data.length() - payload_offset, samples, sample_count, 0); - if(sample_count < 0) { - logError(this->server_id(), "Could not decode opus!"); - return; - } - } - - string target_buffer(512, '\0'); //Way too big! - le2be16(this->voice.packet_id++, (char*) target_buffer.data()); - target_buffer[2] = 5; - - auto encoded = opus_encode(this->encoder, samples, sample_count, (u_char*) &target_buffer[3], 512 - 3); - if(encoded < 0 ){ - logError(this->server_id(), "Could not encode opus!"); - return; - } -*/ void VoiceBridge::handle_audio_data(const std::shared_ptr &channel, const pipes::buffer_view &data, size_t payload_offset) { if(channel->codec->type != rtc::codec::TypedAudio::OPUS) { debugMessage(this->server_id(), "{} Got unknown codec ({})!", CLIENT_STR_LOG_PREFIX_(this->owner()), channel->codec->type); diff --git a/server/src/client/web/VoiceBridge.h b/server/src/client/web/VoiceBridge.h index e55f9d5..d0a8632 100644 --- a/server/src/client/web/VoiceBridge.h +++ b/server/src/client/web/VoiceBridge.h @@ -53,9 +53,6 @@ namespace ts { uint16_t packet_id = 0; bool muted = true; } voice; - - bool negotiation_possible = false; - bool negotiation_required = false; }; } } \ No newline at end of file