1 /*****************************************************************************
2 * output.c : internal management of output streams for the audio output
3 *****************************************************************************
4 * Copyright (C) 2002-2004 VLC authors and VideoLAN
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
31 #include <vlc_common.h>
33 #include <vlc_modules.h>
36 #include "aout_internal.h"
38 static const char unset_str
[1] = ""; /* Non-NULL constant string pointer */
49 static void aout_OutputAssertLocked (audio_output_t
*aout
)
51 aout_owner_t
*owner
= aout_owner (aout
);
53 vlc_assert_locked (&owner
->lock
);
56 static void aout_Destructor( vlc_object_t
* p_this
);
58 static int var_Copy (vlc_object_t
*src
, const char *name
, vlc_value_t prev
,
59 vlc_value_t value
, void *data
)
61 vlc_object_t
*dst
= data
;
63 (void) src
; (void) prev
;
64 return var_Set (dst
, name
, value
);
67 static int var_CopyDevice (vlc_object_t
*src
, const char *name
,
68 vlc_value_t prev
, vlc_value_t value
, void *data
)
70 vlc_object_t
*dst
= data
;
72 (void) src
; (void) name
; (void) prev
;
73 return var_Set (dst
, "audio-device", value
);
77 * Supply or update the current custom ("hardware") volume.
78 * @note This only makes sense after calling aout_VolumeHardInit().
79 * @param volume current custom volume
81 * @warning The caller (i.e. the audio output plug-in) is responsible for
82 * interlocking and synchronizing call to this function and to the
83 * audio_output_t.volume_set callback. This ensures that VLC gets correct
84 * volume information (possibly with a latency).
86 static void aout_VolumeNotify (audio_output_t
*aout
, float volume
)
88 var_SetFloat (aout
, "volume", volume
);
91 static void aout_MuteNotify (audio_output_t
*aout
, bool mute
)
93 var_SetBool (aout
, "mute", mute
);
96 static void aout_PolicyNotify (audio_output_t
*aout
, bool cork
)
98 (cork
? var_IncInteger
: var_DecInteger
) (aout
->obj
.parent
, "corks");
101 static void aout_DeviceNotify (audio_output_t
*aout
, const char *id
)
103 var_SetString (aout
, "device", (id
!= NULL
) ? id
: "");
106 static void aout_HotplugNotify (audio_output_t
*aout
,
107 const char *id
, const char *name
)
109 aout_owner_t
*owner
= aout_owner (aout
);
110 aout_dev_t
*dev
, **pp
= &owner
->dev
.list
;
112 vlc_mutex_lock (&owner
->dev
.lock
);
113 while ((dev
= *pp
) != NULL
)
115 if (!strcmp (id
, dev
->id
))
122 if (dev
== NULL
) /* Added device */
124 dev
= malloc (sizeof (*dev
) + strlen (id
));
125 if (unlikely(dev
== NULL
))
128 strcpy (dev
->id
, id
);
132 else /* Modified device */
134 dev
->name
= strdup (name
);
138 if (dev
!= NULL
) /* Removed device */
147 vlc_mutex_unlock (&owner
->dev
.lock
);
150 static void aout_RestartNotify (audio_output_t
*aout
, unsigned mode
)
152 aout_RequestRestart (aout
, mode
);
155 static int aout_GainNotify (audio_output_t
*aout
, float gain
)
157 aout_owner_t
*owner
= aout_owner (aout
);
159 aout_OutputAssertLocked (aout
);
160 aout_volume_SetVolume (owner
->volume
, gain
);
161 /* XXX: ideally, return -1 if format cannot be amplified */
165 static int FilterCallback (vlc_object_t
*obj
, const char *var
,
166 vlc_value_t prev
, vlc_value_t cur
, void *data
)
168 if (strcmp(prev
.psz_string
, cur
.psz_string
))
169 aout_InputRequestRestart ((audio_output_t
*)obj
);
170 (void) var
; (void) data
;
174 static int StereoModeCallback (vlc_object_t
*obj
, const char *varname
,
175 vlc_value_t oldval
, vlc_value_t newval
, void *data
)
177 audio_output_t
*aout
= (audio_output_t
*)obj
;
178 (void)varname
; (void)oldval
; (void)newval
; (void)data
;
180 aout_RestartRequest (aout
, AOUT_RESTART_STEREOMODE
);
186 * Creates an audio output object and initializes an output module.
188 audio_output_t
*aout_New (vlc_object_t
*parent
)
190 vlc_value_t val
, text
;
192 audio_output_t
*aout
= vlc_custom_create (parent
, sizeof (aout_instance_t
),
194 if (unlikely(aout
== NULL
))
197 aout_owner_t
*owner
= aout_owner (aout
);
199 vlc_mutex_init (&owner
->lock
);
200 vlc_mutex_init (&owner
->req
.lock
);
201 vlc_mutex_init (&owner
->dev
.lock
);
202 owner
->req
.device
= (char *)unset_str
;
203 owner
->req
.volume
= -1.f
;
204 owner
->req
.mute
= -1;
206 vlc_object_set_destructor (aout
, aout_Destructor
);
208 /* Audio output module callbacks */
209 var_Create (aout
, "volume", VLC_VAR_FLOAT
);
210 var_AddCallback (aout
, "volume", var_Copy
, parent
);
211 var_Create (aout
, "mute", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
212 var_AddCallback (aout
, "mute", var_Copy
, parent
);
213 var_Create (aout
, "device", VLC_VAR_STRING
);
214 var_AddCallback (aout
, "device", var_CopyDevice
, parent
);
216 aout
->event
.volume_report
= aout_VolumeNotify
;
217 aout
->event
.mute_report
= aout_MuteNotify
;
218 aout
->event
.policy_report
= aout_PolicyNotify
;
219 aout
->event
.device_report
= aout_DeviceNotify
;
220 aout
->event
.hotplug_report
= aout_HotplugNotify
;
221 aout
->event
.gain_request
= aout_GainNotify
;
222 aout
->event
.restart_request
= aout_RestartNotify
;
224 /* Audio output module initialization */
227 aout
->volume_set
= NULL
;
228 aout
->mute_set
= NULL
;
229 aout
->device_select
= NULL
;
230 owner
->module
= module_need (aout
, "audio output", "$aout", false);
231 if (owner
->module
== NULL
)
233 msg_Err (aout
, "no suitable audio output module");
234 vlc_object_release (aout
);
239 * Persistent audio output variables
241 module_config_t
*cfg
;
245 var_Create (aout
, "visual", VLC_VAR_STRING
);
246 text
.psz_string
= _("Visualizations");
247 var_Change (aout
, "visual", VLC_VAR_SETTEXT
, &text
, NULL
);
248 val
.psz_string
= (char *)"";
249 text
.psz_string
= _("Disable");
250 var_Change (aout
, "visual", VLC_VAR_ADDCHOICE
, &val
, &text
);
251 val
.psz_string
= (char *)"spectrometer";
252 text
.psz_string
= _("Spectrometer");
253 var_Change (aout
, "visual", VLC_VAR_ADDCHOICE
, &val
, &text
);
254 val
.psz_string
= (char *)"scope";
255 text
.psz_string
= _("Scope");
256 var_Change (aout
, "visual", VLC_VAR_ADDCHOICE
, &val
, &text
);
257 val
.psz_string
= (char *)"spectrum";
258 text
.psz_string
= _("Spectrum");
259 var_Change (aout
, "visual", VLC_VAR_ADDCHOICE
, &val
, &text
);
260 val
.psz_string
= (char *)"vuMeter";
261 text
.psz_string
= _("VU meter");
262 var_Change (aout
, "visual", VLC_VAR_ADDCHOICE
, &val
, &text
);
263 /* Look for goom plugin */
264 if (module_exists ("goom"))
266 val
.psz_string
= (char *)"goom";
267 text
.psz_string
= (char *)"Goom";
268 var_Change (aout
, "visual", VLC_VAR_ADDCHOICE
, &val
, &text
);
270 /* Look for libprojectM plugin */
271 if (module_exists ("projectm"))
273 val
.psz_string
= (char *)"projectm";
274 text
.psz_string
= (char*)"projectM";
275 var_Change (aout
, "visual", VLC_VAR_ADDCHOICE
, &val
, &text
);
277 /* Look for VSXu plugin */
278 if (module_exists ("vsxu"))
280 val
.psz_string
= (char *)"vsxu";
281 text
.psz_string
= (char*)"Vovoid VSXu";
282 var_Change (aout
, "visual", VLC_VAR_ADDCHOICE
, &val
, &text
);
284 /* Look for glspectrum plugin */
285 if (module_exists ("glspectrum"))
287 val
.psz_string
= (char *)"glspectrum";
288 text
.psz_string
= (char*)"3D spectrum";
289 var_Change (aout
, "visual", VLC_VAR_ADDCHOICE
, &val
, &text
);
291 str
= var_GetNonEmptyString (aout
, "effect-list");
294 var_SetString (aout
, "visual", str
);
298 var_Create (aout
, "audio-filter", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
299 var_AddCallback (aout
, "audio-filter", FilterCallback
, NULL
);
300 text
.psz_string
= _("Audio filters");
301 var_Change (aout
, "audio-filter", VLC_VAR_SETTEXT
, &text
, NULL
);
304 var_Create (aout
, "audio-visual", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
305 text
.psz_string
= _("Audio visualizations");
306 var_Change (aout
, "audio-visual", VLC_VAR_SETTEXT
, &text
, NULL
);
309 var_Create (aout
, "audio-replay-gain-mode",
310 VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
311 text
.psz_string
= _("Replay gain");
312 var_Change (aout
, "audio-replay-gain-mode", VLC_VAR_SETTEXT
, &text
, NULL
);
313 cfg
= config_FindConfig (VLC_OBJECT(aout
), "audio-replay-gain-mode");
314 if (likely(cfg
!= NULL
))
315 for (unsigned i
= 0; i
< cfg
->list_count
; i
++)
317 val
.psz_string
= (char *)cfg
->list
.psz
[i
];
318 text
.psz_string
= vlc_gettext(cfg
->list_text
[i
]);
319 var_Change (aout
, "audio-replay-gain-mode", VLC_VAR_ADDCHOICE
,
324 var_Create (aout
, "stereo-mode", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
325 var_AddCallback (aout
, "stereo-mode", StereoModeCallback
, NULL
);
327 txt
.psz_string
= _("Stereo audio mode");
328 var_Change (aout
, "stereo-mode", VLC_VAR_SETTEXT
, &txt
, NULL
);
331 var_Create (aout
, "equalizer-preamp", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
332 var_Create (aout
, "equalizer-bands", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
333 var_Create (aout
, "equalizer-preset", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
339 * Deinitializes an audio output module and destroys an audio output object.
341 void aout_Destroy (audio_output_t
*aout
)
343 aout_owner_t
*owner
= aout_owner (aout
);
345 aout_OutputLock (aout
);
346 module_unneed (aout
, owner
->module
);
347 /* Protect against late call from intf.c */
348 aout
->volume_set
= NULL
;
349 aout
->mute_set
= NULL
;
350 aout
->device_select
= NULL
;
351 aout_OutputUnlock (aout
);
353 var_DelCallback (aout
, "audio-filter", FilterCallback
, NULL
);
354 var_DelCallback (aout
, "device", var_CopyDevice
, aout
->obj
.parent
);
355 var_DelCallback (aout
, "mute", var_Copy
, aout
->obj
.parent
);
356 var_SetFloat (aout
, "volume", -1.f
);
357 var_DelCallback (aout
, "volume", var_Copy
, aout
->obj
.parent
);
358 var_DelCallback (aout
, "stereo-mode", StereoModeCallback
, NULL
);
359 vlc_object_release (aout
);
363 * Destroys the audio output lock used (asynchronously) by interface functions.
365 static void aout_Destructor (vlc_object_t
*obj
)
367 audio_output_t
*aout
= (audio_output_t
*)obj
;
368 aout_owner_t
*owner
= aout_owner (aout
);
370 vlc_mutex_destroy (&owner
->dev
.lock
);
371 for (aout_dev_t
*dev
= owner
->dev
.list
, *next
; dev
!= NULL
; dev
= next
)
378 assert (owner
->req
.device
== unset_str
);
379 vlc_mutex_destroy (&owner
->req
.lock
);
380 vlc_mutex_destroy (&owner
->lock
);
383 static void aout_PrepareStereoMode (audio_output_t
*aout
,
384 audio_sample_format_t
*restrict fmt
,
385 aout_filters_cfg_t
*filters_cfg
,
386 int i_forced_stereo_mode
,
387 bool b_stereo_original
)
389 /* Fill Stereo mode choices */
390 var_Change (aout
, "stereo-mode", VLC_VAR_CLEARCHOICES
, NULL
, NULL
);
391 vlc_value_t val
, txt
, default_val
;
394 if (!AOUT_FMT_LINEAR(fmt
))
397 if (!b_stereo_original
)
399 val
.i_int
= AOUT_VAR_CHAN_UNSET
;
400 txt
.psz_string
= _("Original");
401 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
403 if (fmt
->i_chan_mode
& AOUT_CHANMODE_DOLBYSTEREO
)
405 val
.i_int
= AOUT_VAR_CHAN_DOLBYS
;
406 txt
.psz_string
= _("Dolby Surround");
410 val
.i_int
= AOUT_VAR_CHAN_STEREO
;
411 txt
.psz_string
= _("Stereo");
413 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
414 default_val
.i_int
= b_stereo_original
? val
.i_int
: AOUT_VAR_CHAN_UNSET
;
416 if (b_stereo_original
)
418 val
.i_int
= AOUT_VAR_CHAN_LEFT
;
419 txt
.psz_string
= _("Left");
420 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
421 val
.i_int
= AOUT_VAR_CHAN_RIGHT
;
422 txt
.psz_string
= _("Right");
423 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
425 val
.i_int
= AOUT_VAR_CHAN_RSTEREO
;
426 txt
.psz_string
= _("Reverse stereo");
427 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
430 if (fmt
->i_channels
>= 2)
432 val
.i_int
= AOUT_VAR_CHAN_HEADPHONES
;
433 txt
.psz_string
= _("Headphones");
434 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
437 /* The user may have selected a different channels configuration. */
438 switch (i_forced_stereo_mode
)
440 case AOUT_VAR_CHAN_RSTEREO
:
441 filters_cfg
->remap
[AOUT_CHANIDX_LEFT
] = AOUT_CHANIDX_RIGHT
;
442 filters_cfg
->remap
[AOUT_CHANIDX_RIGHT
] = AOUT_CHANIDX_LEFT
;
444 case AOUT_VAR_CHAN_STEREO
:
446 case AOUT_VAR_CHAN_LEFT
:
447 filters_cfg
->remap
[AOUT_CHANIDX_RIGHT
] = AOUT_CHANIDX_DISABLE
;
449 case AOUT_VAR_CHAN_RIGHT
:
450 filters_cfg
->remap
[AOUT_CHANIDX_LEFT
] = AOUT_CHANIDX_DISABLE
;
452 case AOUT_VAR_CHAN_DOLBYS
:
453 fmt
->i_chan_mode
= AOUT_CHANMODE_DOLBYSTEREO
;
455 case AOUT_VAR_CHAN_HEADPHONES
:
456 filters_cfg
->headphones
= true;
459 if (b_stereo_original
&& fmt
->i_chan_mode
& AOUT_CHANMODE_DUALMONO
)
460 { /* Go directly to the left channel. */
461 filters_cfg
->remap
[AOUT_CHANIDX_RIGHT
] = AOUT_CHANIDX_DISABLE
;
462 default_val
.i_int
= val
.i_int
= AOUT_VAR_CHAN_LEFT
;
464 var_Change (aout
, "stereo-mode", VLC_VAR_SETVALUE
, &default_val
,
471 * Starts an audio output stream.
472 * \param fmt audio output stream format [IN/OUT]
473 * \warning The caller must hold the audio output lock.
475 int aout_OutputNew (audio_output_t
*aout
, audio_sample_format_t
*restrict fmt
,
476 aout_filters_cfg_t
*filters_cfg
)
478 aout_OutputAssertLocked (aout
);
480 int i_forced_stereo_mode
= AOUT_VAR_CHAN_UNSET
;
481 bool b_stereo_original
= false;
483 /* Ideally, the audio filters would be created before the audio output,
484 * and the ideal audio format would be the output of the filters chain.
485 * But that scheme would not really play well with digital pass-through. */
486 if (AOUT_FMT_LINEAR(fmt
))
488 if (fmt
->channel_type
== AUDIO_CHANNEL_TYPE_BITMAP
489 && aout_FormatNbChannels(fmt
) == 0)
491 /* The output channel map is unknown, use the WAVE one. */
492 assert(fmt
->i_channels
> 0);
493 aout_SetWavePhysicalChannels(fmt
);
496 /* Try to stay in integer domain if possible for no/slow FPU. */
497 fmt
->i_format
= (fmt
->i_bitspersample
> 16) ? VLC_CODEC_FL32
500 i_forced_stereo_mode
= var_GetInteger (aout
, "stereo-mode");
501 b_stereo_original
= fmt
->i_physical_channels
== AOUT_CHANS_STEREO
;
502 if (i_forced_stereo_mode
!= AOUT_VAR_CHAN_UNSET
)
504 if (i_forced_stereo_mode
== AOUT_VAR_CHAN_LEFT
505 || i_forced_stereo_mode
== AOUT_VAR_CHAN_RIGHT
)
506 fmt
->i_physical_channels
= AOUT_CHAN_CENTER
;
508 fmt
->i_physical_channels
= AOUT_CHANS_STEREO
;
511 aout_FormatPrepare (fmt
);
514 if (aout
->start (aout
, fmt
))
516 msg_Err (aout
, "module not functional");
520 aout_PrepareStereoMode (aout
, fmt
, filters_cfg
, i_forced_stereo_mode
,
523 aout_FormatPrepare (fmt
);
524 assert (aout_FormatNbChannels(fmt
) > 0);
525 assert (fmt
->i_bytes_per_frame
> 0 && fmt
->i_frame_length
> 0);
526 aout_FormatPrint (aout
, "output", fmt
);
531 * Stops the audio output stream (undoes aout_OutputNew()).
532 * \note This can only be called after a successful aout_OutputNew().
533 * \warning The caller must hold the audio output lock.
535 void aout_OutputDelete (audio_output_t
*aout
)
537 aout_OutputAssertLocked (aout
);
539 if (aout
->stop
!= NULL
)
543 int aout_OutputTimeGet (audio_output_t
*aout
, mtime_t
*delay
)
545 aout_OutputAssertLocked (aout
);
547 if (aout
->time_get
== NULL
)
549 return aout
->time_get (aout
, delay
);
553 * Plays a decoded audio buffer.
554 * \note This can only be called after a successful aout_OutputNew().
555 * \warning The caller must hold the audio output lock.
557 void aout_OutputPlay (audio_output_t
*aout
, block_t
*block
)
559 aout_OutputAssertLocked (aout
);
561 aout_owner_t
*owner
= aout_owner (aout
);
562 assert (owner
->mixer_format
.i_frame_length
> 0);
563 assert (block
->i_buffer
== 0 || block
->i_buffer
/ block
->i_nb_samples
==
564 owner
->mixer_format
.i_bytes_per_frame
/
565 owner
->mixer_format
.i_frame_length
);
567 aout
->play (aout
, block
);
570 static void PauseDefault (audio_output_t
*aout
, bool pause
, mtime_t date
)
573 aout_OutputFlush (aout
, false);
578 * Notifies the audio output (if any) of pause/resume events.
579 * This enables the output to expedite pause, instead of waiting for its
581 * \note This can only be called after a successful aout_OutputNew().
582 * \warning The caller must hold the audio output lock.
584 void aout_OutputPause( audio_output_t
*aout
, bool pause
, mtime_t date
)
586 aout_OutputAssertLocked (aout
);
587 ((aout
->pause
!= NULL
) ? aout
->pause
: PauseDefault
) (aout
, pause
, date
);
591 * Flushes or drains the audio output buffers.
592 * This enables the output to expedite seek and stop.
593 * \param wait if true, wait for buffer playback (i.e. drain),
594 * if false, discard the buffers immediately (i.e. flush)
595 * \note This can only be called after a successful aout_OutputNew().
596 * \warning The caller must hold the audio output lock.
598 void aout_OutputFlush( audio_output_t
*aout
, bool wait
)
600 aout_OutputAssertLocked( aout
);
601 aout
->flush (aout
, wait
);
604 static int aout_OutputVolumeSet (audio_output_t
*aout
, float vol
)
606 aout_OutputAssertLocked (aout
);
607 return (aout
->volume_set
!= NULL
) ? aout
->volume_set (aout
, vol
) : -1;
610 static int aout_OutputMuteSet (audio_output_t
*aout
, bool mute
)
612 aout_OutputAssertLocked (aout
);
613 return (aout
->mute_set
!= NULL
) ? aout
->mute_set (aout
, mute
) : -1;
616 static int aout_OutputDeviceSet (audio_output_t
*aout
, const char *id
)
618 aout_OutputAssertLocked (aout
);
619 return (aout
->device_select
!= NULL
) ? aout
->device_select (aout
, id
) : -1;
622 void aout_OutputLock (audio_output_t
*aout
)
624 aout_owner_t
*owner
= aout_owner (aout
);
626 vlc_mutex_lock (&owner
->lock
);
629 static int aout_OutputTryLock (audio_output_t
*aout
)
631 aout_owner_t
*owner
= aout_owner (aout
);
633 return vlc_mutex_trylock (&owner
->lock
);
636 void aout_OutputUnlock (audio_output_t
*aout
)
638 aout_owner_t
*owner
= aout_owner (aout
);
640 vlc_assert_locked (&owner
->lock
);
641 vlc_mutex_lock (&owner
->req
.lock
);
643 if (owner
->req
.device
!= unset_str
)
645 aout_OutputDeviceSet (aout
, owner
->req
.device
);
646 free (owner
->req
.device
);
647 owner
->req
.device
= (char *)unset_str
;
650 if (owner
->req
.volume
>= 0.f
)
652 aout_OutputVolumeSet (aout
, owner
->req
.volume
);
653 owner
->req
.volume
= -1.f
;
656 if (owner
->req
.mute
>= 0)
658 aout_OutputMuteSet (aout
, owner
->req
.mute
);
659 owner
->req
.mute
= -1;
662 vlc_mutex_unlock (&owner
->lock
);
663 /* If another thread is blocked waiting for owner->req.lock at this point,
664 * this aout_OutputUnlock() call will not see and apply its change request.
665 * The other thread will need to apply the change request itself, which
666 * implies it is able to (try-)lock owner->lock. Therefore this thread must
667 * release owner->lock _before_ owner->req.lock. Do not reorder!!! */
668 vlc_mutex_unlock (&owner
->req
.lock
);
672 * Gets the volume of the audio output stream (independent of mute).
673 * \return Current audio volume (0. = silent, 1. = nominal),
674 * or a strictly negative value if undefined.
676 float aout_VolumeGet (audio_output_t
*aout
)
678 return var_GetFloat (aout
, "volume");
682 * Sets the volume of the audio output stream.
683 * \note The mute status is not changed.
684 * \return 0 on success, -1 on failure (TODO).
686 int aout_VolumeSet (audio_output_t
*aout
, float vol
)
688 aout_owner_t
*owner
= aout_owner (aout
);
691 vlc_mutex_lock (&owner
->req
.lock
);
692 owner
->req
.volume
= vol
;
693 vlc_mutex_unlock (&owner
->req
.lock
);
695 if (aout_OutputTryLock (aout
) == 0)
696 aout_OutputUnlock (aout
);
701 * Gets the audio output stream mute flag.
702 * \return 0 if not muted, 1 if muted, -1 if undefined.
704 int aout_MuteGet (audio_output_t
*aout
)
706 return var_InheritBool (aout
, "mute");
710 * Sets the audio output stream mute flag.
711 * \return 0 on success, -1 on failure (TODO).
713 int aout_MuteSet (audio_output_t
*aout
, bool mute
)
715 aout_owner_t
*owner
= aout_owner (aout
);
717 vlc_mutex_lock (&owner
->req
.lock
);
718 owner
->req
.mute
= mute
;
719 vlc_mutex_unlock (&owner
->req
.lock
);
721 if (aout_OutputTryLock (aout
) == 0)
722 aout_OutputUnlock (aout
);
727 * Gets the currently selected device.
728 * \return the selected device ID (caller must free() it)
729 * NULL if no device is selected or in case of error.
731 char *aout_DeviceGet (audio_output_t
*aout
)
733 return var_GetNonEmptyString (aout
, "device");
737 * Selects an audio output device.
738 * \param id device ID to select, or NULL for the default device
739 * \return zero on success, non-zero on error (TODO).
741 int aout_DeviceSet (audio_output_t
*aout
, const char *id
)
743 aout_owner_t
*owner
= aout_owner (aout
);
749 if (unlikely(dev
== NULL
))
753 vlc_mutex_lock (&owner
->req
.lock
);
754 if (owner
->req
.device
!= unset_str
)
755 free (owner
->req
.device
);
756 owner
->req
.device
= dev
;
757 vlc_mutex_unlock (&owner
->req
.lock
);
759 if (aout_OutputTryLock (aout
) == 0)
760 aout_OutputUnlock (aout
);
765 * Enumerates possible audio output devices.
767 * The function will heap-allocate two tables of heap-allocated strings;
768 * the caller is responsible for freeing all strings and both tables.
770 * \param ids pointer to a table of device identifiers [OUT]
771 * \param names pointer to a table of device human-readable descriptions [OUT]
772 * \return the number of devices, or negative on error.
773 * \note In case of error, *ids and *names are undefined.
775 int aout_DevicesList (audio_output_t
*aout
, char ***ids
, char ***names
)
777 aout_owner_t
*owner
= aout_owner (aout
);
778 char **tabid
, **tabname
;
781 vlc_mutex_lock (&owner
->dev
.lock
);
782 tabid
= malloc (sizeof (*tabid
) * owner
->dev
.count
);
783 tabname
= malloc (sizeof (*tabname
) * owner
->dev
.count
);
785 if (unlikely(tabid
== NULL
|| tabname
== NULL
))
791 for (aout_dev_t
*dev
= owner
->dev
.list
; dev
!= NULL
; dev
= dev
->next
)
793 tabid
[i
] = strdup(dev
->id
);
794 if (unlikely(tabid
[i
] == NULL
))
797 tabname
[i
] = strdup(dev
->name
);
798 if (unlikely(tabname
[i
] == NULL
))
806 vlc_mutex_unlock (&owner
->dev
.lock
);
811 vlc_mutex_unlock(&owner
->dev
.lock
);