Skip to content

Commit

Permalink
Merge pull request #5 from cppbitman/master
Browse files Browse the repository at this point in the history
libwebstreamer 0.1
  • Loading branch information
kedacomresearch authored Feb 27, 2018
2 parents 7f38cd3 + 922b1d6 commit 285c1c6
Show file tree
Hide file tree
Showing 36 changed files with 2,795 additions and 164 deletions.
5 changes: 3 additions & 2 deletions CMakelists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ autocmake_pkgconfig_init()
include_directories(lib)

#add_library( libwebstreamer SHARED lib/source/example.cpp)
file(GLOB_RECURSE LWS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/lib/*.[ch]pp")
file(GLOB_RECURSE LWS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/lib/*.[ch]pp" "${CMAKE_CURRENT_SOURCE_DIR}/lib/*.[ch]"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/flatbuffers/*.h")

autocmake_add_library(libwebstreamer SHARED
SOURCES ${LWS_SOURCES}
Expand All @@ -31,4 +32,4 @@ install(TARGETS libwebstreamer
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/libwebstreamer.h DESTINATION include )
INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/libwebstreamer.hpp DESTINATION include )
10 changes: 8 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
set PATH=C:\cerbero\x86_64\bin;%PATH%;
flatc --cpp -o .\lib\flatbuffers -I .\schema .\schema\webrtc.fbs .\schema\webstreamer.fbs

if not exist %~dp0\build mkdir %~dp0\build
pushd %~dp0\build


set PKG_CONFIG=C:\cerbero\build-tools\bin\pkg-config

set PKG_CONFIG_LIBDIR=C:\cerbero\x86_64\lib\pkgconfig
%PKG_CONFIG% --version
cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX="C:/cerbero/x86_64" ..
cmake --build . --target ALL_BUILD --config Debug -- /p:Platform=x64
cmake --build . --target INSTALL --config Debug -- /p:Platform=x64
popd
#cmake --build . --target INSTALL --config Debug -- /p:Platform=x64
popd
pause
38 changes: 0 additions & 38 deletions lib/dispatcher.cpp

This file was deleted.

13 changes: 0 additions & 13 deletions lib/dispatcher.hpp

This file was deleted.

166 changes: 166 additions & 0 deletions lib/flatbuffers/adapter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#include <flatbuffers/adapter.hpp>
#include <message/endpoint.hpp>
#include <glib.h>

namespace libwebstreamer
{
namespace flatbuffers
{
void transform(::webstreamer::Endpoint endpoint, const void * value, std::shared_ptr<message::common::Endpoint>& cxx_endpoint)
{
switch (endpoint)
{
case ::webstreamer::Endpoint::Endpoint_RtspClient:
{
const ::webstreamer::RtspClient * fb_endpoint = static_cast<const ::webstreamer::RtspClient *>(value);
std::shared_ptr<message::endpoint::RtspClient> endpoint = std::make_shared<message::endpoint::RtspClient>();
endpoint->id = fb_endpoint->base()->id()->str();
endpoint->type = message::common::RTSP_CLIENT;
endpoint->url = fb_endpoint->url()->str();

cxx_endpoint = endpoint;
}
break;
case ::webstreamer::Endpoint::Endpoint_Webrtc:
{
const ::webstreamer::Webrtc * fb_endpoint = static_cast<const ::webstreamer::Webrtc *>(value);
std::shared_ptr<message::endpoint::Webrtc> endpoint = std::make_shared<message::endpoint::Webrtc>();
endpoint->id = fb_endpoint->base()->id()->str();
endpoint->type = message::common::WEBRTC;
endpoint->group = fb_endpoint->group()->str();
endpoint->connection = fb_endpoint->connection()->str();
switch (fb_endpoint->sdp_role())
{
case ::webstreamer::webrtc::SdpRole::SdpRole_OFFER:
endpoint->sdp_role = message::webrtc::SdpRole::OFFER;
break;
case ::webstreamer::webrtc::SdpRole::SdpRole_ANSWER:
endpoint->sdp_role = message::webrtc::SdpRole::ANSWER;
break;
case ::webstreamer::webrtc::SdpRole::SdpRole_ANY:
endpoint->sdp_role = message::webrtc::SdpRole::ANY;
break;
default:
g_warn_if_reached();
break;
}

switch (fb_endpoint->video_stream_mode())
{
case ::webstreamer::webrtc::StreamMode::StreamMode_SENDONLY:
endpoint->video_mode = message::webrtc::StreamMode::SEND_ONLY;
break;
case ::webstreamer::webrtc::StreamMode::StreamMode_RECVONLY:
endpoint->video_mode = message::webrtc::StreamMode::RECV_ONLY;
break;
case ::webstreamer::webrtc::StreamMode::StreamMode_SENDRECV:
endpoint->video_mode = message::webrtc::StreamMode::SEND_RECV;
break;
default:
g_warn_if_reached();
break;
}

switch (fb_endpoint->audio_stream_mode())
{
case ::webstreamer::webrtc::StreamMode::StreamMode_SENDONLY:
endpoint->audio_mode = message::webrtc::StreamMode::SEND_ONLY;
break;
case ::webstreamer::webrtc::StreamMode::StreamMode_RECVONLY:
endpoint->audio_mode = message::webrtc::StreamMode::RECV_ONLY;
break;
case ::webstreamer::webrtc::StreamMode::StreamMode_SENDRECV:
endpoint->audio_mode = message::webrtc::StreamMode::SEND_RECV;
break;
default:
g_warn_if_reached();
break;
}

cxx_endpoint = endpoint;
}
break;
default:
break;
}
}

//fb - flatbuffer
void transform(const webstreamer::LiveStreamCreate& fb_message, message::livestream::create_t& cxx_message)
{
//pipeline
//pipeline.id
cxx_message.pipeline.id = fb_message.pipeline()->id()->str();
switch (fb_message.pipeline()->video_codec())//pipeline.video_codec
{
case ::webstreamer::VideoCodec::VideoCodec_H264:
cxx_message.pipeline.video = message::common::VideoCodec::H264;
break;
case ::webstreamer::VideoCodec::VideoCodec_H265:
cxx_message.pipeline.video = message::common::VideoCodec::H265;
break;
case ::webstreamer::VideoCodec::VideoCodec_VP8:
cxx_message.pipeline.video = message::common::VideoCodec::VP8;
break;
default:
g_warn_if_reached();
break;
}
switch (fb_message.pipeline()->audio_codec())//pipeline.audio_codec
{
case ::webstreamer::AudioCodec::AudioCodec_OPUS:
cxx_message.pipeline.audio = message::common::AudioCodec::OPUS;
break;
case ::webstreamer::AudioCodec::AudioCodec_PCMA:
cxx_message.pipeline.audio = message::common::AudioCodec::PCMA;
break;
default:
g_warn_if_reached();
break;
}

//endpoint
transform(fb_message.endpoint_type(), fb_message.endpoint(), cxx_message.endpoint);
}

void transform(const webstreamer::LiveStreamDestroy& fb_message, message::livestream::destroy_t& cxx_message)
{
cxx_message.id = fb_message.id()->str();
}

void transform(const webstreamer::LiveStreamAddEndpoint& fb_message, message::livestream::add_endpoint_t& cxx_message)
{
cxx_message.id = fb_message.id()->str();
transform(fb_message.endpoint_type(), fb_message.endpoint(), cxx_message.endpoint);
}

void transform(const webstreamer::LiveStreamRemoveEndpoint& fb_message, message::livestream::remove_endpoint_t& cxx_message)
{
cxx_message.id = fb_message.id()->str();
cxx_message.endpoint_id = fb_message.endpoint_id()->str();
}

void transform(const webstreamer::LiveStreamAddEndpoints& fb_message, message::livestream::add_endpoints_t& cxx_message)
{
cxx_message.id = fb_message.id()->str();
auto endpoints_type = fb_message.endpoints_type();
auto endpoints = fb_message.endpoints();

for (int i = 0; i < (int)endpoints->size(); i++)
{
std::shared_ptr< message::common::Endpoint> endpoint;
transform( endpoints_type->GetEnum<::webstreamer::Endpoint>(i), endpoints->GetAs<::webstreamer::RtspClient>(i), endpoint );
cxx_message.endpoints.push_back(endpoint);
}
}

void transform(const webstreamer::LiveStreamRemoveEndpoints& fb_message, message::livestream::remove_endpoints_t& cxx_message)
{
cxx_message.id = fb_message.id()->str();
for (int i = 0; i < (int)fb_message.endpoint_ids()->size(); i++)
{
cxx_message.endpoint_ids.push_back(fb_message.endpoint_ids()->GetAsString(i)->str());
}
}
}
}
20 changes: 20 additions & 0 deletions lib/flatbuffers/adapter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef LIBWEBSTREAMER_FLATBUFFERS_ADAPTER_HPP
#define LIBWEBSTREAMER_FLATBUFFERS_ADAPTER_HPP

#include <flatbuffers/webstreamer_generated.h>
#include <message/livestream.hpp>

namespace libwebstreamer
{
namespace flatbuffers
{
void transform(const webstreamer::LiveStreamCreate& fb_message, message::livestream::create_t& cxx_message);
void transform(const webstreamer::LiveStreamDestroy& fb_message, message::livestream::destroy_t& cxx_message);
void transform(const webstreamer::LiveStreamAddEndpoint& fb_message, message::livestream::add_endpoint_t& cxx_message);
void transform(const webstreamer::LiveStreamRemoveEndpoint& fb_message, message::livestream::remove_endpoint_t& cxx_message);
void transform(const webstreamer::LiveStreamAddEndpoints& fb_message, message::livestream::add_endpoints_t& cxx_message);
void transform(const webstreamer::LiveStreamRemoveEndpoints& fb_message, message::livestream::remove_endpoints_t& cxx_message);
}
}

#endif
Loading

0 comments on commit 285c1c6

Please sign in to comment.