音频信息 SDL_AudioSpec 的产生
read_thread
->stream_component_open(ffp, st_index[AVMEDIA_TYPE_AUDIO]);
->/* prepare audio output */
if ((ret = audio_open(ffp, channel_layout, nb_channels, sample_rate, &is->audio_tgt)) < 0)
->while (SDL_AoutOpenAudio(ffp->aout, &wanted_spec, &spec) < 0)
->static int aout_open_audio(SDL_Aout *aout, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
->opaque->aoutController = [[IJKSDLAudioQueueController alloc] initWithAudioSpec:desired];
->SDL_CalculateAudioSpec(&_spec);
->{
spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
spec->size *= spec->channels;
spec->size *= spec->samples;//计算size大小
}
->aout_open_audio 里面
-> if (obtained)
*obtained = opaque->aoutController.spec;//将上一步计算的spec 赋给 obtained
->static int aout_open_audio(SDL_Aout *aout, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
->while (SDL_AoutOpenAudio(ffp->aout, &wanted_spec, &spec) < 0) 既在这个函数执行完spec 就计算出来了。
static void IJKSDLAudioQueueOuptutCallback(void * inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer) {
@autoreleasepool {
JFSDLAudioQueueController* aqController = (__bridge JFSDLAudioQueueController *) inUserData;
if (!aqController) {
// do nothing;
} else if (aqController->_isPaused || aqController->_isStopped) {
memset(inBuffer->mAudioData, aqController.spec.silence, inBuffer->mAudioDataByteSize);
} else {
(*aqController.spec.callback)(aqController.spec.userdata, inBuffer->mAudioData, inBuffer->mAudioDataByteSize);
}
AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL);
}
}
(*aqController.spec.callback)(aqController.spec.userdata, inBuffer->mAudioData, inBuffer->mAudioDataByteSize);
}
/* prepare a new audio buffer */
static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
//此处选择输出是用AudioUnit还是用AudioQueue
/*
* ijksdl_aout_ios_audiounit.m
*
#define SDL_IOS_AUDIO_MAX_CALLBACKS_PER_SEC 15
struct SDL_Aout_Opaque {
// IJKSDLAudioQueueController *aoutController;
IJKSDLAudioUnitController *aoutController;
};
static int aout_open_audio(SDL_Aout *aout, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
{
assert(desired);
SDLTRACE("aout_open_audio()\n");
SDL_Aout_Opaque *opaque = aout->opaque;
// opaque->aoutController = [[IJKSDLAudioQueueController alloc] initWithAudioSpec:desired];
opaque->aoutController = [[IJKSDLAudioUnitController alloc] initWithAudioSpec:desired];
if (!opaque->aoutController) {
ALOGE("aout_open_audio_n: failed to new AudioTrcak()\n");
return -1;
}
if (obtained)
*obtained = opaque->aoutController.spec;
return 0;
}