Valkka  0.17.0
OpenSource Video Management
live.h
Go to the documentation of this file.
1 #ifndef live_HEADER_GUARD
2 #define live_HEADER_GUARD
3 /*
4  * live.h : Interface to live555
5  *
6  * Copyright 2017, 2018 Valkka Security Ltd. and Sampsa Riikonen.
7  *
8  * Authors: Sampsa Riikonen <sampsa.riikonen@iki.fi>
9  *
10  * This file is part of the Valkka library.
11  *
12  * Valkka is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>
24  *
25  */
26 
38 #include "livedep.h"
39 #include "frame.h"
40 #include "framefifo.h"
41 #include "framefilter.h"
42 #include "logging.h"
43 
44 UsageEnvironment& operator<<(UsageEnvironment& env, const RTSPClient& rtspClient);
45 UsageEnvironment& operator<<(UsageEnvironment& env, const MediaSubsession& subsession);
46 Logger& operator<<(Logger& logger, const RTSPClient& rtspClient);
47 Logger& operator<<(Logger& logger, const MediaSubsession& subsession);
48 void usage(UsageEnvironment& env, char const* progName);
49 
50 
51 
62 enum class LiveStatus {
63  none,
64  pending,
65  alive,
66  closed
67 };
68 
69 
79 public:
81  virtual ~StreamClientState();
82 
83 public:
84  MediaSubsessionIterator* iter;
86  MediaSession* session;
87  MediaSubsession* subsession;
88  TaskToken streamTimerTask;
90 
91  double duration;
92  bool frame_flag;
93 
94 public:
95  void close();
96 
97 public: // setters & getters
98  void setFrame() {this->frame_flag=true;}
99  void clearFrame() {this->frame_flag=false;}
100  bool gotFrame() {return this->frame_flag;}
101 };
102 
103 
104 
111 class ValkkaRTSPClient: public RTSPClient {
112 
113 public:
123  static ValkkaRTSPClient* createNew(UsageEnvironment& env, const std::string rtspURL, FrameFilter& framefilter, LiveStatus* livestatus, int verbosityLevel = 0, char const* applicationName = NULL, portNumBits tunnelOverHTTPPortNum = 0);
124 
125 protected:
126  ValkkaRTSPClient(UsageEnvironment& env, const std::string rtspURL, FrameFilter& framefilter, LiveStatus* livestatus, int verbosityLevel, char const* applicationName, portNumBits tunnelOverHTTPPortNum);
128  virtual ~ValkkaRTSPClient();
129 
130 public:
131  StreamClientState scs;
134 
135 public: // some extra parameters and their setters
137  bool request_tcp;
138  unsigned recv_buffer_size;
139  unsigned reordering_time;
140  void requestMulticast() {this->request_multicast=true;}
141  void requestTCP() {this->request_tcp=true;}
142  void setRecvBufferSize(unsigned i) {this->recv_buffer_size=i;}
143  void setReorderingTime(unsigned i) {this->reordering_time=i;}
144 
145 public:
146  // Response handlers
147  static void continueAfterDESCRIBE(RTSPClient* rtspClient, int resultCode, char* resultString);
148  static void continueAfterGET_PARAMETER(RTSPClient* rtspClient, int resultCode, char* resultString);
149  static void continueAfterSETUP(RTSPClient* rtspClient, int resultCode, char* resultString);
150  static void continueAfterPLAY(RTSPClient* rtspClient, int resultCode, char* resultString);
151 
152  // Other event handler functions:
153  static void subsessionAfterPlaying(void* clientData);
154  static void subsessionByeHandler(void* clientData);
155  static void streamTimerHandler(void* clientData);
156  static void setupNextSubsession(RTSPClient* rtspClient);
157  static void shutdownStream(RTSPClient* rtspClient, int exitCode = 1);
158  static void pingGetParameter(void* clientData);
159 };
160 
161 
168 class FrameSink: public MediaSink {
169 
170 public:
171 
180  static FrameSink* createNew(UsageEnvironment& env, StreamClientState& scs, FrameFilter& framefilter, char const* streamId = NULL);
181 
182 private:
183  FrameSink(UsageEnvironment& env, StreamClientState& scs, FrameFilter& framefilter, char const* streamId);
185  virtual ~FrameSink();
186 
187  static void afterGettingFrame(void* clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds);
188  void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds);
189 
190 private:
191  void setReceiveBuffer(unsigned target_size);
192  unsigned checkBufferSize(unsigned target_size);
193  void sendParameterSets();
194 
195 private: // redefined virtual functions:
196  virtual Boolean continuePlaying();
197 
198 private:
199  StreamClientState &scs;
200  u_int8_t* fReceiveBuffer;
201  long unsigned nbuf;
202  MediaSubsession& fSubsession;
203  char* fStreamId;
204  FrameFilter& framefilter;
207  int subsession_index;
208 
209 public: // getters & setters
210  uint8_t* getReceiveBuffer() {return fReceiveBuffer;}
211 
212 public:
213  bool on;
214 };
215 
216 #endif
unsigned recv_buffer_size
Operating system ringbuffer size for incoming socket.
Definition: live.h:138
Custom payload Frame.
Definition: frame.h:160
Thread safe system of fifo and a stack.
TaskToken pingGetParameterTask
Ping the camera periodically with GET_PARAMETER query.
Definition: live.h:89
bool frame_flag
Set always when a frame is received.
Definition: live.h:92
int subsession_index
Managed by RTSPClient or SDPClient.
Definition: live.h:85
BasicFrame basicframe
Data is being copied into this frame.
Definition: live.h:206
MediaSession * session
Created by RTSPClient or SDPClient. Closed by StreamClientState::~StreamClientState.
Definition: live.h:86
Live555 handling of media frames.
Definition: live.h:168
FrameFilter & framefilter
Target frame filter where frames are being fed.
Definition: live.h:132
Class to hold per-stream state that we maintain throughout each stream&#39;s lifetime.
Definition: live.h:78
Logging utilities.
undefined (initial value)
Definition: usbthread.h:143
UsageEnvironment & operator<<(UsageEnvironment &env, const RTSPClient &rtspClient)
A function that outputs a string that identifies each stream (for debugging output).
Definition: live.cpp:47
SetupFrame setupframe
This frame is used to send subsession information.
Definition: live.h:205
turn decoding on
Frame classes.
Logging facility.
Definition: logging.h:63
LiveStatus
Status for the ValkkaRTSPClient.
Definition: live.h:62
MediaSubsession * subsession
Created by RTSPClient or SDPClient. Closed by StreamClientState::close.
Definition: live.h:87
LiveStatus * livestatus
This points to a variable that is being used by LiveThread to inform about the stream state...
Definition: live.h:133
bool request_multicast
Request multicast during rtsp negotiation.
Definition: live.h:136
Handles a live555 RTSP connection.
Definition: live.h:111
Definition of FrameFilter and derived classes for various purposes.
Client has succesfully started playing.
long unsigned nbuf
Size of bytebuffer.
Definition: live.h:201
unsigned reordering_time
Live555 packet reordering treshold time (microsecs)
Definition: live.h:139
Client has been closed and Medium::close has been called on the MediaSession, etc. This is done by shutdownStream (which sets livestatus to LiveStatus::closed). ValkkaRTSPClient has been annihilated!
Setup frame.
Definition: frame.h:270
Client&#39;s been requested to send the describe command. This might hang for several reasons: camera off...
MediaSubsessionIterator * iter
Created by RTSPClient or SDPClient. Deleted by StreamClientState::~StreamClientState.
Definition: live.h:84
List of common header files.
The mother class of all frame filters! FrameFilters are used to create "filter chains".
Definition: framefilter.h:46
bool request_tcp
Request interleaved streaming over tcp.
Definition: live.h:137