void AVPlayer::setSpeed(qreal speed) { if (speed == mSpeed) return; mSpeed = speed; //TODO: check clock type? if (_audio && _audio->isAvailable()) { qDebug("set speed %.2f", mSpeed); _audio->setSpeed(mSpeed); } else { masterClock()->setSpeed(mSpeed); } emit speedChanged(mSpeed); }
void AVPlayer::setupAudioThread() { if (aCodecCtx) { qDebug("has audio"); if (!audio_dec) { audio_dec = new AudioDecoder(); } qDebug("setCodecContext"); audio_dec->setCodecContext(aCodecCtx); //TODO: setAudioOutput() like vo if (!_audio) { qDebug("new audio output"); #if HAVE_OPENAL _audio = new AOOpenAL(); #elif HAVE_PORTAUDIO _audio = new AOPortAudio(); #endif } if (!_audio) { masterClock()->setClockType(AVClock::ExternalClock); return; } _audio->setSampleRate(aCodecCtx->sample_rate); _audio->setChannels(aCodecCtx->channels); if (!_audio->open()) { //return; //audio not ready } if (!audio_thread) { qDebug("new audio thread"); audio_thread = new AudioThread(this); audio_thread->setClock(clock); audio_thread->setDecoder(audio_dec); audio_thread->setStatistics(&mStatistics); qDebug("demux thread setAudioThread"); demuxer_thread->setAudioThread(audio_thread); //reconnect if disconnected } setAudioOutput(_audio); /*if has video, connect video's only to avoid emitting stopped() mulltiple times *otherwise connect audio's. but if video exists previously and now is null. *audio thread will not change. so connection should be here */ if (!vCodecCtx) { disconnect(audio_thread, SIGNAL(finished()), this, SIGNAL(stopped())); connect(audio_thread, SIGNAL(finished()), this, SIGNAL(stopped()), Qt::DirectConnection); } int queue_min = 0.61803*qMax<qreal>(24.0, mStatistics.video.fps); int queue_max = int(1.61803*(qreal)queue_min); //about 1 second audio_thread->packetQueue()->setThreshold(queue_min); audio_thread->packetQueue()->setCapacity(queue_max); } else { //set 0 before delete because demux thread will use the address //TODO: use avthread** ? demuxer_thread->setAudioThread(0); if (audio_thread) { qDebug("release audio thread."); delete audio_thread; audio_thread = 0; //shared ptr? } if (audio_dec) { delete audio_dec; audio_dec = 0; } //DO NOT delete AVOutput. it is setted by user } }