]> git.sesse.net Git - vlc/blob - src/audio_output/output.c
aout: privatize the lock
[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 the VideoLAN team
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
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 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 General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <assert.h>
32 #include <vlc_common.h>
33 #include <vlc_aout.h>
34 #include <vlc_aout_intf.h>
35 #include <vlc_cpu.h>
36 #include <vlc_modules.h>
37
38 #include "libvlc.h"
39 #include "aout_internal.h"
40
41 /*****************************************************************************
42  * aout_OutputNew : allocate a new output and rework the filter pipeline
43  *****************************************************************************
44  * This function is entered with the mixer lock.
45  *****************************************************************************/
46 int aout_OutputNew( audio_output_t *p_aout,
47                     const audio_sample_format_t * p_format )
48 {
49     aout_owner_t *owner = aout_owner (p_aout);
50
51     aout_assert_locked( p_aout );
52     p_aout->format = *p_format;
53
54     /* Retrieve user defaults. */
55     int i_rate = var_InheritInteger( p_aout, "aout-rate" );
56     if ( i_rate != 0 )
57         p_aout->format.i_rate = i_rate;
58     aout_FormatPrepare( &p_aout->format );
59
60     /* Find the best output plug-in. */
61     owner->module = module_need (p_aout, "audio output", "$aout", false);
62     if (owner->module == NULL)
63     {
64         msg_Err( p_aout, "no suitable audio output module" );
65         return -1;
66     }
67
68     if ( var_Type( p_aout, "audio-channels" ) ==
69              (VLC_VAR_INTEGER | VLC_VAR_HASCHOICE) )
70     {
71         /* The user may have selected a different channels configuration. */
72         switch( var_InheritInteger( p_aout, "audio-channels" ) )
73         {
74             case AOUT_VAR_CHAN_RSTEREO:
75                 p_aout->format.i_original_channels |= AOUT_CHAN_REVERSESTEREO;
76                 break;
77             case AOUT_VAR_CHAN_STEREO:
78                 p_aout->format.i_original_channels =
79                                               AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
80                 break;
81             case AOUT_VAR_CHAN_LEFT:
82                 p_aout->format.i_original_channels = AOUT_CHAN_LEFT;
83                 break;
84             case AOUT_VAR_CHAN_RIGHT:
85                 p_aout->format.i_original_channels = AOUT_CHAN_RIGHT;
86                 break;
87             case AOUT_VAR_CHAN_DOLBYS:
88                 p_aout->format.i_original_channels =
89                       AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_DOLBYSTEREO;
90                 break;
91         }
92     }
93     else if ( p_aout->format.i_physical_channels == AOUT_CHAN_CENTER
94               && (p_aout->format.i_original_channels
95                    & AOUT_CHAN_PHYSMASK) == (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT) )
96     {
97         vlc_value_t val, text;
98
99         /* Mono - create the audio-channels variable. */
100         var_Create( p_aout, "audio-channels",
101                     VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
102         text.psz_string = _("Audio Channels");
103         var_Change( p_aout, "audio-channels", VLC_VAR_SETTEXT, &text, NULL );
104
105         val.i_int = AOUT_VAR_CHAN_STEREO; text.psz_string = _("Stereo");
106         var_Change( p_aout, "audio-channels", VLC_VAR_ADDCHOICE, &val, &text );
107         val.i_int = AOUT_VAR_CHAN_LEFT; text.psz_string = _("Left");
108         var_Change( p_aout, "audio-channels", VLC_VAR_ADDCHOICE, &val, &text );
109         val.i_int = AOUT_VAR_CHAN_RIGHT; text.psz_string = _("Right");
110         var_Change( p_aout, "audio-channels", VLC_VAR_ADDCHOICE, &val, &text );
111         if ( p_aout->format.i_original_channels & AOUT_CHAN_DUALMONO )
112         {
113             /* Go directly to the left channel. */
114             p_aout->format.i_original_channels = AOUT_CHAN_LEFT;
115             var_SetInteger( p_aout, "audio-channels", AOUT_VAR_CHAN_LEFT );
116         }
117         var_AddCallback( p_aout, "audio-channels", aout_ChannelsRestart,
118                          NULL );
119     }
120     else if ( p_aout->format.i_physical_channels ==
121                (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)
122                 && (p_aout->format.i_original_channels &
123                      (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT)) )
124     {
125         vlc_value_t val, text;
126
127         /* Stereo - create the audio-channels variable. */
128         var_Create( p_aout, "audio-channels",
129                     VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
130         text.psz_string = _("Audio Channels");
131         var_Change( p_aout, "audio-channels", VLC_VAR_SETTEXT, &text, NULL );
132
133         if ( p_aout->format.i_original_channels & AOUT_CHAN_DOLBYSTEREO )
134         {
135             val.i_int = AOUT_VAR_CHAN_DOLBYS;
136             text.psz_string = _("Dolby Surround");
137         }
138         else
139         {
140             val.i_int = AOUT_VAR_CHAN_STEREO;
141             text.psz_string = _("Stereo");
142         }
143         var_Change( p_aout, "audio-channels", VLC_VAR_ADDCHOICE, &val, &text );
144         val.i_int = AOUT_VAR_CHAN_LEFT; text.psz_string = _("Left");
145         var_Change( p_aout, "audio-channels", VLC_VAR_ADDCHOICE, &val, &text );
146         val.i_int = AOUT_VAR_CHAN_RIGHT; text.psz_string = _("Right");
147         var_Change( p_aout, "audio-channels", VLC_VAR_ADDCHOICE, &val, &text );
148         val.i_int = AOUT_VAR_CHAN_RSTEREO; text.psz_string=_("Reverse stereo");
149         var_Change( p_aout, "audio-channels", VLC_VAR_ADDCHOICE, &val, &text );
150         if ( p_aout->format.i_original_channels & AOUT_CHAN_DUALMONO )
151         {
152             /* Go directly to the left channel. */
153             p_aout->format.i_original_channels = AOUT_CHAN_LEFT;
154             var_SetInteger( p_aout, "audio-channels", AOUT_VAR_CHAN_LEFT );
155         }
156         var_AddCallback( p_aout, "audio-channels", aout_ChannelsRestart,
157                          NULL );
158     }
159     var_TriggerCallback( p_aout, "intf-change" );
160
161     aout_FormatPrepare( &p_aout->format );
162     aout_FormatPrint( p_aout, "output", &p_aout->format );
163
164     /* Choose the mixer format. */
165     owner->mixer_format = p_aout->format;
166     if (AOUT_FMT_NON_LINEAR(&p_aout->format))
167         owner->mixer_format.i_format = p_format->i_format;
168     else
169     /* Most audio filters can only deal with single-precision,
170      * so lets always use that when hardware supports floating point. */
171     if( HAVE_FPU )
172         owner->mixer_format.i_format = VLC_CODEC_FL32;
173     else
174     /* Otherwise, audio filters will not work. Use fixed-point if the input has
175      * more than 16-bits depth. */
176     if( p_format->i_bitspersample > 16 )
177         owner->mixer_format.i_format = VLC_CODEC_FI32;
178     else
179     /* Fallback to 16-bits. This avoids pointless conversion to and from
180      * 32-bits samples for the sole purpose of software mixing. */
181         owner->mixer_format.i_format = VLC_CODEC_S16N;
182
183     aout_FormatPrepare (&owner->mixer_format);
184     aout_FormatPrint (p_aout, "mixer", &owner->mixer_format);
185
186     /* Create filters. */
187     owner->nb_filters = 0;
188     if (aout_FiltersCreatePipeline (p_aout, owner->filters,
189                                     &owner->nb_filters, &owner->mixer_format,
190                                     &p_aout->format) < 0)
191     {
192         msg_Err( p_aout, "couldn't create audio output pipeline" );
193         module_unneed (p_aout, owner->module);
194         owner->module = NULL;
195         return -1;
196     }
197     return 0;
198 }
199
200 /*****************************************************************************
201  * aout_OutputDelete : delete the output
202  *****************************************************************************
203  * This function is entered with the mixer lock.
204  *****************************************************************************/
205 void aout_OutputDelete( audio_output_t * p_aout )
206 {
207     aout_owner_t *owner = aout_owner (p_aout);
208
209     aout_assert_locked( p_aout );
210
211     if (owner->module == NULL)
212         return;
213
214     module_unneed (p_aout, owner->module);
215     aout_VolumeNoneInit( p_aout ); /* clear volume callback */
216     owner->module = NULL;
217     aout_FiltersDestroyPipeline (owner->filters, owner->nb_filters);
218 }
219
220 /*****************************************************************************
221  * aout_OutputPlay : play a buffer
222  *****************************************************************************
223  * This function is entered with the mixer lock.
224  *****************************************************************************/
225 void aout_OutputPlay (audio_output_t *aout, block_t *block)
226 {
227     aout_owner_t *owner = aout_owner (aout);
228
229     aout_assert_locked (aout);
230
231     aout_FiltersPlay (owner->filters, owner->nb_filters, &block);
232     if (block == NULL)
233         return;
234     if (block->i_buffer == 0)
235     {
236         block_Release (block);
237         return;
238     }
239
240     aout->pf_play (aout, block);
241 }
242
243 /**
244  * Notifies the audio output (if any) of pause/resume events.
245  * This enables the output to expedite pause, instead of waiting for its
246  * buffers to drain.
247  */
248 void aout_OutputPause( audio_output_t *aout, bool pause, mtime_t date )
249 {
250     aout_assert_locked( aout );
251     if( aout->pf_pause != NULL )
252         aout->pf_pause( aout, pause, date );
253 }
254
255 /**
256  * Flushes or drains the audio output buffers.
257  * This enables the output to expedite seek and stop.
258  * @param wait if true, wait for buffer playback (i.e. drain),
259  *             if false, discard the buffers immediately (i.e. flush)
260  */
261 void aout_OutputFlush( audio_output_t *aout, bool wait )
262 {
263     aout_assert_locked( aout );
264
265     if( aout->pf_flush != NULL )
266         aout->pf_flush( aout, wait );
267 }
268
269
270 /*** Volume handling ***/
271
272 /**
273  * Dummy volume setter. This is the default volume setter.
274  */
275 static int aout_VolumeNoneSet (audio_output_t *aout, float volume, bool mute)
276 {
277     (void)aout; (void)volume; (void)mute;
278     return -1;
279 }
280
281 /**
282  * Configures the dummy volume setter.
283  * @note Audio output plugins for which volume is irrelevant
284  * should call this function during activation.
285  */
286 void aout_VolumeNoneInit (audio_output_t *aout)
287 {
288     /* aout_New() -safely- calls this function without the lock, before any
289      * other thread knows of this audio output instance.
290     aout_assert_locked (aout); */
291     aout->pf_volume_set = aout_VolumeNoneSet;
292 }
293
294 /**
295  * Volume setter for software volume.
296  */
297 static int aout_VolumeSoftSet (audio_output_t *aout, float volume, bool mute)
298 {
299     aout_owner_t *owner = aout_owner (aout);
300
301     aout_assert_locked (aout);
302
303     /* Cubic mapping from software volume to amplification factor.
304      * This provides a good tradeoff between low and high volume ranges.
305      *
306      * This code is only used for the VLC software mixer. If you change this
307      * formula, be sure to update the aout_VolumeHardInit()-based plugins also.
308      */
309     if (!mute)
310         volume = volume * volume * volume;
311     else
312         volume = 0.;
313
314     owner->volume.multiplier = volume;
315     return 0;
316 }
317
318 /**
319  * Configures the volume setter for software mixing
320  * and apply the default volume.
321  * @note Audio output plugins that cannot apply the volume
322  * should call this function during activation.
323  */
324 void aout_VolumeSoftInit (audio_output_t *aout)
325 {
326     audio_volume_t volume = var_InheritInteger (aout, "volume");
327     bool mute = var_InheritBool (aout, "mute");
328
329     aout_assert_locked (aout);
330     aout->pf_volume_set = aout_VolumeSoftSet;
331     aout_VolumeSoftSet (aout, volume / (float)AOUT_VOLUME_DEFAULT, mute);
332 }
333
334 /**
335  * Configures a custom volume setter. This is used by audio outputs that can
336  * control the hardware volume directly and/or emulate it internally.
337  * @param setter volume setter callback
338  */
339 void aout_VolumeHardInit (audio_output_t *aout, aout_volume_cb setter)
340 {
341     aout_assert_locked (aout);
342     aout->pf_volume_set = setter;
343 }
344
345 /**
346  * Supply or update the current custom ("hardware") volume.
347  * @note This only makes sense after calling aout_VolumeHardInit().
348  * @param setter volume setter callback
349  * @param volume current custom volume
350  * @param mute current mute flag
351  * @note Audio output plugins that cannot apply the volume
352  * should call this function during activation.
353  */
354 void aout_VolumeHardSet (audio_output_t *aout, float volume, bool mute)
355 {
356 #warning FIXME
357     /* REVISIT: This is tricky. We cannot acquire the volume lock as this gets
358      * called from the audio output (it would cause a lock inversion).
359      * We also should not override the input manager volume, but only the
360      * volume of the current audio output... FIXME */
361     msg_Err (aout, "%s(%f, %u)", __func__, volume, (unsigned)mute);
362 }
363
364
365 /*** Packet-oriented audio output support ***/
366
367 static inline aout_packet_t *aout_packet (audio_output_t *aout)
368 {
369     return (aout_packet_t *)(aout->sys);
370 }
371
372 void aout_PacketInit (audio_output_t *aout, aout_packet_t *p, unsigned samples)
373 {
374     assert (p == aout_packet (aout));
375
376     aout_FifoInit (aout, &p->partial, aout->format.i_rate);
377     aout_FifoInit (aout, &p->fifo, aout->format.i_rate);
378     p->pause_date = VLC_TS_INVALID;
379     p->samples = samples;
380     p->starving = true;
381 }
382
383 void aout_PacketDestroy (audio_output_t *aout)
384 {
385     aout_packet_t *p = aout_packet (aout);
386
387     aout_FifoDestroy (&p->partial);
388     aout_FifoDestroy (&p->fifo);
389 }
390
391 static block_t *aout_OutputSlice (audio_output_t *);
392
393 void aout_PacketPlay (audio_output_t *aout, block_t *block)
394 {
395     aout_packet_t *p = aout_packet (aout);
396
397     aout_FifoPush (&p->partial, block);
398     while ((block = aout_OutputSlice (aout)) != NULL)
399         aout_FifoPush (&p->fifo, block);
400 }
401
402 void aout_PacketPause (audio_output_t *aout, bool pause, mtime_t date)
403 {
404     aout_packet_t *p = aout_packet (aout);
405
406     if (pause)
407     {
408         assert (p->pause_date == VLC_TS_INVALID);
409         p->pause_date = date;
410     }
411     else
412     {
413         assert (p->pause_date != VLC_TS_INVALID);
414
415         mtime_t duration = date - p->pause_date;
416
417         p->pause_date = VLC_TS_INVALID;
418         aout_FifoMoveDates (&p->partial, duration);
419         aout_FifoMoveDates (&p->fifo, duration);
420     }
421 }
422
423 void aout_PacketFlush (audio_output_t *aout, bool drain)
424 {
425     aout_packet_t *p = aout_packet (aout);
426
427     aout_FifoReset (&p->partial);
428     aout_FifoReset (&p->fifo);
429     (void) drain; /* TODO */
430 }
431
432
433 /**
434  * Rearranges audio blocks in correct number of samples.
435  * @note (FIXME) This is left here for historical reasons. It belongs in the
436  * output code. Besides, this operation should be avoided if possible.
437  */
438 static block_t *aout_OutputSlice (audio_output_t *p_aout)
439 {
440     aout_packet_t *p = aout_packet (p_aout);
441     aout_fifo_t *p_fifo = &p->partial;
442     const unsigned samples = p->samples;
443     assert( samples > 0 );
444
445     aout_assert_locked( p_aout );
446
447     /* Retrieve the date of the next buffer. */
448     date_t exact_start_date = p->fifo.end_date;
449     mtime_t start_date = date_Get( &exact_start_date );
450
451     /* See if we have enough data to prepare a new buffer for the audio output. */
452     aout_buffer_t *p_buffer = p_fifo->p_first;
453     if( p_buffer == NULL )
454         return NULL;
455
456     /* Find the earliest start date available. */
457     if ( start_date == VLC_TS_INVALID )
458     {
459         start_date = p_buffer->i_pts;
460         date_Set( &exact_start_date, start_date );
461     }
462     /* Compute the end date for the new buffer. */
463     mtime_t end_date = date_Increment( &exact_start_date, samples );
464
465     /* Check that start_date is available. */
466     mtime_t prev_date;
467     for( ;; )
468     {
469         /* Check for the continuity of start_date */
470         prev_date = p_buffer->i_pts + p_buffer->i_length;
471         if( prev_date >= start_date - 1 )
472             break;
473         /* We authorize a +-1 because rounding errors get compensated
474          * regularly. */
475         msg_Warn( p_aout, "got a packet in the past (%"PRId64")",
476                   start_date - prev_date );
477         aout_BufferFree( aout_FifoPop( p_fifo ) );
478
479         p_buffer = p_fifo->p_first;
480         if( p_buffer == NULL )
481             return NULL;
482     }
483
484     /* Check that we have enough samples. */
485     while( prev_date < end_date )
486     {
487         p_buffer = p_buffer->p_next;
488         if( p_buffer == NULL )
489             return NULL;
490
491         /* Check that all buffers are contiguous. */
492         if( prev_date != p_buffer->i_pts )
493         {
494             msg_Warn( p_aout,
495                       "buffer hole, dropping packets (%"PRId64")",
496                       p_buffer->i_pts - prev_date );
497
498             aout_buffer_t *p_deleted;
499             while( (p_deleted = p_fifo->p_first) != p_buffer )
500                 aout_BufferFree( aout_FifoPop( p_fifo ) );
501         }
502
503         prev_date = p_buffer->i_pts + p_buffer->i_length;
504     }
505
506     if( !AOUT_FMT_NON_LINEAR( &p_aout->format ) )
507     {
508         p_buffer = p_fifo->p_first;
509
510         /* Additionally check that p_first_byte_to_mix is well located. */
511         const unsigned framesize = p_aout->format.i_bytes_per_frame;
512         ssize_t delta = (start_date - p_buffer->i_pts)
513                       * p_aout->format.i_rate / CLOCK_FREQ;
514         if( delta != 0 )
515             msg_Warn( p_aout, "input start is not output end (%zd)", delta );
516         if( delta < 0 )
517         {
518             /* Is it really the best way to do it ? */
519             aout_FifoReset (&p->fifo);
520             return NULL;
521         }
522         if( delta > 0 )
523         {
524             mtime_t t = delta * CLOCK_FREQ / p_aout->format.i_rate;
525             p_buffer->i_nb_samples -= delta;
526             p_buffer->i_pts += t;
527             p_buffer->i_length -= t;
528             delta *= framesize;
529             p_buffer->p_buffer += delta;
530             p_buffer->i_buffer -= delta;
531         }
532
533         /* Build packet with adequate number of samples */
534         unsigned needed = samples * framesize;
535         p_buffer = block_Alloc( needed );
536         if( unlikely(p_buffer == NULL) )
537             /* XXX: should free input buffers */
538             return NULL;
539         p_buffer->i_nb_samples = samples;
540
541         for( uint8_t *p_out = p_buffer->p_buffer; needed > 0; )
542         {
543             aout_buffer_t *p_inbuf = p_fifo->p_first;
544             if( unlikely(p_inbuf == NULL) )
545             {
546                 msg_Err( p_aout, "packetization error" );
547                 vlc_memset( p_out, 0, needed );
548                 break;
549             }
550
551             const uint8_t *p_in = p_inbuf->p_buffer;
552             size_t avail = p_inbuf->i_nb_samples * framesize;
553             if( avail > needed )
554             {
555                 vlc_memcpy( p_out, p_in, needed );
556                 p_fifo->p_first->p_buffer += needed;
557                 p_fifo->p_first->i_buffer -= needed;
558                 needed /= framesize;
559                 p_fifo->p_first->i_nb_samples -= needed;
560
561                 mtime_t t = needed * CLOCK_FREQ / p_aout->format.i_rate;
562                 p_fifo->p_first->i_pts += t;
563                 p_fifo->p_first->i_length -= t;
564                 break;
565             }
566
567             vlc_memcpy( p_out, p_in, avail );
568             needed -= avail;
569             p_out += avail;
570             /* Next buffer */
571             aout_BufferFree( aout_FifoPop( p_fifo ) );
572         }
573     }
574     else
575         p_buffer = aout_FifoPop( p_fifo );
576
577     p_buffer->i_pts = start_date;
578     p_buffer->i_length = end_date - start_date;
579
580     return p_buffer;
581 }
582
583 /*****************************************************************************
584  * aout_OutputNextBuffer : give the audio output plug-in the right buffer
585  *****************************************************************************
586  * If b_can_sleek is 1, the aout core functions won't try to resample
587  * new buffers to catch up - that is we suppose that the output plug-in can
588  * compensate it by itself. S/PDIF outputs should always set b_can_sleek = 1.
589  * This function is entered with no lock at all :-).
590  *****************************************************************************/
591 aout_buffer_t * aout_OutputNextBuffer( audio_output_t * p_aout,
592                                        mtime_t start_date,
593                                        bool b_can_sleek )
594 {
595     aout_packet_t *p = aout_packet (p_aout);
596     aout_fifo_t *p_fifo = &p->fifo;
597     aout_buffer_t * p_buffer;
598     mtime_t now = mdate();
599
600     aout_lock( p_aout );
601
602     /* Drop the audio sample if the audio output is really late.
603      * In the case of b_can_sleek, we don't use a resampler so we need to be
604      * a lot more severe. */
605     while( ((p_buffer = p_fifo->p_first) != NULL)
606      && p_buffer->i_pts < (b_can_sleek ? start_date : now) - AOUT_MAX_PTS_DELAY )
607     {
608         msg_Dbg( p_aout, "audio output is too slow (%"PRId64"), "
609                  "trashing %"PRId64"us", now - p_buffer->i_pts,
610                  p_buffer->i_length );
611         aout_BufferFree( aout_FifoPop( p_fifo ) );
612     }
613
614     if( p_buffer == NULL )
615     {
616 #if 0 /* This is bad because the audio output might just be trying to fill
617        * in its internal buffers. And anyway, it's up to the audio output
618        * to deal with this kind of starvation. */
619
620         /* Set date to 0, to allow the mixer to send a new buffer ASAP */
621         aout_FifoReset( &p->fifo );
622         if ( !p->starving )
623             msg_Dbg( p_aout,
624                  "audio output is starving (no input), playing silence" );
625         p_aout->starving = true;
626 #endif
627         goto out;
628     }
629
630     mtime_t delta = start_date - p_buffer->i_pts;
631     /* Here we suppose that all buffers have the same duration - this is
632      * generally true, and anyway if it's wrong it won't be a disaster.
633      */
634     if ( 0 > delta + p_buffer->i_length )
635     {
636         if (!p->starving)
637             msg_Dbg( p_aout, "audio output is starving (%"PRId64"), "
638                      "playing silence", -delta );
639         p->starving = true;
640         p_buffer = NULL;
641         goto out;
642     }
643
644     p->starving = false;
645     p_buffer = aout_FifoPop( p_fifo );
646
647     if( !b_can_sleek
648      && ( delta > AOUT_MAX_PTS_DELAY || delta < -AOUT_MAX_PTS_ADVANCE ) )
649     {
650         /* Try to compensate the drift by doing some resampling. */
651         msg_Warn( p_aout, "output date isn't PTS date, requesting "
652                   "resampling (%"PRId64")", delta );
653
654         aout_FifoMoveDates (&p->partial, delta);
655         aout_FifoMoveDates (p_fifo, delta);
656     }
657 out:
658     aout_unlock( p_aout );
659     return p_buffer;
660 }