~siretart/xine-lib/ubuntu

« back to all changes in this revision

Viewing changes to src/xine-engine/audio_out.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-12-15 13:13:45 UTC
  • mfrom: (0.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051215131345-8n4osv1j7fy9c1s1
* SECURITY UPDATE: Fix arbitrary code execution with crafted PNG images in
  embedded ffmpeg copy.
* src/libffmpeg/libavcodec/utils.c, avcodec_default_get_buffer(): Apply
  upstream patch to fix buffer overflow on decoding of small PIX_FMT_PAL8
  PNG files.
* References:
  CVE-2005-4048
  http://mplayerhq.hu/pipermail/ffmpeg-devel/2005-November/005333.html
  http://www1.mplayerhq.hu/cgi-bin/cvsweb.cgi/ffmpeg/libavcodec/
  utils.c.diff?r1=1.161&r2=1.162&cvsroot=FFMpeg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2000-2004 the xine project
 
2
 * Copyright (C) 2000-2005 the xine project
3
3
 * 
4
4
 * This file is part of xine, a free video player.
5
5
 * 
17
17
 * along with self program; if not, write to the Free Software
18
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
19
19
 *
20
 
 * $Id: audio_out.c,v 1.189.2.1 2005/02/09 19:39:44 mroi Exp $
 
20
 * $Id: audio_out.c,v 1.194 2005/10/30 02:18:35 miguelfreitas Exp $
21
21
 *
22
22
 * 22-8-2001 James imported some useful AC3 sections from the previous alsa driver.
23
23
 *   (c) 2001 Andy Lo A Foe <andy@alsaplayer.org>
216
216
  int             audio_loop_running;
217
217
  int             grab_only; /* => do not start thread, frontend will consume samples */
218
218
  pthread_t       audio_thread;
 
219
  int             audio_thread_created;
219
220
 
220
221
  int64_t         audio_step;           /* pts per 32 768 samples (sample = #bytes/2) */
221
222
  int32_t         frames_per_kpts;      /* frames per 1024/90000 sec                  */
236
237
  audio_fifo_t   *free_fifo;
237
238
  audio_fifo_t   *out_fifo;
238
239
  int64_t         last_audio_vpts;
 
240
  uint32_t        current_speed;        /* the current playback speed */
 
241
  /* FIXME: replace all this->clock->speed with this->current_speed. we should make
 
242
   * sure nobody will change speed without going through xine.c:set_speed_internal */
 
243
  int             slow_fast_audio;      /* play audio even on slow/fast speeds */
239
244
  
240
245
  audio_buffer_t *frame_buf[2];         /* two buffers for "stackable" conversions */
241
246
  int16_t        *zero_space;
984
989
 
985
990
    /* 
986
991
     * wait until user unpauses stream
987
 
     * if we are playing at a different speed
988
 
     * we must process buffers otherwise the entire engine will stop.
 
992
     * if we are playing at a different speed (without slow_fast_audio flag)
 
993
     * we must process/free buffers otherwise the entire engine will stop.
989
994
     */
990
995
    
991
 
    if ( this->clock->speed != XINE_FINE_SPEED_NORMAL && this->audio_loop_running )  {
 
996
    if ( this->audio_loop_running && 
 
997
         (this->clock->speed == XINE_SPEED_PAUSE || 
 
998
          (this->clock->speed != XINE_FINE_SPEED_NORMAL && 
 
999
           !this->slow_fast_audio) ) )  {
992
1000
 
993
1001
      if (this->clock->speed != XINE_SPEED_PAUSE) {
994
1002
 
1282
1290
  }
1283
1291
}
1284
1292
 
 
1293
static int ao_update_resample_factor(aos_t *this) {
 
1294
  
 
1295
  if( !this->driver_open )
 
1296
    return 0;
 
1297
  
 
1298
  switch (this->resample_conf) {
 
1299
  case 1: /* force off */
 
1300
    this->do_resample = 0;
 
1301
    break;
 
1302
  case 2: /* force on */
 
1303
    this->do_resample = 1;
 
1304
    break;
 
1305
  default: /* AUTO */
 
1306
    if( !this->slow_fast_audio || this->current_speed == XINE_SPEED_PAUSE )
 
1307
      this->do_resample = this->output.rate != this->input.rate;
 
1308
    else
 
1309
      this->do_resample = (this->output.rate*this->current_speed/XINE_FINE_SPEED_NORMAL) != this->input.rate;
 
1310
  }
 
1311
 
 
1312
  if (this->do_resample)
 
1313
    xprintf (this->xine, XINE_VERBOSITY_DEBUG,
 
1314
             "will resample audio from %d to %d\n", this->input.rate, this->output.rate);
 
1315
 
 
1316
  if( !this->slow_fast_audio || this->current_speed == XINE_SPEED_PAUSE )
 
1317
    this->frame_rate_factor = ((double)(this->output.rate)) / ((double)(this->input.rate));
 
1318
  else
 
1319
    this->frame_rate_factor = ( XINE_FINE_SPEED_NORMAL / (double)this->current_speed ) * ((double)(this->output.rate)) / ((double)(this->input.rate));
 
1320
  this->frames_per_kpts   = (this->output.rate * 1024) / 90000;
 
1321
  this->audio_step        = ((int64_t)90000 * (int64_t)32768) / (int64_t)this->input.rate;
 
1322
  
 
1323
  lprintf ("audio_step %" PRId64 " pts per 32768 frames\n", this->audio_step);
 
1324
  return this->output.rate;
 
1325
}
1285
1326
 
1286
1327
static int ao_change_settings(aos_t *this, uint32_t bits, uint32_t rate, int mode) {
1287
1328
  int output_sample_rate;
1336
1377
  this->output.rate           = output_sample_rate;
1337
1378
  this->output.bits           = bits;
1338
1379
 
1339
 
  switch (this->resample_conf) {
1340
 
  case 1: /* force off */
1341
 
    this->do_resample = 0;
1342
 
    break;
1343
 
  case 2: /* force on */
1344
 
    this->do_resample = 1;
1345
 
    break;
1346
 
  default: /* AUTO */
1347
 
    this->do_resample = this->output.rate != this->input.rate;
1348
 
  }
1349
 
 
1350
 
  if (this->do_resample)
1351
 
    xprintf (this->xine, XINE_VERBOSITY_DEBUG,
1352
 
             "will resample audio from %d to %d\n", this->input.rate, this->output.rate);
1353
 
 
1354
 
  this->frame_rate_factor = ((double)(this->output.rate)) / ((double)(this->input.rate));
1355
 
  /* FIXME: If this->frames_per_kpts line goes after this->audio_step line,
1356
 
   * xine crashes with FPE, when compiled with gcc 3.0.1!!! Why? */
1357
 
  this->frames_per_kpts   = (this->output.rate * 1024) / 90000;
1358
 
  this->audio_step        = ((int64_t)90000 * (int64_t)32768) / (int64_t)this->input.rate;
1359
 
  
1360
 
  lprintf ("audio_step %" PRId64 " pts per 32768 frames\n", this->audio_step);
1361
 
  return this->output.rate;
 
1380
  return ao_update_resample_factor(this);
1362
1381
}
1363
1382
 
1364
1383
 
1509
1528
  pthread_mutex_unlock(&this->streams_lock);
1510
1529
 
1511
1530
  /* close driver if no streams left */
1512
 
  if (!cur && !this->grab_only) {
 
1531
  if (!cur && !this->grab_only && !stream->gapless_switch) {
1513
1532
    xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_out: no streams left, closing driver\n");
1514
1533
 
1515
1534
    if (this->audio_loop_running) {
1543
1562
    fifo_append (this->out_fifo, buf);
1544
1563
 
1545
1564
    pthread_join (this->audio_thread, &p);
1546
 
    this->audio_thread = 0;
 
1565
    this->audio_thread_created = 0;
1547
1566
  }
1548
1567
      
1549
1568
  if (!this->grab_only) {
1685
1704
  case AO_PROP_DISCARD_BUFFERS:
1686
1705
    ret = this->discard_buffers;
1687
1706
    break;
 
1707
  
 
1708
  case AO_PROP_CLOCK_SPEED:
 
1709
    ret = this->current_speed;
 
1710
    break;
1688
1711
 
1689
1712
  default:
1690
1713
    inc_num_driver_actions(this);
1763
1786
      this->discard_buffers++;
1764
1787
    else
1765
1788
      this->discard_buffers--;
 
1789
  
1766
1790
    ret = this->discard_buffers;
1767
1791
    
1768
1792
    /* discard buffers here because we have no output thread */
1790
1814
    pthread_mutex_unlock( &this->driver_lock );
1791
1815
    break;
1792
1816
 
 
1817
  case AO_PROP_CLOCK_SPEED:
 
1818
    /*
 
1819
     * slow motion / fast forward does not play sound, drop buffered
 
1820
     * samples from the sound driver (check slow_fast_audio flag)
 
1821
     */
 
1822
    if (value != XINE_FINE_SPEED_NORMAL && value != XINE_SPEED_PAUSE && !this->slow_fast_audio )
 
1823
      this->ao.control(&this->ao, AO_CTRL_FLUSH_BUFFERS, NULL);
 
1824
 
 
1825
    this->ao.control(&this->ao,
 
1826
                     (value == XINE_SPEED_PAUSE) ? AO_CTRL_PLAY_PAUSE : AO_CTRL_PLAY_RESUME, NULL);
 
1827
    this->current_speed = value;
 
1828
    if( this->slow_fast_audio )
 
1829
      ao_update_resample_factor(this);
 
1830
    break;
 
1831
    
1793
1832
  default:
1794
1833
    if (!this->grab_only) {
1795
1834
      /* Let the sound driver lock it's own mixer */
2011
2050
                                                     "a fixed offset here to compensate.\nThe unit of "
2012
2051
                                                     "the value is one PTS tick, which is the 90000th "
2013
2052
                                                     "part of a second."), 10, NULL, NULL);
 
2053
  
 
2054
  this->slow_fast_audio = config->register_bool (config,
 
2055
                                                   "audio.synchronization.slow_fast_audio",
 
2056
                                                   0,
 
2057
                                                   _("play audio even on slow/fast speeds"),
 
2058
                                                   _("If you enable this option, the audio will be "
 
2059
                                                     "heard even when playback speed is different "
 
2060
                                                     "than 1X. Of course, it will sound distorted "
 
2061
                                                     "(lower/higher pitch). If want to experiment "
 
2062
                                                     "preserving the pitch you may try the "
 
2063
                                                     "'stretch' audio post plugin instead."), 10, NULL, NULL);
2014
2064
 
2015
2065
  this->compression_factor     = 2.0;
2016
2066
  this->compression_factor_max = 0.0;
2103
2153
    
2104
2154
    pthread_attr_init(&pth_attrs);
2105
2155
    pthread_attr_setscope(&pth_attrs, PTHREAD_SCOPE_SYSTEM);
2106
 
    
 
2156
 
 
2157
    this->audio_thread_created = 1;
2107
2158
    if ((err = pthread_create (&this->audio_thread,
2108
2159
                               &pth_attrs, ao_loop, this)) != 0) {
2109
2160