| FFmpegKit iOS / macOS / tvOS API 4.5

FFmpegSession.m
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Taner Sener
3 *
4 * This file is part of FFmpegKit.
5 *
6 * FFmpegKit is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpegKit is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General License
17 * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#import "ExecuteCallback.h"
21#import "FFmpegSession.h"
22#import "FFmpegKitConfig.h"
23#import "LogCallback.h"
24#import "StatisticsCallback.h"
25
26@implementation FFmpegSession {
27 StatisticsCallback _statisticsCallback;
28 NSMutableArray* _statistics;
29 NSRecursiveLock* _statisticsLock;
30}
31
32+ (void)initialize {
33 // EMPTY INITIALIZE
34}
35
36- (instancetype)init:(NSArray*)arguments {
37
38 self = [super init:arguments withExecuteCallback:nil withLogCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
39
40 if (self) {
41 _statisticsCallback = nil;
42 _statistics = [[NSMutableArray alloc] init];
43 _statisticsLock = [[NSRecursiveLock alloc] init];
44 }
45
46 return self;
47}
48
49- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback {
50
51 self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
52
53 if (self) {
54 _statisticsCallback = nil;
55 _statistics = [[NSMutableArray alloc] init];
56 _statisticsLock = [[NSRecursiveLock alloc] init];
57 }
58
59 return self;
60}
61
62- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback {
63
64 self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
65
66 if (self) {
67 _statisticsCallback = statisticsCallback;
68 _statistics = [[NSMutableArray alloc] init];
69 _statisticsLock = [[NSRecursiveLock alloc] init];
70 }
71
72 return self;
73}
74
75- (instancetype)init:(NSArray*)arguments withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy {
76
77 self = [super init:arguments withExecuteCallback:executeCallback withLogCallback:logCallback withLogRedirectionStrategy:logRedirectionStrategy];
78
79 if (self) {
80 _statisticsCallback = statisticsCallback;
81 _statistics = [[NSMutableArray alloc] init];
82 _statisticsLock = [[NSRecursiveLock alloc] init];
83 }
84
85 return self;
86}
87
88- (StatisticsCallback)getStatisticsCallback {
89 return _statisticsCallback;
90}
91
92- (NSArray*)getAllStatisticsWithTimeout:(int)waitTimeout {
93 [self waitForAsynchronousMessagesInTransmit:waitTimeout];
94
95 if ([self thereAreAsynchronousMessagesInTransmit]) {
96 NSLog(@"getAllStatisticsWithTimeout was called to return all statistics but there are still statistics being transmitted for session id %ld.", [self getSessionId]);
97 }
98
99 return [self getStatistics];
100}
101
102- (NSArray*)getAllStatistics {
103 return [self getAllStatisticsWithTimeout:AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit];
104}
105
106- (NSArray*)getStatistics {
107 [_statisticsLock lock];
108 NSArray* statisticsCopy = [_statistics copy];
109 [_statisticsLock unlock];
110
111 return statisticsCopy;
112}
113
114- (Statistics*)getLastReceivedStatistics {
115 Statistics* lastStatistics = nil;
116
117 [_statisticsLock lock];
118 if ([_statistics count] > 0) {
119 lastStatistics = [_statistics objectAtIndex:[_statistics count] - 1];
120 }
121 [_statisticsLock unlock];
122
123 return lastStatistics;
124}
125
126- (void)addStatistics:(Statistics*)statistics {
127 [_statisticsLock lock];
128 [_statistics addObject:statistics];
129 [_statisticsLock unlock];
130}
131
132- (BOOL)isFFmpeg {
133 return true;
134}
135
136- (BOOL)isFFprobe {
137 return false;
138}
139
140@end
141
ExecuteCallback.h
ExecuteCallback
void(^ ExecuteCallback)(id< Session > session)
Definition: ExecuteCallback.h:46
FFmpegKitConfig.h
statisticsCallback
static StatisticsCallback statisticsCallback
Definition: FFmpegKitConfig.m:67
FFmpegSession.h
_statisticsLock
NSRecursiveLock * _statisticsLock
Definition: FFmpegSession.m:29
_statistics
NSMutableArray * _statistics
Definition: FFmpegSession.m:26
LogCallback.h
LogCallback
void(^ LogCallback)(Log *log)
Definition: LogCallback.h:31
StatisticsCallback.h
StatisticsCallback
void(^ StatisticsCallback)(Statistics *statistics)
Definition: StatisticsCallback.h:31
FFmpegKitConfig
Definition: FFmpegKitConfig.h:50
+[FFmpegKitConfig getLogRedirectionStrategy]
LogRedirectionStrategy getLogRedirectionStrategy()
Definition: FFmpegKitConfig.m:1134
FFmpegSession
Definition: FFmpegSession.h:31
Statistics
Definition: Statistics.h:29