src/audio/SDL_audio.c
changeset 10253 4a1faf81a620
parent 10252 4d99b888e7e5
child 10259 230c0df1e152
equal deleted inserted replaced
10252:4d99b888e7e5 10253:4a1faf81a620
  1147     SDL_AudioDeviceID id = 0;
  1147     SDL_AudioDeviceID id = 0;
  1148     SDL_AudioSpec _obtained;
  1148     SDL_AudioSpec _obtained;
  1149     SDL_AudioDevice *device;
  1149     SDL_AudioDevice *device;
  1150     SDL_bool build_cvt;
  1150     SDL_bool build_cvt;
  1151     void *handle = NULL;
  1151     void *handle = NULL;
  1152     Uint32 stream_len;
       
  1153     int i = 0;
  1152     int i = 0;
  1154 
  1153 
  1155     if (!SDL_WasInit(SDL_INIT_AUDIO)) {
  1154     if (!SDL_WasInit(SDL_INIT_AUDIO)) {
  1156         SDL_SetError("Audio subsystem is not initialized");
  1155         SDL_SetError("Audio subsystem is not initialized");
  1157         return 0;
  1156         return 0;
  1336                 return 0;
  1335                 return 0;
  1337             }
  1336             }
  1338         }
  1337         }
  1339     }
  1338     }
  1340 
  1339 
  1341     /* Allocate a fake audio memory buffer */
       
  1342     stream_len = (device->convert.needed) ? device->convert.len_cvt : 0;
       
  1343     if (device->spec.size > stream_len) {
       
  1344         stream_len = device->spec.size;
       
  1345     }
       
  1346     SDL_assert(stream_len > 0);
       
  1347     device->fake_stream = (Uint8 *) SDL_malloc(stream_len);
       
  1348     if (device->fake_stream == NULL) {
       
  1349         close_audio_device(device);
       
  1350         SDL_OutOfMemory();
       
  1351         return 0;
       
  1352     }
       
  1353 
       
  1354     if (device->spec.callback == NULL) {  /* use buffer queueing? */
  1340     if (device->spec.callback == NULL) {  /* use buffer queueing? */
  1355         /* pool a few packets to start. Enough for two callbacks. */
  1341         /* pool a few packets to start. Enough for two callbacks. */
  1356         const int packetlen = SDL_AUDIOBUFFERQUEUE_PACKETLEN;
  1342         const int packetlen = SDL_AUDIOBUFFERQUEUE_PACKETLEN;
  1357         const int wantbytes = ((device->convert.needed) ? device->convert.len : device->spec.size) * 2;
  1343         const int wantbytes = ((device->convert.needed) ? device->convert.len : device->spec.size) * 2;
  1358         const int wantpackets = (wantbytes / packetlen) + ((wantbytes % packetlen) ? packetlen : 0);
  1344         const int wantpackets = (wantbytes / packetlen) + ((wantbytes % packetlen) ? packetlen : 0);
  1374     open_devices[id] = device;
  1360     open_devices[id] = device;
  1375 
  1361 
  1376     /* Start the audio thread if necessary */
  1362     /* Start the audio thread if necessary */
  1377     if (!current_audio.impl.ProvidesOwnCallbackThread) {
  1363     if (!current_audio.impl.ProvidesOwnCallbackThread) {
  1378         /* Start the audio thread */
  1364         /* Start the audio thread */
       
  1365 
       
  1366         /* Allocate a fake audio buffer; only used by our internal threads. */
       
  1367         Uint32 stream_len = (device->convert.needed) ? device->convert.len_cvt : 0;
       
  1368         if (device->spec.size > stream_len) {
       
  1369             stream_len = device->spec.size;
       
  1370         }
       
  1371         SDL_assert(stream_len > 0);
       
  1372 
       
  1373         device->fake_stream = (Uint8 *) SDL_malloc(stream_len);
       
  1374         if (device->fake_stream == NULL) {
       
  1375             close_audio_device(device);
       
  1376             SDL_OutOfMemory();
       
  1377             return 0;
       
  1378         }
  1379 
  1379 
  1380         /* !!! FIXME: we don't force the audio thread stack size here because it calls into user code, but maybe we should? */
  1380         /* !!! FIXME: we don't force the audio thread stack size here because it calls into user code, but maybe we should? */
  1381         /* buffer queueing callback only needs a few bytes, so make the stack tiny. */
  1381         /* buffer queueing callback only needs a few bytes, so make the stack tiny. */
  1382         char name[64];
  1382         char name[64];
  1383         const size_t stacksize = is_internal_thread ? 64 * 1024 : 0;
  1383         const size_t stacksize = is_internal_thread ? 64 * 1024 : 0;