src/audio/SDL_audio.c
changeset 10242 48c3f46395ae
parent 10240 0ba7106e9a6d
child 10244 aaed7b1f783a
equal deleted inserted replaced
10241:457d9c7868ec 10242:48c3f46395ae
   584 
   584 
   585 void
   585 void
   586 SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
   586 SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
   587 {
   587 {
   588     SDL_AudioDevice *device = get_audio_device(devid);
   588     SDL_AudioDevice *device = get_audio_device(devid);
   589     SDL_AudioBufferQueue *buffer = NULL;
   589     SDL_AudioBufferQueue *packet;
       
   590 
   590     if (!device) {
   591     if (!device) {
   591         return;  /* nothing to do. */
   592         return;  /* nothing to do. */
   592     }
   593     }
   593 
   594 
   594     /* Blank out the device and release the mutex. Free it afterwards. */
   595     /* Blank out the device and release the mutex. Free it afterwards. */
   595     current_audio.impl.LockDevice(device);
   596     current_audio.impl.LockDevice(device);
   596     buffer = device->buffer_queue_head;
   597 
       
   598     /* merge the available pool and the current queue into one list. */
       
   599     packet = device->buffer_queue_head;
       
   600     if (packet) {
       
   601         device->buffer_queue_tail->next = device->buffer_queue_pool;
       
   602     } else {
       
   603         packet = device->buffer_queue_pool;
       
   604     }
       
   605 
       
   606     /* Remove the queued packets from the device. */
   597     device->buffer_queue_tail = NULL;
   607     device->buffer_queue_tail = NULL;
   598     device->buffer_queue_head = NULL;
   608     device->buffer_queue_head = NULL;
   599     device->queued_bytes = 0;
   609     device->queued_bytes = 0;
       
   610     device->buffer_queue_pool = packet;
       
   611 
       
   612     /* Keep up to two packets in the pool to reduce future malloc pressure. */
       
   613     if (packet) {
       
   614         if (!packet->next) {
       
   615             packet = NULL;  /* one packet (the only one) for the pool. */
       
   616         } else {
       
   617             SDL_AudioBufferQueue *next = packet->next->next;
       
   618             packet->next->next = NULL;  /* two packets for the pool. */
       
   619             packet = next;  /* rest will be freed. */
       
   620         }
       
   621     }
       
   622 
   600     current_audio.impl.UnlockDevice(device);
   623     current_audio.impl.UnlockDevice(device);
   601 
   624 
   602     free_audio_queue(buffer);
   625     /* free any extra packets we didn't keep in the pool. */
       
   626     free_audio_queue(packet);
   603 }
   627 }
   604 
   628 
   605 
   629 
   606 /* The general mixing thread function */
   630 /* The general mixing thread function */
   607 static int SDLCALL
   631 static int SDLCALL