]> git.sesse.net Git - vlc/blob - src/audio_output/output.c
macosx: mooaaarr eye-candy for the about dialog
[vlc] / src / audio_output / output.c
1 /*****************************************************************************
2  * output.c : internal management of output streams for the audio output
3  *****************************************************************************
4  * Copyright (C) 2002-2004 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <stdlib.h>
29 #include <assert.h>
30
31 #include <vlc_common.h>
32 #include <vlc_aout.h>
33 #include <vlc_modules.h>
34
35 #include "libvlc.h"
36 #include "aout_internal.h"
37
38 static const char unset_str[1] = ""; /* Non-NULL constant string pointer */
39
40 struct aout_dev
41 {
42     aout_dev_t *next;
43     char *name;
44     char id[1];
45 };
46
47
48 /* Local functions */
49 static void aout_OutputAssertLocked (audio_output_t *aout)
50 {
51     aout_owner_t *owner = aout_owner (aout);
52
53     vlc_assert_locked (&owner->lock);
54 }
55
56 static void aout_Destructor( vlc_object_t * p_this );
57
58 static int var_Copy (vlc_object_t *src, const char *name, vlc_value_t prev,
59                      vlc_value_t value, void *data)
60 {
61     vlc_object_t *dst = data;
62
63     (void) src; (void) prev;
64     return var_Set (dst, name, value);
65 }
66
67 /**
68  * Supply or update the current custom ("hardware") volume.
69  * @note This only makes sense after calling aout_VolumeHardInit().
70  * @param volume current custom volume
71  *
72  * @warning The caller (i.e. the audio output plug-in) is responsible for
73  * interlocking and synchronizing call to this function and to the
74  * audio_output_t.volume_set callback. This ensures that VLC gets correct
75  * volume information (possibly with a latency).
76  */
77 static void aout_VolumeNotify (audio_output_t *aout, float volume)
78 {
79     var_SetFloat (aout, "volume", volume);
80 }
81
82 static void aout_MuteNotify (audio_output_t *aout, bool mute)
83 {
84     var_SetBool (aout, "mute", mute);
85 }
86
87 static void aout_PolicyNotify (audio_output_t *aout, bool cork)
88 {
89     (cork ? var_IncInteger : var_DecInteger) (aout->p_parent, "corks");
90 }
91
92 static void aout_DeviceNotify (audio_output_t *aout, const char *id)
93 {
94     var_SetString (aout, "device", (id != NULL) ? id : "");
95 }
96
97 static void aout_HotplugNotify (audio_output_t *aout,
98                                 const char *id, const char *name)
99 {
100     aout_owner_t *owner = aout_owner (aout);
101     aout_dev_t *dev, **pp = &owner->dev.list;
102
103     vlc_mutex_lock (&owner->dev.lock);
104     while ((dev = *pp) != NULL)
105     {
106         if (!strcmp (id, dev->id))
107             break;
108         pp = &dev->next;
109     }
110
111     if (name != NULL)
112     {
113         if (dev == NULL) /* Added device */
114         {
115             dev = malloc (sizeof (*dev) + strlen (id));
116             if (unlikely(dev == NULL))
117                 goto out;
118             dev->next = NULL;
119             strcpy (dev->id, id);
120             *pp = dev;
121             owner->dev.count++;
122         }
123         else /* Modified device */
124             free (dev->name);
125         dev->name = strdup (name);
126     }
127     else
128     {
129         if (dev != NULL) /* Removed device */
130         {
131             owner->dev.count--;
132             *pp = dev->next;
133             free (dev->name);
134             free (dev);
135         }
136     }
137 out:
138     vlc_mutex_unlock (&owner->dev.lock);
139 }
140
141 static void aout_RestartNotify (audio_output_t *aout, unsigned mode)
142 {
143     aout_RequestRestart (aout, mode);
144 }
145
146 static int aout_GainNotify (audio_output_t *aout, float gain)
147 {
148     aout_owner_t *owner = aout_owner (aout);
149
150     aout_OutputAssertLocked (aout);
151     aout_volume_SetVolume (owner->volume, gain);
152     /* XXX: ideally, return -1 if format cannot be amplified */
153     return 0;
154 }
155
156 #undef aout_New
157 /**
158  * Creates an audio output object and initializes an output module.
159  */
160 audio_output_t *aout_New (vlc_object_t *parent)
161 {
162     vlc_value_t val, text;
163
164     audio_output_t *aout = vlc_custom_create (parent, sizeof (aout_instance_t),
165                                               "audio output");
166     if (unlikely(aout == NULL))
167         return NULL;
168
169     aout_owner_t *owner = aout_owner (aout);
170
171     vlc_mutex_init (&owner->lock);
172     vlc_mutex_init (&owner->req.lock);
173     vlc_mutex_init (&owner->dev.lock);
174     owner->req.device = (char *)unset_str;
175     owner->req.volume = -1.f;
176     owner->req.mute = -1;
177
178     vlc_object_set_destructor (aout, aout_Destructor);
179
180     /* Audio output module callbacks */
181     var_Create (aout, "volume", VLC_VAR_FLOAT);
182     var_AddCallback (aout, "volume", var_Copy, parent);
183     var_Create (aout, "mute", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
184     var_AddCallback (aout, "mute", var_Copy, parent);
185     var_Create (aout, "device", VLC_VAR_STRING);
186
187     aout->event.volume_report = aout_VolumeNotify;
188     aout->event.mute_report = aout_MuteNotify;
189     aout->event.policy_report = aout_PolicyNotify;
190     aout->event.device_report = aout_DeviceNotify;
191     aout->event.hotplug_report = aout_HotplugNotify;
192     aout->event.gain_request = aout_GainNotify;
193     aout->event.restart_request = aout_RestartNotify;
194
195     /* Audio output module initialization */
196     aout->start = NULL;
197     aout->stop = NULL;
198     aout->volume_set = NULL;
199     aout->mute_set = NULL;
200     aout->device_select = NULL;
201     owner->module = module_need (aout, "audio output", "$aout", false);
202     if (owner->module == NULL)
203     {
204         msg_Err (aout, "no suitable audio output module");
205         vlc_object_release (aout);
206         return NULL;
207     }
208
209     /*
210      * Persistent audio output variables
211      */
212     module_config_t *cfg;
213     char *str;
214
215     /* Visualizations */
216     var_Create (aout, "visual", VLC_VAR_STRING | VLC_VAR_HASCHOICE);
217     text.psz_string = _("Visualizations");
218     var_Change (aout, "visual", VLC_VAR_SETTEXT, &text, NULL);
219     val.psz_string = (char *)"";
220     text.psz_string = _("Disable");
221     var_Change (aout, "visual", VLC_VAR_ADDCHOICE, &val, &text);
222     val.psz_string = (char *)"spectrometer";
223     text.psz_string = _("Spectrometer");
224     var_Change (aout, "visual", VLC_VAR_ADDCHOICE, &val, &text);
225     val.psz_string = (char *)"scope";
226     text.psz_string = _("Scope");
227     var_Change (aout, "visual", VLC_VAR_ADDCHOICE, &val, &text);
228     val.psz_string = (char *)"spectrum";
229     text.psz_string = _("Spectrum");
230     var_Change (aout, "visual", VLC_VAR_ADDCHOICE, &val, &text);
231     val.psz_string = (char *)"vuMeter";
232     text.psz_string = _("Vu meter");
233     var_Change (aout, "visual", VLC_VAR_ADDCHOICE, &val, &text);
234     /* Look for goom plugin */
235     if (module_exists ("goom"))
236     {
237         val.psz_string = (char *)"goom";
238         text.psz_string = (char *)"Goom";
239         var_Change (aout, "visual", VLC_VAR_ADDCHOICE, &val, &text);
240     }
241     /* Look for libprojectM plugin */
242     if (module_exists ("projectm"))
243     {
244         val.psz_string = (char *)"projectm";
245         text.psz_string = (char*)"projectM";
246         var_Change (aout, "visual", VLC_VAR_ADDCHOICE, &val, &text);
247     }
248     /* Look for VSXu plugin */
249     if (module_exists ("vsxu"))
250     {
251         val.psz_string = (char *)"vsxu";
252         text.psz_string = (char*)"Vovoid VSXu";
253         var_Change (aout, "visual", VLC_VAR_ADDCHOICE, &val, &text);
254     }
255     str = var_GetNonEmptyString (aout, "effect-list");
256     if (str != NULL)
257     {
258         var_SetString (aout, "visual", str);
259         free (str);
260     }
261
262     /* Equalizer */
263     var_Create (aout, "equalizer", VLC_VAR_STRING | VLC_VAR_HASCHOICE);
264     text.psz_string = _("Equalizer");
265     var_Change (aout, "equalizer", VLC_VAR_SETTEXT, &text, NULL);
266     val.psz_string = (char*)"";
267     text.psz_string = _("Disable");
268     var_Change (aout, "equalizer", VLC_VAR_ADDCHOICE, &val, &text);
269     cfg = config_FindConfig (VLC_OBJECT(aout), "equalizer-preset");
270     if (likely(cfg != NULL))
271         for (unsigned i = 0; i < cfg->list_count; i++)
272         {
273             val.psz_string = cfg->list.psz[i];
274             text.psz_string = vlc_gettext(cfg->list_text[i]);
275             var_Change (aout, "equalizer", VLC_VAR_ADDCHOICE, &val, &text);
276         }
277
278     var_Create (aout, "audio-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
279     text.psz_string = _("Audio filters");
280     var_Change (aout, "audio-filter", VLC_VAR_SETTEXT, &text, NULL);
281
282
283     var_Create (aout, "audio-visual", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
284     text.psz_string = _("Audio visualizations");
285     var_Change (aout, "audio-visual", VLC_VAR_SETTEXT, &text, NULL);
286
287     /* Replay gain */
288     var_Create (aout, "audio-replay-gain-mode",
289                 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
290     text.psz_string = _("Replay gain");
291     var_Change (aout, "audio-replay-gain-mode", VLC_VAR_SETTEXT, &text, NULL);
292     cfg = config_FindConfig (VLC_OBJECT(aout), "audio-replay-gain-mode");
293     if (likely(cfg != NULL))
294         for (unsigned i = 0; i < cfg->list_count; i++)
295         {
296             val.psz_string = cfg->list.psz[i];
297             text.psz_string = vlc_gettext(cfg->list_text[i]);
298             var_Change (aout, "audio-replay-gain-mode", VLC_VAR_ADDCHOICE,
299                             &val, &text);
300         }
301
302     return aout;
303 }
304
305 /**
306  * Deinitializes an audio output module and destroys an audio output object.
307  */
308 void aout_Destroy (audio_output_t *aout)
309 {
310     aout_owner_t *owner = aout_owner (aout);
311
312     aout_OutputLock (aout);
313     module_unneed (aout, owner->module);
314     /* Protect against late call from intf.c */
315     aout->volume_set = NULL;
316     aout->mute_set = NULL;
317     aout_OutputUnlock (aout);
318
319     var_DelCallback (aout, "mute", var_Copy, aout->p_parent);
320     var_SetFloat (aout, "volume", -1.f);
321     var_DelCallback (aout, "volume", var_Copy, aout->p_parent);
322     vlc_object_release (aout);
323 }
324
325 /**
326  * Destroys the audio output lock used (asynchronously) by interface functions.
327  */
328 static void aout_Destructor (vlc_object_t *obj)
329 {
330     audio_output_t *aout = (audio_output_t *)obj;
331     aout_owner_t *owner = aout_owner (aout);
332
333     vlc_mutex_destroy (&owner->dev.lock);
334     for (aout_dev_t *dev = owner->dev.list, *next; dev != NULL; dev = next)
335     {
336         next = dev->next;
337         free (dev->name);
338         free (dev);
339     }
340
341     assert (owner->req.device == unset_str);
342     vlc_mutex_destroy (&owner->req.lock);
343     vlc_mutex_destroy (&owner->lock);
344 }
345
346 /**
347  * Starts an audio output stream.
348  * \param fmt audio output stream format [IN/OUT]
349  * \warning The caller must hold the audio output lock.
350  */
351 int aout_OutputNew (audio_output_t *aout, audio_sample_format_t *restrict fmt)
352 {
353     aout_OutputAssertLocked (aout);
354
355     /* Ideally, the audio filters would be created before the audio output,
356      * and the ideal audio format would be the output of the filters chain.
357      * But that scheme would not really play well with digital pass-through. */
358     if (AOUT_FMT_LINEAR(fmt))
359     {   /* Try to stay in integer domain if possible for no/slow FPU. */
360         fmt->i_format = (fmt->i_bitspersample > 16) ? VLC_CODEC_FL32
361                                                     : VLC_CODEC_S16N;
362         aout_FormatPrepare (fmt);
363     }
364
365     if (aout->start (aout, fmt))
366     {
367         msg_Err (aout, "module not functional");
368         return -1;
369     }
370
371     if (!var_Type (aout, "stereo-mode"))
372         var_Create (aout, "stereo-mode",
373                     VLC_VAR_INTEGER | VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT);
374
375     /* The user may have selected a different channels configuration. */
376     var_AddCallback (aout, "stereo-mode", aout_ChannelsRestart, NULL);
377     switch (var_GetInteger (aout, "stereo-mode"))
378     {
379         case AOUT_VAR_CHAN_RSTEREO:
380             fmt->i_original_channels |= AOUT_CHAN_REVERSESTEREO;
381             break;
382         case AOUT_VAR_CHAN_STEREO:
383             fmt->i_original_channels = AOUT_CHANS_STEREO;
384             break;
385         case AOUT_VAR_CHAN_LEFT:
386             fmt->i_original_channels = AOUT_CHAN_LEFT;
387             break;
388         case AOUT_VAR_CHAN_RIGHT:
389             fmt->i_original_channels = AOUT_CHAN_RIGHT;
390             break;
391         case AOUT_VAR_CHAN_DOLBYS:
392             fmt->i_original_channels = AOUT_CHANS_STEREO|AOUT_CHAN_DOLBYSTEREO;
393             break;
394         default:
395         {
396             if ((fmt->i_original_channels & AOUT_CHAN_PHYSMASK)
397                                                           != AOUT_CHANS_STEREO)
398                  break;
399
400             vlc_value_t val, txt;
401             val.i_int = 0;
402             var_Change (aout, "stereo-mode", VLC_VAR_DELCHOICE, &val, NULL);
403             txt.psz_string = _("Stereo audio mode");
404             var_Change (aout, "stereo-mode", VLC_VAR_SETTEXT, &txt, NULL);
405             if (fmt->i_original_channels & AOUT_CHAN_DOLBYSTEREO)
406             {
407                 val.i_int = AOUT_VAR_CHAN_DOLBYS;
408                 txt.psz_string = _("Dolby Surround");
409             }
410             else
411             {
412                 val.i_int = AOUT_VAR_CHAN_STEREO;
413                 txt.psz_string = _("Stereo");
414             }
415             var_Change (aout, "stereo-mode", VLC_VAR_ADDCHOICE, &val, &txt);
416             var_Change (aout, "stereo-mode", VLC_VAR_SETVALUE, &val, NULL);
417             val.i_int = AOUT_VAR_CHAN_LEFT;
418             txt.psz_string = _("Left");
419             var_Change (aout, "stereo-mode", VLC_VAR_ADDCHOICE, &val, &txt);
420             if (fmt->i_original_channels & AOUT_CHAN_DUALMONO)
421             {   /* Go directly to the left channel. */
422                 fmt->i_original_channels = AOUT_CHAN_LEFT;
423                 var_Change (aout, "stereo-mode", VLC_VAR_SETVALUE, &val, NULL);
424             }
425             val.i_int = AOUT_VAR_CHAN_RIGHT;
426             txt.psz_string = _("Right");
427             var_Change (aout, "stereo-mode", VLC_VAR_ADDCHOICE, &val, &txt);
428             val.i_int = AOUT_VAR_CHAN_RSTEREO;
429             txt.psz_string = _("Reverse stereo");
430             var_Change (aout, "stereo-mode", VLC_VAR_ADDCHOICE, &val, &txt);
431         }
432     }
433
434     aout_FormatPrepare (fmt);
435     aout_FormatPrint (aout, "output", fmt);
436     return 0;
437 }
438
439 /**
440  * Stops the audio output stream (undoes aout_OutputNew()).
441  * \note This can only be called after a succesful aout_OutputNew().
442  * \warning The caller must hold the audio output lock.
443  */
444 void aout_OutputDelete (audio_output_t *aout)
445 {
446     aout_OutputAssertLocked (aout);
447
448     var_DelCallback (aout, "stereo-mode", aout_ChannelsRestart, NULL);
449     if (aout->stop != NULL)
450         aout->stop (aout);
451 }
452
453 int aout_OutputTimeGet (audio_output_t *aout, mtime_t *delay)
454 {
455     aout_OutputAssertLocked (aout);
456
457     if (aout->time_get == NULL)
458         return -1;
459     return aout->time_get (aout, delay);
460 }
461
462 /**
463  * Plays a decoded audio buffer.
464  * \note This can only be called after a succesful aout_OutputNew().
465  * \warning The caller must hold the audio output lock.
466  */
467 void aout_OutputPlay (audio_output_t *aout, block_t *block)
468 {
469     aout_OutputAssertLocked (aout);
470     aout->play (aout, block);
471 }
472
473 static void PauseDefault (audio_output_t *aout, bool pause, mtime_t date)
474 {
475     if (pause)
476         aout_OutputFlush (aout, false);
477     (void) date;
478 }
479
480 /**
481  * Notifies the audio output (if any) of pause/resume events.
482  * This enables the output to expedite pause, instead of waiting for its
483  * buffers to drain.
484  * \note This can only be called after a succesful aout_OutputNew().
485  * \warning The caller must hold the audio output lock.
486  */
487 void aout_OutputPause( audio_output_t *aout, bool pause, mtime_t date )
488 {
489     aout_OutputAssertLocked (aout);
490     ((aout->pause != NULL) ? aout->pause : PauseDefault) (aout, pause, date);
491 }
492
493 /**
494  * Flushes or drains the audio output buffers.
495  * This enables the output to expedite seek and stop.
496  * \param wait if true, wait for buffer playback (i.e. drain),
497  *             if false, discard the buffers immediately (i.e. flush)
498  * \note This can only be called after a succesful aout_OutputNew().
499  * \warning The caller must hold the audio output lock.
500  */
501 void aout_OutputFlush( audio_output_t *aout, bool wait )
502 {
503     aout_OutputAssertLocked( aout );
504     aout->flush (aout, wait);
505 }
506
507 static int aout_OutputVolumeSet (audio_output_t *aout, float vol)
508 {
509     aout_OutputAssertLocked (aout);
510     return (aout->volume_set != NULL) ? aout->volume_set (aout, vol) : -1;
511 }
512
513 static int aout_OutputMuteSet (audio_output_t *aout, bool mute)
514 {
515     aout_OutputAssertLocked (aout);
516     return (aout->mute_set != NULL) ? aout->mute_set (aout, mute) : -1;
517 }
518
519 static int aout_OutputDeviceSet (audio_output_t *aout, const char *id)
520 {
521     aout_OutputAssertLocked (aout);
522     return (aout->device_select != NULL) ? aout->device_select (aout, id) : -1;
523 }
524
525 void aout_OutputLock (audio_output_t *aout)
526 {
527     aout_owner_t *owner = aout_owner (aout);
528
529     vlc_mutex_lock (&owner->lock);
530 }
531
532 static int aout_OutputTryLock (audio_output_t *aout)
533 {
534     aout_owner_t *owner = aout_owner (aout);
535
536     return vlc_mutex_trylock (&owner->lock);
537 }
538
539 void aout_OutputUnlock (audio_output_t *aout)
540 {
541     aout_owner_t *owner = aout_owner (aout);
542
543     vlc_assert_locked (&owner->lock);
544     vlc_mutex_lock (&owner->req.lock);
545
546     if (owner->req.device != unset_str)
547     {
548         aout_OutputDeviceSet (aout, owner->req.device);
549         free (owner->req.device);
550         owner->req.device = (char *)unset_str;
551     }
552
553     if (owner->req.volume >= 0.f)
554     {
555         aout_OutputVolumeSet (aout, owner->req.volume);
556         owner->req.volume = -1.f;
557     }
558
559     if (owner->req.mute >= 0)
560     {
561         aout_OutputMuteSet (aout, owner->req.mute);
562         owner->req.mute = -1;
563     }
564
565     vlc_mutex_unlock (&owner->lock);
566     /* If another thread is blocked waiting for owner->req.lock at this point,
567      * this aout_OutputUnlock() call will not see and apply its change request.
568      * The other thread will need to apply the change request itself, which
569      * implies it is able to (try-)lock owner->lock. Therefore this thread must
570      * release owner->lock _before_ owner->req.lock. Do not reorder!!! */
571     vlc_mutex_unlock (&owner->req.lock);
572 }
573
574 /**
575  * Gets the volume of the audio output stream (independent of mute).
576  * \return Current audio volume (0. = silent, 1. = nominal),
577  * or a strictly negative value if undefined.
578  */
579 float aout_VolumeGet (audio_output_t *aout)
580 {
581     return var_GetFloat (aout, "volume");
582 }
583
584 /**
585  * Sets the volume of the audio output stream.
586  * \note The mute status is not changed.
587  * \return 0 on success, -1 on failure (TODO).
588  */
589 int aout_VolumeSet (audio_output_t *aout, float vol)
590 {
591     aout_owner_t *owner = aout_owner (aout);
592
593     assert (vol >= 0.f);
594     vlc_mutex_lock (&owner->req.lock);
595     owner->req.volume = vol;
596     vlc_mutex_unlock (&owner->req.lock);
597
598     if (aout_OutputTryLock (aout) == 0)
599         aout_OutputUnlock (aout);
600     return 0;
601 }
602
603 /**
604  * Gets the audio output stream mute flag.
605  * \return 0 if not muted, 1 if muted, -1 if undefined.
606  */
607 int aout_MuteGet (audio_output_t *aout)
608 {
609     return var_InheritBool (aout, "mute");
610 }
611
612 /**
613  * Sets the audio output stream mute flag.
614  * \return 0 on success, -1 on failure (TODO).
615  */
616 int aout_MuteSet (audio_output_t *aout, bool mute)
617 {
618     aout_owner_t *owner = aout_owner (aout);
619
620     vlc_mutex_lock (&owner->req.lock);
621     owner->req.mute = mute;
622     vlc_mutex_unlock (&owner->req.lock);
623
624     if (aout_OutputTryLock (aout) == 0)
625         aout_OutputUnlock (aout);
626     return 0;
627 }
628
629 /**
630  * Gets the currently selected device.
631  * \return the selected device ID (caller must free() it)
632  *         NULL if no device is selected or in case of error.
633  */
634 char *aout_DeviceGet (audio_output_t *aout)
635 {
636     return var_GetNonEmptyString (aout, "device");
637 }
638
639 /**
640  * Selects an audio output device.
641  * \param id device ID to select, or NULL for the default device
642  * \return zero on success, non-zero on error (TODO).
643  */
644 int aout_DeviceSet (audio_output_t *aout, const char *id)
645 {
646     aout_owner_t *owner = aout_owner (aout);
647
648     char *dev = NULL;
649     if (id != NULL)
650     {
651         dev = strdup (id);
652         if (unlikely(dev == NULL))
653             return -1;
654     }
655
656     vlc_mutex_lock (&owner->req.lock);
657     if (owner->req.device != unset_str)
658         free (owner->req.device);
659     owner->req.device = dev;
660     vlc_mutex_unlock (&owner->req.lock);
661
662     if (aout_OutputTryLock (aout) == 0)
663         aout_OutputUnlock (aout);
664     return 0;
665 }
666
667 /**
668  * Enumerates possible audio output devices.
669  *
670  * The function will heap-allocate two tables of heap-allocated strings;
671  * the caller is responsible for freeing all strings and both tables.
672  *
673  * \param ids pointer to a table of device identifiers [OUT]
674  * \param names pointer to a table of device human-readable descriptions [OUT]
675  * \return the number of devices, or negative on error.
676  * \note In case of error, *ids and *names are undefined.
677  */
678 int aout_DevicesList (audio_output_t *aout, char ***ids, char ***names)
679 {
680     aout_owner_t *owner = aout_owner (aout);
681     char **tabid, **tabname;
682     unsigned count;
683
684     vlc_mutex_lock (&owner->dev.lock);
685     count = owner->dev.count;
686     tabid = xmalloc (sizeof (*tabid) * count);
687     tabname = xmalloc (sizeof (*tabname) * count);
688     *ids = tabid;
689     *names = tabname;
690     for (aout_dev_t *dev = owner->dev.list; dev != NULL; dev = dev->next)
691     {
692         *(tabid++) = xstrdup (dev->id);
693         *(tabname++) = xstrdup (dev->name);
694     }
695     vlc_mutex_unlock (&owner->dev.lock);
696
697     return count;
698 }