create pipes under the pipes directory

This commit is contained in:
Taner Sener 2021-01-24 19:41:34 +00:00
parent 18a6a9c066
commit 2af487818a
2 changed files with 24 additions and 8 deletions

View File

@ -509,10 +509,19 @@ public class FFmpegKitConfig {
*/
public static String registerNewFFmpegPipe(final Context context) {
// PIPES ARE CREATED UNDER THE CACHE DIRECTORY
// PIPES ARE CREATED UNDER THE PIPES DIRECTORY
final File cacheDir = context.getCacheDir();
final File pipesDir = new File(cacheDir, "pipes");
final String newFFmpegPipePath = MessageFormat.format("{0}{1}{2}{3}", cacheDir, File.separator, FFMPEG_KIT_NAMED_PIPE_PREFIX, pipeIndexGenerator.getAndIncrement());
if (!pipesDir.exists()) {
final boolean pipesDirCreated = pipesDir.mkdirs();
if (!pipesDirCreated) {
android.util.Log.e(TAG, String.format("Failed to create pipes directory: %s.", pipesDir.getAbsolutePath()));
return null;
}
}
final String newFFmpegPipePath = MessageFormat.format("{0}{1}{2}{3}", pipesDir, File.separator, FFMPEG_KIT_NAMED_PIPE_PREFIX, pipeIndexGenerator.getAndIncrement());
// FIRST CLOSE OLD PIPES WITH THE SAME NAME
closeFFmpegPipe(newFFmpegPipePath);

View File

@ -916,11 +916,21 @@ void callbackBlockFunction() {
* @return the full path of named pipe
*/
+ (NSString*)registerNewFFmpegPipe {
NSError *error = nil;
BOOL isDirectory;
// PIPES ARE CREATED UNDER THE CACHE DIRECTORY
// PIPES ARE CREATED UNDER THE PIPES DIRECTORY
NSString *cacheDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pipesDir = [cacheDir stringByAppendingPathComponent:@"pipes"];
NSString *newFFmpegPipePath = [NSString stringWithFormat:@"%@/%@%d", cacheDir, FFMPEG_KIT_PIPE_PREFIX, (++lastCreatedPipeIndex)];
if (![[NSFileManager defaultManager] fileExistsAtPath:pipesDir isDirectory:&isDirectory]) {
if (![[NSFileManager defaultManager] createDirectoryAtPath:pipesDir withIntermediateDirectories:YES attributes:nil error:&error]) {
NSLog(@"Failed to create pipes directory: %@. Operation failed with %@.", pipesDir, error);
return nil;
}
}
NSString *newFFmpegPipePath = [NSString stringWithFormat:@"%@/%@%d", pipesDir, FFMPEG_KIT_PIPE_PREFIX, (++lastCreatedPipeIndex)];
// FIRST CLOSE OLD PIPES WITH THE SAME NAME
[FFmpegKitConfig closeFFmpegPipe:newFFmpegPipePath];
@ -929,10 +939,7 @@ void callbackBlockFunction() {
if (rc == 0) {
return newFFmpegPipePath;
} else {
int activeLogLevel = av_log_get_level();
if ((activeLogLevel != AV_LOG_QUIET) && (AV_LOG_WARNING <= activeLogLevel)) {
NSLog(@"Failed to register new FFmpeg pipe %@. Operation failed with rc=%d.", newFFmpegPipePath, rc);
}
NSLog(@"Failed to register new FFmpeg pipe %@. Operation failed with rc=%d.", newFFmpegPipePath, rc);
return nil;
}
}