FFmpegKit iOS / macOS / tvOS API 5.1
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 "FFmpegSession.h"
21#import "FFmpegKitConfig.h"
22#import "LogCallback.h"
24
25@implementation FFmpegSession {
26 StatisticsCallback _statisticsCallback;
28 NSMutableArray* _statistics;
29 NSRecursiveLock* _statisticsLock;
30}
31
32+ (void)initialize {
33 // EMPTY INITIALIZE
34}
35
36+ (instancetype)create:(NSArray*)arguments {
37 return [[self alloc] init:arguments withCompleteCallback:nil withLogCallback:nil withStatisticsCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
38}
39
40+ (instancetype)create:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback {
41 return [[self alloc] init:arguments withCompleteCallback:completeCallback withLogCallback:nil withStatisticsCallback:nil withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
42}
43
44+ (instancetype)create:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback {
45 return [[self alloc] init:arguments withCompleteCallback:completeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback withLogRedirectionStrategy:[FFmpegKitConfig getLogRedirectionStrategy]];
46}
47
48+ (instancetype)create:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy {
49 return [[self alloc] init:arguments withCompleteCallback:completeCallback withLogCallback:logCallback withStatisticsCallback:statisticsCallback withLogRedirectionStrategy:logRedirectionStrategy];
50}
51
52- (instancetype)init:(NSArray*)arguments withCompleteCallback:(FFmpegSessionCompleteCallback)completeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback withLogRedirectionStrategy:(LogRedirectionStrategy)logRedirectionStrategy {
53
54 self = [super init:arguments withLogCallback:logCallback withLogRedirectionStrategy:logRedirectionStrategy];
55
56 if (self) {
57 _statisticsCallback = statisticsCallback;
58 _completeCallback = completeCallback;
59 _statistics = [[NSMutableArray alloc] init];
60 _statisticsLock = [[NSRecursiveLock alloc] init];
61 }
62
63 return self;
64}
65
66- (StatisticsCallback)getStatisticsCallback {
67 return _statisticsCallback;
68}
69
70- (FFmpegSessionCompleteCallback)getCompleteCallback {
71 return _completeCallback;
72}
73
74- (NSArray*)getAllStatisticsWithTimeout:(int)waitTimeout {
75 [self waitForAsynchronousMessagesInTransmit:waitTimeout];
76
77 if ([self thereAreAsynchronousMessagesInTransmit]) {
78 NSLog(@"getAllStatisticsWithTimeout was called to return all statistics but there are still statistics being transmitted for session id %ld.", [self getSessionId]);
79 }
80
81 return [self getStatistics];
82}
83
84- (NSArray*)getAllStatistics {
85 return [self getAllStatisticsWithTimeout:AbstractSessionDefaultTimeoutForAsynchronousMessagesInTransmit];
86}
87
88- (NSArray*)getStatistics {
89 [_statisticsLock lock];
90 NSArray* statisticsCopy = [_statistics copy];
91 [_statisticsLock unlock];
92
93 return statisticsCopy;
94}
95
96- (Statistics*)getLastReceivedStatistics {
97 Statistics* lastStatistics = nil;
98
99 [_statisticsLock lock];
100 if ([_statistics count] > 0) {
101 lastStatistics = [_statistics objectAtIndex:[_statistics count] - 1];
102 }
103 [_statisticsLock unlock];
104
105 return lastStatistics;
106}
107
108- (void)addStatistics:(Statistics*)statistics {
109 [_statisticsLock lock];
110 [_statistics addObject:statistics];
111 [_statisticsLock unlock];
112}
113
114- (BOOL)isFFmpeg {
115 return true;
116}
117
118- (BOOL)isFFprobe {
119 return false;
120}
121
122- (BOOL)isMediaInformation {
123 return false;
124}
125
126@end
127
static StatisticsCallback statisticsCallback
FFmpegSessionCompleteCallback _completeCallback
Definition: FFmpegSession.m:27
NSRecursiveLock * _statisticsLock
Definition: FFmpegSession.m:29
NSMutableArray * _statistics
Definition: FFmpegSession.m:28
void(^ FFmpegSessionCompleteCallback)(FFmpegSession *session)
void(^ LogCallback)(Log *log)
Definition: LogCallback.h:31
void(^ StatisticsCallback)(Statistics *statistics)
LogRedirectionStrategy getLogRedirectionStrategy()