From 22ab961b940917af64758cd48822c080f3589d59 Mon Sep 17 00:00:00 2001 From: daihongjun Date: Tue, 30 Jan 2018 15:57:32 +0800 Subject: [PATCH 01/18] libwebstreamer flatbuffers schema --- schema/webrtc.fbs | 66 +++++++++++++++++++++++++ schema/webstreamer.fbs | 106 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 schema/webrtc.fbs create mode 100644 schema/webstreamer.fbs diff --git a/schema/webrtc.fbs b/schema/webrtc.fbs new file mode 100644 index 0000000..87c21b2 --- /dev/null +++ b/schema/webrtc.fbs @@ -0,0 +1,66 @@ +namespace webstreamer.webrtc; + + +enum SdpRole : int8 +{ + OFFER, + ANSWER, + ANY +} + +enum StreamMode : int8 +{ + SENDONLY, + RECVONLY, + SENDRECV +} + + +namespace webstreamer.webrtc.topics; + +enum TopicCategory : int8 +{ + SDP, + STATUS +} + +table Endpoint +{ + sdp_role : webstreamer.webrtc.SdpRole; + connection : string; + group : string; +} + +table SubscribeItem +{ + endpoint : Endpoint; + topics : [TopicCategory]; +} + +table Topic +{ + category : TopicCategory; + sdp : string; + status : string; //"connecting", "connected", "disconnected" +} + +table TopicSubscribe +{ + items : [SubscribeItem]; +} + +table TopicNotification +{ + endpoint : Endpoint; + topic : Topic; +} + +table TopicPush +{ + endpoint : Endpoint; + topic : Topic; +} + +root_type TopicSubscribe; +root_type TopicNotification; +root_type TopicPush; \ No newline at end of file diff --git a/schema/webstreamer.fbs b/schema/webstreamer.fbs new file mode 100644 index 0000000..49ee005 --- /dev/null +++ b/schema/webstreamer.fbs @@ -0,0 +1,106 @@ +include "webrtc.fbs"; + +namespace webstreamer; + +enum EndpointType : int8 +{ + RTSPCLIENT, + WEBRTC +} + +table EndpointBase +{ + id : string; + type : EndpointType; +} + +table RtspClient +{ + base : EndpointBase; + url : string; +} + +table Webrtc +{ + base : EndpointBase; + group : string; + connection : string; + sdp_role : webstreamer.webrtc.SdpRole; + audio_stream_mode : webstreamer.webrtc.StreamMode; + video_stream_mode : webstreamer.webrtc.StreamMode; +} + +table Endpoint +{ + rtspclient : RtspClient; + webrtc : Webrtc; +} + +enum VideoCodec : int8 +{ + H264, + H265, + VP8 +} + +enum AudioCodec : int8 +{ + PCMA, + OPUS +} + +table Pipeline +{ + id : string; + video_codec : VideoCodec; + audio_codec : AudioCodec; +} + +table LiveStreamCreate +{ + pipeline : Pipeline; + endpoint : Endpoint; +} + +table LiveStreamDestroy +{ + id : string; +} + +table LiveStreamAddEndpoint +{ + id : string; + endpoint : Endpoint; +} + +table LiveStreamAddEndpoints +{ + id : string; + endpoints : [Endpoint]; +} + +table LiveStreamRemoveEndpoint +{ + id : string; //livestream id + endpoint_id : string; //endpoint id +} + +table LiveStreamRemoveEndpoints +{ + id : string; //livestream id + endpoint_ids : [string]; //endpoint ids +} + +table LiveStreamError +{ + code : int8; + reason : string; +} + +root_type LiveStreamCreate; +root_type LiveStreamDestroy; +root_type LiveStreamAddEndpoint; +root_type LiveStreamRemoveEndpoint; +root_type LiveStreamAddEndpoints; +root_type LiveStreamRemoveEndpoints; +root_type LiveStreamError; \ No newline at end of file From bd4166a681695977ece9abd6d5ed328663e1c47a Mon Sep 17 00:00:00 2001 From: daihongjun Date: Tue, 30 Jan 2018 17:17:57 +0800 Subject: [PATCH 02/18] flatbuffers schema files add and build --- lib/flatbuffers/webrtc_generated.h | 505 +++++++++++ lib/flatbuffers/webstreamer_generated.h | 915 ++++++++++++++++++++ lib/{webstreamer.cpp => libwebstreamer.cpp} | 0 lib/{webstreamer.hpp => libwebstreamer.hpp} | 0 4 files changed, 1420 insertions(+) create mode 100644 lib/flatbuffers/webrtc_generated.h create mode 100644 lib/flatbuffers/webstreamer_generated.h rename lib/{webstreamer.cpp => libwebstreamer.cpp} (100%) rename lib/{webstreamer.hpp => libwebstreamer.hpp} (100%) diff --git a/lib/flatbuffers/webrtc_generated.h b/lib/flatbuffers/webrtc_generated.h new file mode 100644 index 0000000..65ff375 --- /dev/null +++ b/lib/flatbuffers/webrtc_generated.h @@ -0,0 +1,505 @@ +// automatically generated by the FlatBuffers compiler, do not modify + + +#ifndef FLATBUFFERS_GENERATED_WEBRTC_WEBSTREAMER_WEBRTC_TOPICS_H_ +#define FLATBUFFERS_GENERATED_WEBRTC_WEBSTREAMER_WEBRTC_TOPICS_H_ + +#include "flatbuffers/flatbuffers.h" + +namespace webstreamer { +namespace webrtc { +namespace topics { + +struct Endpoint; + +struct SubscribeItem; + +struct Topic; + +struct TopicSubscribe; + +struct TopicNotification; + +struct TopicPush; + +} // namespace topics + +enum SdpRole { + SdpRole_OFFER = 0, + SdpRole_ANSWER = 1, + SdpRole_ANY = 2, + SdpRole_MIN = SdpRole_OFFER, + SdpRole_MAX = SdpRole_ANY +}; + +inline SdpRole (&EnumValuesSdpRole())[3] { + static SdpRole values[] = { + SdpRole_OFFER, + SdpRole_ANSWER, + SdpRole_ANY + }; + return values; +} + +inline const char **EnumNamesSdpRole() { + static const char *names[] = { + "OFFER", + "ANSWER", + "ANY", + nullptr + }; + return names; +} + +inline const char *EnumNameSdpRole(SdpRole e) { + const size_t index = static_cast(e); + return EnumNamesSdpRole()[index]; +} + +enum StreamMode { + StreamMode_SENDONLY = 0, + StreamMode_RECVONLY = 1, + StreamMode_SENDRECV = 2, + StreamMode_MIN = StreamMode_SENDONLY, + StreamMode_MAX = StreamMode_SENDRECV +}; + +inline StreamMode (&EnumValuesStreamMode())[3] { + static StreamMode values[] = { + StreamMode_SENDONLY, + StreamMode_RECVONLY, + StreamMode_SENDRECV + }; + return values; +} + +inline const char **EnumNamesStreamMode() { + static const char *names[] = { + "SENDONLY", + "RECVONLY", + "SENDRECV", + nullptr + }; + return names; +} + +inline const char *EnumNameStreamMode(StreamMode e) { + const size_t index = static_cast(e); + return EnumNamesStreamMode()[index]; +} + +namespace topics { + +enum TopicCategory { + TopicCategory_SDP = 0, + TopicCategory_STATUS = 1, + TopicCategory_MIN = TopicCategory_SDP, + TopicCategory_MAX = TopicCategory_STATUS +}; + +inline TopicCategory (&EnumValuesTopicCategory())[2] { + static TopicCategory values[] = { + TopicCategory_SDP, + TopicCategory_STATUS + }; + return values; +} + +inline const char **EnumNamesTopicCategory() { + static const char *names[] = { + "SDP", + "STATUS", + nullptr + }; + return names; +} + +inline const char *EnumNameTopicCategory(TopicCategory e) { + const size_t index = static_cast(e); + return EnumNamesTopicCategory()[index]; +} + +struct Endpoint FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_SDP_ROLE = 4, + VT_CONNECTION = 6, + VT_GROUP = 8 + }; + webstreamer::webrtc::SdpRole sdp_role() const { + return static_cast(GetField(VT_SDP_ROLE, 0)); + } + const flatbuffers::String *connection() const { + return GetPointer(VT_CONNECTION); + } + const flatbuffers::String *group() const { + return GetPointer(VT_GROUP); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_SDP_ROLE) && + VerifyOffset(verifier, VT_CONNECTION) && + verifier.Verify(connection()) && + VerifyOffset(verifier, VT_GROUP) && + verifier.Verify(group()) && + verifier.EndTable(); + } +}; + +struct EndpointBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_sdp_role(webstreamer::webrtc::SdpRole sdp_role) { + fbb_.AddElement(Endpoint::VT_SDP_ROLE, static_cast(sdp_role), 0); + } + void add_connection(flatbuffers::Offset connection) { + fbb_.AddOffset(Endpoint::VT_CONNECTION, connection); + } + void add_group(flatbuffers::Offset group) { + fbb_.AddOffset(Endpoint::VT_GROUP, group); + } + explicit EndpointBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + EndpointBuilder &operator=(const EndpointBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateEndpoint( + flatbuffers::FlatBufferBuilder &_fbb, + webstreamer::webrtc::SdpRole sdp_role = webstreamer::webrtc::SdpRole_OFFER, + flatbuffers::Offset connection = 0, + flatbuffers::Offset group = 0) { + EndpointBuilder builder_(_fbb); + builder_.add_group(group); + builder_.add_connection(connection); + builder_.add_sdp_role(sdp_role); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateEndpointDirect( + flatbuffers::FlatBufferBuilder &_fbb, + webstreamer::webrtc::SdpRole sdp_role = webstreamer::webrtc::SdpRole_OFFER, + const char *connection = nullptr, + const char *group = nullptr) { + return webstreamer::webrtc::topics::CreateEndpoint( + _fbb, + sdp_role, + connection ? _fbb.CreateString(connection) : 0, + group ? _fbb.CreateString(group) : 0); +} + +struct SubscribeItem FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ENDPOINT = 4, + VT_TOPICS = 6 + }; + const Endpoint *endpoint() const { + return GetPointer(VT_ENDPOINT); + } + const flatbuffers::Vector *topics() const { + return GetPointer *>(VT_TOPICS); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ENDPOINT) && + verifier.VerifyTable(endpoint()) && + VerifyOffset(verifier, VT_TOPICS) && + verifier.Verify(topics()) && + verifier.EndTable(); + } +}; + +struct SubscribeItemBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_endpoint(flatbuffers::Offset endpoint) { + fbb_.AddOffset(SubscribeItem::VT_ENDPOINT, endpoint); + } + void add_topics(flatbuffers::Offset> topics) { + fbb_.AddOffset(SubscribeItem::VT_TOPICS, topics); + } + explicit SubscribeItemBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + SubscribeItemBuilder &operator=(const SubscribeItemBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSubscribeItem( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset endpoint = 0, + flatbuffers::Offset> topics = 0) { + SubscribeItemBuilder builder_(_fbb); + builder_.add_topics(topics); + builder_.add_endpoint(endpoint); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateSubscribeItemDirect( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset endpoint = 0, + const std::vector *topics = nullptr) { + return webstreamer::webrtc::topics::CreateSubscribeItem( + _fbb, + endpoint, + topics ? _fbb.CreateVector(*topics) : 0); +} + +struct Topic FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_CATEGORY = 4, + VT_SDP = 6, + VT_STATUS = 8 + }; + TopicCategory category() const { + return static_cast(GetField(VT_CATEGORY, 0)); + } + const flatbuffers::String *sdp() const { + return GetPointer(VT_SDP); + } + const flatbuffers::String *status() const { + return GetPointer(VT_STATUS); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_CATEGORY) && + VerifyOffset(verifier, VT_SDP) && + verifier.Verify(sdp()) && + VerifyOffset(verifier, VT_STATUS) && + verifier.Verify(status()) && + verifier.EndTable(); + } +}; + +struct TopicBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_category(TopicCategory category) { + fbb_.AddElement(Topic::VT_CATEGORY, static_cast(category), 0); + } + void add_sdp(flatbuffers::Offset sdp) { + fbb_.AddOffset(Topic::VT_SDP, sdp); + } + void add_status(flatbuffers::Offset status) { + fbb_.AddOffset(Topic::VT_STATUS, status); + } + explicit TopicBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + TopicBuilder &operator=(const TopicBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTopic( + flatbuffers::FlatBufferBuilder &_fbb, + TopicCategory category = TopicCategory_SDP, + flatbuffers::Offset sdp = 0, + flatbuffers::Offset status = 0) { + TopicBuilder builder_(_fbb); + builder_.add_status(status); + builder_.add_sdp(sdp); + builder_.add_category(category); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateTopicDirect( + flatbuffers::FlatBufferBuilder &_fbb, + TopicCategory category = TopicCategory_SDP, + const char *sdp = nullptr, + const char *status = nullptr) { + return webstreamer::webrtc::topics::CreateTopic( + _fbb, + category, + sdp ? _fbb.CreateString(sdp) : 0, + status ? _fbb.CreateString(status) : 0); +} + +struct TopicSubscribe FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ITEMS = 4 + }; + const flatbuffers::Vector> *items() const { + return GetPointer> *>(VT_ITEMS); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ITEMS) && + verifier.Verify(items()) && + verifier.VerifyVectorOfTables(items()) && + verifier.EndTable(); + } +}; + +struct TopicSubscribeBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_items(flatbuffers::Offset>> items) { + fbb_.AddOffset(TopicSubscribe::VT_ITEMS, items); + } + explicit TopicSubscribeBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + TopicSubscribeBuilder &operator=(const TopicSubscribeBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTopicSubscribe( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset>> items = 0) { + TopicSubscribeBuilder builder_(_fbb); + builder_.add_items(items); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateTopicSubscribeDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector> *items = nullptr) { + return webstreamer::webrtc::topics::CreateTopicSubscribe( + _fbb, + items ? _fbb.CreateVector>(*items) : 0); +} + +struct TopicNotification FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ENDPOINT = 4, + VT_TOPIC = 6 + }; + const Endpoint *endpoint() const { + return GetPointer(VT_ENDPOINT); + } + const Topic *topic() const { + return GetPointer(VT_TOPIC); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ENDPOINT) && + verifier.VerifyTable(endpoint()) && + VerifyOffset(verifier, VT_TOPIC) && + verifier.VerifyTable(topic()) && + verifier.EndTable(); + } +}; + +struct TopicNotificationBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_endpoint(flatbuffers::Offset endpoint) { + fbb_.AddOffset(TopicNotification::VT_ENDPOINT, endpoint); + } + void add_topic(flatbuffers::Offset topic) { + fbb_.AddOffset(TopicNotification::VT_TOPIC, topic); + } + explicit TopicNotificationBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + TopicNotificationBuilder &operator=(const TopicNotificationBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTopicNotification( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset endpoint = 0, + flatbuffers::Offset topic = 0) { + TopicNotificationBuilder builder_(_fbb); + builder_.add_topic(topic); + builder_.add_endpoint(endpoint); + return builder_.Finish(); +} + +struct TopicPush FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ENDPOINT = 4, + VT_TOPIC = 6 + }; + const Endpoint *endpoint() const { + return GetPointer(VT_ENDPOINT); + } + const Topic *topic() const { + return GetPointer(VT_TOPIC); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ENDPOINT) && + verifier.VerifyTable(endpoint()) && + VerifyOffset(verifier, VT_TOPIC) && + verifier.VerifyTable(topic()) && + verifier.EndTable(); + } +}; + +struct TopicPushBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_endpoint(flatbuffers::Offset endpoint) { + fbb_.AddOffset(TopicPush::VT_ENDPOINT, endpoint); + } + void add_topic(flatbuffers::Offset topic) { + fbb_.AddOffset(TopicPush::VT_TOPIC, topic); + } + explicit TopicPushBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + TopicPushBuilder &operator=(const TopicPushBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTopicPush( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset endpoint = 0, + flatbuffers::Offset topic = 0) { + TopicPushBuilder builder_(_fbb); + builder_.add_topic(topic); + builder_.add_endpoint(endpoint); + return builder_.Finish(); +} + +inline const webstreamer::webrtc::topics::TopicPush *GetTopicPush(const void *buf) { + return flatbuffers::GetRoot(buf); +} + +inline bool VerifyTopicPushBuffer( + flatbuffers::Verifier &verifier) { + return verifier.VerifyBuffer(nullptr); +} + +inline void FinishTopicPushBuffer( + flatbuffers::FlatBufferBuilder &fbb, + flatbuffers::Offset root) { + fbb.Finish(root); +} + +} // namespace topics +} // namespace webrtc +} // namespace webstreamer + +#endif // FLATBUFFERS_GENERATED_WEBRTC_WEBSTREAMER_WEBRTC_TOPICS_H_ diff --git a/lib/flatbuffers/webstreamer_generated.h b/lib/flatbuffers/webstreamer_generated.h new file mode 100644 index 0000000..f1c139b --- /dev/null +++ b/lib/flatbuffers/webstreamer_generated.h @@ -0,0 +1,915 @@ +// automatically generated by the FlatBuffers compiler, do not modify + + +#ifndef FLATBUFFERS_GENERATED_WEBSTREAMER_WEBSTREAMER_H_ +#define FLATBUFFERS_GENERATED_WEBSTREAMER_WEBSTREAMER_H_ + +#include "flatbuffers/flatbuffers.h" + +#include "webrtc_generated.h" + +namespace webstreamer { + +struct EndpointBase; + +struct RtspClient; + +struct Webrtc; + +struct Endpoint; + +struct Pipeline; + +struct LiveStreamCreate; + +struct LiveStreamDestroy; + +struct LiveStreamAddEndpoint; + +struct LiveStreamAddEndpoints; + +struct LiveStreamRemoveEndpoint; + +struct LiveStreamRemoveEndpoints; + +struct LiveStreamError; + +enum EndpointType { + EndpointType_RTSPCLIENT = 0, + EndpointType_WEBRTC = 1, + EndpointType_MIN = EndpointType_RTSPCLIENT, + EndpointType_MAX = EndpointType_WEBRTC +}; + +inline EndpointType (&EnumValuesEndpointType())[2] { + static EndpointType values[] = { + EndpointType_RTSPCLIENT, + EndpointType_WEBRTC + }; + return values; +} + +inline const char **EnumNamesEndpointType() { + static const char *names[] = { + "RTSPCLIENT", + "WEBRTC", + nullptr + }; + return names; +} + +inline const char *EnumNameEndpointType(EndpointType e) { + const size_t index = static_cast(e); + return EnumNamesEndpointType()[index]; +} + +enum VideoCodec { + VideoCodec_H264 = 0, + VideoCodec_H265 = 1, + VideoCodec_VP8 = 2, + VideoCodec_MIN = VideoCodec_H264, + VideoCodec_MAX = VideoCodec_VP8 +}; + +inline VideoCodec (&EnumValuesVideoCodec())[3] { + static VideoCodec values[] = { + VideoCodec_H264, + VideoCodec_H265, + VideoCodec_VP8 + }; + return values; +} + +inline const char **EnumNamesVideoCodec() { + static const char *names[] = { + "H264", + "H265", + "VP8", + nullptr + }; + return names; +} + +inline const char *EnumNameVideoCodec(VideoCodec e) { + const size_t index = static_cast(e); + return EnumNamesVideoCodec()[index]; +} + +enum AudioCodec { + AudioCodec_PCMA = 0, + AudioCodec_OPUS = 1, + AudioCodec_MIN = AudioCodec_PCMA, + AudioCodec_MAX = AudioCodec_OPUS +}; + +inline AudioCodec (&EnumValuesAudioCodec())[2] { + static AudioCodec values[] = { + AudioCodec_PCMA, + AudioCodec_OPUS + }; + return values; +} + +inline const char **EnumNamesAudioCodec() { + static const char *names[] = { + "PCMA", + "OPUS", + nullptr + }; + return names; +} + +inline const char *EnumNameAudioCodec(AudioCodec e) { + const size_t index = static_cast(e); + return EnumNamesAudioCodec()[index]; +} + +struct EndpointBase FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ID = 4, + VT_TYPE = 6 + }; + const flatbuffers::String *id() const { + return GetPointer(VT_ID); + } + EndpointType type() const { + return static_cast(GetField(VT_TYPE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ID) && + verifier.Verify(id()) && + VerifyField(verifier, VT_TYPE) && + verifier.EndTable(); + } +}; + +struct EndpointBaseBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_id(flatbuffers::Offset id) { + fbb_.AddOffset(EndpointBase::VT_ID, id); + } + void add_type(EndpointType type) { + fbb_.AddElement(EndpointBase::VT_TYPE, static_cast(type), 0); + } + explicit EndpointBaseBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + EndpointBaseBuilder &operator=(const EndpointBaseBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateEndpointBase( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset id = 0, + EndpointType type = EndpointType_RTSPCLIENT) { + EndpointBaseBuilder builder_(_fbb); + builder_.add_id(id); + builder_.add_type(type); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateEndpointBaseDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *id = nullptr, + EndpointType type = EndpointType_RTSPCLIENT) { + return webstreamer::CreateEndpointBase( + _fbb, + id ? _fbb.CreateString(id) : 0, + type); +} + +struct RtspClient FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_BASE = 4, + VT_URL = 6 + }; + const EndpointBase *base() const { + return GetPointer(VT_BASE); + } + const flatbuffers::String *url() const { + return GetPointer(VT_URL); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_BASE) && + verifier.VerifyTable(base()) && + VerifyOffset(verifier, VT_URL) && + verifier.Verify(url()) && + verifier.EndTable(); + } +}; + +struct RtspClientBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_base(flatbuffers::Offset base) { + fbb_.AddOffset(RtspClient::VT_BASE, base); + } + void add_url(flatbuffers::Offset url) { + fbb_.AddOffset(RtspClient::VT_URL, url); + } + explicit RtspClientBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + RtspClientBuilder &operator=(const RtspClientBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateRtspClient( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset base = 0, + flatbuffers::Offset url = 0) { + RtspClientBuilder builder_(_fbb); + builder_.add_url(url); + builder_.add_base(base); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateRtspClientDirect( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset base = 0, + const char *url = nullptr) { + return webstreamer::CreateRtspClient( + _fbb, + base, + url ? _fbb.CreateString(url) : 0); +} + +struct Webrtc FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_BASE = 4, + VT_GROUP = 6, + VT_CONNECTION = 8, + VT_SDP_ROLE = 10, + VT_AUDIO_STREAM_MODE = 12, + VT_VIDEO_STREAM_MODE = 14 + }; + const EndpointBase *base() const { + return GetPointer(VT_BASE); + } + const flatbuffers::String *group() const { + return GetPointer(VT_GROUP); + } + const flatbuffers::String *connection() const { + return GetPointer(VT_CONNECTION); + } + webstreamer::webrtc::SdpRole sdp_role() const { + return static_cast(GetField(VT_SDP_ROLE, 0)); + } + webstreamer::webrtc::StreamMode audio_stream_mode() const { + return static_cast(GetField(VT_AUDIO_STREAM_MODE, 0)); + } + webstreamer::webrtc::StreamMode video_stream_mode() const { + return static_cast(GetField(VT_VIDEO_STREAM_MODE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_BASE) && + verifier.VerifyTable(base()) && + VerifyOffset(verifier, VT_GROUP) && + verifier.Verify(group()) && + VerifyOffset(verifier, VT_CONNECTION) && + verifier.Verify(connection()) && + VerifyField(verifier, VT_SDP_ROLE) && + VerifyField(verifier, VT_AUDIO_STREAM_MODE) && + VerifyField(verifier, VT_VIDEO_STREAM_MODE) && + verifier.EndTable(); + } +}; + +struct WebrtcBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_base(flatbuffers::Offset base) { + fbb_.AddOffset(Webrtc::VT_BASE, base); + } + void add_group(flatbuffers::Offset group) { + fbb_.AddOffset(Webrtc::VT_GROUP, group); + } + void add_connection(flatbuffers::Offset connection) { + fbb_.AddOffset(Webrtc::VT_CONNECTION, connection); + } + void add_sdp_role(webstreamer::webrtc::SdpRole sdp_role) { + fbb_.AddElement(Webrtc::VT_SDP_ROLE, static_cast(sdp_role), 0); + } + void add_audio_stream_mode(webstreamer::webrtc::StreamMode audio_stream_mode) { + fbb_.AddElement(Webrtc::VT_AUDIO_STREAM_MODE, static_cast(audio_stream_mode), 0); + } + void add_video_stream_mode(webstreamer::webrtc::StreamMode video_stream_mode) { + fbb_.AddElement(Webrtc::VT_VIDEO_STREAM_MODE, static_cast(video_stream_mode), 0); + } + explicit WebrtcBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + WebrtcBuilder &operator=(const WebrtcBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateWebrtc( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset base = 0, + flatbuffers::Offset group = 0, + flatbuffers::Offset connection = 0, + webstreamer::webrtc::SdpRole sdp_role = webstreamer::webrtc::SdpRole_OFFER, + webstreamer::webrtc::StreamMode audio_stream_mode = webstreamer::webrtc::StreamMode_SENDONLY, + webstreamer::webrtc::StreamMode video_stream_mode = webstreamer::webrtc::StreamMode_SENDONLY) { + WebrtcBuilder builder_(_fbb); + builder_.add_connection(connection); + builder_.add_group(group); + builder_.add_base(base); + builder_.add_video_stream_mode(video_stream_mode); + builder_.add_audio_stream_mode(audio_stream_mode); + builder_.add_sdp_role(sdp_role); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateWebrtcDirect( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset base = 0, + const char *group = nullptr, + const char *connection = nullptr, + webstreamer::webrtc::SdpRole sdp_role = webstreamer::webrtc::SdpRole_OFFER, + webstreamer::webrtc::StreamMode audio_stream_mode = webstreamer::webrtc::StreamMode_SENDONLY, + webstreamer::webrtc::StreamMode video_stream_mode = webstreamer::webrtc::StreamMode_SENDONLY) { + return webstreamer::CreateWebrtc( + _fbb, + base, + group ? _fbb.CreateString(group) : 0, + connection ? _fbb.CreateString(connection) : 0, + sdp_role, + audio_stream_mode, + video_stream_mode); +} + +struct Endpoint FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_RTSPCLIENT = 4, + VT_WEBRTC = 6 + }; + const RtspClient *rtspclient() const { + return GetPointer(VT_RTSPCLIENT); + } + const Webrtc *webrtc() const { + return GetPointer(VT_WEBRTC); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_RTSPCLIENT) && + verifier.VerifyTable(rtspclient()) && + VerifyOffset(verifier, VT_WEBRTC) && + verifier.VerifyTable(webrtc()) && + verifier.EndTable(); + } +}; + +struct EndpointBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_rtspclient(flatbuffers::Offset rtspclient) { + fbb_.AddOffset(Endpoint::VT_RTSPCLIENT, rtspclient); + } + void add_webrtc(flatbuffers::Offset webrtc) { + fbb_.AddOffset(Endpoint::VT_WEBRTC, webrtc); + } + explicit EndpointBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + EndpointBuilder &operator=(const EndpointBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateEndpoint( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset rtspclient = 0, + flatbuffers::Offset webrtc = 0) { + EndpointBuilder builder_(_fbb); + builder_.add_webrtc(webrtc); + builder_.add_rtspclient(rtspclient); + return builder_.Finish(); +} + +struct Pipeline FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ID = 4, + VT_VIDEO_CODEC = 6, + VT_AUDIO_CODEC = 8 + }; + const flatbuffers::String *id() const { + return GetPointer(VT_ID); + } + VideoCodec video_codec() const { + return static_cast(GetField(VT_VIDEO_CODEC, 0)); + } + AudioCodec audio_codec() const { + return static_cast(GetField(VT_AUDIO_CODEC, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ID) && + verifier.Verify(id()) && + VerifyField(verifier, VT_VIDEO_CODEC) && + VerifyField(verifier, VT_AUDIO_CODEC) && + verifier.EndTable(); + } +}; + +struct PipelineBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_id(flatbuffers::Offset id) { + fbb_.AddOffset(Pipeline::VT_ID, id); + } + void add_video_codec(VideoCodec video_codec) { + fbb_.AddElement(Pipeline::VT_VIDEO_CODEC, static_cast(video_codec), 0); + } + void add_audio_codec(AudioCodec audio_codec) { + fbb_.AddElement(Pipeline::VT_AUDIO_CODEC, static_cast(audio_codec), 0); + } + explicit PipelineBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + PipelineBuilder &operator=(const PipelineBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreatePipeline( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset id = 0, + VideoCodec video_codec = VideoCodec_H264, + AudioCodec audio_codec = AudioCodec_PCMA) { + PipelineBuilder builder_(_fbb); + builder_.add_id(id); + builder_.add_audio_codec(audio_codec); + builder_.add_video_codec(video_codec); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreatePipelineDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *id = nullptr, + VideoCodec video_codec = VideoCodec_H264, + AudioCodec audio_codec = AudioCodec_PCMA) { + return webstreamer::CreatePipeline( + _fbb, + id ? _fbb.CreateString(id) : 0, + video_codec, + audio_codec); +} + +struct LiveStreamCreate FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_PIPELINE = 4, + VT_ENDPOINT = 6 + }; + const Pipeline *pipeline() const { + return GetPointer(VT_PIPELINE); + } + const Endpoint *endpoint() const { + return GetPointer(VT_ENDPOINT); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_PIPELINE) && + verifier.VerifyTable(pipeline()) && + VerifyOffset(verifier, VT_ENDPOINT) && + verifier.VerifyTable(endpoint()) && + verifier.EndTable(); + } +}; + +struct LiveStreamCreateBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_pipeline(flatbuffers::Offset pipeline) { + fbb_.AddOffset(LiveStreamCreate::VT_PIPELINE, pipeline); + } + void add_endpoint(flatbuffers::Offset endpoint) { + fbb_.AddOffset(LiveStreamCreate::VT_ENDPOINT, endpoint); + } + explicit LiveStreamCreateBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + LiveStreamCreateBuilder &operator=(const LiveStreamCreateBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLiveStreamCreate( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset pipeline = 0, + flatbuffers::Offset endpoint = 0) { + LiveStreamCreateBuilder builder_(_fbb); + builder_.add_endpoint(endpoint); + builder_.add_pipeline(pipeline); + return builder_.Finish(); +} + +struct LiveStreamDestroy FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ID = 4 + }; + const flatbuffers::String *id() const { + return GetPointer(VT_ID); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ID) && + verifier.Verify(id()) && + verifier.EndTable(); + } +}; + +struct LiveStreamDestroyBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_id(flatbuffers::Offset id) { + fbb_.AddOffset(LiveStreamDestroy::VT_ID, id); + } + explicit LiveStreamDestroyBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + LiveStreamDestroyBuilder &operator=(const LiveStreamDestroyBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLiveStreamDestroy( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset id = 0) { + LiveStreamDestroyBuilder builder_(_fbb); + builder_.add_id(id); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateLiveStreamDestroyDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *id = nullptr) { + return webstreamer::CreateLiveStreamDestroy( + _fbb, + id ? _fbb.CreateString(id) : 0); +} + +struct LiveStreamAddEndpoint FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ID = 4, + VT_ENDPOINT = 6 + }; + const flatbuffers::String *id() const { + return GetPointer(VT_ID); + } + const Endpoint *endpoint() const { + return GetPointer(VT_ENDPOINT); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ID) && + verifier.Verify(id()) && + VerifyOffset(verifier, VT_ENDPOINT) && + verifier.VerifyTable(endpoint()) && + verifier.EndTable(); + } +}; + +struct LiveStreamAddEndpointBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_id(flatbuffers::Offset id) { + fbb_.AddOffset(LiveStreamAddEndpoint::VT_ID, id); + } + void add_endpoint(flatbuffers::Offset endpoint) { + fbb_.AddOffset(LiveStreamAddEndpoint::VT_ENDPOINT, endpoint); + } + explicit LiveStreamAddEndpointBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + LiveStreamAddEndpointBuilder &operator=(const LiveStreamAddEndpointBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLiveStreamAddEndpoint( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset id = 0, + flatbuffers::Offset endpoint = 0) { + LiveStreamAddEndpointBuilder builder_(_fbb); + builder_.add_endpoint(endpoint); + builder_.add_id(id); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateLiveStreamAddEndpointDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *id = nullptr, + flatbuffers::Offset endpoint = 0) { + return webstreamer::CreateLiveStreamAddEndpoint( + _fbb, + id ? _fbb.CreateString(id) : 0, + endpoint); +} + +struct LiveStreamAddEndpoints FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ID = 4, + VT_ENDPOINTS = 6 + }; + const flatbuffers::String *id() const { + return GetPointer(VT_ID); + } + const flatbuffers::Vector> *endpoints() const { + return GetPointer> *>(VT_ENDPOINTS); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ID) && + verifier.Verify(id()) && + VerifyOffset(verifier, VT_ENDPOINTS) && + verifier.Verify(endpoints()) && + verifier.VerifyVectorOfTables(endpoints()) && + verifier.EndTable(); + } +}; + +struct LiveStreamAddEndpointsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_id(flatbuffers::Offset id) { + fbb_.AddOffset(LiveStreamAddEndpoints::VT_ID, id); + } + void add_endpoints(flatbuffers::Offset>> endpoints) { + fbb_.AddOffset(LiveStreamAddEndpoints::VT_ENDPOINTS, endpoints); + } + explicit LiveStreamAddEndpointsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + LiveStreamAddEndpointsBuilder &operator=(const LiveStreamAddEndpointsBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLiveStreamAddEndpoints( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset id = 0, + flatbuffers::Offset>> endpoints = 0) { + LiveStreamAddEndpointsBuilder builder_(_fbb); + builder_.add_endpoints(endpoints); + builder_.add_id(id); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateLiveStreamAddEndpointsDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *id = nullptr, + const std::vector> *endpoints = nullptr) { + return webstreamer::CreateLiveStreamAddEndpoints( + _fbb, + id ? _fbb.CreateString(id) : 0, + endpoints ? _fbb.CreateVector>(*endpoints) : 0); +} + +struct LiveStreamRemoveEndpoint FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ID = 4, + VT_ENDPOINT_ID = 6 + }; + const flatbuffers::String *id() const { + return GetPointer(VT_ID); + } + const flatbuffers::String *endpoint_id() const { + return GetPointer(VT_ENDPOINT_ID); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ID) && + verifier.Verify(id()) && + VerifyOffset(verifier, VT_ENDPOINT_ID) && + verifier.Verify(endpoint_id()) && + verifier.EndTable(); + } +}; + +struct LiveStreamRemoveEndpointBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_id(flatbuffers::Offset id) { + fbb_.AddOffset(LiveStreamRemoveEndpoint::VT_ID, id); + } + void add_endpoint_id(flatbuffers::Offset endpoint_id) { + fbb_.AddOffset(LiveStreamRemoveEndpoint::VT_ENDPOINT_ID, endpoint_id); + } + explicit LiveStreamRemoveEndpointBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + LiveStreamRemoveEndpointBuilder &operator=(const LiveStreamRemoveEndpointBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLiveStreamRemoveEndpoint( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset id = 0, + flatbuffers::Offset endpoint_id = 0) { + LiveStreamRemoveEndpointBuilder builder_(_fbb); + builder_.add_endpoint_id(endpoint_id); + builder_.add_id(id); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateLiveStreamRemoveEndpointDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *id = nullptr, + const char *endpoint_id = nullptr) { + return webstreamer::CreateLiveStreamRemoveEndpoint( + _fbb, + id ? _fbb.CreateString(id) : 0, + endpoint_id ? _fbb.CreateString(endpoint_id) : 0); +} + +struct LiveStreamRemoveEndpoints FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ID = 4, + VT_ENDPOINT_IDS = 6 + }; + const flatbuffers::String *id() const { + return GetPointer(VT_ID); + } + const flatbuffers::Vector> *endpoint_ids() const { + return GetPointer> *>(VT_ENDPOINT_IDS); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_ID) && + verifier.Verify(id()) && + VerifyOffset(verifier, VT_ENDPOINT_IDS) && + verifier.Verify(endpoint_ids()) && + verifier.VerifyVectorOfStrings(endpoint_ids()) && + verifier.EndTable(); + } +}; + +struct LiveStreamRemoveEndpointsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_id(flatbuffers::Offset id) { + fbb_.AddOffset(LiveStreamRemoveEndpoints::VT_ID, id); + } + void add_endpoint_ids(flatbuffers::Offset>> endpoint_ids) { + fbb_.AddOffset(LiveStreamRemoveEndpoints::VT_ENDPOINT_IDS, endpoint_ids); + } + explicit LiveStreamRemoveEndpointsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + LiveStreamRemoveEndpointsBuilder &operator=(const LiveStreamRemoveEndpointsBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLiveStreamRemoveEndpoints( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset id = 0, + flatbuffers::Offset>> endpoint_ids = 0) { + LiveStreamRemoveEndpointsBuilder builder_(_fbb); + builder_.add_endpoint_ids(endpoint_ids); + builder_.add_id(id); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateLiveStreamRemoveEndpointsDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *id = nullptr, + const std::vector> *endpoint_ids = nullptr) { + return webstreamer::CreateLiveStreamRemoveEndpoints( + _fbb, + id ? _fbb.CreateString(id) : 0, + endpoint_ids ? _fbb.CreateVector>(*endpoint_ids) : 0); +} + +struct LiveStreamError FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_CODE = 4, + VT_REASON = 6 + }; + int8_t code() const { + return GetField(VT_CODE, 0); + } + const flatbuffers::String *reason() const { + return GetPointer(VT_REASON); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_CODE) && + VerifyOffset(verifier, VT_REASON) && + verifier.Verify(reason()) && + verifier.EndTable(); + } +}; + +struct LiveStreamErrorBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_code(int8_t code) { + fbb_.AddElement(LiveStreamError::VT_CODE, code, 0); + } + void add_reason(flatbuffers::Offset reason) { + fbb_.AddOffset(LiveStreamError::VT_REASON, reason); + } + explicit LiveStreamErrorBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + LiveStreamErrorBuilder &operator=(const LiveStreamErrorBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLiveStreamError( + flatbuffers::FlatBufferBuilder &_fbb, + int8_t code = 0, + flatbuffers::Offset reason = 0) { + LiveStreamErrorBuilder builder_(_fbb); + builder_.add_reason(reason); + builder_.add_code(code); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateLiveStreamErrorDirect( + flatbuffers::FlatBufferBuilder &_fbb, + int8_t code = 0, + const char *reason = nullptr) { + return webstreamer::CreateLiveStreamError( + _fbb, + code, + reason ? _fbb.CreateString(reason) : 0); +} + +inline const webstreamer::LiveStreamError *GetLiveStreamError(const void *buf) { + return flatbuffers::GetRoot(buf); +} + +inline bool VerifyLiveStreamErrorBuffer( + flatbuffers::Verifier &verifier) { + return verifier.VerifyBuffer(nullptr); +} + +inline void FinishLiveStreamErrorBuffer( + flatbuffers::FlatBufferBuilder &fbb, + flatbuffers::Offset root) { + fbb.Finish(root); +} + +} // namespace webstreamer + +#endif // FLATBUFFERS_GENERATED_WEBSTREAMER_WEBSTREAMER_H_ diff --git a/lib/webstreamer.cpp b/lib/libwebstreamer.cpp similarity index 100% rename from lib/webstreamer.cpp rename to lib/libwebstreamer.cpp diff --git a/lib/webstreamer.hpp b/lib/libwebstreamer.hpp similarity index 100% rename from lib/webstreamer.hpp rename to lib/libwebstreamer.hpp From 4870b7d26b54292c94ecba96b51cc4ebc81fe72a Mon Sep 17 00:00:00 2001 From: daihongjun Date: Tue, 30 Jan 2018 17:20:19 +0800 Subject: [PATCH 03/18] flatbuffers --- CMakelists.txt | 5 +++-- build.bat | 10 ++++++++-- lib/libwebstreamer.cpp | 2 +- lib/plugin.cpp | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CMakelists.txt b/CMakelists.txt index 3db90cc..faea3d7 100644 --- a/CMakelists.txt +++ b/CMakelists.txt @@ -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} @@ -31,4 +32,4 @@ install(TARGETS libwebstreamer ARCHIVE DESTINATION lib RUNTIME DESTINATION bin ) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/libwebstreamer.h DESTINATION include ) \ No newline at end of file +INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/libwebstreamer.hpp DESTINATION include ) \ No newline at end of file diff --git a/build.bat b/build.bat index 3cabda0..6251288 100644 --- a/build.bat +++ b/build.bat @@ -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 \ No newline at end of file +#cmake --build . --target INSTALL --config Debug -- /p:Platform=x64 +popd +pause \ No newline at end of file diff --git a/lib/libwebstreamer.cpp b/lib/libwebstreamer.cpp index 29deaca..4ed5a36 100644 --- a/lib/libwebstreamer.cpp +++ b/lib/libwebstreamer.cpp @@ -1,6 +1,6 @@ #include #include -#include "webstreamer.hpp" +#include "libwebstreamer.hpp" #include LIBWEBSTREAMER_NS_BEGIN diff --git a/lib/plugin.cpp b/lib/plugin.cpp index 9b34a82..c866ebe 100644 --- a/lib/plugin.cpp +++ b/lib/plugin.cpp @@ -78,7 +78,7 @@ ////////////////////////////////// #include "node-plugin-proto.h" -#include "webstreamer.hpp" +#include "libwebstreamer.hpp" USING_LIBWEBSTREAMER_NS static void init(const void* self, const void* data, size_t size) From 14bd95f253c69c6d011c04a10b86779587bb6d94 Mon Sep 17 00:00:00 2001 From: daihongjun Date: Wed, 31 Jan 2018 14:16:58 +0800 Subject: [PATCH 04/18] dispatcher --- lib/pipeline/framework/endpoint.cpp | 0 lib/pipeline/framework/endpoint.hpp | 0 lib/pipeline/framework/pipeline.cpp | 0 lib/pipeline/framework/pipeline.hpp | 12 ++++++++++++ lib/pipeline/pipeline_manager.cpp | 12 ++++++++++++ lib/pipeline/pipeline_manager.hpp | 16 ++++++++++++++++ 6 files changed, 40 insertions(+) create mode 100644 lib/pipeline/framework/endpoint.cpp create mode 100644 lib/pipeline/framework/endpoint.hpp create mode 100644 lib/pipeline/framework/pipeline.cpp create mode 100644 lib/pipeline/framework/pipeline.hpp create mode 100644 lib/pipeline/pipeline_manager.cpp create mode 100644 lib/pipeline/pipeline_manager.hpp diff --git a/lib/pipeline/framework/endpoint.cpp b/lib/pipeline/framework/endpoint.cpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/pipeline/framework/endpoint.hpp b/lib/pipeline/framework/endpoint.hpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/pipeline/framework/pipeline.cpp b/lib/pipeline/framework/pipeline.cpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/pipeline/framework/pipeline.hpp b/lib/pipeline/framework/pipeline.hpp new file mode 100644 index 0000000..1a354ec --- /dev/null +++ b/lib/pipeline/framework/pipeline.hpp @@ -0,0 +1,12 @@ +#ifndef LIBWEBSTREAMER_PIPELINE_HPP +#define LIBWEBSTREAMER_PIPELINE_HPP + +namespace libwebstreamer +{ + namespace pipeline + { + + } +} + +#endif \ No newline at end of file diff --git a/lib/pipeline/pipeline_manager.cpp b/lib/pipeline/pipeline_manager.cpp new file mode 100644 index 0000000..e6d05eb --- /dev/null +++ b/lib/pipeline/pipeline_manager.cpp @@ -0,0 +1,12 @@ +#include + +namespace libwebstreamer +{ + namespace pipeline + { + void PipelineManager::on_call(const void* self, const void* context, const void* data, size_t size) + { + //TODO + } + } +} \ No newline at end of file diff --git a/lib/pipeline/pipeline_manager.hpp b/lib/pipeline/pipeline_manager.hpp new file mode 100644 index 0000000..a344622 --- /dev/null +++ b/lib/pipeline/pipeline_manager.hpp @@ -0,0 +1,16 @@ +#ifndef LIBWEBSTREAMER_PIPELINE_MANAGER_HPP +#define LIBWEBSTREAMER_PIPELINE_MANAGER_HPP + +namespace libwebstreamer +{ + namespace pipeline + { + class PipelineManager + { + public: + void on_call(const void* self, const void* context, const void* data, size_t size); + }; + } +} + +#endif \ No newline at end of file From fd721b17f04af303b780c4435655968ff0b658b8 Mon Sep 17 00:00:00 2001 From: daihongjun Date: Wed, 31 Jan 2018 14:19:23 +0800 Subject: [PATCH 05/18] dispatcher --- lib/dispatcher.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ lib/dispatcher.hpp | 6 +++-- lib/libwebstreamer.cpp | 2 +- lib/libwebstreamer.hpp | 2 +- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/lib/dispatcher.cpp b/lib/dispatcher.cpp index 7d46730..3d01a9c 100644 --- a/lib/dispatcher.cpp +++ b/lib/dispatcher.cpp @@ -1,3 +1,54 @@ +#include +#include +#include "libwebstreamer.hpp" +#include "dispatcher.hpp" +#include + +namespace libwebstreamer +{ + namespace dispatcher + { + static std::unique_ptr call_queue(g_async_queue_new(), &g_async_queue_unref); + static std::unique_ptr pipeline_manager(new pipeline::PipelineManager()); + static gboolean on_pipeline_manager_dispatch(gpointer pipeline_manager); + + struct call_t + { + call_t(const void* self, const void* context, const void* data, size_t size) + : self_(self), + context_(context), + data_(data), + size_(size) + { + } + + const void* self_; + const void* context_; + const void* data_; + size_t size_; + }; + + void on_plugin_call(const void* self, const void* context, const void* data, size_t size) + { + call_t * call = new call_t(self, context, data, size); + + g_async_queue_push(call_queue.get(), call); + + dispatch(on_pipeline_manager_dispatch, pipeline_manager.get()); + + } + + gboolean on_pipeline_manager_dispatch(gpointer pipeline_manager) + { + call_t * call = (call_t *)g_async_queue_pop(call_queue.get()); + static_cast(pipeline_manager)->on_call(call->self_, call->context_, call->data_, call->size_); + delete call; + + return G_SOURCE_REMOVE; + } + } +} + //#include "webstreamer.hpp" //#include "dispatcher.hpp" //#include diff --git a/lib/dispatcher.hpp b/lib/dispatcher.hpp index 648cab5..2b25885 100644 --- a/lib/dispatcher.hpp +++ b/lib/dispatcher.hpp @@ -5,8 +5,10 @@ namespace libwebstreamer { namespace dispatcher { - void on_call(const void* data, size_t size, void* context); - void on_callback(const void* data, size_t size, void* context); + //void on_call(const void* data, size_t size, void* context); + //void on_callback(const void* data, size_t size, void* context); + void on_plugin_call(const void* self, const void* context, const void* data, size_t size); + } } diff --git a/lib/libwebstreamer.cpp b/lib/libwebstreamer.cpp index 4ed5a36..50b2320 100644 --- a/lib/libwebstreamer.cpp +++ b/lib/libwebstreamer.cpp @@ -27,7 +27,7 @@ LIBWEBSTREAMER_NS_BEGIN printf("gstreamer quite.\n"); } - void schedule_with_user_data(GSourceFunc callback, gpointer user_data) + void dispatch(GSourceFunc callback, gpointer user_data) { GSource *source = g_idle_source_new(); diff --git a/lib/libwebstreamer.hpp b/lib/libwebstreamer.hpp index 2170c09..df05d73 100644 --- a/lib/libwebstreamer.hpp +++ b/lib/libwebstreamer.hpp @@ -13,7 +13,7 @@ LIBWEBSTREAMER_NS_BEGIN void initialize(const char* json, size_t size); void terminate(); -void schedule_with_user_data(GSourceFunc callback, gpointer user_data); +void dispatch(GSourceFunc callback, gpointer user_data); LIBWEBSTREAMER_NS_END From 216b514b6fcc1f5642619911770e781709b86869 Mon Sep 17 00:00:00 2001 From: daihongjun Date: Wed, 31 Jan 2018 14:34:09 +0800 Subject: [PATCH 06/18] c++ message define --- lib/message/common.hpp | 0 lib/message/livestream.hpp | 0 lib/message/webrtc.hpp | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/message/common.hpp create mode 100644 lib/message/livestream.hpp create mode 100644 lib/message/webrtc.hpp diff --git a/lib/message/common.hpp b/lib/message/common.hpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/message/livestream.hpp b/lib/message/livestream.hpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/message/webrtc.hpp b/lib/message/webrtc.hpp new file mode 100644 index 0000000..e69de29 From 2d4b000bd3c332b298c014f508edf6412695167e Mon Sep 17 00:00:00 2001 From: daihongjun Date: Thu, 1 Feb 2018 10:51:50 +0800 Subject: [PATCH 07/18] C++ message definition --- lib/message/common.hpp | 50 ++++++++++++++++++++++++ lib/message/endpoint.hpp | 30 +++++++++++++++ lib/message/livestream.hpp | 52 +++++++++++++++++++++++++ lib/message/webrtc.hpp | 30 +++++++++++++++ lib/message/webrtc_topic.hpp | 73 ++++++++++++++++++++++++++++++++++++ 5 files changed, 235 insertions(+) create mode 100644 lib/message/endpoint.hpp create mode 100644 lib/message/webrtc_topic.hpp diff --git a/lib/message/common.hpp b/lib/message/common.hpp index e69de29..88472ef 100644 --- a/lib/message/common.hpp +++ b/lib/message/common.hpp @@ -0,0 +1,50 @@ +#ifndef LIBWEBSTREAMER_MESSAGE_COMMON_HPP +#define LIBWEBSTREAMER_MESSAGE_COMMON_HPP + +#include +#include "webrtc.hpp" + +namespace libwebstreamer +{ + namespace message + { + namespace common + { + //Endpoint + enum EndpointType + { + RTSP_CLIENT, + WEBRTC + }; + + struct Endpoint + { + std::string id; + EndpointType type; + }; + + //Pipeline + enum VideoCodec + { + H264, + H265, + VP8 + }; + + enum AudioCodec + { + OPUS, + PCMA + }; + + struct Pipeline + { + std::string id; + VideoCodec video; + AudioCodec audio; + }; + } + } +} + +#endif \ No newline at end of file diff --git a/lib/message/endpoint.hpp b/lib/message/endpoint.hpp new file mode 100644 index 0000000..2eab9bd --- /dev/null +++ b/lib/message/endpoint.hpp @@ -0,0 +1,30 @@ +#ifndef LIBWEBSTREAMER_MESSAGE_ENDPOINT_HPP +#define LIBWEBSTREAMER_MESSAGE_ENDPOINT_HPP + +#include "common.hpp" + +namespace libwebstreamer +{ + namespace message + { + namespace endpoint + { + struct RtspClient : public common::Endpoint + { + std::string url; + }; + + struct Webrtc : public common::Endpoint + { + std::string group; + std::string connection; + webrtc::SdpRole sdp_role; + webrtc::StreamMode audio_mode; + webrtc::StreamMode video_mode; + }; + + } + } +} + +#endif \ No newline at end of file diff --git a/lib/message/livestream.hpp b/lib/message/livestream.hpp index e69de29..5872bca 100644 --- a/lib/message/livestream.hpp +++ b/lib/message/livestream.hpp @@ -0,0 +1,52 @@ +#ifndef LIBWEBSTREAMER_MESSAGE_LIVESTREAM_HPP +#define LIBWEBSTREAMER_MESSAGE_LIVESTREAM_HPP + +#include "common.hpp" +#include +#include + +namespace libwebstreamer +{ + namespace message + { + namespace livestream + { + struct create_t + { + common::Pipeline pipeline; + std::shared_ptr endpoint; + }; + + struct destroy_t + { + std::string id;//pipeline id + }; + + struct add_endpoint_t + { + std::string id;//pipeline id + std::shared_ptr endpoint; + }; + + struct remove_endpoint_t + { + std::string id;//pipeline id + std::string endpoint_id;//endpoint id + }; + + struct add_endpoints_t + { + std::string id; + std::vector> endpoints; + }; + + struct remove_endpoints_t + { + std::string id;//pipeline id + std::vector endpoint_ids; + }; + } + } +} + +#endif \ No newline at end of file diff --git a/lib/message/webrtc.hpp b/lib/message/webrtc.hpp index e69de29..fc94785 100644 --- a/lib/message/webrtc.hpp +++ b/lib/message/webrtc.hpp @@ -0,0 +1,30 @@ +#ifndef LIBWEBSTREAMER_MESSAGE_WEBRTC_HPP +#define LIBWEBSTREAMER_MESSAGE_WEBRTC_HPP + +namespace libwebstreamer +{ + namespace message + { + namespace webrtc + { + + enum SdpRole + { + OFFER, + ANSWER, + ANY + }; + + enum StreamMode + { + SEND_ONLY, + RECV_ONLY, + SEND_RECV, + NONE, + }; + + } + } +} + +#endif \ No newline at end of file diff --git a/lib/message/webrtc_topic.hpp b/lib/message/webrtc_topic.hpp new file mode 100644 index 0000000..ebfca6d --- /dev/null +++ b/lib/message/webrtc_topic.hpp @@ -0,0 +1,73 @@ +#ifndef LIBWEBSTREAMER_MESSAGE_WEBRTC_TOPICS_HPP +#define LIBWEBSTREAMER_MESSAGE_WEBRTC_TOPICS_HPP + +#include "webrtc.hpp" +#include +#include +#include + +namespace libwebstreamer +{ + namespace message + { + namespace webrtc + { + namespace topic + { + enum Category + { + SDP, + STATUS, + }; + + struct Endpoint + { + webrtc::SdpRole sdp_role; + std::string group; + std::string connection; + }; + + struct SubscribeItem + { + Endpoint endpoint; + std::vector topics; + }; + + struct Topic + { + Category category; + }; + + struct Sdp : public Topic + { + std::string content; + }; + + struct Status : public Topic + { + std::string content;//"connecting", "connected", "disconnected" + }; + + struct subscribe_t + { + std::vector items; + }; + + struct notification_t + { + Endpoint endpoint; + std::vector> topics; + }; + + struct push_t + { + Endpoint endpoint; + std::vector> topics; + }; + } + } + } +} + + +#endif \ No newline at end of file From 2cfb172a0185fea983858b87bef18972a32423a4 Mon Sep 17 00:00:00 2001 From: daihongjun Date: Thu, 1 Feb 2018 11:01:33 +0800 Subject: [PATCH 08/18] nodejs source file --- lib/{ => nodejs}/node-plugin-proto.h | 0 lib/{ => nodejs}/plugin.cpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename lib/{ => nodejs}/node-plugin-proto.h (100%) rename lib/{ => nodejs}/plugin.cpp (100%) diff --git a/lib/node-plugin-proto.h b/lib/nodejs/node-plugin-proto.h similarity index 100% rename from lib/node-plugin-proto.h rename to lib/nodejs/node-plugin-proto.h diff --git a/lib/plugin.cpp b/lib/nodejs/plugin.cpp similarity index 100% rename from lib/plugin.cpp rename to lib/nodejs/plugin.cpp From 238343bc7e025c3e0e70f5d1695c81715045b483 Mon Sep 17 00:00:00 2001 From: daihongjun Date: Thu, 1 Feb 2018 11:17:09 +0800 Subject: [PATCH 09/18] nodejs plugin --- lib/{ => nodejs/adapter}/dispatcher.cpp | 6 ++++-- lib/{ => nodejs/adapter}/dispatcher.hpp | 0 lib/nodejs/plugin.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) rename lib/{ => nodejs/adapter}/dispatcher.cpp (96%) rename lib/{ => nodejs/adapter}/dispatcher.hpp (100%) diff --git a/lib/dispatcher.cpp b/lib/nodejs/adapter/dispatcher.cpp similarity index 96% rename from lib/dispatcher.cpp rename to lib/nodejs/adapter/dispatcher.cpp index 3d01a9c..bd8cbf8 100644 --- a/lib/dispatcher.cpp +++ b/lib/nodejs/adapter/dispatcher.cpp @@ -1,9 +1,11 @@ -#include -#include + #include "libwebstreamer.hpp" #include "dispatcher.hpp" #include +#include +#include + namespace libwebstreamer { namespace dispatcher diff --git a/lib/dispatcher.hpp b/lib/nodejs/adapter/dispatcher.hpp similarity index 100% rename from lib/dispatcher.hpp rename to lib/nodejs/adapter/dispatcher.hpp diff --git a/lib/nodejs/plugin.cpp b/lib/nodejs/plugin.cpp index c866ebe..0404dc2 100644 --- a/lib/nodejs/plugin.cpp +++ b/lib/nodejs/plugin.cpp @@ -78,7 +78,7 @@ ////////////////////////////////// #include "node-plugin-proto.h" -#include "libwebstreamer.hpp" +#include USING_LIBWEBSTREAMER_NS static void init(const void* self, const void* data, size_t size) From fda35a7139b33938c9ec3b3ceb6a5c776cb1d2bc Mon Sep 17 00:00:00 2001 From: daihongjun Date: Thu, 1 Feb 2018 13:10:35 +0800 Subject: [PATCH 10/18] nodejs plugin --- lib/nodejs/adapter/dispatcher.cpp | 106 ++++++++++-------------------- lib/nodejs/adapter/dispatcher.hpp | 14 ++-- lib/nodejs/plugin.cpp | 83 ++--------------------- 3 files changed, 47 insertions(+), 156 deletions(-) diff --git a/lib/nodejs/adapter/dispatcher.cpp b/lib/nodejs/adapter/dispatcher.cpp index bd8cbf8..18704d6 100644 --- a/lib/nodejs/adapter/dispatcher.cpp +++ b/lib/nodejs/adapter/dispatcher.cpp @@ -8,84 +8,48 @@ namespace libwebstreamer { - namespace dispatcher + namespace nodejs { - static std::unique_ptr call_queue(g_async_queue_new(), &g_async_queue_unref); - static std::unique_ptr pipeline_manager(new pipeline::PipelineManager()); - static gboolean on_pipeline_manager_dispatch(gpointer pipeline_manager); - - struct call_t + namespace adapter { - call_t(const void* self, const void* context, const void* data, size_t size) - : self_(self), - context_(context), - data_(data), - size_(size) - { - } + static std::unique_ptr call_queue(g_async_queue_new(), &g_async_queue_unref); + static std::unique_ptr pipeline_manager(new pipeline::PipelineManager()); + static gboolean on_pipeline_manager_dispatch(gpointer pipeline_manager); - const void* self_; - const void* context_; - const void* data_; - size_t size_; - }; + struct call_t + { + call_t(const void* self, const void* context, const void* data, size_t size) + : self_(self), + context_(context), + data_(data), + size_(size) + { + } + + const void* self_; + const void* context_; + const void* data_; + size_t size_; + }; + + void on_plugin_call(const void* self, const void* context, const void* data, size_t size) + { + call_t * call = new call_t(self, context, data, size); - void on_plugin_call(const void* self, const void* context, const void* data, size_t size) - { - call_t * call = new call_t(self, context, data, size); - - g_async_queue_push(call_queue.get(), call); + g_async_queue_push(call_queue.get(), call); - dispatch(on_pipeline_manager_dispatch, pipeline_manager.get()); + dispatch(on_pipeline_manager_dispatch, pipeline_manager.get()); - } + } - gboolean on_pipeline_manager_dispatch(gpointer pipeline_manager) - { - call_t * call = (call_t *)g_async_queue_pop(call_queue.get()); - static_cast(pipeline_manager)->on_call(call->self_, call->context_, call->data_, call->size_); - delete call; + gboolean on_pipeline_manager_dispatch(gpointer pipeline_manager) + { + call_t * call = (call_t *)g_async_queue_pop(call_queue.get()); + static_cast(pipeline_manager)->on_call(call->self_, call->context_, call->data_, call->size_); + delete call; - return G_SOURCE_REMOVE; + return G_SOURCE_REMOVE; + } } } -} - -//#include "webstreamer.hpp" -//#include "dispatcher.hpp" -//#include -//#include - -//namespace libwebstreamer -//{ -// namespace dispatcher -// { -// static std::unique_ptr _data_queue(g_async_queue_new(), &g_async_queue_unref); -// static std::unique_ptr _size_queue(g_async_queue_new(), &g_async_queue_unref); -// static std::unique_ptr _context_queue(g_async_queue_new(), &g_async_queue_unref); -// -// static gboolean on_call_pipeline_manager(gpointer manager); -// -// void on_call(const void* data, size_t size, void* context) -// { -// g_print("@on_call:=--data:%d,size:%d,context:%d---------\n", data, size, context); -// -// g_async_queue_push(_context_queue.get(), context); -// g_async_queue_push(_data_queue.get(), (gpointer)data); -// g_async_queue_push(_size_queue.get(), (gpointer)size); -// -// schedule_with_user_data(on_call_pipeline_manager, NULL); -// } -// -// gboolean on_call_pipeline_manager(gpointer manager) -// { -// const void* data = g_async_queue_pop(_data_queue.get()); -// size_t size = (size_t)g_async_queue_pop(_size_queue.get()); -// void* context = g_async_queue_pop(_context_queue.get()); -// g_print("@on_call_pipeline_manager:=--data:%d,size:%d,context:%d---------\n", data, size, context); -// on_callback(data, size, context); -// -// return G_SOURCE_REMOVE; -// } -// } -//} \ No newline at end of file +} \ No newline at end of file diff --git a/lib/nodejs/adapter/dispatcher.hpp b/lib/nodejs/adapter/dispatcher.hpp index 2b25885..a15a3c4 100644 --- a/lib/nodejs/adapter/dispatcher.hpp +++ b/lib/nodejs/adapter/dispatcher.hpp @@ -1,14 +1,14 @@ -#ifndef LIBWEBSTREAMER_DISPATCHER_DISPATCHER_HPP -#define LIBWEBSTREAMER_DISPATCHER_DISPATCHER_HPP +#ifndef LIBWEBSTREAMER_NODEJS_ADAPTER_DISPATCHER_HPP +#define LIBWEBSTREAMER_NODEJS_ADAPTER_DISPATCHER_HPP namespace libwebstreamer { - namespace dispatcher + namespace nodejs { - //void on_call(const void* data, size_t size, void* context); - //void on_callback(const void* data, size_t size, void* context); - void on_plugin_call(const void* self, const void* context, const void* data, size_t size); - + namespace adapter + { + void on_plugin_call(const void* self, const void* context, const void* data, size_t size); + } } } diff --git a/lib/nodejs/plugin.cpp b/lib/nodejs/plugin.cpp index 0404dc2..755ae91 100644 --- a/lib/nodejs/plugin.cpp +++ b/lib/nodejs/plugin.cpp @@ -1,84 +1,10 @@ -#include -#include -#include - -#include - -#define GST_EXPORTS -#include - - -//#include "libwebstreamer.hpp" -//#include "dispatcher.hpp" - - -// -// -//#define EXTERN_C extern "C" -// -// -//static NODE_PLUGIN_CALLBACK g_callback = NULL; -//static NODE_PLUGIN_CALLBACK g_notify = NULL; -// -////@NODE_PLUGIN_CALL -//EXTERN_C GST_EXPORT -//void plugin_call(const void* data, size_t size, void* context) -//{ -// ::libwebstreamer::initialize(); -// ::libwebstreamer::dispatcher::on_call(data, size, context); -//} -// -////@NODE_PLUGIN_SET_CALLBACK -//EXTERN_C GST_EXPORT -//void plugin_set_callback( -// NODE_PLUGIN_CALLBACK cb, -// NODE_PLUGIN_CALLBACK notify) -//{ -// g_callback = cb; -//} - -// -//namespace libwebstreamer -//{ -// namespace dispatcher -// { -// void on_callback(const void* data, size_t size, void* context) -// { -// static int n = 0; -// n++; -// char* buf = (char*)malloc(size + 64); -// memset(buf, 0, size + 64); -// sprintf(buf, "==>%d %s", n, data); -// size_t len = strlen(buf); -// if (context && g_callback) -// { -// -// g_callback(context, buf, len + 1, 0, NULL, NULL); -// } -// -// if (context && g_notify) -// { -// buf[0] = '-'; -// g_notify(context, buf, len + 1, 0, NULL, NULL); -// } -// -// free(buf); -// } -// } -//} - - - - - - - - - - ////////////////////////////////// #include "node-plugin-proto.h" #include + +#include + +#include USING_LIBWEBSTREAMER_NS static void init(const void* self, const void* data, size_t size) @@ -92,6 +18,7 @@ static void init(const void* self, const void* data, size_t size) static void call(const void* self, const void* context, const void* data, size_t size) { + nodejs::adapter::on_plugin_call(self, context, data, size); } static void terminate(const void* self, void(*done)(const void* self)) From 81645e0d295a968b9ded3cc3760c0581ee1b6e85 Mon Sep 17 00:00:00 2001 From: daihongjun Date: Thu, 1 Feb 2018 13:22:48 +0800 Subject: [PATCH 11/18] flatbuffers message adapter --- lib/flatbuffers/adapter.cpp | 0 lib/flatbuffers/adapter.hpp | 12 ++++++++++++ 2 files changed, 12 insertions(+) create mode 100644 lib/flatbuffers/adapter.cpp create mode 100644 lib/flatbuffers/adapter.hpp diff --git a/lib/flatbuffers/adapter.cpp b/lib/flatbuffers/adapter.cpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/flatbuffers/adapter.hpp b/lib/flatbuffers/adapter.hpp new file mode 100644 index 0000000..c1e6f22 --- /dev/null +++ b/lib/flatbuffers/adapter.hpp @@ -0,0 +1,12 @@ +#ifndef LIBWEBSTREAMER_FLATBUFFERS_ADAPTER_HPP +#define LIBWEBSTREAMER_FLATBUFFERS_ADAPTER_HPP + +namespace libwebstreamer +{ + namespace flatbuffers + { + + } +} + +#endif \ No newline at end of file From 314f4a1f7c5521ac15f8001c5e60bad161ded56e Mon Sep 17 00:00:00 2001 From: daihongjun Date: Thu, 1 Feb 2018 18:50:16 +0800 Subject: [PATCH 12/18] flatbuffers schema redefinition --- lib/flatbuffers/webrtc_generated.h | 173 +++++++++++++++- lib/flatbuffers/webstreamer_generated.h | 259 ++++++++++++++++++++++-- lib/message/common.hpp | 6 + lib/pipeline/pipeline_manager.hpp | 10 + schema/webrtc.fbs | 17 +- schema/webstreamer.fbs | 26 ++- 6 files changed, 461 insertions(+), 30 deletions(-) diff --git a/lib/flatbuffers/webrtc_generated.h b/lib/flatbuffers/webrtc_generated.h index 65ff375..35812fc 100644 --- a/lib/flatbuffers/webrtc_generated.h +++ b/lib/flatbuffers/webrtc_generated.h @@ -22,6 +22,8 @@ struct TopicNotification; struct TopicPush; +struct TopicAny; + } // namespace topics enum SdpRole { @@ -119,6 +121,60 @@ inline const char *EnumNameTopicCategory(TopicCategory e) { return EnumNamesTopicCategory()[index]; } +enum Any { + Any_NONE = 0, + Any_TopicSubscribe = 1, + Any_TopicNotification = 2, + Any_TopicPush = 3, + Any_MIN = Any_NONE, + Any_MAX = Any_TopicPush +}; + +inline Any (&EnumValuesAny())[4] { + static Any values[] = { + Any_NONE, + Any_TopicSubscribe, + Any_TopicNotification, + Any_TopicPush + }; + return values; +} + +inline const char **EnumNamesAny() { + static const char *names[] = { + "NONE", + "TopicSubscribe", + "TopicNotification", + "TopicPush", + nullptr + }; + return names; +} + +inline const char *EnumNameAny(Any e) { + const size_t index = static_cast(e); + return EnumNamesAny()[index]; +} + +template struct AnyTraits { + static const Any enum_value = Any_NONE; +}; + +template<> struct AnyTraits { + static const Any enum_value = Any_TopicSubscribe; +}; + +template<> struct AnyTraits { + static const Any enum_value = Any_TopicNotification; +}; + +template<> struct AnyTraits { + static const Any enum_value = Any_TopicPush; +}; + +bool VerifyAny(flatbuffers::Verifier &verifier, const void *obj, Any type); +bool VerifyAnyVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, const flatbuffers::Vector *types); + struct Endpoint FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { VT_SDP_ROLE = 4, @@ -483,18 +539,123 @@ inline flatbuffers::Offset CreateTopicPush( return builder_.Finish(); } -inline const webstreamer::webrtc::topics::TopicPush *GetTopicPush(const void *buf) { - return flatbuffers::GetRoot(buf); +struct TopicAny FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ANY_TYPE = 4, + VT_ANY = 6 + }; + Any any_type() const { + return static_cast(GetField(VT_ANY_TYPE, 0)); + } + const void *any() const { + return GetPointer(VT_ANY); + } + template const T *any_as() const; + const TopicSubscribe *any_as_TopicSubscribe() const { + return any_type() == Any_TopicSubscribe ? static_cast(any()) : nullptr; + } + const TopicNotification *any_as_TopicNotification() const { + return any_type() == Any_TopicNotification ? static_cast(any()) : nullptr; + } + const TopicPush *any_as_TopicPush() const { + return any_type() == Any_TopicPush ? static_cast(any()) : nullptr; + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_ANY_TYPE) && + VerifyOffset(verifier, VT_ANY) && + VerifyAny(verifier, any(), any_type()) && + verifier.EndTable(); + } +}; + +template<> inline const TopicSubscribe *TopicAny::any_as() const { + return any_as_TopicSubscribe(); +} + +template<> inline const TopicNotification *TopicAny::any_as() const { + return any_as_TopicNotification(); +} + +template<> inline const TopicPush *TopicAny::any_as() const { + return any_as_TopicPush(); +} + +struct TopicAnyBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_any_type(Any any_type) { + fbb_.AddElement(TopicAny::VT_ANY_TYPE, static_cast(any_type), 0); + } + void add_any(flatbuffers::Offset any) { + fbb_.AddOffset(TopicAny::VT_ANY, any); + } + explicit TopicAnyBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + TopicAnyBuilder &operator=(const TopicAnyBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTopicAny( + flatbuffers::FlatBufferBuilder &_fbb, + Any any_type = Any_NONE, + flatbuffers::Offset any = 0) { + TopicAnyBuilder builder_(_fbb); + builder_.add_any(any); + builder_.add_any_type(any_type); + return builder_.Finish(); +} + +inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *obj, Any type) { + switch (type) { + case Any_NONE: { + return true; + } + case Any_TopicSubscribe: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case Any_TopicNotification: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case Any_TopicPush: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + default: return false; + } +} + +inline bool VerifyAnyVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, const flatbuffers::Vector *types) { + if (values->size() != types->size()) return false; + for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) { + if (!VerifyAny( + verifier, values->Get(i), types->GetEnum(i))) { + return false; + } + } + return true; +} + +inline const webstreamer::webrtc::topics::TopicAny *GetTopicAny(const void *buf) { + return flatbuffers::GetRoot(buf); } -inline bool VerifyTopicPushBuffer( +inline bool VerifyTopicAnyBuffer( flatbuffers::Verifier &verifier) { - return verifier.VerifyBuffer(nullptr); + return verifier.VerifyBuffer(nullptr); } -inline void FinishTopicPushBuffer( +inline void FinishTopicAnyBuffer( flatbuffers::FlatBufferBuilder &fbb, - flatbuffers::Offset root) { + flatbuffers::Offset root) { fbb.Finish(root); } diff --git a/lib/flatbuffers/webstreamer_generated.h b/lib/flatbuffers/webstreamer_generated.h index f1c139b..df2bcd0 100644 --- a/lib/flatbuffers/webstreamer_generated.h +++ b/lib/flatbuffers/webstreamer_generated.h @@ -34,6 +34,8 @@ struct LiveStreamRemoveEndpoints; struct LiveStreamError; +struct LiveStreamAny; + enum EndpointType { EndpointType_RTSPCLIENT = 0, EndpointType_WEBRTC = 1, @@ -124,6 +126,88 @@ inline const char *EnumNameAudioCodec(AudioCodec e) { return EnumNamesAudioCodec()[index]; } +enum Any { + Any_NONE = 0, + Any_LiveStreamCreate = 1, + Any_LiveStreamDestroy = 2, + Any_LiveStreamAddEndpoint = 3, + Any_LiveStreamRemoveEndpoint = 4, + Any_LiveStreamAddEndpoints = 5, + Any_LiveStreamRemoveEndpoints = 6, + Any_LiveStreamError = 7, + Any_MIN = Any_NONE, + Any_MAX = Any_LiveStreamError +}; + +inline Any (&EnumValuesAny())[8] { + static Any values[] = { + Any_NONE, + Any_LiveStreamCreate, + Any_LiveStreamDestroy, + Any_LiveStreamAddEndpoint, + Any_LiveStreamRemoveEndpoint, + Any_LiveStreamAddEndpoints, + Any_LiveStreamRemoveEndpoints, + Any_LiveStreamError + }; + return values; +} + +inline const char **EnumNamesAny() { + static const char *names[] = { + "NONE", + "LiveStreamCreate", + "LiveStreamDestroy", + "LiveStreamAddEndpoint", + "LiveStreamRemoveEndpoint", + "LiveStreamAddEndpoints", + "LiveStreamRemoveEndpoints", + "LiveStreamError", + nullptr + }; + return names; +} + +inline const char *EnumNameAny(Any e) { + const size_t index = static_cast(e); + return EnumNamesAny()[index]; +} + +template struct AnyTraits { + static const Any enum_value = Any_NONE; +}; + +template<> struct AnyTraits { + static const Any enum_value = Any_LiveStreamCreate; +}; + +template<> struct AnyTraits { + static const Any enum_value = Any_LiveStreamDestroy; +}; + +template<> struct AnyTraits { + static const Any enum_value = Any_LiveStreamAddEndpoint; +}; + +template<> struct AnyTraits { + static const Any enum_value = Any_LiveStreamRemoveEndpoint; +}; + +template<> struct AnyTraits { + static const Any enum_value = Any_LiveStreamAddEndpoints; +}; + +template<> struct AnyTraits { + static const Any enum_value = Any_LiveStreamRemoveEndpoints; +}; + +template<> struct AnyTraits { + static const Any enum_value = Any_LiveStreamError; +}; + +bool VerifyAny(flatbuffers::Verifier &verifier, const void *obj, Any type); +bool VerifyAnyVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, const flatbuffers::Vector *types); + struct EndpointBase FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { VT_ID = 4, @@ -839,15 +923,15 @@ struct LiveStreamError FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VT_CODE = 4, VT_REASON = 6 }; - int8_t code() const { - return GetField(VT_CODE, 0); + int16_t code() const { + return GetField(VT_CODE, 0); } const flatbuffers::String *reason() const { return GetPointer(VT_REASON); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && - VerifyField(verifier, VT_CODE) && + VerifyField(verifier, VT_CODE) && VerifyOffset(verifier, VT_REASON) && verifier.Verify(reason()) && verifier.EndTable(); @@ -857,8 +941,8 @@ struct LiveStreamError FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { struct LiveStreamErrorBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; - void add_code(int8_t code) { - fbb_.AddElement(LiveStreamError::VT_CODE, code, 0); + void add_code(int16_t code) { + fbb_.AddElement(LiveStreamError::VT_CODE, code, 0); } void add_reason(flatbuffers::Offset reason) { fbb_.AddOffset(LiveStreamError::VT_REASON, reason); @@ -877,7 +961,7 @@ struct LiveStreamErrorBuilder { inline flatbuffers::Offset CreateLiveStreamError( flatbuffers::FlatBufferBuilder &_fbb, - int8_t code = 0, + int16_t code = 0, flatbuffers::Offset reason = 0) { LiveStreamErrorBuilder builder_(_fbb); builder_.add_reason(reason); @@ -887,7 +971,7 @@ inline flatbuffers::Offset CreateLiveStreamError( inline flatbuffers::Offset CreateLiveStreamErrorDirect( flatbuffers::FlatBufferBuilder &_fbb, - int8_t code = 0, + int16_t code = 0, const char *reason = nullptr) { return webstreamer::CreateLiveStreamError( _fbb, @@ -895,18 +979,167 @@ inline flatbuffers::Offset CreateLiveStreamErrorDirect( reason ? _fbb.CreateString(reason) : 0); } -inline const webstreamer::LiveStreamError *GetLiveStreamError(const void *buf) { - return flatbuffers::GetRoot(buf); +struct LiveStreamAny FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum { + VT_ANY_TYPE = 4, + VT_ANY = 6 + }; + Any any_type() const { + return static_cast(GetField(VT_ANY_TYPE, 0)); + } + const void *any() const { + return GetPointer(VT_ANY); + } + template const T *any_as() const; + const LiveStreamCreate *any_as_LiveStreamCreate() const { + return any_type() == Any_LiveStreamCreate ? static_cast(any()) : nullptr; + } + const LiveStreamDestroy *any_as_LiveStreamDestroy() const { + return any_type() == Any_LiveStreamDestroy ? static_cast(any()) : nullptr; + } + const LiveStreamAddEndpoint *any_as_LiveStreamAddEndpoint() const { + return any_type() == Any_LiveStreamAddEndpoint ? static_cast(any()) : nullptr; + } + const LiveStreamRemoveEndpoint *any_as_LiveStreamRemoveEndpoint() const { + return any_type() == Any_LiveStreamRemoveEndpoint ? static_cast(any()) : nullptr; + } + const LiveStreamAddEndpoints *any_as_LiveStreamAddEndpoints() const { + return any_type() == Any_LiveStreamAddEndpoints ? static_cast(any()) : nullptr; + } + const LiveStreamRemoveEndpoints *any_as_LiveStreamRemoveEndpoints() const { + return any_type() == Any_LiveStreamRemoveEndpoints ? static_cast(any()) : nullptr; + } + const LiveStreamError *any_as_LiveStreamError() const { + return any_type() == Any_LiveStreamError ? static_cast(any()) : nullptr; + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_ANY_TYPE) && + VerifyOffset(verifier, VT_ANY) && + VerifyAny(verifier, any(), any_type()) && + verifier.EndTable(); + } +}; + +template<> inline const LiveStreamCreate *LiveStreamAny::any_as() const { + return any_as_LiveStreamCreate(); +} + +template<> inline const LiveStreamDestroy *LiveStreamAny::any_as() const { + return any_as_LiveStreamDestroy(); +} + +template<> inline const LiveStreamAddEndpoint *LiveStreamAny::any_as() const { + return any_as_LiveStreamAddEndpoint(); +} + +template<> inline const LiveStreamRemoveEndpoint *LiveStreamAny::any_as() const { + return any_as_LiveStreamRemoveEndpoint(); +} + +template<> inline const LiveStreamAddEndpoints *LiveStreamAny::any_as() const { + return any_as_LiveStreamAddEndpoints(); +} + +template<> inline const LiveStreamRemoveEndpoints *LiveStreamAny::any_as() const { + return any_as_LiveStreamRemoveEndpoints(); +} + +template<> inline const LiveStreamError *LiveStreamAny::any_as() const { + return any_as_LiveStreamError(); +} + +struct LiveStreamAnyBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_any_type(Any any_type) { + fbb_.AddElement(LiveStreamAny::VT_ANY_TYPE, static_cast(any_type), 0); + } + void add_any(flatbuffers::Offset any) { + fbb_.AddOffset(LiveStreamAny::VT_ANY, any); + } + explicit LiveStreamAnyBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + LiveStreamAnyBuilder &operator=(const LiveStreamAnyBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLiveStreamAny( + flatbuffers::FlatBufferBuilder &_fbb, + Any any_type = Any_NONE, + flatbuffers::Offset any = 0) { + LiveStreamAnyBuilder builder_(_fbb); + builder_.add_any(any); + builder_.add_any_type(any_type); + return builder_.Finish(); +} + +inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *obj, Any type) { + switch (type) { + case Any_NONE: { + return true; + } + case Any_LiveStreamCreate: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case Any_LiveStreamDestroy: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case Any_LiveStreamAddEndpoint: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case Any_LiveStreamRemoveEndpoint: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case Any_LiveStreamAddEndpoints: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case Any_LiveStreamRemoveEndpoints: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case Any_LiveStreamError: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + default: return false; + } +} + +inline bool VerifyAnyVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, const flatbuffers::Vector *types) { + if (values->size() != types->size()) return false; + for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) { + if (!VerifyAny( + verifier, values->Get(i), types->GetEnum(i))) { + return false; + } + } + return true; +} + +inline const webstreamer::LiveStreamAny *GetLiveStreamAny(const void *buf) { + return flatbuffers::GetRoot(buf); } -inline bool VerifyLiveStreamErrorBuffer( +inline bool VerifyLiveStreamAnyBuffer( flatbuffers::Verifier &verifier) { - return verifier.VerifyBuffer(nullptr); + return verifier.VerifyBuffer(nullptr); } -inline void FinishLiveStreamErrorBuffer( +inline void FinishLiveStreamAnyBuffer( flatbuffers::FlatBufferBuilder &fbb, - flatbuffers::Offset root) { + flatbuffers::Offset root) { fbb.Finish(root); } diff --git a/lib/message/common.hpp b/lib/message/common.hpp index 88472ef..6627d0b 100644 --- a/lib/message/common.hpp +++ b/lib/message/common.hpp @@ -43,6 +43,12 @@ namespace libwebstreamer VideoCodec video; AudioCodec audio; }; + + struct error_t + { + int8_t code; + std::string reason; + }; } } } diff --git a/lib/pipeline/pipeline_manager.hpp b/lib/pipeline/pipeline_manager.hpp index a344622..c15d714 100644 --- a/lib/pipeline/pipeline_manager.hpp +++ b/lib/pipeline/pipeline_manager.hpp @@ -1,6 +1,8 @@ #ifndef LIBWEBSTREAMER_PIPELINE_MANAGER_HPP #define LIBWEBSTREAMER_PIPELINE_MANAGER_HPP +#include + namespace libwebstreamer { namespace pipeline @@ -9,6 +11,14 @@ namespace libwebstreamer { public: void on_call(const void* self, const void* context, const void* data, size_t size); + + private://LiveStream + void on_livestream_create(); + void on_livestream_destroy(); + void on_livestream_add_endpoint(); + void on_livestream_remove_endpoint(); + void on_livestream_add_endpoints(); + void on_livestream_remove_endpoints(); }; } } diff --git a/schema/webrtc.fbs b/schema/webrtc.fbs index 87c21b2..0863a56 100644 --- a/schema/webrtc.fbs +++ b/schema/webrtc.fbs @@ -61,6 +61,17 @@ table TopicPush topic : Topic; } -root_type TopicSubscribe; -root_type TopicNotification; -root_type TopicPush; \ No newline at end of file + +union Any +{ + TopicSubscribe, + TopicNotification, + TopicPush +} + +table TopicAny +{ + any : Any; +} + +root_type TopicAny; \ No newline at end of file diff --git a/schema/webstreamer.fbs b/schema/webstreamer.fbs index 49ee005..48ee409 100644 --- a/schema/webstreamer.fbs +++ b/schema/webstreamer.fbs @@ -93,14 +93,24 @@ table LiveStreamRemoveEndpoints table LiveStreamError { - code : int8; + code : short; reason : string; } -root_type LiveStreamCreate; -root_type LiveStreamDestroy; -root_type LiveStreamAddEndpoint; -root_type LiveStreamRemoveEndpoint; -root_type LiveStreamAddEndpoints; -root_type LiveStreamRemoveEndpoints; -root_type LiveStreamError; \ No newline at end of file +union Any +{ + LiveStreamCreate, + LiveStreamDestroy, + LiveStreamAddEndpoint, + LiveStreamRemoveEndpoint, + LiveStreamAddEndpoints, + LiveStreamRemoveEndpoints, + LiveStreamError +} + +table LiveStreamAny +{ + any : Any; +} + +root_type LiveStreamAny; \ No newline at end of file From dc84ae30b781805688144cdf17b465f57c91ef45 Mon Sep 17 00:00:00 2001 From: daihongjun Date: Thu, 1 Feb 2018 19:17:16 +0800 Subject: [PATCH 13/18] api rename --- lib/nodejs/adapter/dispatcher.cpp | 2 +- lib/pipeline/pipeline_manager.cpp | 2 +- lib/pipeline/pipeline_manager.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/nodejs/adapter/dispatcher.cpp b/lib/nodejs/adapter/dispatcher.cpp index 18704d6..7855025 100644 --- a/lib/nodejs/adapter/dispatcher.cpp +++ b/lib/nodejs/adapter/dispatcher.cpp @@ -45,7 +45,7 @@ namespace libwebstreamer gboolean on_pipeline_manager_dispatch(gpointer pipeline_manager) { call_t * call = (call_t *)g_async_queue_pop(call_queue.get()); - static_cast(pipeline_manager)->on_call(call->self_, call->context_, call->data_, call->size_); + static_cast(pipeline_manager)->on_nodejs_call(call->self_, call->context_, call->data_, call->size_); delete call; return G_SOURCE_REMOVE; diff --git a/lib/pipeline/pipeline_manager.cpp b/lib/pipeline/pipeline_manager.cpp index e6d05eb..9321abb 100644 --- a/lib/pipeline/pipeline_manager.cpp +++ b/lib/pipeline/pipeline_manager.cpp @@ -4,7 +4,7 @@ namespace libwebstreamer { namespace pipeline { - void PipelineManager::on_call(const void* self, const void* context, const void* data, size_t size) + void PipelineManager::on_nodejs_call(const void* self, const void* context, const void* data, size_t size) { //TODO } diff --git a/lib/pipeline/pipeline_manager.hpp b/lib/pipeline/pipeline_manager.hpp index c15d714..949efce 100644 --- a/lib/pipeline/pipeline_manager.hpp +++ b/lib/pipeline/pipeline_manager.hpp @@ -10,7 +10,7 @@ namespace libwebstreamer class PipelineManager { public: - void on_call(const void* self, const void* context, const void* data, size_t size); + void on_nodejs_call(const void* self, const void* context, const void* data, size_t size); private://LiveStream void on_livestream_create(); From cbc3e2ac3a4696d68fdf32122c5756e709c3af4c Mon Sep 17 00:00:00 2001 From: daihongjun Date: Thu, 1 Feb 2018 19:40:54 +0800 Subject: [PATCH 14/18] API rename --- lib/nodejs/adapter/dispatcher.cpp | 2 +- lib/nodejs/adapter/dispatcher.hpp | 2 +- lib/nodejs/plugin.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/nodejs/adapter/dispatcher.cpp b/lib/nodejs/adapter/dispatcher.cpp index 7855025..14c86d8 100644 --- a/lib/nodejs/adapter/dispatcher.cpp +++ b/lib/nodejs/adapter/dispatcher.cpp @@ -32,7 +32,7 @@ namespace libwebstreamer size_t size_; }; - void on_plugin_call(const void* self, const void* context, const void* data, size_t size) + void on_nodejs_call(const void* self, const void* context, const void* data, size_t size) { call_t * call = new call_t(self, context, data, size); diff --git a/lib/nodejs/adapter/dispatcher.hpp b/lib/nodejs/adapter/dispatcher.hpp index a15a3c4..efef2fe 100644 --- a/lib/nodejs/adapter/dispatcher.hpp +++ b/lib/nodejs/adapter/dispatcher.hpp @@ -7,7 +7,7 @@ namespace libwebstreamer { namespace adapter { - void on_plugin_call(const void* self, const void* context, const void* data, size_t size); + void on_nodejs_call(const void* self, const void* context, const void* data, size_t size); } } } diff --git a/lib/nodejs/plugin.cpp b/lib/nodejs/plugin.cpp index 755ae91..5c1ec54 100644 --- a/lib/nodejs/plugin.cpp +++ b/lib/nodejs/plugin.cpp @@ -18,7 +18,7 @@ static void init(const void* self, const void* data, size_t size) static void call(const void* self, const void* context, const void* data, size_t size) { - nodejs::adapter::on_plugin_call(self, context, data, size); + nodejs::adapter::on_nodejs_call(self, context, data, size); } static void terminate(const void* self, void(*done)(const void* self)) From b15e1436b2b5d2717ecdfc6bb67ac2b5847ae0cb Mon Sep 17 00:00:00 2001 From: daihongjun Date: Mon, 5 Feb 2018 14:44:44 +0800 Subject: [PATCH 15/18] flatbuffers to cxx message transform --- lib/flatbuffers/adapter.cpp | 166 +++++++++++++++ lib/flatbuffers/adapter.hpp | 10 +- lib/flatbuffers/webstreamer_generated.h | 255 ++++++++++++++---------- lib/pipeline/pipeline_manager.cpp | 82 +++++++- lib/pipeline/pipeline_manager.hpp | 12 +- schema/webstreamer.fbs | 13 +- 6 files changed, 415 insertions(+), 123 deletions(-) diff --git a/lib/flatbuffers/adapter.cpp b/lib/flatbuffers/adapter.cpp index e69de29..fa57b7f 100644 --- a/lib/flatbuffers/adapter.cpp +++ b/lib/flatbuffers/adapter.cpp @@ -0,0 +1,166 @@ +#include +#include +#include + +namespace libwebstreamer +{ + namespace flatbuffers + { + void transform(::webstreamer::Endpoint endpoint, const void * value, std::shared_ptr& cxx_endpoint) + { + switch (endpoint) + { + case ::webstreamer::Endpoint::Endpoint_RtspClient: + { + const ::webstreamer::RtspClient * fb_endpoint = static_cast(value); + std::shared_ptr endpoint = std::make_shared(); + 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(value); + std::shared_ptr endpoint = std::make_shared(); + 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()); + } + } + } +} \ No newline at end of file diff --git a/lib/flatbuffers/adapter.hpp b/lib/flatbuffers/adapter.hpp index c1e6f22..07b5df2 100644 --- a/lib/flatbuffers/adapter.hpp +++ b/lib/flatbuffers/adapter.hpp @@ -1,11 +1,19 @@ #ifndef LIBWEBSTREAMER_FLATBUFFERS_ADAPTER_HPP #define LIBWEBSTREAMER_FLATBUFFERS_ADAPTER_HPP +#include +#include + 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); } } diff --git a/lib/flatbuffers/webstreamer_generated.h b/lib/flatbuffers/webstreamer_generated.h index df2bcd0..8970f3e 100644 --- a/lib/flatbuffers/webstreamer_generated.h +++ b/lib/flatbuffers/webstreamer_generated.h @@ -16,8 +16,6 @@ struct RtspClient; struct Webrtc; -struct Endpoint; - struct Pipeline; struct LiveStreamCreate; @@ -36,35 +34,53 @@ struct LiveStreamError; struct LiveStreamAny; -enum EndpointType { - EndpointType_RTSPCLIENT = 0, - EndpointType_WEBRTC = 1, - EndpointType_MIN = EndpointType_RTSPCLIENT, - EndpointType_MAX = EndpointType_WEBRTC +enum Endpoint { + Endpoint_NONE = 0, + Endpoint_RtspClient = 1, + Endpoint_Webrtc = 2, + Endpoint_MIN = Endpoint_NONE, + Endpoint_MAX = Endpoint_Webrtc }; -inline EndpointType (&EnumValuesEndpointType())[2] { - static EndpointType values[] = { - EndpointType_RTSPCLIENT, - EndpointType_WEBRTC +inline Endpoint (&EnumValuesEndpoint())[3] { + static Endpoint values[] = { + Endpoint_NONE, + Endpoint_RtspClient, + Endpoint_Webrtc }; return values; } -inline const char **EnumNamesEndpointType() { +inline const char **EnumNamesEndpoint() { static const char *names[] = { - "RTSPCLIENT", - "WEBRTC", + "NONE", + "RtspClient", + "Webrtc", nullptr }; return names; } -inline const char *EnumNameEndpointType(EndpointType e) { +inline const char *EnumNameEndpoint(Endpoint e) { const size_t index = static_cast(e); - return EnumNamesEndpointType()[index]; + return EnumNamesEndpoint()[index]; } +template struct EndpointTraits { + static const Endpoint enum_value = Endpoint_NONE; +}; + +template<> struct EndpointTraits { + static const Endpoint enum_value = Endpoint_RtspClient; +}; + +template<> struct EndpointTraits { + static const Endpoint enum_value = Endpoint_Webrtc; +}; + +bool VerifyEndpoint(flatbuffers::Verifier &verifier, const void *obj, Endpoint type); +bool VerifyEndpointVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, const flatbuffers::Vector *types); + enum VideoCodec { VideoCodec_H264 = 0, VideoCodec_H265 = 1, @@ -210,20 +226,15 @@ bool VerifyAnyVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector< struct EndpointBase FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { - VT_ID = 4, - VT_TYPE = 6 + VT_ID = 4 }; const flatbuffers::String *id() const { return GetPointer(VT_ID); } - EndpointType type() const { - return static_cast(GetField(VT_TYPE, 0)); - } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_ID) && verifier.Verify(id()) && - VerifyField(verifier, VT_TYPE) && verifier.EndTable(); } }; @@ -234,9 +245,6 @@ struct EndpointBaseBuilder { void add_id(flatbuffers::Offset id) { fbb_.AddOffset(EndpointBase::VT_ID, id); } - void add_type(EndpointType type) { - fbb_.AddElement(EndpointBase::VT_TYPE, static_cast(type), 0); - } explicit EndpointBaseBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -251,22 +259,18 @@ struct EndpointBaseBuilder { inline flatbuffers::Offset CreateEndpointBase( flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset id = 0, - EndpointType type = EndpointType_RTSPCLIENT) { + flatbuffers::Offset id = 0) { EndpointBaseBuilder builder_(_fbb); builder_.add_id(id); - builder_.add_type(type); return builder_.Finish(); } inline flatbuffers::Offset CreateEndpointBaseDirect( flatbuffers::FlatBufferBuilder &_fbb, - const char *id = nullptr, - EndpointType type = EndpointType_RTSPCLIENT) { + const char *id = nullptr) { return webstreamer::CreateEndpointBase( _fbb, - id ? _fbb.CreateString(id) : 0, - type); + id ? _fbb.CreateString(id) : 0); } struct RtspClient FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -442,58 +446,6 @@ inline flatbuffers::Offset CreateWebrtcDirect( video_stream_mode); } -struct Endpoint FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum { - VT_RTSPCLIENT = 4, - VT_WEBRTC = 6 - }; - const RtspClient *rtspclient() const { - return GetPointer(VT_RTSPCLIENT); - } - const Webrtc *webrtc() const { - return GetPointer(VT_WEBRTC); - } - bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_RTSPCLIENT) && - verifier.VerifyTable(rtspclient()) && - VerifyOffset(verifier, VT_WEBRTC) && - verifier.VerifyTable(webrtc()) && - verifier.EndTable(); - } -}; - -struct EndpointBuilder { - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_rtspclient(flatbuffers::Offset rtspclient) { - fbb_.AddOffset(Endpoint::VT_RTSPCLIENT, rtspclient); - } - void add_webrtc(flatbuffers::Offset webrtc) { - fbb_.AddOffset(Endpoint::VT_WEBRTC, webrtc); - } - explicit EndpointBuilder(flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - EndpointBuilder &operator=(const EndpointBuilder &); - flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); - return o; - } -}; - -inline flatbuffers::Offset CreateEndpoint( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset rtspclient = 0, - flatbuffers::Offset webrtc = 0) { - EndpointBuilder builder_(_fbb); - builder_.add_webrtc(webrtc); - builder_.add_rtspclient(rtspclient); - return builder_.Finish(); -} - struct Pipeline FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { VT_ID = 4, @@ -570,31 +522,54 @@ inline flatbuffers::Offset CreatePipelineDirect( struct LiveStreamCreate FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { VT_PIPELINE = 4, - VT_ENDPOINT = 6 + VT_ENDPOINT_TYPE = 6, + VT_ENDPOINT = 8 }; const Pipeline *pipeline() const { return GetPointer(VT_PIPELINE); } - const Endpoint *endpoint() const { - return GetPointer(VT_ENDPOINT); + Endpoint endpoint_type() const { + return static_cast(GetField(VT_ENDPOINT_TYPE, 0)); + } + const void *endpoint() const { + return GetPointer(VT_ENDPOINT); + } + template const T *endpoint_as() const; + const RtspClient *endpoint_as_RtspClient() const { + return endpoint_type() == Endpoint_RtspClient ? static_cast(endpoint()) : nullptr; + } + const Webrtc *endpoint_as_Webrtc() const { + return endpoint_type() == Endpoint_Webrtc ? static_cast(endpoint()) : nullptr; } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_PIPELINE) && verifier.VerifyTable(pipeline()) && + VerifyField(verifier, VT_ENDPOINT_TYPE) && VerifyOffset(verifier, VT_ENDPOINT) && - verifier.VerifyTable(endpoint()) && + VerifyEndpoint(verifier, endpoint(), endpoint_type()) && verifier.EndTable(); } }; +template<> inline const RtspClient *LiveStreamCreate::endpoint_as() const { + return endpoint_as_RtspClient(); +} + +template<> inline const Webrtc *LiveStreamCreate::endpoint_as() const { + return endpoint_as_Webrtc(); +} + struct LiveStreamCreateBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; void add_pipeline(flatbuffers::Offset pipeline) { fbb_.AddOffset(LiveStreamCreate::VT_PIPELINE, pipeline); } - void add_endpoint(flatbuffers::Offset endpoint) { + void add_endpoint_type(Endpoint endpoint_type) { + fbb_.AddElement(LiveStreamCreate::VT_ENDPOINT_TYPE, static_cast(endpoint_type), 0); + } + void add_endpoint(flatbuffers::Offset endpoint) { fbb_.AddOffset(LiveStreamCreate::VT_ENDPOINT, endpoint); } explicit LiveStreamCreateBuilder(flatbuffers::FlatBufferBuilder &_fbb) @@ -612,10 +587,12 @@ struct LiveStreamCreateBuilder { inline flatbuffers::Offset CreateLiveStreamCreate( flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset pipeline = 0, - flatbuffers::Offset endpoint = 0) { + Endpoint endpoint_type = Endpoint_NONE, + flatbuffers::Offset endpoint = 0) { LiveStreamCreateBuilder builder_(_fbb); builder_.add_endpoint(endpoint); builder_.add_pipeline(pipeline); + builder_.add_endpoint_type(endpoint_type); return builder_.Finish(); } @@ -671,31 +648,54 @@ inline flatbuffers::Offset CreateLiveStreamDestroyDirect( struct LiveStreamAddEndpoint FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { VT_ID = 4, - VT_ENDPOINT = 6 + VT_ENDPOINT_TYPE = 6, + VT_ENDPOINT = 8 }; const flatbuffers::String *id() const { return GetPointer(VT_ID); } - const Endpoint *endpoint() const { - return GetPointer(VT_ENDPOINT); + Endpoint endpoint_type() const { + return static_cast(GetField(VT_ENDPOINT_TYPE, 0)); + } + const void *endpoint() const { + return GetPointer(VT_ENDPOINT); + } + template const T *endpoint_as() const; + const RtspClient *endpoint_as_RtspClient() const { + return endpoint_type() == Endpoint_RtspClient ? static_cast(endpoint()) : nullptr; + } + const Webrtc *endpoint_as_Webrtc() const { + return endpoint_type() == Endpoint_Webrtc ? static_cast(endpoint()) : nullptr; } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_ID) && verifier.Verify(id()) && + VerifyField(verifier, VT_ENDPOINT_TYPE) && VerifyOffset(verifier, VT_ENDPOINT) && - verifier.VerifyTable(endpoint()) && + VerifyEndpoint(verifier, endpoint(), endpoint_type()) && verifier.EndTable(); } }; +template<> inline const RtspClient *LiveStreamAddEndpoint::endpoint_as() const { + return endpoint_as_RtspClient(); +} + +template<> inline const Webrtc *LiveStreamAddEndpoint::endpoint_as() const { + return endpoint_as_Webrtc(); +} + struct LiveStreamAddEndpointBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; void add_id(flatbuffers::Offset id) { fbb_.AddOffset(LiveStreamAddEndpoint::VT_ID, id); } - void add_endpoint(flatbuffers::Offset endpoint) { + void add_endpoint_type(Endpoint endpoint_type) { + fbb_.AddElement(LiveStreamAddEndpoint::VT_ENDPOINT_TYPE, static_cast(endpoint_type), 0); + } + void add_endpoint(flatbuffers::Offset endpoint) { fbb_.AddOffset(LiveStreamAddEndpoint::VT_ENDPOINT, endpoint); } explicit LiveStreamAddEndpointBuilder(flatbuffers::FlatBufferBuilder &_fbb) @@ -713,41 +713,51 @@ struct LiveStreamAddEndpointBuilder { inline flatbuffers::Offset CreateLiveStreamAddEndpoint( flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset id = 0, - flatbuffers::Offset endpoint = 0) { + Endpoint endpoint_type = Endpoint_NONE, + flatbuffers::Offset endpoint = 0) { LiveStreamAddEndpointBuilder builder_(_fbb); builder_.add_endpoint(endpoint); builder_.add_id(id); + builder_.add_endpoint_type(endpoint_type); return builder_.Finish(); } inline flatbuffers::Offset CreateLiveStreamAddEndpointDirect( flatbuffers::FlatBufferBuilder &_fbb, const char *id = nullptr, - flatbuffers::Offset endpoint = 0) { + Endpoint endpoint_type = Endpoint_NONE, + flatbuffers::Offset endpoint = 0) { return webstreamer::CreateLiveStreamAddEndpoint( _fbb, id ? _fbb.CreateString(id) : 0, + endpoint_type, endpoint); } struct LiveStreamAddEndpoints FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { enum { VT_ID = 4, - VT_ENDPOINTS = 6 + VT_ENDPOINTS_TYPE = 6, + VT_ENDPOINTS = 8 }; const flatbuffers::String *id() const { return GetPointer(VT_ID); } - const flatbuffers::Vector> *endpoints() const { - return GetPointer> *>(VT_ENDPOINTS); + const flatbuffers::Vector *endpoints_type() const { + return GetPointer *>(VT_ENDPOINTS_TYPE); + } + const flatbuffers::Vector> *endpoints() const { + return GetPointer> *>(VT_ENDPOINTS); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_ID) && verifier.Verify(id()) && + VerifyOffset(verifier, VT_ENDPOINTS_TYPE) && + verifier.Verify(endpoints_type()) && VerifyOffset(verifier, VT_ENDPOINTS) && verifier.Verify(endpoints()) && - verifier.VerifyVectorOfTables(endpoints()) && + VerifyEndpointVector(verifier, endpoints(), endpoints_type()) && verifier.EndTable(); } }; @@ -758,7 +768,10 @@ struct LiveStreamAddEndpointsBuilder { void add_id(flatbuffers::Offset id) { fbb_.AddOffset(LiveStreamAddEndpoints::VT_ID, id); } - void add_endpoints(flatbuffers::Offset>> endpoints) { + void add_endpoints_type(flatbuffers::Offset> endpoints_type) { + fbb_.AddOffset(LiveStreamAddEndpoints::VT_ENDPOINTS_TYPE, endpoints_type); + } + void add_endpoints(flatbuffers::Offset>> endpoints) { fbb_.AddOffset(LiveStreamAddEndpoints::VT_ENDPOINTS, endpoints); } explicit LiveStreamAddEndpointsBuilder(flatbuffers::FlatBufferBuilder &_fbb) @@ -776,9 +789,11 @@ struct LiveStreamAddEndpointsBuilder { inline flatbuffers::Offset CreateLiveStreamAddEndpoints( flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset id = 0, - flatbuffers::Offset>> endpoints = 0) { + flatbuffers::Offset> endpoints_type = 0, + flatbuffers::Offset>> endpoints = 0) { LiveStreamAddEndpointsBuilder builder_(_fbb); builder_.add_endpoints(endpoints); + builder_.add_endpoints_type(endpoints_type); builder_.add_id(id); return builder_.Finish(); } @@ -786,11 +801,13 @@ inline flatbuffers::Offset CreateLiveStreamAddEndpoints( inline flatbuffers::Offset CreateLiveStreamAddEndpointsDirect( flatbuffers::FlatBufferBuilder &_fbb, const char *id = nullptr, - const std::vector> *endpoints = nullptr) { + const std::vector *endpoints_type = nullptr, + const std::vector> *endpoints = nullptr) { return webstreamer::CreateLiveStreamAddEndpoints( _fbb, id ? _fbb.CreateString(id) : 0, - endpoints ? _fbb.CreateVector>(*endpoints) : 0); + endpoints_type ? _fbb.CreateVector(*endpoints_type) : 0, + endpoints ? _fbb.CreateVector>(*endpoints) : 0); } struct LiveStreamRemoveEndpoint FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -1080,6 +1097,34 @@ inline flatbuffers::Offset CreateLiveStreamAny( return builder_.Finish(); } +inline bool VerifyEndpoint(flatbuffers::Verifier &verifier, const void *obj, Endpoint type) { + switch (type) { + case Endpoint_NONE: { + return true; + } + case Endpoint_RtspClient: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case Endpoint_Webrtc: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + default: return false; + } +} + +inline bool VerifyEndpointVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector> *values, const flatbuffers::Vector *types) { + if (values->size() != types->size()) return false; + for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) { + if (!VerifyEndpoint( + verifier, values->Get(i), types->GetEnum(i))) { + return false; + } + } + return true; +} + inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *obj, Any type) { switch (type) { case Any_NONE: { diff --git a/lib/pipeline/pipeline_manager.cpp b/lib/pipeline/pipeline_manager.cpp index 9321abb..b892235 100644 --- a/lib/pipeline/pipeline_manager.cpp +++ b/lib/pipeline/pipeline_manager.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include namespace libwebstreamer { @@ -6,7 +9,84 @@ namespace libwebstreamer { void PipelineManager::on_nodejs_call(const void* self, const void* context, const void* data, size_t size) { - //TODO + ::flatbuffers::Verifier verifier((const uint8_t *)data, size); + if (webstreamer::VerifyLiveStreamAnyBuffer(verifier)) + { + auto livestream_any = webstreamer::GetLiveStreamAny((const uint8_t *)data); + switch (livestream_any->any_type()) + { + case webstreamer::Any_LiveStreamCreate: + { + auto create = livestream_any->any_as_LiveStreamCreate(); + message::livestream::create_t internal_create; + flatbuffers::transform(*create, internal_create); + on_livestream_create(internal_create); + } + break; + case webstreamer::Any_LiveStreamDestroy: + { + auto destroy = livestream_any->any_as_LiveStreamDestroy(); + message::livestream::destroy_t internal_destroy; + flatbuffers::transform(*destroy, internal_destroy); + on_livestream_destroy(internal_destroy); + } + break; + case webstreamer::Any_LiveStreamAddEndpoint: + { + auto add_endpoint = livestream_any->any_as_LiveStreamAddEndpoint(); + message::livestream::add_endpoint_t internal_add_endpoint; + flatbuffers::transform(*add_endpoint, internal_add_endpoint); + on_livestream_add_endpoint(internal_add_endpoint); + } + break; + case webstreamer::Any_LiveStreamRemoveEndpoint: + { + auto remove_endpoint = livestream_any->any_as_LiveStreamRemoveEndpoint(); + message::livestream::remove_endpoint_t internal_remove_endpoint; + flatbuffers::transform(*remove_endpoint, internal_remove_endpoint); + on_livestream_remove_endpoint(internal_remove_endpoint); + } + break; + case webstreamer::Any_LiveStreamAddEndpoints: + { + auto add_endpoints = livestream_any->any_as_LiveStreamAddEndpoints(); + message::livestream::add_endpoints_t internal_add_endpoints; + flatbuffers::transform(*add_endpoints, internal_add_endpoints); + on_livestream_add_endpoints(internal_add_endpoints); + } + break; + case webstreamer::Any_LiveStreamRemoveEndpoints: + { + auto remove_endpoints = livestream_any->any_as_LiveStreamRemoveEndpoints(); + message::livestream::remove_endpoints_t internal_remove_endpoints; + flatbuffers::transform(*remove_endpoints, internal_remove_endpoints); + on_livestream_remove_endpoints(internal_remove_endpoints); + } + break; + default: + g_warn_if_reached(); + break; + } + } + } + + void PipelineManager::on_livestream_create(const message::livestream::create_t& message) + { + } + void PipelineManager::on_livestream_destroy(const message::livestream::destroy_t& message) + { + } + void PipelineManager::on_livestream_add_endpoint(const message::livestream::add_endpoint_t& message) + { + } + void PipelineManager::on_livestream_remove_endpoint(const message::livestream::remove_endpoint_t& message) + { + } + void PipelineManager::on_livestream_add_endpoints(const message::livestream::add_endpoints_t& message) + { + } + void PipelineManager::on_livestream_remove_endpoints(const message::livestream::remove_endpoints_t& message) + { } } } \ No newline at end of file diff --git a/lib/pipeline/pipeline_manager.hpp b/lib/pipeline/pipeline_manager.hpp index 949efce..cc51fac 100644 --- a/lib/pipeline/pipeline_manager.hpp +++ b/lib/pipeline/pipeline_manager.hpp @@ -13,12 +13,12 @@ namespace libwebstreamer void on_nodejs_call(const void* self, const void* context, const void* data, size_t size); private://LiveStream - void on_livestream_create(); - void on_livestream_destroy(); - void on_livestream_add_endpoint(); - void on_livestream_remove_endpoint(); - void on_livestream_add_endpoints(); - void on_livestream_remove_endpoints(); + void on_livestream_create(const message::livestream::create_t& message); + void on_livestream_destroy(const message::livestream::destroy_t& message); + void on_livestream_add_endpoint(const message::livestream::add_endpoint_t& message); + void on_livestream_remove_endpoint(const message::livestream::remove_endpoint_t& message); + void on_livestream_add_endpoints(const message::livestream::add_endpoints_t& message); + void on_livestream_remove_endpoints(const message::livestream::remove_endpoints_t& message); }; } } diff --git a/schema/webstreamer.fbs b/schema/webstreamer.fbs index 48ee409..7bda769 100644 --- a/schema/webstreamer.fbs +++ b/schema/webstreamer.fbs @@ -2,16 +2,9 @@ include "webrtc.fbs"; namespace webstreamer; -enum EndpointType : int8 -{ - RTSPCLIENT, - WEBRTC -} - table EndpointBase { id : string; - type : EndpointType; } table RtspClient @@ -30,10 +23,10 @@ table Webrtc video_stream_mode : webstreamer.webrtc.StreamMode; } -table Endpoint +union Endpoint { - rtspclient : RtspClient; - webrtc : Webrtc; + RtspClient, + Webrtc } enum VideoCodec : int8 From 15f3ed65e2c3a1db4754e15a3e4dcfee45a794f9 Mon Sep 17 00:00:00 2001 From: daihongjun Date: Mon, 5 Feb 2018 17:18:52 +0800 Subject: [PATCH 16/18] pipeline related --- lib/pipeline/app/endpoint/rtspclient.cpp | 0 lib/pipeline/app/endpoint/rtspclient.hpp | 0 lib/pipeline/app/endpoint/webrtc.cpp | 0 lib/pipeline/app/endpoint/webrtc.hpp | 0 lib/pipeline/app/pipeline/livestream.cpp | 0 lib/pipeline/app/pipeline/livestream.hpp | 0 lib/pipeline/framework/endpoint.hpp | 24 +++++++++++++++++++ lib/pipeline/framework/pipeline.hpp | 14 +++++++++-- .../{ => framework}/pipeline_manager.cpp | 2 +- .../{ => framework}/pipeline_manager.hpp | 14 +++++++++++ 10 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 lib/pipeline/app/endpoint/rtspclient.cpp create mode 100644 lib/pipeline/app/endpoint/rtspclient.hpp create mode 100644 lib/pipeline/app/endpoint/webrtc.cpp create mode 100644 lib/pipeline/app/endpoint/webrtc.hpp create mode 100644 lib/pipeline/app/pipeline/livestream.cpp create mode 100644 lib/pipeline/app/pipeline/livestream.hpp rename lib/pipeline/{ => framework}/pipeline_manager.cpp (96%) rename lib/pipeline/{ => framework}/pipeline_manager.hpp (50%) diff --git a/lib/pipeline/app/endpoint/rtspclient.cpp b/lib/pipeline/app/endpoint/rtspclient.cpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/pipeline/app/endpoint/rtspclient.hpp b/lib/pipeline/app/endpoint/rtspclient.hpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/pipeline/app/endpoint/webrtc.cpp b/lib/pipeline/app/endpoint/webrtc.cpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/pipeline/app/endpoint/webrtc.hpp b/lib/pipeline/app/endpoint/webrtc.hpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/pipeline/app/pipeline/livestream.cpp b/lib/pipeline/app/pipeline/livestream.cpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/pipeline/app/pipeline/livestream.hpp b/lib/pipeline/app/pipeline/livestream.hpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/pipeline/framework/endpoint.hpp b/lib/pipeline/framework/endpoint.hpp index e69de29..afaf7e5 100644 --- a/lib/pipeline/framework/endpoint.hpp +++ b/lib/pipeline/framework/endpoint.hpp @@ -0,0 +1,24 @@ +#ifndef LIBWEBSTREAMER_PIPELINE_FRAMEWORK_ENDPOINT_HPP +#define LIBWEBSTREAMER_PIPELINE_FRAMEWORK_ENDPOINT_HPP + +#include + +namespace libwebstreamer +{ + namespace pipeline + { + class Pipeline; + class Endpoint + { + public: + Endpoint(const message::common::Endpoint& params); + virtual ~Endpoint(); + + private: + std::weak_ptr pipeline;//owner pipeline + }; + } +} + + +#endif \ No newline at end of file diff --git a/lib/pipeline/framework/pipeline.hpp b/lib/pipeline/framework/pipeline.hpp index 1a354ec..a62194d 100644 --- a/lib/pipeline/framework/pipeline.hpp +++ b/lib/pipeline/framework/pipeline.hpp @@ -1,11 +1,21 @@ -#ifndef LIBWEBSTREAMER_PIPELINE_HPP -#define LIBWEBSTREAMER_PIPELINE_HPP +#ifndef LIBWEBSTREAMER_PIPELINE_FRAMEWORK_PIPELINE_HPP +#define LIBWEBSTREAMER_PIPELINE_FRAMEWORK_PIPELINE_HPP +#include +#include "endpoint.hpp" namespace libwebstreamer { namespace pipeline { + class Pipeline + { + public: + Pipeline(const message::common::Pipeline& params); + virtual ~Pipeline(); + private: + std::vector> endpoints; + }; } } diff --git a/lib/pipeline/pipeline_manager.cpp b/lib/pipeline/framework/pipeline_manager.cpp similarity index 96% rename from lib/pipeline/pipeline_manager.cpp rename to lib/pipeline/framework/pipeline_manager.cpp index b892235..c948993 100644 --- a/lib/pipeline/pipeline_manager.cpp +++ b/lib/pipeline/framework/pipeline_manager.cpp @@ -1,4 +1,4 @@ -#include +#include "pipeline_manager.hpp" #include #include #include diff --git a/lib/pipeline/pipeline_manager.hpp b/lib/pipeline/framework/pipeline_manager.hpp similarity index 50% rename from lib/pipeline/pipeline_manager.hpp rename to lib/pipeline/framework/pipeline_manager.hpp index cc51fac..f7de4d2 100644 --- a/lib/pipeline/pipeline_manager.hpp +++ b/lib/pipeline/framework/pipeline_manager.hpp @@ -2,6 +2,17 @@ #define LIBWEBSTREAMER_PIPELINE_MANAGER_HPP #include +#include "pipeline.hpp" +/** +* ,-----------------, 1 * ,---------------, 1 shared_ptr * ,---------------, +* | PipelineManager |------------------>| Pipeline |-------------------->| Endpoint | +* '-----------------' shared_ptr '---------------' '---------------' +* ^._1_ _ _ _ _ _ _ _ _ _ _ _1_/ 1 _.^ +* weak_ptr / +* ,-----------------, / +* | WebrtcManager |_1_ _ _ _ _ _ _ / +* '-----------------' weak_ptr +*/ namespace libwebstreamer { @@ -19,6 +30,9 @@ namespace libwebstreamer void on_livestream_remove_endpoint(const message::livestream::remove_endpoint_t& message); void on_livestream_add_endpoints(const message::livestream::add_endpoints_t& message); void on_livestream_remove_endpoints(const message::livestream::remove_endpoints_t& message); + + private: + std::vector> pipelines; }; } } From f3587d488a08496dcfacebef0b07c1ced7fb5c0b Mon Sep 17 00:00:00 2001 From: daihongjun Date: Mon, 5 Feb 2018 17:32:09 +0800 Subject: [PATCH 17/18] webrtc manager --- lib/pipeline/app/endpoint/webrtc_manager.cpp | 0 lib/pipeline/app/endpoint/webrtc_manager.hpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/pipeline/app/endpoint/webrtc_manager.cpp create mode 100644 lib/pipeline/app/endpoint/webrtc_manager.hpp diff --git a/lib/pipeline/app/endpoint/webrtc_manager.cpp b/lib/pipeline/app/endpoint/webrtc_manager.cpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/pipeline/app/endpoint/webrtc_manager.hpp b/lib/pipeline/app/endpoint/webrtc_manager.hpp new file mode 100644 index 0000000..e69de29 From 922b1d65b7b2200d4ea17954015a26c6d506ffeb Mon Sep 17 00:00:00 2001 From: daihongjun Date: Tue, 27 Feb 2018 13:32:35 +0800 Subject: [PATCH 18/18] pipeline --- lib/pipeline/framework/pipeline.hpp | 6 ++++++ lib/pipeline/framework/pipeline_manager.cpp | 19 +++++++++++++++++++ lib/pipeline/framework/pipeline_manager.hpp | 11 +++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/pipeline/framework/pipeline.hpp b/lib/pipeline/framework/pipeline.hpp index a62194d..e92682e 100644 --- a/lib/pipeline/framework/pipeline.hpp +++ b/lib/pipeline/framework/pipeline.hpp @@ -13,8 +13,14 @@ namespace libwebstreamer Pipeline(const message::common::Pipeline& params); virtual ~Pipeline(); + public: + const std::string& id() const; + private: std::vector> endpoints; + + private: + std::string id_; }; } } diff --git a/lib/pipeline/framework/pipeline_manager.cpp b/lib/pipeline/framework/pipeline_manager.cpp index c948993..6de9396 100644 --- a/lib/pipeline/framework/pipeline_manager.cpp +++ b/lib/pipeline/framework/pipeline_manager.cpp @@ -72,6 +72,11 @@ namespace libwebstreamer void PipelineManager::on_livestream_create(const message::livestream::create_t& message) { + if (is_livestream_created(message.pipeline.id)) + { + //TODO: Exception Feedback + return; + } } void PipelineManager::on_livestream_destroy(const message::livestream::destroy_t& message) { @@ -88,5 +93,19 @@ namespace libwebstreamer void PipelineManager::on_livestream_remove_endpoints(const message::livestream::remove_endpoints_t& message) { } + + bool PipelineManager::is_livestream_created(const std::string& id) + { + auto it = std::find_if(pipelines.begin(), pipelines.end(), [&id](std::shared_ptr& pipeline) { + return pipeline->id() == id; + }); + + if (it != pipelines.end()) + { + return true; + } + + return false; + } } } \ No newline at end of file diff --git a/lib/pipeline/framework/pipeline_manager.hpp b/lib/pipeline/framework/pipeline_manager.hpp index f7de4d2..675f761 100644 --- a/lib/pipeline/framework/pipeline_manager.hpp +++ b/lib/pipeline/framework/pipeline_manager.hpp @@ -7,10 +7,10 @@ * ,-----------------, 1 * ,---------------, 1 shared_ptr * ,---------------, * | PipelineManager |------------------>| Pipeline |-------------------->| Endpoint | * '-----------------' shared_ptr '---------------' '---------------' -* ^._1_ _ _ _ _ _ _ _ _ _ _ _1_/ 1 _.^ -* weak_ptr / -* ,-----------------, / -* | WebrtcManager |_1_ _ _ _ _ _ _ / +* ^._1_ _ _ _ _ _ _ _ _ _ _ _1_/ 1 .^ +* weak_ptr / +* ,-----------------, / +* | WebrtcManager |_1_ _ _ _ _ _ _ _ / * '-----------------' weak_ptr */ @@ -31,6 +31,9 @@ namespace libwebstreamer void on_livestream_add_endpoints(const message::livestream::add_endpoints_t& message); void on_livestream_remove_endpoints(const message::livestream::remove_endpoints_t& message); + private: + bool is_livestream_created(const std::string& id); + private: std::vector> pipelines; };