123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395 |
- #include "pch.h"
- #include "Context.h"
- #include "CreateSessionDescriptionObserver.h"
- #include "GraphicsDevice/GraphicsUtility.h"
- #include "MediaStreamObserver.h"
- #include "PeerConnectionObject.h"
- #include "SetSessionDescriptionObserver.h"
- #include "UnityAudioTrackSource.h"
- #include "UnityLogStream.h"
- #include "WebRTCPlugin.h"
- namespace unity
- {
- namespace webrtc
- {
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wmissing-prototypes"
- static DelegateSetResolution delegateSetResolution = nullptr;
- void SetResolution(int32* width, int32* length)
- {
- if (delegateSetResolution != nullptr)
- {
- delegateSetResolution(width, length);
- }
- }
- template<class T>
- T** ConvertPtrArrayFromRefPtrArray(std::vector<rtc::scoped_refptr<T>> vec, size_t* length)
- {
- *length = vec.size();
- const auto buf = CoTaskMemAlloc(sizeof(T*) * vec.size());
- const auto ret = static_cast<T**>(buf);
- std::copy(vec.begin(), vec.end(), ret);
- return ret;
- }
- template<typename T>
- T* ConvertArray(std::vector<T> vec, size_t* length)
- {
- *length = vec.size();
- size_t size = sizeof(T*) * vec.size();
- auto dst = CoTaskMemAlloc(size);
- auto src = vec.data();
- std::memcpy(dst, src, size);
- return static_cast<T*>(dst);
- }
- template<typename T>
- struct MarshallArray
- {
- size_t length;
- T* values;
- T& operator[](size_t i) const { return values[i]; }
- template<typename U>
- MarshallArray& operator=(const std::vector<U>& src)
- {
- length = static_cast<int32_t>(src.size());
- values = static_cast<T*>(CoTaskMemAlloc(sizeof(T) * src.size()));
- for (size_t i = 0; i < src.size(); i++)
- {
- values[i] = src[i];
- }
- return *this;
- }
- };
- template<typename T, typename U>
- void ConvertArray(const MarshallArray<T>& src, std::vector<U>& dst)
- {
- dst.resize(src.length);
- for (size_t i = 0; i < dst.size(); i++)
- {
- dst[i] = src.values[i];
- }
- }
- template<typename T>
- struct Optional
- {
- bool hasValue;
- T value;
- template<typename U>
- Optional& operator=(const absl::optional<U>& src)
- {
- hasValue = src.has_value();
- if (hasValue)
- {
- value = static_cast<T>(src.value());
- }
- else
- {
- value = T();
- }
- return *this;
- }
- #if defined(__clang__) || defined(__GNUC__)
- __attribute__((optnone))
- #endif
- explicit
- operator const absl::optional<T>() const
- {
- absl::optional<T> dst = absl::nullopt;
- if (hasValue)
- dst = value;
- return dst;
- }
- const T& value_or(const T& v) const { return hasValue ? value : v; }
- };
- template<typename T>
- absl::optional<T> ConvertOptional(const Optional<T>& value)
- {
- absl::optional<T> dst = absl::nullopt;
- if (value.hasValue)
- {
- dst = value.value;
- }
- return dst;
- }
- std::string ConvertSdp(const std::map<std::string, std::string>& map)
- {
- std::string str = "";
- for (const auto& pair : map)
- {
- if (!str.empty())
- {
- str += ";";
- }
- str += pair.first + "=" + pair.second;
- }
- return str;
- }
- std::vector<std::string> Split(const std::string& str, const std::string& delimiter)
- {
- std::vector<std::string> dst;
- std::string s = str;
- size_t pos = 0;
- while (true)
- {
- pos = s.find(delimiter);
- size_t length = pos;
- if (pos == std::string::npos)
- length = str.length();
- if (length == 0)
- break;
- dst.push_back(s.substr(0, length));
- if (pos == std::string::npos)
- break;
- s.erase(0, pos + delimiter.length());
- }
- return dst;
- }
- std::tuple<cricket::MediaType, std::string> ConvertMimeType(const std::string& mimeType)
- {
- const std::vector<std::string> vec = Split(mimeType, "/");
- const std::string kind = vec[0];
- const std::string name = vec[1];
- cricket::MediaType mediaType;
- if (kind == "video")
- {
- mediaType = cricket::MEDIA_TYPE_VIDEO;
- }
- else if (kind == "audio")
- {
- mediaType = cricket::MEDIA_TYPE_AUDIO;
- }
- return std::make_tuple(mediaType, name);
- }
- std::map<std::string, std::string> ConvertSdp(const std::string& src)
- {
- std::map<std::string, std::string> map;
- std::vector<std::string> vec = Split(src, ";");
- for (const auto& str : vec)
- {
- std::vector<std::string> pair = Split(str, "=");
- map.emplace(pair[0], pair[1]);
- }
- return map;
- }
- ///
- /// avoid compile error for vector<bool>
- /// https://en.cppreference.com/w/cpp/container/vector_bool
- bool* ConvertArray(std::vector<bool> vec, size_t* length)
- {
- *length = vec.size();
- size_t size = sizeof(bool*) * vec.size();
- auto dst = CoTaskMemAlloc(size);
- bool* ret = static_cast<bool*>(dst);
- for (size_t i = 0; i < vec.size(); i++)
- {
- ret[i] = vec[i];
- }
- return ret;
- }
- char* ConvertString(const std::string str)
- {
- const size_t size = str.size();
- char* ret = static_cast<char*>(CoTaskMemAlloc(size + sizeof(char)));
- str.copy(ret, size);
- ret[size] = '\0';
- return ret;
- }
- } // end namespace webrtc
- } // end namespace unity
- using namespace unity::webrtc;
- using namespace ::webrtc;
- extern "C"
- {
- UNITY_INTERFACE_EXPORT MediaStreamInterface* ContextCreateMediaStream(Context* context, const char* streamId)
- {
- return context->CreateMediaStream(streamId);
- }
- UNITY_INTERFACE_EXPORT void ContextRegisterMediaStreamObserver(Context* context, MediaStreamInterface* stream)
- {
- context->RegisterMediaStreamObserver(stream);
- }
- UNITY_INTERFACE_EXPORT void ContextUnRegisterMediaStreamObserver(Context* context, MediaStreamInterface* stream)
- {
- context->UnRegisterMediaStreamObserver(stream);
- }
- UNITY_INTERFACE_EXPORT MediaStreamTrackInterface*
- ContextCreateVideoTrack(Context* context, const char* label, webrtc::VideoTrackSourceInterface* source)
- {
- return context->CreateVideoTrack(label, source);
- }
- UNITY_INTERFACE_EXPORT void
- ContextStopMediaStreamTrack(Context* context, ::webrtc::MediaStreamTrackInterface* track)
- {
- context->StopMediaStreamTrack(track);
- }
- UNITY_INTERFACE_EXPORT webrtc::VideoTrackSourceInterface* ContextCreateVideoTrackSource(Context* context)
- {
- return context->CreateVideoSource();
- }
- UNITY_INTERFACE_EXPORT webrtc::AudioSourceInterface* ContextCreateAudioTrackSource(Context* context)
- {
- return context->CreateAudioSource();
- }
- UNITY_INTERFACE_EXPORT webrtc::MediaStreamTrackInterface*
- ContextCreateAudioTrack(Context* context, const char* label, webrtc::AudioSourceInterface* source)
- {
- return context->CreateAudioTrack(label, source);
- }
- UNITY_INTERFACE_EXPORT void ContextAddRefPtr(Context* context, rtc::RefCountInterface* ptr)
- {
- context->AddRefPtr(ptr);
- }
- UNITY_INTERFACE_EXPORT void ContextDeleteRefPtr(Context* context, rtc::RefCountInterface* ptr)
- {
- context->RemoveRefPtr(ptr);
- }
- UNITY_INTERFACE_EXPORT bool MediaStreamAddTrack(MediaStreamInterface* stream, MediaStreamTrackInterface* track)
- {
- if (track->kind() == "audio")
- {
- return stream->AddTrack(static_cast<AudioTrackInterface*>(track));
- }
- else
- {
- return stream->AddTrack(static_cast<VideoTrackInterface*>(track));
- }
- }
- UNITY_INTERFACE_EXPORT bool MediaStreamRemoveTrack(MediaStreamInterface* stream, MediaStreamTrackInterface* track)
- {
- if (track->kind() == "audio")
- {
- return stream->RemoveTrack(static_cast<AudioTrackInterface*>(track));
- }
- else
- {
- return stream->RemoveTrack(static_cast<VideoTrackInterface*>(track));
- }
- }
- UNITY_INTERFACE_EXPORT char* MediaStreamGetID(MediaStreamInterface* stream) { return ConvertString(stream->id()); }
- UNITY_INTERFACE_EXPORT void MediaStreamRegisterOnAddTrack(
- Context* context, MediaStreamInterface* stream, DelegateMediaStreamOnAddTrack callback)
- {
- context->GetObserver(stream)->RegisterOnAddTrack(callback);
- }
- UNITY_INTERFACE_EXPORT void MediaStreamRegisterOnRemoveTrack(
- Context* context, MediaStreamInterface* stream, DelegateMediaStreamOnRemoveTrack callback)
- {
- context->GetObserver(stream)->RegisterOnRemoveTrack(callback);
- }
- UNITY_INTERFACE_EXPORT VideoTrackInterface** MediaStreamGetVideoTracks(MediaStreamInterface* stream, size_t* length)
- {
- return ConvertPtrArrayFromRefPtrArray<VideoTrackInterface>(stream->GetVideoTracks(), length);
- }
- UNITY_INTERFACE_EXPORT AudioTrackInterface** MediaStreamGetAudioTracks(MediaStreamInterface* stream, size_t* length)
- {
- return ConvertPtrArrayFromRefPtrArray<AudioTrackInterface>(stream->GetAudioTracks(), length);
- }
- UNITY_INTERFACE_EXPORT VideoTrackSourceInterface*
- ContextGetVideoSource(Context* context, VideoTrackInterface* track)
- {
- return track->GetSource();
- }
- UNITY_INTERFACE_EXPORT TrackKind MediaStreamTrackGetKind(MediaStreamTrackInterface* track)
- {
- const auto kindStr = track->kind();
- if (kindStr == "audio")
- {
- return TrackKind::Audio;
- }
- else
- {
- return TrackKind::Video;
- }
- }
- UNITY_INTERFACE_EXPORT MediaStreamTrackInterface::TrackState
- MediaStreamTrackGetReadyState(MediaStreamTrackInterface* track)
- {
- return track->state();
- }
- UNITY_INTERFACE_EXPORT char* MediaStreamTrackGetID(MediaStreamTrackInterface* track)
- {
- return ConvertString(track->id());
- }
- UNITY_INTERFACE_EXPORT bool MediaStreamTrackGetEnabled(MediaStreamTrackInterface* track)
- {
- return track->enabled();
- }
- UNITY_INTERFACE_EXPORT void MediaStreamTrackSetEnabled(MediaStreamTrackInterface* track, bool enabled)
- {
- track->set_enabled(enabled);
- }
- UNITY_INTERFACE_EXPORT UnityVideoRenderer*
- CreateVideoRenderer(Context* context, DelegateVideoFrameResize callback, bool needFlipVertical)
- {
- return context->CreateVideoRenderer(callback, needFlipVertical);
- }
- UNITY_INTERFACE_EXPORT uint32_t GetVideoRendererId(UnityVideoRenderer* sink) { return sink->GetId(); }
- UNITY_INTERFACE_EXPORT void DeleteVideoRenderer(Context* context, UnityVideoRenderer* sink)
- {
- context->DeleteVideoRenderer(sink);
- }
- UNITY_INTERFACE_EXPORT void VideoTrackAddOrUpdateSink(VideoTrackInterface* track, UnityVideoRenderer* sink)
- {
- track->AddOrUpdateSink(sink, rtc::VideoSinkWants());
- }
- UNITY_INTERFACE_EXPORT void VideoTrackRemoveSink(VideoTrackInterface* track, UnityVideoRenderer* sink)
- {
- track->RemoveSink(sink);
- }
- UNITY_INTERFACE_EXPORT void
- RegisterDebugLog(DelegateDebugLog func, bool enableNativeLog, rtc::LoggingSeverity loggingSeverity)
- {
- delegateDebugLog = func;
- if (func != nullptr && enableNativeLog)
- {
- UnityLogStream::AddLogStream(func, loggingSeverity);
- }
- else if (func == nullptr)
- {
- UnityLogStream::RemoveLogStream();
- }
- }
- UNITY_INTERFACE_EXPORT void RegisterSetResolution(DelegateSetResolution func) { delegateSetResolution = func; }
- UNITY_INTERFACE_EXPORT Context* ContextCreate(int uid)
- {
- auto ctx = ContextManager::GetInstance()->GetContext(uid);
- if (ctx != nullptr)
- {
- DebugLog("Already created context with ID %d", uid);
- return ctx;
- }
- ContextDependencies dependencies;
- dependencies.device = Plugin::GraphicsDevice();
- dependencies.profiler = Plugin::ProfilerMarkerFactory();
- ctx = ContextManager::GetInstance()->CreateContext(uid, dependencies);
- return ctx;
- }
- UNITY_INTERFACE_EXPORT void ContextDestroy(int uid) { ContextManager::GetInstance()->DestroyContext(uid); }
- UNITY_INTERFACE_EXPORT PeerConnectionObject* ContextCreatePeerConnection(Context* context)
- {
- PeerConnectionInterface::RTCConfiguration config;
- config.sdp_semantics = SdpSemantics::kUnifiedPlan;
- config.enable_implicit_rollback = true;
- return context->CreatePeerConnection(config);
- }
- UNITY_INTERFACE_EXPORT PeerConnectionObject*
- ContextCreatePeerConnectionWithConfig(Context* context, const char* conf)
- {
- PeerConnectionInterface::RTCConfiguration config;
- if (!Convert(conf, config))
- return nullptr;
- config.sdp_semantics = SdpSemantics::kUnifiedPlan;
- config.enable_implicit_rollback = true;
- return context->CreatePeerConnection(config);
- }
- UNITY_INTERFACE_EXPORT void ContextDeletePeerConnection(Context* context, PeerConnectionObject* obj)
- {
- obj->Close();
- context->DeletePeerConnection(obj);
- }
- UNITY_INTERFACE_EXPORT void PeerConnectionClose(PeerConnectionObject* obj) { obj->Close(); }
- UNITY_INTERFACE_EXPORT void PeerConnectionRestartIce(PeerConnectionObject* obj) { obj->connection->RestartIce(); }
- UNITY_INTERFACE_EXPORT RTCErrorType PeerConnectionAddTrack(
- PeerConnectionObject* obj, MediaStreamTrackInterface* track, const char* streamId, RtpSenderInterface** sender)
- {
- std::vector<std::string> streams;
- if (streamId)
- streams.push_back(streamId);
- auto result = obj->connection->AddTrack(rtc::scoped_refptr<MediaStreamTrackInterface>(track), streams);
- if (result.ok())
- {
- *sender = result.value();
- }
- return result.error().type();
- }
- struct RTCRtpEncodingParameters
- {
- bool active;
- Optional<uint64_t> maxBitrate;
- Optional<uint64_t> minBitrate;
- Optional<uint32_t> maxFramerate;
- Optional<double> scaleResolutionDownBy;
- char* rid;
- RTCRtpEncodingParameters& operator=(const RtpEncodingParameters& obj)
- {
- active = obj.active;
- maxBitrate = obj.max_bitrate_bps;
- minBitrate = obj.min_bitrate_bps;
- maxFramerate = obj.max_framerate;
- scaleResolutionDownBy = obj.scale_resolution_down_by;
- rid = ConvertString(obj.rid);
- return *this;
- }
- operator RtpEncodingParameters() const
- {
- RtpEncodingParameters dst = {};
- dst.active = active;
- dst.max_bitrate_bps = static_cast<absl::optional<int>>(ConvertOptional(maxBitrate));
- dst.min_bitrate_bps = static_cast<absl::optional<int>>(ConvertOptional(minBitrate));
- dst.max_framerate = static_cast<absl::optional<double>>(ConvertOptional(maxFramerate));
- dst.scale_resolution_down_by = ConvertOptional(scaleResolutionDownBy);
- if (rid != nullptr)
- dst.rid = std::string(rid);
- return dst;
- }
- };
- struct RTCRtpTransceiverInit
- {
- RtpTransceiverDirection direction;
- MarshallArray<RTCRtpEncodingParameters> sendEncodings;
- MarshallArray<MediaStreamInterface*> streams;
- operator RtpTransceiverInit() const
- {
- RtpTransceiverInit dst = {};
- dst.direction = direction;
- dst.send_encodings.resize(sendEncodings.length);
- for (size_t i = 0; i < dst.send_encodings.size(); i++)
- {
- dst.send_encodings[i] = sendEncodings[i];
- }
- dst.stream_ids.resize(streams.length);
- for (size_t i = 0; i < dst.stream_ids.size(); i++)
- {
- dst.stream_ids[i] = streams[i]->id();
- }
- return dst;
- }
- };
- UNITY_INTERFACE_EXPORT RtpTransceiverInterface*
- PeerConnectionAddTransceiver(PeerConnectionObject* obj, MediaStreamTrackInterface* track)
- {
- auto result = obj->connection->AddTransceiver(track);
- if (!result.ok())
- return nullptr;
- return result.value();
- }
- UNITY_INTERFACE_EXPORT RtpTransceiverInterface* PeerConnectionAddTransceiverWithInit(
- PeerConnectionObject* obj, MediaStreamTrackInterface* track, const RTCRtpTransceiverInit* init)
- {
- auto result = obj->connection->AddTransceiver(track, *init);
- if (!result.ok())
- return nullptr;
- return result.value();
- }
- UNITY_INTERFACE_EXPORT RtpTransceiverInterface*
- PeerConnectionAddTransceiverWithType(PeerConnectionObject* obj, cricket::MediaType type)
- {
- auto result = obj->connection->AddTransceiver(type);
- if (!result.ok())
- return nullptr;
- return result.value();
- }
- UNITY_INTERFACE_EXPORT RtpTransceiverInterface* PeerConnectionAddTransceiverWithTypeAndInit(
- PeerConnectionObject* obj, cricket::MediaType type, const RTCRtpTransceiverInit* init)
- {
- auto result = obj->connection->AddTransceiver(type, *init);
- if (!result.ok())
- return nullptr;
- return result.value();
- }
- UNITY_INTERFACE_EXPORT RTCErrorType PeerConnectionRemoveTrack(PeerConnectionObject* obj, RtpSenderInterface* sender)
- {
- webrtc::RTCError error = obj->connection->RemoveTrackNew(sender);
- return error.type();
- }
- UNITY_INTERFACE_EXPORT RTCErrorType PeerConnectionSetConfiguration(PeerConnectionObject* obj, const char* conf)
- {
- return obj->SetConfiguration(std::string(conf));
- }
- UNITY_INTERFACE_EXPORT char* PeerConnectionGetConfiguration(PeerConnectionObject* obj)
- {
- const std::string str = obj->GetConfiguration();
- return ConvertString(str);
- }
- UNITY_INTERFACE_EXPORT PeerConnectionStatsCollectorCallback* PeerConnectionGetStats(PeerConnectionObject* obj)
- {
- PeerConnectionStatsCollectorCallback* callback = PeerConnectionStatsCollectorCallback::Create(obj);
- obj->connection->GetStats(callback);
- return callback;
- }
- UNITY_INTERFACE_EXPORT PeerConnectionStatsCollectorCallback*
- PeerConnectionSenderGetStats(PeerConnectionObject* obj, RtpSenderInterface* sender)
- {
- PeerConnectionStatsCollectorCallback* callback = PeerConnectionStatsCollectorCallback::Create(obj);
- obj->connection->GetStats(sender, callback);
- return callback;
- }
- UNITY_INTERFACE_EXPORT PeerConnectionStatsCollectorCallback*
- PeerConnectionReceiverGetStats(PeerConnectionObject* obj, RtpReceiverInterface* receiver)
- {
- PeerConnectionStatsCollectorCallback* callback = PeerConnectionStatsCollectorCallback::Create(obj);
- obj->connection->GetStats(receiver, callback);
- return callback;
- }
- UNITY_INTERFACE_EXPORT const RTCStats**
- ContextGetStatsList(Context* context, const RTCStatsReport* report, size_t* length, uint32_t** types)
- {
- return context->GetStatsList(report, length, types);
- }
- UNITY_INTERFACE_EXPORT void ContextDeleteStatsReport(Context* context, const RTCStatsReport* report)
- {
- context->DeleteStatsReport(report);
- }
- UNITY_INTERFACE_EXPORT const char* StatsGetJson(const RTCStats* stats) { return ConvertString(stats->ToJson()); }
- UNITY_INTERFACE_EXPORT int64_t StatsGetTimestamp(const RTCStats* stats) { return stats->timestamp_us(); }
- UNITY_INTERFACE_EXPORT const char* StatsGetId(const RTCStats* stats) { return ConvertString(stats->id()); }
- UNITY_INTERFACE_EXPORT uint32_t StatsGetType(const RTCStats* stats) { return statsTypes.at(stats->type()); }
- UNITY_INTERFACE_EXPORT const RTCStatsMemberInterface** StatsGetMembers(const RTCStats* stats, size_t* length)
- {
- return ConvertArray(stats->Members(), length);
- }
- UNITY_INTERFACE_EXPORT bool StatsMemberIsDefined(const RTCStatsMemberInterface* member)
- {
- return member->is_defined();
- }
- UNITY_INTERFACE_EXPORT const char* StatsMemberGetName(const RTCStatsMemberInterface* member)
- {
- return ConvertString(std::string(member->name()));
- }
- UNITY_INTERFACE_EXPORT bool StatsMemberGetBool(const RTCStatsMemberInterface* member)
- {
- return *member->cast_to<::webrtc::RTCStatsMember<bool>>();
- }
- UNITY_INTERFACE_EXPORT int32_t StatsMemberGetInt(const RTCStatsMemberInterface* member)
- {
- return *member->cast_to<::webrtc::RTCStatsMember<int32_t>>();
- }
- UNITY_INTERFACE_EXPORT uint32_t StatsMemberGetUnsignedInt(const RTCStatsMemberInterface* member)
- {
- return *member->cast_to<::webrtc::RTCStatsMember<uint32_t>>();
- }
- UNITY_INTERFACE_EXPORT int64_t StatsMemberGetLong(const RTCStatsMemberInterface* member)
- {
- return *member->cast_to<::webrtc::RTCStatsMember<int64_t>>();
- }
- UNITY_INTERFACE_EXPORT uint64_t StatsMemberGetUnsignedLong(const RTCStatsMemberInterface* member)
- {
- return *member->cast_to<::webrtc::RTCStatsMember<uint64_t>>();
- }
- UNITY_INTERFACE_EXPORT double StatsMemberGetDouble(const RTCStatsMemberInterface* member)
- {
- return *member->cast_to<::webrtc::RTCStatsMember<double>>();
- }
- UNITY_INTERFACE_EXPORT const char* StatsMemberGetString(const RTCStatsMemberInterface* member)
- {
- return ConvertString(member->ValueToString());
- }
- UNITY_INTERFACE_EXPORT bool* StatsMemberGetBoolArray(const RTCStatsMemberInterface* member, size_t* length)
- {
- return ConvertArray(*member->cast_to<::webrtc::RTCStatsMember<std::vector<bool>>>(), length);
- }
- UNITY_INTERFACE_EXPORT int32_t* StatsMemberGetIntArray(const RTCStatsMemberInterface* member, size_t* length)
- {
- return ConvertArray(*member->cast_to<::webrtc::RTCStatsMember<std::vector<int>>>(), length);
- }
- UNITY_INTERFACE_EXPORT uint32_t*
- StatsMemberGetUnsignedIntArray(const RTCStatsMemberInterface* member, size_t* length)
- {
- return ConvertArray(*member->cast_to<::webrtc::RTCStatsMember<std::vector<uint32_t>>>(), length);
- }
- UNITY_INTERFACE_EXPORT int64_t* StatsMemberGetLongArray(const RTCStatsMemberInterface* member, size_t* length)
- {
- return ConvertArray(*member->cast_to<::webrtc::RTCStatsMember<std::vector<int64_t>>>(), length);
- }
- UNITY_INTERFACE_EXPORT uint64_t*
- StatsMemberGetUnsignedLongArray(const RTCStatsMemberInterface* member, size_t* length)
- {
- return ConvertArray(*member->cast_to<::webrtc::RTCStatsMember<std::vector<uint64_t>>>(), length);
- }
- UNITY_INTERFACE_EXPORT double* StatsMemberGetDoubleArray(const RTCStatsMemberInterface* member, size_t* length)
- {
- return ConvertArray(*member->cast_to<::webrtc::RTCStatsMember<std::vector<double>>>(), length);
- }
- UNITY_INTERFACE_EXPORT const char** StatsMemberGetStringArray(const RTCStatsMemberInterface* member, size_t* length)
- {
- std::vector<std::string> vec = *member->cast_to<::webrtc::RTCStatsMember<std::vector<std::string>>>();
- std::vector<const char*> vc;
- std::transform(vec.begin(), vec.end(), std::back_inserter(vc), ConvertString);
- return ConvertArray(vc, length);
- }
- UNITY_INTERFACE_EXPORT RTCStatsMemberInterface::Type StatsMemberGetType(const RTCStatsMemberInterface* member)
- {
- return member->type();
- }
- UNITY_INTERFACE_EXPORT unity::webrtc::SetSessionDescriptionObserver* PeerConnectionSetLocalDescription(
- PeerConnectionObject* obj,
- const RTCSessionDescription* desc,
- RTCErrorType* errorType,
- char* error[])
- {
- std::string error_;
- auto observer = unity::webrtc::SetSessionDescriptionObserver::Create(obj);
- *errorType = obj->SetLocalDescription(*desc, observer, error_);
- *error = ConvertString(error_);
- return observer.get();
- }
- UNITY_INTERFACE_EXPORT unity::webrtc::SetSessionDescriptionObserver*
- PeerConnectionSetLocalDescriptionWithoutDescription(
- PeerConnectionObject* obj, RTCErrorType* errorType, char* error[])
- {
- std::string error_;
- auto observer = unity::webrtc::SetSessionDescriptionObserver::Create(obj);
- *errorType = obj->SetLocalDescriptionWithoutDescription(observer, error_);
- *error = ConvertString(error_);
- return observer.get();
- }
- UNITY_INTERFACE_EXPORT unity::webrtc::SetSessionDescriptionObserver* PeerConnectionSetRemoteDescription(
- PeerConnectionObject* obj,
- const RTCSessionDescription* desc,
- RTCErrorType* errorType,
- char* error[])
- {
- std::string error_;
- auto observer = unity::webrtc::SetSessionDescriptionObserver::Create(obj);
- *errorType = obj->SetRemoteDescription(*desc, observer, error_);
- *error = ConvertString(error_);
- return observer.get();
- }
- UNITY_INTERFACE_EXPORT bool
- PeerConnectionGetLocalDescription(PeerConnectionObject* obj, RTCSessionDescription* desc)
- {
- return obj->GetSessionDescription(obj->connection->local_description(), *desc);
- }
- UNITY_INTERFACE_EXPORT bool
- PeerConnectionGetRemoteDescription(PeerConnectionObject* obj, RTCSessionDescription* desc)
- {
- return obj->GetSessionDescription(obj->connection->remote_description(), *desc);
- }
- UNITY_INTERFACE_EXPORT bool
- PeerConnectionGetPendingLocalDescription(PeerConnectionObject* obj, RTCSessionDescription* desc)
- {
- return obj->GetSessionDescription(obj->connection->pending_local_description(), *desc);
- }
- UNITY_INTERFACE_EXPORT bool
- PeerConnectionGetPendingRemoteDescription(PeerConnectionObject* obj, RTCSessionDescription* desc)
- {
- return obj->GetSessionDescription(obj->connection->pending_remote_description(), *desc);
- }
- UNITY_INTERFACE_EXPORT bool
- PeerConnectionGetCurrentLocalDescription(PeerConnectionObject* obj, RTCSessionDescription* desc)
- {
- return obj->GetSessionDescription(obj->connection->current_local_description(), *desc);
- }
- UNITY_INTERFACE_EXPORT bool
- PeerConnectionGetCurrentRemoteDescription(PeerConnectionObject* obj, RTCSessionDescription* desc)
- {
- return obj->GetSessionDescription(obj->connection->current_remote_description(), *desc);
- }
- UNITY_INTERFACE_EXPORT RtpReceiverInterface**
- PeerConnectionGetReceivers(Context* context, PeerConnectionObject* obj, size_t* length)
- {
- auto receivers = obj->connection->GetReceivers();
- return ConvertPtrArrayFromRefPtrArray<RtpReceiverInterface>(receivers, length);
- }
- UNITY_INTERFACE_EXPORT RtpSenderInterface**
- PeerConnectionGetSenders(Context* context, PeerConnectionObject* obj, size_t* length)
- {
- auto senders = obj->connection->GetSenders();
- return ConvertPtrArrayFromRefPtrArray<RtpSenderInterface>(senders, length);
- }
- UNITY_INTERFACE_EXPORT RtpTransceiverInterface**
- PeerConnectionGetTransceivers(Context* context, PeerConnectionObject* obj, size_t* length)
- {
- auto transceivers = obj->connection->GetTransceivers();
- return ConvertPtrArrayFromRefPtrArray<RtpTransceiverInterface>(transceivers, length);
- }
- UNITY_INTERFACE_EXPORT unity::webrtc::CreateSessionDescriptionObserver*
- PeerConnectionCreateOffer(PeerConnectionObject* obj, const RTCOfferAnswerOptions* options)
- {
- auto observer = unity::webrtc::CreateSessionDescriptionObserver::Create(obj);
- obj->CreateOffer(*options, observer);
- return observer;
- }
- UNITY_INTERFACE_EXPORT unity::webrtc::CreateSessionDescriptionObserver*
- PeerConnectionCreateAnswer(PeerConnectionObject* obj, const RTCOfferAnswerOptions* options)
- {
- auto observer = unity::webrtc::CreateSessionDescriptionObserver::Create(obj);
- obj->CreateAnswer(*options, observer);
- return observer;
- }
- struct RTCDataChannelInit
- {
- Optional<bool> ordered;
- Optional<int32_t> maxRetransmitTime;
- Optional<int32_t> maxRetransmits;
- char* protocol;
- Optional<bool> negotiated;
- Optional<int32_t> id;
- };
- UNITY_INTERFACE_EXPORT DataChannelInterface* ContextCreateDataChannel(
- Context* ctx, PeerConnectionObject* obj, const char* label, const RTCDataChannelInit* options)
- {
- DataChannelInit _options;
- _options.ordered = options->ordered.value_or(true);
- _options.maxRetransmitTime = static_cast<absl::optional<int32_t>>(options->maxRetransmitTime);
- _options.maxRetransmits = static_cast<absl::optional<int32_t>>(options->maxRetransmits);
- _options.protocol = options->protocol == nullptr ? "" : options->protocol;
- _options.negotiated = options->negotiated.value_or(false);
- _options.id = options->id.value_or(-1);
- return ctx->CreateDataChannel(obj, label, _options);
- }
- UNITY_INTERFACE_EXPORT void ContextDeleteDataChannel(Context* ctx, DataChannelInterface* channel)
- {
- ctx->DeleteDataChannel(channel);
- }
- UNITY_INTERFACE_EXPORT void
- PeerConnectionRegisterIceConnectionChange(PeerConnectionObject* obj, DelegateOnIceConnectionChange callback)
- {
- obj->RegisterIceConnectionChange(callback);
- }
- UNITY_INTERFACE_EXPORT void
- PeerConnectionRegisterIceGatheringChange(PeerConnectionObject* obj, DelegateOnIceGatheringChange callback)
- {
- obj->RegisterIceGatheringChange(callback);
- }
- UNITY_INTERFACE_EXPORT void
- PeerConnectionRegisterConnectionStateChange(PeerConnectionObject* obj, DelegateOnConnectionStateChange callback)
- {
- obj->RegisterConnectionStateChange(callback);
- }
- UNITY_INTERFACE_EXPORT void
- PeerConnectionRegisterOnIceCandidate(PeerConnectionObject* obj, DelegateIceCandidate callback)
- {
- obj->RegisterIceCandidate(callback);
- }
- UNITY_INTERFACE_EXPORT void StatsCollectorRegisterCallback(DelegateCollectStats callback)
- {
- PeerConnectionStatsCollectorCallback::RegisterOnGetStats(callback);
- }
- UNITY_INTERFACE_EXPORT void CreateSessionDescriptionObserverRegisterCallback(DelegateCreateSessionDesc callback)
- {
- unity::webrtc::CreateSessionDescriptionObserver::RegisterCallback(callback);
- }
- UNITY_INTERFACE_EXPORT void SetSessionDescriptionObserverRegisterCallback(DelegateSetSessionDesc callback)
- {
- unity::webrtc::SetSessionDescriptionObserver::RegisterCallback(callback);
- }
- UNITY_INTERFACE_EXPORT bool
- PeerConnectionAddIceCandidate(PeerConnectionObject* obj, const IceCandidateInterface* candidate)
- {
- return obj->connection->AddIceCandidate(candidate);
- }
- struct RTCIceCandidateInit
- {
- char* candidate;
- char* sdpMid;
- int32_t sdpMLineIndex;
- };
- struct Candidate
- {
- char* candidate;
- int32_t component;
- char* foundation;
- char* ip;
- uint16_t port;
- uint32_t priority;
- char* address;
- char* protocol;
- char* relatedAddress;
- uint16_t relatedPort;
- char* tcpType;
- char* type;
- char* usernameFragment;
- Candidate& operator=(const cricket::Candidate& obj)
- {
- candidate = ConvertString(obj.ToString());
- component = obj.component();
- foundation = ConvertString(obj.foundation());
- ip = ConvertString(obj.address().ipaddr().ToString());
- port = obj.address().port();
- priority = obj.priority();
- address = ConvertString(obj.address().ToString());
- protocol = ConvertString(obj.protocol());
- relatedAddress = ConvertString(obj.related_address().ToString());
- relatedPort = obj.related_address().port();
- tcpType = ConvertString(obj.tcptype());
- type = ConvertString(obj.type());
- usernameFragment = ConvertString(obj.username());
- return *this;
- }
- };
- UNITY_INTERFACE_EXPORT RTCErrorType
- CreateIceCandidate(const RTCIceCandidateInit* options, IceCandidateInterface** candidate)
- {
- SdpParseError error;
- IceCandidateInterface* _candidate =
- CreateIceCandidate(options->sdpMid, options->sdpMLineIndex, options->candidate, &error);
- if (_candidate == nullptr)
- return RTCErrorType::INVALID_PARAMETER;
- *candidate = _candidate;
- return RTCErrorType::NONE;
- }
- UNITY_INTERFACE_EXPORT void DeleteIceCandidate(IceCandidateInterface* candidate) { delete candidate; }
- UNITY_INTERFACE_EXPORT void IceCandidateGetCandidate(const IceCandidateInterface* candidate, Candidate* dst)
- {
- *dst = candidate->candidate();
- }
- UNITY_INTERFACE_EXPORT int32_t IceCandidateGetSdpLineIndex(const IceCandidateInterface* candidate)
- {
- return candidate->sdp_mline_index();
- }
- UNITY_INTERFACE_EXPORT const char* IceCandidateGetSdp(const IceCandidateInterface* candidate)
- {
- std::string str;
- if (!candidate->ToString(&str))
- return nullptr;
- return ConvertString(str);
- }
- UNITY_INTERFACE_EXPORT const char* IceCandidateGetSdpMid(const IceCandidateInterface* candidate)
- {
- return ConvertString(candidate->sdp_mid());
- }
- UNITY_INTERFACE_EXPORT PeerConnectionInterface::PeerConnectionState PeerConnectionState(PeerConnectionObject* obj)
- {
- return obj->connection->peer_connection_state();
- }
- UNITY_INTERFACE_EXPORT PeerConnectionInterface::IceConnectionState
- PeerConnectionIceConditionState(PeerConnectionObject* obj)
- {
- return obj->connection->ice_connection_state();
- }
- UNITY_INTERFACE_EXPORT PeerConnectionInterface::SignalingState
- PeerConnectionSignalingState(PeerConnectionObject* obj)
- {
- return obj->connection->signaling_state();
- }
- UNITY_INTERFACE_EXPORT PeerConnectionInterface::IceGatheringState
- PeerConnectionIceGatheringState(PeerConnectionObject* obj)
- {
- return obj->connection->ice_gathering_state();
- }
- UNITY_INTERFACE_EXPORT void
- PeerConnectionRegisterOnDataChannel(PeerConnectionObject* obj, DelegateOnDataChannel callback)
- {
- obj->RegisterOnDataChannel(callback);
- }
- UNITY_INTERFACE_EXPORT void
- PeerConnectionRegisterOnRenegotiationNeeded(PeerConnectionObject* obj, DelegateOnRenegotiationNeeded callback)
- {
- obj->RegisterOnRenegotiationNeeded(callback);
- }
- UNITY_INTERFACE_EXPORT void PeerConnectionRegisterOnTrack(PeerConnectionObject* obj, DelegateOnTrack callback)
- {
- obj->RegisterOnTrack(callback);
- }
- UNITY_INTERFACE_EXPORT void
- PeerConnectionRegisterOnRemoveTrack(PeerConnectionObject* obj, DelegateOnRemoveTrack callback)
- {
- obj->RegisterOnRemoveTrack(callback);
- }
- UNITY_INTERFACE_EXPORT bool
- TransceiverGetCurrentDirection(RtpTransceiverInterface* transceiver, RtpTransceiverDirection* direction)
- {
- if (transceiver->current_direction().has_value())
- {
- *direction = transceiver->current_direction().value();
- return true;
- }
- return false;
- }
- UNITY_INTERFACE_EXPORT RTCErrorType TransceiverStop(RtpTransceiverInterface* transceiver)
- {
- auto error = transceiver->StopStandard();
- return error.type();
- }
- UNITY_INTERFACE_EXPORT RtpTransceiverDirection TransceiverGetDirection(RtpTransceiverInterface* transceiver)
- {
- return transceiver->direction();
- }
- UNITY_INTERFACE_EXPORT RTCErrorType
- TransceiverSetDirection(RtpTransceiverInterface* transceiver, RtpTransceiverDirection direction)
- {
- RTCError error = transceiver->SetDirectionWithError(direction);
- return error.type();
- }
- struct RTCRtpCodecCapability
- {
- char* mimeType;
- Optional<int32_t> clockRate;
- Optional<int32_t> channels;
- char* sdpFmtpLine;
- RTCRtpCodecCapability& operator=(const RtpCodecCapability& obj)
- {
- this->mimeType = ConvertString(obj.mime_type());
- this->clockRate = obj.clock_rate;
- this->channels = obj.num_channels;
- this->sdpFmtpLine = ConvertString(ConvertSdp(obj.parameters));
- return *this;
- }
- };
- UNITY_INTERFACE_EXPORT RTCErrorType
- TransceiverSetCodecPreferences(RtpTransceiverInterface* transceiver, RTCRtpCodecCapability* codecs, size_t length)
- {
- std::vector<RtpCodecCapability> _codecs(length);
- for (size_t i = 0; i < length; i++)
- {
- std::string mimeType = ConvertString(codecs[i].mimeType);
- std::tie(_codecs[i].kind, _codecs[i].name) = ConvertMimeType(mimeType);
- _codecs[i].clock_rate = ConvertOptional(codecs[i].clockRate);
- _codecs[i].num_channels = ConvertOptional(codecs[i].channels);
- _codecs[i].parameters = ConvertSdp(codecs[i].sdpFmtpLine);
- }
- auto error = transceiver->SetCodecPreferences(_codecs);
- if (error.type() != RTCErrorType::NONE)
- RTC_LOG(LS_ERROR) << error.message();
- return error.type();
- }
- UNITY_INTERFACE_EXPORT char* TransceiverGetMid(RtpTransceiverInterface* transceiver)
- {
- auto mid = transceiver->mid();
- if (!mid.has_value())
- {
- return nullptr;
- }
- return ConvertString(mid.value());
- }
- UNITY_INTERFACE_EXPORT RtpReceiverInterface* TransceiverGetReceiver(RtpTransceiverInterface* transceiver)
- {
- return transceiver->receiver().get();
- }
- UNITY_INTERFACE_EXPORT RtpSenderInterface* TransceiverGetSender(RtpTransceiverInterface* transceiver)
- {
- return transceiver->sender().get();
- }
- struct RTCRtpCodecParameters
- {
- int payloadType;
- char* mimeType;
- Optional<uint64_t> clockRate;
- Optional<uint16_t> channels;
- char* sdpFmtpLine;
- RTCRtpCodecParameters& operator=(const RtpCodecParameters& src)
- {
- payloadType = src.payload_type;
- mimeType = ConvertString(src.mime_type());
- clockRate = src.clock_rate;
- channels = src.num_channels;
- sdpFmtpLine = ConvertString(ConvertSdp(src.parameters));
- return *this;
- }
- };
- struct RTCRtpExtension
- {
- char* uri;
- uint16_t id;
- bool encrypted;
- RTCRtpExtension& operator=(const RtpExtension& src)
- {
- uri = ConvertString(src.uri);
- id = static_cast<uint16_t>(src.id);
- encrypted = src.encrypt;
- return *this;
- }
- };
- struct RTCRtcpParameters
- {
- char* cname;
- bool reducedSize;
- RTCRtcpParameters& operator=(const RtcpParameters& src)
- {
- cname = ConvertString(src.cname);
- reducedSize = src.reduced_size;
- return *this;
- }
- };
- struct RTCRtpSendParameters
- {
- MarshallArray<RTCRtpEncodingParameters> encodings;
- char* transactionId;
- MarshallArray<RTCRtpCodecParameters> codecs;
- MarshallArray<RTCRtpExtension> headerExtensions;
- RTCRtcpParameters rtcp;
- RTCRtpSendParameters& operator=(const RtpParameters& src)
- {
- encodings = src.encodings;
- transactionId = ConvertString(src.transaction_id);
- codecs = src.codecs;
- headerExtensions = src.header_extensions;
- rtcp = src.rtcp;
- return *this;
- }
- };
- UNITY_INTERFACE_EXPORT void SenderGetParameters(RtpSenderInterface* sender, RTCRtpSendParameters** parameters)
- {
- const RtpParameters src = sender->GetParameters();
- RTCRtpSendParameters* dst = static_cast<RTCRtpSendParameters*>(CoTaskMemAlloc(sizeof(RTCRtpSendParameters)));
- *dst = src;
- *parameters = dst;
- }
- UNITY_INTERFACE_EXPORT RTCErrorType SenderSetParameters(RtpSenderInterface* sender, const RTCRtpSendParameters* src)
- {
- RtpParameters dst = sender->GetParameters();
- for (size_t i = 0; i < dst.encodings.size(); i++)
- {
- dst.encodings[i].active = src->encodings[i].active;
- dst.encodings[i].max_bitrate_bps =
- static_cast<absl::optional<int>>(ConvertOptional(src->encodings[i].maxBitrate));
- dst.encodings[i].min_bitrate_bps =
- static_cast<absl::optional<int>>(ConvertOptional(src->encodings[i].minBitrate));
- dst.encodings[i].max_framerate =
- static_cast<absl::optional<double>>(ConvertOptional(src->encodings[i].maxFramerate));
- dst.encodings[i].scale_resolution_down_by = ConvertOptional(src->encodings[i].scaleResolutionDownBy);
- if (src->encodings[i].rid != nullptr)
- dst.encodings[i].rid = std::string(src->encodings[i].rid);
- }
- const ::webrtc::RTCError error = sender->SetParameters(dst);
- return error.type();
- }
- struct RTCRtpHeaderExtensionCapability
- {
- char* uri;
- RTCRtpHeaderExtensionCapability& operator=(const RtpHeaderExtensionCapability& obj)
- {
- this->uri = ConvertString(obj.uri);
- return *this;
- }
- };
- struct RTCRtpCapabilities
- {
- MarshallArray<RTCRtpCodecCapability> codecs;
- MarshallArray<RTCRtpHeaderExtensionCapability> extensionHeaders;
- RTCRtpCapabilities& operator=(const RtpCapabilities& src)
- {
- codecs = src.codecs;
- extensionHeaders = src.header_extensions;
- return *this;
- }
- };
- UNITY_INTERFACE_EXPORT void
- ContextGetSenderCapabilities(Context* context, TrackKind trackKind, RTCRtpCapabilities** parameters)
- {
- RtpCapabilities src;
- cricket::MediaType type = trackKind == TrackKind::Audio ? cricket::MEDIA_TYPE_AUDIO : cricket::MEDIA_TYPE_VIDEO;
- context->GetRtpSenderCapabilities(type, &src);
- RTCRtpCapabilities* dst = static_cast<RTCRtpCapabilities*>(CoTaskMemAlloc(sizeof(RTCRtpCapabilities)));
- *dst = src;
- *parameters = dst;
- }
- UNITY_INTERFACE_EXPORT void
- ContextGetReceiverCapabilities(Context* context, TrackKind trackKind, RTCRtpCapabilities** parameters)
- {
- RtpCapabilities src;
- cricket::MediaType type = trackKind == TrackKind::Audio ? cricket::MEDIA_TYPE_AUDIO : cricket::MEDIA_TYPE_VIDEO;
- context->GetRtpReceiverCapabilities(type, &src);
- RTCRtpCapabilities* dst = static_cast<RTCRtpCapabilities*>(CoTaskMemAlloc(sizeof(RTCRtpCapabilities)));
- *dst = src;
- *parameters = dst;
- }
- UNITY_INTERFACE_EXPORT bool SenderReplaceTrack(RtpSenderInterface* sender, MediaStreamTrackInterface* track)
- {
- return sender->SetTrack(track);
- }
- UNITY_INTERFACE_EXPORT MediaStreamTrackInterface* SenderGetTrack(RtpSenderInterface* sender)
- {
- return sender->track().get();
- }
- UNITY_INTERFACE_EXPORT MediaStreamTrackInterface* ReceiverGetTrack(RtpReceiverInterface* receiver)
- {
- return receiver->track().get();
- }
- UNITY_INTERFACE_EXPORT MediaStreamInterface** ReceiverGetStreams(RtpReceiverInterface* receiver, size_t* length)
- {
- return ConvertPtrArrayFromRefPtrArray<MediaStreamInterface>(receiver->streams(), length);
- }
- UNITY_INTERFACE_EXPORT int DataChannelGetID(DataChannelInterface* channel) { return channel->id(); }
- UNITY_INTERFACE_EXPORT char* DataChannelGetLabel(DataChannelInterface* channel)
- {
- return ConvertString(channel->label());
- }
- UNITY_INTERFACE_EXPORT char* DataChannelGetProtocol(DataChannelInterface* channel)
- {
- return ConvertString(channel->protocol());
- }
- UNITY_INTERFACE_EXPORT uint16_t DataChannelGetMaxRetransmits(DataChannelInterface* channel)
- {
- return channel->maxRetransmits();
- }
- UNITY_INTERFACE_EXPORT uint16_t DataChannelGetMaxRetransmitTime(DataChannelInterface* channel)
- {
- return channel->maxRetransmitTime();
- }
- UNITY_INTERFACE_EXPORT bool DataChannelGetOrdered(DataChannelInterface* channel) { return channel->ordered(); }
- UNITY_INTERFACE_EXPORT uint64_t DataChannelGetBufferedAmount(DataChannelInterface* channel)
- {
- return channel->buffered_amount();
- }
- UNITY_INTERFACE_EXPORT bool DataChannelGetNegotiated(DataChannelInterface* channel)
- {
- return channel->negotiated();
- }
- UNITY_INTERFACE_EXPORT DataChannelInterface::DataState DataChannelGetReadyState(DataChannelInterface* channel)
- {
- return channel->state();
- }
- UNITY_INTERFACE_EXPORT void DataChannelSend(DataChannelInterface* channel, const char* data)
- {
- channel->Send(webrtc::DataBuffer(std::string(data)));
- }
- UNITY_INTERFACE_EXPORT void DataChannelSendBinary(DataChannelInterface* channel, const byte* data, int length)
- {
- rtc::CopyOnWriteBuffer buf(data, static_cast<size_t>(length));
- channel->Send(webrtc::DataBuffer(buf, true));
- }
- UNITY_INTERFACE_EXPORT void DataChannelClose(DataChannelInterface* channel) { channel->Close(); }
- UNITY_INTERFACE_EXPORT void
- DataChannelRegisterOnMessage(Context* context, DataChannelInterface* channel, DelegateOnMessage callback)
- {
- context->GetDataChannelObject(channel)->RegisterOnMessage(callback);
- }
- UNITY_INTERFACE_EXPORT void
- DataChannelRegisterOnOpen(Context* context, DataChannelInterface* channel, DelegateOnOpen callback)
- {
- context->GetDataChannelObject(channel)->RegisterOnOpen(callback);
- }
- UNITY_INTERFACE_EXPORT void
- DataChannelRegisterOnClose(Context* context, DataChannelInterface* channel, DelegateOnClose callback)
- {
- context->GetDataChannelObject(channel)->RegisterOnClose(callback);
- }
- UNITY_INTERFACE_EXPORT void SetCurrentContext(Context* context)
- {
- ContextManager::GetInstance()->curContext = context;
- }
- UNITY_INTERFACE_EXPORT void AudioSourceProcessLocalAudio(
- UnityAudioTrackSource* source,
- float* audio_data,
- int32 sample_rate,
- int32 number_of_channels,
- int32 number_of_frames)
- {
- if (source != nullptr)
- {
- source->PushAudioData(
- audio_data,
- sample_rate,
- static_cast<size_t>(number_of_channels),
- static_cast<size_t>(number_of_frames));
- }
- }
- UNITY_INTERFACE_EXPORT AudioTrackSinkAdapter* ContextCreateAudioTrackSink(Context* context)
- {
- return context->CreateAudioTrackSinkAdapter();
- }
- UNITY_INTERFACE_EXPORT void ContextDeleteAudioTrackSink(Context* context, AudioTrackSinkAdapter* sink)
- {
- return context->DeleteAudioTrackSinkAdapter(sink);
- }
- UNITY_INTERFACE_EXPORT void AudioTrackAddSink(AudioTrackInterface* track, AudioTrackSinkInterface* sink)
- {
- track->AddSink(sink);
- }
- UNITY_INTERFACE_EXPORT void AudioTrackRemoveSink(AudioTrackInterface* track, AudioTrackSinkInterface* sink)
- {
- track->RemoveSink(sink);
- }
- UNITY_INTERFACE_EXPORT void
- AudioTrackSinkProcessAudio(AudioTrackSinkAdapter* sink, float* data, size_t length, int channels, int sampleRate)
- {
- sink->ProcessAudio(data, length, static_cast<size_t>(channels), sampleRate);
- }
- #pragma clang diagnostic pop
- }
|