Blame view

build/jrtplib/example2.cpp 2.42 KB
c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
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
  #include <stdio.h>
  #include <iostream>
  #include "rtpsessionparams.h"
  #include "rtpudpv4transmitter.h"
  #include "rtpsession.h"
  #include "rtppacket.h"
  
  #include <thread>
  #include <chrono>
  
  using namespace jrtplib;
  
  
  
  int main(void)
  {
      int localPort = 30026;
  
      // RTPSession rtpSession;
  	RTPSession* rtpSessionPtr = new RTPSession();
      RTPSessionParams           SessParams;
      RTPUDPv4TransmissionParams TransParams;
      SessParams.SetOwnTimestampUnit(1.0/8000.0);    // 时间戳:1秒钟8000个样本
      TransParams.SetPortbase(localPort);   // 设置本地接收的端口号
      int iErrNum = rtpSessionPtr->Create(SessParams, &TransParams);
      if (iErrNum < 0){
          printf( "Create RTP Session error! Reason: %d!\r\n",  iErrNum );
          exit(-1);
      }
      printf( "Create RTP Session OK! Reason: %d!\r\n", iErrNum);
  
  
  	bool m_bRtpExit = false;
  	while (!m_bRtpExit)
  	{
  
  		rtpSessionPtr->Poll();
  		rtpSessionPtr->BeginDataAccess();
  		
  		if (rtpSessionPtr->GotoFirstSourceWithData())
  		{
  			do
  			{
  				RTPPacket* packet;
  				while ((packet = rtpSessionPtr->GetNextPacket()) != NULL) 
  				{
  					printf("got data \n");
  
  					rtpSessionPtr->DeletePacket(packet);
  				}
  			} while (rtpSessionPtr->GotoNextSourceWithData());
  		}
  
  		rtpSessionPtr->EndDataAccess();
  
  		std::this_thread::sleep_for(std::chrono::milliseconds(10));
  	}
  
  
  
  
  
      // // 开始接收数据
      // rtpSessionPtr->BeginDataAccess();
      // if (rtpSessionPtr->GotoFirstSource())
      // {
      //     do
      //     {
      //         RTPPacket *packet;
      //         while ((packet = rtpSessionPtr->GetNextPacket()) != 0)
      //         {
  
      //             // 获取接收数据长度
      //             unsigned int recvSize = packet->GetPayloadLength();
      //             // 获取接收数据
      //             unsigned char * recvData = (unsigned char *)packet->GetPayloadData();
      //             std::cout << "Got packet with extended sequence number "
      //                       << packet->GetExtendedSequenceNumber()
      //                       << " from SSRC " << packet->GetSSRC()  << "; recvSize " << recvSize << "[" << recvData << "]"
      //                       << std::endl;
      //             // 删除数据包
      //             rtpSessionPtr->DeletePacket(packet);
      //         }
      //     } while (rtpSessionPtr->GotoNextSource());
      // }
      // rtpSessionPtr->EndDataAccess();
  
      // rtpSessionPtr->Destroy();
      // rtpSessionPtr->AbortWait();
  
      return 0;
  }