Valkka  1.6.1
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  * (c) Copyright 2017-2024 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 Lesser 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 Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser 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:
124  static ValkkaRTSPClient* createNew(UsageEnvironment& env, const std::string rtspURL, FrameFilter& framefilter, LiveStatus* livestatus, bool& termplease, int verbosityLevel = 0, char const* applicationName = NULL, portNumBits tunnelOverHTTPPortNum = 0);
125 
126 protected:
127  ValkkaRTSPClient(UsageEnvironment& env, const std::string rtspURL, FrameFilter& framefilter, LiveStatus* livestatus, bool& termplease, int verbosityLevel, char const* applicationName, portNumBits tunnelOverHTTPPortNum);
129  virtual ~ValkkaRTSPClient();
130 
131 public:
132  bool passthrough;
133 
134 public:
135  StreamClientState scs;
138  bool& termplease;
139 
140 public: // some extra parameters and their setters
142  bool request_tcp;
143  unsigned recv_buffer_size;
144  unsigned reordering_time;
145  void requestMulticast() {this->request_multicast=true;}
146  void requestTCP() {this->request_tcp=true;}
147  void setRecvBufferSize(unsigned i) {this->recv_buffer_size=i;}
148  void setReorderingTime(unsigned i) {this->reordering_time=i;}
149 
150 public:
151  // Response handlers
152  static void continueAfterDESCRIBE(RTSPClient* rtspClient, int resultCode, char* resultString);
153  static void continueAfterGET_PARAMETER(RTSPClient* rtspClient, int resultCode, char* resultString);
154  static void continueAfterSETUP(RTSPClient* rtspClient, int resultCode, char* resultString);
155  static void continueAfterPLAY(RTSPClient* rtspClient, int resultCode, char* resultString);
156 
157  // Other event handler functions:
158  static void subsessionAfterPlaying(void* clientData);
159  static void subsessionByeHandler(void* clientData);
160  static void streamTimerHandler(void* clientData);
161  static void setupNextSubsession(RTSPClient* rtspClient);
162  static void shutdownStream(RTSPClient* rtspClient, int exitCode = 1);
163  static void pingGetParameter(void* clientData);
164 };
165 
166 
173 class FrameSink: public MediaSink {
174 
175 public:
176 
185  static FrameSink* createNew(UsageEnvironment& env,
186  StreamClientState& scs, FrameFilter& framefilter, bool& passthrough,
187  char const* streamId = NULL);
188 
189 private:
190  FrameSink(UsageEnvironment& env,
191  StreamClientState& scs, FrameFilter& framefilter, bool& passthrough,
192  char const* streamId);
194  virtual ~FrameSink();
195 
196  static void afterGettingFrame(void* clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds);
197  void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds);
198 
199 private:
200  void setReceiveBuffer(unsigned target_size);
201  unsigned checkBufferSize(unsigned target_size);
202  void sendParameterSets();
203 
204 private: // redefined virtual functions:
205  virtual Boolean continuePlaying();
206 
207 private:
208  StreamClientState &scs;
209  u_int8_t* fReceiveBuffer;
210  long unsigned nbuf;
211  MediaSubsession& fSubsession;
212  char* fStreamId;
213  FrameFilter& framefilter;
216  int subsession_index;
217  bool& passthrough;
218 
219 public: // getters & setters
220  uint8_t* getReceiveBuffer() {return fReceiveBuffer;}
221 
222 public:
223  bool on;
224 };
225 
226 #endif
Custom payload Frame.
Definition: frame.h:166
The mother class of all frame filters! FrameFilters are used to create "filter chains".
Definition: framefilter.h:44
Live555 handling of media frames.
Definition: live.h:173
SetupFrame setupframe
This frame is used to send subsession information.
Definition: live.h:214
static FrameSink * createNew(UsageEnvironment &env, StreamClientState &scs, FrameFilter &framefilter, bool &passthrough, char const *streamId=NULL)
Default constructor.
Definition: live.cpp:516
static void afterGettingFrame(void *clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds)
Called after live555 event loop has composed a new frame.
Definition: live.cpp:603
void setReceiveBuffer(unsigned target_size)
Calculates receiving memory buffer size.
Definition: live.cpp:682
bool & passthrough
pass frame to framefilter or not
Definition: live.h:217
virtual Boolean continuePlaying()
Live555 redefined virtual function.
Definition: live.cpp:664
void sendParameterSets()
Extracts sps and pps info from the SDP string. Creates sps and pps frames and sends them to the filte...
Definition: live.cpp:698
unsigned checkBufferSize(unsigned target_size)
Calculates receiving memory buffer size.
Definition: live.cpp:673
long unsigned nbuf
Size of bytebuffer.
Definition: live.h:210
BasicFrame basicframe
Data is being copied into this frame.
Definition: live.h:215
virtual ~FrameSink()
Default virtual destructor.
Definition: live.cpp:596
Setup frame.
Definition: frame.h:277
Class to hold per-stream state that we maintain throughout each stream's lifetime.
Definition: live.h:78
MediaSession * session
Created by RTSPClient or SDPClient. Closed by StreamClientState::~StreamClientState.
Definition: live.h:86
virtual ~StreamClientState()
Default virtual destructor. Calls Medium::close on the MediaSession object.
Definition: live.cpp:486
void close()
Calls Medium::close on the MediaSubsession objects and their sinks.
Definition: live.cpp:473
MediaSubsession * subsession
Created by RTSPClient or SDPClient. Closed by StreamClientState::close.
Definition: live.h:87
int subsession_index
Managed by RTSPClient or SDPClient.
Definition: live.h:85
MediaSubsessionIterator * iter
Created by RTSPClient or SDPClient. Deleted by StreamClientState::~StreamClientState.
Definition: live.h:84
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
StreamClientState()
Default constructor.
Definition: live.cpp:469
Handles a live555 RTSP connection.
Definition: live.h:111
static void shutdownStream(RTSPClient *rtspClient, int exitCode=1)
Used to shut down and close a stream (including its "RTSPClient" object):
Definition: live.cpp:408
bool request_multicast
Request multicast during rtsp negotiation.
Definition: live.h:141
bool passthrough
control media sink passthrough to framefilter
Definition: live.h:132
FrameFilter & framefilter
Target frame filter where frames are being fed.
Definition: live.h:136
static void subsessionByeHandler(void *clientData)
Called when a RTCP "BYE" is received for a subsession.
Definition: live.cpp:387
static void continueAfterSETUP(RTSPClient *rtspClient, int resultCode, char *resultString)
Called after rtsp SETUP command gets a reply.
Definition: live.cpp:236
virtual ~ValkkaRTSPClient()
Default virtual destructor.
Definition: live.cpp:88
static void streamTimerHandler(void *clientData)
Called at the end of a stream's expected duration (if the stream has not already signaled its end usi...
Definition: live.cpp:398
static void subsessionAfterPlaying(void *clientData)
Called when a stream's subsession (e.g., audio or video substream) ends.
Definition: live.cpp:366
LiveStatus * livestatus
This points to a variable that is being used by LiveThread to inform about the stream state.
Definition: live.h:137
bool request_tcp
Request interleaved streaming over tcp.
Definition: live.h:142
static void continueAfterGET_PARAMETER(RTSPClient *rtspClient, int resultCode, char *resultString)
Used by pingGET_PARAMETER: a dummy callback to GET_PARAMETER.
Definition: live.cpp:139
static void setupNextSubsession(RTSPClient *rtspClient)
Used to iterate through each stream's 'subsessions', setting up each one.
Definition: live.cpp:154
static void continueAfterDESCRIBE(RTSPClient *rtspClient, int resultCode, char *resultString)
Called after rtsp DESCRIBE command gets a reply.
Definition: live.cpp:92
static void pingGetParameter(void *clientData)
Send a periodic GET_PARAMETER "ping" to the camera.
Definition: live.cpp:342
bool & termplease
Points to a variable that is being used by LiveThread to inform this client to exit asap if in LiveSt...
Definition: live.h:138
unsigned recv_buffer_size
Operating system ringbuffer size for incoming socket.
Definition: live.h:143
static ValkkaRTSPClient * createNew(UsageEnvironment &env, const std::string rtspURL, FrameFilter &framefilter, LiveStatus *livestatus, bool &termplease, int verbosityLevel=0, char const *applicationName=NULL, portNumBits tunnelOverHTTPPortNum=0)
Default constructor.
Definition: live.cpp:74
static void continueAfterPLAY(RTSPClient *rtspClient, int resultCode, char *resultString)
Called after rtsp PLAY command gets a reply.
Definition: live.cpp:293
unsigned reordering_time
Live555 packet reordering treshold time (microsecs)
Definition: live.h:144
Frame classes.
Thread safe system of fifo and a stack.
Definition of FrameFilter and derived classes for various purposes.
LiveStatus
Status for the ValkkaRTSPClient.
Definition: live.h:62
@ closed
Client has been closed and Medium::close has been called on the MediaSession, etc....
@ alive
Client has succesfully started playing.
@ pending
Client's been requested to send the describe command. This might hang for several reasons: camera off...
UsageEnvironment & operator<<(UsageEnvironment &env, const RTSPClient &rtspClient)
A function that outputs a string that identifies each stream (for debugging output).
Definition: live.cpp:47
List of common header files.
Logging utilities.
Logging facility.
Definition: logging.h:64
@ none
undefined (initial value)
Definition: usbthread.h:143