2019-02-24 13:15:14 +01:00
|
|
|
//
|
|
|
|
// 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"
|
2019-03-10 23:12:09 +01:00
|
|
|
#include "../../logging.h"
|
2019-02-24 13:15:14 +01:00
|
|
|
|
|
|
|
@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;
|
2019-03-10 23:12:09 +01:00
|
|
|
nativeRenderer=new tgvoip::video::SampleBufferDisplayLayerRenderer(self);
|
|
|
|
layer.videoGravity=AVLayerVideoGravityResizeAspect;
|
2019-02-24 13:15:14 +01:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc{
|
|
|
|
delete nativeRenderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (tgvoip::video::VideoRenderer *)nativeVideoRenderer{
|
|
|
|
return nativeRenderer;
|
|
|
|
}
|
|
|
|
|
2019-03-10 23:12:09 +01:00
|
|
|
- (void)_enqueueBuffer: (CMSampleBufferRef)buffer reset: (BOOL)reset{
|
2019-04-15 01:43:10 +02:00
|
|
|
/*if(reset){
|
2019-03-10 23:12:09 +01:00
|
|
|
LOGV("Resetting layer");
|
|
|
|
[layer flush];
|
2019-04-15 01:43:10 +02:00
|
|
|
}*/
|
2019-03-10 23:12:09 +01:00
|
|
|
LOGV("Enqueue buffer");
|
|
|
|
[layer enqueueSampleBuffer:buffer];
|
|
|
|
NSError* error=[layer error];
|
|
|
|
if(error){
|
|
|
|
LOGE("enqueueSampleBuffer failed: %s", [error.description cStringUsingEncoding:NSUTF8StringEncoding]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 01:43:10 +02:00
|
|
|
- (void)_setSizeWidth: (uint16_t)width height: (uint16_t)height{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
LOGI("Callback: setSize %u %u", width, height);
|
|
|
|
[delegate incomingVideoStreamWillStartWithFrameSize:CGSizeMake(width, height)];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_setRotation: (uint16_t)rotation{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
LOGI("Callback: setRotation %u", rotation);
|
|
|
|
[delegate incomingVideoRotationDidChange:(int)rotation];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_setStopped{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
LOGI("Callback: setStopped");
|
|
|
|
[delegate incomingVideoStreamDidStopWithReason:TGVStreamStopReasonUser];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_setPaused{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
LOGI("Callback: setPaused");
|
|
|
|
[delegate incomingVideoStreamDidPauseWithReason:TGVStreamPauseReasonBackground];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_setResumed{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
LOGI("Callback: setResumed");
|
|
|
|
[delegate incomingVideoStreamWillResume];
|
|
|
|
});
|
|
|
|
}
|
2019-02-24 13:15:14 +01:00
|
|
|
@end
|