Skip to content

Commit

Permalink
Generic Rtp Client adjustmnets
Browse files Browse the repository at this point in the history
  • Loading branch information
k-wasniowski committed Oct 7, 2023
1 parent bf939d9 commit f7210ae
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 96 deletions.
1 change: 1 addition & 0 deletions HttpServer/Resources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target_link_libraries(Resources
MediaServer::MediaManager
MediaServer::MediaServer
Media::Core
Media::Sdp
nlohmann_json::nlohmann_json
)

Expand Down
22 changes: 6 additions & 16 deletions HttpServer/Resources/src/GenericRtpController.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <HttpServer/Resources/GenericRtpController.hpp>

#include <Media/Sdp/SessionDescription.hpp>

#include <nlohmann/json.hpp>

#include <iostream>
Expand Down Expand Up @@ -52,11 +54,10 @@ namespace HttpServer

nlohmann::json request = nlohmann::json::parse(requestBody);

std::string address = request["address"];
std::string address = request["ip"];
uint16_t port = request["port"];
std::string sdp = request["sdp"];

auto pMediaTrack = co_await pGenericRtpClient->Initiate(address, port, sdp);
auto pMediaTrack = co_await pGenericRtpClient->Initiate(address, port);
if (!pMediaTrack)
{
std::cout << "Failure" << std::endl;
Expand All @@ -66,7 +67,7 @@ namespace HttpServer
}

auto pMediaResource = co_await pMediaManager->GetMediaResource(resourceName);
if(pMediaResource)
if (pMediaResource)
{
auto pMediaResourceLock = pMediaResource->Lock();

Expand All @@ -82,17 +83,6 @@ namespace HttpServer

co_await pMediaManager->AddMediaResource(pNewMediaResource);
}
// if (!pMediaResource)
// {
//
// pNewMediaResource->AddTrack(pMediaTrack);
//
// co_await pMediaManager->AddMediaResource(pNewMediaResource);
// }
// else
// {
// pMediaResource->AddTrack(pMediaTrack);
// }

std::cout << "Success" << std::endl;
pHttpResponse->setStatusCode(drogon::HttpStatusCode::k200OK);
Expand All @@ -114,7 +104,7 @@ namespace HttpServer
}

auto mediaResources = co_await pMediaManager->GetMediaResources();
if(mediaResources.empty())
if (mediaResources.empty())
{
pHttpResponse->setStatusCode(drogon::HttpStatusCode::k204NoContent);

Expand Down
9 changes: 9 additions & 0 deletions HttpServer/Resources/src/WebRtcController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <MediaServer/MediaManager/MediaResource.hpp>

#include <rtc/rtc.hpp>

#include <memory>

namespace HttpServer
Expand All @@ -26,6 +28,13 @@ namespace HttpServer
auto pHttpResponse = drogon::HttpResponse::newHttpResponse();
pHttpResponse->setStatusCode(drogon::HttpStatusCode::k501NotImplemented);

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

//auto pPeerConnection = std::make_shared<rtc::PeerConnection>(config);



callback(pHttpResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ namespace MediaServer
{
public:
static RtpClientSessionSharedPtr_t Create(boost::asio::io_context& ioContext,
boost::asio::ip::udp::endpoint endpoint,
Media::Sdp::SessionDescriptionSharedPtr_t pSessionDescription);
boost::asio::ip::udp::endpoint endpoint);

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

virtual ~RtpClientSession();

Expand All @@ -36,6 +34,8 @@ namespace MediaServer
public:
void Attach(MediaObserverSharedPtr_t pMediaObserver) override;

std::string Name() const override;

protected:
void StartReading_();

Expand All @@ -49,7 +49,6 @@ namespace MediaServer
boost::asio::io_context& m_ioContext;
boost::asio::ip::udp::socket m_socket;
std::array<std::byte, 8192> m_readStreamBuffer;
Media::Sdp::SessionDescriptionSharedPtr_t m_pSessionDescription;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace MediaServer

virtual ~GenericRtpClient();

bool InitiateNewSession(std::string ip, uint16_t port, std::string sessionDescription, std::function<void(IMediaTrackSharedPtr_t pMediaTrack)> callback) override;
bool InitiateNewSession(std::string ip, uint16_t port, std::function<void(IMediaTrackSharedPtr_t pMediaTrack)> callback) override;

private:
boost::asio::io_context m_ioContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <Gondor/Execution/CallbackAwaiter.hpp>
#include <Gondor/Execution/ExecutionContext.hpp>

#include <Media/Sdp/SessionDescription.hpp>

#include <MediaServer/MediaManager/IMediaTrack.hpp>

#include <coroutine>
Expand All @@ -22,7 +24,6 @@ namespace MediaServer

virtual bool InitiateNewSession(std::string ip,
uint16_t port,
std::string sessionDescription,
std::function<void(IMediaTrackSharedPtr_t pMediaTrack)> callback) = 0;
};

Expand All @@ -34,13 +35,11 @@ namespace MediaServer
GenericRtpStreamAwaiter(Gondor::Execution::ExecutionContextWeakPtr pExecutionContext,
IGenericRtpClientSharedPtr_t pGenericRtpClient,
std::string ip,
uint16_t port,
std::string sessionDescription)
uint16_t port)
: m_pExecutionContext{pExecutionContext}
, m_pGenericRtpClient{pGenericRtpClient}
, m_ip{ip}
, m_port{port}
, m_sessionDescription{sessionDescription}
{
std::cout << "GenericRtpStreamAwaiter::GenericRtpStreamAwaiter()" << std::endl;
}
Expand All @@ -63,7 +62,6 @@ namespace MediaServer
m_pGenericRtpClient,
m_ip,
m_port,
m_sessionDescription,
[this, handle](IMediaTrackSharedPtr_t pMediaTrack) -> void {
SetValue(pMediaTrack);
handle.resume();
Expand All @@ -82,15 +80,14 @@ namespace MediaServer
IGenericRtpClientSharedPtr_t m_pGenericRtpClient;
std::string m_ip;
uint16_t m_port;
std::string m_sessionDescription;
};

class IGenericRtpClientProxy
{
public:
virtual ~IGenericRtpClientProxy() = default;

virtual GenericRtpStreamAwaiter Initiate(std::string ip, uint16_t port, std::string sessionDescription) = 0;
virtual GenericRtpStreamAwaiter Initiate(std::string ip, uint16_t port) = 0;
};

using IGenericRtpClientProxySharedPtr_t = std::shared_ptr<IGenericRtpClientProxy>;
Expand Down
16 changes: 10 additions & 6 deletions MediaServer/GenericRtpClient/src/Details/RtpClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ namespace MediaServer
namespace Rtp
{
RtpClientSessionSharedPtr_t RtpClientSession::Create(boost::asio::io_context& ioContext,
boost::asio::ip::udp::endpoint endpoint,
Media::Sdp::SessionDescriptionSharedPtr_t pSessionDescription)
boost::asio::ip::udp::endpoint endpoint)
{
return std::make_shared<RtpClientSession>(ioContext, endpoint, pSessionDescription);
return std::make_shared<RtpClientSession>(ioContext, endpoint);
}

RtpClientSession::RtpClientSession(boost::asio::io_context& ioContext,
boost::asio::ip::udp::endpoint endpoint,
Media::Sdp::SessionDescriptionSharedPtr_t pSessionDescription)
boost::asio::ip::udp::endpoint endpoint)
: m_ioContext{ioContext}
, m_socket{m_ioContext, endpoint}
, m_readStreamBuffer{}
, m_pSessionDescription{pSessionDescription}
{
std::cout << "RtpClientSession::RtpClientSession()" << std::endl;
}
Expand Down Expand Up @@ -83,6 +80,8 @@ namespace MediaServer
auto pMediaBuffer = Media::Core::MediaBuffer::Create(std::move(data));
auto pFrame = Media::Core::VideoFrame::Create(pMediaBuffer);



// std::cout << "Frame received!" << std::endl;

StartReading_();
Expand All @@ -92,5 +91,10 @@ namespace MediaServer
{
std::cout << "RtpClientSession::Attach()" << std::endl;
}

std::string RtpClientSession::Name() const
{
return "";
}
}
}
10 changes: 2 additions & 8 deletions MediaServer/GenericRtpClient/src/GenericRtpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,12 @@ namespace MediaServer
m_threadPool.join_all();
}

bool GenericRtpClient::InitiateNewSession(std::string ip, uint16_t port, std::string sessionDescription, std::function<void(IMediaTrackSharedPtr_t pMediaTrack)> callback)
bool GenericRtpClient::InitiateNewSession(std::string ip, uint16_t port, std::function<void(IMediaTrackSharedPtr_t pMediaTrack)> callback)
{
std::cout << "GenericRtpClient::InitiateNewClient()" << std::endl;
std::cout << "IP: " << ip << std::endl;
std::cout << "Port: " << port << std::endl;
std::cout << "Session Description: " << sessionDescription << std::endl;

try
{
auto endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::make_address(ip), port);
auto pSessionDescription = Media::Sdp::SessionDescription::Parse(sessionDescription);
auto pRtpClientSession = RtpClientSession::Create(m_ioContext, endpoint, pSessionDescription);
auto pRtpClientSession = RtpClientSession::Create(m_ioContext, endpoint);

pRtpClientSession->Initiate(callback);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <vector>
#include <memory>
#include <string>

namespace MediaServer
{
Expand All @@ -20,6 +21,8 @@ namespace MediaServer
public:
virtual ~IMediaTrack() = default;

virtual std::string Name() const = 0;

virtual void Attach(MediaObserverSharedPtr_t pMediaObserver) = 0;
};

Expand Down
6 changes: 6 additions & 0 deletions MediaServer/MediaServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ target_link_libraries(MediaServer
Gondor::Execution
)

target_link_libraries(MediaServer
PUBLIC
Media::Sdp
Media::Core
)

target_link_libraries(MediaServer
PUBLIC
MediaServer::MediaManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma once

#include <MediaServer/GenericRtpClient/IGenericRtpClient.hpp>

#include <MediaServer/GenericRtpClient/GenericRtpClient.hpp>

#include <Media/Sdp/SessionDescription.hpp>

#include <Gondor/Execution/ExecutionContext.hpp>

#include <memory>
Expand All @@ -23,7 +24,7 @@ namespace MediaServer
MediaServer::Rtp::GenericRtpClientSharedPtr_t pGenericRtpClient);
~GenericRtpClientProxy();

MediaServer::Rtp::GenericRtpStreamAwaiter Initiate(std::string ip, uint16_t port, std::string sessionDescription) override;
MediaServer::Rtp::GenericRtpStreamAwaiter Initiate(std::string ip, uint16_t port) override;

private:
Gondor::Execution::ExecutionContextWeakPtr m_pExecutionContext;
Expand Down
4 changes: 2 additions & 2 deletions MediaServer/MediaServer/src/GenericRtpClientProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace MediaServer
std::cout << "GenericRtpClientProxy::~GenericRtpClientProxy()" << std::endl;
}

MediaServer::Rtp::GenericRtpStreamAwaiter GenericRtpClientProxy::Initiate(std::string ip, uint16_t port, std::string sessionDescription)
MediaServer::Rtp::GenericRtpStreamAwaiter GenericRtpClientProxy::Initiate(std::string ip, uint16_t port)
{
std::cout << "GenericRtpClient::Initiate()" << std::endl;

return MediaServer::Rtp::GenericRtpStreamAwaiter(m_pExecutionContext, m_pGenericRtpClient, ip, port, sessionDescription);
return MediaServer::Rtp::GenericRtpStreamAwaiter(m_pExecutionContext, m_pGenericRtpClient, ip, port);
}
}
Loading

0 comments on commit f7210ae

Please sign in to comment.