zhangzengfei
2022-07-20 c90c3e794bdd95127d0c34ff1d9e8759d18a0445
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
/******************************************************************************
* FILE:    RtpApp.h
* Description:
*    Interface class of jrtplib module.
*
* Modified Code History
* Mark  Date        By          Modification Reason
*******************************************************************************
* 01    2008-4-15   songxw Initial creation.
******************************************************************************/
 
#if !defined(__RTP_APP_H__)
#define __RTP_APP_H__
 
#include "TypeDef.h"
#include "rtpsession.h"
#include "rtpudpv4transmitter.h"
#include "rtpsessionparams.h"
#include "rtpipv4address.h"
#include "str.h"
 
using namespace std;
using namespace jrtplib;
 
#define RTP_PAYLOAD_MAX_LEN         1800               //µ¥¸öRTP¸ºÔØ×î´óÈÝÁ¿
#define ONE_FRAME_MAX_LEN           1024 * 1024 * 1    //ÿ֡×î´ó×Ö½ÚÊý
#define FILE_MAX_LEN                1024 * 1024 * 100  //Îļþ×î´ó³¤¶È(×Ö½Ú)
#define DELETE_OLDEST_HINT_MIN_SIZE 1024 * 20          //ɾ³ýÎļþµÄ×îС´ÅÅ̿ռä, KB
#define NOT_SAVING_MIN_SIZE         1024 * 5           //²»´æ´¢µÄ×îС´ÅÅ̿ռä, KB
#define GOOD_FILE_MIN_LEN           1024 * 20          //¼ÏñÎļþСÓÚºê(×Ö½Ú)£¬ÊÓΪ»µÎļþ
 
#define JRTP_BUFFER_SIZE_NORMAL     2*1024*1024
#define JRTP_BUFFER_SIZE_MAX        4*1024*1024
 
#define A_RTP_PACKET_DATA_LEN       1400   //1514-42-12
 
 
 
/* RTP info from a packet */
/*
typedef struct
{
    UINT8  DataType;                                   //¸ºÔØÖÖÀà
    UINT32 DataLen;                                    //¸ºÔس¤¶È
    bool   bIsFrame;                                   //Marker-M
    UINT16 sNum;                                       //˳ÐòºÅ
    UINT32 Timestamp;                                  //ʱ¼ä´Á
    UINT8  *pRawData;                                  //¸ºÔØ
}RTPInfo_T;
*/
 
/* Interface class of jrtplib module */
class CRtpApp : public RTPSession
{
public:
    CRtpApp();
    ~CRtpApp();
 
    int        CreateSession(UINT16 ListenPort, UINT32 nSsrc = 0, bool usethread = true);          //RTP´´½¨
    void    RtpDestroy();                              //RTPÏú»Ù
 
    void    SetTsunit(double ts) {tsunit = ts;}
    double    GetTsunit(void) {return tsunit;};
 
    //Set and send out nat mapping packet
    int NatMappingControl(char IpStr[], UINT16 port, int SSId);
 
      RTPUDPv4TransmissionParams TransParams;
      RTPSessionParams           SessParams;
 
    int GetTimeStamp(void);
    int GetAudioTimeStamp(void);
    void ResetTimeStamp(void) 
    {
        struct timezone tzone;
        gettimeofday(&RunTime, &tzone);
        gettimeofday(&RunTime2, &tzone);    
    }
 
protected:
    void OnPollThreadStep();
 
    //Send a packet to traverse NAT
    void SendNatMappingPacket(void);
    
    CRtpApp* GetThis(void) {return this;}
    
    //NAT packet time interval
    time_t SendTimeForNAT;
 
private:
    virtual void CBRtpRecv();                          //RTP½ÓÊÕ±¨ÎÄ
    
    double    tsunit;                                    //ʱ¼ä´Á
    
    //Running time
    struct timeval RunTime;
    struct timeval RunTime2;
    
    //Sequence number for a packet of traversing NAT
    UINT16 SeqNum;
    
    //Session ID for a call
    int    SessionID;
};
 
#endif    //#if !defined(__RTP_APP_H__)