forked from ZoneMinder/zoneminder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzm_rtp_source.h
192 lines (157 loc) · 4.82 KB
/
zm_rtp_source.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//
// ZoneMinder RTP Source Class Interface, $Date$, $Revision$
// Copyright (C) 2001-2008 Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#ifndef ZM_RTP_SOURCE_H
#define ZM_RTP_SOURCE_H
#include "zm_buffer.h"
#include "zm_ffmpeg.h"
#include "zm_thread.h"
#include <sys/time.h>
#include <stdint.h>
#include <string>
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,25,0)
#define _AVCODECID AVCodecID
#else
#define _AVCODECID CodecID
#endif
struct RtpDataHeader;
class RtpSource
{
public:
typedef enum { EMPTY, FILLING, READY } FrameState;
private:
static const int RTP_SEQ_MOD = 1<<16;
static const int MAX_DROPOUT = 3000;
static const int MAX_MISORDER = 100;
static const int MIN_SEQUENTIAL = 2;
private:
// Identity
int mId; // General id (usually monitor id)
std::string mCname; // Canonical name, for SDES
// RTP/RTCP fields
uint32_t mSsrc;
uint16_t mMaxSeq; // highest seq. number seen
uint32_t mCycles; // shifted count of seq. number cycles
uint32_t mBaseSeq; // base seq number
uint32_t mBadSeq; // last 'bad' seq number + 1
uint32_t mProbation; // sequ. packets till source is valid
uint32_t mReceivedPackets; // packets received
uint32_t mExpectedPrior; // packet expected at last interval
uint32_t mReceivedPrior; // packet received at last interval
uint32_t mTransit; // relative trans time for prev pkt
uint32_t mJitter; // estimated jitter
// Ports/Channels
std::string mLocalHost;
int mLocalPortChans[2];
std::string mRemoteHost;
int mRemotePortChans[2];
// Time keys
uint32_t mRtpClock;
uint32_t mRtpFactor;
struct timeval mBaseTimeReal;
struct timeval mBaseTimeNtp;
uint32_t mBaseTimeRtp;
struct timeval mLastSrTimeReal;
uint32_t mLastSrTimeNtpSecs;
uint32_t mLastSrTimeNtpFrac;
struct timeval mLastSrTimeNtp;
uint32_t mLastSrTimeRtp;
// Stats, intermittently updated
uint32_t mExpectedPackets;
uint32_t mLostPackets;
uint8_t mLostFraction;
_AVCODECID mCodecId;
Buffer mFrame;
int mFrameCount;
bool mFrameGood;
bool prevM;
ThreadData<bool> mFrameReady;
ThreadData<bool> mFrameProcessed;
private:
void init( uint16_t seq );
public:
RtpSource( int id, const std::string &localHost, int localPortBase, const std::string &remoteHost, int remotePortBase, uint32_t ssrc, uint16_t seq, uint32_t rtpClock, uint32_t rtpTime, _AVCODECID codecId );
bool updateSeq( uint16_t seq );
void updateJitter( const RtpDataHeader *header );
void updateRtcpData( uint32_t ntpTimeSecs, uint32_t ntpTimeFrac, uint32_t rtpTime );
void updateRtcpStats();
bool handlePacket( const unsigned char *packet, size_t packetLen );
uint32_t getSsrc() const
{
return( mSsrc );
}
void setSsrc( uint32_t ssrc )
{
mSsrc = ssrc;
}
bool getFrame( Buffer &buffer );
const std::string &getCname() const
{
return( mCname );
}
const std::string &getLocalHost() const
{
return( mLocalHost );
}
int getLocalDataPort() const
{
return( mLocalPortChans[0] );
}
int getLocalCtrlPort() const
{
return( mLocalPortChans[1] );
}
const std::string &getRemoteHost() const
{
return( mRemoteHost );
}
int getRemoteDataPort() const
{
return( mRemotePortChans[0] );
}
int getRemoteCtrlPort() const
{
return( mRemotePortChans[1] );
}
uint32_t getMaxSeq() const
{
return( mCycles + mMaxSeq );
}
uint32_t getExpectedPackets() const
{
return( mExpectedPackets );
}
uint32_t getLostPackets() const
{
return( mLostPackets );
}
uint8_t getLostFraction() const
{
return( mLostFraction );
}
uint32_t getJitter() const
{
return( mJitter >> 4 );
}
uint32_t getLastSrTimestamp() const
{
return( ((mLastSrTimeNtpSecs&0xffff)<<16)|(mLastSrTimeNtpFrac>>16) );
}
};
#undef _AVCODECID
#endif // ZM_RTP_SOURCE_H