1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-11-30 04:39:03 +01:00

Swift? Where we are going, we don't need Swift!

This commit is contained in:
Grishka 2019-02-24 16:15:14 +04:00
parent 632d7d5083
commit aabd289ba1
14 changed files with 349 additions and 3 deletions

View File

@ -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();
}
}

View File

@ -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

View File

@ -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 = "<group>"; };
69E357AF20F88954002E163B /* AudioIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioIO.h; sourceTree = "<group>"; };
69E629ED21AF62A900377D0F /* json11.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = json11.cpp; sourceTree = "<group>"; };
69F7914A2220A41000FE53C4 /* TGVVideoSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TGVVideoSource.h; sourceTree = "<group>"; };
69F7914B2220A41000FE53C4 /* TGVVideoSource.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TGVVideoSource.mm; sourceTree = "<group>"; };
69F7914E2220A76500FE53C4 /* TGVVideoRenderer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TGVVideoRenderer.h; sourceTree = "<group>"; };
69F7914F2220A76500FE53C4 /* TGVVideoRenderer.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TGVVideoRenderer.mm; sourceTree = "<group>"; };
69F791522221F16C00FE53C4 /* VideoToolboxEncoderSource.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VideoToolboxEncoderSource.cpp; sourceTree = "<group>"; };
69F791532221F16C00FE53C4 /* VideoToolboxEncoderSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VideoToolboxEncoderSource.h; sourceTree = "<group>"; };
69F791562222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SampleBufferDisplayLayerRenderer.cpp; sourceTree = "<group>"; };
69F791572222AC2800FE53C4 /* SampleBufferDisplayLayerRenderer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SampleBufferDisplayLayerRenderer.h; sourceTree = "<group>"; };
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 = "<group>"; };
69FB0B2C20F6860D00827817 /* MessageThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageThread.h; sourceTree = "<group>"; };
@ -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 */,

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string>
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.
</string>
</dict>
</plist>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string>
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.
</string>
</dict>
</plist>

View File

@ -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){

View File

@ -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<Buffer>& csd){
}
void SampleBufferDisplayLayerRenderer::DecodeAndDisplay(Buffer frame, uint32_t pts){
}
void SampleBufferDisplayLayerRenderer::SetStreamEnabled(bool enabled){
}
int SampleBufferDisplayLayerRenderer::GetMaximumResolution(){
return INIT_VIDEO_RES_1080;
}

View File

@ -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<Buffer>& csd) override;
virtual void DecodeAndDisplay(Buffer frame, uint32_t pts) override;
virtual void SetStreamEnabled(bool enabled) override;
static int GetMaximumResolution();
private:
};
}
}
#endif /* TGVOIP_SAMPLEBUFFERDISPLAYLAYERRENDERER */

View File

@ -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 <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
namespace tgvoip{
namespace video{
class VideoRenderer;
}
}
typedef NS_ENUM(int, TGVStreamPauseReason){
TGVStreamPauseReasonBackground,
TGVStreamPauseReasonPoorConnection
};
typedef NS_ENUM(int, TGVStreamStopReason){
TGVStreamStopReasonUser,
TGVStreamStopReasonPoorConnection
};
@protocol TGVVideoRendererDelegate <NSObject>
- (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<TGVVideoRendererDelegate>)delegate;
- (tgvoip::video::VideoRenderer*)nativeVideoRenderer;
@end

View File

@ -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<TGVVideoRendererDelegate> delegate;
tgvoip::video::SampleBufferDisplayLayerRenderer* nativeRenderer;
}
- (instancetype)initWithDisplayLayer:(AVSampleBufferDisplayLayer *)layer delegate:(nonnull id<TGVVideoRendererDelegate>)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

View File

@ -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 <Foundation/Foundation.h>
#import <CoreMedia/CoreMedia.h>
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

View File

@ -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

View File

@ -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){
}

View File

@ -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 <CoreMedia/CoreMedia.h>
#include <VideoToolbox/VideoToolbox.h>
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 */