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_OUTPUT
);
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
);
384 * Starts an audio output stream.
385 * \param fmt audio output stream format [IN/OUT]
386 * \warning The caller must hold the audio output lock.
388 int aout_OutputNew (audio_output_t
*aout
, audio_sample_format_t
*restrict fmt
,
391 aout_OutputAssertLocked (aout
);
393 int i_forced_stereo_mode
= var_GetInteger (aout
, "stereo-mode");
394 bool b_stereo_original
= fmt
->i_physical_channels
== AOUT_CHANS_STEREO
;
395 if (i_forced_stereo_mode
!= AOUT_VAR_CHAN_UNSET
)
397 if (i_forced_stereo_mode
== AOUT_VAR_CHAN_LEFT
398 || i_forced_stereo_mode
== AOUT_VAR_CHAN_RIGHT
)
399 fmt
->i_physical_channels
= AOUT_CHAN_CENTER
;
401 fmt
->i_physical_channels
= AOUT_CHANS_STEREO
;
404 /* Ideally, the audio filters would be created before the audio output,
405 * and the ideal audio format would be the output of the filters chain.
406 * But that scheme would not really play well with digital pass-through. */
407 if (AOUT_FMT_LINEAR(fmt
))
408 { /* Try to stay in integer domain if possible for no/slow FPU. */
409 fmt
->i_format
= (fmt
->i_bitspersample
> 16) ? VLC_CODEC_FL32
411 aout_FormatPrepare (fmt
);
414 if (aout
->start (aout
, fmt
))
416 msg_Err (aout
, "module not functional");
420 /* Fill Stereo mode choices */
421 var_Change (aout
, "stereo-mode", VLC_VAR_CLEARCHOICES
, NULL
, NULL
);
422 vlc_value_t val
, txt
, default_val
;
424 if (!b_stereo_original
)
426 val
.i_int
= AOUT_VAR_CHAN_UNSET
;
427 txt
.psz_string
= _("Original");
428 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
430 if (fmt
->i_chan_mode
& AOUT_CHANMODE_DOLBYSTEREO
)
432 val
.i_int
= AOUT_VAR_CHAN_DOLBYS
;
433 txt
.psz_string
= _("Dolby Surround");
437 val
.i_int
= AOUT_VAR_CHAN_STEREO
;
438 txt
.psz_string
= _("Stereo");
440 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
441 default_val
.i_int
= b_stereo_original
? val
.i_int
: AOUT_VAR_CHAN_UNSET
;
443 if (b_stereo_original
)
445 val
.i_int
= AOUT_VAR_CHAN_LEFT
;
446 txt
.psz_string
= _("Left");
447 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
448 val
.i_int
= AOUT_VAR_CHAN_RIGHT
;
449 txt
.psz_string
= _("Right");
450 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
452 val
.i_int
= AOUT_VAR_CHAN_RSTEREO
;
453 txt
.psz_string
= _("Reverse stereo");
454 var_Change (aout
, "stereo-mode", VLC_VAR_ADDCHOICE
, &val
, &txt
);
456 /* The user may have selected a different channels configuration. */
457 switch (i_forced_stereo_mode
)
459 case AOUT_VAR_CHAN_RSTEREO
:
460 remap
[AOUT_CHANIDX_LEFT
] = AOUT_CHANIDX_RIGHT
;
461 remap
[AOUT_CHANIDX_RIGHT
] = AOUT_CHANIDX_LEFT
;
463 case AOUT_VAR_CHAN_STEREO
:
465 case AOUT_VAR_CHAN_LEFT
:
466 remap
[AOUT_CHANIDX_RIGHT
] = AOUT_CHANIDX_DISABLE
;
468 case AOUT_VAR_CHAN_RIGHT
:
469 remap
[AOUT_CHANIDX_LEFT
] = AOUT_CHANIDX_DISABLE
;
471 case AOUT_VAR_CHAN_DOLBYS
:
472 fmt
->i_chan_mode
= AOUT_CHANMODE_DOLBYSTEREO
;
475 if (b_stereo_original
&& fmt
->i_chan_mode
& AOUT_CHANMODE_DUALMONO
)
476 { /* Go directly to the left channel. */
477 remap
[AOUT_CHANIDX_RIGHT
] = AOUT_CHANIDX_DISABLE
;
478 val
.i_int
= AOUT_VAR_CHAN_LEFT
;
479 var_Change (aout
, "stereo-mode", VLC_VAR_SETVALUE
, &val
, NULL
);
482 var_Change (aout
, "stereo-mode", VLC_VAR_SETVALUE
, &default_val
,
487 aout_FormatPrepare (fmt
);
488 assert (aout_FormatNbChannels(fmt
) > 0);
489 assert (fmt
->i_bytes_per_frame
> 0 && fmt
->i_frame_length
> 0);
490 aout_FormatPrint (aout
, "output", fmt
);
495 * Stops the audio output stream (undoes aout_OutputNew()).
496 * \note This can only be called after a successful aout_OutputNew().
497 * \warning The caller must hold the audio output lock.
499 void aout_OutputDelete (audio_output_t
*aout
)
501 aout_OutputAssertLocked (aout
);
503 if (aout
->stop
!= NULL
)
507 int aout_OutputTimeGet (audio_output_t
*aout
, mtime_t
*delay
)
509 aout_OutputAssertLocked (aout
);
511 if (aout
->time_get
== NULL
)
513 return aout
->time_get (aout
, delay
);
517 * Plays a decoded audio buffer.
518 * \note This can only be called after a successful aout_OutputNew().
519 * \warning The caller must hold the audio output lock.
521 void aout_OutputPlay (audio_output_t
*aout
, block_t
*block
)
523 aout_OutputAssertLocked (aout
);
525 aout_owner_t
*owner
= aout_owner (aout
);
526 assert (owner
->mixer_format
.i_frame_length
> 0);
527 assert (block
->i_buffer
== 0 || block
->i_buffer
/ block
->i_nb_samples
==
528 owner
->mixer_format
.i_bytes_per_frame
/
529 owner
->mixer_format
.i_frame_length
);
531 aout
->play (aout
, block
);
534 static void PauseDefault (audio_output_t
*aout
, bool pause
, mtime_t date
)
537 aout_OutputFlush (aout
, false);
542 * Notifies the audio output (if any) of pause/resume events.
543 * This enables the output to expedite pause, instead of waiting for its
545 * \note This can only be called after a successful aout_OutputNew().
546 * \warning The caller must hold the audio output lock.
548 void aout_OutputPause( audio_output_t
*aout
, bool pause
, mtime_t date
)
550 aout_OutputAssertLocked (aout
);
551 ((aout
->pause
!= NULL
) ? aout
->pause
: PauseDefault
) (aout
, pause
, date
);
555 * Flushes or drains the audio output buffers.
556 * This enables the output to expedite seek and stop.
557 * \param wait if true, wait for buffer playback (i.e. drain),
558 * if false, discard the buffers immediately (i.e. flush)
559 * \note This can only be called after a successful aout_OutputNew().
560 * \warning The caller must hold the audio output lock.
562 void aout_OutputFlush( audio_output_t
*aout
, bool wait
)
564 aout_OutputAssertLocked( aout
);
565 aout
->flush (aout
, wait
);
568 static int aout_OutputVolumeSet (audio_output_t
*aout
, float vol
)
570 aout_OutputAssertLocked (aout
);
571 return (aout
->volume_set
!= NULL
) ? aout
->volume_set (aout
, vol
) : -1;
574 static int aout_OutputMuteSet (audio_output_t
*aout
, bool mute
)
576 aout_OutputAssertLocked (aout
);
577 return (aout
->mute_set
!= NULL
) ? aout
->mute_set (aout
, mute
) : -1;
580 static int aout_OutputDeviceSet (audio_output_t
*aout
, const char *id
)
582 aout_OutputAssertLocked (aout
);
583 return (aout
->device_select
!= NULL
) ? aout
->device_select (aout
, id
) : -1;
586 void aout_OutputLock (audio_output_t
*aout
)
588 aout_owner_t
*owner
= aout_owner (aout
);
590 vlc_mutex_lock (&owner
->lock
);
593 static int aout_OutputTryLock (audio_output_t
*aout
)
595 aout_owner_t
*owner
= aout_owner (aout
);
597 return vlc_mutex_trylock (&owner
->lock
);
600 void aout_OutputUnlock (audio_output_t
*aout
)
602 aout_owner_t
*owner
= aout_owner (aout
);
604 vlc_assert_locked (&owner
->lock
);
605 vlc_mutex_lock (&owner
->req
.lock
);
607 if (owner
->req
.device
!= unset_str
)
609 aout_OutputDeviceSet (aout
, owner
->req
.device
);
610 free (owner
->req
.device
);
611 owner
->req
.device
= (char *)unset_str
;
614 if (owner
->req
.volume
>= 0.f
)
616 aout_OutputVolumeSet (aout
, owner
->req
.volume
);
617 owner
->req
.volume
= -1.f
;
620 if (owner
->req
.mute
>= 0)
622 aout_OutputMuteSet (aout
, owner
->req
.mute
);
623 owner
->req
.mute
= -1;
626 vlc_mutex_unlock (&owner
->lock
);
627 /* If another thread is blocked waiting for owner->req.lock at this point,
628 * this aout_OutputUnlock() call will not see and apply its change request.
629 * The other thread will need to apply the change request itself, which
630 * implies it is able to (try-)lock owner->lock. Therefore this thread must
631 * release owner->lock _before_ owner->req.lock. Do not reorder!!! */
632 vlc_mutex_unlock (&owner
->req
.lock
);
636 * Gets the volume of the audio output stream (independent of mute).
637 * \return Current audio volume (0. = silent, 1. = nominal),
638 * or a strictly negative value if undefined.
640 float aout_VolumeGet (audio_output_t
*aout
)
642 return var_GetFloat (aout
, "volume");
646 * Sets the volume of the audio output stream.
647 * \note The mute status is not changed.
648 * \return 0 on success, -1 on failure (TODO).
650 int aout_VolumeSet (audio_output_t
*aout
, float vol
)
652 aout_owner_t
*owner
= aout_owner (aout
);
655 vlc_mutex_lock (&owner
->req
.lock
);
656 owner
->req
.volume
= vol
;
657 vlc_mutex_unlock (&owner
->req
.lock
);
659 if (aout_OutputTryLock (aout
) == 0)
660 aout_OutputUnlock (aout
);
665 * Gets the audio output stream mute flag.
666 * \return 0 if not muted, 1 if muted, -1 if undefined.
668 int aout_MuteGet (audio_output_t
*aout
)
670 return var_InheritBool (aout
, "mute");
674 * Sets the audio output stream mute flag.
675 * \return 0 on success, -1 on failure (TODO).
677 int aout_MuteSet (audio_output_t
*aout
, bool mute
)
679 aout_owner_t
*owner
= aout_owner (aout
);
681 vlc_mutex_lock (&owner
->req
.lock
);
682 owner
->req
.mute
= mute
;
683 vlc_mutex_unlock (&owner
->req
.lock
);
685 if (aout_OutputTryLock (aout
) == 0)
686 aout_OutputUnlock (aout
);
691 * Gets the currently selected device.
692 * \return the selected device ID (caller must free() it)
693 * NULL if no device is selected or in case of error.
695 char *aout_DeviceGet (audio_output_t
*aout
)
697 return var_GetNonEmptyString (aout
, "device");
701 * Selects an audio output device.
702 * \param id device ID to select, or NULL for the default device
703 * \return zero on success, non-zero on error (TODO).
705 int aout_DeviceSet (audio_output_t
*aout
, const char *id
)
707 aout_owner_t
*owner
= aout_owner (aout
);
713 if (unlikely(dev
== NULL
))
717 vlc_mutex_lock (&owner
->req
.lock
);
718 if (owner
->req
.device
!= unset_str
)
719 free (owner
->req
.device
);
720 owner
->req
.device
= dev
;
721 vlc_mutex_unlock (&owner
->req
.lock
);
723 if (aout_OutputTryLock (aout
) == 0)
724 aout_OutputUnlock (aout
);
729 * Enumerates possible audio output devices.
731 * The function will heap-allocate two tables of heap-allocated strings;
732 * the caller is responsible for freeing all strings and both tables.
734 * \param ids pointer to a table of device identifiers [OUT]
735 * \param names pointer to a table of device human-readable descriptions [OUT]
736 * \return the number of devices, or negative on error.
737 * \note In case of error, *ids and *names are undefined.
739 int aout_DevicesList (audio_output_t
*aout
, char ***ids
, char ***names
)
741 aout_owner_t
*owner
= aout_owner (aout
);
742 char **tabid
, **tabname
;
745 vlc_mutex_lock (&owner
->dev
.lock
);
746 tabid
= malloc (sizeof (*tabid
) * owner
->dev
.count
);
747 tabname
= malloc (sizeof (*tabname
) * owner
->dev
.count
);
749 if (unlikely(tabid
== NULL
|| tabname
== NULL
))
755 for (aout_dev_t
*dev
= owner
->dev
.list
; dev
!= NULL
; dev
= dev
->next
)
757 tabid
[i
] = strdup(dev
->id
);
758 if (unlikely(tabid
[i
] == NULL
))
761 tabname
[i
] = strdup(dev
->name
);
762 if (unlikely(tabname
[i
] == NULL
))
770 vlc_mutex_unlock (&owner
->dev
.lock
);
775 vlc_mutex_unlock(&owner
->dev
.lock
);