forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PacketBuffer.h
88 lines (76 loc) · 2.78 KB
/
PacketBuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2015 Wang Bin <[email protected]>
* This file is part of QtAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAV_PACKETBUFFER_H
#define QTAV_PACKETBUFFER_H
#include <QtCore/QQueue>
#include <QtAV/Packet.h>
#include "utils/BlockingQueue.h"
namespace QtAV {
/*
* take empty: start buffering, block at next take if still empty
* take enough: start to put more packets
* put enough: end buffering, end take block
* put full: stop putting more packets
*/
class PacketBuffer : BlockingQueue<Packet, QQueue>
{
public:
enum BufferMode {
BufferTime,
BufferBytes,
BufferPackets
};
PacketBuffer();
~PacketBuffer();
void setBufferMode(BufferMode mode);
BufferMode bufferMode() const;
/*!
* \brief setBufferValue
* Ensure the buffered msecs/bytes/packets in queue is at least the given value
* \param value BufferBytes: bytes, BufferTime: msecs, BufferPackets: packets count
*/
void setBufferValue(int value);
int bufferValue() const;
//void setBufferMax(int max);
/*!
* \brief buffered
* Current buffered value in the queue
*/
int buffered() const;
bool isBuffering() const;
/*!
* \brief bufferProgress
* How much of the data buffer is currently filled, from 0.0 (empty) to 1.0 (enough or full).
* bufferProgress() can be less than 1 if not isBuffering();
* \return Percent of buffered time, bytes or packets.
*/
qreal bufferProgress() const;
qreal bufferSpeed() const;
protected:
bool checkEnough() const Q_DECL_OVERRIDE;
bool checkFull() const Q_DECL_OVERRIDE;
void onTake(const Packet &) Q_DECL_OVERRIDE;
void onPut(const Packet &) Q_DECL_OVERRIDE;
private:
BufferMode m_mode;
bool m_buffering;
// bytes or count
quint32 m_buffer;
qint32 m_value0, m_value1;
};
} //namespace QtAV
#endif // QTAV_PACKETBUFFER_H