Skip to content

Commit

Permalink
Merge pull request wang-bin#100 from e3c/master
Browse files Browse the repository at this point in the history
Fix corrupt initial frames wang-bin#70
  • Loading branch information
wang-bin committed Oct 26, 2013
2 parents 96682bf 8892d0e commit a3727e9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 676,12 @@ void AVPlayer::play()
if (aCodecCtx && audio_thread) {
qDebug("Starting audio thread...");
audio_thread->start();
audio_thread->waitForReady();
}
if (vCodecCtx && video_thread) {
qDebug("Starting video thread...");
video_thread->start();
video_thread->waitForReady();
}
demuxer_thread->start();
//blockSignals(false);
Expand Down
15 changes: 14 additions & 1 deletion src/AVThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 36,7 @@ AVThreadPrivate::~AVThreadPrivate() {
next_pause = false;
cond.wakeAll();
}
ready_cond.wakeAll();
packets.setBlocking(true); //???
packets.clear();
//not neccesary context is managed by filters.
Expand Down Expand Up @@ -120,8 121,9 @@ void AVThread::stop()
pause(false);
if (d.writer)
d.writer->pause(false); //stop waiting
QMutexLocker lock(&d.ready_mutex);
d.ready = false;
//terminate();

}

//TODO: output set
Expand Down Expand Up @@ -227,6 229,9 @@ void AVThread::resetState()
d.packets.clear();
//not neccesary context is managed by filters.
d.filter_context = 0;
QMutexLocker lock(&d.ready_mutex);
d.ready = true;
d.ready_cond.wakeOne();
}

bool AVThread::tryPause(int timeout)
Expand Down Expand Up @@ -260,4 265,12 @@ void AVThread::setStatistics(Statistics *statistics)
d.statistics = statistics;
}

void AVThread::waitForReady()
{
QMutexLocker lock(&d_func().ready_mutex);
while (!d_func().ready) {
d_func().ready_cond.wait(&d_func().ready_mutex);
}
}

} //namespace QtAV
2 changes: 2 additions & 0 deletions src/QtAV/AVThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 68,8 @@ class Q_AV_EXPORT AVThread : public QThread

bool isPaused() const;

void waitForReady();

bool installFilter(Filter *filter, bool lock = true);
bool uninstallFilter(Filter *filter, bool lock = true);
const QList<Filter *> &filters() const;
Expand Down
4 changes: 4 additions & 0 deletions src/QtAV/private/AVThread_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 56,7 @@ class Q_AV_EXPORT AVThreadPrivate : public DPtrPrivate<AVThread>
, delay(0)
, filter_context(0)
, statistics(0)
, ready(false)
{
}
//DO NOT delete dec and writer. We do not own them
Expand All @@ -77,6 78,9 @@ class Q_AV_EXPORT AVThreadPrivate : public DPtrPrivate<AVThread>
Statistics *statistics; //not obj. Statistics is unique for the player, which is in AVPlayer
QList<AVOutput*> update_outputs;
QList<QRunnable*> tasks;
QWaitCondition ready_cond;
QMutex ready_mutex;
bool ready;
};

} //namespace QtAV
Expand Down

0 comments on commit a3727e9

Please sign in to comment.