-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathrtspClientHelper.hh
139 lines (125 loc) · 3.56 KB
/
rtspClientHelper.hh
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
#include <unistd.h>
#include <string.h>
#include <iostream>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <utility>
#include <memory>
#include <thread>
#include <tuple>
#include <functional>
#include <atomic>
#include <mutex>
#include <memory>
#include <chrono>
#include <random>
#include <condition_variable>
#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"
#define RTSP_CLIENT_VERBOSITY_LEVEL 1 // by default, print verbose output from each "RTSPClient"
// #define REQUEST_STREAMING_OVER_TCP False
#define DUMMY_SINK_RECEIVE_BUFFER_SIZE 1048576 // 100000
// #define DEBUG_PRINT_EACH_RECEIVED_FRAME 0
enum retcode
{
OK = 1,
FAIL,
ERR_INVALID_PARAM,
ERR_TIMEOUT,
ERR_NOT_IMPLEMENTED,
ERR_NOT_FOUND,
ERR_NOT_SUPPORT,
ERR_NOT_READY,
ERR_NOT_EXIST,
ERR_NOT_INIT,
ERR_NOT_MATCH,
ERR_NOT_ENOUGH_SPACE,
ERR_NOT_ENOUGH_DATA,
ERR_NOT_ENOUGH_TIME,
ERR_NOT_ENOUGH_RESOURCE,
ERR_NOT_ENOUGH_STORAGE,
ERR_NOT_ENOUGH_MEMORY
};
class StreamClientState
{
public:
StreamClientState();
virtual ~StreamClientState();
public:
MediaSubsessionIterator *iter;
MediaSession *session;
MediaSubsession *subsession;
TaskToken streamTimerTask;
double duration;
};
class rtspPlayer
{
public:
char watchVariable;
bool isPlaying;
bool overTCP;
int startRTSP(const char *url, bool overTCP, const char *username, const char *password);
void stopRTSP();
void (*onConnectionSetup)(char *, void *);
void (*onFrameData)(unsigned char *, const char *, unsigned, unsigned, struct timeval, void *);
void *privateData;
rtspPlayer(void *data)
{
onFrameData = NULL;
onConnectionSetup = NULL;
overTCP = false;
privateData = data;
}
~rtspPlayer()
{
}
private:
void playRTSP(const char *url, const char *username, const char *password);
};
class ourRTSPClient : public RTSPClient
{
public:
rtspPlayer *player;
unsigned rtspClientCount;
bool isClosed;
static ourRTSPClient *createNew(UsageEnvironment &env, char const *rtspURL,
int verbosityLevel = 0,
char const *applicationName = NULL,
portNumBits tunnelOverHTTPPortNum = 0);
protected:
ourRTSPClient(UsageEnvironment &env, char const *rtspURL,
int verbosityLevel, char const *applicationName, portNumBits tunnelOverHTTPPortNum);
// called only by createNew();
virtual ~ourRTSPClient();
public:
StreamClientState scs;
};
class DummySink : public MediaSink
{
public:
rtspPlayer *player;
static DummySink *createNew(UsageEnvironment &env,
MediaSubsession &subsession, // identifies the kind of data that's being received
char const *streamId = NULL); // identifies the stream itself (optional)
private:
DummySink(UsageEnvironment &env, MediaSubsession &subsession, char const *streamId);
// called only by "createNew()"
virtual ~DummySink();
static void afterGettingFrame(void *clientData, unsigned frameSize,
unsigned numTruncatedBytes,
struct timeval presentationTime,
unsigned durationInMicroseconds);
void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes,
struct timeval presentationTime, unsigned durationInMicroseconds);
private:
// redefined virtual functions:
virtual Boolean continuePlaying();
private:
u_int8_t *fReceiveBuffer;
MediaSubsession &fSubsession;
char *fStreamId;
};