forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Statistics.cpp
135 lines (116 loc) · 3.13 KB
/
Statistics.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
* This file is part of QtAV (from 2013)
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
******************************************************************************/
#include "QtAV/Statistics.h"
#include "utils/ring.h"
namespace QtAV {
Statistics::Common::Common():
available(false)
, bit_rate(0)
, frames(0)
, frame_rate(0)
{
}
Statistics::AudioOnly::AudioOnly():
sample_rate(0)
, channels(0)
, frame_size(0)
, block_align(0)
{
}
class Statistics::VideoOnly::Private : public QSharedData {
public:
Private()
: pts(0)
, history(ring<qreal>(30))
{}
qreal pts;
ring<qreal> history;
};
Statistics::VideoOnly::VideoOnly():
width(0)
, height(0)
, coded_width(0)
, coded_height(0)
, gop_size(0)
, rotate(0)
, d(new Private())
{
}
Statistics::VideoOnly::VideoOnly(const VideoOnly& v)
: width(v.width)
, height(v.height)
, coded_width(v.coded_width)
, coded_height(v.coded_height)
, gop_size(v.gop_size)
, rotate(v.rotate)
, d(v.d)
{
}
Statistics::VideoOnly& Statistics::VideoOnly::operator =(const VideoOnly& v)
{
width = v.width;
height = v.height;
coded_width = v.coded_width;
coded_height = v.coded_height;
gop_size = v.gop_size;
rotate = v.rotate;
d = v.d;
return *this;
}
Statistics::VideoOnly::~VideoOnly()
{
}
qreal Statistics::VideoOnly::pts() const
{
return d->pts;
}
qint64 Statistics::VideoOnly::frameDisplayed(qreal pts)
{
d->pts = pts;
const qint64 msecs = QDateTime::currentMSecsSinceEpoch();
const qreal t = (double)msecs/1000.0;
d->history.push_back(t);
return msecs;
}
// d->history is not thread safe!
qreal Statistics::VideoOnly::currentDisplayFPS() const
{
if (d->history.empty())
return 0;
// DO NOT use d->history.last-first
const qreal dt = (double)QDateTime::currentMSecsSinceEpoch()/1000.0 - d->history.front();
// dt should be always > 0 because history stores absolute time
if (qFuzzyIsNull(dt))
return 0;
return (qreal)d->history.size()/dt;
}
Statistics::Statistics()
{
}
Statistics::~Statistics()
{
}
void Statistics::reset()
{
url = QString();
audio = Common();
video = Common();
audio_only = AudioOnly();
video_only = VideoOnly();
metadata.clear();
}
} //namespace QtAV