Commit 617abeec authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

playlist: type-safe functions for audio output management

parent 1e10857a
......@@ -364,6 +364,30 @@ VLC_API int playlist_NodeDelete( playlist_t *, playlist_item_t *, bool , bool );
VLC_API playlist_item_t * playlist_GetNextLeaf( playlist_t *p_playlist, playlist_item_t *p_root, playlist_item_t *p_item, bool b_ena, bool b_unplayed ) VLC_USED;
VLC_API playlist_item_t * playlist_GetPrevLeaf( playlist_t *p_playlist, playlist_item_t *p_root, playlist_item_t *p_item, bool b_ena, bool b_unplayed ) VLC_USED;
/**************************
* Audio output management
**************************/
#define AOUT_VOLUME_DEFAULT 256
#define AOUT_VOLUME_MAX 512
VLC_API float playlist_VolumeGet( playlist_t * );
VLC_API int playlist_VolumeSet( playlist_t *, float );
VLC_API int playlist_VolumeUp( playlist_t *, int, float * );
#define playlist_VolumeDown(a, b, c) playlist_VolumeUp(a, -(b), c)
VLC_API int playlist_MuteSet( playlist_t *, bool );
VLC_API int playlist_MuteGet( playlist_t * );
static inline int playlist_MuteToggle( playlist_t *pl )
{
int val = playlist_MuteGet( pl );
if (val >= 0)
val = playlist_MuteSet( pl, !val );
return val;
}
VLC_API void playlist_EnableAudioFilter( playlist_t *, const char *, bool );
/***********************************************************************
* Inline functions
***********************************************************************/
......
......@@ -330,6 +330,7 @@ SOURCES_libvlc_common = \
playlist/playlist_internal.h \
playlist/art.c \
playlist/art.h \
playlist/aout.c \
playlist/thread.c \
playlist/control.c \
playlist/engine.c \
......
......@@ -352,6 +352,12 @@ playlist_Status
playlist_TreeMove
playlist_TreeMoveMany
playlist_Unlock
playlist_EnableAudioFilter
playlist_VolumeGet
playlist_VolumeSet
playlist_VolumeUp
playlist_MuteSet
playlist_MuteGet
pl_Get
resolve_xml_special_chars
sdp_AddAttribute
......
/*****************************************************************************
* aout.c: audio output controls for the VLC playlist
*****************************************************************************
* Copyright (C) 2002-2012 VLC authors and VideoLAN
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_aout.h>
#include <vlc_playlist.h>
#include "../audio_output/aout_internal.h"
#include "playlist_internal.h"
static inline audio_output_t *findAout(playlist_t *pl)
{
/* NOTE: it is assumed that the input resource exists. In practice,
* the playlist must have been activated. This is automatic when calling * pl_Get(). FIXME: input resources are deleted at deactivation, this can
* be too early. */
playlist_private_t *sys = pl_priv(pl);
return input_resource_HoldAout(sys->p_input_resource);
}
float playlist_VolumeGet (playlist_t *pl)
{
float volume = -1.f;
audio_output_t *aout = findAout (pl);
if (aout != NULL)
{
volume = aout_OutputVolumeGet (aout);
vlc_object_release (aout);
}
return volume;
}
int playlist_VolumeSet (playlist_t *pl, float vol)
{
int ret = -1;
audio_output_t *aout = findAout (pl);
if (aout != NULL)
{
ret = aout_OutputVolumeSet (aout, vol);
vlc_object_release (aout);
}
return ret;
}
/**
* Raises the volume.
* \param value how much to increase (> 0) or decrease (< 0) the volume
* \param volp if non-NULL, will contain contain the resulting volume
*/
int playlist_VolumeUp (playlist_t *pl, int value, float *volp)
{
int ret = -1;
value *= var_InheritInteger (pl, "volume-step");
audio_output_t *aout = findAout (pl);
if (aout != NULL)
{
float vol = aout_OutputVolumeGet (aout);
if (vol >= 0.)
{
vol += value / (float)AOUT_VOLUME_DEFAULT;
if (vol < 0.)
vol = 0.;
if (vol > 2.)
vol = 2.;
if (volp != NULL)
*volp = vol;
ret = aout_OutputVolumeSet (aout, vol);
}
vlc_object_release (aout);
}
return ret;
}
int playlist_MuteGet (playlist_t *pl)
{
int mute = -1;
audio_output_t *aout = findAout (pl);
if (aout != NULL)
{
mute = aout_OutputMuteGet (aout);
vlc_object_release (aout);
}
return mute;
}
int playlist_MuteSet (playlist_t *pl, bool mute)
{
int ret = -1;
audio_output_t *aout = findAout (pl);
if (aout != NULL)
{
ret = aout_OutputMuteSet (aout, mute);
vlc_object_release (aout);
if (ret == 0)
var_SetBool (pl, "mute", mute);
}
return ret;
}
void playlist_EnableAudioFilter (playlist_t *pl, const char *name, bool add)
{
audio_output_t *aout = findAout (pl);
if (aout_ChangeFilterString (VLC_OBJECT(pl), VLC_OBJECT(aout),
"audio-filter", name, add))
{
if (aout != NULL)
aout_InputRequestRestart (aout);
}
if (aout != NULL)
vlc_object_release (aout);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment