RTPTcpReceiver.h 1.78 KB
#ifndef _RTP_TCP_RECEIVER_H_
#define _RTP_TCP_RECEIVER_H_


#include "demuxer.h"
#include "buffer.h"

#include "rtpsession.h"
#include "rtptcptransmitter.h"
#include "rtpipv4address.h"
#include "rtptcpaddress.h"
#include "rtpsessionparams.h"
#include "rtperrors.h"
#include "rtpsourcedata.h"
#include "rtpsocketutil.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>

#include <queue>
#include <atomic>
#include <thread>
#include <mutex>

#include "RTPReceiver.h"


#define OUTTIME_RTCP	30*1000
#define PAYLOAD			99
#define PAYLOAD_PS		96
#define PAYLOAD_H264	98
#define PAYLOAD_MP4		97

#define UDP_SIZE		1400
#define MIN_PORT		10000
#define MAX_PORT		60000
#define RTP_MAX_PACKET_LEN   1450

using namespace jrtplib;
using namespace std;



class TcpRTPSession;
class MyTCPTransmitter;

class RTPTcpReceiver:public RTPReceiver
{
public:
	RTPTcpReceiver();
	~RTPTcpReceiver();

	bool Open(uint16_t localPort);
	bool IsOpened();
	void Close();

public:
	int OnRtpRecv();
    bool ReConnect();
    int ListenFinish();
    bool RequestStream();
    bool isClosing();

private:
    int initSession(int localPort);
    void close_task();

private:
	
    std::atomic_bool    m_bRtpExit;					// 标识RTP收包线程闭

    std::atomic_bool    m_bOpened;
    std::atomic_bool    m_bAccepted;
    std::atomic_bool    m_bClosing;

	int64_t             m_idleCount;
	int64_t             m_noDataCount;//线程计数,用于打开流成功但是实际没流过来

    std::thread      	m_rtpThread; 					// RTP接收线程
    SocketType          m_nListener;

    RTPSession*	        m_rtpSessionPtr;					// RTP会话
    RTPSessionParams*   m_pSessparams;
    MyTCPTransmitter*   m_pTrans;

    std::thread      	m_listenFinishThread; 					// RTP接收线程
    
};

#endif  // _RTP_TCP_RECEIVER_H_