GF_EXPORT void gf_sc_reload_audio_filters(GF_Compositor *compositor) { GF_AudioRenderer *ar = compositor->audio_renderer; if (!ar) return; gf_mixer_lock(ar->mixer, GF_TRUE); gf_afc_unload(&ar->filter_chain); gf_afc_load(&ar->filter_chain, ar->user, (char*)gf_cfg_get_key(ar->user->config, "Audio", "Filter")); gf_ar_pause(ar, GF_TRUE, GF_TRUE, GF_FALSE); ar->need_reconfig = GF_FALSE; gf_ar_setup_output_format(ar); gf_ar_pause(ar, GF_FALSE, GF_TRUE, GF_FALSE); gf_mixer_lock(ar->mixer, GF_FALSE); }
GF_AudioFilterItem *gf_af_new(GF_Compositor *compositor, GF_AudioInterface *src, char *filter_name) { GF_AudioFilterItem *filter; if (!src || !filter_name) return NULL; GF_SAFEALLOC(filter, GF_AudioFilterItem); filter->src = src; filter->input.FetchFrame = gf_af_fetch_frame; filter->input.ReleaseFrame = gf_af_release_frame; filter->input.GetSpeed = gf_af_get_speed; filter->input.GetChannelVolume = gf_af_get_channel_volume; filter->input.IsMuted = gf_af_is_muted; filter->input.GetConfig = gf_af_get_config; filter->input.callback = filter; gf_afc_load(&filter->filter_chain, compositor->user, filter_name); return filter; }
GF_AudioRenderer *gf_sc_ar_load(GF_User *user) { const char *sOpt; u32 i, count; u32 num_buffers, total_duration; GF_Err e; GF_AudioRenderer *ar; ar = (GF_AudioRenderer *) gf_malloc(sizeof(GF_AudioRenderer)); memset(ar, 0, sizeof(GF_AudioRenderer)); num_buffers = total_duration = 0; sOpt = gf_cfg_get_key(user->config, "Audio", "ForceConfig"); if (sOpt && !stricmp(sOpt, "yes")) { sOpt = gf_cfg_get_key(user->config, "Audio", "NumBuffers"); num_buffers = sOpt ? atoi(sOpt) : 6; sOpt = gf_cfg_get_key(user->config, "Audio", "TotalDuration"); total_duration = sOpt ? atoi(sOpt) : 400; } sOpt = gf_cfg_get_key(user->config, "Audio", "NoResync"); ar->disable_resync = (sOpt && !stricmp(sOpt, "yes")) ? GF_TRUE : GF_FALSE; sOpt = gf_cfg_get_key(user->config, "Audio", "DisableMultiChannel"); ar->disable_multichannel = (sOpt && !stricmp(sOpt, "yes")) ? GF_TRUE : GF_FALSE; ar->mixer = gf_mixer_new(ar); ar->user = user; sOpt = gf_cfg_get_key(user->config, "Audio", "Volume"); ar->volume = sOpt ? atoi(sOpt) : 75; sOpt = gf_cfg_get_key(user->config, "Audio", "Pan"); ar->pan = sOpt ? atoi(sOpt) : 50; if (! (user->init_flags & GF_TERM_NO_AUDIO) ) { /*get a prefered compositor*/ sOpt = gf_cfg_get_key(user->config, "Audio", "DriverName"); if (sOpt) { ar->audio_out = (GF_AudioOutput *) gf_modules_load_interface_by_name(user->modules, sOpt, GF_AUDIO_OUTPUT_INTERFACE); if (!ar->audio_out) { ar->audio_out = NULL; sOpt = NULL; } } if (!ar->audio_out) { GF_AudioOutput *raw_out = NULL; count = gf_modules_get_count(ar->user->modules); for (i=0; i<count; i++) { ar->audio_out = (GF_AudioOutput *) gf_modules_load_interface(ar->user->modules, i, GF_AUDIO_OUTPUT_INTERFACE); if (!ar->audio_out) continue; //in enum mode, only use raw out if everything else failed ... if (!stricmp(ar->audio_out->module_name, "Raw Audio Output")) { raw_out = ar->audio_out; ar->audio_out = NULL; continue; } GF_LOG(GF_LOG_DEBUG, GF_LOG_AUDIO, ("[AudioRender] Audio output module %s loaded\n", ar->audio_out->module_name)); /*check that's a valid audio compositor*/ if ((ar->audio_out->SelfThreaded && ar->audio_out->SetPriority) || ar->audio_out->WriteAudio) { /*remember the module we use*/ gf_cfg_set_key(user->config, "Audio", "DriverName", ar->audio_out->module_name); break; } gf_modules_close_interface((GF_BaseInterface *)ar->audio_out); ar->audio_out = NULL; } if (raw_out) { if (ar->audio_out) gf_modules_close_interface((GF_BaseInterface *)raw_out); else ar->audio_out = raw_out; } } /*if not init we run with a NULL audio compositor*/ if (ar->audio_out) { ar->audio_out->FillBuffer = gf_ar_fill_output; ar->audio_out->audio_renderer = ar; GF_LOG(GF_LOG_DEBUG, GF_LOG_AUDIO, ("[AudioRender] Setting up audio module %s\n", ar->audio_out->module_name)); e = ar->audio_out->Setup(ar->audio_out, ar->user->os_window_handler, num_buffers, total_duration); /*load main audio filter*/ gf_afc_load(&ar->filter_chain, user, (char*)gf_cfg_get_key(user->config, "Audio", "Filter")); if (e != GF_OK) { GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("Could not setup audio out %s\n", ar->audio_out->module_name)); gf_modules_close_interface((GF_BaseInterface *)ar->audio_out); ar->audio_out = NULL; } else { if (!ar->audio_out->SelfThreaded) { ar->th = gf_th_new("AudioRenderer"); gf_th_run(ar->th, gf_ar_proc, ar); } else { gf_ar_setup_output_format(ar); if (ar->audio_out->SetPriority) ar->audio_out->SetPriority(ar->audio_out, GF_THREAD_PRIORITY_REALTIME); } } } if (!ar->audio_out) { gf_cfg_set_key(user->config, "Audio", "DriverName", "No Audio Output Available"); } else { if (user->init_flags & GF_TERM_USE_AUDIO_HW_CLOCK) ar->clock_use_audio_out = GF_TRUE; } } /*init compositor timer*/ ar->start_time = gf_sys_clock_high_res(); ar->current_time = 0; return ar; }