Skip to content

Commit

Permalink
Merge branch 'release/0.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverepper committed Apr 11, 2023
2 parents fce2a59 + bf54eea commit 199e923
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 89 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.3)

project(phone VERSION 0.6.0 LANGUAGES C CXX)
project(phone VERSION 0.6.1 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)

Expand Down
1 change: 1 addition & 0 deletions build-darwin-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sh ../scripts/build-pjproject-simulator-x86_64.sh "$(pwd)/../installed"

sh ../scripts/build-pjproject-macos-arm64.sh "$(pwd)/../installed"
sh ../scripts/build-pjproject-macos-x86_64.sh "$(pwd)/../installed"
sh ../scripts/create-pjproject-macos-universal.sh "$(pwd)/../installed"

sh ../scripts/build-pjproject-catalyst-arm64.sh "$(pwd)/../installed"
sh ../scripts/build-pjproject-catalyst-x86_64.sh "$(pwd)/../installed"
Expand Down
8 changes: 6 additions & 2 deletions scripts/build-opus-darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ MACCATALYST_X86_64_INSTALL_PREFIX="${PREFIX}/maccatalyst-x86_64"
build MAC_CATALYST "${MACCATALYST_X86_64_INSTALL_PREFIX}" 13.1

# build for macOS on arm64
MACOS_UNIVERSAL_INSTALL_PREFIX="${PREFIX}/macos-arm64"
build MAC_ARM64 "${MACOS_UNIVERSAL_INSTALL_PREFIX}" 11.0
MACOS_ARM64_INSTALL_PREFIX="${PREFIX}/macos-arm64"
build MAC_ARM64 "${MACOS_ARM64_INSTALL_PREFIX}" 11.0

# build for macOS on x86_64
MACOS_X86_64_INSTALL_PREFIX="${PREFIX}/macos-x86_64"
build MAC "${MACOS_X86_64_INSTALL_PREFIX}" 11.0

# build macOS universal
MACOS_UNIVERSAL_INSTALL_PREFIX="${PREFIX}/macos-universal"
build MAC_UNIVERSAL "${MACOS_UNIVERSAL_INSTALL_PREFIX}" 11.0
4 changes: 4 additions & 0 deletions scripts/build-sdl-darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ build MAC_ARM64 "${MACOS_ARM64_INSTALL_PREFIX}" 11.0
# build for macOS on x86_64
MACOS_X86_64_INSTALL_PREFIX="${PREFIX}/macos-x86_64"
build MAC "${MACOS_X86_64_INSTALL_PREFIX}" 11.0

# build macOS universal
MACOS_UNIVERSAL_INSTALL_PREFIX="${PREFIX}/macos-universal"
build MAC_UNIVERSAL "${MACOS_UNIVERSAL_INSTALL_PREFIX}" 11.0
23 changes: 23 additions & 0 deletions scripts/create-pjproject-macos-universal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# Oliver Epper <[email protected]>

source "$(dirname "$0")"/build-pjproject-darwin-base.sh

ARM64="${PREFIX}/macos-arm64"
X86_64="${PREFIX}/macos-x86_64"
UNIVERSAL="${PREFIX}/macos-universal"

rm -rf "${UNIVERSAL}"
mkdir "${UNIVERSAL}"

cp -a "${ARM64}"/* "${UNIVERSAL}"

rm -rf "${UNIVERSAL:?}"/lib/*

lipo -create \
"${ARM64}/lib/libpjproject.a" \
"${X86_64}/lib/libpjproject.a" \
-o "${UNIVERSAL}/lib/libpjproject.a"

pkgconfig_macos "${UNIVERSAL}"

2 changes: 1 addition & 1 deletion scripts/get-ios-toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [ -d ios-cmake ]
then
pushd ios-cmake
git clean -fxd
git reset --hard $IOS_TOOLCHAIN_IOS_TOOLCHAIN_COMMIT
git reset --hard "${IOS_TOOLCHAIN_IOS_TOOLCHAIN_COMMIT}"
popd
else
git clone https://github.com/leetal/ios-cmake.git
Expand Down
8 changes: 6 additions & 2 deletions src/cpp_cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ struct app_state {
<< " – Incoming call index: " << last_call_index
<< ", call id: " << phone.get_call_id(last_call_index)
<< std::endl;

auto incoming_message = phone.call_incoming_message(call_index);
if (incoming_message.has_value())
std::cout << incoming_message.value().substr(0, 10) + "... " << std::endl;
std::cout << incoming_message.value().substr(0, 64) + "... " << std::endl;

auto answer_after = phone.call_answer_after(call_index);
if (answer_after.has_value()) {
std::cout << "Will auto-answer call for you" << std::endl;
Expand All @@ -53,9 +55,11 @@ struct app_state {
<< " - Incoming call id: " << last_call_id
<< ", call index: " << phone.get_call_index(last_call_id)
<< std::endl;

auto incoming_message = phone.call_incoming_message(call_id);
if (incoming_message.has_value())
std::cout << incoming_message.value().substr(0, 10) + "... " << std::endl;
std::cout << incoming_message.value().substr(0, 64) + "... " << std::endl;

auto answer_after = phone.call_answer_after(call_id);
std::cout << "Will auto-answer call for you" << std::endl;
if (answer_after.has_value()) {
Expand Down
Binary file removed src/java_cli/Cli/libphone.0.dylib
Binary file not shown.
1 change: 0 additions & 1 deletion src/phone/include/phone_instance_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace pj {
class Endpoint;
class EpConfig;
} //namespace pj

class account_t;
Expand Down
143 changes: 62 additions & 81 deletions src/phone/include/private/account_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include "call_t.h"
#include <pjsua2.hpp>

namespace phone {
template<typename T>
concept CallID = std::is_same_v<T, int> || std::is_same_v<T, std::string>;
}

class account_t : public pj::Account {
public:
std::optional<std::function<void(bool, int)>> on_registration_state;
Expand All @@ -15,34 +20,35 @@ class account_t : public pj::Account {
void onRegState(pj::OnRegStateParam &prm) override {
auto info = getInfo();
if (info.regIsActive) {
PJ_LOG(3,(__BASE_FILE__, "register code: %d", prm.code));
PJ_LOG(3, (__BASE_FILE__, "register code: %d", prm.code));
} else {
PJ_LOG(3,(__BASE_FILE__, "unregister code: %d", prm.code));
PJ_LOG(3, (__BASE_FILE__, "unregister code: %d", prm.code));
}
if (on_registration_state.has_value()) on_registration_state.value()(info.regIsActive, prm.code);
}

void onIncomingCall(pj::OnIncomingCallParam &prm) override {
PJ_LOG(3,(__BASE_FILE__, "Incoming call: %d", prm.callId));
PJ_LOG(3, (__BASE_FILE__, "Incoming call: %d", prm.callId));
m_calls.emplace_back(std::make_unique<call_t>(*this,
[this](int id){ delete_call(id); },
[this](int id) { delete_call(id); },
prm.callId));

auto rx_data = static_cast<pjsip_rx_data *>(prm.rdata.pjRxData);
if (rx_data) {
// as an escape hatch save the complete INVITE message as a string
m_calls.back()->incoming_message.emplace(rx_data->msg_info.msg_buf);

auto call_info_key = pj_str((char *)"Call-Info");
auto call_info_header = static_cast<pjsip_generic_string_hdr *>(pjsip_msg_find_hdr_by_name(rx_data->msg_info.msg, &call_info_key,
nullptr));
auto call_info_key = pj_str((char *) "Call-Info");
auto call_info_header = static_cast<pjsip_generic_string_hdr *>(pjsip_msg_find_hdr_by_name(
rx_data->msg_info.msg, &call_info_key,
nullptr));
while (call_info_header != nullptr) {
/* IDEA maybe I should save the SERVER, too?
* Call-Info: <sip:SERVER>;answer-after=0
* std::optional<std::pair> answer-after
*/
do {
auto answer_after_key = pj_str((char *)"answer-after");
auto answer_after_key = pj_str((char *) "answer-after");
char *pos = pj_stristr(&call_info_header->hvalue, &answer_after_key);
if (pos == nullptr)
break;
Expand All @@ -51,121 +57,96 @@ class account_t : public pj::Account {
break;
try {
m_calls.back()->answer_after.emplace(std::stoi(++pos));
} catch (const std::invalid_argument& e) {
} catch (const std::invalid_argument &e) {
PJ_LOG(1, (__BASE_FILE__, "%s", e.what()));
} catch (const std::out_of_range& e) {
} catch (const std::out_of_range &e) {
PJ_LOG(1, (__BASE_FILE__, "%s", e.what()));
}
} while (false);
if (m_calls.back()->answer_after.has_value())
break;
call_info_header = static_cast<pjsip_generic_string_hdr *>(pjsip_msg_find_hdr_by_name(rx_data->msg_info.msg, &call_info_key, call_info_header->next));
call_info_header = static_cast<pjsip_generic_string_hdr *>(pjsip_msg_find_hdr_by_name(
rx_data->msg_info.msg, &call_info_key, call_info_header->next));
}
}

m_calls.back()->on_call_state_with_index = on_call_state_with_index;
m_calls.back()->on_call_state_with_id = on_call_state_with_id;
if (on_incoming_call_with_index.has_value()) on_incoming_call_with_index.value()(static_cast<int>(*m_calls.back()));
if (on_incoming_call_with_id.has_value()) on_incoming_call_with_id.value()(static_cast<std::string>(*m_calls.back()));
if (on_incoming_call_with_index.has_value())
on_incoming_call_with_index.value()(static_cast<int>(*m_calls.back()));
if (on_incoming_call_with_id.has_value())
on_incoming_call_with_id.value()(static_cast<std::string>(*m_calls.back()));
}

void make_call(const std::string& uri) {
m_calls.emplace_back(std::make_unique<call_t>(*this, [this](int id){ delete_call(id); } ));
void make_call(const std::string &uri) {
m_calls.emplace_back(std::make_unique<call_t>(*this, [this](int id) { delete_call(id); }));
m_calls.back()->on_call_state_with_index = on_call_state_with_index;
m_calls.back()->on_call_state_with_id = on_call_state_with_id;
pj::CallOpParam prm{true};
prm.opt.videoCount = 0;
m_calls.back()->makeCall(uri, prm);
}

template<typename ID>
auto call_for(ID id) {
return std::find_if(std::begin(m_calls), std::end(m_calls), [&id](const auto& element) {
std::vector<std::unique_ptr<call_t>>::iterator call_iterator(phone::CallID auto id) {
return std::find_if(std::begin(m_calls), std::end(m_calls), [&id](const auto &element) {
return static_cast<decltype(id)>(*element) == id;
});
}

template<typename ID>
void answer_call(ID id) {
typename std::vector<std::unique_ptr<call_t>>::iterator it = call_for(id); //NOLINT(modernize-use-auto)
call_t *find_call(phone::CallID auto id) {
auto it = call_iterator(id);
if (it != std::end(m_calls)) {
pj::CallOpParam prm;
prm.statusCode = PJSIP_SC_OK;
(*it)->answer(prm);
return it->get();
}
}

template<typename ID>
void start_ringing_call(ID id) {
typename std::vector<std::unique_ptr<call_t>>::iterator it = call_for(id); //NOLINT(modernize-use-auto)
if (it != std::end(m_calls)) {
pj::CallOpParam prm;
prm.statusCode = PJSIP_SC_RINGING;
(*it)->answer(prm);
if constexpr (std::is_same_v<decltype(id), int>) {
throw std::invalid_argument{"no call for index: <" + std::to_string(id) + ">"};
} else {
throw std::invalid_argument{"no call for id: <" + id + ">"};
}
}

template<typename ID>
void hangup_call(ID id) {
typename std::vector<std::unique_ptr<call_t>>::iterator it = call_for(id); //NOLINT(modernize-use-auto)
if (it != std::end(m_calls)) {
pj::CallOpParam prm;
prm.statusCode = PJSIP_SC_DECLINE;
(*it)->hangup(prm);
}
void answer_call(phone::CallID auto id) {
call_t *call = find_call(id);
pj::CallOpParam prm;
prm.statusCode = PJSIP_SC_OK;
call->answer(prm);
}

std::string get_call_id(int call_index) {
typename std::vector<std::unique_ptr<call_t>>::iterator it = call_for(call_index); //NOLINT(modernize-use-auto)
if (it != std::end(m_calls)) {
return static_cast<std::string>(*it->get()); //NOLINT(readability-redundant-smartptr-get)
}
throw std::invalid_argument{"no call for index: <" + std::to_string(call_index) + ">"};
void start_ringing_call(phone::CallID auto id) {
call_t *call = find_call(id);
pj::CallOpParam prm;
prm.statusCode = PJSIP_SC_RINGING;
call->answer(prm);
}

int get_call_index(const std::string& call_id) {
typename std::vector<std::unique_ptr<call_t>>::iterator it = call_for(call_id); //NOLINT(modernize-use-auto)
if (it != std::end(m_calls)) {
return static_cast<int>(*it->get()); //NOLINT(readability-redundant-smartptr-get)
}
throw std::invalid_argument{"no call for id: <" + call_id + ">"};
void hangup_call(phone::CallID auto id) {
call_t *call = find_call(id);
pj::CallOpParam prm;
prm.statusCode = PJSIP_SC_DECLINE;
call->hangup(prm);
}

std::optional<std::string> call_incoming_message(int call_index) {
typename std::vector<std::unique_ptr<call_t>>::iterator it = call_for(call_index); //NOLINT(modernize-use-auto)
if (it != std::end(m_calls)) {
return (*it)->incoming_message;
}
throw std::invalid_argument{"no call for index: <" + std::to_string(call_index) + ">"};
std::optional<std::string> call_incoming_message(phone::CallID auto id) {
call_t *call = find_call(id);
return call->incoming_message;
}

std::optional<std::string> call_incoming_message(const std::string& call_id) {
typename std::vector<std::unique_ptr<call_t>>::iterator it = call_for(call_id); //NOLINT(modernize-use-auto)
if (it != std::end(m_calls)) {
return (*it)->incoming_message;
}
throw std::invalid_argument{"no call for id: <" + call_id + ">"};
std::optional<int> call_answer_after(phone::CallID auto id) {
call_t *call = find_call(id);
return call->answer_after;
}

std::optional<int> call_answer_after(int call_index) {
typename std::vector<std::unique_ptr<call_t>>::iterator it = call_for(call_index); //NOLINT(modernize-use-auto)
if (it != std::end(m_calls)) {
return (*it)->answer_after;
}
throw std::invalid_argument{"no call for index: <" + std::to_string(call_index) + ">"};
std::string get_call_id(int call_index) {
return static_cast<std::string>(*find_call(call_index));
}

std::optional<int> call_answer_after(const std::string& call_id) {
typename std::vector<std::unique_ptr<call_t>>::iterator it = call_for(call_id); //NOLINT(modernize-use-auto)
if (it != std::end(m_calls)) {
return (*it)->answer_after;
}
throw std::invalid_argument{"no call for id: <" + call_id + ">"};
int get_call_index(const std::string &call_id) {
return static_cast<int>(*find_call(call_id));
}

void delete_call(int call_index) {
PJ_LOG(3,(__BASE_FILE__, "Going to delete call: %d", call_index));
auto it = call_for(call_index);
void delete_call(int call_index) noexcept {
PJ_LOG(3, (__BASE_FILE__, "Going to delete call: %d", call_index));
auto it = call_iterator(call_index);
if (it != std::end(m_calls)) { m_calls.erase(it); }
}

Expand All @@ -175,6 +156,6 @@ class account_t : public pj::Account {

private:
std::vector<std::unique_ptr<call_t>> m_calls{};
} ;
};

#endif //ACCOUNT_T_H
2 changes: 1 addition & 1 deletion src/python_cli/python_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
nameservers = ["217.237.148.22", "217.237.150.51"]
stunservers = ["stun.t-online.de"]
sipserver = "tel.t-online.de"
username = "+4965191899543"
username = "+49..."
password = None
opus_channel_count = 1
opus_complexity = 8
Expand Down

0 comments on commit 199e923

Please sign in to comment.