Skip to content

Commit

Permalink
use PacketBuffer instead of a simple blocking queue
Browse files Browse the repository at this point in the history
rename AVThread.packetQueue()?
  • Loading branch information
wang-bin committed Mar 18, 2015
1 parent 128cce3 commit ce7b02b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 33 deletions.
10 changes: 3 additions & 7 deletions src/AVDemuxThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@
#include "QtAV/AVClock.h"
#include "QtAV/AVDemuxer.h"
#include "QtAV/AVDecoder.h"
#include "QtAV/Packet.h"
#include "AVThread.h"
#include "VideoThread.h"
#include <QtCore/QTime>
#include <QtCore/QTimer>
#include <QtCore/QEventLoop>
#include "utils/Logger.h"

#define RESUME_ONCE_ON_SEEK 0

namespace QtAV {

class QueueEmptyCall : public PacketQueue::StateChangeCallback
class QueueEmptyCall : public PacketBuffer::StateChangeCallback
{
public:
QueueEmptyCall(AVDemuxThread* thread):
Expand Down Expand Up @@ -385,8 +381,8 @@ void AVDemuxThread::run()
Packet pkt;
pause(false);
qDebug("get av queue a/v thread = %p %p", audio_thread, video_thread);
PacketQueue *aqueue = audio_thread ? audio_thread->packetQueue() : 0;
PacketQueue *vqueue = video_thread ? video_thread->packetQueue() : 0;
PacketBuffer *aqueue = audio_thread ? audio_thread->packetQueue() : 0;
PacketBuffer *vqueue = video_thread ? video_thread->packetQueue() : 0;
if (aqueue) {
aqueue->clear();
aqueue->setBlocking(true);
Expand Down
3 changes: 1 addition & 2 deletions src/AVDemuxThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
#include <QtCore/QAtomicInt>
#include <QtCore/QMutex>
#include <QtCore/QThread>
#include <QtCore/QQueue>
#include <QtCore/QRunnable>
#include "QtAV/CommonTypes.h"
#include "utils/BlockingQueue.h"
#include "PacketBuffer.h"

namespace QtAV {

Expand Down
1 change: 1 addition & 0 deletions src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ void AVPlayer::setFrameRate(qreal value)
{
d->force_fps = value;
// clock set here will be reset in playInternal()
// also we can't change user's setting of ClockType and autoClock here if force frame rate is disabled.
}

qreal AVPlayer::forcedFrameRate() const
Expand Down
14 changes: 6 additions & 8 deletions src/AVPlayerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,9 @@ bool AVPlayer::Private::setupAudioThread(AVPlayer *player)
}
athread->setDecoder(adec);
player->setAudioOutput(ao);
int queue_min = 0.61803*qMax<qreal>(24.0, statistics.video_only.frame_rate);
int queue_max = int(1.61803*(qreal)queue_min); //about 1 second
athread->packetQueue()->setCapacity(queue_max);
athread->packetQueue()->setThreshold(queue_min);
const int queue_min = 0.61803*qMax<qreal>(24.0, statistics.video_only.frame_rate);
athread->packetQueue()->setBufferMode(PacketBuffer::BufferPackets);
athread->packetQueue()->setBufferValue(queue_min);
initAudioStatistics(demuxer.audioStream());
return true;
}
Expand Down Expand Up @@ -469,10 +468,9 @@ bool AVPlayer::Private::setupVideoThread(AVPlayer *player)
vthread->setBrightness(brightness);
vthread->setContrast(contrast);
vthread->setSaturation(saturation);
int queue_min = 0.61803*qMax<qreal>(24.0, statistics.video_only.frame_rate);
int queue_max = int(1.61803*(qreal)queue_min); //about 1 second
vthread->packetQueue()->setCapacity(queue_max);
vthread->packetQueue()->setThreshold(queue_min);
const int queue_min = 0.61803*qMax<qreal>(24.0, statistics.video_only.frame_rate);
vthread->packetQueue()->setBufferMode(PacketBuffer::BufferPackets);
vthread->packetQueue()->setBufferValue(queue_min);
initVideoStatistics(demuxer.videoStream());
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/AVThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ AVClock* AVThread::clock() const
return d_func().clock;
}

PacketQueue* AVThread::packetQueue() const
PacketBuffer* AVThread::packetQueue() const
{
return const_cast<PacketQueue*>(&d_func().packets);
return const_cast<PacketBuffer*>(&d_func().packets);
}

void AVThread::setDecoder(AVDecoder *decoder)
Expand Down
11 changes: 3 additions & 8 deletions src/AVThread.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2015 Wang Bin <[email protected]>
* This file is part of QtAV
Expand All @@ -25,14 +25,11 @@
#include <QtCore/QRunnable>
#include <QtCore/QScopedPointer>
#include <QtCore/QThread>
#include "QtAV/Packet.h"
#include "utils/BlockingQueue.h"
#include "PacketBuffer.h"
//TODO: pause functions. AVOutput may be null, use AVThread's pause state

namespace QtAV {

typedef BlockingQueue<Packet, QQueue> PacketQueue;

class AVDecoder;
class AVThreadPrivate;
class AVOutput;
Expand All @@ -55,8 +52,7 @@ class AVThread : public QThread
void setClock(AVClock *clock);
AVClock* clock() const;

//void setPacketQueue(PacketQueue *queue);
PacketQueue* packetQueue() const;
PacketBuffer* packetQueue() const;

void setDecoder(AVDecoder *decoder);
AVDecoder *decoder() const;
Expand All @@ -79,7 +75,6 @@ class AVThread : public QThread

// TODO: resample, resize task etc.
void scheduleTask(QRunnable *task);

//only decode video without display or skip decode audio until pts reaches
void skipRenderUntil(qreal pts);

Expand Down
9 changes: 3 additions & 6 deletions src/AVThread_p.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
Copyright (C) 2012-2015 Wang Bin <[email protected]>
* This file is part of QtAV
Expand All @@ -24,11 +24,8 @@

#include <QtCore/QMutex>
#include <QtCore/QMutexLocker>
#include <QtCore/QQueue>
#include <QtCore/QWaitCondition>
#include "QtAV/Packet.h"
#include "utils/BlockingQueue.h"
//#include "AVThread.h" //PacketQueue
#include "PacketBuffer.h"

class QRunnable;
namespace QtAV {
Expand Down Expand Up @@ -65,7 +62,7 @@ class AVThreadPrivate : public DPtrPrivate<AVThread>
bool demux_end;
volatile bool stop; //true when packets is empty and demux is end.
AVClock *clock;
BlockingQueue<Packet, QQueue> packets;
PacketBuffer packets;
AVDecoder *dec;
OutputSet *outputSet;
QMutex mutex;
Expand Down

0 comments on commit ce7b02b

Please sign in to comment.