void uninit_audio_chain(struct MPContext *mpctx) { if (mpctx->d_audio) { mixer_uninit_audio(mpctx->mixer); audio_uninit(mpctx->d_audio); mpctx->d_audio = NULL; talloc_free(mpctx->ao_buffer); mpctx->ao_buffer = NULL; mpctx->audio_status = STATUS_EOF; reselect_demux_streams(mpctx); } }
//****************************************************************************************** // open & setup audio device // return: 1=success 0=fail static int audio_init(int rate, int channels, int format, int flags) { CSingleLock lock(m_critAudio); char strFourCC[10]; char strAudioCodec[128]; long lBitRate; long lSampleRate; int iChannels; BOOL bVBR; bool bAC3PassThru = false; audio_uninit(1); //Make sure nothing else was uninted first. mplayer sometimes forgets. mplayer_GetAudioInfo(strFourCC, strAudioCodec, &lBitRate, &lSampleRate, &iChannels, &bVBR); int ao_format_bits; //Make sure we only accept formats that we can handle switch (format) { case AFMT_AC3: ao_format_bits = 16; break; case AFMT_S16_LE: case AFMT_S8: case AFMT_U8: //Not sure about this one, added as we have handling for it later ao_format_bits = audio_out_format_bits(format); break; default: CLog::Log(LOGDEBUG, "ao_win32: format %d not supported defaulting to Signed 16-bit Little-Endian\n", format); format = AFMT_S16_LE; ao_format_bits = audio_out_format_bits(format); } pao_data = GetAOData(); channels = pao_data->channels; //In the case of forced audio filter, channel number for the GetAudioInfo, and from pao_data //is not the same, so the follwing two lines are not correct //Make sure we only output as many channels as we how. don't try to create any virtual. //if (channels > iChannels) channels = iChannels; // Check whether we are passing digital output direct through. // Anything with 48kHz 2 channel audio can be passed direct. if (g_guiSettings.GetInt("audiooutput.mode") == AUDIO_DIGITAL) { // Check that we are allowed to pass through DD or DTS if (strstr(strAudioCodec, "SPDIF")) bAC3PassThru = true; } if (bAC3PassThru) { channels = 2; // ac3 passthru m_pAudioDecoder = new CAc97DirectSound(m_pAudioCallback, channels, rate, ao_format_bits, bAC3PassThru); } else { // check if we should resample this audio // currently we don't do this for videos for fear of CPU issues bool bResample = false; if( !mplayer_HasVideo() && channels <= 2 && rate != 48000 ) bResample = true; if ( channels == 3 || channels == 5 || channels > 6 ) return 1; // this is an ugly hack due to our code use mplayer_open_file for both playing file, and format detecttion if(bResample) m_pAudioDecoder = new CResampleDirectSound(m_pAudioCallback, channels, rate, ao_format_bits, strAudioCodec, !mplayer_HasVideo()); else m_pAudioDecoder = new CASyncDirectSound(m_pAudioCallback, channels, rate, ao_format_bits, strAudioCodec, !mplayer_HasVideo()); } pao_data->channels = channels; pao_data->samplerate = rate; pao_data->format = format; pao_data->bps = channels * rate; if (format != AFMT_U8 && format != AFMT_S8) { pao_data->bps *= (ao_format_bits / 8); } pao_data->outburst = m_pAudioDecoder->GetChunkLen(); if( mplayer_HasVideo() ) { m_waitvideo = 5; /* allow 5 empty returns after filling audio buffer */ m_pAudioDecoder->Pause(); } return 1; }