Skip to content

Commit

Permalink
Moved WebRTC code to trash temorarly
Browse files Browse the repository at this point in the history
  • Loading branch information
k-wasniowski committed Sep 25, 2023
1 parent 5f0c3aa commit 45cf93e
Show file tree
Hide file tree
Showing 29 changed files with 248 additions and 179 deletions.
19 changes: 15 additions & 4 deletions DevApps/GenericRtpClientDevApp/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
#include <MediaServer/GenericRtpClient/Details/RtpClientSession.hpp>
#include <MediaServer/GenericRtpClient/GenericRtpClient.hpp>

#include <boost/asio.hpp>

int main()
{
boost::asio::io_context ioContext{};

boost::asio::ip::udp::endpoint mediaEndpoint{boost::asio::ip::address::from_string("127.0.0.1"), 5004};
auto pRtpClientSession = MediaServer::Rtp::RtpClientSession::Create(ioContext, mediaEndpoint);
auto pRtpClientSession = MediaServer::Rtp::GenericRtpClient::Create(ioContext);

pRtpClientSession->Initiate();
std::string address{"127.0.0.1"};
uint16_t port = 5004;
std::string sessionDescription = "v=0\r\n"
"o=- 0 0 IN IP4 127.0.0.1\r\n"
"s=No Name\r\n"
"c=IN IP4 127.0.0.1\r\n"
"t=0 0\r\n"
"a=tool:libavformat 60.4.101\r\n"
"m=video 5004 RTP/AVP 96\r\n"
"b=AS:256\r\n"
"a=rtpmap:96 VP8/90000\r\n";

pRtpClientSession->InitiateNewSession(address, port, sessionDescription);

ioContext.run();

Expand Down
6 changes: 1 addition & 5 deletions HttpServer/Resources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
add_library(Resources
STATIC
${CMAKE_CURRENT_SOURCE_DIR}/src/PeerConnection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/GenericRtpController.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/WebRtcController.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/WhipSignalingHandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/WhepSignalingHandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/VideoEndpointRx.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/VideoEndpointTx.cpp
)

target_link_libraries(Resources
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <drogon/HttpController.h>

#include <memory>

namespace HttpServer
{
namespace Resources
{
class GenericRtpController;
using GenericRtpControllerSharedPtr_t = std::shared_ptr<GenericRtpController>;

class GenericRtpController : public drogon::HttpController<GenericRtpController, false>
{
public:
static GenericRtpControllerSharedPtr_t Create();

GenericRtpController();
~GenericRtpController() override;

METHOD_LIST_BEGIN
ADD_METHOD_TO(GenericRtpController::PostResource, "/api/v1/resources/generic-rtp/{resource}", drogon::Post);
METHOD_LIST_END

void PostResource(const drogon::HttpRequestPtr &req, std::function<void(const drogon::HttpResponsePtr &)> &&callback, std::string&& resource);

private:
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <MediaServer/MediaManager/MediaManager.hpp>

#include <drogon/HttpController.h>

#include <memory>

namespace HttpServer
{
namespace Resources
{
class WebRtcController;
using WebRtcControllerSharedPtr_t = std::shared_ptr<WebRtcController>;

class WebRtcController : public drogon::HttpController<WebRtcController, false>
{
public:
static WebRtcControllerSharedPtr_t Create(MediaServer::MediaManagerSharedPtr_t pMediaManager);

explicit WebRtcController(MediaServer::MediaManagerSharedPtr_t pMediaManager);
~WebRtcController() override = default;

METHOD_LIST_BEGIN
ADD_METHOD_TO(WebRtcController::PostResource, "/api/v1/resources/webrtc/{resource}", drogon::Post);
ADD_METHOD_TO(WebRtcController::GetResource, "/api/v1/resources/webrtc/{resource}", drogon::Get);
METHOD_LIST_END

void PostResource(const drogon::HttpRequestPtr &req, std::function<void(const drogon::HttpResponsePtr &)> &&callback, std::string&& resource);

void GetResource(const drogon::HttpRequestPtr &req, std::function<void(const drogon::HttpResponsePtr &)> &&callback, std::string&& resource);

private:
MediaServer::MediaManagerSharedPtr_t m_pMediaManager;
};
}
}
34 changes: 0 additions & 34 deletions HttpServer/Resources/include/Resources/WebRtcController.hpp

This file was deleted.

38 changes: 38 additions & 0 deletions HttpServer/Resources/src/GenericRtpController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <HttpServer/Resources/GenericRtpController.hpp>

#include <iostream>

namespace HttpServer
{
namespace Resources
{
GenericRtpControllerSharedPtr_t GenericRtpController::Create()
{
return std::make_shared<GenericRtpController>();
}

GenericRtpController::GenericRtpController()
{
std::cout << "Creating GenericRtpController" << std::endl;
}

GenericRtpController::~GenericRtpController()
{
std::cout << "Terminating GenericRtpController" << std::endl;
}

void GenericRtpController::PostResource(const drogon::HttpRequestPtr& pHttpRequest,
std::function<void(const drogon::HttpResponsePtr&)>&& callback,
std::string&& resource)
{
std::cout << "GenericRtpController::PostResource" << std::endl;



auto pHttpResponse = drogon::HttpResponse::newHttpResponse();
pHttpResponse->setStatusCode(drogon::HttpStatusCode::k200OK);

callback(pHttpResponse);
}
}
}
117 changes: 33 additions & 84 deletions HttpServer/Resources/src/WebRtcController.cpp
Original file line number Diff line number Diff line change
@@ -1,94 +1,43 @@
#include <Resources/PeerConnection.hpp>
#include <Resources/WebRtcController.hpp>
#include <Resources/WhepSignalingHandler.hpp>
#include <Resources/WhipSignalingHandler.hpp>

#include <Resources/VideoEndpointRx.hpp>
#include <Resources/VideoEndpointTx.hpp>
#include <HttpServer/Resources/WebRtcController.hpp>

#include <MediaServer/MediaManager/MediaResource.hpp>

#include <rtc/rtc.hpp>

#include <memory>

namespace Http
namespace HttpServer
{
WebRtcControllerSharedPtr_t WebRtcController::Create(MediaServer::MediaManagerSharedPtr_t pMediaManager)
namespace Resources
{
return std::make_shared<WebRtcController>(pMediaManager);
WebRtcControllerSharedPtr_t WebRtcController::Create(MediaServer::MediaManagerSharedPtr_t pMediaManager)
{
return std::make_shared<WebRtcController>(pMediaManager);
}

WebRtcController::WebRtcController(MediaServer::MediaManagerSharedPtr_t pMediaManager)
: m_pMediaManager{std::move(pMediaManager)}
{
std::cout << "Creating WebRtcController" << std::endl;
}

void WebRtcController::PostResource(const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& callback,
std::string&& resource)
{
auto pHttpResponse = drogon::HttpResponse::newHttpResponse();
pHttpResponse->setStatusCode(drogon::HttpStatusCode::k501NotImplemented);

callback(pHttpResponse);
}

void WebRtcController::GetResource(const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& callback,
std::string&& resource)
{
auto pHttpResponse = drogon::HttpResponse::newHttpResponse();
pHttpResponse->setStatusCode(drogon::HttpStatusCode::k501NotImplemented);

callback(pHttpResponse);
}
}

WebRtcController::WebRtcController(MediaServer::MediaManagerSharedPtr_t pMediaManager)
: m_pMediaManager{std::move(pMediaManager)}
{
std::cout << "Creating WebRtcController" << std::endl;
}

void WebRtcController::PostResource(const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& callback,
std::string&& resource)
{
std::cout << "WebRtcController::PostResource" << std::endl;

std::string body{req->body()};

rtc::Configuration config;
config.iceServers.emplace_back("stun:stun.l.google.com:19302");
config.iceServers.emplace_back("stun:stun1.l.google.com:19302");
config.iceServers.emplace_back("stun:stun2.l.google.com:19302");
config.iceServers.emplace_back("stun:stun3.l.google.com:19302");
config.iceServers.emplace_back("stun:stun4.l.google.com:19302");

auto pMediaResource = MediaServer::MediaResource::Create(std::move(resource));
m_pMediaManager->AddMediaResource(pMediaResource);

auto onTrackCallback = [pMediaResource](std::shared_ptr<rtc::Track> pTrack) {
std::cout << "onTrackCallback - " << pTrack->direction() << std::endl;

auto pVideoTrack = WebRTC::VideoEndpointRx::Create(std::move(pTrack));
pMediaResource->AddTrack(pVideoTrack);
};

auto pRTCPeerConnection = std::make_shared<rtc::PeerConnection>();
auto pPeerConnection = WebRTC::PeerConnection::Create(pRTCPeerConnection, onTrackCallback);

auto pWhepSignalingHandler = WebRTC::WhepSignalingHandler::Create(std::move(callback));
pPeerConnection->InitiateSignaling(std::move(pWhepSignalingHandler), body);
}

void WebRtcController::GetResource(const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& callback,
std::string&& resource)
{
std::cout << "WebRtcController::PostResource" << std::endl;

std::string body{req->body()};

rtc::Configuration config;
config.iceServers.emplace_back("stun:stun.l.google.com:19302");
config.iceServers.emplace_back("stun:stun1.l.google.com:19302");
config.iceServers.emplace_back("stun:stun2.l.google.com:19302");
config.iceServers.emplace_back("stun:stun3.l.google.com:19302");
config.iceServers.emplace_back("stun:stun4.l.google.com:19302");

auto pMediaResource = m_pMediaManager->GetMediaResource(resource);

auto onTrackCallback = [pMediaResource](std::shared_ptr<rtc::Track> pTrack) {
std::cout << "onTrackCallback - " << pTrack->direction() << std::endl;

auto pVideoEndpointTx = WebRTC::VideoEndpointTx::Create(std::move(pTrack));

auto pVideoEndpointRx = pMediaResource->GetTrack("");

pVideoEndpointRx->Attach(pVideoEndpointTx);
};

auto pRTCPeerConnection = std::make_shared<rtc::PeerConnection>();

auto pPeerConnection = WebRTC::PeerConnection::Create(pRTCPeerConnection, onTrackCallback);

auto pWhipSignalingHandler = WebRTC::WhipSignalingHandler::Create(std::move(callback));
pPeerConnection->InitiateSignaling(std::move(pWhipSignalingHandler), body);
}
}
7 changes: 5 additions & 2 deletions HttpServer/Server/src/Server.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <HttpServer/Server.hpp>

#include <HealthCheck/HealthCheckController.hpp>
#include <Resources/WebRtcController.hpp>
#include <HttpServer/Resources/WebRtcController.hpp>
#include <HttpServer/Resources/GenericRtpController.hpp>

#include <MediaServer/MediaManager/MediaManager.hpp>

Expand Down Expand Up @@ -46,7 +47,9 @@ namespace HttpServer
{
std::cout << "Running Server Impl" << std::endl;
auto pHealthCheckController = Http::HealthCheckController::Create();
auto pWebRtcController = Http::WebRtcController::Create(m_pMediaManager);
auto pWebRtcController = HttpServer::Resources::WebRtcController::Create(m_pMediaManager);
auto pGenericRtpController = HttpServer::Resources::GenericRtpController::Create();

drogon::app()
.addListener("127.0.0.1", 80)
.registerController(pHealthCheckController)
Expand Down
2 changes: 1 addition & 1 deletion Media/Sdp/src/Details/builders/SessionDescriptionBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define SDP_SESSION_DESCRIPTION_BUILDER_H_

#include "Builder.h"
#include "SessionDescription.h"
#include "SessionDescription.hpp"

using namespace Media::Sdp;
using namespace abnf;
Expand Down
2 changes: 1 addition & 1 deletion Media/Sdp/src/SessionDescription.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "SessionDescription.h"
#include "SessionDescription.hpp"
#include "abnf/ParserContext.hpp"
#include "abnf/ParserException.hpp"
#include "abnf/Rule_session_description.hpp"
Expand Down
1 change: 1 addition & 0 deletions MediaServer/GenericRtpClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_include_directories(GenericRtpClient
target_link_libraries(GenericRtpClient
PRIVATE
Media::Core
Media::Sdp
)

add_library(MediaServer::GenericRtpClient ALIAS GenericRtpClient)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <Media/Sdp/SessionDescription.hpp>

#include <boost/asio.hpp>

#include <memory>
Expand All @@ -15,9 +17,13 @@ namespace MediaServer
class RtpClientSession : public std::enable_shared_from_this<RtpClientSession>
{
public:
static RtpClientSessionSharedPtr_t Create(boost::asio::io_context& ioContext, boost::asio::ip::udp::endpoint endpoint);
static RtpClientSessionSharedPtr_t Create(boost::asio::io_context& ioContext,
boost::asio::ip::udp::endpoint endpoint,
Media::Sdp::SessionDescriptionSharedPtr_t pSessionDescription);

explicit RtpClientSession(boost::asio::io_context& ioContext, boost::asio::ip::udp::endpoint endpoint);
explicit RtpClientSession(boost::asio::io_context& ioContext,
boost::asio::ip::udp::endpoint endpoint,
Media::Sdp::SessionDescriptionSharedPtr_t pSessionDescription);

virtual ~RtpClientSession();

Expand All @@ -31,7 +37,8 @@ namespace MediaServer
private:
boost::asio::io_context& m_ioContext;
boost::asio::ip::udp::socket m_socket;
std::array<std::byte, 8192> m_readStreamBuffer{};
std::array<std::byte, 8192> m_readStreamBuffer;
Media::Sdp::SessionDescriptionSharedPtr_t m_pSessionDescription;
};
}
}
Loading

0 comments on commit 45cf93e

Please sign in to comment.