diff --git a/Buffers.cpp b/Buffers.cpp index 227be98..85db3e9 100644 --- a/Buffers.cpp +++ b/Buffers.cpp @@ -130,6 +130,8 @@ void BufferInputStream::EnsureEnoughRemaining(size_t need){ BufferOutputStream::BufferOutputStream(size_t size){ buffer=(unsigned char*) malloc(size); + if(!buffer) + throw std::bad_alloc(); offset=0; this->size=size; bufferProvided=false; @@ -217,6 +219,8 @@ void BufferOutputStream::ExpandBufferIfNeeded(size_t need){ buffer=(unsigned char *) realloc(buffer, size+need); size+=need; } + if(!buffer) + throw std::bad_alloc(); } } diff --git a/PrivateDefines.h b/PrivateDefines.h index e6668be..1343699 100644 --- a/PrivateDefines.h +++ b/PrivateDefines.h @@ -72,6 +72,8 @@ #define EXTRA_TYPE_GROUP_CALL_KEY 5 #define EXTRA_TYPE_REQUEST_GROUP 6 #define EXTRA_TYPE_IPV6_ENDPOINT 7 +#define EXTRA_TYPE_BW_ESTIMATE 8 +#define EXTRA_TYPE_VIDEO_ROTATION 9 #define STREAM_FLAG_ENABLED 1 #define STREAM_FLAG_DTX 2 diff --git a/libtgvoip.xcodeproj/project.pbxproj b/libtgvoip.xcodeproj/project.pbxproj index 80838e7..ca0a9f4 100644 --- a/libtgvoip.xcodeproj/project.pbxproj +++ b/libtgvoip.xcodeproj/project.pbxproj @@ -314,6 +314,14 @@ 69DD8D03218CD401001E8140 /* VideoSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 69DD8CFF218CD400001E8140 /* VideoSource.cpp */; }; 69E357B020F88955002E163B /* AudioIO.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 69E357A720F88954002E163B /* AudioIO.cpp */; }; 69E629EE21AF62A900377D0F /* json11.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 69E629ED21AF62A900377D0F /* json11.cpp */; }; + 69F7914C2220A41000FE53C4 /* TGVVideoSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 69F7914A2220A41000FE53C4 /* TGVVideoSource.h */; }; + 69F7914D2220A41000FE53C4 /* TGVVideoSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69F7914B2220A41000FE53C4 /* TGVVideoSource.mm */; }; + 69F791502220A76500FE53C4 /* TGVVideoRenderer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69F7914E2220A76500FE53C4 /* TGVVideoRenderer.h */; }; + 69F791512220A76500FE53C4 /* TGVVideoRenderer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 69F7914F2220A76500FE53C4 /* TGVVideoRenderer.mm */; }; + 69F791542221F16C00FE53C4 /* VideoToolboxEncoderSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 69F791522221F16C00FE53C4 /* VideoToolboxEncoderSource.cpp */; }; + 69F791552221F16C00FE53C4 /* VideoToolboxEncoderSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 69F791532221F16C00FE53C4 /* VideoToolboxEncoderSource.h */; }; + 69F791582222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 69F791562222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.cpp */; }; + 69F791592222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69F791572222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.h */; }; 69FB0B2D20F6860E00827817 /* MessageThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 69FB0B2420F6860D00827817 /* MessageThread.cpp */; }; /* End PBXBuildFile section */ @@ -1024,6 +1032,14 @@ 69E357A720F88954002E163B /* AudioIO.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioIO.cpp; sourceTree = ""; }; 69E357AF20F88954002E163B /* AudioIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioIO.h; sourceTree = ""; }; 69E629ED21AF62A900377D0F /* json11.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = json11.cpp; sourceTree = ""; }; + 69F7914A2220A41000FE53C4 /* TGVVideoSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TGVVideoSource.h; sourceTree = ""; }; + 69F7914B2220A41000FE53C4 /* TGVVideoSource.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TGVVideoSource.mm; sourceTree = ""; }; + 69F7914E2220A76500FE53C4 /* TGVVideoRenderer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TGVVideoRenderer.h; sourceTree = ""; }; + 69F7914F2220A76500FE53C4 /* TGVVideoRenderer.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TGVVideoRenderer.mm; sourceTree = ""; }; + 69F791522221F16C00FE53C4 /* VideoToolboxEncoderSource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VideoToolboxEncoderSource.cpp; sourceTree = ""; }; + 69F791532221F16C00FE53C4 /* VideoToolboxEncoderSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VideoToolboxEncoderSource.h; sourceTree = ""; }; + 69F791562222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SampleBufferDisplayLayerRenderer.cpp; sourceTree = ""; }; + 69F791572222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SampleBufferDisplayLayerRenderer.h; sourceTree = ""; }; 69F842361E67540700C110F7 /* libtgvoip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = libtgvoip.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 69FB0B2420F6860D00827817 /* MessageThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MessageThread.cpp; sourceTree = ""; }; 69FB0B2C20F6860D00827817 /* MessageThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageThread.h; sourceTree = ""; }; @@ -1124,6 +1140,14 @@ isa = PBXGroup; children = ( 692AB8BE1E6759DD00706ACC /* AudioInputAudioUnit.cpp */, + 69F7914A2220A41000FE53C4 /* TGVVideoSource.h */, + 69F7914B2220A41000FE53C4 /* TGVVideoSource.mm */, + 69F7914E2220A76500FE53C4 /* TGVVideoRenderer.h */, + 69F7914F2220A76500FE53C4 /* TGVVideoRenderer.mm */, + 69F791562222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.cpp */, + 69F791572222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.h */, + 69F791522221F16C00FE53C4 /* VideoToolboxEncoderSource.cpp */, + 69F791532221F16C00FE53C4 /* VideoToolboxEncoderSource.h */, 692AB8BF1E6759DD00706ACC /* AudioInputAudioUnit.h */, 692AB8C01E6759DD00706ACC /* AudioOutputAudioUnit.cpp */, 692AB8C11E6759DD00706ACC /* AudioOutputAudioUnit.h */, @@ -2330,8 +2354,12 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 69F791552221F16C00FE53C4 /* VideoToolboxEncoderSource.h in Headers */, + 69F7914C2220A41000FE53C4 /* TGVVideoSource.h in Headers */, 692AB9051E6759DD00706ACC /* VoIPServerConfig.h in Headers */, 692AB9031E6759DD00706ACC /* VoIPController.h in Headers */, + 69F791592222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.h in Headers */, + 69F791502220A76500FE53C4 /* TGVVideoRenderer.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2487,6 +2515,7 @@ 697E9C9721A4ED6D00E03846 /* biquad_filter.cc in Sources */, 697E9B5021A4ED6B00E03846 /* audio_converter.cc in Sources */, 697E9CFC21A4ED6D00E03846 /* subband_erle_estimator.cc in Sources */, + 69F791512220A76500FE53C4 /* TGVVideoRenderer.mm in Sources */, 697E9B4E21A4ED6B00E03846 /* fft4g.c in Sources */, 697E9C6821A4ED6C00E03846 /* spectral_features_internal.cc in Sources */, 697E9CAE21A4ED6D00E03846 /* aec_resampler.cc in Sources */, @@ -2583,6 +2612,7 @@ 697E9D1521A4ED6D00E03846 /* render_signal_analyzer.cc in Sources */, 697E9B5E21A4ED6B00E03846 /* levinson_durbin.c in Sources */, 697E9D0321A4ED6D00E03846 /* adaptive_fir_filter.cc in Sources */, + 69F791542221F16C00FE53C4 /* VideoToolboxEncoderSource.cpp in Sources */, 697E9B4A21A4ED6B00E03846 /* wav_file.cc in Sources */, 697E9CE721A4ED6D00E03846 /* render_delay_buffer2.cc in Sources */, 697E9C1121A4ED6C00E03846 /* lpc_gain_swb_tables.c in Sources */, @@ -2641,6 +2671,7 @@ 697E9D3821A4ED6D00E03846 /* block_processor2.cc in Sources */, 697E9BEB21A4ED6C00E03846 /* criticalsection.cc in Sources */, 69791A571EE8272A00BB85FB /* Resampler.cpp in Sources */, + 69F7914D2220A41000FE53C4 /* TGVVideoSource.mm in Sources */, 697E9B8221A4ED6B00E03846 /* resample_by_2.c in Sources */, 697E9B3521A4ED6B00E03846 /* wav_header.cc in Sources */, 697E9D5621A4ED6E00E03846 /* vad_circular_buffer.cc in Sources */, @@ -2712,6 +2743,7 @@ 697E9D6321A4ED6E00E03846 /* gmm.cc in Sources */, 697E9CAA21A4ED6D00E03846 /* level_estimator_impl.cc in Sources */, 697E9D3021A4ED6D00E03846 /* echo_remover.cc in Sources */, + 69F791582222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.cpp in Sources */, 697E9C8721A4ED6C00E03846 /* vad_with_level.cc in Sources */, 697E9B3721A4ED6B00E03846 /* fir_filter_neon.cc in Sources */, 697E9C4621A4ED6C00E03846 /* noise_suppression.c in Sources */, diff --git a/libtgvoip.xcodeproj/xcshareddata/IDETemplateMacros.plist b/libtgvoip.xcodeproj/xcshareddata/IDETemplateMacros.plist new file mode 100644 index 0000000..7e0b977 --- /dev/null +++ b/libtgvoip.xcodeproj/xcshareddata/IDETemplateMacros.plist @@ -0,0 +1,12 @@ + + + + + FILEHEADER + +libtgvoip is free and unencumbered public domain software. +For more information, see http://unlicense.org or the UNLICENSE file +you should have received with this source code distribution. + + + diff --git a/libtgvoip_osx.xcodeproj/xcshareddata/IDETemplateMacros.plist b/libtgvoip_osx.xcodeproj/xcshareddata/IDETemplateMacros.plist new file mode 100644 index 0000000..7e0b977 --- /dev/null +++ b/libtgvoip_osx.xcodeproj/xcshareddata/IDETemplateMacros.plist @@ -0,0 +1,12 @@ + + + + + FILEHEADER + +libtgvoip is free and unencumbered public domain software. +For more information, see http://unlicense.org or the UNLICENSE file +you should have received with this source code distribution. + + + diff --git a/os/android/VideoRendererAndroid.cpp b/os/android/VideoRendererAndroid.cpp index 805816a..1591bf9 100644 --- a/os/android/VideoRendererAndroid.cpp +++ b/os/android/VideoRendererAndroid.cpp @@ -48,7 +48,7 @@ void VideoRendererAndroid::Reset(uint32_t codec, unsigned int width, unsigned in void VideoRendererAndroid::DecodeAndDisplay(Buffer frame, uint32_t pts){ /*decoderThread.Post(std::bind([this](Buffer frame){ }, std::move(frame)));*/ - LOGV("2 before decode %u", (unsigned int)frame.Length()); + //LOGV("2 before decode %u", (unsigned int)frame.Length()); queue.Put(std::move(frame)); } @@ -89,9 +89,9 @@ void VideoRendererAndroid::RunThread(){ jobject jbuf=env->NewDirectByteBuffer(buf, bufferSize); while(running){ - LOGV("before get from queue"); + //LOGV("before get from queue"); Buffer frame=std::move(queue.GetBlocking()); - LOGV("1 before decode %u", (unsigned int)frame.Length()); + //LOGV("1 before decode %u", (unsigned int)frame.Length()); if(!running) break; if(frame.Length()>bufferSize){ diff --git a/os/darwin/SampleBufferDisplayLayerRenderer.cpp b/os/darwin/SampleBufferDisplayLayerRenderer.cpp new file mode 100644 index 0000000..1a0046f --- /dev/null +++ b/os/darwin/SampleBufferDisplayLayerRenderer.cpp @@ -0,0 +1,35 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file +// you should have received with this source code distribution. +// + +#include "SampleBufferDisplayLayerRenderer.h" +#include "../../PrivateDefines.h" + +using namespace tgvoip; +using namespace tgvoip::video; + +SampleBufferDisplayLayerRenderer::SampleBufferDisplayLayerRenderer(){ + +} + +SampleBufferDisplayLayerRenderer::~SampleBufferDisplayLayerRenderer(){ + +} + +void SampleBufferDisplayLayerRenderer::Reset(uint32_t codec, unsigned int width, unsigned int height, std::vector& csd){ + +} + +void SampleBufferDisplayLayerRenderer::DecodeAndDisplay(Buffer frame, uint32_t pts){ + +} + +void SampleBufferDisplayLayerRenderer::SetStreamEnabled(bool enabled){ + +} + +int SampleBufferDisplayLayerRenderer::GetMaximumResolution(){ + return INIT_VIDEO_RES_1080; +} diff --git a/os/darwin/SampleBufferDisplayLayerRenderer.h b/os/darwin/SampleBufferDisplayLayerRenderer.h new file mode 100644 index 0000000..257a06d --- /dev/null +++ b/os/darwin/SampleBufferDisplayLayerRenderer.h @@ -0,0 +1,28 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file +// you should have received with this source code distribution. +// + +#ifndef TGVOIP_SAMPLEBUFFERDISPLAYLAYERRENDERER +#define TGVOIP_SAMPLEBUFFERDISPLAYLAYERRENDERER + +#include "../../video/VideoRenderer.h" + +namespace tgvoip{ + namespace video{ + class SampleBufferDisplayLayerRenderer : public VideoRenderer{ + public: + SampleBufferDisplayLayerRenderer(); + virtual ~SampleBufferDisplayLayerRenderer(); + virtual void Reset(uint32_t codec, unsigned int width, unsigned int height, std::vector& csd) override; + virtual void DecodeAndDisplay(Buffer frame, uint32_t pts) override; + virtual void SetStreamEnabled(bool enabled) override; + static int GetMaximumResolution(); + private: + + }; + } +} + +#endif /* TGVOIP_SAMPLEBUFFERDISPLAYLAYERRENDERER */ diff --git a/os/darwin/TGVVideoRenderer.h b/os/darwin/TGVVideoRenderer.h new file mode 100644 index 0000000..a658dc5 --- /dev/null +++ b/os/darwin/TGVVideoRenderer.h @@ -0,0 +1,41 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file +// you should have received with this source code distribution. +// + +#import +#import + +namespace tgvoip{ +namespace video{ +class VideoRenderer; +} +} + +typedef NS_ENUM(int, TGVStreamPauseReason){ + TGVStreamPauseReasonBackground, + TGVStreamPauseReasonPoorConnection +}; + +typedef NS_ENUM(int, TGVStreamStopReason){ + TGVStreamStopReasonUser, + TGVStreamStopReasonPoorConnection +}; + +@protocol TGVVideoRendererDelegate + +- (void)incomingVideoRotationDidChange: (int)rotation; +- (void)incomingVideoStreamWillStartWithFrameSize: (CGSize)size; +- (void)incomingVideoStreamDidStopWithReason: (TGVStreamStopReason)reason; +- (void)incomingVideoStreamDidPauseWithReason: (TGVStreamPauseReason)reason; +- (void)incomingVideoStreamWillResume; + +@end + +@interface TGVVideoRenderer : NSObject + +- (instancetype)initWithDisplayLayer: (AVSampleBufferDisplayLayer *)layer delegate: (id)delegate; +- (tgvoip::video::VideoRenderer*)nativeVideoRenderer; + +@end diff --git a/os/darwin/TGVVideoRenderer.mm b/os/darwin/TGVVideoRenderer.mm new file mode 100644 index 0000000..ebd7bb4 --- /dev/null +++ b/os/darwin/TGVVideoRenderer.mm @@ -0,0 +1,32 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file +// you should have received with this source code distribution. +// + +#import "TGVVideoRenderer.h" +#include "SampleBufferDisplayLayerRenderer.h" + +@implementation TGVVideoRenderer{ + AVSampleBufferDisplayLayer* layer; + id delegate; + tgvoip::video::SampleBufferDisplayLayerRenderer* nativeRenderer; +} + +- (instancetype)initWithDisplayLayer:(AVSampleBufferDisplayLayer *)layer delegate:(nonnull id)delegate{ + self=[super init]; + self->layer=layer; + self->delegate=delegate; + nativeRenderer=new tgvoip::video::SampleBufferDisplayLayerRenderer(); + return self; +} + +- (void)dealloc{ + delete nativeRenderer; +} + +- (tgvoip::video::VideoRenderer *)nativeVideoRenderer{ + return nativeRenderer; +} + +@end diff --git a/os/darwin/TGVVideoSource.h b/os/darwin/TGVVideoSource.h new file mode 100644 index 0000000..e657c29 --- /dev/null +++ b/os/darwin/TGVVideoSource.h @@ -0,0 +1,32 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file +// you should have received with this source code distribution. +// + +#import +#import + +namespace tgvoip{ +namespace video{ +class VideoSource; +} +} + +typedef NS_ENUM(int, TGVVideoResolution){ + TGVVideoResolution1080, + TGVVideoResolution720, + TGVVideoResolution480, + TGVVideoResolution360 +}; + +@interface TGVVideoSource : NSObject + +- (void)sendVideoFrame: (CMSampleBufferRef)buffer; +- (TGVVideoResolution)maximumSupportedVideoResolution; +- (void)setVideoRotation: (int)rotation; +- (void)pauseStream; +- (void)resumeStream; +- (tgvoip::video::VideoSource*)nativeVideoSource; + +@end diff --git a/os/darwin/TGVVideoSource.mm b/os/darwin/TGVVideoSource.mm new file mode 100644 index 0000000..0173cc2 --- /dev/null +++ b/os/darwin/TGVVideoSource.mm @@ -0,0 +1,48 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file +// you should have received with this source code distribution. +// + +#import "TGVVideoSource.h" +#include "VideoToolboxEncoderSource.h" + +@implementation TGVVideoSource{ + tgvoip::video::VideoToolboxEncoderSource* nativeSource; +} + +- (instancetype)init{ + self=[super init]; + nativeSource=new tgvoip::video::VideoToolboxEncoderSource(); + return self; +} + +- (void)dealloc{ + delete nativeSource; +} + +- (void)sendVideoFrame: (CMSampleBufferRef)buffer{ + nativeSource->EncodeFrame(buffer); +} + +- (TGVVideoResolution)maximumSupportedVideoResolution{ + return TGVVideoResolution1080; +} + +- (void)setVideoRotation: (int)rotation{ + +} + +- (void)pauseStream{ + +} + +- (void)resumeStream{ + +} + +- (tgvoip::video::VideoSource*)nativeVideoSource{ + return nativeSource; +} + +@end diff --git a/os/darwin/VideoToolboxEncoderSource.cpp b/os/darwin/VideoToolboxEncoderSource.cpp new file mode 100644 index 0000000..602c31d --- /dev/null +++ b/os/darwin/VideoToolboxEncoderSource.cpp @@ -0,0 +1,39 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file +// you should have received with this source code distribution. +// + +#include "VideoToolboxEncoderSource.h" +#include "../../PrivateDefines.h" + +using namespace tgvoip; +using namespace tgvoip::video; + +VideoToolboxEncoderSource::VideoToolboxEncoderSource(){ + +} + +VideoToolboxEncoderSource::~VideoToolboxEncoderSource(){ + +} + +void VideoToolboxEncoderSource::Start(){ + +} + +void VideoToolboxEncoderSource::Stop(){ + +} + +void VideoToolboxEncoderSource::Reset(uint32_t codec, int maxResolution){ + +} + +void VideoToolboxEncoderSource::RequestKeyFrame(){ + +} + +void VideoToolboxEncoderSource::EncodeFrame(CMSampleBufferRef frame){ + +} diff --git a/os/darwin/VideoToolboxEncoderSource.h b/os/darwin/VideoToolboxEncoderSource.h new file mode 100644 index 0000000..d25fcb0 --- /dev/null +++ b/os/darwin/VideoToolboxEncoderSource.h @@ -0,0 +1,29 @@ +// +// libtgvoip is free and unencumbered public domain software. +// For more information, see http://unlicense.org or the UNLICENSE file +// you should have received with this source code distribution. +// + +#ifndef LIBTGVOIP_VIDEOTOOLBOXENCODERSOURCE +#define LIBTGVOIP_VIDEOTOOLBOXENCODERSOURCE + +#include "../../video/VideoSource.h" +#include +#include + +namespace tgvoip{ + namespace video{ + class VideoToolboxEncoderSource : public VideoSource{ + public: + VideoToolboxEncoderSource(); + virtual ~VideoToolboxEncoderSource(); + virtual void Start() override; + virtual void Stop() override; + virtual void Reset(uint32_t codec, int maxResolution) override; + virtual void RequestKeyFrame() override; + void EncodeFrame(CMSampleBufferRef frame); + }; + } +} + +#endif /* LIBTGVOIP_VIDEOTOOLBOXENCODERSOURCE */