static u32 gf_ar_fill_output(void *ptr, char *buffer, u32 buffer_size) { u32 written; GF_AudioRenderer *ar = (GF_AudioRenderer *) ptr; if (!ar->need_reconfig) { u32 delay_ms = ar->disable_resync ? 0 : ar->audio_delay; if (ar->filter_chain.enable_filters) { char *ptr = buffer; u32 res = buffer_size; written = 0; delay_ms += ar->filter_chain.delay_ms; while (buffer_size) { u32 to_copy; if (!ar->nb_used) { u32 nb_bytes; /*fill input block*/ nb_bytes = gf_mixer_get_output(ar->mixer, ar->filter_chain.tmp_block1, ar->filter_chain.min_block_size, delay_ms); if (!nb_bytes) return written; /*delay used to check for late frames - we only use it on the first call to gf_mixer_get_output()*/ delay_ms = 0; ar->nb_filled = gf_afc_process(&ar->filter_chain, nb_bytes); if (!ar->nb_filled) continue; } to_copy = ar->nb_filled - ar->nb_used; if (to_copy>buffer_size) to_copy = buffer_size; memcpy(ptr, ar->filter_chain.tmp_block1 + ar->nb_used, to_copy); ptr += to_copy; buffer_size -= to_copy; written += to_copy; ar->nb_used += to_copy; if (ar->nb_used==ar->nb_filled) ar->nb_used = 0; } assert(res==written); } else { written = gf_mixer_get_output(ar->mixer, buffer, buffer_size, delay_ms); } if (ar->audio_listeners) { u32 k=0; GF_AudioListener *l; while ((l = gf_list_enum(ar->audio_listeners, &k))) { l->on_audio_frame(l->udta, buffer, written, gf_sc_ar_get_clock(ar), delay_ms); } } return written; } return 0; }
static u32 gf_ar_fill_output(void *ptr, char *buffer, u32 buffer_size) { u32 written; GF_AudioRenderer *ar = (GF_AudioRenderer *) ptr; if (!ar->need_reconfig) { u32 delay_ms = ar->disable_resync ? 0 : ar->audio_delay; if (ar->Frozen) { memset(buffer, 0, buffer_size); return buffer_size; } gf_mixer_lock(ar->mixer, GF_TRUE); if (ar->filter_chain.enable_filters) { char *ptr = buffer; written = 0; delay_ms += ar->filter_chain.delay_ms; while (buffer_size) { u32 to_copy; if (!ar->nb_used) { u32 nb_bytes; /*fill input block*/ nb_bytes = gf_mixer_get_output(ar->mixer, ar->filter_chain.tmp_block1, ar->filter_chain.min_block_size, delay_ms); if (!nb_bytes) return written; /*delay used to check for late frames - we only use it on the first call to gf_mixer_get_output()*/ delay_ms = 0; ar->nb_filled = gf_afc_process(&ar->filter_chain, nb_bytes); if (!ar->nb_filled) continue; } to_copy = ar->nb_filled - ar->nb_used; if (to_copy>buffer_size) to_copy = buffer_size; memcpy(ptr, ar->filter_chain.tmp_block1 + ar->nb_used, to_copy); ptr += to_copy; buffer_size -= to_copy; written += to_copy; ar->nb_used += to_copy; if (ar->nb_used==ar->nb_filled) ar->nb_used = 0; } } else { written = gf_mixer_get_output(ar->mixer, buffer, buffer_size, delay_ms); } gf_mixer_lock(ar->mixer, GF_FALSE); //done with one sim step, go back in pause if (ar->step_mode) { ar->step_mode = GF_FALSE; gf_ar_pause(ar, GF_TRUE, GF_FALSE, GF_FALSE); } if (!ar->need_reconfig) { if (ar->audio_listeners) { u32 k=0; GF_AudioListener *l; while ((l = (GF_AudioListener*)gf_list_enum(ar->audio_listeners, &k))) { l->on_audio_frame(l->udta, buffer, buffer_size, gf_sc_ar_get_clock(ar), delay_ms); } } ar->bytes_requested += buffer_size; ar->current_time = ar->time_at_last_config + (u32) (ar->bytes_requested * 1000 / ar->bytes_per_second); } //always return buffer size (eg requested input size to be filled), since the clock is always increased by buffer_size (cf above line) return buffer_size; } return 0; }
static GF_Err gf_ar_setup_output_format(GF_AudioRenderer *ar) { GF_Err e; u32 freq, nb_bits, nb_chan, ch_cfg; u32 in_ch, in_cfg, in_bps, in_freq; gf_mixer_get_config(ar->mixer, &freq, &nb_chan, &nb_bits, &ch_cfg); /*user disabled multichannel audio*/ if (ar->disable_multichannel && (nb_chan>2) ) nb_chan = 2; in_ch = nb_chan; in_cfg = ch_cfg; in_bps = nb_bits; in_freq = freq; if (ar->filter_chain.filters) { u32 osr, obps, och, ocfg; e = gf_afc_setup(&ar->filter_chain, nb_bits, freq, nb_chan, ch_cfg, &och, &ocfg); osr = freq; obps = nb_bits; nb_chan = och; /*try to reconfigure audio output*/ if (!e) e = ar->audio_out->ConfigureOutput(ar->audio_out, &osr, &och, &obps, ocfg); /*output module cannot support filter output, disable it ...*/ if (e || (osr != freq) || (och != nb_chan) || (obps != nb_bits)) { nb_bits = in_bps; freq = in_freq; nb_chan = in_ch; ar->filter_chain.enable_filters = GF_FALSE; e = ar->audio_out->ConfigureOutput(ar->audio_out, &freq, &nb_chan, &nb_bits, ch_cfg); } } else { e = ar->audio_out->ConfigureOutput(ar->audio_out, &freq, &nb_chan, &nb_bits, ch_cfg); } if (e) { GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("[AudioRender] reconfigure error %d\n", e)); if (nb_chan>2) { nb_chan=2; in_ch=2; ch_cfg=0; e = ar->audio_out->ConfigureOutput(ar->audio_out, &freq, &nb_chan, &nb_bits, ch_cfg); } if (e) return e; } gf_mixer_set_config(ar->mixer, freq, nb_chan, nb_bits, in_cfg); ar->audio_delay = ar->audio_out->GetAudioDelay(ar->audio_out); ar->audio_out->SetVolume(ar->audio_out, ar->volume); ar->audio_out->SetPan(ar->audio_out, ar->pan); ar->time_at_last_config = ar->current_time; ar->bytes_requested = 0; ar->bytes_per_second = freq * nb_chan * nb_bits / 8; if (ar->audio_listeners) { u32 k=0; GF_AudioListener *l; while ((l = (GF_AudioListener*)gf_list_enum(ar->audio_listeners, &k))) { l->on_audio_reconfig(l->udta, in_freq, in_bps, in_ch, in_cfg); } } return GF_OK; }