[vlc-commits] cli: return error code from commands
Rémi Denis-Courmont
git at videolan.org
Sat Nov 21 15:51:32 CET 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 21 11:55:32 2020 +0200| [05e1b15760d2b692da31e6979d4bd09c254e4b65] | committer: Rémi Denis-Courmont
cli: return error code from commands
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=05e1b15760d2b692da31e6979d4bd09c254e4b65
---
modules/control/cli/cli.c | 46 +++++---
modules/control/cli/cli.h | 2 +-
modules/control/cli/player.c | 235 +++++++++++++++++++++++++----------------
modules/control/cli/playlist.c | 134 +++++++++++++----------
4 files changed, 254 insertions(+), 163 deletions(-)
diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c
index c741e7fcad..cf65594ade 100644
--- a/modules/control/cli/cli.c
+++ b/modules/control/cli/cli.c
@@ -146,7 +146,7 @@ void RegisterHandlers(intf_thread_t *intf, const struct cli_handler *handlers,
# include "../intromsg.h"
#endif
-static void Help( intf_thread_t *p_intf, const char *const *args, size_t count)
+static int Help( intf_thread_t *p_intf, const char *const *args, size_t count)
{
msg_rc("%s", _("+----[ Remote control commands ]"));
msg_rc( "| ");
@@ -207,20 +207,22 @@ static void Help( intf_thread_t *p_intf, const char *const *args, size_t count)
msg_rc( "| ");
msg_rc("%s", _("+----[ end of help ]"));
(void) args; (void) count;
+ return 0;
}
-static void Intf(intf_thread_t *intf, const char *const *args, size_t count)
+static int Intf(intf_thread_t *intf, const char *const *args, size_t count)
{
- intf_Create(vlc_object_instance(intf), count == 1 ? "" : args[1]);
+ return intf_Create(vlc_object_instance(intf), count == 1 ? "" : args[1]);
}
-static void Quit(intf_thread_t *intf, const char *const *args, size_t count)
+static int Quit(intf_thread_t *intf, const char *const *args, size_t count)
{
libvlc_Quit(vlc_object_instance(intf));
(void) args; (void) count;
+ return 0;
}
-static void LogOut(intf_thread_t *intf, const char *const *args, size_t count)
+static int LogOut(intf_thread_t *intf, const char *const *args, size_t count)
{
intf_sys_t *sys = intf->p_sys;
@@ -255,14 +257,18 @@ static void LogOut(intf_thread_t *intf, const char *const *args, size_t count)
}
#endif
(void) args; (void) count;
+ return 0;
}
-static void KeyAction(intf_thread_t *intf, const char *const *args, size_t n)
+static int KeyAction(intf_thread_t *intf, const char *const *args, size_t n)
{
vlc_object_t *vlc = VLC_OBJECT(vlc_object_instance(intf));
- if (n > 1)
- var_SetInteger(vlc, "key-action", vlc_actions_get_id(args[1]));
+ if (n != 1)
+ return VLC_EGENERIC; /* EINVAL */
+
+ var_SetInteger(vlc, "key-action", vlc_actions_get_id(args[1]));
+ return 0;
}
static const struct cli_handler cmds[] =
@@ -280,21 +286,23 @@ static const struct cli_handler cmds[] =
{ "hotkey", KeyAction },
};
-static void UnknownCmd(intf_thread_t *intf, const char *const *args,
+static int UnknownCmd(intf_thread_t *intf, const char *const *args,
size_t count)
{
msg_print(intf, _("Unknown command `%s'. Type `help' for help."), args[0]);
(void) count;
+ return VLC_EGENERIC;
}
-static void Process(intf_thread_t *intf, const char *line)
+static int Process(intf_thread_t *intf, const char *line)
{
intf_sys_t *sys = intf->p_sys;
/* Skip heading spaces */
const char *cmd = line + strspn(line, " ");
+ int ret;
if (*cmd == '\0')
- return; /* Ignore empty line */
+ return 0; /* Ignore empty line */
#ifdef HAVE_WORDEXP
wordexp_t we;
@@ -303,15 +311,24 @@ static void Process(intf_thread_t *intf, const char *line)
if (val != 0)
{
if (val == WRDE_NOSPACE)
+ {
+ ret = VLC_ENOMEM;
error: wordfree(&we);
+ }
+ else
+ ret = VLC_EGENERIC;
+
msg_print(intf, N_("parse error"));
- return;
+ return ret;
}
size_t count = we.we_wordc;
const char **args = vlc_alloc(count, sizeof (*args));
if (unlikely(args == NULL))
+ {
+ ret = VLC_ENOMEM;
goto error;
+ }
for (size_t i = 0; i < we.we_wordc; i++)
args[i] = we.we_wordv[i];
@@ -334,19 +351,20 @@ error: wordfree(&we);
if (count > 0)
{
- void (*cb)(intf_thread_t *, const char *const *, size_t) = UnknownCmd;
+ int (*cb)(intf_thread_t *, const char *const *, size_t) = UnknownCmd;
const struct cli_handler **h = tfind(&args[0], &sys->commands, cmdcmp);
if (h != NULL)
cb = (*h)->callback;
- cb(intf, args, count);
+ ret = cb(intf, args, count);
}
#ifdef HAVE_WORDEXP
free(args);
wordfree(&we);
#endif
+ return ret;
}
#ifndef _WIN32
diff --git a/modules/control/cli/cli.h b/modules/control/cli/cli.h
index ae2dedc5c1..b4a010d633 100644
--- a/modules/control/cli/cli.h
+++ b/modules/control/cli/cli.h
@@ -56,7 +56,7 @@ void msg_print(intf_thread_t *p_intf, const char *psz_fmt, ...);
struct cli_handler
{
const char *name;
- void (*callback)(intf_thread_t *intf, const char *const *, size_t);
+ int (*callback)(intf_thread_t *intf, const char *const *, size_t);
};
void RegisterHandlers(intf_thread_t *intf, const struct cli_handler *handlers,
diff --git a/modules/control/cli/player.c b/modules/control/cli/player.c
index c4807a3880..72d28c04f5 100644
--- a/modules/control/cli/player.c
+++ b/modules/control/cli/player.c
@@ -158,7 +158,7 @@ static const struct vlc_player_aout_cbs player_aout_cbs =
.on_volume_changed = player_aout_on_volume_changed,
};
-static void PlayerDoVoid(intf_thread_t *intf, void (*cb)(vlc_player_t *))
+static int PlayerDoVoid(intf_thread_t *intf, void (*cb)(vlc_player_t *))
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
@@ -166,33 +166,43 @@ static void PlayerDoVoid(intf_thread_t *intf, void (*cb)(vlc_player_t *))
vlc_player_Lock(player);
cb(player);
vlc_player_Unlock(player);
+ return 0;
}
-static void PlayerDoFloat(intf_thread_t *intf, const char *const *args,
- size_t count,
- void (*setter)(vlc_player_t *, float),
- float (*getter)(vlc_player_t *))
+static int PlayerDoFloat(intf_thread_t *intf, const char *const *args,
+ size_t count,
+ void (*setter)(vlc_player_t *, float),
+ float (*getter)(vlc_player_t *))
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
+ int ret = 0;
vlc_player_Lock(player);
- if (count < 2)
- msg_print(intf, "%f", getter(player));
- else
- setter(player, atof(args[1]));
+ switch (count)
+ {
+ case 1:
+ msg_print(intf, "%f", getter(player));
+ break;
+ case 2:
+ setter(player, atof(args[1]));
+ break;
+ default:
+ ret = VLC_EGENERIC; /* EINVAL */
+ }
vlc_player_Unlock(player);
+ return ret;
}
-static void PlayerPause(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerPause(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlayerDoVoid(intf, vlc_player_TogglePause);
(void) args; (void) count;
+ return PlayerDoVoid(intf, vlc_player_TogglePause);
}
-static void PlayerFastForward(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerFastForward(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
@@ -213,9 +223,10 @@ static void PlayerFastForward(intf_thread_t *intf, const char *const *args,
}
vlc_player_Unlock(player);
(void) args; (void) count;
+ return 0;
}
-static void PlayerRewind(intf_thread_t *intf, const char *const *args,
+static int PlayerRewind(intf_thread_t *intf, const char *const *args,
size_t count)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
@@ -236,20 +247,21 @@ static void PlayerRewind(intf_thread_t *intf, const char *const *args,
}
vlc_player_Unlock(player);
(void) args; (void) count;
+ return 0;
}
-static void PlayerFaster(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerFaster(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlayerDoVoid(intf, vlc_player_IncrementRate);
(void) args; (void) count;
+ return PlayerDoVoid(intf, vlc_player_IncrementRate);
}
-static void PlayerSlower(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerSlower(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlayerDoVoid(intf, vlc_player_DecrementRate);
(void) args; (void) count;
+ return PlayerDoVoid(intf, vlc_player_DecrementRate);
}
static void PlayerDoNormal(vlc_player_t *player)
@@ -257,62 +269,63 @@ static void PlayerDoNormal(vlc_player_t *player)
vlc_player_ChangeRate(player, 1.f);
}
-static void PlayerNormal(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerNormal(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlayerDoVoid(intf, PlayerDoNormal);
(void) args; (void) count;
+ return PlayerDoVoid(intf, PlayerDoNormal);
}
-static void PlayerRate(intf_thread_t *intf, const char *const *args, size_t n)
+static int PlayerRate(intf_thread_t *intf, const char *const *args, size_t n)
{
- PlayerDoFloat(intf, args, n, vlc_player_ChangeRate, vlc_player_GetRate);
+ return PlayerDoFloat(intf, args, n, vlc_player_ChangeRate,
+ vlc_player_GetRate);
}
-static void PlayerFrame(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerFrame(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlayerDoVoid(intf, vlc_player_NextVideoFrame);
(void) args; (void) count;
+ return PlayerDoVoid(intf, vlc_player_NextVideoFrame);
}
-static void PlayerChapterPrev(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerChapterPrev(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlayerDoVoid(intf, vlc_player_SelectPrevChapter);
(void) args; (void) count;
+ return PlayerDoVoid(intf, vlc_player_SelectPrevChapter);
}
-static void PlayerChapterNext(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerChapterNext(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlayerDoVoid(intf, vlc_player_SelectNextChapter);
(void) args; (void) count;
+ return PlayerDoVoid(intf, vlc_player_SelectNextChapter);
}
-static void PlayerTitlePrev(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerTitlePrev(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlayerDoVoid(intf, vlc_player_SelectPrevTitle);
(void) args; (void) count;
+ return PlayerDoVoid(intf, vlc_player_SelectPrevTitle);
}
-static void PlayerTitleNext(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerTitleNext(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlayerDoVoid(intf, vlc_player_SelectNextTitle);
(void) args; (void) count;
+ return PlayerDoVoid(intf, vlc_player_SelectNextTitle);
}
-static void PlayerSeek(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerSeek(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
if (count != 2)
{
msg_print(intf, "%s expects one parameter", args[0]);
- return;
+ return VLC_EGENERIC; /* EINVAL */
}
char *end;
@@ -334,12 +347,14 @@ static void PlayerSeek(intf_thread_t *intf, const char *const *args,
else
vlc_player_SetTime(player, vlc_tick_from_sec(value));
vlc_player_Unlock(player);
+ return 0;
}
-static void PlayerSetChapter(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerSetChapter(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
+ int ret = 0;
vlc_player_Lock(player);
@@ -355,15 +370,20 @@ static void PlayerSetChapter(intf_thread_t *intf, const char *const *args,
msg_print(intf, "Currently playing chapter %zd/%zu.",
chapter, title->chapter_count);
else
+ {
msg_print(intf, "No chapter selected.");
+ ret = VLC_ENOITEM;
+ }
}
vlc_player_Unlock(player);
+ return ret;
}
-static void PlayerSetTitle(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerSetTitle(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
+ int ret = 0;
vlc_player_Lock(player);
@@ -385,18 +405,22 @@ static void PlayerSetTitle(intf_thread_t *intf, const char *const *args,
msg_print(intf, "Currently playing title %zd/%zu.", title,
title_count);
else
+ {
msg_print(intf, "No title selected.");
+ ret = VLC_ENOITEM;
+ }
}
vlc_player_Unlock(player);
+ return ret;
}
-static void PlayerSetTrack(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerSetTrack(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
const char *psz_cmd = args[0];
-
enum es_format_category_e cat;
+ int ret = VLC_EGENERIC; /* EINVAL */
switch (psz_cmd[0])
{
@@ -425,7 +449,10 @@ static void PlayerSetTrack(intf_thread_t *intf, const char *const *args,
struct vlc_player_track const *track =
vlc_player_GetTrackAt(player, cat, (size_t)idx);
if (track != NULL)
+ {
vlc_player_SelectTrack(player, track, VLC_PLAYER_SELECT_EXCLUSIVE);
+ ret = 0;
+ }
}
else
{
@@ -443,13 +470,15 @@ static void PlayerSetTrack(intf_thread_t *intf, const char *const *args,
i, track->name, track == cur_track ? " *" : "");
}
msg_print(intf, "+----[ end of %s ]", name);
+ ret = 0;
}
out:
vlc_player_Unlock(player);
+ return ret;
}
-static void PlayerRecord(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerRecord(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
@@ -469,10 +498,11 @@ static void PlayerRecord(intf_thread_t *intf, const char *const *args,
if (cur_value != new_value)
vlc_player_SetRecordingEnabled(player, new_value);
vlc_player_Unlock(player);
+ return 0;
}
-static void PlayerItemInfo(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerItemInfo(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
input_item_t *item;
@@ -499,15 +529,14 @@ static void PlayerItemInfo(intf_thread_t *intf, const char *const *args,
vlc_mutex_unlock(&item->lock);
}
else
- {
msg_print(intf, "no input");
- }
vlc_player_Unlock(player);
(void) args; (void) count;
+ return (item != NULL) ? 0 : VLC_ENOITEM;
}
-static void PlayerGetTime(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerGetTime(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
vlc_tick_t t;
@@ -515,14 +544,16 @@ static void PlayerGetTime(intf_thread_t *intf, const char *const *args,
vlc_player_Lock(player);
t = vlc_player_GetTime(player);
vlc_player_Unlock(player);
- if (t != VLC_TICK_INVALID)
- msg_print(intf, "%"PRIu64, SEC_FROM_VLC_TICK(t));
+ if (t == VLC_TICK_INVALID)
+ return VLC_ENOITEM;
+ msg_print(intf, "%"PRIu64, SEC_FROM_VLC_TICK(t));
(void) args; (void) count;
+ return 0;
}
-static void PlayerGetLength(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerGetLength(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
vlc_tick_t l;
@@ -531,14 +562,16 @@ static void PlayerGetLength(intf_thread_t *intf, const char *const *args,
l = vlc_player_GetLength(player);
vlc_player_Unlock(player);
- if (l != VLC_TICK_INVALID)
- msg_print(intf, "%"PRIu64, SEC_FROM_VLC_TICK(l));
+ if (l == VLC_TICK_INVALID)
+ return VLC_ENOITEM;
+ msg_print(intf, "%"PRIu64, SEC_FROM_VLC_TICK(l));
(void) args; (void) count;
+ return 0;
}
-static void PlayerGetTitle(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerGetTitle(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
const struct vlc_player_title *title;
@@ -548,17 +581,18 @@ static void PlayerGetTitle(intf_thread_t *intf, const char *const *args,
msg_print(intf, "%s", (title != NULL) ? title->name : "");
vlc_player_Unlock(player);
(void) args; (void) count;
+ return (title != NULL) ? 0 : VLC_ENOITEM;
}
-static void PlayerVoutSnapshot(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerVoutSnapshot(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlayerDoVoid(intf, vlc_player_vout_Snapshot);
(void) args; (void) count;
+ return PlayerDoVoid(intf, vlc_player_vout_Snapshot);
}
-static void PlayerFullscreen(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerFullscreen(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
bool fs = !vlc_player_vout_IsFullscreen(player);
@@ -572,9 +606,10 @@ static void PlayerFullscreen(intf_thread_t *intf, const char *const *args,
}
vlc_player_vout_SetFullscreen(player, fs);
+ return 0;
}
-static void Volume(intf_thread_t *intf, const char *const *args, size_t count)
+static int Volume(intf_thread_t *intf, const char *const *args, size_t count)
{
const char *arg = count > 1 ? args[1] : "";
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
@@ -593,10 +628,11 @@ static void Volume(intf_thread_t *intf, const char *const *args, size_t count)
msg_print(intf, STATUS_CHANGE "( audio volume: %ld )", volume);
}
vlc_player_Unlock(player);
+ return 0;
}
-static void VolumeMove(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int VolumeMove(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
const char *psz_cmd = args[0];
@@ -611,10 +647,11 @@ static void VolumeMove(intf_thread_t *intf, const char *const *args,
vlc_player_Lock(player);
vlc_player_aout_IncrementVolume(player, i_nb_steps, &volume);
vlc_player_Unlock(player);
+ return 0;
}
-static void VideoConfig(intf_thread_t *intf, const char *const *args,
- size_t n_args)
+static int VideoConfig(intf_thread_t *intf, const char *const *args,
+ size_t n_args)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
vout_thread_t *p_vout = vlc_player_vout_Hold(player);
@@ -661,7 +698,7 @@ static void VideoConfig(intf_thread_t *intf, const char *const *args,
if( psz_value == NULL )
{
vout_Release(p_vout);
- return;
+ return VLC_ENOVAR;
}
}
@@ -670,7 +707,7 @@ static void VideoConfig(intf_thread_t *intf, const char *const *args,
{
vout_Release(p_vout);
free( psz_value );
- return;
+ return VLC_ENOMEM;
}
/* Get the descriptive name of the variable */
@@ -713,22 +750,28 @@ static void VideoConfig(intf_thread_t *intf, const char *const *args,
free( name );
}
vout_Release(p_vout);
+ return 0;
}
-static void AudioDevice(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int AudioDevice(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
const char *cmd = args[0];
const char *arg = count > 1 ? args[1] : "";
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
audio_output_t *aout = vlc_player_aout_Hold(player);
+ int ret = 0;
+
if (aout == NULL)
- return;
+ return VLC_ENOOBJ;
char **ids, **names;
int n = aout_DevicesList(aout, &ids, &names);
if (n < 0)
+ {
+ ret = VLC_ENOMEM;
goto out;
+ }
bool setdev = count > 1;
if (setdev)
@@ -771,17 +814,20 @@ static void AudioDevice(intf_thread_t *intf, const char *const *args,
free(names);
out:
aout_Release(aout);
+ return ret;
}
-static void AudioChannel(intf_thread_t *intf, const char *const *args,
- size_t n_args)
+static int AudioChannel(intf_thread_t *intf, const char *const *args,
+ size_t n_args)
{
const char *cmd = args[0];
const char *arg = n_args > 1 ? args[1] : "";
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
audio_output_t *p_aout = vlc_player_aout_Hold(player);
+ int ret = 0;
+
if ( p_aout == NULL )
- return;
+ return VLC_ENOOBJ;
if ( !*arg )
{
@@ -792,7 +838,10 @@ static void AudioChannel(intf_thread_t *intf, const char *const *args,
if ( var_Change( p_aout, "stereo-mode", VLC_VAR_GETCHOICES,
&count, &val, &text ) < 0 )
+ {
+ ret = VLC_ENOVAR;
goto out;
+ }
int i_value = var_GetInteger( p_aout, "stereo-mode" );
@@ -815,10 +864,11 @@ static void AudioChannel(intf_thread_t *intf, const char *const *args,
var_SetInteger(p_aout, "stereo-mode", atoi(arg));
out:
aout_Release(p_aout);
+ return ret;
}
-static void Statistics(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int Statistics(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
input_item_t *item;
@@ -874,10 +924,11 @@ static void Statistics(intf_thread_t *intf, const char *const *args,
}
vlc_player_Unlock(player);
(void) args; (void) count;
+ return (item != NULL) ? 0 : VLC_ENOITEM;
}
-static void IsPlaying(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int IsPlaying(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
intf_sys_t *sys = intf->p_sys;
vlc_player_t *player = vlc_playlist_GetPlayer(sys->playlist);
@@ -889,10 +940,11 @@ static void IsPlaying(intf_thread_t *intf, const char *const *args,
|| state == VLC_PLAYER_STATE_PAUSED);
vlc_player_Unlock(player);
(void) args; (void) count;
+ return 0;
}
-static void PlayerStatus(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlayerStatus(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
@@ -943,6 +995,7 @@ static void PlayerStatus(intf_thread_t *intf, const char *const *args,
msg_print(intf, STATUS_CHANGE "( %s state: %u )", stname, stnum);
(void) args; (void) count;
+ return 0;
}
static const struct cli_handler cmds[] =
diff --git a/modules/control/cli/playlist.c b/modules/control/cli/playlist.c
index 5f31c5aeac..20881b502d 100644
--- a/modules/control/cli/playlist.c
+++ b/modules/control/cli/playlist.c
@@ -162,34 +162,36 @@ static void print_playlist(intf_thread_t *p_intf, vlc_playlist_t *playlist)
}
}
-static void PlaylistDoVoid(intf_thread_t *intf, int (*cb)(vlc_playlist_t *))
+static int PlaylistDoVoid(intf_thread_t *intf, int (*cb)(vlc_playlist_t *))
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
+ int ret;
vlc_playlist_Lock(playlist);
- cb(playlist);
+ ret = cb(playlist);
vlc_playlist_Unlock(playlist);
+ return ret;
}
-static void PlaylistPrev(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistPrev(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlaylistDoVoid(intf, vlc_playlist_Prev);
(void) args; (void) count;
+ return PlaylistDoVoid(intf, vlc_playlist_Prev);
}
-static void PlaylistNext(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistNext(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlaylistDoVoid(intf, vlc_playlist_Next);
(void) args; (void) count;
+ return PlaylistDoVoid(intf, vlc_playlist_Next);
}
-static void PlaylistPlay(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistPlay(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlaylistDoVoid(intf, vlc_playlist_Start);
(void) args; (void) count;
+ return PlaylistDoVoid(intf, vlc_playlist_Start);
}
static int PlaylistDoStop(vlc_playlist_t *playlist)
@@ -198,25 +200,25 @@ static int PlaylistDoStop(vlc_playlist_t *playlist)
return 0;
}
-static void PlaylistStop(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistStop(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlaylistDoVoid(intf, PlaylistDoStop);
(void) args; (void) count;
+ return PlaylistDoVoid(intf, PlaylistDoStop);
}
static int PlaylistDoClear(vlc_playlist_t *playlist)
{
- PlaylistDoStop(playlist);
+ vlc_playlist_Stop(playlist);
vlc_playlist_Clear(playlist);
return 0;
}
-static void PlaylistClear(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistClear(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlaylistDoVoid(intf, PlaylistDoClear);
(void) args; (void) count;
+ return PlaylistDoVoid(intf, PlaylistDoClear);
}
static int PlaylistDoSort(vlc_playlist_t *playlist)
@@ -230,15 +232,15 @@ static int PlaylistDoSort(vlc_playlist_t *playlist)
return vlc_playlist_Sort(playlist, &criteria, 1);
}
-static void PlaylistSort(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistSort(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlaylistDoVoid(intf, PlaylistDoSort);
(void) args; (void) count;
+ return PlaylistDoVoid(intf, PlaylistDoSort);
}
-static void PlaylistList(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistList(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
@@ -248,11 +250,12 @@ static void PlaylistList(intf_thread_t *intf, const char *const *args,
vlc_playlist_Unlock(playlist);
msg_print(intf, "+----[ End of playlist ]");
(void) args; (void) count;
+ return 0;
}
-static void PlaylistRepeatCommon(intf_thread_t *intf, const char *const *args,
- size_t count,
- enum vlc_playlist_playback_repeat on_mode)
+static int PlaylistRepeatCommon(intf_thread_t *intf, const char *const *args,
+ size_t count,
+ enum vlc_playlist_playback_repeat on_mode)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
@@ -280,23 +283,25 @@ static void PlaylistRepeatCommon(intf_thread_t *intf, const char *const *args,
vlc_playlist_SetPlaybackRepeat(playlist, new_mode);
vlc_playlist_Unlock(playlist);
+ return 0;
}
-static void PlaylistRepeat(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistRepeat(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlaylistRepeatCommon(intf, args, count,
- VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT);
+ return PlaylistRepeatCommon(intf, args, count,
+ VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT);
}
-static void PlaylistLoop(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistLoop(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlaylistRepeatCommon(intf, args, count, VLC_PLAYLIST_PLAYBACK_REPEAT_ALL);
+ return PlaylistRepeatCommon(intf, args, count,
+ VLC_PLAYLIST_PLAYBACK_REPEAT_ALL);
}
-static void PlaylistRandom(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistRandom(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
@@ -323,10 +328,11 @@ static void PlaylistRandom(intf_thread_t *intf, const char *const *args,
vlc_playlist_SetPlaybackOrder(playlist, new_mode);
vlc_playlist_Unlock(playlist);
+ return 0;
}
-static void PlaylistGoto(intf_thread_t *intf, const char *const *args,
- size_t n_args)
+static int PlaylistGoto(intf_thread_t *intf, const char *const *args,
+ size_t n_args)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
const char *arg = n_args > 1 ? args[1] : "";
@@ -334,24 +340,26 @@ static void PlaylistGoto(intf_thread_t *intf, const char *const *args,
vlc_playlist_Lock(playlist);
- size_t count = vlc_playlist_Count(playlist);
+ int ret = vlc_playlist_PlayAt(playlist, index);
+ if (ret) {
+ size_t count = vlc_playlist_Count(playlist);
- if (index < count)
- vlc_playlist_PlayAt(playlist, index);
- else
msg_print(intf,
vlc_ngettext("Playlist has only %zu element",
"Playlist has only %zu elements", count),
count);
+ }
vlc_playlist_Unlock(playlist);
+ return ret;
}
-static void PlaylistAddCommon(intf_thread_t *intf, const char *const *args,
- size_t n_args, bool play)
+static int PlaylistAddCommon(intf_thread_t *intf, const char *const *args,
+ size_t n_args, bool play)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
size_t count;
+ int ret = 0;
vlc_playlist_Lock(playlist);
count = vlc_playlist_Count(playlist);
@@ -394,7 +402,10 @@ static void PlaylistAddCommon(intf_thread_t *intf, const char *const *args,
}
if (unlikely(item == NULL))
+ {
+ ret = VLC_ENOMEM;
continue;
+ }
if (vlc_playlist_InsertOne(playlist, count, item) == VLC_SUCCESS)
{
@@ -424,29 +435,31 @@ static void PlaylistAddCommon(intf_thread_t *intf, const char *const *args,
}
#endif
vlc_playlist_Unlock(playlist);
+ return ret;
}
-static void PlaylistAdd(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistAdd(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlaylistAddCommon(intf, args, count, true);
+ return PlaylistAddCommon(intf, args, count, true);
}
-static void PlaylistEnqueue(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistEnqueue(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
- PlaylistAddCommon(intf, args, count, false);
+ return PlaylistAddCommon(intf, args, count, false);
}
-static void PlaylistMove(intf_thread_t *intf, const char *const *args,
- size_t count)
+static int PlaylistMove(intf_thread_t *intf, const char *const *args,
+ size_t count)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
+ int ret;
if (count != 3)
{
msg_print(intf, "%s expects two parameters", args[0]);
- return;
+ return VLC_EGENERIC /*EINVAL*/;
}
size_t from = strtoul(args[1], NULL, 0);
@@ -455,13 +468,20 @@ static void PlaylistMove(intf_thread_t *intf, const char *const *args,
vlc_playlist_Lock(playlist);
size_t size = vlc_playlist_Count(playlist);
- if (from >= size || to >= size)
- msg_print(intf,
- vlc_ngettext("Playlist has only %zu element",
- "Playlist has only %zu elements", size), size);
- else
+ if (from < size && to < size)
+ {
vlc_playlist_Move(playlist, from, 1, to);
+ ret = 0;
+ }
+ else
+ {
+ msg_print(intf, vlc_ngettext("Playlist has only %zu element",
+ "Playlist has only %zu elements", size),
+ size);
+ ret = VLC_ENOITEM;
+ }
vlc_playlist_Unlock(playlist);
+ return ret;
}
static const struct cli_handler cmds[] =
More information about the vlc-commits
mailing list