Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Feat add clear individual session #1067

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apple/src/FFmpegKitConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ typedef NS_ENUM(NSUInteger, Signal) {
*/
+ (NSArray*)getSessions;

/**
* <p>Clears the session specified with <code>sessionId</code> from the session history.
* <p>Note that callbacks cannot be triggered for deleted sessions.
*
* @param sessionId session identifier
*/
+ (void)clearSession:(long)sessionId;

/**
* <p>Clears all, including ongoing, sessions in the session history.
* <p>Note that callbacks cannot be triggered for deleted sessions.
Expand Down
11 changes: 11 additions & 0 deletions apple/src/FFmpegKitConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,17 @@ + (NSArray*)getSessions {
return sessionsCopy;
}

+ (void)clearSession:(long)sessionId {
[sessionHistoryLock lock];
id<Session> session = [self getSession:sessionId];
if (session != nil) {
[sessionHistoryList removeObject:session];
[sessionHistoryMap removeObjectForKey:[NSNumber numberWithLong:sessionId]];
}

[sessionHistoryLock unlock];
}

+ (void)clearSessions {
[sessionHistoryLock lock];

Expand Down
11 changes: 11 additions & 0 deletions flutter/flutter/ios/Classes/FFmpegKitFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
[self getSessions:result];
} else if ([@"clearSessions" isEqualToString:call.method]) {
[self clearSessions:result];
} else if ([@"clearSession" isEqualToString:call.method]) {
if (sessionId != nil) {
[self clearSession:sessionId result:result];
} else {
result([FlutterError errorWithCode:@"INVALID_SESSION" message:@"Invalid session id." details:nil]);
}
} else if ([@"getSessionsByState" isEqualToString:call.method]) {
NSNumber* stateIndex = call.arguments[@"state"];
if (stateIndex != nil) {
Expand Down Expand Up @@ -909,6 +915,11 @@ - (void)getSessions:(FlutterResult)result {
result([FFmpegKitFlutterPlugin toSessionArray:[FFmpegKitConfig getSessions]]);
}

- (void)clearSession:(NSNumber*)sessionId result:(FlutterResult)result {
[FFmpegKitConfig clearSession:[sessionId longValue]];
result(nil);
}

- (void)clearSessions:(FlutterResult)result {
[FFmpegKitConfig clearSessions];
result(nil);
Expand Down
12 changes: 12 additions & 0 deletions flutter/flutter/lib/ffmpeg_kit_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,18 @@ class FFmpegKitConfig {
}
}

/// Deletes a session from the session history.
/// Note that callbacks cannot be triggered for deleted sessions.
static Future<void> clearSession(int sessionId) async {
try {
await init();
return _platform.clearSession(sessionId);
} on PlatformException catch (e, stack) {
print("Plugin clearSession error: ${e.message}");
return Future.error("clearSession failed.", stack);
}
}

/// Clears all, including ongoing, sessions in the session history.
/// Note that callbacks cannot be triggered for deleted sessions.
static Future<void> clearSessions() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ abstract class FFmpegKitPlatform extends PlatformInterface {
'ffmpegKitConfigGetSessions() has not been implemented!');
}

Future<void> clearSession(int sessionId) async {
throw UnimplementedError('clearSession() has not been implemented!');
}

Future<void> clearSessions() async {
throw UnimplementedError('clearSessions() has not been implemented!');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ class MethodChannelFFmpegKit extends FFmpegKitPlatform {
Future<List<dynamic>?> ffmpegKitConfigGetSessions() async =>
_channel.invokeMethod<List<dynamic>>('getSessions');

@override
Future<void> clearSession(int sessionId) async =>
_channel.invokeMethod<void>('clearSession', {'sessionId': sessionId});

@override
Future<void> clearSessions() async =>
_channel.invokeMethod<void>('clearSessions');
Expand Down