Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ros2 jazzy #72

Draft
wants to merge 3 commits into
base: develop-ros2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion webrtc/build/get_gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ then
git clone https://gn.googlesource.com/gn third_party/gn
cd third_party/gn
git checkout 501b49a3ab4f0d099457b6e5b62c709a1d2311be
CC=gcc CXX=g++ LDFLAGS=-fuse-ld=gold python build/gen.py
CC=gcc CXX=g++ LDFLAGS=-fuse-ld=gold python3 build/gen.py
"$rootdir/depot_tools/ninja" -C out gn
cp out/gn .
fi
Expand Down
9 changes: 6 additions & 3 deletions webrtc_ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find_package(webrtc_ros_msgs REQUIRED)
find_package(webrtc REQUIRED)
find_package(X11 REQUIRED)
find_package(jsoncpp REQUIRED)
find_package(OpenCV REQUIRED)


###########
Expand All @@ -23,7 +24,7 @@ include_directories(
${OpenCV_INCLUDE_DIRS}
${webrtc_ros_msgs_INCLUDE_DIRS}
${webrtc_INCLUDE_DIRS}

)
add_definitions(${webrtc_DEFINITIONS})

Expand Down Expand Up @@ -56,15 +57,17 @@ ament_target_dependencies(
image_transport
rclcpp
std_msgs
webrtc_ros_msgs
webrtc_ros_msgs

)

target_link_libraries(${PROJECT_NAME}_server_node
${webrtc_LIBRARIES}
webrtc
jsoncpp_lib
${X11_LIBRARIES}
${OpenCV_LIBS}
ament_index_cpp::ament_index_cpp
)

set_target_properties(${PROJECT_NAME}_server_node PROPERTIES COMPILE_OPTIONS "-std=c++17")
Expand Down
7 changes: 5 additions & 2 deletions webrtc_ros/include/webrtc_ros/ros_video_capturer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class RosVideoCapturer :
bool remote() const override;

private:
RTC_DISALLOW_COPY_AND_ASSIGN(RosVideoCapturer);
RosVideoCapturer(const RosVideoCapturer&) = delete;
RosVideoCapturer& operator=(const RosVideoCapturer&) = delete;

boost::shared_ptr<RosVideoCapturerImpl> impl_;
};

Expand All @@ -56,7 +58,8 @@ class RosVideoCapturerImpl : public boost::enable_shared_from_this<RosVideoCaptu
void Stop();

private:
RTC_DISALLOW_COPY_AND_ASSIGN(RosVideoCapturerImpl);
RosVideoCapturerImpl(const RosVideoCapturerImpl&) = delete;
RosVideoCapturerImpl& operator=(const RosVideoCapturerImpl&) = delete;

ImageTransportFactory it_;
const std::string topic_, transport_;
Expand Down
3 changes: 2 additions & 1 deletion webrtc_ros/include/webrtc_ros/ros_video_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class RosVideoRenderer :
virtual void OnFrame(const webrtc::VideoFrame& frame) override;

private:
RTC_DISALLOW_COPY_AND_ASSIGN(RosVideoRenderer);
RosVideoRenderer(const RosVideoRenderer&) = delete;
RosVideoRenderer& operator=(const RosVideoRenderer&) = delete;
std::shared_ptr<image_transport::ImageTransport> it_;
const std::string topic_;
image_transport::Publisher pub_;
Expand Down
3 changes: 1 addition & 2 deletions webrtc_ros/src/ros_video_capturer.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "webrtc_ros/ros_video_capturer.h"
#include "webrtc/rtc_base/bind.h"

#include <rclcpp/rclcpp.hpp>
#include <cv_bridge/cv_bridge.h>
#include <cv_bridge/cv_bridge.hpp>
#include <boost/enable_shared_from_this.hpp>

namespace webrtc_ros
Expand Down
2 changes: 1 addition & 1 deletion webrtc_ros/src/ros_video_renderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <webrtc_ros/ros_video_renderer.h>
#include <rclcpp/rclcpp.hpp>
#include <cv_bridge/cv_bridge.h>
#include <cv_bridge/cv_bridge.hpp>
#include <webrtc/3rdparty/libyuv/convert_from.h>

namespace webrtc_ros
Expand Down
21 changes: 9 additions & 12 deletions webrtc_ros/src/webrtc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <webrtc_ros/ice_candidate_message.h>
//#include "talk/media/devices/devicemanager.h"
#include <webrtc/api/video/video_source_interface.h>
#include <webrtc/rtc_base/bind.h>
#include <webrtc_ros/ros_video_capturer.h>
#include <webrtc_ros_msgs/srv/get_ice_servers.hpp>

Expand Down Expand Up @@ -177,8 +176,7 @@ class MessageHandlerImpl : public MessageHandler {
{
WebrtcClientPtr _this = weak_this_.lock();
if (_this)
_this->signaling_thread_->Invoke<void>(RTC_FROM_HERE, rtc::Bind(&WebrtcClient::handle_message,
_this.get(), type, raw));
_this->signaling_thread_->BlockingCall([t = _this.get(), type, raw] { t->handle_message(type, raw); });
}
private:
WebrtcClientWeakPtr weak_this_;
Expand Down Expand Up @@ -285,7 +283,7 @@ void WebrtcClient::handle_message(MessageHandler::Type type, const std::string&

rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = peer_connection_factory_->CreateLocalMediaStream(stream_id);

if (!peer_connection_->AddStream(stream))
if (!peer_connection_->AddStream(stream.get()))
{
RCLCPP_WARN(nh_->get_logger(), "Adding stream to PeerConnection failed");
continue;
Expand All @@ -300,7 +298,7 @@ void WebrtcClient::handle_message(MessageHandler::Type type, const std::string&
RCLCPP_WARN_STREAM(nh_->get_logger(), "Stream not found with id: " << stream_id);
continue;
}
peer_connection_->RemoveStream(stream);
peer_connection_->RemoveStream(stream.get());
}
else if(action.type == ConfigureAction::kAddVideoTrackActionName) {
FIND_PROPERTY_OR_CONTINUE("stream_id", stream_id);
Expand All @@ -326,7 +324,7 @@ void WebrtcClient::handle_message(MessageHandler::Type type, const std::string&
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
peer_connection_factory_->CreateVideoTrack(
track_id,
capturer));
capturer.get()));
stream->AddTrack(video_track);
capturer->Start();
}
Expand Down Expand Up @@ -356,10 +354,9 @@ void WebrtcClient::handle_message(MessageHandler::Type type, const std::string&
if(audio_type == "local") {
cricket::AudioOptions options;
rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
peer_connection_factory_->CreateAudioTrack(
track_id,
peer_connection_factory_->CreateAudioSource(options)));
stream->AddTrack(audio_track);
peer_connection_factory_->CreateAudioTrack(track_id, peer_connection_factory_->CreateAudioSource(options).get())
);
stream->AddTrack(audio_track);
}
else {
RCLCPP_WARN_STREAM(nh_->get_logger(), "Unknown video source type: " << audio_type);
Expand Down Expand Up @@ -416,7 +413,7 @@ void WebrtcClient::handle_message(MessageHandler::Type type, const std::string&

RCLCPP_DEBUG_STREAM(nh_->get_logger(), "Received remote description: " << message.sdp);
rtc::scoped_refptr<DummySetSessionDescriptionObserver> dummy_set_description_observer(new rtc::RefCountedObject<DummySetSessionDescriptionObserver>());
peer_connection_->SetRemoteDescription(dummy_set_description_observer, session_description);
peer_connection_->SetRemoteDescription(dummy_set_description_observer.get(), session_description);
}
else if (IceCandidateMessage::isIceCandidate(message_json))
{
Expand Down Expand Up @@ -465,7 +462,7 @@ void WebrtcClient::handle_message(MessageHandler::Type type, const std::string&
void WebrtcClient::OnSessionDescriptionSuccess(webrtc::SessionDescriptionInterface* description)
{
rtc::scoped_refptr<DummySetSessionDescriptionObserver> dummy_set_description_observer(new rtc::RefCountedObject<DummySetSessionDescriptionObserver>());
peer_connection_->SetLocalDescription(dummy_set_description_observer, description);
peer_connection_->SetLocalDescription(dummy_set_description_observer.get(), description);

SdpMessage message;
if (message.fromSessionDescription(*description))
Expand Down
9 changes: 5 additions & 4 deletions webrtc_ros/src/webrtc_ros_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#include <webrtc_ros/webrtc_ros_server.h>
#include "webrtc/rtc_base/ssl_adapter.h"

#include "webrtc/rtc_base/bind.h"

namespace webrtc_ros
{

MessageHandler* WebrtcRosServer_handle_new_signaling_channel(void* _this, SignalingChannel *channel)
{
return ((WebrtcRosServer*) _this)->signaling_thread_->Invoke<MessageHandler*>(RTC_FROM_HERE, rtc::Bind(&WebrtcRosServer::handle_new_signaling_channel,
(WebrtcRosServer*)_this, channel));
MessageHandler* result;
((WebrtcRosServer*) _this)->signaling_thread_->BlockingCall(
[&]{ result = ((WebrtcRosServer*) _this)->handle_new_signaling_channel(channel);}
);
return result;
}

WebrtcRosServer::WebrtcRosServer(rclcpp::Node::SharedPtr nh)
Expand Down