]> git.sesse.net Git - vlc/blob - modules/audio_output/oss.c
Do not forget to register aout_ChannelsRestart as the callback for
[vlc] / modules / audio_output / oss.c
1 /*****************************************************************************
2  * oss.c : OSS /dev/dsp module for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2002 VideoLAN
5  * $Id: oss.c,v 1.44 2003/01/13 14:51:25 massiot Exp $
6  *
7  * Authors: Michel Kaempf <maxx@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Christophe Massiot <massiot@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <errno.h>                                                 /* ENOMEM */
30 #include <fcntl.h>                                       /* open(), O_WRONLY */
31 #include <sys/ioctl.h>                                            /* ioctl() */
32 #include <string.h>                                            /* strerror() */
33 #include <unistd.h>                                      /* write(), close() */
34 #include <stdlib.h>                            /* calloc(), malloc(), free() */
35
36 #include <vlc/vlc.h>
37
38 #ifdef HAVE_ALLOCA_H
39 #   include <alloca.h>
40 #endif
41
42 #include <vlc/aout.h>
43
44 #include "aout_internal.h"
45
46 /* SNDCTL_DSP_RESET, SNDCTL_DSP_SETFMT, SNDCTL_DSP_STEREO, SNDCTL_DSP_SPEED,
47  * SNDCTL_DSP_GETOSPACE */
48 #ifdef HAVE_SOUNDCARD_H
49 #   include <soundcard.h>
50 #elif defined( HAVE_SYS_SOUNDCARD_H )
51 #   include <sys/soundcard.h>
52 #elif defined( HAVE_MACHINE_SOUNDCARD_H )
53 #   include <machine/soundcard.h>
54 #endif
55
56 /*****************************************************************************
57  * aout_sys_t: OSS audio output method descriptor
58  *****************************************************************************
59  * This structure is part of the audio output thread descriptor.
60  * It describes the dsp specific properties of an audio device.
61  *****************************************************************************/
62 struct aout_sys_t
63 {
64     int i_fd;
65     int b_workaround_buggy_driver;
66     int i_fragstotal;
67     mtime_t max_buffer_duration;
68 };
69
70 /* This must be a power of 2. */
71 #define FRAME_SIZE 1024
72 #define FRAME_COUNT 4
73
74 /*****************************************************************************
75  * Local prototypes
76  *****************************************************************************/
77 static int  Open         ( vlc_object_t * );
78 static void Close        ( vlc_object_t * );
79
80 static void Play         ( aout_instance_t * );
81 static int  OSSThread    ( aout_instance_t * );
82
83 static mtime_t BufferDuration( aout_instance_t * p_aout );
84
85 /*****************************************************************************
86  * Module descriptor
87  *****************************************************************************/
88 #define BUGGY_TEXT N_("Try to work around buggy OSS drivers")
89 #define BUGGY_LONGTEXT N_( \
90     "Some buggy OSS drivers just don't like when their internal buffers " \
91     "are completely filled (the sound gets heavily hashed). If you have one " \
92     "of these drivers, then you need to enable this option." )
93
94 #define SPDIF_TEXT N_("Try to use S/PDIF output")
95 #define SPDIF_LONGTEXT N_( \
96     "Sometimes we attempt to use the S/PDIF output, even if nothing is " \
97     "connected to it. Un-checking this option disables this behaviour, " \
98     "and permanently selects analog PCM output." )
99
100 vlc_module_begin();
101     add_category_hint( N_("OSS"), NULL );
102     add_file( "dspdev", "/dev/dsp", aout_FindAndRestart,
103               N_("OSS dsp device"), NULL );
104     add_bool( "oss-buggy", 0, NULL, BUGGY_TEXT, BUGGY_LONGTEXT );
105     add_bool( "spdif", 1, NULL, SPDIF_TEXT, SPDIF_LONGTEXT );
106     set_description( _("Linux OSS /dev/dsp module") );
107     set_capability( "audio output", 100 );
108     add_shortcut( "oss" );
109     set_callbacks( Open, Close );
110 vlc_module_end();
111
112 /*****************************************************************************
113  * Probe: probe the audio device for available formats and channels
114  *****************************************************************************/
115 static void Probe( aout_instance_t * p_aout )
116 {
117     struct aout_sys_t * p_sys = p_aout->output.p_sys;
118     vlc_value_t val;
119     int i_format, i_nb_channels;
120
121     var_Create( p_aout, "audio-device", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
122
123     if( ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 )
124     {
125         msg_Err( p_aout, "cannot reset OSS audio device" );
126         var_Destroy( p_aout, "audio-device" );
127         return;
128     }
129
130     if ( config_GetInt( p_aout, "spdif" )
131           && AOUT_FMT_NON_LINEAR( &p_aout->output.output ) )
132     {
133         i_format = AFMT_AC3;
134
135         if( ioctl( p_sys->i_fd, SNDCTL_DSP_SETFMT, &i_format ) >= 0
136              && i_format == AFMT_AC3 )
137         {
138             val.psz_string = N_("A/52 over S/PDIF");
139             var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
140         }
141     }
142
143     /* Go to PCM mode. */
144     i_format = AFMT_S16_NE;
145     if( ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 ||
146         ioctl( p_sys->i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0 )
147     {
148         return;
149     }
150
151 #ifdef SNDCTL_DSP_GETCHANNELMASK
152     if ( aout_FormatNbChannels( &p_aout->output.output ) > 2 )
153     {
154         /* Check that the device supports this. */
155
156         int i_chanmask;
157         if ( ioctl( p_sys->i_fd, SNDCTL_DSP_GETCHANNELMASK,
158                     &i_chanmask ) == 0 )
159         {
160             if ( !(i_chanmask & DSP_BIND_FRONT) )
161             {
162                 msg_Err( p_aout, "No front channels ! (%x)",
163                          i_chanmask );
164                 return;
165             }
166
167             if ( (i_chanmask & (DSP_BIND_SURR | DSP_BIND_CENTER_LFE))
168                   && (p_aout->output.output.i_physical_channels ==
169                        (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
170                          | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT
171                          | AOUT_CHAN_LFE)) )
172             {
173                 val.psz_string = N_("5.1");
174                 var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
175             }
176
177             if ( (i_chanmask & DSP_BIND_SURR)
178                   && (p_aout->output.output.i_physical_channels &
179                        (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
180                          | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT)) )
181             {
182                 val.psz_string = N_("2 Front 2 Rear");
183                 var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
184             }
185         }
186     }
187 #endif
188
189     /* Test for stereo. */
190     i_nb_channels = 2;
191     if( ioctl( p_sys->i_fd, SNDCTL_DSP_CHANNELS, &i_nb_channels ) >= 0
192          && i_nb_channels == 2 )
193     {
194         val.psz_string = N_("Stereo");
195         var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
196     }
197
198     /* Reset all. */
199     i_format = AFMT_S16_NE;
200     if( ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 ||
201         ioctl( p_sys->i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0 )
202     {
203         msg_Err( p_aout, "cannot reset OSS audio device" );
204         var_Destroy( p_aout, "audio-device" );
205         return;
206     }
207
208     /* Test for mono. */
209     i_nb_channels = 1;
210     if( ioctl( p_sys->i_fd, SNDCTL_DSP_CHANNELS, &i_nb_channels ) >= 0  
211          && i_nb_channels == 1 )
212     {
213         val.psz_string = N_("Mono");
214         var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );        
215     }
216
217
218     var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart,
219                      NULL );
220 }
221
222 /*****************************************************************************
223  * Open: open the audio device (the digital sound processor)
224  *****************************************************************************
225  * This function opens the dsp as a usual non-blocking write-only file, and
226  * modifies the p_aout->p_sys->i_fd with the file's descriptor.
227  *****************************************************************************/
228 static int Open( vlc_object_t *p_this )
229 {
230     aout_instance_t * p_aout = (aout_instance_t *)p_this;
231     struct aout_sys_t * p_sys;
232     char * psz_device;
233     vlc_value_t val;
234
235     /* Allocate structure */
236     p_aout->output.p_sys = p_sys = malloc( sizeof( aout_sys_t ) );
237     if( p_sys == NULL )
238     {
239         msg_Err( p_aout, "out of memory" );
240         return VLC_ENOMEM;
241     }
242
243     /* Get device name */
244     if( (psz_device = config_GetPsz( p_aout, "dspdev" )) == NULL )
245     {
246         msg_Err( p_aout, "no audio device given (maybe /dev/dsp ?)" );
247         free( p_sys );
248         return VLC_EGENERIC;
249     }
250
251     /* Open the sound device */
252     p_sys->i_fd = open( psz_device, O_WRONLY );
253     if( p_sys->i_fd < 0 )
254     {
255         msg_Err( p_aout, "cannot open audio device (%s)", psz_device );
256         free( p_sys );
257         return VLC_EGENERIC;
258     }
259     free( psz_device );
260
261     p_aout->output.pf_play = Play;
262
263     if ( var_Type( p_aout, "audio-device" ) == 0 )
264     {
265         Probe( p_aout );
266     }
267
268     if ( var_Get( p_aout, "audio-device", &val ) < 0 )
269     {
270         /* Probe() has failed. */
271         free( p_sys );
272         return VLC_EGENERIC;
273     }
274
275     if ( !strcmp( val.psz_string, N_("A/52 over S/PDIF") ) )
276     {
277         p_aout->output.output.i_format = VLC_FOURCC('s','p','d','i');
278     }
279     else if ( !strcmp( val.psz_string, N_("5.1") ) )
280     {
281         p_aout->output.output.i_format = AOUT_FMT_S16_NE;
282         p_aout->output.output.i_physical_channels
283             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
284                | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT
285                | AOUT_CHAN_LFE;
286     }
287     else if ( !strcmp( val.psz_string, N_("2 Front 2 Rear") ) )
288     {
289         p_aout->output.output.i_format = AOUT_FMT_S16_NE;
290         p_aout->output.output.i_physical_channels
291             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
292                | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT;
293     }
294     else if ( !strcmp( val.psz_string, N_("Stereo") ) )
295     {
296         p_aout->output.output.i_format = AOUT_FMT_S16_NE;
297         p_aout->output.output.i_physical_channels
298             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
299     }
300     else if ( !strcmp( val.psz_string, N_("Mono") ) )
301     {
302         p_aout->output.output.i_format = AOUT_FMT_S16_NE;
303         p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER;
304     }
305     else
306     {
307         /* This should not happen ! */
308         msg_Err( p_aout, "internal: can't find audio-device (%s)",
309                  val.psz_string );
310         free( p_sys );
311         return VLC_EGENERIC;
312     }
313     free( val.psz_string );
314
315     val.b_bool = VLC_TRUE;
316     var_Set( p_aout, "intf-change", val );
317
318     /* Reset the DSP device */
319     if( ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 )
320     {
321         msg_Err( p_aout, "cannot reset OSS audio device" );
322         close( p_sys->i_fd );
323         free( p_sys );
324         return VLC_EGENERIC;
325     }
326
327     /* Set the output format */
328     if ( AOUT_FMT_NON_LINEAR( &p_aout->output.output ) )
329     {
330         int i_format = AFMT_AC3;
331
332         if( ioctl( p_sys->i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0
333              || i_format != AFMT_AC3 )
334         {
335             msg_Err( p_aout, "cannot reset OSS audio device" );
336             close( p_sys->i_fd );
337             free( p_sys );
338             return VLC_EGENERIC;
339         }
340
341         p_aout->output.output.i_format = VLC_FOURCC('s','p','d','i');
342         p_aout->output.i_nb_samples = A52_FRAME_NB;
343         p_aout->output.output.i_bytes_per_frame = AOUT_SPDIF_SIZE;
344         p_aout->output.output.i_frame_length = A52_FRAME_NB;
345
346         aout_VolumeNoneInit( p_aout );
347     }
348
349     if ( !AOUT_FMT_NON_LINEAR( &p_aout->output.output ) )
350     {
351         unsigned int i_format = AFMT_S16_NE;
352         unsigned int i_frame_size, i_fragments;
353         unsigned int i_rate;
354         unsigned int i_nb_channels;
355         audio_buf_info audio_buf;
356
357         if( ioctl( p_sys->i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0 )
358         {
359             msg_Err( p_aout, "cannot set audio output format" );
360             close( p_sys->i_fd );
361             free( p_sys );
362             return VLC_EGENERIC;
363         }
364
365         switch ( i_format )
366         {
367         case AFMT_U8:
368             p_aout->output.output.i_format = VLC_FOURCC('u','8',' ',' ');
369             break;
370         case AFMT_S8:
371             p_aout->output.output.i_format = VLC_FOURCC('s','8',' ',' ');
372             break;
373         case AFMT_U16_LE:
374             p_aout->output.output.i_format = VLC_FOURCC('u','1','6','l');
375             break;
376         case AFMT_S16_LE:
377             p_aout->output.output.i_format = VLC_FOURCC('s','1','6','l');
378             break;
379         case AFMT_U16_BE:
380             p_aout->output.output.i_format = VLC_FOURCC('u','1','6','b');
381             break;
382         case AFMT_S16_BE:
383             p_aout->output.output.i_format = VLC_FOURCC('s','1','6','b');
384             break;
385         default:
386             msg_Err( p_aout, "OSS fell back to an unknown format (%d)",
387                      i_format );
388             close( p_sys->i_fd );
389             free( p_sys );
390             return VLC_EGENERIC;
391         }
392
393         i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
394
395         /* Set the number of channels */
396         if( ioctl( p_sys->i_fd, SNDCTL_DSP_CHANNELS, &i_nb_channels ) < 0 ||
397             i_nb_channels != aout_FormatNbChannels( &p_aout->output.output ) )
398         {
399             msg_Err( p_aout, "cannot set number of audio channels (%s)",
400                      aout_FormatPrintChannels( &p_aout->output.output) );
401             close( p_sys->i_fd );
402             free( p_sys );
403             return VLC_EGENERIC;
404         }
405
406         /* Set the output rate */
407         i_rate = p_aout->output.output.i_rate;
408         if( ioctl( p_sys->i_fd, SNDCTL_DSP_SPEED, &i_rate ) < 0 )
409         {
410             msg_Err( p_aout, "cannot set audio output rate (%i)",
411                              p_aout->output.output.i_rate );
412             close( p_sys->i_fd );
413             free( p_sys );
414             return VLC_EGENERIC;
415         }
416
417         if( i_rate != p_aout->output.output.i_rate )
418         {
419             p_aout->output.output.i_rate = i_rate;
420         }
421
422         /* Set the fragment size */
423         aout_FormatPrepare( &p_aout->output.output );
424
425         /* i_fragment = xxxxyyyy where: xxxx        is fragtotal
426          *                              1 << yyyy   is fragsize */
427         i_fragments = 0;
428         i_frame_size = FRAME_SIZE * p_aout->output.output.i_bytes_per_frame;
429         while( i_frame_size >>= 1 )
430         {
431             ++i_fragments;
432         }
433         i_fragments |= FRAME_COUNT << 16;
434         if( ioctl( p_sys->i_fd, SNDCTL_DSP_SETFRAGMENT, &i_fragments ) < 0 )
435         {
436             msg_Warn( p_aout, "cannot set fragment size (%.8x)", i_fragments );
437         }
438
439         if( ioctl( p_sys->i_fd, SNDCTL_DSP_GETOSPACE, &audio_buf ) < 0 )
440         {
441             msg_Err( p_aout, "cannot get fragment size" );
442             close( p_sys->i_fd );
443             free( p_sys );
444             return VLC_EGENERIC;
445         }
446         else
447         {
448             /* Number of fragments actually allocated */
449             p_aout->output.p_sys->i_fragstotal = audio_buf.fragstotal;
450
451             /* Maximum duration the soundcard's buffer can hold */
452             p_aout->output.p_sys->max_buffer_duration =
453                 (mtime_t)audio_buf.fragstotal * audio_buf.fragsize * 1000000
454                 / p_aout->output.output.i_bytes_per_frame
455                 / p_aout->output.output.i_rate
456                 * p_aout->output.output.i_frame_length;
457
458             p_aout->output.i_nb_samples = audio_buf.fragsize /
459                 p_aout->output.output.i_bytes_per_frame;
460         }
461
462         aout_VolumeSoftInit( p_aout );
463     }
464
465     p_aout->output.p_sys->b_workaround_buggy_driver =
466         config_GetInt( p_aout, "oss-buggy" );
467
468     /* Create OSS thread and wait for its readiness. */
469     if( vlc_thread_create( p_aout, "aout", OSSThread,
470                            VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
471     {
472         msg_Err( p_aout, "cannot create OSS thread (%s)", strerror(errno) );
473         close( p_sys->i_fd );
474         free( p_sys );
475         return VLC_ETHREAD;
476     }
477
478     return VLC_SUCCESS;
479 }
480
481 /*****************************************************************************
482  * Play: nothing to do
483  *****************************************************************************/
484 static void Play( aout_instance_t *p_aout )
485 {
486 }
487
488 /*****************************************************************************
489  * Close: close the dsp audio device
490  *****************************************************************************/
491 static void Close( vlc_object_t * p_this )
492 {
493     aout_instance_t *p_aout = (aout_instance_t *)p_this;
494     struct aout_sys_t * p_sys = p_aout->output.p_sys;
495
496     p_aout->b_die = VLC_TRUE;
497     vlc_thread_join( p_aout );
498     p_aout->b_die = VLC_FALSE;
499
500     ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL );
501     close( p_sys->i_fd );
502
503     free( p_sys );
504 }
505
506 /*****************************************************************************
507  * BufferDuration: buffer status query
508  *****************************************************************************
509  * This function returns the duration in microseconds of the current buffer.
510  *****************************************************************************/
511 static mtime_t BufferDuration( aout_instance_t * p_aout )
512 {
513     struct aout_sys_t * p_sys = p_aout->output.p_sys;
514     audio_buf_info audio_buf;
515     int i_bytes;
516
517     /* Fill the audio_buf_info structure:
518      * - fragstotal: total number of fragments allocated
519      * - fragsize: size of a fragment in bytes
520      * - bytes: available space in bytes (includes partially used fragments)
521      * Note! 'bytes' could be more than fragments*fragsize */
522     ioctl( p_sys->i_fd, SNDCTL_DSP_GETOSPACE, &audio_buf );
523
524     /* calculate number of available fragments (not partially used ones) */
525     i_bytes = (audio_buf.fragstotal * audio_buf.fragsize) - audio_buf.bytes;
526
527     /* Return the fragment duration */
528     return (mtime_t)i_bytes * 1000000
529             / p_aout->output.output.i_bytes_per_frame
530             / p_aout->output.output.i_rate
531             * p_aout->output.output.i_frame_length;
532 }
533
534 /*****************************************************************************
535  * OSSThread: asynchronous thread used to DMA the data to the device
536  *****************************************************************************/
537 static int OSSThread( aout_instance_t * p_aout )
538 {
539     struct aout_sys_t * p_sys = p_aout->output.p_sys;
540     mtime_t next_date = 0;
541
542     while ( !p_aout->b_die )
543     {
544         aout_buffer_t * p_buffer = NULL;
545         int i_tmp, i_size;
546         byte_t * p_bytes;
547
548         if ( p_aout->output.output.i_format != VLC_FOURCC('s','p','d','i') )
549         {
550             mtime_t buffered = BufferDuration( p_aout );
551
552             if( p_aout->output.p_sys->b_workaround_buggy_driver )
553             {
554 #define i_fragstotal p_aout->output.p_sys->i_fragstotal
555                 /* Wait a bit - we don't want our buffer to be full */
556                 if( buffered > (p_aout->output.p_sys->max_buffer_duration
557                                 / i_fragstotal * (i_fragstotal - 1)) )
558                 {
559                     msleep((p_aout->output.p_sys->max_buffer_duration
560                                 / i_fragstotal ));
561                     buffered = BufferDuration( p_aout );
562                 }
563 #undef i_fragstotal
564             }
565
566             /* Next buffer will be played at mdate() + buffered */
567             p_buffer = aout_OutputNextBuffer( p_aout, mdate() + buffered,
568                                               VLC_FALSE );
569
570             if( p_buffer == NULL &&
571                 buffered > ( p_aout->output.p_sys->max_buffer_duration
572                              / p_aout->output.p_sys->i_fragstotal ) )
573             {
574                 /* If we have at least a fragment full, then we can wait a
575                  * little and retry to get a new audio buffer instead of
576                  * playing a blank sample */
577                 msleep( ( p_aout->output.p_sys->max_buffer_duration
578                           / p_aout->output.p_sys->i_fragstotal / 2 ) );
579                 continue;
580             }
581         }
582         else
583         {
584             /* emu10k1 driver does not report Buffer Duration correctly in
585              * passthrough mode so we have to cheat */
586             if( !next_date )
587             {
588                 next_date = mdate();
589             }
590             else
591             {
592                 mtime_t delay = next_date - mdate();
593                 if( delay > AOUT_PTS_TOLERANCE )
594                 {
595                     msleep( delay / 2 );
596                 }
597             }
598             
599             while( !p_aout->b_die && ! ( p_buffer =
600                 aout_OutputNextBuffer( p_aout, next_date, VLC_TRUE ) ) )
601             {
602                 msleep( 1000 );
603                 next_date = mdate();
604             }
605         }
606
607         if ( p_buffer != NULL )
608         {
609             p_bytes = p_buffer->p_buffer;
610             i_size = p_buffer->i_nb_bytes;
611             /* This is theoretical ... we'll see next iteration whether
612              * we're drifting */
613             next_date += p_buffer->end_date - p_buffer->start_date;
614         }
615         else
616         {
617             i_size = FRAME_SIZE / p_aout->output.output.i_frame_length
618                       * p_aout->output.output.i_bytes_per_frame;
619             p_bytes = malloc( i_size );
620             memset( p_bytes, 0, i_size );
621             next_date = 0;
622         }
623
624         i_tmp = write( p_sys->i_fd, p_bytes, i_size );
625
626         if( i_tmp < 0 )
627         {
628             msg_Err( p_aout, "write failed (%s)", strerror(errno) );
629         }
630
631         if ( p_buffer != NULL )
632         {
633             aout_BufferFree( p_buffer );
634         }
635         else
636         {
637             free( p_bytes );
638         }
639     }
640
641     return VLC_SUCCESS;
642 }