[vlc-devel] [PATCH 3/5] strings: add an input_item_t arg to vlc_strfinput()
Thomas Guillem
thomas at gllm.fr
Thu Jul 19 15:50:18 CEST 2018
That way, this helper can be used with just an input_item_t. Few formats won't
be able to work without the input_thread_t, like rate for example.
---
include/vlc_strings.h | 7 ++++---
modules/gui/macosx/VLCCoreInteraction.m | 2 +-
modules/gui/macosx/VLCMainWindow.m | 2 +-
modules/gui/qt/input_manager.cpp | 2 +-
modules/gui/skins2/src/vlcproc.cpp | 2 +-
src/input/input.c | 2 +-
src/text/strings.c | 7 ++++---
src/video_output/snapshot.c | 2 +-
8 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/include/vlc_strings.h b/include/vlc_strings.h
index af5df4f6d6..3f0c169e68 100644
--- a/include/vlc_strings.h
+++ b/include/vlc_strings.h
@@ -139,12 +139,13 @@ VLC_API char *vlc_strftime( const char * );
*
* Formats input and input item meta-informations into a heap-allocated string.
*/
-VLC_API char *vlc_strfinput( input_thread_t *, const char * );
+VLC_API char *vlc_strfinput( input_thread_t *, input_item_t *, const char * );
-static inline char *str_format( input_thread_t *input, const char *fmt )
+static inline char *str_format( input_thread_t *input, input_item_t *item,
+ const char *fmt )
{
char *s1 = vlc_strftime( fmt );
- char *s2 = vlc_strfinput( input, s1 );
+ char *s2 = vlc_strfinput( input, item, s1 );
free( s1 );
return s2;
}
diff --git a/modules/gui/macosx/VLCCoreInteraction.m b/modules/gui/macosx/VLCCoreInteraction.m
index ce66f8df23..f127844b57 100644
--- a/modules/gui/macosx/VLCCoreInteraction.m
+++ b/modules/gui/macosx/VLCCoreInteraction.m
@@ -320,7 +320,7 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
NSString *o_name = @"";
char *format = var_InheritString(getIntf(), "input-title-format");
if (format) {
- char *formated = vlc_strfinput(p_input, format);
+ char *formated = vlc_strfinput(p_input, NULL, format);
free(format);
o_name = toNSStr(formated);
free(formated);
diff --git a/modules/gui/macosx/VLCMainWindow.m b/modules/gui/macosx/VLCMainWindow.m
index c49af65e18..bcf03eca5f 100644
--- a/modules/gui/macosx/VLCMainWindow.m
+++ b/modules/gui/macosx/VLCMainWindow.m
@@ -587,7 +587,7 @@ static const float f_min_window_height = 307.;
if (!config_GetPsz("video-title")) {
char *format = var_InheritString(getIntf(), "input-title-format");
if (format) {
- char *formated = vlc_strfinput(p_input, format);
+ char *formated = vlc_strfinput(p_input, NULL, format);
free(format);
aString = toNSStr(formated);
free(formated);
diff --git a/modules/gui/qt/input_manager.cpp b/modules/gui/qt/input_manager.cpp
index 98e3f81f22..e191b0dcfc 100644
--- a/modules/gui/qt/input_manager.cpp
+++ b/modules/gui/qt/input_manager.cpp
@@ -520,7 +520,7 @@ void InputManager::UpdateName()
char *formatted = NULL;
if (format != NULL)
{
- formatted = vlc_strfinput( p_input, format );
+ formatted = vlc_strfinput( p_input, NULL, format );
free( format );
if( formatted != NULL )
{
diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp
index d9a050f980..ba2fdf3211 100644
--- a/modules/gui/skins2/src/vlcproc.cpp
+++ b/modules/gui/skins2/src/vlcproc.cpp
@@ -729,7 +729,7 @@ void VlcProc::update_current_input()
char *psz_name = NULL;
if( psz_fmt != NULL )
{
- psz_name = vlc_strfinput( pInput, psz_fmt );
+ psz_name = vlc_strfinput( pInput, NULL, psz_fmt );
free( psz_fmt );
}
diff --git a/src/input/input.c b/src/input/input.c
index 941e3b4f2d..31bee4f4cb 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -3374,7 +3374,7 @@ char *input_CreateFilename(input_thread_t *input, const char *dir,
const char *filenamefmt, const char *ext)
{
char *path;
- char *filename = str_format(input, filenamefmt);
+ char *filename = str_format(input, NULL, filenamefmt);
if (unlikely(filename == NULL))
return NULL;
diff --git a/src/text/strings.c b/src/text/strings.c
index 8ae73d3027..c094d374e4 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -538,18 +538,19 @@ static int write_meta(struct vlc_memstream *stream, input_item_t *item,
return 0;
}
-char *vlc_strfinput(input_thread_t *input, const char *s)
+char *vlc_strfinput(input_thread_t *input, input_item_t *item, const char *s)
{
struct vlc_memstream stream[1];
- input_item_t *item = (input != NULL) ? input_GetItem(input) : NULL;
-
char c;
bool b_is_format = false;
bool b_empty_if_na = false;
assert(s != NULL);
+ if (!item && input)
+ item = input_GetItem(input);
+
vlc_memstream_open(stream);
while ((c = *s) != '\0')
diff --git a/src/video_output/snapshot.c b/src/video_output/snapshot.c
index 35bedad380..8d32ddad95 100644
--- a/src/video_output/snapshot.c
+++ b/src/video_output/snapshot.c
@@ -150,7 +150,7 @@ int vout_snapshot_SaveImage(char **name, int *sequential,
/* */
char *prefix = NULL;
if (cfg->prefix_fmt)
- prefix = str_format(input, cfg->prefix_fmt);
+ prefix = str_format(input, NULL, cfg->prefix_fmt);
if (prefix)
filename_sanitize(prefix);
else {
--
2.18.0
More information about the vlc-devel
mailing list