-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMPSampleBuffer+Image.c
45 lines (35 loc) · 962 Bytes
/
CMPSampleBuffer+Image.c
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
#include "CMPSampleBuffer+Image.h"
#include "CMPAtoms.h"
#include "CMPBlockBuffer+Image.h"
CGImageRef CMPSampleBufferCopyImage(CFAllocatorRef allocator, CMSampleBufferRef sampleBuffer)
{
if(sampleBuffer == NULL)
{
return NULL;
}
CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
if(formatDescription == NULL)
{
return NULL;
}
CMMediaType mediaType = CMFormatDescriptionGetMediaType(formatDescription);
if(mediaType != kCMMediaType_Video)
{
return NULL;
}
CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
if(blockBuffer == NULL)
{
return NULL;
}
FourCharCode mediaSubType = CMFormatDescriptionGetMediaSubType(formatDescription);
if(mediaSubType == kCMPImageTypeJpeg)
{
return CMPBlockBufferCopyJPEGImage(allocator, blockBuffer);
}
if(mediaSubType == kCMPImageTypePng)
{
return CMPBlockBufferCopyPNGImage(allocator, blockBuffer);
}
return NULL;
}