forked from wjhwsh/VideoPlayer-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFFMpegEngine.m
97 lines (81 loc) · 1.86 KB
/
FFMpegEngine.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// FFMpegEngine.m
// FFmpegPlayTest
//
// Created by Jack on 11/14/12.
// Copyright (c) 2012 Jack. All rights reserved.
//
#import <libkern/OSAtomic.h>
#import <dispatch/dispatch.h>
#import "FFMpegEngine.h"
#import "FFmpeg.h"
@interface FFMpegEngine ()
{
BOOL _initialized;
}
@end
@implementation FFMpegEngine
static FFMpegEngine* volatile _sharedInstance = nil;
+ (FFMpegEngine*) shareInstance
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
static dispatch_once_t __once = 0;
dispatch_once(&__once, ^{ _sharedInstance = [[FFMpegEngine alloc] init]; });
#else
if (!_shareInstance) {
FFMpegEngine *_obj = [[FFMpegEngine alloc] init];
if(OSAtomicCompareAndSwapPtrBarrier(nil, _obj, (void* volatile*)&_sharedInstance) == false)
[obj release];
}
#endif
return _sharedInstance;
}
#pragma mark - Class Level Methods
+ (UInt32) bitsForSampleFormat: (int) sampleFormat
{
switch (sampleFormat) {
case AV_SAMPLE_FMT_U8:
case AV_SAMPLE_FMT_U8P:
return 8;
break;
case AV_SAMPLE_FMT_S16:
case AV_SAMPLE_FMT_S16P:
return 16;
break;
case AV_SAMPLE_FMT_S32:
case AV_SAMPLE_FMT_S32P:
return 32;
break;
case AV_SAMPLE_FMT_FLT:
case AV_SAMPLE_FMT_FLTP:
return sizeof(float);
break;
case AV_SAMPLE_FMT_DBL:
case AV_SAMPLE_FMT_DBLP:
return sizeof(double);
default:
break;
}
return 0;
};
- (id) init
{
self = [super init];
if (self) {
_initialized = NO;
}
return self;
}
- (void) initFFmpegEngine
{
if (!_initialized) {
av_register_all();
avcodec_register_all();
_initialized = YES;
}
}
- (BOOL) isInitialized
{
return _initialized;
}
@end