rtp_stream.h 2.05 KB
Newer Older
1
/**
2 3 4
 * @file rtp_stream.h
 * @brief Base class for RTP streams
 * @copyright Copyright (C) 2017 Elphel Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * @author AUTHOR <EMAIL>
 *
 * @par License:
 *  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 3 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, see <http://www.gnu.org/licenses/>.
*/

22 23 24 25
#ifndef __H_RTP_STREAM__
#define __H_RTP_STREAM__

#include <sys/time.h>
26
#include <cstring>
27 28 29 30
#include <pthread.h>
#include <semaphore.h>
#include <stdint.h>

31 32 33
#include "socket.h"
#include "parameters.h"

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
using namespace std;

extern int fd_stream;

class RTP_Stream {
public:
	RTP_Stream(void);
	virtual ~RTP_Stream();

	int ptype(void) { return _ptype; };
	virtual void Start(string ip, int port, int ttl = -1);
	virtual void Stop(void);
protected:
	void init_pthread(void *__this);
	pthread_t pth;
	int pth_id;
	static void *pthread_f(void *_this);
	void *thread(void);
	pthread_mutex_t pthm_flow;
	virtual long process(void) = 0;

	int _ptype;
	bool _play;
57
	sem_t sem_play;                                             //< semaphore to wait 'play' event
58 59 60
	Socket *rtp_socket;
	Socket *rtcp_socket;

61
	unsigned short packet_num;                                  //< sequence number in RTP packet header
62 63 64
	unsigned long SSRC;

	struct timeval f_tv;
65
	struct timeval rtcp_tv;                                     //< time of last SR
66 67 68 69 70 71 72 73 74 75 76
	long rtcp_delay;
	unsigned long timestamp;

	unsigned long rtp_packets;
	unsigned long rtp_octets;

	void rtcp(void);
	void rtcp_send_sr(void);
	void rtcp_send_sdes(void);

	string stream_name;
77 78
	Parameters *params;
	int sensor_port;
79 80 81
};

#endif //__H_RTP_STREAM__