+ sout_mux_t *p_mux;
+
+ const char *psz_mux_byext = NULL;
+
+ config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
+ p_stream->p_cfg );
+
+ var_Get( p_stream, SOUT_CFG_PREFIX "access", &val );
+ psz_access = *val.psz_string ? val.psz_string : NULL;
+ if( !*val.psz_string ) free( val.psz_string );
+
+ var_Get( p_stream, SOUT_CFG_PREFIX "mux", &val );
+ psz_mux = *val.psz_string ? val.psz_string : NULL;
+ if( !*val.psz_string ) free( val.psz_string );
+
+ var_Get( p_stream, SOUT_CFG_PREFIX "dst", &val );
+ psz_url = *val.psz_string ? val.psz_string : NULL;
+ if( !*val.psz_string ) free( val.psz_string );
+
+ p_sys = p_stream->p_sys = malloc( sizeof( sout_stream_sys_t) );
+ if( !p_sys ) return VLC_ENOMEM;
+ p_stream->p_sys->p_session = NULL;
+
+ msg_Dbg( p_this, "creating `%s/%s://%s'", psz_access, psz_mux, psz_url );
+
+ /* ext -> muxer name */
+ if( psz_url && strrchr( psz_url, '.' ) )
+ {
+ /* by extension */
+ static struct { const char ext[6]; const char mux[32]; } exttomux[] =
+ {
+ { "avi", "avi" },
+ { "ogg", "ogg" },
+ { "ogm", "ogg" },
+ { "mp4", "mp4" },
+ { "mov", "mov" },
+ { "moov","mov" },
+ { "asf", "asf" },
+ { "wma", "asf" },
+ { "wmv", "asf" },
+ { "trp", "ts" },
+ { "ts", "ts" },
+ { "mpg", "ps" },
+ { "mpeg","ps" },
+ { "ps", "ps" },
+ { "mpeg1","mpeg1" },
+ { "wav", "wav" },
+ { "flv", "ffmpeg{mux=flv}" },
+ { "mkv", "ffmpeg{mux=matroska}"},
+ { "", "" }
+ };
+ const char *psz_ext = strrchr( psz_url, '.' ) + 1;
+ int i;
+
+ msg_Dbg( p_this, "extension is %s", psz_ext );
+ for( i = 0; exttomux[i].ext[0]; i++ )
+ {
+ if( !strcasecmp( psz_ext, exttomux[i].ext ) )
+ {
+ psz_mux_byext = exttomux[i].mux;
+ break;
+ }
+ }
+ msg_Dbg( p_this, "extension -> mux=%s", psz_mux_byext );
+ }
+
+ /* We fix access/mux to valid couple */
+
+ if( !psz_access && !psz_mux )
+ {
+ if( psz_mux_byext )
+ {
+ msg_Warn( p_stream,
+ "no access _and_ no muxer, extension gives file/%s",
+ psz_mux_byext );
+ psz_access = strdup("file");
+ psz_mux = strdup(psz_mux_byext);
+ }
+ else
+ {
+ msg_Err( p_stream, "no access _and_ no muxer (fatal error)" );
+ return VLC_EGENERIC;
+ }
+ }
+
+ if( psz_access && !psz_mux )
+ {
+ /* access given, no mux */
+ if( !strncmp( psz_access, "mmsh", 4 ) )
+ {
+ psz_mux = strdup("asfh");
+ }
+ else if (!strcmp (psz_access, "udp")
+ || !strcmp (psz_access, "rtp"))
+ {
+ psz_mux = strdup("ts");
+ }
+ else if( psz_mux_byext )
+ {
+ psz_mux = strdup(psz_mux_byext);
+ }
+ else
+ {
+ msg_Err( p_stream, "no mux specified or found by extension" );
+ return VLC_EGENERIC;
+ }
+ }
+ else if( psz_mux && !psz_access )
+ {
+ /* mux given, no access */
+ if( !strncmp( psz_mux, "asfh", 4 ) )
+ {
+ psz_access = strdup("mmsh");
+ }
+ else
+ {
+ /* default file */
+ psz_access = strdup("file");
+ }
+ }