-
Notifications
You must be signed in to change notification settings - Fork 1
/
DVGStackableCompositionInstruction.m
71 lines (65 loc) · 2.58 KB
/
DVGStackableCompositionInstruction.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#import "DVGStackableCompositionInstruction.h"
@implementation DVGStackableCompositionInstruction
- (id)initProcessingZero
{
self = [super init];
if (self) {
self.pools = @{}.mutableCopy;
_requiredSourceTrackIDs = nil;
_passthroughTrackID = kCMPersistentTrackID_Invalid;
_timeRange = kCMTimeRangeZero;
_containsTweening = TRUE;
_enablePostProcessing = FALSE;
}
return self;
}
- (id)initProcessingWithSourceTrackIDs:(NSArray *)sourceTrackIDs forTimeRange:(CMTimeRange)timeRange
{
self = [super init];
if (self) {
self.pools = @{}.mutableCopy;
_requiredSourceTrackIDs = sourceTrackIDs;
_passthroughTrackID = kCMPersistentTrackID_Invalid;
_timeRange = timeRange;
_containsTweening = TRUE;
_enablePostProcessing = FALSE;
}
return self;
}
- (id)getPixelBufferPoolForWidth:(int)w andHeight:(int)h {
NSString* key = [NSString stringWithFormat:@"pixpool_%i_%i",w,h];
NSValue* pool = [self.pools objectForKey:key];
if(pool == nil){
CVPixelBufferPoolRef bufferPool = nil;
NSMutableDictionary* attributes;
attributes = [NSMutableDictionary dictionary];
[attributes setObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey];
[attributes setObject:[NSNumber numberWithInt:w] forKey: (NSString*)kCVPixelBufferWidthKey];
[attributes setObject:[NSNumber numberWithInt:h] forKey: (NSString*)kCVPixelBufferHeightKey];
NSDictionary *IOSurfaceProperties = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], @"IOSurfaceOpenGLESFBOCompatibility",[NSNumber numberWithBool:YES], @"IOSurfaceOpenGLESTextureCompatibility",nil];
[attributes setObject:IOSurfaceProperties forKey:(NSString*)kCVPixelBufferIOSurfacePropertiesKey];
CVPixelBufferPoolCreate(kCFAllocatorDefault, NULL, (__bridge CFDictionaryRef) attributes, &bufferPool);
pool = [NSValue valueWithPointer:bufferPool];
[self.pools setObject:pool forKey:key];
}
return [pool pointerValue];
}
-(void)dealloc
{
for (NSString* key in self.pools) {
id value = [self.pools objectForKey:key];
// do stuff
if([key containsString:@"pixpool_"]){
CVPixelBufferPoolRef bufferPool = [value pointerValue];
CVPixelBufferPoolRelease(bufferPool);
}
}
self.pools = nil;
for(DVGOglEffectBase* renderer in self.renderersStack){
[renderer releaseOglResources];
}
if(self.lastOkRenderedPixels){
CVPixelBufferRelease(self.lastOkRenderedPixels);
}
}
@end