-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathVideoDecoderHelper.x
More file actions
34 lines (30 loc) · 1.22 KB
/
VideoDecoderHelper.x
File metadata and controls
34 lines (30 loc) · 1.22 KB
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
#import "Header.h"
NSInteger HAMGetSampleSize(HAMInputSampleBuffer *buf, NSInteger i) {
if ([buf respondsToSelector:@selector(sampleSizeForSample:)]) {
return [buf sampleSizeForSample:i];
}
static ptrdiff_t off;
if (!off) {
Ivar iv = class_getInstanceVariable([buf class], "_sampleBuffer");
off = iv ? ivar_getOffset(iv) : -1;
}
CMSampleBufferRef cmBuf = (off > 0)
? *(CMSampleBufferRef *)((uint8_t *)(__bridge void *)buf + off) : NULL;
return (cmBuf) ? CMSampleBufferGetSampleSize(cmBuf, i) : 0;
}
CMSampleTimingInfo HAMGetSampleTiming(HAMInputSampleBuffer *buf, NSInteger i) {
if ([buf respondsToSelector:@selector(timingInfoForSample:)]) {
return [buf timingInfoForSample:i];
}
static ptrdiff_t off;
if (!off) {
Ivar iv = class_getInstanceVariable([buf class], "_sampleBuffer");
off = iv ? ivar_getOffset(iv) : -1;
}
CMSampleBufferRef cmBuf = (off > 0)
? *(CMSampleBufferRef *)((uint8_t *)(__bridge void *)buf + off) : NULL;
CMSampleTimingInfo t;
if (!cmBuf || CMSampleBufferGetSampleTimingInfo(cmBuf, i, &t) != noErr)
t = (CMSampleTimingInfo){kCMTimeInvalid, kCMTimeInvalid, kCMTimeInvalid};
return t;
}