From 575929c1bf7f5c4c52db27ae0d4061cd7152f294 Mon Sep 17 00:00:00 2001 From: Laky64 Date: Mon, 11 Sep 2023 14:20:48 +0200 Subject: [PATCH 01/16] Removed named DispatchQueue --- ntgcalls/io/base_reader.cpp | 2 +- ntgcalls/ntgcalls.cpp | 2 +- ntgcalls/stream.cpp | 2 +- ntgcalls/utils/dispatch_queue.cpp | 3 +-- ntgcalls/utils/dispatch_queue.hpp | 3 +-- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ntgcalls/io/base_reader.cpp b/ntgcalls/io/base_reader.cpp index b9fabadd..5cc8beda 100644 --- a/ntgcalls/io/base_reader.cpp +++ b/ntgcalls/io/base_reader.cpp @@ -7,7 +7,7 @@ namespace ntgcalls { BaseReader::BaseReader() { - dispatchQueue = std::make_shared("Reader_" + rtc::CreateRandomUuid()); + dispatchQueue = std::make_shared(); } BaseReader::~BaseReader() { diff --git a/ntgcalls/ntgcalls.cpp b/ntgcalls/ntgcalls.cpp index 8bee6ec8..bc9ac325 100644 --- a/ntgcalls/ntgcalls.cpp +++ b/ntgcalls/ntgcalls.cpp @@ -6,7 +6,7 @@ namespace ntgcalls { NTgCalls::NTgCalls() { - dispatchUpdates = std::make_shared("Updates_" + rtc::CreateRandomUuid()); + dispatchUpdates = std::make_shared(); } std::string NTgCalls::createCall(int64_t chatId, MediaDescription media) { diff --git a/ntgcalls/stream.cpp b/ntgcalls/stream.cpp index e2e1b75a..59e89c11 100644 --- a/ntgcalls/stream.cpp +++ b/ntgcalls/stream.cpp @@ -8,7 +8,7 @@ namespace ntgcalls { Stream::Stream() { audio = std::make_shared(); video = std::make_shared(); - dispatchQueue = std::make_shared("StreamQueue_" + rtc::CreateRandomUuid()); + dispatchQueue = std::make_shared(); } Stream::~Stream() { diff --git a/ntgcalls/utils/dispatch_queue.cpp b/ntgcalls/utils/dispatch_queue.cpp index bf3ed71a..500f559c 100644 --- a/ntgcalls/utils/dispatch_queue.cpp +++ b/ntgcalls/utils/dispatch_queue.cpp @@ -4,8 +4,7 @@ #include "dispatch_queue.hpp" -DispatchQueue::DispatchQueue(std::string name, size_t threadCount) : - name{std::move(name)}, threads(threadCount) { +DispatchQueue::DispatchQueue(size_t threadCount) : threads(threadCount) { for(auto & i : threads) { i = std::thread(&DispatchQueue::dispatchThreadHandler, this); } diff --git a/ntgcalls/utils/dispatch_queue.hpp b/ntgcalls/utils/dispatch_queue.hpp index d245830a..9d11f1ce 100644 --- a/ntgcalls/utils/dispatch_queue.hpp +++ b/ntgcalls/utils/dispatch_queue.hpp @@ -17,7 +17,7 @@ class DispatchQueue { typedef std::function fp_t; public: - explicit DispatchQueue(std::string name, size_t threadCount = 1); + explicit DispatchQueue(size_t threadCount = 1); ~DispatchQueue(); void dispatch(const fp_t& op); @@ -25,7 +25,6 @@ class DispatchQueue { void dispatch(fp_t&& op); private: - std::string name; std::mutex lockMutex; std::vector threads; std::queue queue; From 14ee7cdd701f444fe42e3d4c89e4e4a6bb7e199e Mon Sep 17 00:00:00 2001 From: Laky64 Date: Mon, 11 Sep 2023 14:21:17 +0200 Subject: [PATCH 02/16] Fixed a segfault while streaming with audio-video --- ntgcalls/stream.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ntgcalls/stream.cpp b/ntgcalls/stream.cpp index 59e89c11..2152e356 100644 --- a/ntgcalls/stream.cpp +++ b/ntgcalls/stream.cpp @@ -66,20 +66,19 @@ namespace ntgcalls { } void Stream::sendSample() { - if (idling || !(reader->audio || reader->video)) { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - } else { - auto bsBR = unsafePrepareForSample(); - auto sample = bsBR.second->read(bsBR.first->frameSize()); - bsBR.first->sendData(sample); - if (sample != nullptr) delete[] sample; - checkStream(); - } - if (running) { - dispatchQueue->dispatch([this]() { - sendSample(); - }); + if (idling || !reader || !(reader->audio || reader->video)) { + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } else { + auto bsBR = unsafePrepareForSample(); + if (bsBR.first != nullptr && bsBR.second != nullptr) { + auto sample = bsBR.second->read(bsBR.first->frameSize()); + bsBR.first->sendData(sample); + if (sample != nullptr) delete[] sample; + } + checkStream(); + } + sendSample(); } } From 16f8056fffc6f32ef98b3e95dd631b8899166a77 Mon Sep 17 00:00:00 2001 From: Laky64 Date: Tue, 12 Sep 2023 14:05:39 +0200 Subject: [PATCH 03/16] Fixed segfault while re-connecting to WebRTC --- ntgcalls/client.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ntgcalls/client.cpp b/ntgcalls/client.cpp index 46b16c3c..a9425ea1 100644 --- a/ntgcalls/client.cpp +++ b/ntgcalls/client.cpp @@ -109,6 +109,7 @@ namespace ntgcalls { } }); waitConnection.wait(); + connection->onIceStateChange(nullptr); stream->start(); } From 3199d887001c71896758baa80e6e11589dfe848a Mon Sep 17 00:00:00 2001 From: Laky64 Date: Tue, 12 Sep 2023 14:05:53 +0200 Subject: [PATCH 04/16] Code Cleanup --- ntgcalls/io/base_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntgcalls/io/base_reader.cpp b/ntgcalls/io/base_reader.cpp index 5cc8beda..681555fb 100644 --- a/ntgcalls/io/base_reader.cpp +++ b/ntgcalls/io/base_reader.cpp @@ -36,7 +36,7 @@ namespace ntgcalls { if (promise != nullptr) promise->get_future().wait(); } res = nextBuffer[0]; - nextBuffer.erase(nextBuffer.begin(), nextBuffer.begin() + 1); + nextBuffer.erase(nextBuffer.begin() + 1); return res; } From 9998b9a0e6c4712847ade1c645eb6c52dbe8fdeb Mon Sep 17 00:00:00 2001 From: Laky64 Date: Tue, 12 Sep 2023 14:28:58 +0200 Subject: [PATCH 05/16] Added missing parameters to Video Frame --- wrtc/interfaces/media/rtc_video_source.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wrtc/interfaces/media/rtc_video_source.cpp b/wrtc/interfaces/media/rtc_video_source.cpp index 462b27d1..f5f1dd05 100644 --- a/wrtc/interfaces/media/rtc_video_source.cpp +++ b/wrtc/interfaces/media/rtc_video_source.cpp @@ -24,7 +24,10 @@ namespace wrtc { void RTCVideoSource::OnFrame(i420ImageData data) { webrtc::VideoFrame::Builder builder; + builder.set_timestamp_rtp(0); + builder.set_timestamp_us(rtc::TimeMillis()); builder.set_timestamp_us(rtc::TimeMicros()); + builder.set_rotation(webrtc::kVideoRotation_0); builder.set_video_frame_buffer(data.buffer()); source->PushFrame(builder.build()); } From 1ce3a95cabed0a6a102d75402afe76abb5b7f244 Mon Sep 17 00:00:00 2001 From: Laky64 Date: Tue, 12 Sep 2023 18:53:00 +0200 Subject: [PATCH 06/16] Code cleanup --- ntgcalls/bindings/pythonapi.cpp | 18 +++++++++--------- ntgcalls/io/base_reader.cpp | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ntgcalls/bindings/pythonapi.cpp b/ntgcalls/bindings/pythonapi.cpp index 342907d8..49ae9b63 100644 --- a/ntgcalls/bindings/pythonapi.cpp +++ b/ntgcalls/bindings/pythonapi.cpp @@ -15,15 +15,15 @@ namespace py = pybind11; PYBIND11_MODULE(ntgcalls, m) { py::class_ wrapper(m, "NTgCalls"); wrapper.def(py::init<>()); - wrapper.def("createCall", &ntgcalls::NTgCalls::createCall, py::arg("chat_id"), py::arg("media")); - wrapper.def("connect", &ntgcalls::NTgCalls::connect, py::arg("chat_id"), py::arg("params")); - wrapper.def("changeStream", &ntgcalls::NTgCalls::changeStream, py::arg("chat_id"), py::arg("media")); - wrapper.def("pause", &ntgcalls::NTgCalls::pause, py::arg("chat_id")); - wrapper.def("resume", &ntgcalls::NTgCalls::resume, py::arg("chat_id")); - wrapper.def("mute", &ntgcalls::NTgCalls::mute, py::arg("chat_id")); - wrapper.def("unmute", &ntgcalls::NTgCalls::unmute, py::arg("chat_id")); - wrapper.def("stop", &ntgcalls::NTgCalls::stop, py::arg("chat_id")); - wrapper.def("time", &ntgcalls::NTgCalls::time, py::arg("chat_id")); + wrapper.def("createCall", &ntgcalls::NTgCalls::createCall, py::arg("chat_id"), py::arg("media")); + wrapper.def("connect", &ntgcalls::NTgCalls::connect, py::arg("chat_id"), py::arg("params")); + wrapper.def("changeStream", &ntgcalls::NTgCalls::changeStream, py::arg("chat_id"), py::arg("media")); + wrapper.def("pause", &ntgcalls::NTgCalls::pause, py::arg("chat_id")); + wrapper.def("resume", &ntgcalls::NTgCalls::resume, py::arg("chat_id")); + wrapper.def("mute", &ntgcalls::NTgCalls::mute, py::arg("chat_id")); + wrapper.def("unmute", &ntgcalls::NTgCalls::unmute, py::arg("chat_id")); + wrapper.def("stop", &ntgcalls::NTgCalls::stop, py::arg("chat_id")); + wrapper.def("time", &ntgcalls::NTgCalls::time, py::arg("chat_id")); wrapper.def("onUpgrade", &ntgcalls::NTgCalls::onUpgrade); wrapper.def("onStreamEnd", &ntgcalls::NTgCalls::onStreamEnd); wrapper.def("calls", &ntgcalls::NTgCalls::calls); diff --git a/ntgcalls/io/base_reader.cpp b/ntgcalls/io/base_reader.cpp index 681555fb..f35fed3a 100644 --- a/ntgcalls/io/base_reader.cpp +++ b/ntgcalls/io/base_reader.cpp @@ -29,7 +29,7 @@ namespace ntgcalls { } catch (...) { _eof = true; } - if (promise!= nullptr) promise->set_value(); + if (promise != nullptr) promise->set_value(); }); } if (nextBuffer.empty() && !_eof) { From f56c5e092e70b8dcade4272b617048c62d3b0411 Mon Sep 17 00:00:00 2001 From: Laky64 Date: Tue, 12 Sep 2023 18:53:59 +0200 Subject: [PATCH 07/16] Updated C Bindings --- include/ntgcalls.h | 44 +++++++++++++++---------------- ntgcalls/bindings/ntgcalls.cpp | 48 +++++++++++++++++----------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/include/ntgcalls.h b/include/ntgcalls.h index 612637a4..249af223 100644 --- a/include/ntgcalls.h +++ b/include/ntgcalls.h @@ -39,62 +39,62 @@ typedef enum { NTG_FILE, NTG_SHELL, NTG_FFMPEG -} ntgInputMode; +} ntg_input_mode_enum; typedef enum { - NTG_STREAM_AUDIO = 0, - NTG_STREAM_VIDEO = 1 -} ntgStreamType; + NTG_STREAM_AUDIO, + NTG_STREAM_VIDEO +} ntg_stream_type_enum; typedef enum { NTG_PLAYING, NTG_PAUSED, NTG_IDLING -} ntgStreamStatus; +} ntg_stream_status_enum; typedef struct { - ntgInputMode inputMode; + ntg_input_mode_enum inputMode; char* input; uint16_t sampleRate; uint8_t bitsPerSample, channelCount; -} ntgAudioDescription; +} ntg_audio_description_struct; typedef struct { - ntgInputMode inputMode; + ntg_input_mode_enum inputMode; char* input; uint16_t width, height; uint8_t fps; -} ntgVideoDescription; +} ntg_video_description_struct; typedef struct { - ntgAudioDescription* audio; - ntgVideoDescription* video; -} ntgMediaDescription; + ntg_audio_description_struct* audio; + ntg_video_description_struct* video; +} ntg_media_description_struct; typedef struct { int64_t chatId; - ntgStreamStatus status; -} ntgGroupCall; + ntg_stream_status_enum status; +} ntg_group_call_struct; typedef struct { bool muted; bool videoPaused; bool videoStopped; -} ntgMediaState; +} ntg_media_state_struct; -typedef void (*ntgStreamEndCallback)(uint32_t, int64_t, ntgStreamType); +typedef void (*ntg_stream_callback)(uint32_t, int64_t, ntg_stream_type_enum); -typedef void (*ntgUpgradeCallback)(uint32_t, int64_t, ntgMediaState); +typedef void (*ntg_upgrade_callback)(uint32_t, int64_t, ntg_media_state_struct); NTG_C_EXPORT uint32_t ntg_init(); NTG_C_EXPORT int ntg_destroy(uint32_t uid); -NTG_C_EXPORT int ntg_get_params(uint32_t uid, int64_t chatID, ntgMediaDescription rep, char* buffer, int size); +NTG_C_EXPORT int ntg_get_params(uint32_t uid, int64_t chatID, ntg_media_description_struct rep, char* buffer, int size); NTG_C_EXPORT int ntg_connect(uint32_t uid, int64_t chatID, char* params); -NTG_C_EXPORT int ntg_change_stream(uint32_t uid, int64_t chatID, ntgMediaDescription desc); +NTG_C_EXPORT int ntg_change_stream(uint32_t uid, int64_t chatID, ntg_media_description_struct desc); NTG_C_EXPORT bool ntg_pause(uint32_t uid, int64_t chatID); @@ -108,13 +108,13 @@ NTG_C_EXPORT int ntg_stop(uint32_t uid, int64_t chatID); NTG_C_EXPORT uint64_t ntg_time(uint32_t uid, int64_t chatID); -NTG_C_EXPORT int ntg_calls(uint32_t uid, ntgGroupCall *buffer, int size); +NTG_C_EXPORT int ntg_calls(uint32_t uid, ntg_group_call_struct *buffer, int size); NTG_C_EXPORT int ntg_calls_count(uint32_t uid); -NTG_C_EXPORT int ntg_on_stream_end(uint32_t uid, ntgStreamEndCallback callback); +NTG_C_EXPORT int ntg_on_stream_end(uint32_t uid, ntg_stream_callback callback); -NTG_C_EXPORT int ntg_on_upgrade(uint32_t uid, ntgUpgradeCallback callback); +NTG_C_EXPORT int ntg_on_upgrade(uint32_t uid, ntg_upgrade_callback callback); #ifdef __cplusplus } diff --git a/ntgcalls/bindings/ntgcalls.cpp b/ntgcalls/bindings/ntgcalls.cpp index e10732cf..9f7cd8f5 100644 --- a/ntgcalls/bindings/ntgcalls.cpp +++ b/ntgcalls/bindings/ntgcalls.cpp @@ -38,35 +38,35 @@ std::shared_ptr safeUID(uint32_t uid) { return clients[uid]; } -ntgcalls::BaseMediaDescription::InputMode parseInputMode(ntgInputMode mode) { +ntgcalls::BaseMediaDescription::InputMode parseInputMode(ntg_input_mode_enum mode) { switch (mode) { - case ntgInputMode::NTG_FILE: + case ntg_input_mode_enum::NTG_FILE: return ntgcalls::BaseMediaDescription::InputMode::File; - case ntgInputMode::NTG_SHELL: + case ntg_input_mode_enum::NTG_SHELL: return ntgcalls::BaseMediaDescription::InputMode::Shell; - case ntgInputMode::NTG_FFMPEG: + case ntg_input_mode_enum::NTG_FFMPEG: return ntgcalls::BaseMediaDescription::InputMode::FFmpeg; } } -ntgStreamStatus parseStatus(ntgcalls::Stream::Status status) { +ntg_stream_status_enum parseStatus(ntgcalls::Stream::Status status) { switch (status) { case ntgcalls::Stream::Playing: - return ntgStreamStatus::NTG_PLAYING; + return ntg_stream_status_enum::NTG_PLAYING; case ntgcalls::Stream::Paused: - return ntgStreamStatus::NTG_PAUSED; + return ntg_stream_status_enum::NTG_PAUSED; case ntgcalls::Stream::Idling: - return ntgStreamStatus::NTG_IDLING; + return ntg_stream_status_enum::NTG_IDLING; } } -ntgcalls::MediaDescription parseMediaDescription(ntgMediaDescription& desc) { +ntgcalls::MediaDescription parseMediaDescription(ntg_media_description_struct& desc) { std::optional audio; std::optional video; if (desc.audio) { switch (desc.audio->inputMode) { - case ntgInputMode::NTG_FILE: - case ntgInputMode::NTG_SHELL: + case ntg_input_mode_enum::NTG_FILE: + case ntg_input_mode_enum::NTG_SHELL: audio = ntgcalls::AudioDescription( parseInputMode(desc.audio->inputMode), desc.audio->sampleRate, @@ -75,14 +75,14 @@ ntgcalls::MediaDescription parseMediaDescription(ntgMediaDescription& desc) { std::string(desc.audio->input) ); break; - case ntgInputMode::NTG_FFMPEG: + case ntg_input_mode_enum::NTG_FFMPEG: throw ntgcalls::FFmpegError("Not supported"); } } if (desc.video) { switch (desc.audio->inputMode) { - case ntgInputMode::NTG_FILE: - case ntgInputMode::NTG_SHELL: + case ntg_input_mode_enum::NTG_FILE: + case ntg_input_mode_enum::NTG_SHELL: video = ntgcalls::VideoDescription( parseInputMode(desc.audio->inputMode), desc.video->width, @@ -91,7 +91,7 @@ ntgcalls::MediaDescription parseMediaDescription(ntgMediaDescription& desc) { std::string(desc.video->input) ); break; - case ntgInputMode::NTG_FFMPEG: + case ntg_input_mode_enum::NTG_FFMPEG: throw ntgcalls::FFmpegError("Not supported"); } } @@ -115,7 +115,7 @@ int ntg_destroy(uint32_t uid) { return 0; } -int ntg_get_params(uint32_t uid, int64_t chatID, ntgMediaDescription desc, char* buffer, int size) { +int ntg_get_params(uint32_t uid, int64_t chatID, ntg_media_description_struct desc, char* buffer, int size) { try { return copyAndReturn(safeUID(uid)->createCall(chatID, parseMediaDescription(desc)), buffer, size); } catch (ntgcalls::InvalidUUID) { @@ -152,7 +152,7 @@ int ntg_connect(uint32_t uid, int64_t chatID, char* params) { return 0; } -int ntg_change_stream(uint32_t uid, int64_t chatID, ntgMediaDescription desc) { +int ntg_change_stream(uint32_t uid, int64_t chatID, ntg_media_description_struct desc) { try { safeUID(uid)->changeStream(chatID, parseMediaDescription(desc)); } catch (ntgcalls::InvalidUUID) { @@ -220,12 +220,12 @@ uint64_t ntg_time(uint32_t uid, int64_t chatID) { } } -int ntg_calls(uint32_t uid, ntgGroupCall *buffer, int size) { +int ntg_calls(uint32_t uid, ntg_group_call_struct *buffer, int size) { try { auto callsCpp = safeUID(uid)->calls(); - std::vector groupCalls; + std::vector groupCalls; for (auto call : callsCpp) { - groupCalls.push_back(ntgGroupCall{ + groupCalls.push_back(ntg_group_call_struct{ call.first, parseStatus(call.second), }); @@ -244,10 +244,10 @@ int ntg_calls_count(uint32_t uid) { } } -int ntg_on_stream_end(uint32_t uid, ntgStreamEndCallback callback) { +int ntg_on_stream_end(uint32_t uid, ntg_stream_callback callback) { try { safeUID(uid)->onStreamEnd([uid, callback](int64_t chatId, ntgcalls::Stream::Type type) { - callback(uid, chatId, type == ntgcalls::Stream::Type::Audio ? ntgStreamType::NTG_STREAM_AUDIO:ntgStreamType::NTG_STREAM_VIDEO); + callback(uid, chatId, type == ntgcalls::Stream::Type::Audio ? ntg_stream_type_enum::NTG_STREAM_AUDIO : ntg_stream_type_enum::NTG_STREAM_VIDEO); }); } catch (ntgcalls::InvalidUUID) { return NTG_INVALID_UID; @@ -257,10 +257,10 @@ int ntg_on_stream_end(uint32_t uid, ntgStreamEndCallback callback) { return 0; } -int ntg_on_upgrade(uint32_t uid, ntgUpgradeCallback callback) { +int ntg_on_upgrade(uint32_t uid, ntg_upgrade_callback callback) { try { safeUID(uid)->onUpgrade([uid, callback](int64_t chatId, ntgcalls::MediaState state) { - callback(uid, chatId, ntgMediaState{ + callback(uid, chatId, ntg_media_state_struct{ state.muted, state.videoPaused, state.videoStopped, From 977aded391d9f3dc1ccf6e1c19edf105ac138c11 Mon Sep 17 00:00:00 2001 From: Laky64 Date: Tue, 12 Sep 2023 18:59:37 +0200 Subject: [PATCH 08/16] Updated Go Example --- examples/go/ntgcalls/audio_description.go | 4 ++-- examples/go/ntgcalls/media_description.go | 4 ++-- examples/go/ntgcalls/ntgcalls.go | 10 +++++----- examples/go/ntgcalls/types.go | 2 +- examples/go/ntgcalls/video_description.go | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/go/ntgcalls/audio_description.go b/examples/go/ntgcalls/audio_description.go index b1b2c26c..ae9380cb 100644 --- a/examples/go/ntgcalls/audio_description.go +++ b/examples/go/ntgcalls/audio_description.go @@ -11,8 +11,8 @@ type AudioDescription struct { BitsPerSample, ChannelCount uint8 } -func (ctx *AudioDescription) ParseToC() C.ntgAudioDescription { - var x C.ntgAudioDescription +func (ctx *AudioDescription) ParseToC() C.ntg_audio_description_struct { + var x C.ntg_audio_description_struct x.inputMode = ctx.InputMode.ParseToC() x.input = C.CString(ctx.Input) x.sampleRate = C.uint16_t(ctx.SampleRate) diff --git a/examples/go/ntgcalls/media_description.go b/examples/go/ntgcalls/media_description.go index 442c44fb..793efa74 100644 --- a/examples/go/ntgcalls/media_description.go +++ b/examples/go/ntgcalls/media_description.go @@ -8,8 +8,8 @@ type MediaDescription struct { Video *VideoDescription } -func (ctx *MediaDescription) ParseToC() C.ntgMediaDescription { - var x C.ntgMediaDescription +func (ctx *MediaDescription) ParseToC() C.ntg_media_description_struct { + var x C.ntg_media_description_struct if ctx.Audio != nil { audio := ctx.Audio.ParseToC() x.audio = &audio diff --git a/examples/go/ntgcalls/ntgcalls.go b/examples/go/ntgcalls/ntgcalls.go index b61242de..69acc5e8 100644 --- a/examples/go/ntgcalls/ntgcalls.go +++ b/examples/go/ntgcalls/ntgcalls.go @@ -1,8 +1,8 @@ package ntgcalls //#include "ntgcalls.h" -//extern void handleStream(uint32_t uid, int64_t chatID, ntgStreamType streamType); -//extern void handleUpgrade(uint32_t uid, int64_t chatID, ntgMediaState state); +//extern void handleStream(uint32_t uid, int64_t chatID, ntg_stream_type_enum streamType); +//extern void handleUpgrade(uint32_t uid, int64_t chatID, ntg_media_state_struct state); import "C" import ( "fmt" @@ -23,7 +23,7 @@ func NTgCalls() *Instance { } //export handleStream -func handleStream(uid C.uint32_t, chatID C.int64_t, streamType C.ntgStreamType) { +func handleStream(uid C.uint32_t, chatID C.int64_t, streamType C.ntg_stream_type_enum) { goChatID := int64(chatID) goUID := uint32(uid) var goStreamType StreamType @@ -40,7 +40,7 @@ func handleStream(uid C.uint32_t, chatID C.int64_t, streamType C.ntgStreamType) } //export handleUpgrade -func handleUpgrade(uid C.uint32_t, chatID C.int64_t, state C.ntgMediaState) { +func handleUpgrade(uid C.uint32_t, chatID C.int64_t, state C.ntg_media_state_struct) { goChatID := int64(chatID) goUID := uint32(uid) goState := MediaState{ @@ -135,7 +135,7 @@ func (ctx *Instance) Calls() map[int64]StreamStatus { mapReturn := make(map[int64]StreamStatus) callSize := C.ntg_calls_count(C.uint32_t(ctx.uid)) - buffer := make([]C.ntgGroupCall, callSize) + buffer := make([]C.ntg_group_call_struct, callSize) C.ntg_calls(C.uint32_t(ctx.uid), &buffer[0], callSize) for _, call := range buffer { diff --git a/examples/go/ntgcalls/types.go b/examples/go/ntgcalls/types.go index 2b4161af..d2cb7c27 100644 --- a/examples/go/ntgcalls/types.go +++ b/examples/go/ntgcalls/types.go @@ -27,7 +27,7 @@ const ( IdlingStream ) -func (ctx InputMode) ParseToC() C.ntgInputMode { +func (ctx InputMode) ParseToC() C.ntg_input_mode_enum { switch ctx { case InputModeFile: return C.NTG_FILE diff --git a/examples/go/ntgcalls/video_description.go b/examples/go/ntgcalls/video_description.go index 96cc8380..f756e1ea 100644 --- a/examples/go/ntgcalls/video_description.go +++ b/examples/go/ntgcalls/video_description.go @@ -11,8 +11,8 @@ type VideoDescription struct { Fps uint8 } -func (ctx *VideoDescription) ParseToC() C.ntgVideoDescription { - var x C.ntgVideoDescription +func (ctx *VideoDescription) ParseToC() C.ntg_video_description_struct { + var x C.ntg_video_description_struct x.inputMode = ctx.InputMode.ParseToC() x.input = C.CString(ctx.Input) x.width = C.uint16_t(ctx.Width) From 1cfb419d6f946e66f7c88f204cd03bd03fb21079 Mon Sep 17 00:00:00 2001 From: dogghi no <75123663+doggyhaha@users.noreply.github.com> Date: Tue, 12 Sep 2023 21:43:51 +0200 Subject: [PATCH 09/16] Automatic releases --- .github/workflows/build.yml | 56 ++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 58cef68a..15b1ce5e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -79,11 +79,65 @@ jobs: needs: [build] permissions: id-token: write + contents: write steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Get library Version + id: get-library-version + run: | + VERSION=$(grep -oP -m 1 'ntgcalls VERSION \K[A-Za-z0-9.]+' CMakeLists.txt) + echo "Library Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Patch version number + id: patch-version + run: | + version="${{ steps.get-library-version.outputs.version }}" + if [[ "$version" == *.*.* ]]; then + echo "Version contains three dots" + major=$(echo "$version" | cut -d. -f1) + minor=$(echo "$version" | cut -d. -f2) + patch=$(echo "$version" | cut -d. -f3) + tweak=$(echo "$version" | cut -d. -f4) + new_version="${major}.${minor}.${patch}.dev${tweak}" + echo $new_version + echo "new_version=$new_version" >> $GITHUB_OUTPUT + echo "is_dev=true" >> $GITHUB_OUTPUT + else + echo "Version does not contain three dots" + echo "new_version=${{ steps.get-library-version.outputs.version }}" >> $GITHUB_OUTPUT + echo "is_dev=false" >> $GITHUB_OUTPUT + fi + - name: Download artifacts uses: actions/download-artifact@v3 with: path: tmp/ + + - name: Zip releases + run: | + mkdir releases + for dir in tmp/*.zip; do + if [ -d "$dir" ]; then + folder_name=$(basename "$dir" .zip) + zip -r "releases/${folder_name}.zip" "$dir" + fi + done + ls releases + + - name: Create Release + id: create-new-release + uses: softprops/action-gh-release@v1 + with: + files: | + ./releases/* + tag_name: "v${{ steps.patch-version.outputs.new_version }}" + name: "NTgCalls auto build v${{ steps.patch-version.outputs.new_version }}" + body: "These are the build files for the commit [${{ github.sha }}](https://github.com/${{ github.repository }}/${{ github.sha }}).\nThese files were built during [this workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})." + prerelease: ${{ steps.patch-version.outputs.is_dev }} + - name: Extract artifacts run: | mkdir dist @@ -94,4 +148,4 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 with: skip-existing: true - packages-dir: dist/ \ No newline at end of file + packages-dir: dist/ From 29b727fc6d4a3c2f1e7d5c93042c965dfa5dbe37 Mon Sep 17 00:00:00 2001 From: Laky64 Date: Tue, 12 Sep 2023 23:28:54 +0200 Subject: [PATCH 10/16] Updated WebRTC to m117 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7baf9b2..ef404611 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ endif () include(ExternalProject) # https://chromiumdash.appspot.com/branches -set(WEBRTC_REVISION m116.5845.6.1) +set(WEBRTC_REVISION m117.5938.2.0) set(BOOST_REVISION 1.83.0) set(BOOST_LIBS filesystem) From 94f62db9ed9e3e5ab4a016b918831523430bcace Mon Sep 17 00:00:00 2001 From: Laky64 Date: Tue, 12 Sep 2023 23:29:03 +0200 Subject: [PATCH 11/16] Code cleanup --- ntgcalls/stream.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ntgcalls/stream.cpp b/ntgcalls/stream.cpp index 2152e356..4bb482d7 100644 --- a/ntgcalls/stream.cpp +++ b/ntgcalls/stream.cpp @@ -71,10 +71,10 @@ namespace ntgcalls { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } else { auto bsBR = unsafePrepareForSample(); - if (bsBR.first != nullptr && bsBR.second != nullptr) { + if (bsBR.first && bsBR.second) { auto sample = bsBR.second->read(bsBR.first->frameSize()); bsBR.first->sendData(sample); - if (sample != nullptr) delete[] sample; + if (sample) delete[] sample; } checkStream(); } From 5f45b3d8b2efe6915fe8387aa15fe11f5574d79d Mon Sep 17 00:00:00 2001 From: Laky64 Date: Tue, 12 Sep 2023 23:29:29 +0200 Subject: [PATCH 12/16] Fixed wrong deleting set bytes index --- ntgcalls/io/base_reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntgcalls/io/base_reader.cpp b/ntgcalls/io/base_reader.cpp index f35fed3a..00b6ba83 100644 --- a/ntgcalls/io/base_reader.cpp +++ b/ntgcalls/io/base_reader.cpp @@ -36,7 +36,7 @@ namespace ntgcalls { if (promise != nullptr) promise->get_future().wait(); } res = nextBuffer[0]; - nextBuffer.erase(nextBuffer.begin() + 1); + nextBuffer.erase(nextBuffer.begin()); return res; } From d94312fa6ee43518e799f098d72e2746d2bdf094 Mon Sep 17 00:00:00 2001 From: Laky64 Date: Tue, 12 Sep 2023 23:49:46 +0200 Subject: [PATCH 13/16] Updated README.md --- README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8971f6d4..44c6bdfe 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# NativeTgCalls:
An experimental implementation of Telegram Group Calls +# NativeTgCalls:
An experimental implementation of Telegram Group Calls Welcome to NativeTgCalls, an innovative open-source project. NativeTgCalls represents the next evolution in Telegram calling, building on the foundation laid by PyTgCalls. | Powerful | Simple | Light | @@ -62,7 +62,7 @@ For developers looking to use NativeTgCalls with C and C++, we provide C Binding * @kuogi (Senior UI/UX designer, Documenter): * As a Senior UI/UX Designer, Kuogi has significantly improved the user interface of our documentation, making it more visually appealing and user-friendly. - * Has also played a key role in writing and structuring our documentation, ensuring that it is clear, + * It Has also played a key role in writing and structuring our documentation, ensuring that it is clear, informative, and accessible to all users. * @vrumger (Mid-level NodeJS Developer): * Avrumy has made important fixes and enhancements to the WebRTC component of the library, @@ -74,17 +74,18 @@ For developers looking to use NativeTgCalls with C and C++, we provide C Binding in expanding the functionality and usability of the library. * @null-nick (Junior Go Developer, Tester): * Performs testing of NTgCalls on macOS to ensure its reliability and compatibility. - * Is in the process of integrating NTgCalls into a Go wrapper, further enhancing the library's + * It Is in the process of integrating NTgCalls into a Go wrapper, further enhancing the library's versatility and accessibility. * @tappo03 (Junior Go Developer, Tester): * Performs testing of NTgCalls on Windows to ensure its reliability and compatibility. - * Is in the process of integrating NTgCalls into a Go wrapper, further enhancing the library's + * It Is in the process of integrating NTgCalls into a Go wrapper, further enhancing the library's versatility and accessibility. ## Special Thanks * @shiguredo: We extend our special thanks to 時雨堂 (shiguredo) for their invaluable assistance in integrating the WebRTC component. Their contributions, utilizing the Sora C++ SDK, have been instrumental in enhancing the functionality of our library. + * @evgeny-nadymov: A heartfelt thank you to Evgeny Nadymov for graciously allowing us to use their code from telegram-react. His contribution has been pivotal to the success of this project. @@ -92,3 +93,10 @@ For developers looking to use NativeTgCalls with C and C++, we provide C Binding * @morethanwords: We extend our special thanks to morethanwords for their invaluable help in integrating the connection to WebRTC with Telegram Web K. Their assistance has been instrumental in enhancing the functionality of our library. + + +_We would like to extend a special thanks to @doggyhaha +and @branchscope for their valuable contributions to the testing phase of the library. +Their dedication to testing and optimizing the library has been instrumental in its success._ + +_Additionally, we extend our gratitude to all contributors for their exceptional work in making this project a reality._ From 46b861fe5891ef3e281486d34384405c7024d78e Mon Sep 17 00:00:00 2001 From: Laky64 Date: Wed, 13 Sep 2023 01:59:50 +0200 Subject: [PATCH 14/16] Added debug generator for Shared Libs --- setup.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index fab51e83..e84a434a 100644 --- a/setup.py +++ b/setup.py @@ -105,18 +105,20 @@ class SharedCommand(Command): description = 'Generate shared-libs files' user_options = [ ('no-preserve-cache', None, "Do not preserve cache"), + ('debug', None, "Debug build"), ] # noinspection PyAttributeOutsideInit def initialize_options(self): self.no_preserve_cache = False + self.debug = False def finalize_options(self): pass # noinspection PyMethodMayBeStatic def run(self): - cfg = "RelWithDebInfo" if "dev" in version else "Release" + cfg = "RelWithDebInfo" if self.debug else "Release" cmake_args = [ f'-DCMAKE_BUILD_TYPE={cfg}', ] @@ -138,7 +140,7 @@ def run(self): release_path = Path(build_temp, 'ntgcalls') tmp_release_path = Path(release_path, cfg) - build_output = Path("shared-output") + build_output = Path("shared-output-debug" if self.debug else "shared-output") if build_output.exists(): shutil.rmtree(build_output) build_output.mkdir(parents=True) From 6e01580961ffa63eb10f2bc383db82264d615eff Mon Sep 17 00:00:00 2001 From: Laky64 Date: Wed, 13 Sep 2023 02:02:48 +0200 Subject: [PATCH 15/16] Fixed Releases and added Debug Builds --- .github/workflows/build.yml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 15b1ce5e..6934c3ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,13 +47,23 @@ jobs: with: platforms: arm64 - - name: Build Shared Libs + - name: Build Debug Shared lib + run: python3 setup.py build_shared --no-preserve-cache --debug + + - name: Build Release Shared lib run: python3 setup.py build_shared --no-preserve-cache - - name: Upload shared libs for ${{ matrix.shared_name }} + - name: Upload Debug Shared lib for ${{ matrix.shared_name }} + uses: actions/upload-artifact@v3 + with: + name: ntgcalls.${{ matrix.shared_name }}-debug-shared_libs + path: ./shared-output-debug/* + if-no-files-found: error + + - name: Upload Release Shared lib for ${{ matrix.shared_name }} uses: actions/upload-artifact@v3 with: - name: ntgcalls-${{ matrix.shared_name }}-lib.zip + name: ntgcalls.${{ matrix.shared_name }}-shared_libs path: ./shared-output/* if-no-files-found: error @@ -70,7 +80,7 @@ jobs: - uses: actions/upload-artifact@v3 with: - name: ntgcalls-${{ matrix.shared_name }}-wheels.zip + name: ntgcalls-${{ matrix.shared_name }}-wheels path: ./wheelhouse/*.whl if-no-files-found: error @@ -119,13 +129,13 @@ jobs: - name: Zip releases run: | mkdir releases - for dir in tmp/*.zip; do + for dir in tmp/*shared_libs; do if [ -d "$dir" ]; then + echo "$dir" folder_name=$(basename "$dir" .zip) - zip -r "releases/${folder_name}.zip" "$dir" + (cd $dir && zip -r "../../releases/${folder_name}.zip" *) fi done - ls releases - name: Create Release id: create-new-release From e1fbe5ef0f179fa5af6011baf70fd8570b3cc82b Mon Sep 17 00:00:00 2001 From: Laky64 Date: Wed, 13 Sep 2023 02:03:58 +0200 Subject: [PATCH 16/16] Version Bump --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef404611..87278271 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ if(DEFINED PY_VERSION_INFO) set(IS_PYTHON TRUE) endif() -project(ntgcalls VERSION 1.0.0.5 LANGUAGES C CXX) +project(ntgcalls VERSION 1.0.0.6 LANGUAGES C CXX) find_package(Threads REQUIRED)