Skip to content

Commit

Permalink
remove AVThreadPrivate.writer. audio part not finished
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Nov 17, 2013
1 parent e7563f9 commit d00fd7d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ VideoRenderer *AVPlayer::renderer()
{
//QList assert empty in debug mode
if (mpVOSet->outputs().isEmpty())
return 0;
return 0;
return static_cast<VideoRenderer*>(mpVOSet->outputs().last());
}

Expand Down Expand Up @@ -216,15 +216,15 @@ void AVPlayer::setAVOutput(Out *&pOut, Out *pNew, AVThread *thread)
return;
}
//FIXME: what if isPaused()==false but pause(true) in another thread?
bool need_lock = isPlaying() && !thread->isPaused();
if (need_lock)
thread->lock();
//bool need_lock = isPlaying() && !thread->isPaused();
//if (need_lock)
// thread->lock();
qDebug("set AVThread output");
thread->setOutput(pOut);
if (pOut) {
pOut->setStatistics(&mStatistics);
if (need_lock)
thread->unlock(); //??why here?
//if (need_lock)
// thread->unlock(); //??why here?
}
//now the old avoutput is not used by avthread, we can delete it safely
//AVOutput must be allocated in heap. Just like QObject's children.
Expand Down Expand Up @@ -886,6 +886,7 @@ bool AVPlayer::setupAudioThread()
audio_thread->setClock(clock);
audio_thread->setDecoder(audio_dec);
audio_thread->setStatistics(&mStatistics);
audio_thread->setOutputSet(mpAOSet);
qDebug("demux thread setAudioThread");
demuxer_thread->setAudioThread(audio_thread);
//reconnect if disconnected
Expand Down
15 changes: 9 additions & 6 deletions src/AVThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ void AVThread::stop()
d.packets.setBlocking(false); //stop blocking take()
d.packets.clear();
pause(false);
if (d.writer)
d.writer->pause(false); //stop waiting
QMutexLocker lock(&d.ready_mutex);
d.ready = false;
//terminate();
Expand Down Expand Up @@ -184,14 +182,21 @@ AVDecoder* AVThread::decoder() const

void AVThread::setOutput(AVOutput *out)
{
d_func().writer = out;
DPTR_D(AVThread);
if (!d.outputSet)
return;
d_func().outputSet->addOutput(out);
}

AVOutput* AVThread::output() const
{
return d_func().writer;
DPTR_D(const AVThread);
if (!d.outputSet || d.outputSet->outputs().isEmpty())
return 0;
return d.outputSet->outputs().first();
}

// TODO: remove?
void AVThread::setOutputSet(OutputSet *set)
{
d_func().outputSet = set;
Expand All @@ -211,8 +216,6 @@ void AVThread::resetState()
{
DPTR_D(AVThread);
pause(false);
if (d.writer)
d.writer->pause(false); //stop waiting. Important when replay
d.stop = false;
d.demux_end = false;
d.packets.setBlocking(true);
Expand Down
6 changes: 4 additions & 2 deletions src/AudioThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QtAV/AudioOutput.h>
#include <QtAV/AudioResampler.h>
#include <QtAV/AVClock.h>
#include <QtAV/OutputSet.h>
#include <QtAV/QtAV_Compat.h>
#include <QtCore/QCoreApplication>

Expand Down Expand Up @@ -57,12 +58,12 @@ void AudioThread::run()
{
DPTR_D(AudioThread);
//No decoder or output. No audio output is ok, just display picture
if (!d.dec || !d.dec->isAvailable())
if (!d.dec || !d.dec->isAvailable() || !d.outputSet)
return;
resetState();
Q_ASSERT(d.clock != 0);
AudioDecoder *dec = static_cast<AudioDecoder*>(d.dec);
AudioOutput *ao = static_cast<AudioOutput*>(d.writer);
AudioOutput *ao = static_cast<AudioOutput*>(d.outputSet->outputs().first()); //TODO: not here
static const double max_len = 0.02; //TODO: how to choose?
d.init();
//TODO: bool need_sync in private class
Expand Down Expand Up @@ -131,6 +132,7 @@ void AudioThread::run()
//DO NOT decode and convert if ao is not available or mute!
bool has_ao = ao && ao->isAvailable();
//if (!has_ao) {//do not decode?
// TODO: move resampler to AudioFrame, like VideoFrame does
if (has_ao && dec->resampler()) {
if (dec->resampler()->speed() != ao->speed()
|| dec->resampler()->outAudioFormat() != ao->audioFormat()) {
Expand Down
6 changes: 3 additions & 3 deletions src/QtAV/AVOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/

#ifndef QAV_WRITER_H
#define QAV_WRITER_H
#ifndef QAV_AVOUTPUT_H
#define QAV_AVOUTPUT_H

#include <QtCore/QByteArray>
#include <QtAV/QtAV_Global.h>
Expand Down Expand Up @@ -93,4 +93,4 @@ class Q_AV_EXPORT AVOutput
};

} //namespace QtAV
#endif //QAV_WRITER_H
#endif //QAV_AVOUTPUT_H
3 changes: 0 additions & 3 deletions src/QtAV/private/AVThread_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ class Q_AV_EXPORT AVThreadPrivate : public DPtrPrivate<AVThread>
, clock(0)
, dec(0)
, outputSet(0)
, writer(0)
, delay(0)
, filter_context(0)
, statistics(0)
, ready(false)
{
}
//DO NOT delete dec and writer. We do not own them
virtual ~AVThreadPrivate();

bool paused, next_pause;
Expand All @@ -69,7 +67,6 @@ class Q_AV_EXPORT AVThreadPrivate : public DPtrPrivate<AVThread>
PacketQueue packets;
AVDecoder *dec;
OutputSet *outputSet;
AVOutput *writer;
QMutex mutex;
QWaitCondition cond; //pause
qreal delay;
Expand Down

0 comments on commit d00fd7d

Please sign in to comment.