Supports WebRTC branch head 60
parent
137fe1cfbc
commit
ea11b4baa2
|
@ -4,12 +4,7 @@
|
||||||
#
|
#
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
if (APPLE)
|
cmake_minimum_required(VERSION 3.2)
|
||||||
cmake_minimum_required(VERSION 3.2)
|
|
||||||
else (APPLE)
|
|
||||||
cmake_minimum_required(VERSION 2.8)
|
|
||||||
endif (APPLE)
|
|
||||||
|
|
||||||
project(peerconnect)
|
project(peerconnect)
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,14 +144,14 @@ if (PC_WITH_STATIC)
|
||||||
if (_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
|
if (_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
|
||||||
add_custom_command(TARGET peerconnect PRE_LINK
|
add_custom_command(TARGET peerconnect PRE_LINK
|
||||||
COMMAND ${CMAKE_COMMAND} -E env \"PATH=${DEPOT_TOOLS_DIR}:$ENV{PATH}\" gn gen ${WEBRTC_OUT_DIR_DEBUG} --args=\"is_debug=true is_component_build=false\"
|
COMMAND ${CMAKE_COMMAND} -E env \"PATH=${DEPOT_TOOLS_DIR}:$ENV{PATH}\" gn gen ${WEBRTC_OUT_DIR_DEBUG} --args=\"is_debug=true is_component_build=false\"
|
||||||
COMMAND ${CMAKE_COMMAND} -E env \"PATH=${DEPOT_TOOLS_DIR}:$ENV{PATH}\" ninja -C ${WEBRTC_OUT_DIR_DEBUG} peerconnection_unittests
|
COMMAND ${CMAKE_COMMAND} -E env \"PATH=${DEPOT_TOOLS_DIR}:$ENV{PATH}\" ninja -C ${WEBRTC_OUT_DIR_DEBUG}
|
||||||
WORKING_DIRECTORY "${WEBRTC_ROOT_DIR}"
|
WORKING_DIRECTORY "${WEBRTC_ROOT_DIR}"
|
||||||
COMMENT "Building WebRTC library (Once)"
|
COMMENT "Building WebRTC library (Once)"
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
add_custom_command(TARGET peerconnect PRE_LINK
|
add_custom_command(TARGET peerconnect PRE_LINK
|
||||||
COMMAND ${CMAKE_COMMAND} -E env \"PATH=${DEPOT_TOOLS_DIR}:$ENV{PATH}\" gn gen ${WEBRTC_OUT_DIR} --args=\"is_debug=false is_component_build=false\"
|
COMMAND ${CMAKE_COMMAND} -E env \"PATH=${DEPOT_TOOLS_DIR}:$ENV{PATH}\" gn gen ${WEBRTC_OUT_DIR} --args=\"is_debug=false is_component_build=false\"
|
||||||
COMMAND ${CMAKE_COMMAND} -E env \"PATH=${DEPOT_TOOLS_DIR}:$ENV{PATH}\" ninja -C ${WEBRTC_OUT_DIR} peerconnection_unittests
|
COMMAND ${CMAKE_COMMAND} -E env \"PATH=${DEPOT_TOOLS_DIR}:$ENV{PATH}\" ninja -C ${WEBRTC_OUT_DIR}
|
||||||
WORKING_DIRECTORY "${WEBRTC_ROOT_DIR}"
|
WORKING_DIRECTORY "${WEBRTC_ROOT_DIR}"
|
||||||
COMMENT "Building WebRTC library (Once)"
|
COMMENT "Building WebRTC library (Once)"
|
||||||
)
|
)
|
||||||
|
@ -251,7 +246,6 @@ if (PC_WITH_SHARED)
|
||||||
CACHE STRING "PeerConnect shared library")
|
CACHE STRING "PeerConnect shared library")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Test
|
# Test
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
@ -259,7 +253,6 @@ endif()
|
||||||
if (PC_BUILD_TEST)
|
if (PC_BUILD_TEST)
|
||||||
add_executable(test_main src/test/test_main.cc)
|
add_executable(test_main src/test/test_main.cc)
|
||||||
add_dependencies(test_main peerconnect)
|
add_dependencies(test_main peerconnect)
|
||||||
|
|
||||||
target_include_directories(test_main PRIVATE ${PEERCONNECT_INCLUDE_DIR})
|
target_include_directories(test_main PRIVATE ${PEERCONNECT_INCLUDE_DIR})
|
||||||
target_link_libraries(test_main ${PEERCONNECT_LIBRARIES_STATIC})
|
target_link_libraries(test_main ${PEERCONNECT_LIBRARIES_STATIC})
|
||||||
set_target_properties (test_main PROPERTIES FOLDER test)
|
set_target_properties (test_main PROPERTIES FOLDER test)
|
||||||
|
|
|
@ -63,10 +63,10 @@ In the [WebRTC development](https://webrtc.org/native-code/development/) instruc
|
||||||
* Follow 'Before You Start' step
|
* Follow 'Before You Start' step
|
||||||
* Follow 'Getting the code' step
|
* Follow 'Getting the code' step
|
||||||
|
|
||||||
Currently PeerConnect supports WebRTC branch-heads/55 so run
|
Currently PeerConnect supports WebRTC branch-heads/60 so run
|
||||||
|
|
||||||
```
|
```
|
||||||
$ git checkout -b peers55 refs/remotes/branch-heads/55
|
$ git checkout -b peers60 refs/remotes/branch-heads/60
|
||||||
```
|
```
|
||||||
|
|
||||||
To update build toolchain and dependencies of WebRTC, run:
|
To update build toolchain and dependencies of WebRTC, run:
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -39,7 +39,7 @@ macro (MERGE_STATIC_LIBRARIES TARGET_LIB LIBRARIES LIBRARIES_DEBUG OBJECTS OBJEC
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(outfile $<TARGET_FILE:${TARGET_LIB}>)
|
set(outfile $<TARGET_FILE:${TARGET_LIB}>)
|
||||||
set(target_temp_file "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${TARGET_LIB}_temp.a")
|
set(target_temp_file "${CMAKE_CURRENT_BINARY_DIR}/lib${TARGET_LIB}_temp.a")
|
||||||
|
|
||||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" _CMAKE_BUILD_TYPE)
|
string(TOUPPER "${CMAKE_BUILD_TYPE}" _CMAKE_BUILD_TYPE)
|
||||||
if (_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
|
if (_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
|
||||||
|
@ -74,8 +74,8 @@ macro (MERGE_STATIC_LIBRARIES TARGET_LIB LIBRARIES LIBRARIES_DEBUG OBJECTS OBJEC
|
||||||
set(_OBJECTS ${OBJECTS})
|
set(_OBJECTS ${OBJECTS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
get_target_property (outfile ${TARGET_LIB} LOCATION)
|
set(outfile "libpeerconnect.a")
|
||||||
set(target_temp_file "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${TARGET_LIB}_temp.a")
|
set(target_temp_file "${CMAKE_CURRENT_BINARY_DIR}/lib${TARGET_LIB}_temp.a")
|
||||||
|
|
||||||
set(MRI_SCRIPT "create ${outfile}\n")
|
set(MRI_SCRIPT "create ${outfile}\n")
|
||||||
foreach(lib ${_LIBRARIES})
|
foreach(lib ${_LIBRARIES})
|
||||||
|
@ -89,13 +89,13 @@ macro (MERGE_STATIC_LIBRARIES TARGET_LIB LIBRARIES LIBRARIES_DEBUG OBJECTS OBJEC
|
||||||
set(MRI_SCRIPT "${MRI_SCRIPT}save\n")
|
set(MRI_SCRIPT "${MRI_SCRIPT}save\n")
|
||||||
set(MRI_SCRIPT "${MRI_SCRIPT}end\n")
|
set(MRI_SCRIPT "${MRI_SCRIPT}end\n")
|
||||||
|
|
||||||
file(WRITE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/peerconnect.mri" "${MRI_SCRIPT}")
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/peerconnect.mri" "${MRI_SCRIPT}")
|
||||||
|
|
||||||
add_custom_command(TARGET ${TARGET_LIB} POST_BUILD
|
add_custom_command(TARGET ${TARGET_LIB} POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy "${outfile}"
|
COMMAND ${CMAKE_COMMAND} -E copy "${outfile}"
|
||||||
"${target_temp_file}"
|
"${target_temp_file}"
|
||||||
COMMAND rm "${outfile}"
|
COMMAND rm "${outfile}"
|
||||||
COMMAND ${CMAKE_AR} -M < "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/peerconnect.mri"
|
COMMAND ${CMAKE_AR} -M < "${CMAKE_CURRENT_BINARY_DIR}/peerconnect.mri"
|
||||||
COMMAND rm "${target_temp_file}"
|
COMMAND rm "${target_temp_file}"
|
||||||
)
|
)
|
||||||
endif (WIN32)
|
endif (WIN32)
|
||||||
|
|
322
src/control.cc
322
src/control.cc
|
@ -38,18 +38,18 @@ Control::Control(std::shared_ptr<Signal> signal)
|
||||||
|
|
||||||
signal_->SignalOnCommandReceived_.connect(this, &Control::OnSignalCommandReceived);
|
signal_->SignalOnCommandReceived_.connect(this, &Control::OnSignalCommandReceived);
|
||||||
signal_->SignalOnClosed_.connect(this, &Control::OnSignalConnectionClosed);
|
signal_->SignalOnClosed_.connect(this, &Control::OnSignalConnectionClosed);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
Control::~Control() {
|
Control::~Control() {
|
||||||
LOGP_F( INFO ) << "Starting";
|
LOG_F( INFO ) << "Starting";
|
||||||
|
|
||||||
peers_.clear();
|
peers_.clear();
|
||||||
DeleteControl();
|
DeleteControl();
|
||||||
signal_->SignalOnCommandReceived_.disconnect(this);
|
signal_->SignalOnCommandReceived_.disconnect(this);
|
||||||
signal_->SignalOnClosed_.disconnect(this);
|
signal_->SignalOnClosed_.disconnect(this);
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,29 +59,29 @@ Control::~Control() {
|
||||||
|
|
||||||
bool Control::InitializeControl() {
|
bool Control::InitializeControl() {
|
||||||
|
|
||||||
ASSERT(peer_connection_factory_.get() == NULL);
|
RTC_DCHECK(peer_connection_factory_.get() == NULL);
|
||||||
|
|
||||||
webrtc::MediaConstraintsInterface* constraints = NULL;
|
webrtc::MediaConstraintsInterface* constraints = NULL;
|
||||||
|
|
||||||
if ( !CreatePeerFactory(constraints) ) {
|
if ( !CreatePeerFactory(constraints) ) {
|
||||||
LOGP_F(LERROR) << "CreatePeerFactory failed";
|
LOG_F(LERROR) << "CreatePeerFactory failed";
|
||||||
DeleteControl();
|
DeleteControl();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
webrtc_thread_ = rtc::Thread::Current();
|
webrtc_thread_ = rtc::Thread::Current();
|
||||||
ASSERT( webrtc_thread_ != nullptr );
|
RTC_DCHECK( webrtc_thread_ != nullptr );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::DeleteControl() {
|
void Control::DeleteControl() {
|
||||||
LOGP_F( INFO ) << "Starting";
|
LOG_F( INFO ) << "Starting";
|
||||||
|
|
||||||
peer_connection_factory_ = NULL;
|
peer_connection_factory_ = NULL;
|
||||||
fake_audio_capture_module_ = NULL;
|
fake_audio_capture_module_ = NULL;
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ void Control::Open(const string& user_id, const string& user_password, const str
|
||||||
// 4. Generate 'open' event to PeerConnect
|
// 4. Generate 'open' event to PeerConnect
|
||||||
|
|
||||||
if (signal_.get() == NULL) {
|
if (signal_.get() == NULL) {
|
||||||
LOGP_F( LERROR ) << "Open failed, no signal server";
|
LOG_F( LERROR ) << "Open failed, no signal server";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ void Control::Open(const string& user_id, const string& user_password, const str
|
||||||
// Connect to signal server
|
// Connect to signal server
|
||||||
signal_->Open(user_id, user_password);
|
signal_->Open(user_id, user_password);
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,18 +117,18 @@ void Control::Connect(const string peer) {
|
||||||
// 4. Connect datachannel
|
// 4. Connect datachannel
|
||||||
|
|
||||||
if (signal_.get() == NULL) {
|
if (signal_.get() == NULL) {
|
||||||
LOGP_F(LERROR) << "Join failed, no signal server";
|
LOG_F(LERROR) << "Join failed, no signal server";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Joining channel " << peer;
|
LOG_F( INFO ) << "Joining channel " << peer;
|
||||||
JoinChannel(peer);
|
JoinChannel(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::Close(const CloseCode code, bool force_queuing) {
|
void Control::Close(const CloseCode code, bool force_queuing) {
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Call";
|
LOG_F( INFO ) << "Call";
|
||||||
|
|
||||||
//
|
//
|
||||||
// Verify current thread
|
// Verify current thread
|
||||||
//
|
//
|
||||||
|
@ -136,7 +136,7 @@ void Control::Close(const CloseCode code, bool force_queuing) {
|
||||||
if (force_queuing || webrtc_thread_ != rtc::Thread::Current()) {
|
if (force_queuing || webrtc_thread_ != rtc::Thread::Current()) {
|
||||||
ControlMessageData *data = new ControlMessageData(code, ref_);
|
ControlMessageData *data = new ControlMessageData(code, ref_);
|
||||||
webrtc_thread_->Post(RTC_FROM_HERE, this, MSG_CLOSE, data);
|
webrtc_thread_->Post(RTC_FROM_HERE, this, MSG_CLOSE, data);
|
||||||
LOGP_F( INFO ) << "Queued";
|
LOG_F( INFO ) << "Queued";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,10 +150,10 @@ void Control::Close(const CloseCode code, bool force_queuing) {
|
||||||
peer_ids.push_back(peer.second->remote_id());
|
peer_ids.push_back(peer.second->remote_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F(INFO) << "Close(): peer count is " << peer_ids.size();
|
LOG_F(INFO) << "Close(): peer count is " << peer_ids.size();
|
||||||
|
|
||||||
for (auto id : peer_ids) {
|
for (auto id : peer_ids) {
|
||||||
LOGP_F( INFO ) << "Try to close peer having id " << id;
|
LOG_F( INFO ) << "Try to close peer having id " << id;
|
||||||
ClosePeer(id, code);
|
ClosePeer(id, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ void Control::Close(const CloseCode code, bool force_queuing) {
|
||||||
pc_->OnClose( peer_name_ ,code );
|
pc_->OnClose( peer_name_ ,code );
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::ClosePeer( const string peer, const CloseCode code, bool force_queuing ) {
|
void Control::ClosePeer( const string peer, const CloseCode code, bool force_queuing ) {
|
||||||
|
@ -188,7 +188,7 @@ void Control::ClosePeer( const string peer, const CloseCode code, bool force_que
|
||||||
|
|
||||||
auto peer_found = peers_.find(peer);
|
auto peer_found = peers_.find(peer);
|
||||||
if ( peer_found == peers_.end() ) {
|
if ( peer_found == peers_.end() ) {
|
||||||
LOGP_F( WARNING ) << "peer not found, " << peer;
|
LOG_F( WARNING ) << "peer not found, " << peer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ void Control::ClosePeer( const string peer, const CloseCode code, bool force_que
|
||||||
// 3. Leave channel on signal server
|
// 3. Leave channel on signal server
|
||||||
LeaveChannel(peer);
|
LeaveChannel(peer);
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done, peer is " << peer;
|
LOG_F( INFO ) << "Done, peer is " << peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -239,12 +239,12 @@ void Control::SendCommand(const string& peer, const string& command, const Json:
|
||||||
|
|
||||||
void Control::OnPeerConnect(const string peer) {
|
void Control::OnPeerConnect(const string peer) {
|
||||||
if ( pc_ == nullptr ) {
|
if ( pc_ == nullptr ) {
|
||||||
LOGP_F( WARNING ) << "pc_ is null, peer is " << peer;
|
LOG_F( WARNING ) << "pc_ is null, peer is " << peer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pc_->OnConnect(peer);
|
pc_->OnConnect(peer);
|
||||||
LOGP_F( INFO ) << "Done, peer is " << peer;
|
LOG_F( INFO ) << "Done, peer is " << peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::OnPeerClose(const string peer, CloseCode code) {
|
void Control::OnPeerClose(const string peer, CloseCode code) {
|
||||||
|
@ -254,20 +254,20 @@ void Control::OnPeerClose(const string peer, CloseCode code) {
|
||||||
|
|
||||||
// Call Control::OnPeerDisconnected()
|
// Call Control::OnPeerDisconnected()
|
||||||
webrtc_thread_->Post(RTC_FROM_HERE, this, MSG_ON_PEER_CLOSE, data);
|
webrtc_thread_->Post(RTC_FROM_HERE, this, MSG_ON_PEER_CLOSE, data);
|
||||||
LOGP_F( INFO ) << "Queued, peer is " << peer;
|
LOG_F( INFO ) << "Queued, peer is " << peer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Enter, peer is " << peer;
|
LOG_F( INFO ) << "Enter, peer is " << peer;
|
||||||
|
|
||||||
if ( pc_ == nullptr ) {
|
if ( pc_ == nullptr ) {
|
||||||
LOGP_F( WARNING ) << "pc_ is null, peer is " << peer;
|
LOG_F( WARNING ) << "pc_ is null, peer is " << peer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pc_->OnClose( peer, code );
|
pc_->OnClose( peer, code );
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done, peer is " << peer;
|
LOG_F( INFO ) << "Done, peer is " << peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -276,7 +276,7 @@ void Control::OnPeerClose(const string peer, CloseCode code) {
|
||||||
|
|
||||||
void Control::OnPeerMessage(const string& peer, const char* data, const size_t size) {
|
void Control::OnPeerMessage(const string& peer, const char* data, const size_t size) {
|
||||||
if ( pc_ == nullptr ) {
|
if ( pc_ == nullptr ) {
|
||||||
LOGP_F( WARNING ) << "pc_ is null, peer is " << peer;
|
LOG_F( WARNING ) << "pc_ is null, peer is " << peer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pc_->OnMessage(peer, data, size);
|
pc_->OnMessage(peer, data, size);
|
||||||
|
@ -284,7 +284,7 @@ void Control::OnPeerMessage(const string& peer, const char* data, const size_t s
|
||||||
|
|
||||||
void Control::OnPeerWritable(const string& peer) {
|
void Control::OnPeerWritable(const string& peer) {
|
||||||
if ( pc_ == nullptr ) {
|
if ( pc_ == nullptr ) {
|
||||||
LOGP_F( WARNING ) << "pc_ is null, peer is " << peer;
|
LOG_F( WARNING ) << "pc_ is null, peer is " << peer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pc_->OnWritable(peer);
|
pc_->OnWritable(peer);
|
||||||
|
@ -294,14 +294,14 @@ void Control::RegisterObserver(ControlObserver* observer, std::shared_ptr<Contro
|
||||||
ref_ = ref;
|
ref_ = ref;
|
||||||
pc_ = observer;
|
pc_ = observer;
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Registered";
|
LOG_F( INFO ) << "Registered";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::UnregisterObserver() {
|
void Control::UnregisterObserver() {
|
||||||
pc_ = nullptr;
|
pc_ = nullptr;
|
||||||
ref_.reset();
|
ref_.reset();
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Unregistered";
|
LOG_F( INFO ) << "Unregistered";
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -309,11 +309,11 @@ void Control::UnregisterObserver() {
|
||||||
//
|
//
|
||||||
|
|
||||||
void Control::OnMessage(rtc::Message* msg) {
|
void Control::OnMessage(rtc::Message* msg) {
|
||||||
ControlMessageData* param = nullptr;
|
ControlMessageData* param = nullptr;
|
||||||
switch (msg->message_id) {
|
switch (msg->message_id) {
|
||||||
case MSG_COMMAND_RECEIVED:
|
case MSG_COMMAND_RECEIVED:
|
||||||
param = static_cast<ControlMessageData*>(msg->pdata);
|
param = static_cast<ControlMessageData*>(msg->pdata);
|
||||||
OnCommandReceived(param->data_json_);
|
OnCommandReceived(param->data_json_);
|
||||||
break;
|
break;
|
||||||
case MSG_CLOSE:
|
case MSG_CLOSE:
|
||||||
param = static_cast<ControlMessageData*>(msg->pdata);
|
param = static_cast<ControlMessageData*>(msg->pdata);
|
||||||
|
@ -332,7 +332,7 @@ void Control::OnMessage(rtc::Message* msg) {
|
||||||
Close((CloseCode)param->data_int32_);
|
Close((CloseCode)param->data_int32_);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOGP_F( WARNING ) << "Unknown message";
|
LOG_F( WARNING ) << "Unknown message";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ void Control::OnCommandReceived(const Json::Value& message) {
|
||||||
if (!rtc::GetStringFromJsonObject(message, "command", &command) ||
|
if (!rtc::GetStringFromJsonObject(message, "command", &command) ||
|
||||||
!rtc::GetValueFromJsonObject(message, "data", &data)) {
|
!rtc::GetValueFromJsonObject(message, "data", &data)) {
|
||||||
|
|
||||||
LOGP_F(LERROR) << "Invalid message:" << message;
|
LOG_F(LERROR) << "Invalid message:" << message;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,16 +393,16 @@ void Control::OnCommandReceived(const Json::Value& message) {
|
||||||
void Control::OnSignalCommandReceived(const Json::Value& message) {
|
void Control::OnSignalCommandReceived(const Json::Value& message) {
|
||||||
ControlMessageData *data = new ControlMessageData(message, ref_);
|
ControlMessageData *data = new ControlMessageData(message, ref_);
|
||||||
webrtc_thread_->Post(RTC_FROM_HERE, this, MSG_COMMAND_RECEIVED, data);
|
webrtc_thread_->Post(RTC_FROM_HERE, this, MSG_COMMAND_RECEIVED, data);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::OnSignalConnectionClosed(websocketpp::close::status::value code) {
|
void Control::OnSignalConnectionClosed(websocketpp::close::status::value code) {
|
||||||
LOGP_F(INFO) << "Enter, code is " << code;
|
LOG_F(INFO) << "Enter, code is " << code;
|
||||||
if (code != websocketpp::close::status::normal) {
|
if (code != websocketpp::close::status::normal) {
|
||||||
ControlMessageData *data = new ControlMessageData(CLOSE_SIGNAL_ERROR, ref_);
|
ControlMessageData *data = new ControlMessageData(CLOSE_SIGNAL_ERROR, ref_);
|
||||||
webrtc_thread_->Post(RTC_FROM_HERE, this, MSG_ON_SIGLAL_CONNECTION_CLOSE, data);
|
webrtc_thread_->Post(RTC_FROM_HERE, this, MSG_ON_SIGLAL_CONNECTION_CLOSE, data);
|
||||||
}
|
}
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -410,26 +410,26 @@ void Control::OnSignalConnectionClosed(websocketpp::close::status::value code) {
|
||||||
//
|
//
|
||||||
|
|
||||||
void Control::CreateChannel(const string name) {
|
void Control::CreateChannel(const string name) {
|
||||||
LOGP_F( INFO ) << "channel is " << name;
|
LOG_F( INFO ) << "channel is " << name;
|
||||||
|
|
||||||
Json::Value data;
|
Json::Value data;
|
||||||
data["name"] = name;
|
data["name"] = name;
|
||||||
SendCommand(name, "createchannel", data);
|
SendCommand(name, "createchannel", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::JoinChannel(const string name) {
|
void Control::JoinChannel(const string name) {
|
||||||
LOGP_F( INFO ) << "channel is " << name;
|
LOG_F( INFO ) << "channel is " << name;
|
||||||
|
|
||||||
Json::Value data;
|
Json::Value data;
|
||||||
data["name"] = name;
|
data["name"] = name;
|
||||||
SendCommand(name, "joinchannel", data);
|
SendCommand(name, "joinchannel", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::LeaveChannel(const string name) {
|
void Control::LeaveChannel(const string name) {
|
||||||
LOGP_F( INFO ) << "channel is " << name;
|
LOG_F( INFO ) << "channel is " << name;
|
||||||
|
|
||||||
Json::Value data;
|
Json::Value data;
|
||||||
data["name"] = name;
|
data["name"] = name;
|
||||||
SendCommand(name, "leavechannel", data);
|
SendCommand(name, "leavechannel", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ bool Control::CreatePeerFactory(
|
||||||
|
|
||||||
fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
|
fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
|
||||||
if (fake_audio_capture_module_ == NULL) {
|
if (fake_audio_capture_module_ == NULL) {
|
||||||
LOGP_F( LERROR ) << "Failed to create FakeAudioCaptureModule";
|
LOG_F( LERROR ) << "Failed to create FakeAudioCaptureModule";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,11 +452,11 @@ bool Control::CreatePeerFactory(
|
||||||
fake_audio_capture_module_, NULL, NULL);
|
fake_audio_capture_module_, NULL, NULL);
|
||||||
|
|
||||||
if (!peer_connection_factory_.get()) {
|
if (!peer_connection_factory_.get()) {
|
||||||
LOGP_F( LERROR ) << "Failed to create CreatePeerConnectionFactory";
|
LOG_F( LERROR ) << "Failed to create CreatePeerConnectionFactory";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,28 +472,28 @@ void Control::AddIceCandidate(const string& peer_id, const Json::Value& data) {
|
||||||
string candidate;
|
string candidate;
|
||||||
|
|
||||||
if ( !rtc::GetStringFromJsonObject( data, "sdp_mid", &sdp_mid ) ) {
|
if ( !rtc::GetStringFromJsonObject( data, "sdp_mid", &sdp_mid ) ) {
|
||||||
LOGP_F( LERROR ) << "sdp_mid not found, " << data.toStyledString();
|
LOG_F( LERROR ) << "sdp_mid not found, " << data.toStyledString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !rtc::GetIntFromJsonObject( data, "sdp_mline_index", &sdp_mline_index ) ) {
|
if ( !rtc::GetIntFromJsonObject( data, "sdp_mline_index", &sdp_mline_index ) ) {
|
||||||
LOGP_F( LERROR ) << "sdp_mline_index not found, " << data.toStyledString();
|
LOG_F( LERROR ) << "sdp_mline_index not found, " << data.toStyledString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !rtc::GetStringFromJsonObject( data, "candidate", &candidate ) ) {
|
if ( !rtc::GetStringFromJsonObject( data, "candidate", &candidate ) ) {
|
||||||
LOGP_F( LERROR ) << "candidate not found, " << data.toStyledString();
|
LOG_F( LERROR ) << "candidate not found, " << data.toStyledString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( peers_.find( peer_id ) == peers_.end() ) {
|
if ( peers_.find( peer_id ) == peers_.end() ) {
|
||||||
LOGP_F( WARNING ) << "peer_id not found, peer_id is " << peer_id << " and " <<
|
LOG_F( WARNING ) << "peer_id not found, peer_id is " << peer_id << " and " <<
|
||||||
"data is " << data.toStyledString();
|
"data is " << data.toStyledString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
peers_[peer_id]->AddIceCandidate(sdp_mid, sdp_mline_index, candidate);
|
peers_[peer_id]->AddIceCandidate(sdp_mid, sdp_mline_index, candidate);
|
||||||
LOGP_F( INFO ) << "Done, peer_id is " << peer_id;
|
LOG_F( INFO ) << "Done, peer_id is " << peer_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -503,94 +503,94 @@ void Control::AddIceCandidate(const string& peer_id, const Json::Value& data) {
|
||||||
//
|
//
|
||||||
|
|
||||||
void Control::OnOpen(const Json::Value& data) {
|
void Control::OnOpen(const Json::Value& data) {
|
||||||
bool result;
|
bool result;
|
||||||
if (!rtc::GetBoolFromJsonObject(data, "result", &result)) {
|
if (!rtc::GetBoolFromJsonObject(data, "result", &result)) {
|
||||||
LOGP_F(WARNING) << "Unknown open response";
|
LOG_F(WARNING) << "Unknown open response";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
LOGP_F(LERROR) << "Open failed";
|
LOG_F(LERROR) << "Open failed";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string session_id;
|
string session_id;
|
||||||
if (!rtc::GetStringFromJsonObject(data, "session_id", &session_id)) {
|
if (!rtc::GetStringFromJsonObject(data, "session_id", &session_id)) {
|
||||||
LOGP_F(LERROR) << "Open failed - no session_id";
|
LOG_F(LERROR) << "Open failed - no session_id";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
session_id_ = session_id;
|
session_id_ = session_id;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create channel
|
// Create channel
|
||||||
//
|
//
|
||||||
|
|
||||||
CreateChannel(peer_name_);
|
CreateChannel(peer_name_);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Control::OnChannelCreate(const Json::Value& data) {
|
void Control::OnChannelCreate(const Json::Value& data) {
|
||||||
bool result;
|
bool result;
|
||||||
if (!rtc::GetBoolFromJsonObject(data, "result", &result)) {
|
if (!rtc::GetBoolFromJsonObject(data, "result", &result)) {
|
||||||
LOGP_F(WARNING) << "Unknown open response";
|
LOG_F(WARNING) << "Unknown open response";
|
||||||
pc_->OnClose(peer_name_, CLOSE_SIGNAL_ERROR);
|
pc_->OnClose(peer_name_, CLOSE_SIGNAL_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string peer;
|
string peer;
|
||||||
if (!rtc::GetStringFromJsonObject(data, "name", &peer)) {
|
if (!rtc::GetStringFromJsonObject(data, "name", &peer)) {
|
||||||
pc_->OnClose(peer_name_, CLOSE_SIGNAL_ERROR);
|
pc_->OnClose(peer_name_, CLOSE_SIGNAL_ERROR);
|
||||||
LOGP_F(LERROR) << "Create channel failed - no channel name";
|
LOG_F(LERROR) << "Create channel failed - no channel name";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
LOGP_F(LERROR) << "Create channel failed";
|
LOG_F(LERROR) << "Create channel failed";
|
||||||
string desc;
|
string desc;
|
||||||
if (!rtc::GetStringFromJsonObject(data, "desc", &desc)) {
|
if (!rtc::GetStringFromJsonObject(data, "desc", &desc)) {
|
||||||
desc = "Unknown reason";
|
desc = "Unknown reason";
|
||||||
}
|
}
|
||||||
|
|
||||||
pc_->OnClose(peer, CLOSE_SIGNAL_ERROR, desc);
|
pc_->OnClose(peer, CLOSE_SIGNAL_ERROR, desc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pc_->OnOpen(peer);
|
pc_->OnOpen(peer);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::OnChannelJoin(const Json::Value& data) {
|
void Control::OnChannelJoin(const Json::Value& data) {
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
LOGP_F(INFO) << "OnChannelJoined(" << data.toStyledString() << ")";
|
LOG_F(INFO) << "OnChannelJoined(" << data.toStyledString() << ")";
|
||||||
|
|
||||||
if (!rtc::GetBoolFromJsonObject(data, "result", &result)) {
|
if (!rtc::GetBoolFromJsonObject(data, "result", &result)) {
|
||||||
pc_->OnClose( "", CLOSE_SIGNAL_ERROR );
|
pc_->OnClose( "", CLOSE_SIGNAL_ERROR );
|
||||||
LOGP_F(LERROR) << "Unknown channel join response";
|
LOG_F(LERROR) << "Unknown channel join response";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string peer;
|
string peer;
|
||||||
if (!rtc::GetStringFromJsonObject(data, "name", &peer)) {
|
if (!rtc::GetStringFromJsonObject(data, "name", &peer)) {
|
||||||
pc_->OnClose( "", CLOSE_SIGNAL_ERROR );
|
pc_->OnClose( "", CLOSE_SIGNAL_ERROR );
|
||||||
LOGP_F(LERROR) << "Join channel failed - no channel name";
|
LOG_F(LERROR) << "Join channel failed - no channel name";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
LOGP_F(LERROR) << "Join channel failed";
|
LOG_F(LERROR) << "Join channel failed";
|
||||||
string desc;
|
string desc;
|
||||||
if (!rtc::GetStringFromJsonObject(data, "desc", &desc)) {
|
if (!rtc::GetStringFromJsonObject(data, "desc", &desc)) {
|
||||||
desc = "Unknown reason";
|
desc = "Unknown reason";
|
||||||
}
|
}
|
||||||
|
|
||||||
pc_->OnClose( peer, CLOSE_SIGNAL_ERROR, desc );
|
pc_->OnClose( peer, CLOSE_SIGNAL_ERROR, desc );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -604,7 +604,7 @@ void Control::OnChannelLeave(const Json::Value& data) {
|
||||||
|
|
||||||
|
|
||||||
void Control::OnRemotePeerClose(const string& peer_id, const Json::Value& data) {
|
void Control::OnRemotePeerClose(const string& peer_id, const Json::Value& data) {
|
||||||
ClosePeer( peer_id, CLOSE_NORMAL );
|
ClosePeer( peer_id, CLOSE_NORMAL );
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -612,32 +612,32 @@ void Control::OnRemotePeerClose(const string& peer_id, const Json::Value& data)
|
||||||
//
|
//
|
||||||
|
|
||||||
void Control::CreateOffer(const Json::Value& data) {
|
void Control::CreateOffer(const Json::Value& data) {
|
||||||
|
|
||||||
Json::Value peers;
|
Json::Value peers;
|
||||||
if (!rtc::GetValueFromJsonObject(data, "peers", &peers)) {
|
if (!rtc::GetValueFromJsonObject(data, "peers", &peers)) {
|
||||||
LOGP_F(LERROR) << "createoffer failed - no peers value";
|
LOG_F(LERROR) << "createoffer failed - no peers value";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < peers.size(); ++i) {
|
for (size_t i = 0; i < peers.size(); ++i) {
|
||||||
string remote_id;
|
string remote_id;
|
||||||
if (!rtc::GetStringFromJsonArray(peers, i, &remote_id)) {
|
if (!rtc::GetStringFromJsonArray(peers, i, &remote_id)) {
|
||||||
LOGP_F(LERROR) << "Peer handshake failed - invalid peer id";
|
LOG_F(LERROR) << "Peer handshake failed - invalid peer id";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Peer peer = new rtc::RefCountedObject<PeerControl>(peer_name_, remote_id, this, peer_connection_factory_);
|
Peer peer = new rtc::RefCountedObject<PeerControl>(peer_name_, remote_id, this, peer_connection_factory_);
|
||||||
if ( !peer->Initialize() ) {
|
if ( !peer->Initialize() ) {
|
||||||
LOGP_F( LERROR ) << "Peer initialization failed";
|
LOG_F( LERROR ) << "Peer initialization failed";
|
||||||
OnPeerClose( remote_id, CLOSE_ABNORMAL );
|
OnPeerClose( remote_id, CLOSE_ABNORMAL );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
peers_.insert(std::pair<string, Peer>(remote_id, peer));
|
peers_.insert(std::pair<string, Peer>(remote_id, peer));
|
||||||
peer->CreateOffer(NULL);
|
peer->CreateOffer(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -648,14 +648,14 @@ void Control::ReceiveOfferSdp(const string& peer_id, const Json::Value& data) {
|
||||||
string sdp;
|
string sdp;
|
||||||
|
|
||||||
if ( !rtc::GetStringFromJsonObject( data, "sdp", &sdp ) ) {
|
if ( !rtc::GetStringFromJsonObject( data, "sdp", &sdp ) ) {
|
||||||
LOGP_F( LERROR ) << "sdp not found, peer_id is " << peer_id << " and " <<
|
LOG_F( LERROR ) << "sdp not found, peer_id is " << peer_id << " and " <<
|
||||||
"data is " << data.toStyledString();
|
"data is " << data.toStyledString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Peer peer = new rtc::RefCountedObject<PeerControl>(peer_name_, peer_id, this, peer_connection_factory_);
|
Peer peer = new rtc::RefCountedObject<PeerControl>(peer_name_, peer_id, this, peer_connection_factory_);
|
||||||
if ( !peer->Initialize() ) {
|
if ( !peer->Initialize() ) {
|
||||||
LOGP_F( LERROR ) << "Peer initialization failed";
|
LOG_F( LERROR ) << "Peer initialization failed";
|
||||||
OnPeerClose( peer_id, CLOSE_ABNORMAL );
|
OnPeerClose( peer_id, CLOSE_ABNORMAL );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -663,7 +663,7 @@ void Control::ReceiveOfferSdp(const string& peer_id, const Json::Value& data) {
|
||||||
peers_.insert(std::pair<string, Peer>(peer_id, peer));
|
peers_.insert(std::pair<string, Peer>(peer_id, peer));
|
||||||
peer->ReceiveOfferSdp(sdp);
|
peer->ReceiveOfferSdp(sdp);
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -675,20 +675,20 @@ void Control::ReceiveAnswerSdp(const string& peer_id, const Json::Value& data) {
|
||||||
string sdp;
|
string sdp;
|
||||||
|
|
||||||
if ( !rtc::GetStringFromJsonObject( data, "sdp", &sdp ) ) {
|
if ( !rtc::GetStringFromJsonObject( data, "sdp", &sdp ) ) {
|
||||||
LOGP_F( LERROR ) << "sdp not found, peer_id is " << peer_id << " and " <<
|
LOG_F( LERROR ) << "sdp not found, peer_id is " << peer_id << " and " <<
|
||||||
"data is " << data.toStyledString();
|
"data is " << data.toStyledString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto peer = peers_.find(peer_id);
|
auto peer = peers_.find(peer_id);
|
||||||
if ( peer == peers_.end() ) {
|
if ( peer == peers_.end() ) {
|
||||||
LOGP_F( LERROR ) << "peer_id not found, peer_id is " << peer_id << " and " <<
|
LOG_F( LERROR ) << "peer_id not found, peer_id is " << peer_id << " and " <<
|
||||||
"data is " << data.toStyledString();
|
"data is " << data.toStyledString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
peer->second->ReceiveAnswerSdp(sdp);
|
peer->second->ReceiveAnswerSdp(sdp);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace pc
|
} // namespace pc
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "webrtc/api/test/fakeaudiocapturemodule.h"
|
#include "webrtc/pc/test/fakeaudiocapturemodule.h"
|
||||||
|
|
||||||
#include "webrtc/base/common.h"
|
#include "webrtc/base/checks.h"
|
||||||
#include "webrtc/base/refcount.h"
|
#include "webrtc/base/refcount.h"
|
||||||
#include "webrtc/base/thread.h"
|
#include "webrtc/base/thread.h"
|
||||||
#include "webrtc/base/timeutils.h"
|
#include "webrtc/base/timeutils.h"
|
||||||
|
@ -23,7 +23,7 @@ static const int kHighSampleValue = 10000;
|
||||||
|
|
||||||
// Same value as src/modules/audio_device/main/source/audio_device_config.h in
|
// Same value as src/modules/audio_device/main/source/audio_device_config.h in
|
||||||
// https://code.google.com/p/webrtc/
|
// https://code.google.com/p/webrtc/
|
||||||
static const uint32_t kAdmMaxIdleTimeProcess = 1000;
|
static const int kAdmMaxIdleTimeProcess = 1000;
|
||||||
|
|
||||||
// Constants here are derived by running VoE using a real ADM.
|
// Constants here are derived by running VoE using a real ADM.
|
||||||
// The constants correspond to 10ms of mono audio at 44kHz.
|
// The constants correspond to 10ms of mono audio at 44kHz.
|
||||||
|
@ -73,12 +73,12 @@ int FakeAudioCaptureModule::frames_received() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FakeAudioCaptureModule::TimeUntilNextProcess() {
|
int64_t FakeAudioCaptureModule::TimeUntilNextProcess() {
|
||||||
const uint32_t current_time = rtc::Time();
|
const int64_t current_time = rtc::TimeMillis();
|
||||||
if (current_time < last_process_time_ms_) {
|
if (current_time < last_process_time_ms_) {
|
||||||
// TODO: wraparound could be handled more gracefully.
|
// TODO: wraparound could be handled more gracefully.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const uint32_t elapsed_time = current_time - last_process_time_ms_;
|
const int64_t elapsed_time = current_time - last_process_time_ms_;
|
||||||
if (kAdmMaxIdleTimeProcess < elapsed_time) {
|
if (kAdmMaxIdleTimeProcess < elapsed_time) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -86,17 +86,17 @@ int64_t FakeAudioCaptureModule::TimeUntilNextProcess() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeAudioCaptureModule::Process() {
|
void FakeAudioCaptureModule::Process() {
|
||||||
last_process_time_ms_ = rtc::Time();
|
last_process_time_ms_ = rtc::TimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::ActiveAudioLayer(
|
int32_t FakeAudioCaptureModule::ActiveAudioLayer(
|
||||||
AudioLayer* /*audio_layer*/) const {
|
AudioLayer* /*audio_layer*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
webrtc::AudioDeviceModule::ErrorCode FakeAudioCaptureModule::LastError() const {
|
webrtc::AudioDeviceModule::ErrorCode FakeAudioCaptureModule::LastError() const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return webrtc::AudioDeviceModule::kAdmErrNone;
|
return webrtc::AudioDeviceModule::kAdmErrNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,17 +125,17 @@ int32_t FakeAudioCaptureModule::Terminate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeAudioCaptureModule::Initialized() const {
|
bool FakeAudioCaptureModule::Initialized() const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t FakeAudioCaptureModule::PlayoutDevices() {
|
int16_t FakeAudioCaptureModule::PlayoutDevices() {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t FakeAudioCaptureModule::RecordingDevices() {
|
int16_t FakeAudioCaptureModule::RecordingDevices() {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ int32_t FakeAudioCaptureModule::PlayoutDeviceName(
|
||||||
uint16_t /*index*/,
|
uint16_t /*index*/,
|
||||||
char /*name*/[webrtc::kAdmMaxDeviceNameSize],
|
char /*name*/[webrtc::kAdmMaxDeviceNameSize],
|
||||||
char /*guid*/[webrtc::kAdmMaxGuidSize]) {
|
char /*guid*/[webrtc::kAdmMaxGuidSize]) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ int32_t FakeAudioCaptureModule::RecordingDeviceName(
|
||||||
uint16_t /*index*/,
|
uint16_t /*index*/,
|
||||||
char /*name*/[webrtc::kAdmMaxDeviceNameSize],
|
char /*name*/[webrtc::kAdmMaxDeviceNameSize],
|
||||||
char /*guid*/[webrtc::kAdmMaxGuidSize]) {
|
char /*guid*/[webrtc::kAdmMaxGuidSize]) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ int32_t FakeAudioCaptureModule::SetRecordingDevice(
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::PlayoutIsAvailable(bool* /*available*/) {
|
int32_t FakeAudioCaptureModule::PlayoutIsAvailable(bool* /*available*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ bool FakeAudioCaptureModule::PlayoutIsInitialized() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::RecordingIsAvailable(bool* /*available*/) {
|
int32_t FakeAudioCaptureModule::RecordingIsAvailable(bool* /*available*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,8 +205,7 @@ int32_t FakeAudioCaptureModule::InitRecording() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeAudioCaptureModule::RecordingIsInitialized() const {
|
bool FakeAudioCaptureModule::RecordingIsInitialized() const {
|
||||||
ASSERT(false);
|
return rec_is_initialized_;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::StartPlayout() {
|
int32_t FakeAudioCaptureModule::StartPlayout() {
|
||||||
|
@ -273,20 +272,20 @@ int32_t FakeAudioCaptureModule::SetAGC(bool /*enable*/) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeAudioCaptureModule::AGC() const {
|
bool FakeAudioCaptureModule::AGC() const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SetWaveOutVolume(uint16_t /*volume_left*/,
|
int32_t FakeAudioCaptureModule::SetWaveOutVolume(uint16_t /*volume_left*/,
|
||||||
uint16_t /*volume_right*/) {
|
uint16_t /*volume_right*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::WaveOutVolume(
|
int32_t FakeAudioCaptureModule::WaveOutVolume(
|
||||||
uint16_t* /*volume_left*/,
|
uint16_t* /*volume_left*/,
|
||||||
uint16_t* /*volume_right*/) const {
|
uint16_t* /*volume_right*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +295,7 @@ int32_t FakeAudioCaptureModule::InitSpeaker() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeAudioCaptureModule::SpeakerIsInitialized() const {
|
bool FakeAudioCaptureModule::SpeakerIsInitialized() const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,46 +305,46 @@ int32_t FakeAudioCaptureModule::InitMicrophone() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeAudioCaptureModule::MicrophoneIsInitialized() const {
|
bool FakeAudioCaptureModule::MicrophoneIsInitialized() const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SpeakerVolumeIsAvailable(bool* /*available*/) {
|
int32_t FakeAudioCaptureModule::SpeakerVolumeIsAvailable(bool* /*available*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SetSpeakerVolume(uint32_t /*volume*/) {
|
int32_t FakeAudioCaptureModule::SetSpeakerVolume(uint32_t /*volume*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SpeakerVolume(uint32_t* /*volume*/) const {
|
int32_t FakeAudioCaptureModule::SpeakerVolume(uint32_t* /*volume*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::MaxSpeakerVolume(
|
int32_t FakeAudioCaptureModule::MaxSpeakerVolume(
|
||||||
uint32_t* /*max_volume*/) const {
|
uint32_t* /*max_volume*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::MinSpeakerVolume(
|
int32_t FakeAudioCaptureModule::MinSpeakerVolume(
|
||||||
uint32_t* /*min_volume*/) const {
|
uint32_t* /*min_volume*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SpeakerVolumeStepSize(
|
int32_t FakeAudioCaptureModule::SpeakerVolumeStepSize(
|
||||||
uint16_t* /*step_size*/) const {
|
uint16_t* /*step_size*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::MicrophoneVolumeIsAvailable(
|
int32_t FakeAudioCaptureModule::MicrophoneVolumeIsAvailable(
|
||||||
bool* /*available*/) {
|
bool* /*available*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,59 +368,59 @@ int32_t FakeAudioCaptureModule::MaxMicrophoneVolume(
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::MinMicrophoneVolume(
|
int32_t FakeAudioCaptureModule::MinMicrophoneVolume(
|
||||||
uint32_t* /*min_volume*/) const {
|
uint32_t* /*min_volume*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::MicrophoneVolumeStepSize(
|
int32_t FakeAudioCaptureModule::MicrophoneVolumeStepSize(
|
||||||
uint16_t* /*step_size*/) const {
|
uint16_t* /*step_size*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SpeakerMuteIsAvailable(bool* /*available*/) {
|
int32_t FakeAudioCaptureModule::SpeakerMuteIsAvailable(bool* /*available*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SetSpeakerMute(bool /*enable*/) {
|
int32_t FakeAudioCaptureModule::SetSpeakerMute(bool /*enable*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SpeakerMute(bool* /*enabled*/) const {
|
int32_t FakeAudioCaptureModule::SpeakerMute(bool* /*enabled*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::MicrophoneMuteIsAvailable(bool* /*available*/) {
|
int32_t FakeAudioCaptureModule::MicrophoneMuteIsAvailable(bool* /*available*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SetMicrophoneMute(bool /*enable*/) {
|
int32_t FakeAudioCaptureModule::SetMicrophoneMute(bool /*enable*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::MicrophoneMute(bool* /*enabled*/) const {
|
int32_t FakeAudioCaptureModule::MicrophoneMute(bool* /*enabled*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::MicrophoneBoostIsAvailable(
|
int32_t FakeAudioCaptureModule::MicrophoneBoostIsAvailable(
|
||||||
bool* /*available*/) {
|
bool* /*available*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SetMicrophoneBoost(bool /*enable*/) {
|
int32_t FakeAudioCaptureModule::SetMicrophoneBoost(bool /*enable*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::MicrophoneBoost(bool* /*enabled*/) const {
|
int32_t FakeAudioCaptureModule::MicrophoneBoost(bool* /*enabled*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +439,7 @@ int32_t FakeAudioCaptureModule::SetStereoPlayout(bool /*enable*/) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::StereoPlayout(bool* /*enabled*/) const {
|
int32_t FakeAudioCaptureModule::StereoPlayout(bool* /*enabled*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +458,7 @@ int32_t FakeAudioCaptureModule::SetStereoRecording(bool enable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::StereoRecording(bool* /*enabled*/) const {
|
int32_t FakeAudioCaptureModule::StereoRecording(bool* /*enabled*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,7 +467,7 @@ int32_t FakeAudioCaptureModule::SetRecordingChannel(
|
||||||
if (channel != AudioDeviceModule::kChannelBoth) {
|
if (channel != AudioDeviceModule::kChannelBoth) {
|
||||||
// There is no right or left in mono. I.e. kChannelBoth should be used for
|
// There is no right or left in mono. I.e. kChannelBoth should be used for
|
||||||
// mono.
|
// mono.
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -483,13 +482,13 @@ int32_t FakeAudioCaptureModule::RecordingChannel(ChannelType* channel) const {
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SetPlayoutBuffer(const BufferType /*type*/,
|
int32_t FakeAudioCaptureModule::SetPlayoutBuffer(const BufferType /*type*/,
|
||||||
uint16_t /*size_ms*/) {
|
uint16_t /*size_ms*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::PlayoutBuffer(BufferType* /*type*/,
|
int32_t FakeAudioCaptureModule::PlayoutBuffer(BufferType* /*type*/,
|
||||||
uint16_t* /*size_ms*/) const {
|
uint16_t* /*size_ms*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,73 +499,73 @@ int32_t FakeAudioCaptureModule::PlayoutDelay(uint16_t* delay_ms) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::RecordingDelay(uint16_t* /*delay_ms*/) const {
|
int32_t FakeAudioCaptureModule::RecordingDelay(uint16_t* /*delay_ms*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::CPULoad(uint16_t* /*load*/) const {
|
int32_t FakeAudioCaptureModule::CPULoad(uint16_t* /*load*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::StartRawOutputFileRecording(
|
int32_t FakeAudioCaptureModule::StartRawOutputFileRecording(
|
||||||
const char /*pcm_file_name_utf8*/[webrtc::kAdmMaxFileNameSize]) {
|
const char /*pcm_file_name_utf8*/[webrtc::kAdmMaxFileNameSize]) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::StopRawOutputFileRecording() {
|
int32_t FakeAudioCaptureModule::StopRawOutputFileRecording() {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::StartRawInputFileRecording(
|
int32_t FakeAudioCaptureModule::StartRawInputFileRecording(
|
||||||
const char /*pcm_file_name_utf8*/[webrtc::kAdmMaxFileNameSize]) {
|
const char /*pcm_file_name_utf8*/[webrtc::kAdmMaxFileNameSize]) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::StopRawInputFileRecording() {
|
int32_t FakeAudioCaptureModule::StopRawInputFileRecording() {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SetRecordingSampleRate(
|
int32_t FakeAudioCaptureModule::SetRecordingSampleRate(
|
||||||
const uint32_t /*samples_per_sec*/) {
|
const uint32_t /*samples_per_sec*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::RecordingSampleRate(
|
int32_t FakeAudioCaptureModule::RecordingSampleRate(
|
||||||
uint32_t* /*samples_per_sec*/) const {
|
uint32_t* /*samples_per_sec*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SetPlayoutSampleRate(
|
int32_t FakeAudioCaptureModule::SetPlayoutSampleRate(
|
||||||
const uint32_t /*samples_per_sec*/) {
|
const uint32_t /*samples_per_sec*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::PlayoutSampleRate(
|
int32_t FakeAudioCaptureModule::PlayoutSampleRate(
|
||||||
uint32_t* /*samples_per_sec*/) const {
|
uint32_t* /*samples_per_sec*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::ResetAudioDevice() {
|
int32_t FakeAudioCaptureModule::ResetAudioDevice() {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::SetLoudspeakerStatus(bool /*enable*/) {
|
int32_t FakeAudioCaptureModule::SetLoudspeakerStatus(bool /*enable*/) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FakeAudioCaptureModule::GetLoudspeakerStatus(bool* /*enabled*/) const {
|
int32_t FakeAudioCaptureModule::GetLoudspeakerStatus(bool* /*enabled*/) const {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,7 +580,7 @@ void FakeAudioCaptureModule::OnMessage(rtc::Message* msg) {
|
||||||
default:
|
default:
|
||||||
// All existing messages should be caught. Getting here should never
|
// All existing messages should be caught. Getting here should never
|
||||||
// happen.
|
// happen.
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,7 +590,7 @@ bool FakeAudioCaptureModule::Initialize() {
|
||||||
// sent to it. Note that the audio processing pipeline will likely distort the
|
// sent to it. Note that the audio processing pipeline will likely distort the
|
||||||
// original signal.
|
// original signal.
|
||||||
SetSendBuffer(kHighSampleValue);
|
SetSendBuffer(kHighSampleValue);
|
||||||
last_process_time_ms_ = rtc::Time();
|
last_process_time_ms_ = rtc::TimeMillis();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,7 +638,7 @@ void FakeAudioCaptureModule::UpdateProcessing(bool start) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeAudioCaptureModule::StartProcessP() {
|
void FakeAudioCaptureModule::StartProcessP() {
|
||||||
ASSERT(process_thread_->IsCurrent());
|
RTC_CHECK(process_thread_->IsCurrent());
|
||||||
if (started_) {
|
if (started_) {
|
||||||
// Already started.
|
// Already started.
|
||||||
return;
|
return;
|
||||||
|
@ -648,9 +647,9 @@ void FakeAudioCaptureModule::StartProcessP() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeAudioCaptureModule::ProcessFrameP() {
|
void FakeAudioCaptureModule::ProcessFrameP() {
|
||||||
ASSERT(process_thread_->IsCurrent());
|
RTC_CHECK(process_thread_->IsCurrent());
|
||||||
if (!started_) {
|
if (!started_) {
|
||||||
next_frame_time_ = rtc::Time();
|
next_frame_time_ = rtc::TimeMillis();
|
||||||
started_ = true;
|
started_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,14 +665,14 @@ void FakeAudioCaptureModule::ProcessFrameP() {
|
||||||
}
|
}
|
||||||
|
|
||||||
next_frame_time_ += kTimePerFrameMs;
|
next_frame_time_ += kTimePerFrameMs;
|
||||||
const uint32_t current_time = rtc::Time();
|
const int64_t current_time = rtc::TimeMillis();
|
||||||
const uint32_t wait_time =
|
const int64_t wait_time =
|
||||||
(next_frame_time_ > current_time) ? next_frame_time_ - current_time : 0;
|
(next_frame_time_ > current_time) ? next_frame_time_ - current_time : 0;
|
||||||
process_thread_->PostDelayed(RTC_FROM_HERE, wait_time, this, MSG_RUN_PROCESS);
|
process_thread_->PostDelayed(RTC_FROM_HERE, wait_time, this, MSG_RUN_PROCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeAudioCaptureModule::ReceiveFrameP() {
|
void FakeAudioCaptureModule::ReceiveFrameP() {
|
||||||
ASSERT(process_thread_->IsCurrent());
|
RTC_CHECK(process_thread_->IsCurrent());
|
||||||
{
|
{
|
||||||
rtc::CritScope cs(&crit_callback_);
|
rtc::CritScope cs(&crit_callback_);
|
||||||
if (!audio_callback_) {
|
if (!audio_callback_) {
|
||||||
|
@ -687,9 +686,9 @@ void FakeAudioCaptureModule::ReceiveFrameP() {
|
||||||
kNumberOfChannels, kSamplesPerSecond,
|
kNumberOfChannels, kSamplesPerSecond,
|
||||||
rec_buffer_, nSamplesOut,
|
rec_buffer_, nSamplesOut,
|
||||||
&elapsed_time_ms, &ntp_time_ms) != 0) {
|
&elapsed_time_ms, &ntp_time_ms) != 0) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
}
|
}
|
||||||
ASSERT(nSamplesOut == kNumberSamples);
|
RTC_CHECK(nSamplesOut == kNumberSamples);
|
||||||
}
|
}
|
||||||
// The SetBuffer() function ensures that after decoding, the audio buffer
|
// The SetBuffer() function ensures that after decoding, the audio buffer
|
||||||
// should contain samples of similar magnitude (there is likely to be some
|
// should contain samples of similar magnitude (there is likely to be some
|
||||||
|
@ -704,7 +703,7 @@ void FakeAudioCaptureModule::ReceiveFrameP() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeAudioCaptureModule::SendFrameP() {
|
void FakeAudioCaptureModule::SendFrameP() {
|
||||||
ASSERT(process_thread_->IsCurrent());
|
RTC_CHECK(process_thread_->IsCurrent());
|
||||||
rtc::CritScope cs(&crit_callback_);
|
rtc::CritScope cs(&crit_callback_);
|
||||||
if (!audio_callback_) {
|
if (!audio_callback_) {
|
||||||
return;
|
return;
|
||||||
|
@ -719,8 +718,7 @@ void FakeAudioCaptureModule::SendFrameP() {
|
||||||
kClockDriftMs, current_mic_level,
|
kClockDriftMs, current_mic_level,
|
||||||
key_pressed,
|
key_pressed,
|
||||||
current_mic_level) != 0) {
|
current_mic_level) != 0) {
|
||||||
ASSERT(false);
|
RTC_NOTREACHED();
|
||||||
}
|
}
|
||||||
SetMicrophoneVolume(current_mic_level);
|
SetMicrophoneVolume(current_mic_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,11 @@
|
||||||
// Note P postfix of a function indicates that it should only be called by the
|
// Note P postfix of a function indicates that it should only be called by the
|
||||||
// processing thread.
|
// processing thread.
|
||||||
|
|
||||||
#ifndef WEBRTC_API_TEST_FAKEAUDIOCAPTUREMODULE_H_
|
#ifndef _PEERCONNECT_PC_TEST_FAKEAUDIOCAPTUREMODULE_H_
|
||||||
#define WEBRTC_API_TEST_FAKEAUDIOCAPTUREMODULE_H_
|
#define _PEERCONNECT_PC_TEST_FAKEAUDIOCAPTUREMODULE_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "webrtc/base/basictypes.h"
|
#include "webrtc/base/basictypes.h"
|
||||||
#include "webrtc/base/criticalsection.h"
|
#include "webrtc/base/criticalsection.h"
|
||||||
#include "webrtc/base/messagehandler.h"
|
#include "webrtc/base/messagehandler.h"
|
||||||
|
@ -172,12 +173,22 @@ class FakeAudioCaptureModule
|
||||||
int32_t ResetAudioDevice() override;
|
int32_t ResetAudioDevice() override;
|
||||||
int32_t SetLoudspeakerStatus(bool enable) override;
|
int32_t SetLoudspeakerStatus(bool enable) override;
|
||||||
int32_t GetLoudspeakerStatus(bool* enabled) const override;
|
int32_t GetLoudspeakerStatus(bool* enabled) const override;
|
||||||
virtual bool BuiltInAECIsAvailable() const override { return false; }
|
bool BuiltInAECIsAvailable() const override { return false; }
|
||||||
virtual int32_t EnableBuiltInAEC(bool enable) override { return -1; }
|
int32_t EnableBuiltInAEC(bool enable) override { return -1; }
|
||||||
virtual bool BuiltInAGCIsAvailable() const override { return false; }
|
bool BuiltInAGCIsAvailable() const override { return false; }
|
||||||
virtual int32_t EnableBuiltInAGC(bool enable) override { return -1; }
|
int32_t EnableBuiltInAGC(bool enable) override { return -1; }
|
||||||
virtual bool BuiltInNSIsAvailable() const override { return false; }
|
bool BuiltInNSIsAvailable() const override { return false; }
|
||||||
virtual int32_t EnableBuiltInNS(bool enable) override { return -1; }
|
int32_t EnableBuiltInNS(bool enable) override { return -1; }
|
||||||
|
#if defined(WEBRTC_IOS)
|
||||||
|
int GetPlayoutAudioParameters(
|
||||||
|
webrtc::AudioParameters* params) const override {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int GetRecordAudioParameters(webrtc::AudioParameters* params) const override {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif // WEBRTC_IOS
|
||||||
|
|
||||||
// End of functions inherited from webrtc::AudioDeviceModule.
|
// End of functions inherited from webrtc::AudioDeviceModule.
|
||||||
|
|
||||||
// The following function is inherited from rtc::MessageHandler.
|
// The following function is inherited from rtc::MessageHandler.
|
||||||
|
@ -225,7 +236,7 @@ class FakeAudioCaptureModule
|
||||||
|
|
||||||
// The time in milliseconds when Process() was last called or 0 if no call
|
// The time in milliseconds when Process() was last called or 0 if no call
|
||||||
// has been made.
|
// has been made.
|
||||||
uint32_t last_process_time_ms_;
|
int64_t last_process_time_ms_;
|
||||||
|
|
||||||
// Callback for playout and recording.
|
// Callback for playout and recording.
|
||||||
webrtc::AudioTransport* audio_callback_;
|
webrtc::AudioTransport* audio_callback_;
|
||||||
|
@ -245,7 +256,7 @@ class FakeAudioCaptureModule
|
||||||
// wall clock time the next frame should be generated and received. started_
|
// wall clock time the next frame should be generated and received. started_
|
||||||
// ensures that next_frame_time_ can be initialized properly on first call.
|
// ensures that next_frame_time_ can be initialized properly on first call.
|
||||||
bool started_;
|
bool started_;
|
||||||
uint32_t next_frame_time_;
|
int64_t next_frame_time_;
|
||||||
|
|
||||||
std::unique_ptr<rtc::Thread> process_thread_;
|
std::unique_ptr<rtc::Thread> process_thread_;
|
||||||
|
|
||||||
|
@ -267,4 +278,4 @@ class FakeAudioCaptureModule
|
||||||
rtc::CriticalSection crit_callback_;
|
rtc::CriticalSection crit_callback_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBRTC_API_TEST_FAKEAUDIOCAPTUREMODULE_H_
|
#endif // _PEERCONNECT_PC_TEST_FAKEAUDIOCAPTUREMODULE_H_
|
||||||
|
|
|
@ -119,7 +119,7 @@ CriticalSection g_log_crit;
|
||||||
// The list of logging streams currently configured.
|
// The list of logging streams currently configured.
|
||||||
// Note: we explicitly do not clean this up, because of the uncertain ordering
|
// Note: we explicitly do not clean this up, because of the uncertain ordering
|
||||||
// of destructors at program exit. Let the person who sets the stream trigger
|
// of destructors at program exit. Let the person who sets the stream trigger
|
||||||
// cleanup by setting to NULL, or let it leak (safe at program exit).
|
// cleanup by setting to null, or let it leak (safe at program exit).
|
||||||
LogMessage::StreamList LogMessage::streams_ GUARDED_BY(g_log_crit);
|
LogMessage::StreamList LogMessage::streams_ GUARDED_BY(g_log_crit);
|
||||||
|
|
||||||
// Boolean options default to false (0)
|
// Boolean options default to false (0)
|
||||||
|
@ -133,7 +133,9 @@ LogMessage::LogMessage(const char* file,
|
||||||
const char* module)
|
const char* module)
|
||||||
: severity_(sev), tag_(kLibjingle) {
|
: severity_(sev), tag_(kLibjingle) {
|
||||||
if (timestamp_) {
|
if (timestamp_) {
|
||||||
int64_t time = TimeSince(LogStartTime());
|
// Use SystemTimeMillis so that even if tests use fake clocks, the timestamp
|
||||||
|
// in log messages represents the real system time.
|
||||||
|
int64_t time = TimeDiff(SystemTimeMillis(), LogStartTime());
|
||||||
// Also ensure WallClockStartTime is initialized, so that it matches
|
// Also ensure WallClockStartTime is initialized, so that it matches
|
||||||
// LogStartTime.
|
// LogStartTime.
|
||||||
WallClockStartTime();
|
WallClockStartTime();
|
||||||
|
@ -147,7 +149,7 @@ LogMessage::LogMessage(const char* file,
|
||||||
print_stream_ << "[" << std::dec << id << "] ";
|
print_stream_ << "[" << std::dec << id << "] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file != NULL)
|
if (file != nullptr)
|
||||||
print_stream_ << "(" << FilenameFromPath(file) << ":" << line << "): ";
|
print_stream_ << "(" << FilenameFromPath(file) << ":" << line << "): ";
|
||||||
|
|
||||||
if (err_ctx != ERRCTX_NONE) {
|
if (err_ctx != ERRCTX_NONE) {
|
||||||
|
@ -157,7 +159,7 @@ LogMessage::LogMessage(const char* file,
|
||||||
case ERRCTX_ERRNO:
|
case ERRCTX_ERRNO:
|
||||||
tmp << " " << strerror(err);
|
tmp << " " << strerror(err);
|
||||||
break;
|
break;
|
||||||
#if WEBRTC_WIN
|
#ifdef WEBRTC_WIN
|
||||||
case ERRCTX_HRESULT: {
|
case ERRCTX_HRESULT: {
|
||||||
char msgbuf[256];
|
char msgbuf[256];
|
||||||
DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM;
|
DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM;
|
||||||
|
@ -165,9 +167,8 @@ LogMessage::LogMessage(const char* file,
|
||||||
if (hmod)
|
if (hmod)
|
||||||
flags |= FORMAT_MESSAGE_FROM_HMODULE;
|
flags |= FORMAT_MESSAGE_FROM_HMODULE;
|
||||||
if (DWORD len = FormatMessageA(
|
if (DWORD len = FormatMessageA(
|
||||||
flags, hmod, err,
|
flags, hmod, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
msgbuf, sizeof(msgbuf) / sizeof(msgbuf[0]), nullptr)) {
|
||||||
msgbuf, sizeof(msgbuf) / sizeof(msgbuf[0]), NULL)) {
|
|
||||||
while ((len > 0) &&
|
while ((len > 0) &&
|
||||||
isspace(static_cast<unsigned char>(msgbuf[len-1]))) {
|
isspace(static_cast<unsigned char>(msgbuf[len-1]))) {
|
||||||
msgbuf[--len] = 0;
|
msgbuf[--len] = 0;
|
||||||
|
@ -179,9 +180,8 @@ LogMessage::LogMessage(const char* file,
|
||||||
#endif // WEBRTC_WIN
|
#endif // WEBRTC_WIN
|
||||||
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
|
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
|
||||||
case ERRCTX_OSSTATUS: {
|
case ERRCTX_OSSTATUS: {
|
||||||
// PeerConnect don't need this.
|
// std::string desc(DescriptionFromOSStatus(err));
|
||||||
// std::string desc(DescriptionFromOSStatus(err));
|
// tmp << " " << (desc.empty() ? "Unknown error" : desc.c_str());
|
||||||
// tmp << " " << (desc.empty() ? "Unknown error" : desc.c_str());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif // WEBRTC_MAC && !defined(WEBRTC_IOS)
|
#endif // WEBRTC_MAC && !defined(WEBRTC_IOS)
|
||||||
|
@ -196,7 +196,12 @@ LogMessage::LogMessage(const char* file,
|
||||||
int line,
|
int line,
|
||||||
LoggingSeverity sev,
|
LoggingSeverity sev,
|
||||||
const std::string& tag)
|
const std::string& tag)
|
||||||
: LogMessage(file, line, sev, ERRCTX_NONE, 0 /* err */, NULL /* module */) {
|
: LogMessage(file,
|
||||||
|
line,
|
||||||
|
sev,
|
||||||
|
ERRCTX_NONE,
|
||||||
|
0 /* err */,
|
||||||
|
nullptr /* module */) {
|
||||||
tag_ = tag;
|
tag_ = tag;
|
||||||
print_stream_ << tag << ": ";
|
print_stream_ << tag << ": ";
|
||||||
}
|
}
|
||||||
|
@ -220,12 +225,12 @@ LogMessage::~LogMessage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t LogMessage::LogStartTime() {
|
int64_t LogMessage::LogStartTime() {
|
||||||
static const int64_t g_start = TimeMillis();
|
static const int64_t g_start = SystemTimeMillis();
|
||||||
return g_start;
|
return g_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t LogMessage::WallClockStartTime() {
|
uint32_t LogMessage::WallClockStartTime() {
|
||||||
static const uint32_t g_start_wallclock = time(NULL);
|
static const uint32_t g_start_wallclock = time(nullptr);
|
||||||
return g_start_wallclock;
|
return g_start_wallclock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +362,7 @@ void LogMessage::OutputToDebug(const std::string& str,
|
||||||
"logToStdErr",
|
"logToStdErr",
|
||||||
kCFStringEncodingUTF8);
|
kCFStringEncodingUTF8);
|
||||||
CFStringRef domain = CFBundleGetIdentifier(CFBundleGetMainBundle());
|
CFStringRef domain = CFBundleGetIdentifier(CFBundleGetMainBundle());
|
||||||
if (key != NULL && domain != NULL) {
|
if (key != nullptr && domain != nullptr) {
|
||||||
Boolean exists_and_is_valid;
|
Boolean exists_and_is_valid;
|
||||||
Boolean should_log =
|
Boolean should_log =
|
||||||
CFPreferencesGetAppBooleanValue(key, domain, &exists_and_is_valid);
|
CFPreferencesGetAppBooleanValue(key, domain, &exists_and_is_valid);
|
||||||
|
@ -365,7 +370,7 @@ void LogMessage::OutputToDebug(const std::string& str,
|
||||||
// stderr.
|
// stderr.
|
||||||
log_to_stderr = exists_and_is_valid && should_log;
|
log_to_stderr = exists_and_is_valid && should_log;
|
||||||
}
|
}
|
||||||
if (key != NULL) {
|
if (key != nullptr) {
|
||||||
CFRelease(key);
|
CFRelease(key);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -446,15 +451,15 @@ void LogMessage::OutputToDebug(const std::string& str,
|
||||||
void LogMultiline(LoggingSeverity level, const char* label, bool input,
|
void LogMultiline(LoggingSeverity level, const char* label, bool input,
|
||||||
const void* data, size_t len, bool hex_mode,
|
const void* data, size_t len, bool hex_mode,
|
||||||
LogMultilineState* state) {
|
LogMultilineState* state) {
|
||||||
if (!LOGP_CHECK_LEVEL_V(level))
|
if (!LOG_CHECK_LEVEL_V(level))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const char * direction = (input ? " << " : " >> ");
|
const char * direction = (input ? " << " : " >> ");
|
||||||
|
|
||||||
// NULL data means to flush our count of unprintable characters.
|
// null data means to flush our count of unprintable characters.
|
||||||
if (!data) {
|
if (!data) {
|
||||||
if (state && state->unprintable_count_[input]) {
|
if (state && state->unprintable_count_[input]) {
|
||||||
LOGP_V(level) << label << direction << "## "
|
LOG_V(level) << label << direction << "## "
|
||||||
<< state->unprintable_count_[input]
|
<< state->unprintable_count_[input]
|
||||||
<< " consecutive unprintable ##";
|
<< " consecutive unprintable ##";
|
||||||
state->unprintable_count_[input] = 0;
|
state->unprintable_count_[input] = 0;
|
||||||
|
@ -480,7 +485,7 @@ void LogMultiline(LoggingSeverity level, const char* label, bool input,
|
||||||
}
|
}
|
||||||
asc_line[sizeof(asc_line)-1] = 0;
|
asc_line[sizeof(asc_line)-1] = 0;
|
||||||
hex_line[sizeof(hex_line)-1] = 0;
|
hex_line[sizeof(hex_line)-1] = 0;
|
||||||
LOGP_V(level) << label << direction
|
LOG_V(level) << label << direction
|
||||||
<< asc_line << " " << hex_line << " ";
|
<< asc_line << " " << hex_line << " ";
|
||||||
udata += line_len;
|
udata += line_len;
|
||||||
len -= line_len;
|
len -= line_len;
|
||||||
|
@ -534,7 +539,7 @@ void LogMultiline(LoggingSeverity level, const char* label, bool input,
|
||||||
// Print out the current line, but prefix with a count of prior unprintable
|
// Print out the current line, but prefix with a count of prior unprintable
|
||||||
// characters.
|
// characters.
|
||||||
if (consecutive_unprintable) {
|
if (consecutive_unprintable) {
|
||||||
LOGP_V(level) << label << direction << "## " << consecutive_unprintable
|
LOG_V(level) << label << direction << "## " << consecutive_unprintable
|
||||||
<< " consecutive unprintable ##";
|
<< " consecutive unprintable ##";
|
||||||
consecutive_unprintable = 0;
|
consecutive_unprintable = 0;
|
||||||
}
|
}
|
||||||
|
@ -549,9 +554,9 @@ void LogMultiline(LoggingSeverity level, const char* label, bool input,
|
||||||
pos_private = substr.find("Passwd");
|
pos_private = substr.find("Passwd");
|
||||||
}
|
}
|
||||||
if (pos_private == std::string::npos) {
|
if (pos_private == std::string::npos) {
|
||||||
LOGP_V(level) << label << direction << substr;
|
LOG_V(level) << label << direction << substr;
|
||||||
} else {
|
} else {
|
||||||
LOGP_V(level) << label << direction << "## omitted for privacy ##";
|
LOG_V(level) << label << direction << "## omitted for privacy ##";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
140
src/logging.h
140
src/logging.h
|
@ -14,7 +14,7 @@
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// LOGP(...) an ostream target that can be used to send formatted
|
// LOG(...) an ostream target that can be used to send formatted
|
||||||
// output to a variety of logging targets, such as debugger console, stderr,
|
// output to a variety of logging targets, such as debugger console, stderr,
|
||||||
// or any LogSink.
|
// or any LogSink.
|
||||||
// The severity level passed as the first argument to the LOGging
|
// The severity level passed as the first argument to the LOGging
|
||||||
|
@ -24,30 +24,30 @@
|
||||||
// There are several variations on the LOG macro which facilitate logging
|
// There are several variations on the LOG macro which facilitate logging
|
||||||
// of common error conditions, detailed below.
|
// of common error conditions, detailed below.
|
||||||
|
|
||||||
// LOGP(sev) logs the given stream at severity "sev", which must be a
|
// LOG(sev) logs the given stream at severity "sev", which must be a
|
||||||
// compile-time constant of the LoggingSeverity type, without the namespace
|
// compile-time constant of the LoggingSeverity type, without the namespace
|
||||||
// prefix.
|
// prefix.
|
||||||
// LOGP_V(sev) Like LOGP(), but sev is a run-time variable of the LoggingSeverity
|
// LOG_V(sev) Like LOG(), but sev is a run-time variable of the LoggingSeverity
|
||||||
// type (basically, it just doesn't prepend the namespace).
|
// type (basically, it just doesn't prepend the namespace).
|
||||||
// LOGP_F(sev) Like LOGP(), but includes the name of the current function.
|
// LOG_F(sev) Like LOG(), but includes the name of the current function.
|
||||||
// LOGP_T(sev) Like LOGP(), but includes the this pointer.
|
// LOG_T(sev) Like LOG(), but includes the this pointer.
|
||||||
// LOGP_T_F(sev) Like LOGP_F(), but includes the this pointer.
|
// LOG_T_F(sev) Like LOG_F(), but includes the this pointer.
|
||||||
// LOGP_GLE(M)(sev [, mod]) attempt to add a string description of the
|
// LOG_GLE(M)(sev [, mod]) attempt to add a string description of the
|
||||||
// HRESULT returned by GetLastError. The "M" variant allows searching of a
|
// HRESULT returned by GetLastError. The "M" variant allows searching of a
|
||||||
// DLL's string table for the error description.
|
// DLL's string table for the error description.
|
||||||
// LOGP_ERRNO(sev) attempts to add a string description of an errno-derived
|
// LOG_ERRNO(sev) attempts to add a string description of an errno-derived
|
||||||
// error. errno and associated facilities exist on both Windows and POSIX,
|
// error. errno and associated facilities exist on both Windows and POSIX,
|
||||||
// but on Windows they only apply to the C/C++ runtime.
|
// but on Windows they only apply to the C/C++ runtime.
|
||||||
// LOGP_ERR(sev) is an alias for the platform's normal error system, i.e. _GLE on
|
// LOG_ERR(sev) is an alias for the platform's normal error system, i.e. _GLE on
|
||||||
// Windows and _ERRNO on POSIX.
|
// Windows and _ERRNO on POSIX.
|
||||||
// (The above three also all have _EX versions that let you specify the error
|
// (The above three also all have _EX versions that let you specify the error
|
||||||
// code, rather than using the last one.)
|
// code, rather than using the last one.)
|
||||||
// LOGP_E(sev, ctx, err, ...) logs a detailed error interpreted using the
|
// LOG_E(sev, ctx, err, ...) logs a detailed error interpreted using the
|
||||||
// specified context.
|
// specified context.
|
||||||
// LOGP_CHECK_LEVEL(sev) (and LOGP_CHECK_LEVEL_V(sev)) can be used as a test
|
// LOG_CHECK_LEVEL(sev) (and LOG_CHECK_LEVEL_V(sev)) can be used as a test
|
||||||
// before performing expensive or sensitive operations whose sole purpose is
|
// before performing expensive or sensitive operations whose sole purpose is
|
||||||
// to output logging data at the desired level.
|
// to output logging data at the desired level.
|
||||||
// Lastly, PLOGP(sev, err) is an alias for LOGP_ERR_EX.
|
// Lastly, PLOG(sev, err) is an alias for LOG_ERR_EX.
|
||||||
|
|
||||||
#ifndef __PEERCONNECT_LOGGING_H__
|
#ifndef __PEERCONNECT_LOGGING_H__
|
||||||
#define __PEERCONNECT_LOGGING_H__
|
#define __PEERCONNECT_LOGGING_H__
|
||||||
|
@ -81,16 +81,13 @@ namespace pc {
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// int err = LibraryFunc();
|
// int err = LibraryFunc();
|
||||||
// LOGP(LS_ERROR) << "LibraryFunc returned: "
|
// LOG(LS_ERROR) << "LibraryFunc returned: "
|
||||||
// << ErrorName(err, LIBRARY_ERRORS);
|
// << ErrorName(err, LIBRARY_ERRORS);
|
||||||
|
|
||||||
struct ConstantLabel { int value; const char * label; };
|
struct ConstantLabel { int value; const char * label; };
|
||||||
|
|
||||||
#ifndef KLABEL
|
|
||||||
#define KLABEL(x) { x, #x }
|
#define KLABEL(x) { x, #x }
|
||||||
#define TLABEL(x, y) { x, y }
|
#define TLABEL(x, y) { x, y }
|
||||||
#define LASTLABEL { 0, 0 }
|
#define LASTLABEL { 0, 0 }
|
||||||
#endif
|
|
||||||
|
|
||||||
const char* FindLabel(int value, const ConstantLabel entries[]);
|
const char* FindLabel(int value, const ConstantLabel entries[]);
|
||||||
std::string ErrorName(int err, const ConstantLabel* err_table);
|
std::string ErrorName(int err, const ConstantLabel* err_table);
|
||||||
|
@ -148,9 +145,12 @@ class LogSink {
|
||||||
|
|
||||||
class LogMessage {
|
class LogMessage {
|
||||||
public:
|
public:
|
||||||
LogMessage(const char* file, int line, LoggingSeverity sev,
|
LogMessage(const char* file,
|
||||||
LogErrorContext err_ctx = ERRCTX_NONE, int err = 0,
|
int line,
|
||||||
const char* module = NULL);
|
LoggingSeverity sev,
|
||||||
|
LogErrorContext err_ctx = ERRCTX_NONE,
|
||||||
|
int err = 0,
|
||||||
|
const char* module = nullptr);
|
||||||
|
|
||||||
LogMessage(const char* file,
|
LogMessage(const char* file,
|
||||||
int line,
|
int line,
|
||||||
|
@ -194,7 +194,7 @@ class LogMessage {
|
||||||
// GetLogToStream gets the severity for the specified stream, of if none
|
// GetLogToStream gets the severity for the specified stream, of if none
|
||||||
// is specified, the minimum stream severity.
|
// is specified, the minimum stream severity.
|
||||||
// RemoveLogToStream removes the specified stream, without destroying it.
|
// RemoveLogToStream removes the specified stream, without destroying it.
|
||||||
static int GetLogToStream(LogSink* stream = NULL);
|
static int GetLogToStream(LogSink* stream = nullptr);
|
||||||
static void AddLogToStream(LogSink* stream, LoggingSeverity min_sev);
|
static void AddLogToStream(LogSink* stream, LoggingSeverity min_sev);
|
||||||
static void RemoveLogToStream(LogSink* stream);
|
static void RemoveLogToStream(LogSink* stream);
|
||||||
|
|
||||||
|
@ -263,12 +263,12 @@ class LogMultilineState {
|
||||||
};
|
};
|
||||||
|
|
||||||
// When possible, pass optional state variable to track various data across
|
// When possible, pass optional state variable to track various data across
|
||||||
// multiple calls to LogMultiline. Otherwise, pass NULL.
|
// multiple calls to LogMultiline. Otherwise, pass null.
|
||||||
void LogMultiline(LoggingSeverity level, const char* label, bool input,
|
void LogMultiline(LoggingSeverity level, const char* label, bool input,
|
||||||
const void* data, size_t len, bool hex_mode,
|
const void* data, size_t len, bool hex_mode,
|
||||||
LogMultilineState* state);
|
LogMultilineState* state);
|
||||||
|
|
||||||
#ifndef LOGP
|
#ifndef LOG
|
||||||
|
|
||||||
// The following non-obvious technique for implementation of a
|
// The following non-obvious technique for implementation of a
|
||||||
// conditional log stream was stolen from google3/base/logging.h.
|
// conditional log stream was stolen from google3/base/logging.h.
|
||||||
|
@ -285,101 +285,91 @@ class LogMessageVoidify {
|
||||||
void operator&(std::ostream&) { }
|
void operator&(std::ostream&) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LOGP_SEVERITY_PRECONDITION(sev) \
|
#define LOG_SEVERITY_PRECONDITION(sev) \
|
||||||
!(pc::LogMessage::Loggable(sev)) \
|
!(pc::LogMessage::Loggable(sev)) \
|
||||||
? (void) 0 \
|
? (void) 0 \
|
||||||
: pc::LogMessageVoidify() &
|
: pc::LogMessageVoidify() &
|
||||||
|
|
||||||
#define LOGP(sev) \
|
#define LOG(sev) \
|
||||||
LOGP_SEVERITY_PRECONDITION(pc::sev) \
|
LOG_SEVERITY_PRECONDITION(pc::sev) \
|
||||||
pc::LogMessage(__FILE__, __LINE__, pc::sev).stream()
|
pc::LogMessage(__FILE__, __LINE__, pc::sev).stream()
|
||||||
|
|
||||||
#define LOGP_IF(cond, sev) \
|
|
||||||
!(cond) \
|
|
||||||
? (void) 0 \
|
|
||||||
: LOGP(sev)
|
|
||||||
|
|
||||||
#define LOGP_F_IF(cond, sev) \
|
|
||||||
!(cond) \
|
|
||||||
? (void) 0 \
|
|
||||||
: LOGP_F(sev)
|
|
||||||
|
|
||||||
// The _V version is for when a variable is passed in. It doesn't do the
|
// The _V version is for when a variable is passed in. It doesn't do the
|
||||||
// namespace concatination.
|
// namespace concatination.
|
||||||
#define LOGP_V(sev) \
|
#define LOG_V(sev) \
|
||||||
LOGP_SEVERITY_PRECONDITION(sev) \
|
LOG_SEVERITY_PRECONDITION(sev) \
|
||||||
pc::LogMessage(__FILE__, __LINE__, sev).stream()
|
pc::LogMessage(__FILE__, __LINE__, sev).stream()
|
||||||
|
|
||||||
// The _F version prefixes the message with the current function name.
|
// The _F version prefixes the message with the current function name.
|
||||||
#if (defined(__GNUC__) && !defined(NDEBUG)) || defined(WANT_PRETTY_LOG_F)
|
#if (defined(__GNUC__) && !defined(NDEBUG)) || defined(WANT_PRETTY_LOG_F)
|
||||||
#define LOGP_F(sev) LOGP(sev) << __PRETTY_FUNCTION__ << ": "
|
#define LOG_F(sev) LOG(sev) << __PRETTY_FUNCTION__ << ": "
|
||||||
#define LOGP_T_F(sev) LOGP(sev) << this << ": " << __PRETTY_FUNCTION__ << ": "
|
#define LOG_T_F(sev) LOG(sev) << this << ": " << __PRETTY_FUNCTION__ << ": "
|
||||||
#else
|
#else
|
||||||
#define LOGP_F(sev) LOGP(sev) << __FUNCTION__ << ": "
|
#define LOG_F(sev) LOG(sev) << __FUNCTION__ << ": "
|
||||||
#define LOGP_T_F(sev) LOGP(sev) << this << ": " << __FUNCTION__ << ": "
|
#define LOG_T_F(sev) LOG(sev) << this << ": " << __FUNCTION__ << ": "
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LOGP_CHECK_LEVEL(sev) \
|
#define LOG_CHECK_LEVEL(sev) \
|
||||||
pc::LogCheckLevel(pc::sev)
|
pc::LogCheckLevel(pc::sev)
|
||||||
#define LOGP_CHECK_LEVEL_V(sev) \
|
#define LOG_CHECK_LEVEL_V(sev) \
|
||||||
pc::LogCheckLevel(sev)
|
pc::LogCheckLevel(sev)
|
||||||
|
|
||||||
inline bool LogCheckLevel(LoggingSeverity sev) {
|
inline bool LogCheckLevel(LoggingSeverity sev) {
|
||||||
return (LogMessage::GetMinLogSeverity() <= sev);
|
return (LogMessage::GetMinLogSeverity() <= sev);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOGP_E(sev, ctx, err, ...) \
|
#define LOG_E(sev, ctx, err, ...) \
|
||||||
LOGP_SEVERITY_PRECONDITION(pc::sev) \
|
LOG_SEVERITY_PRECONDITION(pc::sev) \
|
||||||
pc::LogMessage(__FILE__, __LINE__, pc::sev, \
|
pc::LogMessage(__FILE__, __LINE__, pc::sev, \
|
||||||
pc::ERRCTX_ ## ctx, err , ##__VA_ARGS__) \
|
pc::ERRCTX_ ## ctx, err , ##__VA_ARGS__) \
|
||||||
.stream()
|
.stream()
|
||||||
|
|
||||||
#define LOGP_T(sev) LOGP(sev) << this << ": "
|
#define LOG_T(sev) LOG(sev) << this << ": "
|
||||||
|
|
||||||
#define LOGP_ERRNO_EX(sev, err) \
|
#define LOG_ERRNO_EX(sev, err) \
|
||||||
LOGP_E(sev, ERRNO, err)
|
LOG_E(sev, ERRNO, err)
|
||||||
#define LOGP_ERRNO(sev) \
|
#define LOG_ERRNO(sev) \
|
||||||
LOGP_ERRNO_EX(sev, errno)
|
LOG_ERRNO_EX(sev, errno)
|
||||||
|
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
#define LOGP_GLE_EX(sev, err) \
|
#define LOG_GLE_EX(sev, err) \
|
||||||
LOGP_E(sev, HRESULT, err)
|
LOG_E(sev, HRESULT, err)
|
||||||
#define LOGP_GLE(sev) \
|
#define LOG_GLE(sev) \
|
||||||
LOGP_GLE_EX(sev, GetLastError())
|
LOG_GLE_EX(sev, GetLastError())
|
||||||
#define LOGP_GLEM(sev, mod) \
|
#define LOG_GLEM(sev, mod) \
|
||||||
LOGP_E(sev, HRESULT, GetLastError(), mod)
|
LOG_E(sev, HRESULT, GetLastError(), mod)
|
||||||
#define LOGP_ERR_EX(sev, err) \
|
#define LOG_ERR_EX(sev, err) \
|
||||||
LOGP_GLE_EX(sev, err)
|
LOG_GLE_EX(sev, err)
|
||||||
#define LOGP_ERR(sev) \
|
#define LOG_ERR(sev) \
|
||||||
LOGP_GLE(sev)
|
LOG_GLE(sev)
|
||||||
#define LAST_SYSTEM_ERROR \
|
#define LAST_SYSTEM_ERROR \
|
||||||
(::GetLastError())
|
(::GetLastError())
|
||||||
#elif __native_client__
|
#elif defined(__native_client__) && __native_client__
|
||||||
#define LOGP_ERR_EX(sev, err) \
|
#define LOG_ERR_EX(sev, err) \
|
||||||
LOGP(sev)
|
LOG(sev)
|
||||||
#define LOGP_ERR(sev) \
|
#define LOG_ERR(sev) \
|
||||||
LOGP(sev)
|
LOG(sev)
|
||||||
#define LAST_SYSTEM_ERROR \
|
#define LAST_SYSTEM_ERROR \
|
||||||
(0)
|
(0)
|
||||||
#elif defined(WEBRTC_POSIX)
|
#elif defined(WEBRTC_POSIX)
|
||||||
#define LOGP_ERR_EX(sev, err) \
|
#define LOG_ERR_EX(sev, err) \
|
||||||
LOGP_ERRNO_EX(sev, err)
|
LOG_ERRNO_EX(sev, err)
|
||||||
#define LOGP_ERR(sev) \
|
#define LOG_ERR(sev) \
|
||||||
LOGP_ERRNO(sev)
|
LOG_ERRNO(sev)
|
||||||
#define LAST_SYSTEM_ERROR \
|
#define LAST_SYSTEM_ERROR \
|
||||||
(errno)
|
(errno)
|
||||||
#endif // WEBRTC_WIN
|
#endif // WEBRTC_WIN
|
||||||
|
|
||||||
#define LOGP_TAG(sev, tag) \
|
#define LOG_TAG(sev, tag) \
|
||||||
LOGP_SEVERITY_PRECONDITION(sev) \
|
LOG_SEVERITY_PRECONDITION(sev) \
|
||||||
pc::LogMessage(NULL, 0, sev, tag).stream()
|
pc::LogMessage(nullptr, 0, sev, tag).stream()
|
||||||
|
|
||||||
#define PLOGP(sev, err) \
|
#define PLOG(sev, err) \
|
||||||
LOGP_ERR_EX(sev, err)
|
LOG_ERR_EX(sev, err)
|
||||||
|
|
||||||
// TODO(?): Add an "assert" wrapper that logs in the same manner.
|
// TODO(?): Add an "assert" wrapper that logs in the same manner.
|
||||||
|
|
||||||
#endif // LOGP
|
#endif // LOG
|
||||||
|
|
||||||
} // namespace pc
|
} // namespace pc
|
||||||
|
|
||||||
|
|
132
src/peer.cc
132
src/peer.cc
|
@ -7,7 +7,7 @@
|
||||||
#include "control.h"
|
#include "control.h"
|
||||||
#include "peer.h"
|
#include "peer.h"
|
||||||
#include "webrtc/api/test/fakeconstraints.h"
|
#include "webrtc/api/test/fakeconstraints.h"
|
||||||
#include "webrtc/api/test/mockpeerconnectionobservers.h"
|
#include "webrtc/pc/test/mockpeerconnectionobservers.h"
|
||||||
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
@ -31,16 +31,16 @@ PeerControl::PeerControl(const string local_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerControl::~PeerControl() {
|
PeerControl::~PeerControl() {
|
||||||
ASSERT(state_ == pClosed);
|
RTC_DCHECK(state_ == pClosed);
|
||||||
DeletePeerConnection();
|
DeletePeerConnection();
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PeerControl::Initialize() {
|
bool PeerControl::Initialize() {
|
||||||
|
|
||||||
if (!CreatePeerConnection()) {
|
if (!CreatePeerConnection()) {
|
||||||
LOGP_F(LS_ERROR) << "CreatePeerConnection failed";
|
LOG_F(LS_ERROR) << "CreatePeerConnection failed";
|
||||||
DeletePeerConnection();
|
DeletePeerConnection();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -48,20 +48,20 @@ bool PeerControl::Initialize() {
|
||||||
webrtc::DataChannelInit init;
|
webrtc::DataChannelInit init;
|
||||||
const string data_channel_name = string("pc_data_") + remote_id_;
|
const string data_channel_name = string("pc_data_") + remote_id_;
|
||||||
if (!CreateDataChannel(data_channel_name, init)) {
|
if (!CreateDataChannel(data_channel_name, init)) {
|
||||||
LOGP_F(LS_ERROR) << "CreateDataChannel failed";
|
LOG_F(LS_ERROR) << "CreateDataChannel failed";
|
||||||
DeletePeerConnection();
|
DeletePeerConnection();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerControl::Send(const char* buffer, const size_t size) {
|
bool PeerControl::Send(const char* buffer, const size_t size) {
|
||||||
ASSERT( state_ == pOpen );
|
RTC_DCHECK( state_ == pOpen );
|
||||||
|
|
||||||
if ( state_ != pOpen ) {
|
if ( state_ != pOpen ) {
|
||||||
LOGP_F( WARNING ) << "Send data when a peer state is not opened";
|
LOG_F( WARNING ) << "Send data when a peer state is not opened";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,10 +69,10 @@ bool PeerControl::Send(const char* buffer, const size_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerControl::SyncSend(const char* buffer, const size_t size) {
|
bool PeerControl::SyncSend(const char* buffer, const size_t size) {
|
||||||
ASSERT( state_ == pOpen );
|
RTC_DCHECK( state_ == pOpen );
|
||||||
|
|
||||||
if ( state_ != pOpen ) {
|
if ( state_ != pOpen ) {
|
||||||
LOGP_F( WARNING ) << "Send data when a peer state is not opened";
|
LOG_F( WARNING ) << "Send data when a peer state is not opened";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ bool PeerControl::SyncSend(const char* buffer, const size_t size) {
|
||||||
bool PeerControl::IsWritable() {
|
bool PeerControl::IsWritable() {
|
||||||
|
|
||||||
if ( state_ != pOpen ) {
|
if ( state_ != pOpen ) {
|
||||||
LOGP_F( WARNING ) << "A function was called when a peer state is not opened";
|
LOG_F( WARNING ) << "A function was called when a peer state is not opened";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,16 +90,16 @@ bool PeerControl::IsWritable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerControl::Close(const CloseCode code) {
|
void PeerControl::Close(const CloseCode code) {
|
||||||
LOGP_F_IF(state_ != pOpen, WARNING) << "Closing peer when it is not opened";
|
// LOG_F_IF(state_ != pOpen, WARNING) << "Closing peer when it is not opened";
|
||||||
|
|
||||||
if ( state_ == pClosing || state_ == pClosed ) {
|
if ( state_ == pClosing || state_ == pClosed ) {
|
||||||
LOGP_F( WARNING ) << "Close peer when is closing or already closed";
|
LOG_F( WARNING ) << "Close peer when is closing or already closed";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state_ = pClosing;
|
state_ = pClosing;
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Close data-channel of remote_id_ " << remote_id_;
|
LOG_F( INFO ) << "Close data-channel of remote_id_ " << remote_id_;
|
||||||
|
|
||||||
if ( peer_connection_ ) {
|
if ( peer_connection_ ) {
|
||||||
|
|
||||||
|
@ -120,45 +120,45 @@ void PeerControl::Close(const CloseCode code) {
|
||||||
|
|
||||||
|
|
||||||
void PeerControl::CreateOffer(const webrtc::MediaConstraintsInterface* constraints) {
|
void PeerControl::CreateOffer(const webrtc::MediaConstraintsInterface* constraints) {
|
||||||
ASSERT( state_ == pClosed );
|
RTC_DCHECK( state_ == pClosed );
|
||||||
|
|
||||||
state_ = pConnecting;
|
state_ = pConnecting;
|
||||||
peer_connection_->CreateOffer(this, constraints);
|
peer_connection_->CreateOffer(this, constraints);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PeerControl::CreateAnswer(const webrtc::MediaConstraintsInterface* constraints) {
|
void PeerControl::CreateAnswer(const webrtc::MediaConstraintsInterface* constraints) {
|
||||||
ASSERT( state_ == pClosed );
|
RTC_DCHECK( state_ == pClosed );
|
||||||
|
|
||||||
state_ = pConnecting;
|
state_ = pConnecting;
|
||||||
peer_connection_->CreateAnswer(this, constraints);
|
peer_connection_->CreateAnswer(this, constraints);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PeerControl::ReceiveOfferSdp(const string& sdp) {
|
void PeerControl::ReceiveOfferSdp(const string& sdp) {
|
||||||
ASSERT( state_ == pClosed);
|
RTC_DCHECK( state_ == pClosed);
|
||||||
SetRemoteDescription(webrtc::SessionDescriptionInterface::kOffer, sdp);
|
SetRemoteDescription(webrtc::SessionDescriptionInterface::kOffer, sdp);
|
||||||
CreateAnswer(NULL);
|
CreateAnswer(NULL);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PeerControl::ReceiveAnswerSdp(const string& sdp) {
|
void PeerControl::ReceiveAnswerSdp(const string& sdp) {
|
||||||
ASSERT( state_ == pConnecting );
|
RTC_DCHECK( state_ == pConnecting );
|
||||||
SetRemoteDescription(webrtc::SessionDescriptionInterface::kAnswer, sdp);
|
SetRemoteDescription(webrtc::SessionDescriptionInterface::kAnswer, sdp);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerControl::OnDataChannel(webrtc::DataChannelInterface* data_channel) {
|
void PeerControl::OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> channel) {
|
||||||
LOGP_F( INFO ) << "remote_id_ is " << remote_id_;
|
LOG_F( INFO ) << "remote_id_ is " << remote_id_;
|
||||||
|
|
||||||
PeerDataChannelObserver* Observer = new PeerDataChannelObserver(data_channel);
|
PeerDataChannelObserver* Observer = new PeerDataChannelObserver(channel);
|
||||||
remote_data_channel_ = std::unique_ptr<PeerDataChannelObserver>(Observer);
|
remote_data_channel_ = std::unique_ptr<PeerDataChannelObserver>(Observer);
|
||||||
Attach(remote_data_channel_.get());
|
Attach(remote_data_channel_.get());
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerControl::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) {
|
void PeerControl::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) {
|
||||||
|
@ -178,7 +178,7 @@ void PeerControl::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConn
|
||||||
// Ice connection has been closed.
|
// Ice connection has been closed.
|
||||||
// Notify it to Control so the Control will remove peer in peers_
|
// Notify it to Control so the Control will remove peer in peers_
|
||||||
//
|
//
|
||||||
LOGP_F( INFO ) << "new_state is " << "kIceConnectionClosed";
|
LOG_F( INFO ) << "new_state is " << "kIceConnectionClosed";
|
||||||
OnPeerDisconnected();
|
OnPeerDisconnected();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -186,23 +186,23 @@ void PeerControl::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConn
|
||||||
//
|
//
|
||||||
// Peer disconnected and notify it to control that makes control trigger closing
|
// Peer disconnected and notify it to control that makes control trigger closing
|
||||||
//
|
//
|
||||||
LOGP_F( INFO ) << "new_state is " << "kIceConnectionDisconnected";
|
LOG_F( INFO ) << "new_state is " << "kIceConnectionDisconnected";
|
||||||
OnPeerDisconnected();
|
OnPeerDisconnected();
|
||||||
break;
|
break;
|
||||||
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionNew:
|
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionNew:
|
||||||
LOGP_F( INFO ) << "new_state is " << "kIceConnectionNew";
|
LOG_F( INFO ) << "new_state is " << "kIceConnectionNew";
|
||||||
break;
|
break;
|
||||||
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionChecking:
|
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionChecking:
|
||||||
LOGP_F( INFO ) << "new_state is " << "kIceConnectionChecking";
|
LOG_F( INFO ) << "new_state is " << "kIceConnectionChecking";
|
||||||
break;
|
break;
|
||||||
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionConnected:
|
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionConnected:
|
||||||
LOGP_F( INFO ) << "new_state is " << "kIceConnectionConnected";
|
LOG_F( INFO ) << "new_state is " << "kIceConnectionConnected";
|
||||||
break;
|
break;
|
||||||
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionCompleted:
|
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionCompleted:
|
||||||
LOGP_F( INFO ) << "new_state is " << "kIceConnectionCompleted";
|
LOG_F( INFO ) << "new_state is " << "kIceConnectionCompleted";
|
||||||
break;
|
break;
|
||||||
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionFailed:
|
case webrtc::PeerConnectionInterface::IceConnectionState::kIceConnectionFailed:
|
||||||
LOGP_F( INFO ) << "new_state is " << "kIceConnectionFailed";
|
LOG_F( INFO ) << "new_state is " << "kIceConnectionFailed";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -221,7 +221,7 @@ void PeerControl::OnIceCandidate(const webrtc::IceCandidateInterface* candidate)
|
||||||
data["candidate"] = sdp;
|
data["candidate"] = sdp;
|
||||||
|
|
||||||
control_->SendCommand(remote_id_, "ice_candidate", data);
|
control_->SendCommand(remote_id_, "ice_candidate", data);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerControl::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
|
void PeerControl::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
|
||||||
|
@ -233,7 +233,7 @@ void PeerControl::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
|
||||||
if (!desc->ToString(&sdp)) return;
|
if (!desc->ToString(&sdp)) return;
|
||||||
|
|
||||||
if ( state_ != pConnecting ) {
|
if ( state_ != pConnecting ) {
|
||||||
LOGP_F( WARNING ) << "Invalid state";
|
LOG_F( WARNING ) << "Invalid state";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ void PeerControl::OnSuccess(webrtc::SessionDescriptionInterface* desc) {
|
||||||
data["sdp"] = sdp;
|
data["sdp"] = sdp;
|
||||||
control_->SendCommand(remote_id_, "answersdp", data);
|
control_->SendCommand(remote_id_, "answersdp", data);
|
||||||
}
|
}
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerControl::OnPeerOpened() {
|
void PeerControl::OnPeerOpened() {
|
||||||
|
@ -263,7 +263,7 @@ void PeerControl::OnPeerOpened() {
|
||||||
remote_data_channel_->state() == webrtc::DataChannelInterface::DataState::kOpen
|
remote_data_channel_->state() == webrtc::DataChannelInterface::DataState::kOpen
|
||||||
) {
|
) {
|
||||||
LOG_F( INFO ) << "Peers are connected, " << remote_id_ << " and " << local_id_;
|
LOG_F( INFO ) << "Peers are connected, " << remote_id_ << " and " << local_id_;
|
||||||
ASSERT( state_ == pConnecting );
|
RTC_DCHECK( state_ == pConnecting );
|
||||||
|
|
||||||
// Fianlly, data-channel has been opened.
|
// Fianlly, data-channel has been opened.
|
||||||
state_ = pOpen;
|
state_ = pOpen;
|
||||||
|
@ -271,17 +271,17 @@ void PeerControl::OnPeerOpened() {
|
||||||
control_->OnPeerWritable(local_id_);
|
control_->OnPeerWritable(local_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerControl::OnPeerDisconnected() {
|
void PeerControl::OnPeerDisconnected() {
|
||||||
|
|
||||||
if ( state_ == pClosed ) {
|
if ( state_ == pClosed ) {
|
||||||
LOGP_F( WARNING ) << "Already closed";
|
LOG_F( WARNING ) << "Already closed";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if ( state_ == pClosing ) {
|
else if ( state_ == pClosing ) {
|
||||||
LOGP_F( INFO ) << "Already closing";
|
LOG_F( INFO ) << "Already closing";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ void PeerControl::OnPeerMessage(const webrtc::DataBuffer& buffer) {
|
||||||
|
|
||||||
void PeerControl::OnBufferedAmountChange(const uint64_t previous_amount) {
|
void PeerControl::OnBufferedAmountChange(const uint64_t previous_amount) {
|
||||||
if ( !local_data_channel_->IsWritable() ) {
|
if ( !local_data_channel_->IsWritable() ) {
|
||||||
LOGP_F( LERROR ) << "local_data_channel_ is not writable";
|
LOG_F( LERROR ) << "local_data_channel_ is not writable";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
control_->OnPeerWritable( remote_id_ );
|
control_->OnPeerWritable( remote_id_ );
|
||||||
|
@ -317,19 +317,19 @@ bool PeerControl::CreateDataChannel(
|
||||||
|
|
||||||
data_channel = peer_connection_->CreateDataChannel(label, &init);
|
data_channel = peer_connection_->CreateDataChannel(label, &init);
|
||||||
if (data_channel.get() == nullptr) {
|
if (data_channel.get() == nullptr) {
|
||||||
LOGP_F( LERROR ) << "data_channel is null";
|
LOG_F( LERROR ) << "data_channel is null";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
local_data_channel_.reset(new PeerDataChannelObserver(data_channel));
|
local_data_channel_.reset(new PeerDataChannelObserver(data_channel));
|
||||||
if (local_data_channel_.get() == NULL) {
|
if (local_data_channel_.get() == NULL) {
|
||||||
LOGP_F( LERROR ) << "local_data_channel_ is null";
|
LOG_F( LERROR ) << "local_data_channel_ is null";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Attach(local_data_channel_.get());
|
Attach(local_data_channel_.get());
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,13 +340,13 @@ void PeerControl::AddIceCandidate(const string& sdp_mid, int sdp_mline_index,
|
||||||
webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, candidate, NULL));
|
webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, candidate, NULL));
|
||||||
|
|
||||||
peer_connection_->AddIceCandidate(owned_candidate.get());
|
peer_connection_->AddIceCandidate(owned_candidate.get());
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PeerControl::CreatePeerConnection() {
|
bool PeerControl::CreatePeerConnection() {
|
||||||
ASSERT(peer_connection_factory_.get() != NULL);
|
RTC_DCHECK(peer_connection_factory_.get() != NULL);
|
||||||
ASSERT(peer_connection_.get() == NULL);
|
RTC_DCHECK(peer_connection_.get() == NULL);
|
||||||
|
|
||||||
// Enable DTLS
|
// Enable DTLS
|
||||||
webrtc::FakeConstraints constraints;
|
webrtc::FakeConstraints constraints;
|
||||||
|
@ -362,7 +362,7 @@ bool PeerControl::CreatePeerConnection() {
|
||||||
config, &constraints, NULL, NULL, this);
|
config, &constraints, NULL, NULL, this);
|
||||||
|
|
||||||
if ( peer_connection_.get() == nullptr ) {
|
if ( peer_connection_.get() == nullptr ) {
|
||||||
LOGP_F( LERROR ) << "peer_connection is null";
|
LOG_F( LERROR ) << "peer_connection is null";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,14 +378,14 @@ void PeerControl::DeletePeerConnection() {
|
||||||
peer_connection_ = NULL;
|
peer_connection_ = NULL;
|
||||||
peer_connection_factory_ = NULL;
|
peer_connection_factory_ = NULL;
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerControl::SetLocalDescription(const string& type,
|
void PeerControl::SetLocalDescription(const string& type,
|
||||||
const string& sdp) {
|
const string& sdp) {
|
||||||
|
|
||||||
if ( peer_connection_ == nullptr ) {
|
if ( peer_connection_ == nullptr ) {
|
||||||
LOGP_F( LERROR ) << "peer_connection_ is nullptr";
|
LOG_F( LERROR ) << "peer_connection_ is nullptr";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ void PeerControl::SetLocalDescription(const string& type,
|
||||||
peer_connection_->SetLocalDescription(
|
peer_connection_->SetLocalDescription(
|
||||||
observer, webrtc::CreateSessionDescription(type, sdp, NULL));
|
observer, webrtc::CreateSessionDescription(type, sdp, NULL));
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerControl::SetRemoteDescription(const string& type,
|
void PeerControl::SetRemoteDescription(const string& type,
|
||||||
|
@ -407,12 +407,12 @@ void PeerControl::SetRemoteDescription(const string& type,
|
||||||
peer_connection_->SetRemoteDescription(
|
peer_connection_->SetRemoteDescription(
|
||||||
observer, webrtc::CreateSessionDescription(type, sdp, NULL));
|
observer, webrtc::CreateSessionDescription(type, sdp, NULL));
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerControl::Attach(PeerDataChannelObserver* datachannel) {
|
void PeerControl::Attach(PeerDataChannelObserver* datachannel) {
|
||||||
if (datachannel == nullptr) {
|
if (datachannel == nullptr) {
|
||||||
LOGP_F(WARNING) << "Attach to nullptr";
|
LOG_F(WARNING) << "Attach to nullptr";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,12 +420,12 @@ void PeerControl::Attach(PeerDataChannelObserver* datachannel) {
|
||||||
datachannel->SignalOnDisconnected_.connect(this, &PeerControl::OnPeerDisconnected);
|
datachannel->SignalOnDisconnected_.connect(this, &PeerControl::OnPeerDisconnected);
|
||||||
datachannel->SignalOnMessage_.connect(this, &PeerControl::OnPeerMessage);
|
datachannel->SignalOnMessage_.connect(this, &PeerControl::OnPeerMessage);
|
||||||
datachannel->SignalOnBufferedAmountChange_.connect(this, &PeerControl::OnBufferedAmountChange);
|
datachannel->SignalOnBufferedAmountChange_.connect(this, &PeerControl::OnBufferedAmountChange);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerControl::Detach(PeerDataChannelObserver* datachannel) {
|
void PeerControl::Detach(PeerDataChannelObserver* datachannel) {
|
||||||
if (datachannel == nullptr) {
|
if (datachannel == nullptr) {
|
||||||
LOGP_F(WARNING) << "Detach from nullptr";
|
LOG_F(WARNING) << "Detach from nullptr";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,7 +433,7 @@ void PeerControl::Detach(PeerDataChannelObserver* datachannel) {
|
||||||
datachannel->SignalOnDisconnected_.disconnect(this);
|
datachannel->SignalOnDisconnected_.disconnect(this);
|
||||||
datachannel->SignalOnMessage_.disconnect(this);
|
datachannel->SignalOnMessage_.disconnect(this);
|
||||||
datachannel->SignalOnBufferedAmountChange_.disconnect(this);
|
datachannel->SignalOnBufferedAmountChange_.disconnect(this);
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -446,14 +446,14 @@ PeerDataChannelObserver::PeerDataChannelObserver(webrtc::DataChannelInterface* c
|
||||||
: channel_(channel) {
|
: channel_(channel) {
|
||||||
channel_->RegisterObserver(this);
|
channel_->RegisterObserver(this);
|
||||||
state_ = channel_->state();
|
state_ = channel_->state();
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerDataChannelObserver::~PeerDataChannelObserver() {
|
PeerDataChannelObserver::~PeerDataChannelObserver() {
|
||||||
channel_->Close();
|
channel_->Close();
|
||||||
state_ = channel_->state();
|
state_ = channel_->state();
|
||||||
channel_->UnregisterObserver();
|
channel_->UnregisterObserver();
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerDataChannelObserver::OnBufferedAmountChange(uint64_t previous_amount) {
|
void PeerDataChannelObserver::OnBufferedAmountChange(uint64_t previous_amount) {
|
||||||
|
@ -470,11 +470,11 @@ void PeerDataChannelObserver::OnBufferedAmountChange(uint64_t previous_amount) {
|
||||||
void PeerDataChannelObserver::OnStateChange() {
|
void PeerDataChannelObserver::OnStateChange() {
|
||||||
state_ = channel_->state();
|
state_ = channel_->state();
|
||||||
if (state_ == webrtc::DataChannelInterface::DataState::kOpen) {
|
if (state_ == webrtc::DataChannelInterface::DataState::kOpen) {
|
||||||
LOGP_F( INFO ) << "Data channel internal state is kOpen";
|
LOG_F( INFO ) << "Data channel internal state is kOpen";
|
||||||
SignalOnOpen_();
|
SignalOnOpen_();
|
||||||
}
|
}
|
||||||
else if (state_ == webrtc::DataChannelInterface::DataState::kClosed) {
|
else if (state_ == webrtc::DataChannelInterface::DataState::kClosed) {
|
||||||
LOGP_F( INFO ) << "Data channel internal state is kClosed";
|
LOG_F( INFO ) << "Data channel internal state is kClosed";
|
||||||
SignalOnDisconnected_();
|
SignalOnDisconnected_();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -488,7 +488,7 @@ bool PeerDataChannelObserver::Send(const char* buffer, const size_t size) {
|
||||||
webrtc::DataBuffer databuffer(rtcbuffer, true);
|
webrtc::DataBuffer databuffer(rtcbuffer, true);
|
||||||
|
|
||||||
if ( channel_->buffered_amount() >= max_buffer_size_ ) {
|
if ( channel_->buffered_amount() >= max_buffer_size_ ) {
|
||||||
LOGP_F( LERROR ) << "Buffer is full";
|
LOG_F( LERROR ) << "Buffer is full";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,7 +504,7 @@ bool PeerDataChannelObserver::SyncSend(const char* buffer, const size_t size) {
|
||||||
|
|
||||||
if (!send_cv_.wait_for(lock, std::chrono::milliseconds(60*1000),
|
if (!send_cv_.wait_for(lock, std::chrono::milliseconds(60*1000),
|
||||||
[this] () { return channel_->buffered_amount() == 0; })) {
|
[this] () { return channel_->buffered_amount() == 0; })) {
|
||||||
LOGP_F( LERROR ) << "Buffer is full";
|
LOG_F( LERROR ) << "Buffer is full";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,7 +512,7 @@ bool PeerDataChannelObserver::SyncSend(const char* buffer, const size_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerDataChannelObserver::Close() {
|
void PeerDataChannelObserver::Close() {
|
||||||
LOGP_F(LS_INFO) << "Closing data channel";
|
LOG_F(LS_INFO) << "Closing data channel";
|
||||||
if (channel_->state() != webrtc::DataChannelInterface::kClosing) {
|
if (channel_->state() != webrtc::DataChannelInterface::kClosing) {
|
||||||
channel_->Close();
|
channel_->Close();
|
||||||
}
|
}
|
||||||
|
@ -529,17 +529,17 @@ uint64_t PeerDataChannelObserver::BufferedAmount() {
|
||||||
|
|
||||||
bool PeerDataChannelObserver::IsWritable() {
|
bool PeerDataChannelObserver::IsWritable() {
|
||||||
if ( channel_ == nullptr ) {
|
if ( channel_ == nullptr ) {
|
||||||
LOGP_F( LERROR ) << "channel_ is null";
|
LOG_F( LERROR ) << "channel_ is null";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !IsOpen() ) {
|
if ( !IsOpen() ) {
|
||||||
LOGP_F( LERROR ) << "data channel is not opened";
|
LOG_F( LERROR ) << "data channel is not opened";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( channel_->buffered_amount() > 0 ) {
|
if ( channel_->buffered_amount() > 0 ) {
|
||||||
LOGP_F( LERROR ) << "buffer is full";
|
LOG_F( LERROR ) << "buffer is full";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,9 +94,9 @@ public:
|
||||||
//
|
//
|
||||||
|
|
||||||
void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) override;
|
void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) override;
|
||||||
void OnAddStream(webrtc::MediaStreamInterface* stream) override {};
|
void OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override {};
|
||||||
void OnRemoveStream(webrtc::MediaStreamInterface* stream) override {}
|
void OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override {}
|
||||||
void OnDataChannel(webrtc::DataChannelInterface* channel) override;
|
void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> channel) override;
|
||||||
void OnRenegotiationNeeded() override {}
|
void OnRenegotiationNeeded() override {}
|
||||||
void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
|
void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
|
||||||
void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
|
void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
|
||||||
|
|
|
@ -35,28 +35,28 @@ PeerConnect::PeerConnect( const string peer ) {
|
||||||
peer_ = local_peer;
|
peer_ = local_peer;
|
||||||
close_once_ = false;
|
close_once_ = false;
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerConnect::~PeerConnect() {
|
PeerConnect::~PeerConnect() {
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerConnect::Run() {
|
void PeerConnect::Run() {
|
||||||
rtc::ThreadManager::Instance()->CurrentThread()->Run();
|
rtc::ThreadManager::Instance()->CurrentThread()->Run();
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerConnect::Stop() {
|
void PeerConnect::Stop() {
|
||||||
rtc::ThreadManager::Instance()->CurrentThread()->Quit();
|
rtc::ThreadManager::Instance()->CurrentThread()->Quit();
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PeerConnect::Open() {
|
void PeerConnect::Open() {
|
||||||
|
|
||||||
if ( control_.get() != nullptr ) {
|
if ( control_.get() != nullptr ) {
|
||||||
LOGP_F( WARNING ) << "Already open.";
|
LOG_F( WARNING ) << "Already open.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ void PeerConnect::Open() {
|
||||||
control_->RegisterObserver( this, control_ );
|
control_->RegisterObserver( this, control_ );
|
||||||
|
|
||||||
if ( control_.get() == NULL ) {
|
if ( control_.get() == NULL ) {
|
||||||
LOGP_F( LERROR ) << "Failed to create class Control.";
|
LOG_F( LERROR ) << "Failed to create class Control.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ void PeerConnect::Open() {
|
||||||
//
|
//
|
||||||
|
|
||||||
if ( !control_->InitializeControl() ) {
|
if ( !control_->InitializeControl() ) {
|
||||||
LOGP_F( LERROR ) << "Failed to initialize Control.";
|
LOG_F( LERROR ) << "Failed to initialize Control.";
|
||||||
control_.reset();
|
control_.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ void PeerConnect::Open() {
|
||||||
//
|
//
|
||||||
|
|
||||||
control_->Open( setting_.signal_id_, setting_.signal_password_, peer_ );
|
control_->Open( setting_.signal_id_, setting_.signal_password_, peer_ );
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,12 +108,12 @@ void PeerConnect::Close( const string peer ) {
|
||||||
else {
|
else {
|
||||||
control_->ClosePeer( peer, CLOSE_NORMAL, FORCE_QUEUING_ON );
|
control_->ClosePeer( peer, CLOSE_NORMAL, FORCE_QUEUING_ON );
|
||||||
}
|
}
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerConnect::Connect( const string peer ) {
|
void PeerConnect::Connect( const string peer ) {
|
||||||
control_->Connect( peer );
|
control_->Connect( peer );
|
||||||
LOGP_F( INFO ) << "Done, peer is " << peer;
|
LOG_F( INFO ) << "Done, peer is " << peer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,10 +171,10 @@ PeerConnect& PeerConnect::On( string event_id, std::function<void( string )> han
|
||||||
if ( event_id == "open" || event_id == "connect" || event_id == "writable" ) {
|
if ( event_id == "open" || event_id == "connect" || event_id == "writable" ) {
|
||||||
std::unique_ptr<EventHandler_2> f( new EventHandler_2( handler ) );
|
std::unique_ptr<EventHandler_2> f( new EventHandler_2( handler ) );
|
||||||
event_handler_.insert( Events::value_type( event_id, std::move( f ) ) );
|
event_handler_.insert( Events::value_type( event_id, std::move( f ) ) );
|
||||||
LOGP_F( INFO ) << "An event handler '" << event_id << "' has been inserted";
|
LOG_F( INFO ) << "An event handler '" << event_id << "' has been inserted";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOGP_F( LERROR ) << "Unsupported event type: " << event_id;
|
LOG_F( LERROR ) << "Unsupported event type: " << event_id;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ PeerConnect& PeerConnect::On( string event_id, std::function<void( string, strin
|
||||||
|
|
||||||
if ( event_id.empty() ) return *this;
|
if ( event_id.empty() ) return *this;
|
||||||
|
|
||||||
LOGP_F( LERROR ) << "Unsupported event type: " << event_id;
|
LOG_F( LERROR ) << "Unsupported event type: " << event_id;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,10 +194,10 @@ PeerConnect& PeerConnect::On( string event_id, std::function<void( string, pc::C
|
||||||
std::unique_ptr<EventHandler_Close> f( new EventHandler_Close( handler ) );
|
std::unique_ptr<EventHandler_Close> f( new EventHandler_Close( handler ) );
|
||||||
event_handler_.insert( Events::value_type( event_id, std::move( f ) ) );
|
event_handler_.insert( Events::value_type( event_id, std::move( f ) ) );
|
||||||
|
|
||||||
LOGP_F( INFO ) << "An event handler '" << event_id << "' has been inserted";
|
LOG_F( INFO ) << "An event handler '" << event_id << "' has been inserted";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOGP_F( LERROR ) << "Unsupported event type: " << event_id;
|
LOG_F( LERROR ) << "Unsupported event type: " << event_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -210,10 +210,10 @@ PeerConnect& PeerConnect::On( string event_id, std::function<void( string, char*
|
||||||
std::unique_ptr<EventHandler_Message> f( new EventHandler_Message( handler ) );
|
std::unique_ptr<EventHandler_Message> f( new EventHandler_Message( handler ) );
|
||||||
event_handler_.insert( Events::value_type( event_id, std::move( f ) ) );
|
event_handler_.insert( Events::value_type( event_id, std::move( f ) ) );
|
||||||
|
|
||||||
LOGP_F( INFO ) << "An event handler '" << event_id << "' has been inserted";
|
LOG_F( INFO ) << "An event handler '" << event_id << "' has been inserted";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOGP_F( LERROR ) << "Unsupported event type: " << event_id;
|
LOG_F( LERROR ) << "Unsupported event type: " << event_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -230,7 +230,7 @@ void PeerConnect::OnOpen( const string peer ) {
|
||||||
CallEventHandler( "open", peer );
|
CallEventHandler( "open", peer );
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerConnect::OnClose( const string peer, const CloseCode code, const string desc ) {
|
void PeerConnect::OnClose( const string peer, const CloseCode code, const string desc ) {
|
||||||
|
@ -238,7 +238,7 @@ void PeerConnect::OnClose( const string peer, const CloseCode code, const string
|
||||||
// This instance of PeerConnect and local peer is going to be closed
|
// This instance of PeerConnect and local peer is going to be closed
|
||||||
if ( peer == peer_ ) {
|
if ( peer == peer_ ) {
|
||||||
if ( close_once_ ) {
|
if ( close_once_ ) {
|
||||||
LOGP_F( WARNING ) << "close_ is false, peer is " << peer;
|
LOG_F( WARNING ) << "close_ is false, peer is " << peer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ void PeerConnect::OnClose( const string peer, const CloseCode code, const string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done, peer is " << peer;
|
LOG_F( INFO ) << "Done, peer is " << peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerConnect::OnConnect( const string peer ) {
|
void PeerConnect::OnConnect( const string peer ) {
|
||||||
|
@ -266,7 +266,7 @@ void PeerConnect::OnConnect( const string peer ) {
|
||||||
CallEventHandler( "connect", peer );
|
CallEventHandler( "connect", peer );
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done, peer is " << peer;
|
LOG_F( INFO ) << "Done, peer is " << peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerConnect::OnMessage( const string peer, const char* data, const size_t size ) {
|
void PeerConnect::OnMessage( const string peer, const char* data, const size_t size ) {
|
||||||
|
@ -280,7 +280,7 @@ void PeerConnect::OnWritable( const string peer ) {
|
||||||
CallEventHandler( "writable", peer );
|
CallEventHandler( "writable", peer );
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done, peer is " << peer;
|
LOG_F( INFO ) << "Done, peer is " << peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ bool PeerConnect::ParseOptions( const string& options ) {
|
||||||
string value;
|
string value;
|
||||||
|
|
||||||
if ( !reader.parse( options, joptions ) ) {
|
if ( !reader.parse( options, joptions ) ) {
|
||||||
LOGP_F( WARNING ) << "Invalid setting: " << options;
|
LOG_F( WARNING ) << "Invalid setting: " << options;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2016 The PeerConnect Project Authors. All rights reserved.
|
* Copyright 2016 The PeerConnect Project Authors. All rights reserved.
|
||||||
*
|
*
|
||||||
* Ryan Lee
|
* Ryan Lee
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(WEBRTC_WIN)
|
#if defined(WEBRTC_WIN)
|
||||||
#pragma warning(disable:4503)
|
#pragma warning(disable:4503)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "signalconnection.h"
|
#include "signalconnection.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
namespace pc {
|
namespace pc {
|
||||||
|
|
||||||
Signal::Signal(const string url) :
|
Signal::Signal(const string url) :
|
||||||
con_state_(con_closed),
|
con_state_(con_closed),
|
||||||
network_thread_(),
|
network_thread_(),
|
||||||
reconn_attempts_(3),
|
reconn_attempts_(3),
|
||||||
reconn_made_(0),
|
reconn_made_(0),
|
||||||
reconn_delay_(5000),
|
reconn_delay_(5000),
|
||||||
reconn_delay_max_(25000),
|
reconn_delay_max_(25000),
|
||||||
url_(url) {
|
url_(url) {
|
||||||
|
|
||||||
#if _DEBUG || DEBUG
|
#if _DEBUG || DEBUG
|
||||||
client_.clear_access_channels(websocketpp::log::alevel::all);
|
client_.clear_access_channels(websocketpp::log::alevel::all);
|
||||||
|
@ -32,10 +32,10 @@ Signal::Signal(const string url) :
|
||||||
client_.clear_error_channels(websocketpp::log::alevel::all);
|
client_.clear_error_channels(websocketpp::log::alevel::all);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Default settings
|
// Default settings
|
||||||
if (url_.empty()) {
|
if (url_.empty()) {
|
||||||
url_ = "wss://signal.peers.io/hello";
|
url_ = "wss://signal.peers.io/hello";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize ASIO
|
// Initialize ASIO
|
||||||
client_.init_asio();
|
client_.init_asio();
|
||||||
|
@ -51,27 +51,27 @@ Signal::Signal(const string url) :
|
||||||
client_.set_message_handler(bind(&Signal::OnMessage, this, _1, _2));
|
client_.set_message_handler(bind(&Signal::OnMessage, this, _1, _2));
|
||||||
client_.set_tls_init_handler(bind(&Signal::OnTlsInit, this, _1));
|
client_.set_tls_init_handler(bind(&Signal::OnTlsInit, this, _1));
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
Signal::~Signal() {
|
|
||||||
Teardown();
|
|
||||||
LOGP_F( INFO ) << "Done";
|
|
||||||
}
|
|
||||||
|
|
||||||
void Signal::Open(const string& id, const string& password) {
|
|
||||||
user_id_ = id;
|
|
||||||
user_password_ = password;
|
|
||||||
Connect();
|
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
Signal::~Signal() {
|
||||||
}
|
Teardown();
|
||||||
|
LOG_F( INFO ) << "Done";
|
||||||
void Signal::Close() {
|
}
|
||||||
|
|
||||||
if ( !opened() ) {
|
void Signal::Open(const string& id, const string& password) {
|
||||||
LOGP_F( WARNING ) << "It is not opened";
|
user_id_ = id;
|
||||||
return;
|
user_password_ = password;
|
||||||
|
Connect();
|
||||||
|
|
||||||
|
LOG_F( INFO ) << "Done";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Signal::Close() {
|
||||||
|
|
||||||
|
if ( !opened() ) {
|
||||||
|
LOG_F( WARNING ) << "It is not opened";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
con_state_ = con_closing;
|
con_state_ = con_closing;
|
||||||
|
@ -79,14 +79,14 @@ void Signal::Close() {
|
||||||
this,
|
this,
|
||||||
websocketpp::close::status::normal,
|
websocketpp::close::status::normal,
|
||||||
"End by user"));
|
"End by user"));
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Signal::SyncClose()
|
void Signal::SyncClose()
|
||||||
{
|
{
|
||||||
if ( !opened() ) {
|
if ( !opened() ) {
|
||||||
LOGP_F( WARNING ) << "It is not opened";
|
LOG_F( WARNING ) << "It is not opened";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,53 +102,53 @@ void Signal::SyncClose()
|
||||||
network_thread_.reset();
|
network_thread_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Signal::SendCommand(const string channel,
|
void Signal::SendCommand(const string channel,
|
||||||
const string commandname,
|
const string commandname,
|
||||||
const Json::Value& data) {
|
const Json::Value& data) {
|
||||||
|
|
||||||
if (commandname.empty()) {
|
if (commandname.empty()) {
|
||||||
LOGP_F(WARNING) << "SendCommand with empty commandname";
|
LOG_F(WARNING) << "SendCommand with empty commandname";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opened()) {
|
if (!opened()) {
|
||||||
LOGP_F(WARNING) << "Signal server is not opened";
|
LOG_F(WARNING) << "Signal server is not opened";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value message;
|
Json::Value message;
|
||||||
Json::FastWriter writer;
|
Json::FastWriter writer;
|
||||||
message["command"] = commandname;
|
message["command"] = commandname;
|
||||||
message["data"] = data;
|
message["data"] = data;
|
||||||
if (!channel.empty()) message["channel"] = channel;
|
if (!channel.empty()) message["channel"] = channel;
|
||||||
|
|
||||||
LOGP_F( LS_VERBOSE ) << "message is " << message.toStyledString();
|
LOG_F( LS_VERBOSE ) << "message is " << message.toStyledString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client_.send(con_hdl_, writer.write(message), websocketpp::frame::opcode::text);
|
client_.send(con_hdl_, writer.write(message), websocketpp::frame::opcode::text);
|
||||||
}
|
}
|
||||||
catch (websocketpp::lib::error_code& ec) {
|
catch (websocketpp::lib::error_code& ec) {
|
||||||
LOGP_F(LERROR) << "SendCommand Error: " << ec;
|
LOG_F(LERROR) << "SendCommand Error: " << ec;
|
||||||
}
|
}
|
||||||
catch (std::exception& e) {
|
catch (std::exception& e) {
|
||||||
LOGP_F(LERROR) << "SendCommand Error: " << e.what();
|
LOG_F(LERROR) << "SendCommand Error: " << e.what();
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
LOGP_F(LERROR) << "SendCommand Error: ";
|
LOG_F(LERROR) << "SendCommand Error: ";
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Signal::SendGlobalCommand(const string commandname,
|
void Signal::SendGlobalCommand(const string commandname,
|
||||||
const Json::Value& data) {
|
const Json::Value& data) {
|
||||||
SendCommand("", commandname, data);
|
SendCommand("", commandname, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Signal::Connect()
|
void Signal::Connect()
|
||||||
{
|
{
|
||||||
if (reconn_timer_)
|
if (reconn_timer_)
|
||||||
|
@ -180,9 +180,9 @@ void Signal::Connect()
|
||||||
this->ResetState();
|
this->ResetState();
|
||||||
client_.get_io_service().dispatch(websocketpp::lib::bind(&Signal::ConnectInternal, this));
|
client_.get_io_service().dispatch(websocketpp::lib::bind(&Signal::ConnectInternal, this));
|
||||||
network_thread_.reset(new websocketpp::lib::thread(websocketpp::lib::bind(&Signal::RunLoop, this)));
|
network_thread_.reset(new websocketpp::lib::thread(websocketpp::lib::bind(&Signal::RunLoop, this)));
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Signal::Teardown()
|
void Signal::Teardown()
|
||||||
{
|
{
|
||||||
|
@ -190,17 +190,17 @@ void Signal::Teardown()
|
||||||
network_thread_->detach();
|
network_thread_->detach();
|
||||||
network_thread_.reset();
|
network_thread_.reset();
|
||||||
}
|
}
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
asio::io_service& Signal::GetIoService()
|
asio::io_service& Signal::GetIoService()
|
||||||
{
|
{
|
||||||
return client_.get_io_service();
|
return client_.get_io_service();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Signal::SendOpenCommand() {
|
void Signal::SendOpenCommand() {
|
||||||
Json::Value data;
|
Json::Value data;
|
||||||
|
|
||||||
|
@ -209,19 +209,19 @@ void Signal::SendOpenCommand() {
|
||||||
|
|
||||||
SendGlobalCommand("open", data);
|
SendGlobalCommand("open", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Signal::OnCommandReceived(Json::Value& message) {
|
void Signal::OnCommandReceived(Json::Value& message) {
|
||||||
SignalOnCommandReceived_(message);
|
SignalOnCommandReceived_(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Signal::RunLoop()
|
void Signal::RunLoop()
|
||||||
{
|
{
|
||||||
client_.run();
|
client_.run();
|
||||||
client_.reset();
|
client_.reset();
|
||||||
client_.get_alog().write(websocketpp::log::alevel::devel,
|
client_.get_alog().write(websocketpp::log::alevel::devel,
|
||||||
"run loop end");
|
"run loop end");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Signal::ConnectInternal()
|
void Signal::ConnectInternal()
|
||||||
{
|
{
|
||||||
|
@ -235,13 +235,13 @@ void Signal::ConnectInternal()
|
||||||
|
|
||||||
client_.connect(con);
|
client_.connect(con);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Signal::CloseInternal(websocketpp::close::status::value const& code, string const& desc)
|
void Signal::CloseInternal(websocketpp::close::status::value const& code, string const& desc)
|
||||||
{
|
{
|
||||||
LOGP_F(WARNING) << "Close by reason:" << desc;
|
LOG_F(WARNING) << "Close by reason:" << desc;
|
||||||
|
|
||||||
if (reconn_timer_)
|
if (reconn_timer_)
|
||||||
{
|
{
|
||||||
|
@ -250,7 +250,7 @@ void Signal::CloseInternal(websocketpp::close::status::value const& code, string
|
||||||
}
|
}
|
||||||
if (con_hdl_.expired())
|
if (con_hdl_.expired())
|
||||||
{
|
{
|
||||||
LOGP_F(LERROR) << "Error: No active session";
|
LOG_F(LERROR) << "Error: No active session";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -258,7 +258,7 @@ void Signal::CloseInternal(websocketpp::close::status::value const& code, string
|
||||||
client_.close(con_hdl_, code, desc, ec);
|
client_.close(con_hdl_, code, desc, ec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Signal::TimeoutReconnect(websocketpp::lib::asio::error_code const& ec)
|
void Signal::TimeoutReconnect(websocketpp::lib::asio::error_code const& ec)
|
||||||
{
|
{
|
||||||
if (ec)
|
if (ec)
|
||||||
|
@ -271,29 +271,29 @@ void Signal::TimeoutReconnect(websocketpp::lib::asio::error_code const& ec)
|
||||||
con_state_ = con_opening;
|
con_state_ = con_opening;
|
||||||
reconn_made_++;
|
reconn_made_++;
|
||||||
this->ResetState();
|
this->ResetState();
|
||||||
LOGP_F(WARNING) << "Reconnecting..";
|
LOG_F(WARNING) << "Reconnecting..";
|
||||||
client_.get_io_service().dispatch(websocketpp::lib::bind(&Signal::ConnectInternal, this));
|
client_.get_io_service().dispatch(websocketpp::lib::bind(&Signal::ConnectInternal, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Signal::NextDelay() const
|
unsigned Signal::NextDelay() const
|
||||||
{
|
{
|
||||||
//no jitter, fixed power root.
|
//no jitter, fixed power root.
|
||||||
unsigned reconn_made = std::min<unsigned>(reconn_made_, 32);//protect the pow result to be too big.
|
unsigned reconn_made = std::min<unsigned>(reconn_made_, 32);//protect the pow result to be too big.
|
||||||
return static_cast<unsigned>(std::min<double>(reconn_delay_ * pow(1.5, reconn_made), reconn_delay_max_));
|
return static_cast<unsigned>(std::min<double>(reconn_delay_ * pow(1.5, reconn_made), reconn_delay_max_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Signal::OnOpen(websocketpp::connection_hdl con)
|
void Signal::OnOpen(websocketpp::connection_hdl con)
|
||||||
{
|
{
|
||||||
LOGP_F(WARNING) << "Connected.";
|
LOG_F(WARNING) << "Connected.";
|
||||||
con_state_ = con_opened;
|
con_state_ = con_opened;
|
||||||
con_hdl_ = con;
|
con_hdl_ = con;
|
||||||
reconn_made_ = 0;
|
reconn_made_ = 0;
|
||||||
|
|
||||||
SendOpenCommand();
|
SendOpenCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Signal::OnClose(websocketpp::connection_hdl con)
|
void Signal::OnClose(websocketpp::connection_hdl con)
|
||||||
{
|
{
|
||||||
|
@ -307,7 +307,7 @@ void Signal::OnClose(websocketpp::connection_hdl con)
|
||||||
websocketpp::close::status::value code = websocketpp::close::status::normal;
|
websocketpp::close::status::value code = websocketpp::close::status::normal;
|
||||||
client_type::connection_ptr conn_ptr = client_.get_con_from_hdl(con, ec);
|
client_type::connection_ptr conn_ptr = client_.get_con_from_hdl(con, ec);
|
||||||
if (ec) {
|
if (ec) {
|
||||||
LOGP_F(LERROR) << "get conn failed" << ec;
|
LOG_F(LERROR) << "get conn failed" << ec;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
code = conn_ptr->get_local_close_code();
|
code = conn_ptr->get_local_close_code();
|
||||||
|
@ -328,7 +328,7 @@ void Signal::OnClose(websocketpp::connection_hdl con)
|
||||||
|
|
||||||
//if (reconn_made_<reconn_attempts_)
|
//if (reconn_made_<reconn_attempts_)
|
||||||
//{
|
//{
|
||||||
// LOGP_F(LS_WARNING) << "Reconnect for attempt:" << reconn_made_;
|
// LOG_F(LS_WARNING) << "Reconnect for attempt:" << reconn_made_;
|
||||||
// unsigned delay = this->NextDelay();
|
// unsigned delay = this->NextDelay();
|
||||||
// reconn_timer_.reset(new websocketpp::lib::asio::steady_timer(client_.get_io_service()));
|
// reconn_timer_.reset(new websocketpp::lib::asio::steady_timer(client_.get_io_service()));
|
||||||
// websocketpp::lib::asio::error_code ec;
|
// websocketpp::lib::asio::error_code ec;
|
||||||
|
@ -340,10 +340,10 @@ void Signal::OnClose(websocketpp::connection_hdl con)
|
||||||
SignalOnClosed_(code);
|
SignalOnClosed_(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( INFO ) << "Done";
|
LOG_F( INFO ) << "Done";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Signal::OnFail(websocketpp::connection_hdl con)
|
void Signal::OnFail(websocketpp::connection_hdl con)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
@ -355,7 +355,7 @@ void Signal::OnFail(websocketpp::connection_hdl con)
|
||||||
websocketpp::close::status::value code = websocketpp::close::status::abnormal_close;
|
websocketpp::close::status::value code = websocketpp::close::status::abnormal_close;
|
||||||
client_type::connection_ptr conn_ptr = client_.get_con_from_hdl(con, ec);
|
client_type::connection_ptr conn_ptr = client_.get_con_from_hdl(con, ec);
|
||||||
if (ec) {
|
if (ec) {
|
||||||
LOGP_F(LERROR) << "get conn failed" << ec;
|
LOG_F(LERROR) << "get conn failed" << ec;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
code = conn_ptr->get_local_close_code();
|
code = conn_ptr->get_local_close_code();
|
||||||
|
@ -364,11 +364,11 @@ void Signal::OnFail(websocketpp::connection_hdl con)
|
||||||
con_hdl_.reset();
|
con_hdl_.reset();
|
||||||
con_state_ = con_closed;
|
con_state_ = con_closed;
|
||||||
|
|
||||||
LOGP_F(LERROR) << "Connection failed.";
|
LOG_F(LERROR) << "Connection failed.";
|
||||||
|
|
||||||
if (reconn_made_<reconn_attempts_)
|
if (reconn_made_<reconn_attempts_)
|
||||||
{
|
{
|
||||||
LOGP_F(WARNING) << "Reconnect for attempt:" << reconn_made_;
|
LOG_F(WARNING) << "Reconnect for attempt:" << reconn_made_;
|
||||||
unsigned delay = this->NextDelay();
|
unsigned delay = this->NextDelay();
|
||||||
reconn_timer_.reset(new asio::steady_timer(client_.get_io_service()));
|
reconn_timer_.reset(new asio::steady_timer(client_.get_io_service()));
|
||||||
websocketpp::lib::asio::error_code ec;
|
websocketpp::lib::asio::error_code ec;
|
||||||
|
@ -379,19 +379,19 @@ void Signal::OnFail(websocketpp::connection_hdl con)
|
||||||
SignalOnClosed_(code);
|
SignalOnClosed_(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Signal::OnMessage(websocketpp::connection_hdl con, client_type::message_ptr msg)
|
void Signal::OnMessage(websocketpp::connection_hdl con, client_type::message_ptr msg)
|
||||||
{
|
{
|
||||||
Json::Reader reader;
|
Json::Reader reader;
|
||||||
Json::Value jmessage;
|
Json::Value jmessage;
|
||||||
|
|
||||||
if (!reader.parse(msg->get_payload(), jmessage)) {
|
if (!reader.parse(msg->get_payload(), jmessage)) {
|
||||||
LOGP_F(WARNING) << "Received unknown message: " << msg->get_payload();
|
LOG_F(WARNING) << "Received unknown message: " << msg->get_payload();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP_F( LS_VERBOSE ) << jmessage.toStyledString();
|
LOG_F( LS_VERBOSE ) << jmessage.toStyledString();
|
||||||
OnCommandReceived(jmessage);
|
OnCommandReceived(jmessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,11 +410,11 @@ Signal::context_ptr Signal::OnTlsInit(websocketpp::connection_hdl conn)
|
||||||
asio::ssl::context::single_dh_use, ec);
|
asio::ssl::context::single_dh_use, ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOGP_F(LERROR) << "Init tls failed,reason:" << ec.message();
|
LOG_F(LERROR) << "Init tls failed,reason:" << ec.message();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace pc
|
} // namespace pc
|
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2016 The PeerConnect Project Authors. All rights reserved.
|
* Copyright 2016 The PeerConnect Project Authors. All rights reserved.
|
||||||
*
|
*
|
||||||
* Ryan Lee
|
* Ryan Lee
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Reference: socket.io-client-cpp
|
Reference: socket.io-client-cpp
|
||||||
|
|
||||||
Copyright (c) 2015, Melo Yao
|
Copyright (c) 2015, Melo Yao
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
|
@ -26,62 +26,62 @@
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __PEERCONNECT_SIGNAL_H__
|
#ifndef __PEERCONNECT_SIGNAL_H__
|
||||||
#define __PEERCONNECT_SIGNAL_H__
|
#define __PEERCONNECT_SIGNAL_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#if _DEBUG || DEBUG
|
#if _DEBUG || DEBUG
|
||||||
#include <websocketpp/config/debug_asio.hpp>
|
#include <websocketpp/config/debug_asio.hpp>
|
||||||
#else
|
#else
|
||||||
#include <websocketpp/config/asio_client.hpp>
|
#include <websocketpp/config/asio_client.hpp>
|
||||||
#endif //DEBUG
|
#endif //DEBUG
|
||||||
|
|
||||||
#include "websocketpp/client.hpp"
|
#include "websocketpp/client.hpp"
|
||||||
#include "websocketpp/common/thread.hpp"
|
#include "websocketpp/common/thread.hpp"
|
||||||
|
|
||||||
#include "webrtc/base/sigslot.h"
|
#include "webrtc/base/sigslot.h"
|
||||||
#include "webrtc/base/json.h"
|
#include "webrtc/base/json.h"
|
||||||
|
|
||||||
|
|
||||||
namespace pc {
|
namespace pc {
|
||||||
|
|
||||||
class SignalInterface {
|
class SignalInterface {
|
||||||
public:
|
public:
|
||||||
virtual void Open(const std::string& id, const std::string& password) = 0;
|
virtual void Open(const std::string& id, const std::string& password) = 0;
|
||||||
virtual void Close() = 0;
|
virtual void Close() = 0;
|
||||||
|
|
||||||
virtual void SendCommand(const std::string id,
|
virtual void SendCommand(const std::string id,
|
||||||
const std::string commandname,
|
const std::string commandname,
|
||||||
const Json::Value& data) = 0;
|
const Json::Value& data) = 0;
|
||||||
virtual void SendGlobalCommand(const std::string commandname,
|
virtual void SendGlobalCommand(const std::string commandname,
|
||||||
const Json::Value& data) = 0;
|
const Json::Value& data) = 0;
|
||||||
std::string session_id() { return session_id_; }
|
std::string session_id() { return session_id_; }
|
||||||
|
|
||||||
// sigslots
|
// sigslots
|
||||||
sigslot::signal1<const Json::Value&> SignalOnCommandReceived_;
|
sigslot::signal1<const Json::Value&> SignalOnCommandReceived_;
|
||||||
sigslot::signal1<const websocketpp::close::status::value> SignalOnClosed_;
|
sigslot::signal1<const websocketpp::close::status::value> SignalOnClosed_;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string session_id_;
|
std::string session_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Signal
|
class Signal
|
||||||
: public SignalInterface {
|
: public SignalInterface {
|
||||||
public:
|
public:
|
||||||
enum con_state
|
enum con_state
|
||||||
{
|
{
|
||||||
con_opening,
|
con_opening,
|
||||||
con_opened,
|
con_opened,
|
||||||
con_closing,
|
con_closing,
|
||||||
con_closed
|
con_closed
|
||||||
};
|
};
|
||||||
|
|
||||||
using string = std::string;
|
using string = std::string;
|
||||||
|
|
||||||
|
@ -89,22 +89,22 @@ public:
|
||||||
typedef websocketpp::config::debug_asio_tls client_config;
|
typedef websocketpp::config::debug_asio_tls client_config;
|
||||||
#else
|
#else
|
||||||
typedef websocketpp::config::asio_tls_client client_config;
|
typedef websocketpp::config::asio_tls_client client_config;
|
||||||
#endif //DEBUG
|
#endif //DEBUG
|
||||||
typedef websocketpp::client<client_config> client_type;
|
typedef websocketpp::client<client_config> client_type;
|
||||||
|
|
||||||
Signal(const string url);
|
Signal(const string url);
|
||||||
~Signal();
|
~Signal();
|
||||||
|
|
||||||
void Open(const string& id, const string& password);
|
void Open(const string& id, const string& password);
|
||||||
void Close();
|
void Close();
|
||||||
void SyncClose();
|
void SyncClose();
|
||||||
|
|
||||||
void SendCommand(const string channel,
|
void SendCommand(const string channel,
|
||||||
const string commandname,
|
const string commandname,
|
||||||
const Json::Value& data);
|
const Json::Value& data);
|
||||||
void SendGlobalCommand(const string commandname,
|
void SendGlobalCommand(const string commandname,
|
||||||
const Json::Value& data);
|
const Json::Value& data);
|
||||||
|
|
||||||
void Teardown();
|
void Teardown();
|
||||||
|
|
||||||
bool opened() const { return con_state_ == con_opened;}
|
bool opened() const { return con_state_ == con_opened;}
|
||||||
|
@ -149,15 +149,15 @@ private:
|
||||||
unsigned reconn_delay_;
|
unsigned reconn_delay_;
|
||||||
unsigned reconn_delay_max_;
|
unsigned reconn_delay_max_;
|
||||||
unsigned reconn_attempts_;
|
unsigned reconn_attempts_;
|
||||||
unsigned reconn_made_;
|
unsigned reconn_made_;
|
||||||
|
|
||||||
// Signal server
|
// Signal server
|
||||||
string url_;
|
string url_;
|
||||||
string user_id_;
|
string user_id_;
|
||||||
string user_password_;
|
string user_password_;
|
||||||
}; // class Signal
|
}; // class Signal
|
||||||
|
|
||||||
|
|
||||||
} // namespace pc
|
} // namespace pc
|
||||||
|
|
||||||
#endif // __PEERCONNECT_SIGNAL_H__
|
#endif // __PEERCONNECT_SIGNAL_H__
|
|
@ -1 +1 @@
|
||||||
branch-heads/55
|
branch-heads/60
|
Loading…
Reference in New Issue