]> git.sesse.net Git - vlc/blob - modules/audio_output/oss.c
6d47adb147e21f3112cbd935f69161c8c8666521
[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.49 2003/02/02 00:57:21 jobi 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         if ( p_aout->output.output.i_physical_channels == AOUT_CHAN_CENTER )
216         {
217             var_Set( p_aout, "audio-device", val );
218         }
219     }
220
221
222     var_AddCallback( p_aout, "audio-device", aout_ChannelsRestart,
223                      NULL );
224 }
225
226 /*****************************************************************************
227  * Open: open the audio device (the digital sound processor)
228  *****************************************************************************
229  * This function opens the dsp as a usual non-blocking write-only file, and
230  * modifies the p_aout->p_sys->i_fd with the file's descriptor.
231  *****************************************************************************/
232 static int Open( vlc_object_t *p_this )
233 {
234     aout_instance_t * p_aout = (aout_instance_t *)p_this;
235     struct aout_sys_t * p_sys;
236     char * psz_device;
237     vlc_value_t val;
238
239     /* Allocate structure */
240     p_aout->output.p_sys = p_sys = malloc( sizeof( aout_sys_t ) );
241     if( p_sys == NULL )
242     {
243         msg_Err( p_aout, "out of memory" );
244         return VLC_ENOMEM;
245     }
246
247     /* Get device name */
248     if( (psz_device = config_GetPsz( p_aout, "dspdev" )) == NULL )
249     {
250         msg_Err( p_aout, "no audio device given (maybe /dev/dsp ?)" );
251         free( p_sys );
252         return VLC_EGENERIC;
253     }
254
255     /* Open the sound device */
256     p_sys->i_fd = open( psz_device, O_WRONLY | O_NDELAY );
257     if( p_sys->i_fd < 0 )
258     {
259         msg_Err( p_aout, "cannot open audio device (%s)", psz_device );
260         free( p_sys );
261         return VLC_EGENERIC;
262     }
263
264     /* if the opening was ok, put the device back in blocking mode */
265     fcntl( p_sys->i_fd, F_SETFL,
266             fcntl( p_sys->i_fd, F_GETFL ) &~ FNDELAY );
267
268     free( psz_device );
269
270     p_aout->output.pf_play = Play;
271
272     if ( var_Type( p_aout, "audio-device" ) == 0 )
273     {
274         Probe( p_aout );
275     }
276
277     if ( var_Get( p_aout, "audio-device", &val ) < 0 )
278     {
279         /* Probe() has failed. */
280         free( p_sys );
281         return VLC_EGENERIC;
282     }
283
284     if ( !strcmp( val.psz_string, N_("A/52 over S/PDIF") ) )
285     {
286         p_aout->output.output.i_format = VLC_FOURCC('s','p','d','i');
287     }
288     else if ( !strcmp( val.psz_string, N_("5.1") ) )
289     {
290         p_aout->output.output.i_format = AOUT_FMT_S16_NE;
291         p_aout->output.output.i_physical_channels
292             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
293                | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT
294                | AOUT_CHAN_LFE;
295     }
296     else if ( !strcmp( val.psz_string, N_("2 Front 2 Rear") ) )
297     {
298         p_aout->output.output.i_format = AOUT_FMT_S16_NE;
299         p_aout->output.output.i_physical_channels
300             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
301                | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARLEFT;
302     }
303     else if ( !strcmp( val.psz_string, N_("Stereo") ) )
304     {
305         p_aout->output.output.i_format = AOUT_FMT_S16_NE;
306         p_aout->output.output.i_physical_channels
307             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
308     }
309     else if ( !strcmp( val.psz_string, N_("Mono") ) )
310     {
311         p_aout->output.output.i_format = AOUT_FMT_S16_NE;
312         p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER;
313     }
314     else
315     {
316         /* This should not happen ! */
317         msg_Err( p_aout, "internal: can't find audio-device (%s)",
318                  val.psz_string );
319         free( p_sys );
320         return VLC_EGENERIC;
321     }
322     free( val.psz_string );
323
324     val.b_bool = VLC_TRUE;
325     var_Set( p_aout, "intf-change", val );
326
327     /* Reset the DSP device */
328     if( ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 )
329     {
330         msg_Err( p_aout, "cannot reset OSS audio device" );
331         close( p_sys->i_fd );
332         free( p_sys );
333         return VLC_EGENERIC;
334     }
335
336     /* Set the output format */
337     if ( AOUT_FMT_NON_LINEAR( &p_aout->output.output ) )
338     {
339         int i_format = AFMT_AC3;
340
341         if( ioctl( p_sys->i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0
342              || i_format != AFMT_AC3 )
343         {
344             msg_Err( p_aout, "cannot reset OSS audio device" );
345             close( p_sys->i_fd );
346             free( p_sys );
347             return VLC_EGENERIC;
348         }
349
350         p_aout->output.output.i_format = VLC_FOURCC('s','p','d','i');
351         p_aout->output.i_nb_samples = A52_FRAME_NB;
352         p_aout->output.output.i_bytes_per_frame = AOUT_SPDIF_SIZE;
353         p_aout->output.output.i_frame_length = A52_FRAME_NB;
354
355         aout_VolumeNoneInit( p_aout );
356     }
357
358     if ( !AOUT_FMT_NON_LINEAR( &p_aout->output.output ) )
359     {
360         unsigned int i_format = AFMT_S16_NE;
361         unsigned int i_frame_size, i_fragments;
362         unsigned int i_rate;
363         unsigned int i_nb_channels;
364         audio_buf_info audio_buf;
365
366         if( ioctl( p_sys->i_fd, SNDCTL_DSP_SETFMT, &i_format ) < 0 )
367         {
368             msg_Err( p_aout, "cannot set audio output format" );
369             close( p_sys->i_fd );
370             free( p_sys );
371             return VLC_EGENERIC;
372         }
373
374         switch ( i_format )
375         {
376         case AFMT_U8:
377             p_aout->output.output.i_format = VLC_FOURCC('u','8',' ',' ');
378             break;
379         case AFMT_S8:
380             p_aout->output.output.i_format = VLC_FOURCC('s','8',' ',' ');
381             break;
382         case AFMT_U16_LE:
383             p_aout->output.output.i_format = VLC_FOURCC('u','1','6','l');
384             break;
385         case AFMT_S16_LE:
386             p_aout->output.output.i_format = VLC_FOURCC('s','1','6','l');
387             break;
388         case AFMT_U16_BE:
389             p_aout->output.output.i_format = VLC_FOURCC('u','1','6','b');
390             break;
391         case AFMT_S16_BE:
392             p_aout->output.output.i_format = VLC_FOURCC('s','1','6','b');
393             break;
394         default:
395             msg_Err( p_aout, "OSS fell back to an unknown format (%d)",
396                      i_format );
397             close( p_sys->i_fd );
398             free( p_sys );
399             return VLC_EGENERIC;
400         }
401
402         i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
403
404         /* Set the number of channels */
405         if( ioctl( p_sys->i_fd, SNDCTL_DSP_CHANNELS, &i_nb_channels ) < 0 ||
406             i_nb_channels != aout_FormatNbChannels( &p_aout->output.output ) )
407         {
408             msg_Err( p_aout, "cannot set number of audio channels (%s)",
409                      aout_FormatPrintChannels( &p_aout->output.output) );
410             close( p_sys->i_fd );
411             free( p_sys );
412             return VLC_EGENERIC;
413         }
414
415         /* Set the output rate */
416         i_rate = p_aout->output.output.i_rate;
417         if( ioctl( p_sys->i_fd, SNDCTL_DSP_SPEED, &i_rate ) < 0 )
418         {
419             msg_Err( p_aout, "cannot set audio output rate (%i)",
420                              p_aout->output.output.i_rate );
421             close( p_sys->i_fd );
422             free( p_sys );
423             return VLC_EGENERIC;
424         }
425
426         if( i_rate != p_aout->output.output.i_rate )
427         {
428             p_aout->output.output.i_rate = i_rate;
429         }
430
431         /* Set the fragment size */
432         aout_FormatPrepare( &p_aout->output.output );
433
434         /* i_fragment = xxxxyyyy where: xxxx        is fragtotal
435          *                              1 << yyyy   is fragsize */
436         i_fragments = 0;
437         i_frame_size = FRAME_SIZE * p_aout->output.output.i_bytes_per_frame;
438         while( i_frame_size >>= 1 )
439         {
440             ++i_fragments;
441         }
442         i_fragments |= FRAME_COUNT << 16;
443         if( ioctl( p_sys->i_fd, SNDCTL_DSP_SETFRAGMENT, &i_fragments ) < 0 )
444         {
445             msg_Warn( p_aout, "cannot set fragment size (%.8x)", i_fragments );
446         }
447
448         if( ioctl( p_sys->i_fd, SNDCTL_DSP_GETOSPACE, &audio_buf ) < 0 )
449         {
450             msg_Err( p_aout, "cannot get fragment size" );
451             close( p_sys->i_fd );
452             free( p_sys );
453             return VLC_EGENERIC;
454         }
455         else
456         {
457             /* Number of fragments actually allocated */
458             p_aout->output.p_sys->i_fragstotal = audio_buf.fragstotal;
459
460             /* Maximum duration the soundcard's buffer can hold */
461             p_aout->output.p_sys->max_buffer_duration =
462                 (mtime_t)audio_buf.fragstotal * audio_buf.fragsize * 1000000
463                 / p_aout->output.output.i_bytes_per_frame
464                 / p_aout->output.output.i_rate
465                 * p_aout->output.output.i_frame_length;
466
467             p_aout->output.i_nb_samples = audio_buf.fragsize /
468                 p_aout->output.output.i_bytes_per_frame;
469         }
470
471         aout_VolumeSoftInit( p_aout );
472     }
473
474     p_aout->output.p_sys->b_workaround_buggy_driver =
475         config_GetInt( p_aout, "oss-buggy" );
476
477     /* Create OSS thread and wait for its readiness. */
478     if( vlc_thread_create( p_aout, "aout", OSSThread,
479                            VLC_THREAD_PRIORITY_OUTPUT, VLC_FALSE ) )
480     {
481         msg_Err( p_aout, "cannot create OSS thread (%s)", strerror(errno) );
482         close( p_sys->i_fd );
483         free( p_sys );
484         return VLC_ETHREAD;
485     }
486
487     return VLC_SUCCESS;
488 }
489
490 /*****************************************************************************
491  * Play: nothing to do
492  *****************************************************************************/
493 static void Play( aout_instance_t *p_aout )
494 {
495 }
496
497 /*****************************************************************************
498  * Close: close the dsp audio device
499  *****************************************************************************/
500 static void Close( vlc_object_t * p_this )
501 {
502     aout_instance_t *p_aout = (aout_instance_t *)p_this;
503     struct aout_sys_t * p_sys = p_aout->output.p_sys;
504
505     p_aout->b_die = VLC_TRUE;
506     vlc_thread_join( p_aout );
507     p_aout->b_die = VLC_FALSE;
508
509     ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL );
510     close( p_sys->i_fd );
511
512     free( p_sys );
513 }
514
515 /*****************************************************************************
516  * BufferDuration: buffer status query
517  *****************************************************************************
518  * This function returns the duration in microseconds of the current buffer.
519  *****************************************************************************/
520 static mtime_t BufferDuration( aout_instance_t * p_aout )
521 {
522     struct aout_sys_t * p_sys = p_aout->output.p_sys;
523     audio_buf_info audio_buf;
524     int i_bytes;
525
526     /* Fill the audio_buf_info structure:
527      * - fragstotal: total number of fragments allocated
528      * - fragsize: size of a fragment in bytes
529      * - bytes: available space in bytes (includes partially used fragments)
530      * Note! 'bytes' could be more than fragments*fragsize */
531     ioctl( p_sys->i_fd, SNDCTL_DSP_GETOSPACE, &audio_buf );
532
533     /* calculate number of available fragments (not partially used ones) */
534     i_bytes = (audio_buf.fragstotal * audio_buf.fragsize) - audio_buf.bytes;
535
536     /* Return the fragment duration */
537     return (mtime_t)i_bytes * 1000000
538             / p_aout->output.output.i_bytes_per_frame
539             / p_aout->output.output.i_rate
540             * p_aout->output.output.i_frame_length;
541 }
542
543 /*****************************************************************************
544  * OSSThread: asynchronous thread used to DMA the data to the device
545  *****************************************************************************/
546 static int OSSThread( aout_instance_t * p_aout )
547 {
548     struct aout_sys_t * p_sys = p_aout->output.p_sys;
549     mtime_t next_date = 0;
550
551     while ( !p_aout->b_die )
552     {
553         aout_buffer_t * p_buffer = NULL;
554         int i_tmp, i_size;
555         byte_t * p_bytes;
556
557         if ( p_aout->output.output.i_format != VLC_FOURCC('s','p','d','i') )
558         {
559             mtime_t buffered = BufferDuration( p_aout );
560
561             if( p_aout->output.p_sys->b_workaround_buggy_driver )
562             {
563 #define i_fragstotal p_aout->output.p_sys->i_fragstotal
564                 /* Wait a bit - we don't want our buffer to be full */
565                 if( buffered > (p_aout->output.p_sys->max_buffer_duration
566                                 / i_fragstotal * (i_fragstotal - 1)) )
567                 {
568                     msleep((p_aout->output.p_sys->max_buffer_duration
569                                 / i_fragstotal ));
570                     buffered = BufferDuration( p_aout );
571                 }
572 #undef i_fragstotal
573             }
574
575             /* Next buffer will be played at mdate() + buffered */
576             p_buffer = aout_OutputNextBuffer( p_aout, mdate() + buffered,
577                                               VLC_FALSE );
578
579             if( p_buffer == NULL &&
580                 buffered > ( p_aout->output.p_sys->max_buffer_duration
581                              / p_aout->output.p_sys->i_fragstotal ) )
582             {
583                 /* If we have at least a fragment full, then we can wait a
584                  * little and retry to get a new audio buffer instead of
585                  * playing a blank sample */
586                 msleep( ( p_aout->output.p_sys->max_buffer_duration
587                           / p_aout->output.p_sys->i_fragstotal / 2 ) );
588                 continue;
589             }
590         }
591         else
592         {
593             /* emu10k1 driver does not report Buffer Duration correctly in
594              * passthrough mode so we have to cheat */
595             if( !next_date )
596             {
597                 next_date = mdate();
598             }
599             else
600             {
601                 mtime_t delay = next_date - mdate();
602                 if( delay > AOUT_PTS_TOLERANCE )
603                 {
604                     msleep( delay / 2 );
605                 }
606             }
607
608             while( !p_aout->b_die && ! ( p_buffer =
609                 aout_OutputNextBuffer( p_aout, next_date, VLC_TRUE ) ) )
610             {
611                 msleep( 1000 );
612                 next_date = mdate();
613             }
614         }
615
616         if ( p_buffer != NULL )
617         {
618             p_bytes = p_buffer->p_buffer;
619             i_size = p_buffer->i_nb_bytes;
620             /* This is theoretical ... we'll see next iteration whether
621              * we're drifting */
622             next_date += p_buffer->end_date - p_buffer->start_date;
623         }
624         else
625         {
626             i_size = FRAME_SIZE / p_aout->output.output.i_frame_length
627                       * p_aout->output.output.i_bytes_per_frame;
628             p_bytes = malloc( i_size );
629             memset( p_bytes, 0, i_size );
630             next_date = 0;
631         }
632
633         i_tmp = write( p_sys->i_fd, p_bytes, i_size );
634
635         if( i_tmp < 0 )
636         {
637             msg_Err( p_aout, "write failed (%s)", strerror(errno) );
638         }
639
640         if ( p_buffer != NULL )
641         {
642             aout_BufferFree( p_buffer );
643         }
644         else
645         {
646             free( p_bytes );
647         }
648     }
649
650     return VLC_SUCCESS;
651 }