-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMPSampleBuffer+Text.c
64 lines (50 loc) · 1.75 KB
/
CMPSampleBuffer+Text.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "CMPSampleBuffer+Text.h"
#include <TargetConditionals.h>
#include "CMPAtoms.h"
#include "CMPBlockBuffer+Text.h"
#include "CMPErrors.h"
OSStatus CMPSampleBufferCreateWithText(CFAllocatorRef allocator, CFStringRef text, Boolean dataReady, CMSampleBufferMakeDataReadyCallback makeDataReadyCallback, void *makeDataReadyRefcon, CMFormatDescriptionRef formatDescription, const CMSampleTimingInfo *sampleTiming, CMSampleBufferRef *outSampleBuffer)
{
if(text == NULL)
{
return CMPParameterError;
}
CMBlockBufferRef blockBuffer = NULL;
OSStatus status = CMPBlockBufferCreateWithText(allocator, text, &blockBuffer);
if(status != noErr)
{
return status;
}
size_t blockBufferLength = CMBlockBufferGetDataLength(blockBuffer);
status = CMSampleBufferCreate(allocator, blockBuffer, dataReady, makeDataReadyCallback, makeDataReadyRefcon, formatDescription, 1, 1, sampleTiming, 1, &blockBufferLength, outSampleBuffer );
CFRelease( blockBuffer );
return status;
}
CFStringRef CMPSampleBufferCopyText(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_Text)
{
return NULL;
}
FourCharCode mediaSubType = CMFormatDescriptionGetMediaSubType(formatDescription);
if(mediaSubType != kCMTextFormatType_QTText && mediaSubType != kCMTextFormatType_3GText)
{
return NULL;
}
CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
if(blockBuffer == NULL)
{
return NULL;
}
return CMPBlockBufferCopyText(allocator, blockBuffer);
}