[vlc-devel] [PATCH v3 14/14] record: avoid pointless file creation for probing
Lyndon Brown
jnqnfe at gmail.com
Wed Oct 14 04:57:14 CEST 2020
From: Lyndon Brown <jnqnfe at gmail.com>
Date: Wed, 14 Oct 2020 02:51:14 +0100
Subject: record: avoid pointless file creation for probing
when probing muxers we don't really need the temporary file to exist in the
filesystem, we can use vlc_memfd() and pass along the file descriptor for
duplication in the file access module.
OutputNew() takes a new 'fd' param, and when probing we use that to pass
in the FD returned by vlc_memfd(), with a NULL for the path. Otherwise we
provide a path and -1 for 'fd'. If 'fd' is -1 it uses 'file' as the access
module and the specified path. If 'fd' is not -1, it uses the FD converted
to a string as the path and 'fd' as the access module. (same module,
different shortcut, which just triggers FD mode via the different access
name).
diff --git a/modules/stream_out/record.c b/modules/stream_out/record.c
index 53cc812069..6c8a758ea5 100644
--- a/modules/stream_out/record.c
+++ b/modules/stream_out/record.c
@@ -314,31 +314,45 @@ static const muxer_properties_t p_muxers[] = {
};
#undef M
-static int OutputNew( sout_stream_t *p_stream,
- const char *psz_muxer, const char *psz_prefix, const char *psz_extension )
+static int OutputNew( sout_stream_t *p_stream, const char *psz_muxer, int fd,
+ const char *psz_prefix, const char *psz_extension )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
char *psz_file = NULL, *psz_tmp = NULL;
char *psz_output = NULL;
+ const char *access = NULL;
int i_count;
- if( asprintf( &psz_tmp, "%s%s%s",
- psz_prefix, psz_extension ? "." : "", psz_extension ? psz_extension : "" ) < 0 )
+ if (fd != -1)
{
- goto error;
+ access = "fd";
+ if( asprintf(&psz_file, "%d", fd) < 0 )
+ {
+ goto error;
+ }
}
-
- psz_file = config_StringEscape( psz_tmp );
- if( !psz_file )
+ else
{
+ access = "file";
+
+ if( asprintf( &psz_tmp, "%s%s%s",
+ psz_prefix, psz_extension ? "." : "", psz_extension ? psz_extension : "" ) < 0 )
+ {
+ goto error;
+ }
+
+ psz_file = config_StringEscape( psz_tmp );
+ if( !psz_file )
+ {
+ free( psz_tmp );
+ goto error;
+ }
free( psz_tmp );
- goto error;
}
- free( psz_tmp );
if( asprintf( &psz_output,
- "std{access=file{no-append,no-format,no-overwrite},"
- "mux=%s,dst='%s'}", psz_muxer, psz_file ) < 0 )
+ "std{access=%s{no-append,no-format,no-overwrite},"
+ "mux=%s,dst='%s'}", access, psz_muxer, psz_file ) < 0 )
{
psz_output = NULL;
goto error;
@@ -464,10 +478,9 @@ static void OutputStart( sout_stream_t *p_stream )
msg_Warn( p_stream, "failed to find an adequate muxer, probing muxers" );
for( unsigned i = 0; i < sizeof(ppsz_muxers) / sizeof(*ppsz_muxers); i++ )
{
- char *psz_file;
int i_es;
- int fd = vlc_MakeTmpFile(&psz_file, PACKAGE_NAME"-rec.");
+ int fd = vlc_memfd();
if( fd == -1 )
{
msg_Warn( p_stream, "failed to create temporary file" );
@@ -475,15 +488,11 @@ static void OutputStart( sout_stream_t *p_stream )
}
msg_Dbg( p_stream, "probing muxer %s", ppsz_muxers[i][0] );
- i_es = OutputNew( p_stream, ppsz_muxers[i][0], psz_file, NULL );
+ i_es = OutputNew( p_stream, ppsz_muxers[i][0], fd, NULL, NULL );
+ vlc_close( fd );
if( i_es < 0 )
- {
- vlc_unlink( psz_file );
- free( psz_file );
- vlc_close( fd );
continue;
- }
/* */
for( int j = 0; j < p_sys->i_id; j++ )
@@ -506,9 +515,6 @@ static void OutputStart( sout_stream_t *p_stream )
if( i_best_es >= p_sys->i_id )
break;
}
- vlc_unlink( psz_file );
- free( psz_file );
- vlc_close( fd );
}
/* */
@@ -519,7 +525,7 @@ static void OutputStart( sout_stream_t *p_stream )
}
/* Create the output */
- if( OutputNew( p_stream, psz_muxer, p_sys->psz_prefix, psz_extension ) < 0 )
+ if( OutputNew( p_stream, psz_muxer, -1, p_sys->psz_prefix, psz_extension ) < 0 )
{
msg_Err( p_stream, "failed to open output");
return;
More information about the vlc-devel
mailing list