mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 13:50:40 +01:00
Enforcing return type handling on VoIP API.
- This CL also affects some return type handling in Android Voip demo app due to changes in return type handling. Bug: webrtc:12193 Change-Id: Id76faf7c871476ed1f2d08fb587211ae234ae8d3 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/196625 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Tim Na <natim@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32821}
This commit is contained in:
parent
1a9be30702
commit
9325d343e5
6 changed files with 39 additions and 30 deletions
|
@ -21,6 +21,7 @@ rtc_source_set("voip_api") {
|
|||
]
|
||||
deps = [
|
||||
"..:array_view",
|
||||
"../../rtc_base/system:unused",
|
||||
"../audio_codecs:audio_codecs_api",
|
||||
"../neteq:neteq_api",
|
||||
]
|
||||
|
|
|
@ -3,6 +3,10 @@ specific_include_rules = {
|
|||
"+third_party/absl/types/optional.h",
|
||||
],
|
||||
|
||||
"voip_base.h": [
|
||||
"+rtc_base/system/unused.h",
|
||||
],
|
||||
|
||||
"voip_engine_factory.h": [
|
||||
"+modules/audio_device/include/audio_device.h",
|
||||
"+modules/audio_processing/include/audio_processing.h",
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#define API_VOIP_VOIP_BASE_H_
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "rtc_base/system/unused.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
|
@ -35,7 +36,7 @@ class Transport;
|
|||
|
||||
enum class ChannelId : int {};
|
||||
|
||||
enum class VoipResult {
|
||||
enum class RTC_WARN_UNUSED_RESULT VoipResult {
|
||||
// kOk indicates the function was successfully invoked with no error.
|
||||
kOk,
|
||||
// kInvalidArgument indicates the caller specified an invalid argument, such
|
||||
|
|
|
@ -70,14 +70,18 @@ TEST_F(VoipCoreTest, BasicVoipCoreOperation) {
|
|||
|
||||
auto channel = voip_core_->CreateChannel(&transport_, 0xdeadc0de);
|
||||
|
||||
voip_core_->SetSendCodec(channel, kPcmuPayload, kPcmuFormat);
|
||||
voip_core_->SetReceiveCodecs(channel, {{kPcmuPayload, kPcmuFormat}});
|
||||
EXPECT_EQ(voip_core_->SetSendCodec(channel, kPcmuPayload, kPcmuFormat),
|
||||
VoipResult::kOk);
|
||||
EXPECT_EQ(
|
||||
voip_core_->SetReceiveCodecs(channel, {{kPcmuPayload, kPcmuFormat}}),
|
||||
VoipResult::kOk);
|
||||
|
||||
EXPECT_EQ(voip_core_->StartSend(channel), VoipResult::kOk);
|
||||
EXPECT_EQ(voip_core_->StartPlayout(channel), VoipResult::kOk);
|
||||
|
||||
voip_core_->RegisterTelephoneEventType(channel, kPcmuPayload,
|
||||
kPcmuSampleRateHz);
|
||||
EXPECT_EQ(voip_core_->RegisterTelephoneEventType(channel, kPcmuPayload,
|
||||
kPcmuSampleRateHz),
|
||||
VoipResult::kOk);
|
||||
|
||||
EXPECT_EQ(
|
||||
voip_core_->SendDtmfEvent(channel, kDtmfEventCode, kDtmfEventDurationMs),
|
||||
|
@ -125,7 +129,8 @@ TEST_F(VoipCoreTest, SendDtmfEventWithoutRegistering) {
|
|||
|
||||
auto channel = voip_core_->CreateChannel(&transport_, 0xdeadc0de);
|
||||
|
||||
voip_core_->SetSendCodec(channel, kPcmuPayload, kPcmuFormat);
|
||||
EXPECT_EQ(voip_core_->SetSendCodec(channel, kPcmuPayload, kPcmuFormat),
|
||||
VoipResult::kOk);
|
||||
|
||||
EXPECT_EQ(voip_core_->StartSend(channel), VoipResult::kOk);
|
||||
// Send Dtmf event without registering beforehand, thus payload
|
||||
|
@ -145,8 +150,10 @@ TEST_F(VoipCoreTest, SendDtmfEventWithoutRegistering) {
|
|||
TEST_F(VoipCoreTest, SendDtmfEventWithoutStartSend) {
|
||||
auto channel = voip_core_->CreateChannel(&transport_, 0xdeadc0de);
|
||||
|
||||
voip_core_->RegisterTelephoneEventType(channel, kPcmuPayload,
|
||||
kPcmuSampleRateHz);
|
||||
EXPECT_EQ(voip_core_->RegisterTelephoneEventType(channel, kPcmuPayload,
|
||||
kPcmuSampleRateHz),
|
||||
VoipResult::kOk);
|
||||
|
||||
// Send Dtmf event without calling StartSend beforehand, thus
|
||||
// Dtmf events cannot be sent and kFailedPrecondition is expected.
|
||||
EXPECT_EQ(
|
||||
|
|
|
@ -120,7 +120,7 @@ int GetPayloadType(const std::string& codec_name) {
|
|||
|
||||
namespace webrtc_examples {
|
||||
|
||||
bool AndroidVoipClient::Init(
|
||||
void AndroidVoipClient::Init(
|
||||
JNIEnv* env,
|
||||
const webrtc::JavaParamRef<jobject>& application_context) {
|
||||
webrtc::VoipEngineConfig config;
|
||||
|
@ -132,20 +132,16 @@ bool AndroidVoipClient::Init(
|
|||
config.audio_processing = webrtc::AudioProcessingBuilder().Create();
|
||||
|
||||
voip_thread_->Start();
|
||||
|
||||
// Due to consistent thread requirement on
|
||||
// modules/audio_device/android/audio_device_template.h,
|
||||
// code is invoked in the context of voip_thread_.
|
||||
return voip_thread_->Invoke<bool>(RTC_FROM_HERE, [this, &config] {
|
||||
voip_thread_->Invoke<void>(RTC_FROM_HERE, [this, &config] {
|
||||
RTC_DCHECK_RUN_ON(voip_thread_.get());
|
||||
|
||||
supported_codecs_ = config.encoder_factory->GetSupportedEncoders();
|
||||
env_ = webrtc::AttachCurrentThreadIfNeeded();
|
||||
voip_engine_ = webrtc::CreateVoipEngine(std::move(config));
|
||||
if (!voip_engine_) {
|
||||
RTC_LOG(LS_ERROR) << "VoipEngine creation failed";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -175,9 +171,7 @@ AndroidVoipClient* AndroidVoipClient::Create(
|
|||
// Using `new` to access a non-public constructor.
|
||||
auto voip_client =
|
||||
absl::WrapUnique(new AndroidVoipClient(env, j_voip_client));
|
||||
if (!voip_client->Init(env, application_context)) {
|
||||
return nullptr;
|
||||
}
|
||||
voip_client->Init(env, application_context);
|
||||
return voip_client.release();
|
||||
}
|
||||
|
||||
|
@ -220,8 +214,9 @@ void AndroidVoipClient::SetEncoder(const std::string& encoder) {
|
|||
}
|
||||
for (const webrtc::AudioCodecSpec& codec : supported_codecs_) {
|
||||
if (codec.format.name == encoder) {
|
||||
voip_engine_->Codec().SetSendCodec(
|
||||
webrtc::VoipResult result = voip_engine_->Codec().SetSendCodec(
|
||||
*channel_, GetPayloadType(codec.format.name), codec.format);
|
||||
RTC_CHECK(result == webrtc::VoipResult::kOk);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +246,9 @@ void AndroidVoipClient::SetDecoders(const std::vector<std::string>& decoders) {
|
|||
}
|
||||
}
|
||||
|
||||
webrtc::VoipResult result =
|
||||
voip_engine_->Codec().SetReceiveCodecs(*channel_, decoder_specs);
|
||||
RTC_CHECK(result == webrtc::VoipResult::kOk);
|
||||
}
|
||||
|
||||
void AndroidVoipClient::SetDecoders(
|
||||
|
@ -305,13 +302,8 @@ void AndroidVoipClient::SetRemoteAddress(
|
|||
void AndroidVoipClient::StartSession(JNIEnv* env) {
|
||||
RUN_ON_VOIP_THREAD(StartSession, env);
|
||||
|
||||
// CreateChannel guarantees to return valid channel id.
|
||||
channel_ = voip_engine_->Base().CreateChannel(this, absl::nullopt);
|
||||
if (!channel_) {
|
||||
RTC_LOG(LS_ERROR) << "Channel creation failed";
|
||||
Java_VoipClient_onStartSessionCompleted(env_, j_voip_client_,
|
||||
/*isSuccessful=*/false);
|
||||
return;
|
||||
}
|
||||
|
||||
rtp_socket_.reset(rtc::AsyncUDPSocket::Create(voip_thread_->socketserver(),
|
||||
rtp_local_address_));
|
||||
|
@ -357,7 +349,9 @@ void AndroidVoipClient::StopSession(JNIEnv* env) {
|
|||
rtp_socket_->Close();
|
||||
rtcp_socket_->Close();
|
||||
|
||||
voip_engine_->Base().ReleaseChannel(*channel_);
|
||||
webrtc::VoipResult result = voip_engine_->Base().ReleaseChannel(*channel_);
|
||||
RTC_CHECK(result == webrtc::VoipResult::kOk);
|
||||
|
||||
channel_ = absl::nullopt;
|
||||
Java_VoipClient_onStopSessionCompleted(env_, j_voip_client_,
|
||||
/*isSuccessful=*/true);
|
||||
|
@ -470,9 +464,10 @@ void AndroidVoipClient::ReadRTPPacket(const std::vector<uint8_t>& packet_copy) {
|
|||
RTC_LOG(LS_ERROR) << "Channel has not been created";
|
||||
return;
|
||||
}
|
||||
voip_engine_->Network().ReceivedRTPPacket(
|
||||
webrtc::VoipResult result = voip_engine_->Network().ReceivedRTPPacket(
|
||||
*channel_,
|
||||
rtc::ArrayView<const uint8_t>(packet_copy.data(), packet_copy.size()));
|
||||
RTC_CHECK(result == webrtc::VoipResult::kOk);
|
||||
}
|
||||
|
||||
void AndroidVoipClient::OnSignalReadRTPPacket(rtc::AsyncPacketSocket* socket,
|
||||
|
@ -495,9 +490,10 @@ void AndroidVoipClient::ReadRTCPPacket(
|
|||
RTC_LOG(LS_ERROR) << "Channel has not been created";
|
||||
return;
|
||||
}
|
||||
voip_engine_->Network().ReceivedRTCPPacket(
|
||||
webrtc::VoipResult result = voip_engine_->Network().ReceivedRTCPPacket(
|
||||
*channel_,
|
||||
rtc::ArrayView<const uint8_t>(packet_copy.data(), packet_copy.size()));
|
||||
RTC_CHECK(result == webrtc::VoipResult::kOk);
|
||||
}
|
||||
|
||||
void AndroidVoipClient::OnSignalReadRTCPPacket(rtc::AsyncPacketSocket* socket,
|
||||
|
|
|
@ -141,7 +141,7 @@ class AndroidVoipClient : public webrtc::Transport,
|
|||
: voip_thread_(rtc::Thread::CreateWithSocketServer()),
|
||||
j_voip_client_(env, j_voip_client) {}
|
||||
|
||||
bool Init(JNIEnv* env,
|
||||
void Init(JNIEnv* env,
|
||||
const webrtc::JavaParamRef<jobject>& application_context);
|
||||
|
||||
// Overloaded methods having native C++ variables as arguments.
|
||||
|
|
Loading…
Reference in a new issue