diff --git a/net-im/telegram-desktop/patches/telegram_desktop-1.3.12-libtgvoip.patchset b/net-im/telegram-desktop/patches/telegram_desktop-1.3.14-libtgvoip.patchset similarity index 64% rename from net-im/telegram-desktop/patches/telegram_desktop-1.3.12-libtgvoip.patchset rename to net-im/telegram-desktop/patches/telegram_desktop-1.3.14-libtgvoip.patchset index 220585afa..ea073ee3e 100644 --- a/net-im/telegram-desktop/patches/telegram_desktop-1.3.12-libtgvoip.patchset +++ b/net-im/telegram-desktop/patches/telegram_desktop-1.3.14-libtgvoip.patchset @@ -1,174 +1,15 @@ -From 15130ecca47fcbfd3e15c9ace71b00a669042202 Mon Sep 17 00:00:00 2001 +From 957b6bc19b971d44f878a458c441301bd3215185 Mon Sep 17 00:00:00 2001 From: Gerasim Troeglazov <3dEyes@gmail.com> -Date: Sun, 10 Jun 2018 11:08:42 +1000 -Subject: Fix for using external opus lib +Date: Thu, 30 Aug 2018 20:14:24 +1000 +Subject: Add Haiku platform -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/OpusDecoder.h b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/OpusDecoder.h -index 6425c97..848b930 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/OpusDecoder.h -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/OpusDecoder.h -@@ -9,7 +9,7 @@ - - - #include "MediaStreamItf.h" --#include "opus.h" -+#include - #include "threading.h" - #include "BlockingQueue.h" - #include "Buffers.h" -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/OpusEncoder.h b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/OpusEncoder.h -index 4726f6b..92d8c33 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/OpusEncoder.h -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/OpusEncoder.h -@@ -9,7 +9,7 @@ - - - #include "MediaStreamItf.h" --#include "opus.h" -+#include - #include "threading.h" - #include "BlockingQueue.h" - #include "Buffers.h" --- -2.16.4 - - -From b4be4f2018dcc71fee9682e1f20f2a75799d9902 Mon Sep 17 00:00:00 2001 -From: Gerasim Troeglazov <3dEyes@gmail.com> -Date: Sun, 10 Jun 2018 11:10:12 +1000 -Subject: Add haiku modules - - -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/VoIPController.cpp b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/VoIPController.cpp -index 6d266a5..d08296a 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/VoIPController.cpp -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/VoIPController.cpp -@@ -8,6 +8,9 @@ - #include - #include - #endif -+#ifdef __HAIKU__ -+#include -+#endif - #include - #include - #include -@@ -2404,6 +2407,10 @@ double VoIPController::GetCurrentTime(){ - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec+(double)ts.tv_nsec/1000000000.0; -+#elif defined(__HAIKU__) -+ struct timeval tm; -+ gettimeofday(&tm, NULL); -+ return tm.tv_sec+(double)tm.tv_usec/1000000.0; - #elif defined(__APPLE__) - static pthread_once_t token = PTHREAD_ONCE_INIT; - pthread_once(&token, &initMachTimestart); -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/audio/AudioInput.cpp b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/audio/AudioInput.cpp -index 062ca06..887889e 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/audio/AudioInput.cpp -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/audio/AudioInput.cpp -@@ -22,6 +22,8 @@ - #elif defined(__linux__) - #include "../os/linux/AudioInputALSA.h" - #include "../os/linux/AudioInputPulse.h" -+#elif defined(__HAIKU__) -+#include "../os/haiku/AudioInputHaiku.h" - #else - #error "Unsupported operating system" - #endif -@@ -64,6 +66,8 @@ AudioInput *AudioInput::Create(std::string deviceID, void* platformSpecific){ - LOGW("in: PulseAudio available but not working; trying ALSA"); - } - return new AudioInputALSA(deviceID); -+#elif defined(__HAIKU__) -+ return new AudioInputHaiku(deviceID); - #endif - } - -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/audio/AudioOutput.cpp b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/audio/AudioOutput.cpp -index 109d24d..c3cc014 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/audio/AudioOutput.cpp -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/audio/AudioOutput.cpp -@@ -25,6 +25,8 @@ - #elif defined(__linux__) - #include "../os/linux/AudioOutputALSA.h" - #include "../os/linux/AudioOutputPulse.h" -+#elif defined(__HAIKU__) -+#include "../os/haiku/AudioOutputHaiku.h" - #else - #error "Unsupported operating system" - #endif -@@ -59,6 +61,9 @@ std::unique_ptr AudioOutput::Create(std::string deviceID, void* pla - LOGW("out: PulseAudio available but not working; trying ALSA"); - } - return std::unique_ptr(new AudioOutputALSA(deviceID)); -+#elif defined(__HAIKU__) -+ LOGW("out: MediaKitAudio enabled"); -+ return std::unique_ptr(new AudioOutputHaiku(deviceID)); - #endif - } - -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/libtgvoip.gyp b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/libtgvoip.gyp -index f236987..24f017b 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/libtgvoip.gyp -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/libtgvoip.gyp -@@ -100,6 +100,14 @@ - '<(tgvoip_src_loc)/os/linux/PulseAudioLoader.cpp', - '<(tgvoip_src_loc)/os/linux/PulseAudioLoader.h', - -+ # Haiku -+ '<(tgvoip_src_loc)/os/haiku/AudioInputHaiku.cpp', -+ '<(tgvoip_src_loc)/os/haiku/AudioInputHaiku.h', -+ '<(tgvoip_src_loc)/os/haiku/AudioOutputHaiku.cpp', -+ '<(tgvoip_src_loc)/os/haiku/AudioOutputHaiku.h', -+ '<(tgvoip_src_loc)/os/haiku/RingBuffer.cpp', -+ '<(tgvoip_src_loc)/os/haiku/RingBuffer.h', -+ - # POSIX - '<(tgvoip_src_loc)/os/posix/NetworkSocketPosix.cpp', - '<(tgvoip_src_loc)/os/posix/NetworkSocketPosix.h', -@@ -253,6 +261,11 @@ - 'sources/': [['exclude', '<(tgvoip_src_loc)/os/posix/']], - }, - ], -+ [ -+ '"<(OS)" != "haiku"', { -+ 'sources/': [['exclude', '<(tgvoip_src_loc)/os/haiku/']], -+ }, -+ ], - [ - '"<(OS)" != "mac"', { - 'sources/': [['exclude', '<(tgvoip_src_loc)/os/darwin/']], -@@ -378,6 +391,21 @@ - }, - ], - [ -+ '"<(OS)" == "haiku"', { -+ 'defines': [ -+ 'WEBRTC_POSIX', -+ ], -+ 'cflags_cc': [ -+ '-msse2', -+ '-std=gnu++14', -+ ], -+ 'direct_dependent_settings': { -+ 'libraries': [ -+ -+ ], -+ }, -+ }, -+ ], [ - '"<(OS)" == "linux"', { - 'defines': [ - 'WEBRTC_POSIX', -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.cpp b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.cpp +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioInputHaiku.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioInputHaiku.cpp new file mode 100644 -index 0000000..ce54b6e +index 0000000..1bfbfad --- /dev/null -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.cpp -@@ -0,0 +1,198 @@ ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioInputHaiku.cpp +@@ -0,0 +1,272 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file @@ -181,36 +22,108 @@ index 0000000..ce54b6e +#include +#include "AudioInputHaiku.h" +#include "../../logging.h" ++#include "../../audio/Resampler.h" +#include "../../VoIPController.h" + +#include "RingBuffer.h" + -+#define BUFFER_SIZE 960 -+ +using namespace tgvoip::audio; + -+void RecordFile(void* cookie, bigtime_t timestamp, void* data, size_t size, const media_format &format) ++void RecordData(void* cookie, bigtime_t timestamp, void* data, size_t size, const media_format &format) +{ -+ AudioInputHaiku *obj = (AudioInputHaiku*)cookie; -+ if (!obj->IsRecording()) ++ AudioInputHaiku *audioInput = (AudioInputHaiku*)cookie; ++ if (!audioInput->IsRecording()) ++ return; ++ ++ if (format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_SHORT && ++ format.u.raw_audio.channel_count == 1) { ++ audioInput->fRingBuffer->Write((unsigned char*)data, size); + return; -+ if (format.u.raw_audio.channel_count == 1) { -+ obj->fRingBuffer->Write((unsigned char*)data, size); -+ } else if (format.u.raw_audio.channel_count == 2) { -+ unsigned char *s = (unsigned char*)data; -+ for (int i=0; ifRingBuffer->Write(s, 2); + } -+ ++ ++ uint32 bytesPerSample = 2; ++ switch (format.u.raw_audio.format) { ++ case media_raw_audio_format::B_AUDIO_CHAR: ++ bytesPerSample = 1; ++ break; ++ case media_raw_audio_format::B_AUDIO_SHORT: ++ bytesPerSample = 2; ++ break; ++ case media_raw_audio_format::B_AUDIO_INT: ++ bytesPerSample = 4; ++ break; ++ case media_raw_audio_format::B_AUDIO_FLOAT: ++ bytesPerSample = 4; ++ break; ++ default: ++ break; ++ } ++ ++ int frames = size / (format.u.raw_audio.channel_count * bytesPerSample); ++ int16_t *dst = audioInput->workBuffer; ++ ++ if (format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_CHAR) { ++ unsigned char* src=reinterpret_cast(data); ++ for (int n=0; n < frames; n++) { ++ int32_t value = 0; ++ for (int j=0; j < format.u.raw_audio.channel_count; j++, src++) { ++ value += ((int32_t)(*src) - INT8_MAX) * UINT8_MAX; ++ } ++ value /= format.u.raw_audio.channel_count; ++ dst[n] = (int16_t)value; ++ } ++ } else if (format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_SHORT) { ++ int16_t* src=reinterpret_cast(data); ++ for (int n=0; n < frames; n++) { ++ int32_t value = 0; ++ for (int j=0; j < format.u.raw_audio.channel_count; j++, src++) { ++ value += *src; ++ } ++ value /= format.u.raw_audio.channel_count; ++ dst[n] = (int16_t)value; ++ } ++ } else if (format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_INT) { ++ int32_t* src=reinterpret_cast(data); ++ for (int n=0; n < frames; n++) { ++ int64_t value = 0; ++ for (int j=0; j < format.u.raw_audio.channel_count; j++, src++) { ++ value += (int64_t)(*src); ++ } ++ value /= format.u.raw_audio.channel_count; ++ dst[n] = (int16_t)(value / (UINT16_MAX + 1)); ++ } ++ } else if (format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_FLOAT) { ++ float* src=reinterpret_cast(data); ++ for (int n=0; n < frames; n++) { ++ float value = 0; ++ for (int j=0; j < format.u.raw_audio.channel_count; j++, src++) { ++ value += *src; ++ } ++ value /= format.u.raw_audio.channel_count; ++ dst[n] = (int16_t)(value*INT16_MAX); ++ } ++ } ++ ++ if(format.u.raw_audio.frame_rate != audioInput->tgFrameRate) { ++ size_t len = tgvoip::audio::Resampler::Convert(dst, audioInput->convertBuffer, ++ frames, frames, audioInput->tgFrameRate, format.u.raw_audio.frame_rate) * audioInput->tgBytesPerSample; ++ audioInput->fRingBuffer->Write((unsigned char*)audioInput->convertBuffer, len); ++ } else { ++ audioInput->fRingBuffer->Write((unsigned char*)dst, frames * audioInput->tgBytesPerSample); ++ } +} + -+void NotifyRecordFile(void * cookie, BMediaRecorder::notification code, ...) ++void NotifyRecordData(void * cookie, BMediaRecorder::notification code, ...) +{ ++ AudioInputHaiku *audioInput = (AudioInputHaiku*)cookie; + if (code == BMediaRecorder::B_WILL_STOP) { ++ if (audioInput->IsRecording()) { ++ audioInput->Stop(); ++ } + } +} + -+AudioInputHaiku::AudioInputHaiku(std::string devID) ++AudioInputHaiku::AudioInputHaiku() +{ + fRecorder = NULL; + fRingBuffer = NULL; @@ -287,7 +200,7 @@ index 0000000..ce54b6e + } + fRecordFormat.type = B_MEDIA_RAW_AUDIO; + -+ error = fRecorder->SetHooks(RecordFile, NotifyRecordFile, this); ++ error = fRecorder->SetHooks(RecordData, NotifyRecordData, this); + if (error < B_OK) { + failed=true; + return; @@ -322,7 +235,9 @@ index 0000000..ce54b6e +} + +void AudioInputHaiku::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels){ -+ ++ tgFrameRate = sampleRate; ++ tgChannelsCount = channels; ++ tgBytesPerSample = bitsPerSample / 8; +} + +bool AudioInputHaiku::IsRecording(){ @@ -367,12 +282,12 @@ index 0000000..ce54b6e + snooze(100); + } +} -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.h b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.h +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioInputHaiku.h b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioInputHaiku.h new file mode 100644 -index 0000000..80573df +index 0000000..2425666 --- /dev/null -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.h -@@ -0,0 +1,57 @@ ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioInputHaiku.h +@@ -0,0 +1,66 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file @@ -397,20 +312,29 @@ index 0000000..80573df + +#include "RingBuffer.h" + ++#define BUFFER_SIZE 960 ++ +namespace tgvoip{ +namespace audio{ + +class AudioInputHaiku : public AudioInput{ + +public: -+ AudioInputHaiku(std::string devID); ++ AudioInputHaiku(); + virtual ~AudioInputHaiku(); + virtual void Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels); + virtual void Start(); + virtual void Stop(); + virtual bool IsRecording(); -+ -+ RingBuffer *fRingBuffer; ++ ++ RingBuffer *fRingBuffer; ++ int16_t workBuffer[BUFFER_SIZE * 16]; ++ int16_t convertBuffer[BUFFER_SIZE * 16]; ++ ++ uint32 tgFrameRate; ++ uint32 tgChannelsCount; ++ uint32 tgBytesPerSample; ++ +private: + void RunThread(void* arg); + @@ -422,20 +346,20 @@ index 0000000..80573df + media_format fRecordFormat; + media_node fAudioInputNode; + media_node fAudioMixerNode; -+ ++ + Thread* thread; +}; + +} +} + -+#endif //LIBTGVOIP_AUDIOINPUTALSA_H -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.cpp b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.cpp ++#endif //LIBTGVOIP_AUDIOINPUTHAIKU_H +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.cpp new file mode 100644 -index 0000000..4454323 +index 0000000..533128d --- /dev/null -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.cpp -@@ -0,0 +1,101 @@ ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.cpp +@@ -0,0 +1,102 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file @@ -460,7 +384,7 @@ index 0000000..4454323 +} + + -+AudioOutputHaiku::AudioOutputHaiku(std::string devID){ ++AudioOutputHaiku::AudioOutputHaiku(){ + soundPlayer = NULL; + isPlaying = false; + isConfigured = false; @@ -482,7 +406,7 @@ index 0000000..4454323 + (uint32)channels, + media_raw_audio_format::B_AUDIO_SHORT, + B_MEDIA_LITTLE_ENDIAN, -+ (uint32)BUFFER_SIZE * 2 * channels ++ (uint32)BUFFER_SIZE * (bitsPerSample / 8) * channels + }; + + switch (bitsPerSample) { @@ -506,6 +430,7 @@ index 0000000..4454323 + delete soundPlayer; + soundPlayer = NULL; + isPlaying = false; ++ failed = true; + return; + } + @@ -537,11 +462,11 @@ index 0000000..4454323 +float AudioOutputHaiku::GetLevel(){ + return 0; +} -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.h b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.h +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.h b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.h new file mode 100644 -index 0000000..6880709 +index 0000000..0ea8230 --- /dev/null -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.h ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.h @@ -0,0 +1,36 @@ +// +// libtgvoip is free and unencumbered public domain software. @@ -562,7 +487,7 @@ index 0000000..6880709 + +class AudioOutputHaiku : public AudioOutput{ +public: -+ AudioOutputHaiku(std::string devID); ++ AudioOutputHaiku(); + virtual ~AudioOutputHaiku(); + virtual void Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels); + virtual void Start(); @@ -578,12 +503,12 @@ index 0000000..6880709 +} +} + -+#endif //LIBTGVOIP_AudioOutputHaiku_H -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/RingBuffer.cpp b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/RingBuffer.cpp ++#endif //LIBTGVOIP_AUDIOOUTPUTHAIKU_H +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/RingBuffer.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/RingBuffer.cpp new file mode 100644 index 0000000..43236d3 --- /dev/null -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/RingBuffer.cpp ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/RingBuffer.cpp @@ -0,0 +1,130 @@ +#include +#include @@ -715,11 +640,11 @@ index 0000000..43236d3 +{ + return initialized?B_OK:B_ERROR; +} -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/RingBuffer.h b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/RingBuffer.h +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/RingBuffer.h b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/RingBuffer.h new file mode 100644 index 0000000..4715632 --- /dev/null -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/RingBuffer.h ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/RingBuffer.h @@ -0,0 +1,31 @@ +#ifndef __RING_BUFFER_H__ +#define __RING_BUFFER_H__ @@ -752,38 +677,163 @@ index 0000000..4715632 +}; + +#endif -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/posix/NetworkSocketPosix.cpp b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/posix/NetworkSocketPosix.cpp -index 05ddbb9..fcf7580 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/posix/NetworkSocketPosix.cpp -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/posix/NetworkSocketPosix.cpp -@@ -47,6 +47,7 @@ NetworkSocketPosix::~NetworkSocketPosix(){ - } - - void NetworkSocketPosix::SetMaxPriority(){ -+#ifndef __HAIKU__ - #ifdef __APPLE__ - int prio=NET_SERVICE_TYPE_VO; - int res=setsockopt(fd, SOL_SOCKET, SO_NET_SERVICE_TYPE, &prio, sizeof(prio)); -@@ -65,6 +66,7 @@ void NetworkSocketPosix::SetMaxPriority(){ - LOGE("error setting ip tos: %d / %s", errno, strerror(errno)); - } +-- +2.16.4 + + +From 753b20ad62db41d0041b352dac9c9a45ecd3009b Mon Sep 17 00:00:00 2001 +From: Gerasim Troeglazov <3dEyes@gmail.com> +Date: Thu, 30 Aug 2018 20:15:02 +1000 +Subject: Fix Haiku build + + +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/VoIPController.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/VoIPController.cpp +index b82899e..700b0cd 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/VoIPController.cpp ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/VoIPController.cpp +@@ -8,6 +8,9 @@ + #include + #include #endif -+#endif //__HAIKU__ - } ++#ifdef __HAIKU__ ++#include ++#endif + #include + #include + #include +@@ -2052,6 +2055,10 @@ double VoIPController::GetCurrentTime(){ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec+(double)ts.tv_nsec/1000000000.0; ++#elif defined(__HAIKU__) ++ struct timeval tm; ++ gettimeofday(&tm, NULL); ++ return tm.tv_sec+(double)tm.tv_usec/1000000.0; + #elif defined(__APPLE__) + static pthread_once_t token = PTHREAD_ONCE_INIT; + pthread_once(&token, &initMachTimestart); +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioIO.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioIO.cpp +index 06beea7..bae4d64 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioIO.cpp ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioIO.cpp +@@ -37,6 +37,9 @@ + #ifndef WITHOUT_PULSE + #include "../os/linux/AudioPulse.h" + #endif ++#elif defined(__HAIKU__) ++#include "../os/haiku/AudioInputHaiku.h" ++#include "../os/haiku/AudioOutputHaiku.h" + #else + #error "Unsupported operating system" + #endif +@@ -62,6 +65,8 @@ shared_ptr AudioIO::Create(){ + return std::make_shared>(inputDevice, outputDevice); + #endif + return std::make_shared>(inputDevice, outputDevice); ++#elif defined(__HAIKU__) ++ return std::make_shared>(); + #elif defined(__linux__) + #ifndef WITHOUT_ALSA + #ifndef WITHOUT_PULSE +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioInput.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioInput.cpp +index 3e3ccb9..a3e4c06 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioInput.cpp ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioInput.cpp +@@ -31,6 +31,8 @@ + #ifndef WITHOUT_PULSE + #include "../os/linux/AudioPulse.h" + #endif ++#elif defined(__HAIKU__) ++#include "../os/haiku/AudioInputHaiku.h" + #else + #error "Unsupported operating system" + #endif +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioOutput.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioOutput.cpp +index 938c1aa..36900a8 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioOutput.cpp ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/audio/AudioOutput.cpp +@@ -35,6 +35,8 @@ + #include "../os/linux/AudioOutputPulse.h" + #include "../os/linux/AudioPulse.h" + #endif ++#elif defined(__HAIKU__) ++#include "../os/haiku/AudioOutputHaiku.h" + #else + #error "Unsupported operating system" + #endif +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/libtgvoip.gyp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/libtgvoip.gyp +index 0cf04ea..4f21d1e 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/libtgvoip.gyp ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/libtgvoip.gyp +@@ -104,6 +104,14 @@ + '<(tgvoip_src_loc)/os/linux/AudioPulse.cpp', + '<(tgvoip_src_loc)/os/linux/AudioPulse.h', - void NetworkSocketPosix::Send(NetworkPacket *packet){ -@@ -196,8 +198,10 @@ void NetworkSocketPosix::Open(){ ++ # Haiku ++ '<(tgvoip_src_loc)/os/haiku/AudioInputHaiku.cpp', ++ '<(tgvoip_src_loc)/os/haiku/AudioInputHaiku.h', ++ '<(tgvoip_src_loc)/os/haiku/AudioOutputHaiku.cpp', ++ '<(tgvoip_src_loc)/os/haiku/AudioOutputHaiku.h', ++ '<(tgvoip_src_loc)/os/haiku/RingBuffer.cpp', ++ '<(tgvoip_src_loc)/os/haiku/RingBuffer.h', ++ + # POSIX + '<(tgvoip_src_loc)/os/posix/NetworkSocketPosix.cpp', + '<(tgvoip_src_loc)/os/posix/NetworkSocketPosix.h', +@@ -257,6 +265,11 @@ + 'sources/': [['exclude', '<(tgvoip_src_loc)/os/posix/']], + }, + ], ++ [ ++ '"<(OS)" != "haiku"', { ++ 'sources/': [['exclude', '<(tgvoip_src_loc)/os/haiku/']], ++ }, ++ ], + [ + '"<(OS)" != "mac"', { + 'sources/': [['exclude', '<(tgvoip_src_loc)/os/darwin/']], +@@ -382,6 +395,21 @@ + }, + ], + [ ++ '"<(OS)" == "haiku"', { ++ 'defines': [ ++ 'WEBRTC_POSIX', ++ ], ++ 'cflags_cc': [ ++ '-msse2', ++ '-std=gnu++14', ++ ], ++ 'direct_dependent_settings': { ++ 'libraries': [ ++ ++ ], ++ }, ++ }, ++ ], [ + '"<(OS)" == "linux"', { + 'defines': [ + 'WEBRTC_POSIX', +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/posix/NetworkSocketPosix.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/posix/NetworkSocketPosix.cpp +index ef8d2cb..da39a17 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/posix/NetworkSocketPosix.cpp ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/posix/NetworkSocketPosix.cpp +@@ -202,12 +202,13 @@ void NetworkSocketPosix::Open(){ + } + int flag=0; int res=setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &flag, sizeof(flag)); ++#ifndef __HAIKU__ if(res<0){ LOGE("error enabling dual stack socket: %d / %s", errno, strerror(errno)); -+#ifndef __HAIKU__ failed=true; return; -+#endif } - +- ++#endif SetMaxPriority(); -@@ -345,6 +349,8 @@ std::string NetworkSocketPosix::GetLocalInterfaceInfo(IPv4Address *v4addr, IPv6A + + int tries=0; +@@ -353,6 +354,8 @@ std::string NetworkSocketPosix::GetLocalInterfaceInfo(IPv4Address *v4addr, IPv6A if(didAttach){ sharedJVM->DetachCurrentThread(); } @@ -792,10 +842,10 @@ index 05ddbb9..fcf7580 100644 #else struct ifaddrs* interfaces; if(!getifaddrs(&interfaces)){ -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/threading.h b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/threading.h -index 0b4933c..87ea3b7 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/threading.h -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/threading.h +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/threading.h b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/threading.h +index 0bcf7c3..af86ef2 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/threading.h ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/threading.h @@ -33,7 +33,7 @@ namespace tgvoip{ }; } @@ -805,15 +855,17 @@ index 0b4933c..87ea3b7 100644 #include #include -@@ -94,11 +94,13 @@ namespace tgvoip{ +@@ -115,6 +115,7 @@ namespace tgvoip{ static void* ActualEntryPoint(void* arg){ Thread* self=reinterpret_cast(arg); if(self->name){ +#ifndef __HAIKU__ - #ifndef __APPLE__ + #if !defined(__APPLE__) && !defined(__gnu_hurd__) pthread_setname_np(self->thread, self->name); - #else - pthread_setname_np(self->name); + #elif !defined(__gnu_hurd__) +@@ -123,6 +124,7 @@ namespace tgvoip{ + DarwinSpecific::SetCurrentThreadPriority(DarwinSpecific::THREAD_PRIO_USER_INTERACTIVE); + } #endif +#endif //__HAKIU__ } @@ -823,230 +875,72 @@ index 0b4933c..87ea3b7 100644 2.16.4 -From 4dbfc02248dde7ae10d29d81f25575942f204c89 Mon Sep 17 00:00:00 2001 +From 1bf1510ada4edb23b04da953284b5d1decca9bd0 Mon Sep 17 00:00:00 2001 From: Gerasim Troeglazov <3dEyes@gmail.com> -Date: Sun, 10 Jun 2018 22:01:28 +1000 -Subject: Add mix and resample for haiku audio input +Date: Thu, 30 Aug 2018 23:52:44 +1000 +Subject: Remove GetLevel function -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.cpp b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.cpp -index ce54b6e..d7cc39a 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.cpp -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.cpp -@@ -10,32 +10,104 @@ - #include - #include "AudioInputHaiku.h" - #include "../../logging.h" -+#include "../../audio/Resampler.h" - #include "../../VoIPController.h" - - #include "RingBuffer.h" - --#define BUFFER_SIZE 960 +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.cpp +index 533128d..3dc052c 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.cpp ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.cpp +@@ -96,7 +96,3 @@ void AudioOutputHaiku::Stop(){ + bool AudioOutputHaiku::IsPlaying(){ + return isPlaying; + } - - using namespace tgvoip::audio; - --void RecordFile(void* cookie, bigtime_t timestamp, void* data, size_t size, const media_format &format) -+void RecordData(void* cookie, bigtime_t timestamp, void* data, size_t size, const media_format &format) - { -- AudioInputHaiku *obj = (AudioInputHaiku*)cookie; -- if (!obj->IsRecording()) -+ AudioInputHaiku *audioInput = (AudioInputHaiku*)cookie; -+ if (!audioInput->IsRecording()) -+ return; -+ -+ if (format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_SHORT && -+ format.u.raw_audio.channel_count == 1) { -+ audioInput->fRingBuffer->Write((unsigned char*)data, size); - return; -- if (format.u.raw_audio.channel_count == 1) { -- obj->fRingBuffer->Write((unsigned char*)data, size); -- } else if (format.u.raw_audio.channel_count == 2) { -- unsigned char *s = (unsigned char*)data; -- for (int i=0; ifRingBuffer->Write(s, 2); - } -- -+ -+ uint32 bytesPerSample = 2; -+ switch (format.u.raw_audio.format) { -+ case media_raw_audio_format::B_AUDIO_CHAR: -+ bytesPerSample = 1; -+ break; -+ case media_raw_audio_format::B_AUDIO_SHORT: -+ bytesPerSample = 2; -+ break; -+ case media_raw_audio_format::B_AUDIO_INT: -+ bytesPerSample = 4; -+ break; -+ case media_raw_audio_format::B_AUDIO_FLOAT: -+ bytesPerSample = 4; -+ break; -+ default: -+ break; -+ } -+ -+ int frames = size / (format.u.raw_audio.channel_count * bytesPerSample); -+ int16_t *dst = audioInput->workBuffer; -+ -+ if (format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_CHAR) { -+ unsigned char* src=reinterpret_cast(data); -+ for (int n=0; n < frames; n++) { -+ int32_t value = 0; -+ for (int j=0; j < format.u.raw_audio.channel_count; j++, src++) { -+ value += ((int32_t)(*src) - INT8_MAX) * UINT8_MAX; -+ } -+ value /= format.u.raw_audio.channel_count; -+ dst[n] = (int16_t)value; -+ } -+ } else if (format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_SHORT) { -+ int16_t* src=reinterpret_cast(data); -+ for (int n=0; n < frames; n++) { -+ int32_t value = 0; -+ for (int j=0; j < format.u.raw_audio.channel_count; j++, src++) { -+ value += *src; -+ } -+ value /= format.u.raw_audio.channel_count; -+ dst[n] = (int16_t)value; -+ } -+ } else if (format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_INT) { -+ int32_t* src=reinterpret_cast(data); -+ for (int n=0; n < frames; n++) { -+ int64_t value = 0; -+ for (int j=0; j < format.u.raw_audio.channel_count; j++, src++) { -+ value += (int64_t)(*src); -+ } -+ value /= format.u.raw_audio.channel_count; -+ dst[n] = (int16_t)(value / (UINT16_MAX + 1)); -+ } -+ } else if (format.u.raw_audio.format == media_raw_audio_format::B_AUDIO_FLOAT) { -+ float* src=reinterpret_cast(data); -+ for (int n=0; n < frames; n++) { -+ float value = 0; -+ for (int j=0; j < format.u.raw_audio.channel_count; j++, src++) { -+ value += *src; -+ } -+ value /= format.u.raw_audio.channel_count; -+ dst[n] = (int16_t)(value*INT16_MAX); -+ } -+ } -+ -+ if(format.u.raw_audio.frame_rate != audioInput->tgFrameRate) { -+ size_t len = tgvoip::audio::Resampler::Convert(dst, audioInput->convertBuffer, -+ frames, frames, audioInput->tgFrameRate, format.u.raw_audio.frame_rate) * audioInput->tgBytesPerSample; -+ audioInput->fRingBuffer->Write((unsigned char*)audioInput->convertBuffer, len); -+ } else { -+ audioInput->fRingBuffer->Write((unsigned char*)dst, frames * audioInput->tgBytesPerSample); -+ } - } - --void NotifyRecordFile(void * cookie, BMediaRecorder::notification code, ...) -+void NotifyRecordData(void * cookie, BMediaRecorder::notification code, ...) - { -+ AudioInputHaiku *audioInput = (AudioInputHaiku*)cookie; - if (code == BMediaRecorder::B_WILL_STOP) { -+ if (audioInput->IsRecording()) { -+ audioInput->Stop(); -+ } - } - } - -@@ -116,7 +188,7 @@ AudioInputHaiku::AudioInputHaiku(std::string devID) - } - fRecordFormat.type = B_MEDIA_RAW_AUDIO; - -- error = fRecorder->SetHooks(RecordFile, NotifyRecordFile, this); -+ error = fRecorder->SetHooks(RecordData, NotifyRecordData, this); - if (error < B_OK) { - failed=true; - return; -@@ -151,7 +223,9 @@ AudioInputHaiku::~AudioInputHaiku(){ - } - - void AudioInputHaiku::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels){ -- -+ tgFrameRate = sampleRate; -+ tgChannelsCount = channels; -+ tgBytesPerSample = bitsPerSample / 8; - } - - bool AudioInputHaiku::IsRecording(){ -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.h b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.h -index 80573df..746d7df 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.h -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioInputHaiku.h -@@ -22,6 +22,8 @@ - - #include "RingBuffer.h" - -+#define BUFFER_SIZE 960 -+ - namespace tgvoip{ - namespace audio{ - -@@ -34,8 +36,15 @@ public: +-float AudioOutputHaiku::GetLevel(){ +- return 0; +-} +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.h b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.h +index 0ea8230..91f2521 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.h ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/os/haiku/AudioOutputHaiku.h +@@ -23,7 +23,6 @@ public: virtual void Start(); virtual void Stop(); - virtual bool IsRecording(); -- -- RingBuffer *fRingBuffer; -+ -+ RingBuffer *fRingBuffer; -+ int16_t workBuffer[BUFFER_SIZE * 16]; -+ int16_t convertBuffer[BUFFER_SIZE * 16]; -+ -+ uint32 tgFrameRate; -+ uint32 tgChannelsCount; -+ uint32 tgBytesPerSample; -+ + virtual bool IsPlaying() override; +- virtual float GetLevel() override; private: - void RunThread(void* arg); - -@@ -47,11 +56,11 @@ private: - media_format fRecordFormat; - media_node fAudioInputNode; - media_node fAudioMixerNode; -- -+ - Thread* thread; - }; - - } - } - --#endif //LIBTGVOIP_AUDIOINPUTALSA_H -+#endif //LIBTGVOIP_AUDIOINPUTHAIKU_H -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.cpp b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.cpp -index 4454323..11650da 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.cpp -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.cpp -@@ -44,7 +44,7 @@ void AudioOutputHaiku::Configure(uint32_t sampleRate, uint32_t bitsPerSample, ui - (uint32)channels, - media_raw_audio_format::B_AUDIO_SHORT, - B_MEDIA_LITTLE_ENDIAN, -- (uint32)BUFFER_SIZE * 2 * channels -+ (uint32)BUFFER_SIZE * (bitsPerSample / 8) * channels - }; - - switch (bitsPerSample) { -@@ -68,6 +68,7 @@ void AudioOutputHaiku::Configure(uint32_t sampleRate, uint32_t bitsPerSample, ui - delete soundPlayer; - soundPlayer = NULL; - isPlaying = false; -+ failed = true; - return; - } - -diff --git a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.h b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.h -index 6880709..6a463fa 100644 ---- a/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.h -+++ b/libtgvoip-697eea96aa90205db4fc368df4127eef56b2a5c6/os/haiku/AudioOutputHaiku.h -@@ -33,4 +33,4 @@ private: - } - } - --#endif //LIBTGVOIP_AudioOutputHaiku_H -+#endif //LIBTGVOIP_AUDIOOUTPUTHAIKU_H + bool isPlaying; + bool isConfigured; +-- +2.16.4 + + +From 50540bcbe0cd11cf96cf6b095d99e2ed5ab36d30 Mon Sep 17 00:00:00 2001 +From: Gerasim Troeglazov <3dEyes@gmail.com> +Date: Thu, 30 Aug 2018 23:53:16 +1000 +Subject: Fix opus includes + + +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/OpusDecoder.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/OpusDecoder.cpp +index 87a48eb..545113a 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/OpusDecoder.cpp ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/OpusDecoder.cpp +@@ -10,7 +10,7 @@ + #include + #include + #include +-#ifdef HAVE_CONFIG_H ++#if defined(HAVE_CONFIG_H) || defined(__HAIKU__) + #include + #else + #include "opus.h" +diff --git a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/OpusEncoder.cpp b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/OpusEncoder.cpp +index e30f814..c31aee2 100644 +--- a/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/OpusEncoder.cpp ++++ b/libtgvoip-bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34/OpusEncoder.cpp +@@ -8,7 +8,7 @@ + #include + #include "logging.h" + #include "VoIPServerConfig.h" +-#ifdef HAVE_CONFIG_H ++#if defined(HAVE_CONFIG_H) || defined(__HAIKU__) + #include + #else + #include "opus.h" -- 2.16.4 diff --git a/net-im/telegram-desktop/patches/telegram_desktop-1.3.12-systemqt.patch b/net-im/telegram-desktop/patches/telegram_desktop-1.3.14-systemqt.patch similarity index 100% rename from net-im/telegram-desktop/patches/telegram_desktop-1.3.12-systemqt.patch rename to net-im/telegram-desktop/patches/telegram_desktop-1.3.14-systemqt.patch diff --git a/net-im/telegram-desktop/patches/telegram_desktop-1.3.12.patchset b/net-im/telegram-desktop/patches/telegram_desktop-1.3.14.patchset similarity index 85% rename from net-im/telegram-desktop/patches/telegram_desktop-1.3.12.patchset rename to net-im/telegram-desktop/patches/telegram_desktop-1.3.14.patchset index 3b7cf4a89..6e36872be 100644 --- a/net-im/telegram-desktop/patches/telegram_desktop-1.3.12.patchset +++ b/net-im/telegram-desktop/patches/telegram_desktop-1.3.14.patchset @@ -2469,3 +2469,429 @@ index 1928257..4ce6ac6 100644 -- 2.16.4 + +From 95c36a14498a6ede405420d45bbeeb46df5d8d7e Mon Sep 17 00:00:00 2001 +From: Gerasim Troeglazov <3dEyes@gmail.com> +Date: Tue, 4 Sep 2018 22:57:02 +1000 +Subject: Add native notifations + + +diff --git a/Telegram/SourceFiles/platform/haiku/notifications_haiku_gate.cpp b/Telegram/SourceFiles/platform/haiku/notifications_haiku_gate.cpp +new file mode 100644 +index 0000000..bf9c7be +--- /dev/null ++++ b/Telegram/SourceFiles/platform/haiku/notifications_haiku_gate.cpp +@@ -0,0 +1,40 @@ ++#include ++ ++#include ++#include ++ ++#define APPSIGNATURE "application/x-vnd.tg-notify-gate" ++ ++class SimpleLauncherApp : public BApplication { ++ public: ++ SimpleLauncherApp(int argc, char **argv); ++ void ArgvReceived(int32 argc, char **argv); ++ virtual void ReadyToRun(); ++}; ++ ++SimpleLauncherApp::SimpleLauncherApp(int argc, char **argv) : BApplication(APPSIGNATURE) ++{ ++} ++ ++void ++SimpleLauncherApp::ArgvReceived(int32 argc, char **argv) ++{ ++ if (argc==2) { ++ FILE *out=fopen("/tmp/tg_notify","wt"); ++ fprintf(out,"%s\n", argv[1]); ++ fclose(out); ++ } ++} ++ ++void ++SimpleLauncherApp::ReadyToRun() ++{ ++ Quit(); ++} ++ ++int main(int argc, char **argv) ++{ ++ SimpleLauncherApp application(argc, argv); ++ application.Run(); ++ return 0; ++} +diff --git a/Telegram/SourceFiles/platform/haiku/notifications_haiku_gate.rdef b/Telegram/SourceFiles/platform/haiku/notifications_haiku_gate.rdef +new file mode 100644 +index 0000000..b6f3490 +--- /dev/null ++++ b/Telegram/SourceFiles/platform/haiku/notifications_haiku_gate.rdef +@@ -0,0 +1,13 @@ ++resource app_flags B_MULTIPLE_LAUNCH | B_BACKGROUND_APP; ++ ++resource app_version { ++ major = 0, ++ middle = 0, ++ minor = 1, ++ variety = B_APPV_FINAL, ++ internal = 0, ++ short_info = "tg-notify-gate", ++ long_info = "Telegram native notifications gate" ++}; ++ ++resource app_signature "application/x-vnd.tg-notify-gate"; +diff --git a/Telegram/SourceFiles/platform/haiku/notifications_manager_haiku.cpp b/Telegram/SourceFiles/platform/haiku/notifications_manager_haiku.cpp +index b3d186a..8a75ed7 100644 +--- a/Telegram/SourceFiles/platform/haiku/notifications_manager_haiku.cpp ++++ b/Telegram/SourceFiles/platform/haiku/notifications_manager_haiku.cpp +@@ -18,65 +18,197 @@ to link the code of portions of this program with the OpenSSL library. + Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE + Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org + */ ++ ++#include ++#include ++#include ++#include ++ + #include "platform/haiku/notifications_manager_haiku.h" + + #include "window/notifications_utilities.h" + #include "lang/lang_keys.h" + #include "history/history.h" + ++#include ++#include ++#include ++#include ++#include ++ + namespace Platform { + namespace Notifications { + namespace { + +-bool LibNotifyLoaded() { +- return false; +-} +- +-QString escapeHtml(const QString &text) { +- auto result = QString(); +- auto copyFrom = 0, textSize = text.size(); +- auto data = text.constData(); +- for (auto i = 0; i != textSize; ++i) { +- auto ch = data[i]; +- if (ch == '<' || ch == '>' || ch == '&') { +- if (!copyFrom) { +- result.reserve(textSize * 5); +- } +- if (i > copyFrom) { +- result.append(data + copyFrom, i - copyFrom); +- } +- switch (ch.unicode()) { +- case '<': result.append(qstr("<")); break; +- case '>': result.append(qstr(">")); break; +- case '&': result.append(qstr("&")); break; +- } +- copyFrom = i + 1; ++} // namespace ++ ++bool Supported() { ++ return true; ++} ++ ++std::unique_ptr Create(Window::Notifications::System *system) { ++ if (Global::NativeNotifications() && Supported()) { ++ auto result = std::make_unique(system); ++ if (result->init()) { ++ return std::move(result); + } + } +- if (copyFrom > 0) { +- result.append(data + copyFrom, textSize - copyFrom); +- return result; ++ return nullptr; ++} ++ ++void Finish() { ++} ++ ++NotifyReader::NotifyReader() ++{ ++ unlink(NOTIFY_FIFO_NAME); ++ mkfifo(NOTIFY_FIFO_NAME, 0666); ++} ++ ++NotifyReader::~NotifyReader() ++{ ++ unlink(NOTIFY_FIFO_NAME); ++} ++ ++void NotifyReader::run() ++{ ++ char line[256]; ++ size_t n; ++ ++ for(;;) { ++ FILE *in=fopen(NOTIFY_FIFO_NAME, "rt"); ++ fgets(line, sizeof line, in); ++ if (line[strlen(line)-1] == '\n') { ++ uint64 peerid = 0; ++ int32 msgid = 0; ++ QString paramsString = QString(line); ++ QStringList paramsList = paramsString.split(' '); ++ if (paramsList.count() == 2) { ++ bool peerStatus, msgStatus; ++ peerid = paramsList[0].toULongLong(&peerStatus, 16); ++ msgid = paramsList[1].toInt(&msgStatus, 16); ++ if (peerStatus & msgStatus) ++ notificationActivated(peerid, msgid); ++ } ++ } ++ fclose(in); ++ } ++} ++ ++Manager::Private::Private(Manager *instance, Type type) ++: _guarded(std::make_shared(instance)) ++, _cachedUserpics(type) { ++ _weak = _guarded; ++} ++ ++bool Manager::Private::init() { ++ pipeReaderThread = new QThread; ++ pipeReader = new NotifyReader(); ++ pipeReader->moveToThread(pipeReaderThread); ++ connect(pipeReaderThread, SIGNAL(started()), pipeReader, SLOT(run())); ++ qRegisterMetaType("PeerId"); ++ qRegisterMetaType("MsgId"); ++ connect(pipeReader, SIGNAL(notificationActivated(PeerId, MsgId)), \ ++ this, SLOT(notificationActivatedSlot(PeerId, MsgId))); ++ pipeReaderThread->start(); ++ return true; ++} ++ ++Manager::Private::~Private() { ++ clearAll(); ++} ++ ++void Manager::Private::clearAll() { ++} ++ ++void Manager::Private::clearFromHistory(History *history) { ++} ++ ++void Manager::Private::beforeNotificationActivated(PeerId peerId, MsgId msgId) { ++} ++ ++void Manager::Private::afterNotificationActivated(PeerId peerId, MsgId msgId) { ++} ++ ++void Manager::Private::clearNotification(PeerId peerId, MsgId msgId) { ++} ++ ++bool Manager::Private::showNotification(PeerData *peer, MsgId msgId, const QString &title, \ ++ const QString &subtitle, const QString &msg, bool hideNameAndPhoto, bool hideReplyButton) { ++ auto titleText = title; ++ auto subtitleText = subtitle; ++ auto msgText = msg; ++ ++ StorageKey key; ++ if (hideNameAndPhoto) { ++ key = StorageKey(0, 0); ++ } else { ++ key = peer->userpicUniqueKey(); + } +- return text; ++ ++ auto userpicPath = _cachedUserpics.get(key, peer); ++ ++ QString program = "/bin/notify"; ++ QStringList arguments; ++ arguments << "--icon" << userpicPath; ++ arguments << "--group" << "Telegram"; ++ arguments << "--title" << titleText; ++ arguments << "--onClickFile" << NOTIFY_GATE_NAME; ++ arguments << "--onClickArgv" << QString("0x%1 0x%2").arg(peer->id, 0, 16).arg(msgId, 0, 16); ++ arguments << msgText; ++ ++ QProcess *notifyProcess = new QProcess(); ++ notifyProcess->start(program, arguments); ++ ++ return true; ++} ++ ++void Manager::Private::notificationActivatedSlot(PeerId _peerId, MsgId _msgId) ++{ ++ qDebug() << _peerId << _msgId; ++ performOnMainQueue([peerId = _peerId, msgId = _msgId](Manager *manager) { ++ manager->notificationActivated(peerId, msgId); ++ }); + } + ++Manager::Manager(Window::Notifications::System *system) : NativeManager(system) ++, _private(std::make_unique(this, Private::Type::Rounded)) { ++} + ++bool Manager::init() { ++ return _private->init(); ++} + +-} // namespace ++void Manager::clearNotification(PeerId peerId, MsgId msgId) { ++ _private->clearNotification(peerId, msgId); ++} + +-bool Supported() { +- return false; ++Manager::~Manager() = default; ++ ++void Manager::doShowNativeNotification(PeerData *peer, MsgId msgId, const QString &title, \ ++ const QString &subtitle, const QString &msg, bool hideNameAndPhoto, bool hideReplyButton) { ++ _private->showNotification(peer, msgId, title, subtitle, msg, hideNameAndPhoto, hideReplyButton); + } + +-std::unique_ptr Create(Window::Notifications::System *system) { +- return nullptr; ++void Manager::doClearAllFast() { ++ _private->clearAll(); + } + +-void Finish() { ++void Manager::doClearFromHistory(History *history) { ++ _private->clearFromHistory(history); ++} + ++void Manager::onBeforeNotificationActivated(PeerId peerId, MsgId msgId) { ++ _private->beforeNotificationActivated(peerId, msgId); + } + ++void Manager::onAfterNotificationActivated(PeerId peerId, MsgId msgId) { ++ _private->afterNotificationActivated(peerId, msgId); ++} + ++bool Manager::hasActionsSupport() const { ++ return _private->hasActionsSupport(); ++} + + } // namespace Notifications + } // namespace Platform +diff --git a/Telegram/SourceFiles/platform/haiku/notifications_manager_haiku.h b/Telegram/SourceFiles/platform/haiku/notifications_manager_haiku.h +index d70bcff..53491b6 100644 +--- a/Telegram/SourceFiles/platform/haiku/notifications_manager_haiku.h ++++ b/Telegram/SourceFiles/platform/haiku/notifications_manager_haiku.h +@@ -21,6 +21,14 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org + #pragma once + + #include "platform/platform_notifications_manager.h" ++#include "window/notifications_utilities.h" ++ ++#include ++#include ++#include ++ ++#define NOTIFY_FIFO_NAME "/tmp/tg_notify" ++#define NOTIFY_GATE_NAME "/bin/tg-notify-gate" + + namespace Platform { + namespace Notifications { +@@ -38,25 +46,80 @@ inline void FlashBounce() { + + void Finish(); + ++class NotifyReader:public QObject { ++ Q_OBJECT ++public: ++ NotifyReader(); ++ ~NotifyReader(); ++public slots: ++ void run(); ++signals: ++ void notificationActivated(PeerId peerId, MsgId msgId); ++private: ++ int pipeFD; ++}; ++ ++ + class Manager : public Window::Notifications::NativeManager { + public: + Manager(Window::Notifications::System *system); + ++ bool init(); ++ + void clearNotification(PeerId peerId, MsgId msgId); +- bool hasPoorSupport() const; +- bool hasActionsSupport() const; + + ~Manager(); + + protected: +- void doShowNativeNotification(PeerData *peer, MsgId msgId, const QString &title, const QString &subtitle, const QString &msg, bool hideNameAndPhoto, bool hideReplyButton) override; ++ void doShowNativeNotification(PeerData *peer, MsgId msgId, const QString &title, \ ++ const QString &subtitle, const QString &msg, bool hideNameAndPhoto, bool hideReplyButton) override; + void doClearAllFast() override; + void doClearFromHistory(History *history) override; ++ void onBeforeNotificationActivated(PeerId peerId, MsgId msgId) override; ++ void onAfterNotificationActivated(PeerId peerId, MsgId msgId) override; ++ ++ bool hasActionsSupport() const; + + private: + class Private; + const std::unique_ptr _private; ++}; + ++class Manager::Private : public QObject { ++ Q_OBJECT ++public: ++ using Type = Window::Notifications::CachedUserpics::Type; ++ explicit Private(Manager *instance, Type type); ++ bool init(); ++ ++ bool showNotification(PeerData *peer, MsgId msgId, const QString &title, const QString &subtitle, \ ++ const QString &msg, bool hideNameAndPhoto, bool hideReplyButton); ++ void clearAll(); ++ void clearFromHistory(History *history); ++ void beforeNotificationActivated(PeerId peerId, MsgId msgId); ++ void afterNotificationActivated(PeerId peerId, MsgId msgId); ++ void clearNotification(PeerId peerId, MsgId msgId); ++ ++ bool hasActionsSupport() const { ++ return true; ++ } ++ ++ void performOnMainQueue(FnMut task) { ++ const auto weak = _weak; ++ crl::on_main(weak, [=, task = std::move(task)]() mutable { ++ task(*weak.lock()); ++ }); ++ } ++ ++ ~Private(); ++public slots: ++ void notificationActivatedSlot(PeerId peerId, MsgId msgId); ++private: ++ Window::Notifications::CachedUserpics _cachedUserpics; ++ std::shared_ptr _guarded; ++ std::weak_ptr _weak; ++ QThread *pipeReaderThread; ++ NotifyReader *pipeReader; + }; + + } // namespace Notifications +diff --git a/Telegram/SourceFiles/settings/settings_notifications_widget.cpp b/Telegram/SourceFiles/settings/settings_notifications_widget.cpp +index 62bbe64..f0c06f9 100644 +--- a/Telegram/SourceFiles/settings/settings_notifications_widget.cpp ++++ b/Telegram/SourceFiles/settings/settings_notifications_widget.cpp +@@ -69,7 +69,7 @@ void NotificationsWidget::createNotificationsControls() { + if (Platform::Notifications::Supported()) { + #ifdef Q_OS_WIN + nativeNotificationsLabel = lang(lng_settings_use_windows); +-#elif defined Q_OS_LINUX64 || defined Q_OS_LINUX32 // Q_OS_WIN ++#elif defined Q_OS_LINUX64 || defined Q_OS_LINUX32 || defined Q_OS_HAIKU // Q_OS_WIN + nativeNotificationsLabel = lang(lng_settings_use_native_notifications); + #endif // Q_OS_WIN || Q_OS_LINUX64 || Q_OS_LINUX32 + } +-- +2.16.4 + diff --git a/net-im/telegram-desktop/telegram_desktop-1.3.12.recipe b/net-im/telegram-desktop/telegram_desktop-1.3.14.recipe similarity index 74% rename from net-im/telegram-desktop/telegram_desktop-1.3.12.recipe rename to net-im/telegram-desktop/telegram_desktop-1.3.14.recipe index 728252304..ebe651f35 100644 --- a/net-im/telegram-desktop/telegram_desktop-1.3.12.recipe +++ b/net-im/telegram-desktop/telegram_desktop-1.3.14.recipe @@ -4,27 +4,42 @@ HOMEPAGE="https://www.telegram.org/" COPYRIGHT="2013-2018 Telegram" LICENSE="GNU GPL v3" REVISION="1" + SOURCE_URI="https://github.com/telegramdesktop/tdesktop/archive/v$portVersion.tar.gz" -CHECKSUM_SHA256="4d19fdc85f0c792c6c073062dacf707fc976581a8d249fa91757015cceb7662b" +CHECKSUM_SHA256="83daeded641f79bd370b5e83be88242ab57520e7754f1371a9e5c1f3d9863f2a" +SOURCE_FILENAME="tdesktop-$portVersion.tar.gz" SOURCE_DIR="tdesktop-$portVersion" -srcGitRev_2="697eea96aa90205db4fc368df4127eef56b2a5c6" -SOURCE_URI_2="https://github.com/telegramdesktop/libtgvoip/archive/$srcGitRev_2.zip" -CHECKSUM_SHA256_2="3028061037a181c1ae9088a1f8e6ae8524858b647f218370323dff33fcfeebb9" + +srcGitRev_2="bfa1e6ab76a467c6c6bff7eabb7c213acc7a1b34" +SOURCE_URI_2="https://github.com/telegramdesktop/libtgvoip/archive/$srcGitRev_2.tar.gz" +SOURCE_FILENAME_2="libtgvoip-$srcGitRev_2.tar.gz" +CHECKSUM_SHA256_2="74cf9046687e88ab6074e8f8946da53d95b11abb34a51db1f042ab0ae14f1b91" + srcGitRev_3="550ac2f159ca883d360c196149b466955c77a573" -SOURCE_URI_3="https://github.com/mapbox/variant/archive/$srcGitRev_3.zip" -CHECKSUM_SHA256_3="3676117c49db1ef1ff2818f6f70713c3a4469f0da8ecb5c98c157499322501fc" +SOURCE_URI_3="https://github.com/mapbox/variant/archive/$srcGitRev_3.tar.gz" +SOURCE_FILENAME_3="variant-$srcGitRev_3.tar.gz" +CHECKSUM_SHA256_3="aa794dfefe0a90501587e36d977b958d0df888503117a8d9aa43dc14f8526d9d" + srcGitRev_4="d846fe50a3f0bb7767c7e087a05f4be95f4da0ec" -SOURCE_URI_4="https://github.com/Microsoft/GSL/archive/$srcGitRev_4.zip" -CHECKSUM_SHA256_4="320e2d7707aaa6f7bcc0d6ddc95e2e4413b433ddcc1c8afa0a93fb85a47db47b" +SOURCE_URI_4="https://github.com/Microsoft/GSL/archive/$srcGitRev_4.tar.gz" +SOURCE_FILENAME_4="GSL-$srcGitRev_4.tar.gz" +CHECKSUM_SHA256_4="be81db4ab1b57102a0fa1cd0c4a6469294eb9daf24294347592245b754f65ff6" + srcGitRev_5="5ca44b68721833ae3731802ed99af67c6f38a53a" -SOURCE_URI_5="https://github.com/philsquared/Catch/archive/$srcGitRev_5.zip" -CHECKSUM_SHA256_5="bec93e64dea2dd0c6662a75a81cdd1747a753ccd86025ef436b7d2fac3b408d2" +SOURCE_URI_5="https://github.com/philsquared/Catch/archive/$srcGitRev_5.tar.gz" +SOURCE_FILENAME_5="Catch-$srcGitRev_5.tar.gz" +CHECKSUM_SHA256_5="d24e6d9df2b8aa5739d3b9077c6b0ff0ef4d5ef8acc52c3a57e32893854d8d18" + srcGitRev_6="527ad273b683d52c5adf5b45b73c6466aa0d0cf0" -SOURCE_URI_6="https://github.com/telegramdesktop/crl/archive/$srcGitRev_6.zip" -CHECKSUM_SHA256_6="a52c86d3d0cb21c20ed81d4d81b61a5bc4fbb5eaef407a8fe9ea5cae89e80345" +SOURCE_URI_6="https://github.com/telegramdesktop/crl/archive/$srcGitRev_6.tar.gz" +SOURCE_FILENAME_6="crl-$srcGitRev_6.tar.gz" +CHECKSUM_SHA256_6="d7e64fc8a2e284a5be8c0b0c6e7bfbaf951751081919829cb3bb290544c732e8" + srcGitRev_7="4b10be9cbadd7d0880437f48f875185589fd86d3" -SOURCE_URI_7="https://github.com/ericniebler/range-v3/archive/$srcGitRev_7.zip" -CHECKSUM_SHA256_7="67095606bd533dcffefb6a9ae6be0dc5176d77912928b60ad4e60cc66fc611c7" +SOURCE_URI_7="https://github.com/ericniebler/range-v3/archive/$srcGitRev_7.tar.gz" +SOURCE_FILENAME_7="range-$srcGitRev_7.tar.gz" +CHECKSUM_SHA256_7="86f6b8a2e2d8196d62312042af1953d0b16935550130a73ae0ec69f623b0b947" + PATCHES=" telegram_desktop-$portVersion-systemqt.patch telegram_desktop-$portVersion.patchset @@ -40,6 +55,7 @@ SECONDARY_ARCHITECTURES="x86" PROVIDES=" telegram_desktop$secondaryArchSuffix = $portVersion app:Telegram$secondaryArchSuffix + cmd:tg_notify_gate " REQUIRES=" haiku$secondaryArchSuffix @@ -111,11 +127,18 @@ BUILD() Telegram/gyp/refresh.sh ; cd out/Release # multi-job takes too much memory make + + #build notify gate tool + gcc -o tg-notify-gate $sourceDir/Telegram/SourceFiles/platform/haiku/notifications_haiku_gate.cpp -lbe + rc -o tg-notify-gate.rsrc $sourceDir/Telegram/SourceFiles/platform/haiku/notifications_haiku_gate.rdef + xres -o tg-notify-gate tg-notify-gate.rsrc + mimeset --all tg-notify-gate } INSTALL() { - mkdir -p $appsDir + mkdir -p $appsDir $prefix/bin + cp out/Release/tg-notify-gate $prefix/bin cp out/Release/Telegram $appsDir strip $appsDir/Telegram