├── examples ├── .dummy ├── CMakeLists.txt ├── example2.cpp ├── example4.cpp └── example1.cpp ├── sphinxdoc ├── source │ ├── _static │ │ └── .dummy │ └── _templates │ │ └── .dummy └── README.md ├── tools ├── suffix.cpp ├── getloginrtest.cpp ├── polltest.cpp ├── wsapolltest.cpp ├── strncpystest.cpp ├── performancecounter.cpp ├── randstest.cpp ├── clockgettimetest.cpp ├── msgnosignaltest.cpp ├── winsocktest.cpp ├── arrayalloc.cpp ├── salentest.cpp ├── ipv6test.cpp ├── socklentest.cpp ├── ipv4mcasttest.cpp ├── ipv6mcasttest.cpp └── gettypes.cpp ├── src ├── rtptypes.h.in ├── errcodecommand ├── reformaterrors.py ├── rtplibraryversioninternal.h.in ├── rtptypes_win.h ├── rtpdebug.h ├── rtpipv4destination.cpp ├── rtpsocketutil.h ├── rtptimeutilities.cpp ├── rtplibraryversion.cpp ├── rtpinternalutils.h ├── rtprandomrands.h ├── rtprandomurandom.h ├── rtpipv6destination.cpp ├── rtcppacket.cpp ├── rtppollthread.h ├── rtprandomrand48.h ├── rtpmemoryobject.h ├── rtptcpaddress.cpp ├── rtplibraryversion.h ├── rtprandom.h ├── rtpsocketutilinternal.h ├── rtcpapppacket.cpp ├── rtcpunknownpacket.h ├── rtptcpaddress.h ├── rtpdefines.h ├── rtpipv4address.cpp ├── rtpconfig.h.in ├── rtpipv6destination.h ├── rtcppacket.h ├── rtprandomurandom.cpp ├── rtprandom.cpp ├── rtcpbyepacket.cpp ├── rtpstructs.h ├── rtpcollisionlist.h ├── rtpbyteaddress.cpp ├── rtcprrpacket.cpp ├── rtpsessionparams.cpp ├── rtpipv6address.cpp ├── rtprandomrand48.cpp ├── rtpaddress.h ├── rtpbyteaddress.h ├── rtcpsrpacket.cpp ├── rtpcollisionlist.cpp ├── rtpsessionsources.h ├── rtpipv4destination.h ├── rtpabortdescriptors.h ├── rtcpapppacket.h ├── CMakeLists.txt ├── rtcpcompoundpacket.h ├── rtcpbyepacket.h ├── rtpipv6address.h ├── rtppollthread.cpp └── rtprandomrands.cpp ├── cmake ├── JRTPLIBConfig.cmake.in ├── FindLIBSRTP.cmake ├── FindJThread.cmake └── Macros.cmake ├── pkgconfig └── jrtplib.pc.in ├── tests ├── timeinittest.cpp ├── CMakeLists.txt ├── timetest.cpp ├── testexttrans.cpp ├── testautoportbase.cpp ├── testmultiplex.cpp ├── abortdesctest.cpp └── testexistingsockets.cpp ├── TODO ├── LICENSE.MIT └── visual_studio_jthread_jrtplib_compilation.txt /examples/.dummy: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sphinxdoc/source/_static/.dummy: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sphinxdoc/source/_templates/.dummy: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/suffix.cpp: -------------------------------------------------------------------------------- 1 | int main(void) 2 | { 3 | return (int)10ui64; 4 | } 5 | -------------------------------------------------------------------------------- /src/rtptypes.h.in: -------------------------------------------------------------------------------- 1 | #include "rtpconfig.h" 2 | 3 | ${RTP_WINSOCK_HEADERS} 4 | ${RTP_INTTYPE_HEADERS} 5 | -------------------------------------------------------------------------------- /sphinxdoc/README.md: -------------------------------------------------------------------------------- 1 | Not really using Sphinx documentation, just a small script so that the docs 2 | are automatically generated on readthedocs. 3 | -------------------------------------------------------------------------------- /tools/getloginrtest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | char buf[256]; 6 | getlogin_r(buf,256); 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tools/polltest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | struct pollfd pfd = { 0, 0, 0}; 6 | int status = poll(&pfd, 1, 0); 7 | return status; 8 | } 9 | -------------------------------------------------------------------------------- /tools/wsapolltest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | WSAPOLLFD pfd = { INVALID_SOCKET, 0, 0 }; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tools/strncpystest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | char hostname[1024]; 6 | strncpy_s(hostname,1024,"localhost",_TRUNCATE); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /cmake/JRTPLIBConfig.cmake.in: -------------------------------------------------------------------------------- 1 | 2 | set(JRTPLIB_FOUND 1) 3 | 4 | set(JRTPLIB_INCLUDE_DIRS ${JRTPLIB_INCDIRS_CMAKECONFIG}) 5 | 6 | set(JRTPLIB_LIBRARIES ${JRTPLIB_LIBS_CMAKECONFIG}) 7 | 8 | -------------------------------------------------------------------------------- /tools/performancecounter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | LARGE_INTEGER performanceCount; 6 | QueryPerformanceCounter(&performanceCount); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /pkgconfig/jrtplib.pc.in: -------------------------------------------------------------------------------- 1 | Name: Jrtplib 2 | Description: A full featured RTP library 3 | Requires: 4 | Version: ${VERSION} 5 | Libs: ${JRTPLIB_LIBS_PKGCONFIG} 6 | Cflags: ${JRTPLIB_INCDIRS_PKGCONFIG} 7 | -------------------------------------------------------------------------------- /tools/randstest.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_RAND_S 2 | #include 3 | 4 | int main(void) 5 | { 6 | unsigned int number = 0; 7 | errno_t err = rand_s(&number); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tools/clockgettimetest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | struct timespec tp; 6 | 7 | clock_gettime(CLOCK_MONOTONIC, &tp); 8 | clock_gettime(CLOCK_REALTIME, &tp); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tools/msgnosignaltest.cpp: -------------------------------------------------------------------------------- 1 | #ifdef RTP_SOCKETTYPE_WINSOCK 2 | #include 3 | #else 4 | #include 5 | #include 6 | #endif // RTP_SOCKETTYPE_WINSOCK 7 | 8 | int main(void) 9 | { 10 | return MSG_NOSIGNAL; 11 | } 12 | -------------------------------------------------------------------------------- /tools/winsocktest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | WSADATA wsaData; 7 | WORD version = MAKEWORD(2, 2); 8 | //WSAStartup(version, &wsaData); // Would need to specify winsock lib for linking 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/timeinittest.cpp: -------------------------------------------------------------------------------- 1 | #include "rtptimeutilities.h" 2 | #include "rtpudpv4transmitter.h" 3 | #include 4 | 5 | int main(void) 6 | { 7 | jrtplib::RTPUDPv4Transmitter trans(0); 8 | jrtplib::RTPTime t(0); 9 | std::cout << t.GetDouble() << std::endl; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tools/arrayalloc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | inline void *operator new[](size_t numbytes, int memtype) 5 | { 6 | return operator new[](numbytes); 7 | } 8 | 9 | inline void operator delete[](void *buffer, int memtype) 10 | { 11 | operator delete[](buffer); 12 | } 13 | 14 | int main(void) 15 | { 16 | int j = 10; 17 | char *a = new(j) char[10]; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | apply_include_paths("${JRTPLIB_INTERNAL_INCLUDES}") 2 | apply_include_paths("${JRTPLIB_EXTERNAL_INCLUDES}") 3 | 4 | foreach(IDX 1 2 3 4 5 6 7 8) 5 | add_executable(example${IDX} example${IDX}.cpp) 6 | if (NOT MSVC OR JRTPLIB_COMPILE_STATIC) 7 | target_link_libraries(example${IDX} jrtplib-static) 8 | else () 9 | target_link_libraries(example${IDX} jrtplib-shared) 10 | endif () 11 | endforeach(IDX) 12 | 13 | -------------------------------------------------------------------------------- /tools/salentest.cpp: -------------------------------------------------------------------------------- 1 | #ifdef RTP_SOCKETTYPE_WINSOCK 2 | #include 3 | #include 4 | #ifndef _WIN32_WCE 5 | #include 6 | #endif // !_WIN32_WCE 7 | #else 8 | #include 9 | #include 10 | #include 11 | #endif // RTP_SOCKETTYPE_WINSOCK 12 | 13 | int main(void) 14 | { 15 | struct sockaddr sa; 16 | sa.sa_len = 0; 17 | 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | For v3: 3 | * Look into bug where lastmsgtime = srcdat->INF_GetLastMessageTime() was somehow 4 | negative 5 | * similar changes to udpv6 transmitter as to udpv4 transmitter 6 | 7 | For v4: 8 | * introduce a basic transmitter which does not have things like a destination list, 9 | ignore list, accept list 10 | * similarly: create a basic rtpsession class 11 | * don't order accepted rtp packets anymore, don't look for duplicates 12 | -------------------------------------------------------------------------------- /tools/ipv6test.cpp: -------------------------------------------------------------------------------- 1 | #ifdef RTP_SOCKETTYPE_WINSOCK 2 | #include 3 | #include 4 | #ifndef _WIN32_WCE 5 | #include 6 | #endif // !_WIN32_WCE 7 | #else 8 | #include 9 | #include 10 | #include 11 | #endif // RTP_SOCKETTYPE_WINSOCK 12 | 13 | int main(void) 14 | { 15 | struct sockaddr_in6 addr; 16 | 17 | addr.sin6_family = PF_INET6; 18 | 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tools/socklentest.cpp: -------------------------------------------------------------------------------- 1 | #ifdef RTP_SOCKETTYPE_WINSOCK 2 | #include 3 | #include 4 | #ifndef _WIN32_WCE 5 | #include 6 | #endif // !_WIN32_WCE 7 | #else 8 | #include 9 | #include 10 | #include 11 | #endif // RTP_SOCKETTYPE_WINSOCK 12 | 13 | int main(void) 14 | { 15 | int param; 16 | int sock = 0; 17 | struct sockaddr addr; 18 | 19 | getsockname(sock,&addr,¶m); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tools/ipv4mcasttest.cpp: -------------------------------------------------------------------------------- 1 | #ifdef RTP_SOCKETTYPE_WINSOCK 2 | #include 3 | #include 4 | #ifndef _WIN32_WCE 5 | #include 6 | #endif // !_WIN32_WCE 7 | #else 8 | #include 9 | #include 10 | #include 11 | #endif // RTP_SOCKETTYPE_WINSOCK 12 | 13 | int main(void) 14 | { 15 | int testval; 16 | struct ip_mreq mreq,mreq2; 17 | mreq = mreq2; // avoid 'unused variable' 18 | testval = IP_MULTICAST_TTL; 19 | testval = IP_ADD_MEMBERSHIP; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | apply_include_paths("${JRTPLIB_INTERNAL_INCLUDES}") 2 | apply_include_paths("${JRTPLIB_EXTERNAL_INCLUDES}") 3 | 4 | foreach(T testmultiplex testexistingsockets testautoportbase srtptest rtcpdump readlogfile 5 | timetest timeinittest abortdesctest abortdescipv6 tcptest sigintrtest 6 | testexttrans) 7 | add_executable(${T} ${T}.cpp) 8 | if (NOT MSVC OR JRTPLIB_COMPILE_STATIC) 9 | target_link_libraries(${T} jrtplib-static) 10 | else () 11 | target_link_libraries(${T} jrtplib-shared) 12 | endif () 13 | endforeach(T) 14 | 15 | -------------------------------------------------------------------------------- /src/errcodecommand: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in `cat rtperrors.h | cut -f 2 -d " " | cut -f 1 |grep -e "^ERR"`; do 3 | echo $i 4 | BLA=`grep $i rt*.cpp rt*.h extratransmitters/rt*.h extratransmitters/rt*.cpp |cut -f 1 -d ":"|sort|uniq` 5 | gotdesc=N 6 | if [ "BLA$BLA" != BLA ] ; then 7 | for j in $BLA ; do 8 | if [ $j != "rtperrors.h" ] ; then 9 | echo -e "\t$j" ; 10 | if [ $j = "rtperrors.cpp" ] ; then 11 | gotdesc=Y 12 | fi 13 | fi 14 | done 15 | fi 16 | if [ $gotdesc = "N" ] ; then 17 | echo -e "\tNEEDS DESCRIPTION" 18 | fi 19 | done 20 | -------------------------------------------------------------------------------- /tools/ipv6mcasttest.cpp: -------------------------------------------------------------------------------- 1 | #ifdef RTP_SOCKETTYPE_WINSOCK 2 | #include 3 | #include 4 | #ifndef _WIN32_WCE 5 | #include 6 | #endif // !_WIN32_WCE 7 | #else 8 | #include 9 | #include 10 | #include 11 | #endif // RTP_SOCKETTYPE_WINSOCK 12 | 13 | int main(void) 14 | { 15 | int testval; 16 | struct ipv6_mreq mreq,mreq2; 17 | mreq = mreq2; // avoid 'unused variable' 18 | testval = IPV6_MULTICAST_HOPS; 19 | testval = IPV6_JOIN_GROUP; 20 | testval = IPV6_LEAVE_GROUP; 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/reformaterrors.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from __future__ import print_function 4 | 5 | lines = [ l for l in open("rtperrors.h").readlines() if "ERR_RTP" in l ] 6 | tgtcode = 0 7 | 8 | defines = [ ] 9 | 10 | for l in lines: 11 | tgtcode -= 1 12 | l = l.strip() 13 | parts = l.split() 14 | n = parts[1] 15 | code = int(parts[2]) 16 | 17 | if not n.startswith("ERR_RTP"): 18 | raise Exception("Unexpected line: " + l) 19 | if tgtcode != code: 20 | print("WARNING: mismatch in error code for line (expected {}): {}".format(tgtcode, l)) 21 | 22 | defines.append([ n, tgtcode]) 23 | 24 | maxlen = 0 25 | for n,c in defines: 26 | maxlen = max(maxlen,len(n + " ")) 27 | 28 | boundary = 8 29 | if maxlen%boundary != 0: 30 | maxlen = ((maxlen//boundary)+1)*boundary 31 | 32 | for n,c in defines: 33 | print("#define {} {} {}".format(n, " "*(maxlen-len(n)), c)) 34 | -------------------------------------------------------------------------------- /cmake/FindLIBSRTP.cmake: -------------------------------------------------------------------------------- 1 | INCLUDE(FindPkgConfig OPTIONAL) 2 | 3 | IF(PKG_CONFIG_FOUND) 4 | INCLUDE(FindPkgConfig) 5 | PKG_CHECK_MODULES(LIBSRTP srtp) 6 | ENDIF(PKG_CONFIG_FOUND) 7 | 8 | IF(NOT LIBSRTP_FOUND) 9 | FIND_PATH(LIBSRTP_INCLUDE_DIR srtp/srtp.h 10 | /usr/local/include 11 | /usr/include 12 | ) 13 | 14 | FIND_LIBRARY(LIBSRTP_LIBRARY_DIR 15 | NAMES srtp 16 | PATH 17 | /usr/local/lib 18 | /usr/local/lib64 19 | /usr/lib 20 | /usr/lib64 21 | ) 22 | MESSAGE(STATUS "Found LIBSRTP: ${LIBSRTP_LIBRARY_DIR} ${LIBSRTP_INCLUDE_DIR}") 23 | ENDIF(NOT LIBSRTP_FOUND) 24 | 25 | IF(LIBSRTP_LIBRARY_DIR AND LIBSRTP_INCLUDE_DIR) 26 | SET(LIBSRTP_FOUND TRUE) 27 | ENDIF(LIBSRTP_LIBRARY_DIR AND LIBSRTP_INCLUDE_DIR) 28 | 29 | IF(NOT LIBSRTP_FOUND) 30 | IF(LIBSRTP_FIND_REQUIRED) 31 | MESSAGE(FATAL_ERROR "Could not find LIBSRTP") 32 | ENDIF(LIBSRTP_FIND_REQUIRED) 33 | ENDIF(NOT LIBSRTP_FOUND) 34 | -------------------------------------------------------------------------------- /LICENSE.MIT: -------------------------------------------------------------------------------- 1 | 2 | Permission is hereby granted, free of charge, to any person obtaining a 3 | copy of this software and associated documentation files (the "Software"), 4 | to deal in the Software without restriction, including without limitation 5 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 6 | and/or sell copies of the Software, and to permit persons to whom the 7 | Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included 10 | in all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 18 | IN THE SOFTWARE. 19 | 20 | -------------------------------------------------------------------------------- /tools/gettypes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | printf("#ifndef RTPTYPES_H\n\n"); 6 | printf("#define RTPTYPES_H\n\n"); 7 | printf("#include \n\n"); 8 | 9 | if (sizeof(char) == 1) 10 | { 11 | printf("typedef char int8_t;\n"); 12 | printf("typedef unsigned char uint8_t;\n\n"); 13 | } 14 | else 15 | return -1; 16 | 17 | if (sizeof(short) == 2) 18 | { 19 | printf("typedef short int16_t;\n"); 20 | printf("typedef unsigned short uint16_t;\n\n"); 21 | } 22 | else 23 | return -1; 24 | 25 | if (sizeof(int) == 4) 26 | { 27 | printf("typedef int int32_t;\n"); 28 | printf("typedef unsigned int uint32_t;\n\n"); 29 | } 30 | else if (sizeof(long) == 4) 31 | { 32 | printf("typedef long int32_t;\n"); 33 | printf("typedef unsigned long uint32_t;\n\n"); 34 | } 35 | else 36 | return -1; 37 | 38 | if (sizeof(long long) == 8) 39 | { 40 | printf("typedef long long int64_t;\n"); 41 | printf("typedef unsigned long long uint64_t;\n\n"); 42 | } 43 | else 44 | return -1; 45 | 46 | printf("#endif // RTPTYPES_H\n"); 47 | 48 | return 0; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /cmake/FindJThread.cmake: -------------------------------------------------------------------------------- 1 | 2 | find_package(JThread QUIET NO_MODULE) 3 | 4 | if (NOT JTHREAD_FOUND) # Config file could not be found 5 | find_path(JTHREAD_INCLUDE_DIR jthread/jthread.h) 6 | 7 | set(JTHREAD_INCLUDE_DIRS ${JTHREAD_INCLUDE_DIR}) 8 | 9 | if (UNIX) 10 | find_library(JTHREAD_LIBRARY jthread) 11 | if (JTHREAD_LIBRARY) 12 | set(JTHREAD_LIBRARIES ${JTHREAD_LIBRARY}) 13 | find_library(JTHREAD_PTHREAD_LIB pthread) 14 | if (JTHREAD_PTHREAD_LIB) 15 | set(JTHREAD_LIBRARIES ${JTHREAD_LIBRARY} ${JTHREAD_PTHREAD_LIB}) 16 | endif(JTHREAD_PTHREAD_LIB) 17 | endif (JTHREAD_LIBRARY) 18 | else (UNIX) 19 | find_library(JTHREAD_LIB_RELEASE jthread) 20 | find_library(JTHREAD_LIB_DEBUG jthread_d) 21 | 22 | if (JTHREAD_LIB_RELEASE OR JTHREAD_LIB_DEBUG) 23 | set(JTHREAD_LIBRARIES "") 24 | if (JTHREAD_LIB_RELEASE) 25 | set(JTHREAD_LIBRARIES ${JTHREAD_LIBRARIES} optimized ${JTHREAD_LIB_RELEASE}) 26 | endif (JTHREAD_LIB_RELEASE) 27 | if (JTHREAD_LIB_DEBUG) 28 | set(JTHREAD_LIBRARIES ${JTHREAD_LIBRARIES} debug ${JTHREAD_LIB_DEBUG}) 29 | endif (JTHREAD_LIB_DEBUG) 30 | endif (JTHREAD_LIB_RELEASE OR JTHREAD_LIB_DEBUG) 31 | endif(UNIX) 32 | endif (NOT JTHREAD_FOUND) 33 | 34 | include(FindPackageHandleStandardArgs) 35 | 36 | find_package_handle_standard_args(JThread DEFAULT_MSG JTHREAD_INCLUDE_DIRS JTHREAD_LIBRARIES) 37 | 38 | -------------------------------------------------------------------------------- /tests/timetest.cpp: -------------------------------------------------------------------------------- 1 | #include "rtptimeutilities.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | using namespace jrtplib; 7 | 8 | int main(void) 9 | { 10 | double times[] = { 1.2, -2.3, 0, 3.999999 }; 11 | 12 | for (int i = 0 ; i < sizeof(times)/sizeof(double) ; i++) 13 | { 14 | RTPTime t(times[i]); 15 | 16 | cout << "Double: " << times[i] << endl; 17 | cout << "Seconds: " << t.GetSeconds() << endl; 18 | cout << "Microseconds: " << t.GetMicroSeconds() << endl; 19 | cout << endl; 20 | } 21 | 22 | int32_t secsAndMuSecs[][2] = { { 1, 3000}, {-2, 200}, {0, 0}, {-2, 999999} }; 23 | for (int i = 0 ; i < sizeof(secsAndMuSecs)/(2*sizeof(int32_t)) ; i++) 24 | { 25 | RTPTime t(secsAndMuSecs[i][0], secsAndMuSecs[i][1]); 26 | 27 | cout << "Input Seconds: " << secsAndMuSecs[i][0] << endl; 28 | cout << "Input Microseconds: " << secsAndMuSecs[i][1] << endl; 29 | cout << "Output Seconds: " << t.GetSeconds() << endl; 30 | cout << "Output Microseconds: " << t.GetMicroSeconds() << endl; 31 | cout << "Output Double: " << t.GetDouble() << endl; 32 | cout << endl; 33 | } 34 | 35 | for (int i = 0 ; i < 10 ; i++) 36 | { 37 | RTPTime now = RTPTime::CurrentTime(); 38 | fprintf(stderr, "%10u.%06d\n", (uint32_t)now.GetSeconds(), now.GetMicroSeconds()); 39 | RTPTime::Wait(RTPTime(1)); 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /tests/testexttrans.cpp: -------------------------------------------------------------------------------- 1 | #include "rtpsession.h" 2 | #include "rtpsessionparams.h" 3 | #include "rtpexternaltransmitter.h" 4 | #include "rtperrors.h" 5 | #include "rtpsourcedata.h" 6 | #include "rtpipv4address.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace jrtplib; 13 | using namespace std; 14 | 15 | void checkerror(int rtperr) 16 | { 17 | if (rtperr < 0) 18 | { 19 | cout << "ERROR: " << RTPGetErrorString(rtperr) << endl; 20 | exit(-1); 21 | } 22 | } 23 | 24 | class ExtSender : public RTPExternalSender 25 | { 26 | public: 27 | ExtSender() { } 28 | ~ExtSender() { } 29 | private: 30 | bool SendRTP(const void *pData, size_t len) 31 | { 32 | return true; 33 | } 34 | 35 | bool SendRTCP(const void *pData, size_t len) 36 | { 37 | return true; 38 | } 39 | 40 | bool ComesFromThisSender(const RTPAddress *pAddr) 41 | { 42 | return false; 43 | } 44 | }; 45 | 46 | int main(void) 47 | { 48 | ExtSender sender; 49 | RTPSessionParams sessParams; 50 | RTPExternalTransmissionParams transParams(&sender, 0); 51 | RTPSession session; 52 | 53 | sessParams.SetOwnTimestampUnit(1.0/48000.0); // Just set something, not relevant for this test 54 | int status = session.Create(sessParams, &transParams, RTPTransmitter::ExternalProto); 55 | checkerror(status); 56 | 57 | RTPExternalTransmissionInfo *pTransInf = static_cast(session.GetTransmissionInfo()); 58 | RTPExternalPacketInjecter *pPacketInjector = pTransInf->GetPacketInjector(); 59 | session.DeleteTransmissionInfo(pTransInf); 60 | 61 | for (int i = 0 ; i < 1024*1024 ; i++) 62 | { 63 | if (i%1000 == 0) 64 | cout << "Writing packet " << i << endl; 65 | RTPIPv4Address addr(0x7f000001, 1234); 66 | pPacketInjector->InjectRTP("12345", 5, addr); 67 | } 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /src/rtplibraryversioninternal.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtplibraryversioninternal.h 35 | */ 36 | 37 | #ifndef RTPLIBRARYVERSIONINTERNAL_H 38 | 39 | #define RTPLIBRARYVERSIONINTERNAL_H 40 | 41 | #define JRTPLIB_VERSION_MAJOR ${VERSION_MAJOR} 42 | #define JRTPLIB_VERSION_MINOR ${VERSION_MINOR} 43 | #define JRTPLIB_VERSION_DEBUG ${VERSION_DEBUG} 44 | 45 | #endif // RTPLIBRARYVERSIONINTERNAL_H 46 | 47 | -------------------------------------------------------------------------------- /src/rtptypes_win.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #ifndef RTPTYPES_WIN_H 34 | 35 | #define RTPTYPES_WIN_H 36 | 37 | #ifndef INTTYPES_DEFINED 38 | 39 | #define INTTYPES_DEFINED 40 | 41 | typedef char int8_t; 42 | typedef unsigned char uint8_t; 43 | typedef short int16_t; 44 | typedef unsigned short uint16_t; 45 | typedef int int32_t; 46 | typedef unsigned int uint32_t; 47 | typedef __int64 int64_t; 48 | typedef unsigned __int64 uint64_t; 49 | 50 | #endif // INTTYPES_DEFINED 51 | 52 | #endif // RTPTYPES_WIN_H 53 | 54 | -------------------------------------------------------------------------------- /src/rtpdebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #ifndef RTPDEBUG_H 34 | 35 | #define RTPDEBUG_H 36 | 37 | #include "rtpconfig.h" 38 | 39 | #ifdef RTPDEBUG 40 | #include "rtptypes.h" 41 | 42 | void *operator new(size_t s,char filename[],int line); 43 | #ifdef RTP_HAVE_ARRAYALLOC 44 | void *operator new[](size_t s,char filename[],int line); 45 | #define new new ((char*)__FILE__,__LINE__) 46 | #else 47 | #define new new ((char*)__FILE__,__LINE__) 48 | #endif // RTP_HAVE_ARRAYALLOC 49 | #endif // RTPDEBUG 50 | 51 | #endif // RTPDEBUG_H 52 | 53 | -------------------------------------------------------------------------------- /src/rtpipv4destination.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2011 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtpipv4destination.h" 34 | #include "rtpinternalutils.h" 35 | 36 | namespace jrtplib 37 | { 38 | 39 | std::string RTPIPv4Destination::GetDestinationString() const 40 | { 41 | char str[24]; 42 | uint32_t ip = GetIP(); 43 | uint16_t portbase = ntohs(GetRTPPort_NBO()); 44 | 45 | RTP_SNPRINTF(str,24,"%d.%d.%d.%d:%d",(int)((ip>>24)&0xFF),(int)((ip>>16)&0xFF),(int)((ip>>8)&0xFF),(int)(ip&0xFF),(int)(portbase)); 46 | return std::string(str); 47 | } 48 | 49 | } // end namespace 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/rtpsocketutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpsocketutil.h 35 | */ 36 | 37 | #ifndef RTPSOCKETUTIL_H 38 | 39 | #define RTPSOCKETUTIL_H 40 | 41 | #include "rtpconfig.h" 42 | #ifdef RTP_SOCKETTYPE_WINSOCK 43 | #include "rtptypes.h" 44 | #endif // RTP_SOCKETTYPE_WINSOCK 45 | 46 | namespace jrtplib 47 | { 48 | 49 | #ifndef RTP_SOCKETTYPE_WINSOCK 50 | 51 | typedef int SocketType; 52 | 53 | #else 54 | 55 | typedef SOCKET SocketType; 56 | 57 | #endif // RTP_SOCKETTYPE_WINSOCK 58 | 59 | } // end namespace 60 | 61 | #endif // RTPSOCKETUTIL_H 62 | -------------------------------------------------------------------------------- /src/rtptimeutilities.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtpconfig.h" 34 | #include "rtptimeutilities.h" 35 | #ifdef RTPDEBUG 36 | #include 37 | #endif // RTPDEBUG 38 | 39 | namespace jrtplib 40 | { 41 | 42 | RTPTimeInitializerObject::RTPTimeInitializerObject() 43 | { 44 | #ifdef RTPDEBUG 45 | std::cout << "RTPTimeInitializer: Initializing RTPTime::CurrentTime()" << std::endl; 46 | #endif // RTPDEBUG 47 | RTPTime curtime = RTPTime::CurrentTime(); 48 | JRTPLIB_UNUSED(curtime); 49 | dummy = -1; 50 | } 51 | 52 | RTPTimeInitializerObject timeinit; 53 | 54 | } // end namespace 55 | 56 | -------------------------------------------------------------------------------- /src/rtplibraryversion.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtplibraryversion.h" 34 | #include "rtpdefines.h" 35 | #include "rtplibraryversioninternal.h" 36 | #include "rtpinternalutils.h" 37 | #include 38 | 39 | namespace jrtplib 40 | { 41 | 42 | RTPLibraryVersion RTPLibraryVersion::GetVersion() 43 | { 44 | return RTPLibraryVersion(JRTPLIB_VERSION_MAJOR, JRTPLIB_VERSION_MINOR, JRTPLIB_VERSION_DEBUG); 45 | } 46 | 47 | std::string RTPLibraryVersion::GetVersionString() const 48 | { 49 | char str[16]; 50 | 51 | RTP_SNPRINTF(str,16,"%d.%d.%d",majornr,minornr,debugnr); 52 | 53 | return std::string(str); 54 | } 55 | 56 | } // end namespace 57 | 58 | -------------------------------------------------------------------------------- /src/rtpinternalutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2011 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #ifndef RTPINTERNALUTILS_H 34 | 35 | #define RTPINTERNALUTILS_H 36 | 37 | #include "rtpconfig.h" 38 | 39 | #if defined(RTP_HAVE_SNPRINTF_S) 40 | #include 41 | #include 42 | #define RTP_SNPRINTF _snprintf_s 43 | #elif defined(RTP_HAVE_SNPRINTF) 44 | #include 45 | #include 46 | #define RTP_SNPRINTF _snprintf 47 | #else 48 | #include 49 | #define RTP_SNPRINTF snprintf 50 | #endif 51 | 52 | #ifdef RTP_HAVE_STRNCPY_S 53 | #define RTP_STRNCPY(dest, src, len) strncpy_s((dest), (len), (src), _TRUNCATE) 54 | #else 55 | #define RTP_STRNCPY(dest, src, len) strncpy((dest), (src), (len)) 56 | #endif // RTP_HAVE_STRNCPY_S 57 | 58 | #endif // RTPINTERNALUTILS_H 59 | 60 | -------------------------------------------------------------------------------- /src/rtprandomrands.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtprandomrands.h 35 | */ 36 | 37 | #ifndef RTPRANDOMRANDS_H 38 | 39 | #define RTPRANDOMRANDS_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtprandom.h" 43 | 44 | namespace jrtplib 45 | { 46 | 47 | /** A random number generator which tries to use the \c rand_s function on the 48 | * Win32 platform. 49 | */ 50 | class JRTPLIB_IMPORTEXPORT RTPRandomRandS : public RTPRandom 51 | { 52 | public: 53 | RTPRandomRandS(); 54 | ~RTPRandomRandS(); 55 | 56 | /** Initialize the random number generator. */ 57 | int Init(); 58 | 59 | uint8_t GetRandom8(); 60 | uint16_t GetRandom16(); 61 | uint32_t GetRandom32(); 62 | double GetRandomDouble(); 63 | private: 64 | bool initialized; 65 | }; 66 | 67 | } // end namespace 68 | 69 | #endif // RTPRANDOMRANDS_H 70 | 71 | -------------------------------------------------------------------------------- /src/rtprandomurandom.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtprandomurandom.h 35 | */ 36 | 37 | #ifndef RTPRANDOMURANDOM_H 38 | 39 | #define RTPRANDOMURANDOM_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtprandom.h" 43 | #include 44 | 45 | namespace jrtplib 46 | { 47 | 48 | /** A random number generator which uses bytes delivered by the /dev/urandom device. */ 49 | class JRTPLIB_IMPORTEXPORT RTPRandomURandom : public RTPRandom 50 | { 51 | public: 52 | RTPRandomURandom(); 53 | ~RTPRandomURandom(); 54 | 55 | /** Initialize the random number generator. */ 56 | int Init(); 57 | 58 | uint8_t GetRandom8(); 59 | uint16_t GetRandom16(); 60 | uint32_t GetRandom32(); 61 | double GetRandomDouble(); 62 | private: 63 | FILE *device; 64 | }; 65 | 66 | } // end namespace 67 | 68 | #endif // RTPRANDOMURANDOM_H 69 | -------------------------------------------------------------------------------- /src/rtpipv6destination.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2011 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtpipv6destination.h" 34 | 35 | #ifdef RTP_SUPPORT_IPV6 36 | 37 | #include "rtpinternalutils.h" 38 | 39 | namespace jrtplib 40 | { 41 | 42 | std::string RTPIPv6Destination::GetDestinationString() const 43 | { 44 | uint16_t ip16[8]; 45 | char str[48]; 46 | uint16_t portbase = ntohs(rtpaddr.sin6_port); 47 | int i,j; 48 | for (i = 0,j = 0 ; j < 8 ; j++,i += 2) 49 | { 50 | ip16[j] = (((uint16_t)rtpaddr.sin6_addr.s6_addr[i])<<8); 51 | ip16[j] |= ((uint16_t)rtpaddr.sin6_addr.s6_addr[i+1]); 52 | } 53 | RTP_SNPRINTF(str,48,"%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X/%d",(int)ip16[0],(int)ip16[1],(int)ip16[2],(int)ip16[3],(int)ip16[4],(int)ip16[5],(int)ip16[6],(int)ip16[7],(int)portbase); 54 | return std::string(str); 55 | } 56 | 57 | } // end namespace 58 | 59 | #endif // RTP_SUPPORT_IPV6 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/rtcppacket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtcppacket.h" 34 | #ifdef RTPDEBUG 35 | #include 36 | #endif // RTPDEBUG 37 | 38 | #include "rtpdebug.h" 39 | 40 | #ifdef RTPDEBUG 41 | 42 | namespace jrtplib 43 | { 44 | 45 | void RTCPPacket::Dump() 46 | { 47 | switch(packettype) 48 | { 49 | case SR: 50 | std::cout << "RTCP Sender Report "; 51 | break; 52 | case RR: 53 | std::cout << "RTCP Receiver Report "; 54 | break; 55 | case SDES: 56 | std::cout << "RTCP Source Description "; 57 | break; 58 | case APP: 59 | std::cout << "RTCP APP Packet "; 60 | break; 61 | case BYE: 62 | std::cout << "RTCP Bye Packet "; 63 | break; 64 | case Unknown: 65 | std::cout << "Unknown RTCP Packet "; 66 | break; 67 | default: 68 | std::cout << "ERROR: Invalid packet type!" << std::endl; 69 | } 70 | std::cout << "Length: " << datalen; 71 | std::cout << std::endl; 72 | } 73 | 74 | } // end namespace 75 | 76 | #endif // RTPDEBUG 77 | -------------------------------------------------------------------------------- /src/rtppollthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtppollthread.h 35 | */ 36 | 37 | #ifndef RTPPOLLTHREAD_H 38 | 39 | #define RTPPOLLTHREAD_H 40 | 41 | #include "rtpconfig.h" 42 | 43 | #ifdef RTP_SUPPORT_THREAD 44 | 45 | #include "rtptransmitter.h" 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | namespace jrtplib 52 | { 53 | 54 | class RTPSession; 55 | class RTCPScheduler; 56 | 57 | class JRTPLIB_IMPORTEXPORT RTPPollThread : private jthread::JThread 58 | { 59 | public: 60 | RTPPollThread(RTPSession &session,RTCPScheduler &rtcpsched); 61 | ~RTPPollThread(); 62 | int Start(RTPTransmitter *trans); 63 | void Stop(); 64 | private: 65 | void *Thread(); 66 | 67 | bool stop; 68 | jthread::JMutex stopmutex; 69 | RTPTransmitter *transmitter; 70 | 71 | RTPSession &rtpsession; 72 | RTCPScheduler &rtcpsched; 73 | }; 74 | 75 | } // end namespace 76 | 77 | #endif // RTP_SUPPORT_THREAD 78 | 79 | #endif // RTPPOLLTHREAD_H 80 | -------------------------------------------------------------------------------- /src/rtprandomrand48.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtprandomrand48.h 35 | */ 36 | 37 | #ifndef RTPRANDOMRAND48_H 38 | 39 | #define RTPRANDOMRAND48_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtprandom.h" 43 | #ifdef RTP_SUPPORT_THREAD 44 | #include 45 | #endif // RTP_SUPPORT_THREAD 46 | #include 47 | 48 | namespace jrtplib 49 | { 50 | 51 | /** A random number generator using the algorithm of the rand48 set of functions. */ 52 | class JRTPLIB_IMPORTEXPORT RTPRandomRand48 : public RTPRandom 53 | { 54 | public: 55 | RTPRandomRand48(); 56 | RTPRandomRand48(uint32_t seed); 57 | ~RTPRandomRand48(); 58 | 59 | uint8_t GetRandom8(); 60 | uint16_t GetRandom16(); 61 | uint32_t GetRandom32(); 62 | double GetRandomDouble(); 63 | private: 64 | void SetSeed(uint32_t seed); 65 | 66 | #ifdef RTP_SUPPORT_THREAD 67 | jthread::JMutex mutex; 68 | #endif // RTP_SUPPORT_THREAD 69 | uint64_t state; 70 | }; 71 | 72 | } // end namespace 73 | 74 | #endif // RTPRANDOMRAND48_H 75 | 76 | -------------------------------------------------------------------------------- /examples/example2.cpp: -------------------------------------------------------------------------------- 1 | #include "rtpsession.h" 2 | #include "rtpsessionparams.h" 3 | #include "rtpudpv4transmitter.h" 4 | #include "rtpipv4address.h" 5 | #include "rtptimeutilities.h" 6 | #include "rtppacket.h" 7 | #include 8 | #include 9 | 10 | using namespace jrtplib; 11 | 12 | int main(void) 13 | { 14 | #ifdef RTP_SOCKETTYPE_WINSOCK 15 | WSADATA dat; 16 | WSAStartup(MAKEWORD(2,2),&dat); 17 | #endif // RTP_SOCKETTYPE_WINSOCK 18 | 19 | RTPSession session; 20 | 21 | RTPSessionParams sessionparams; 22 | sessionparams.SetOwnTimestampUnit(1.0/8000.0); 23 | 24 | RTPUDPv4TransmissionParams transparams; 25 | transparams.SetPortbase(8000); 26 | 27 | int status = session.Create(sessionparams,&transparams); 28 | if (status < 0) 29 | { 30 | std::cerr << RTPGetErrorString(status) << std::endl; 31 | exit(-1); 32 | } 33 | 34 | uint8_t localip[]={127,0,0,1}; 35 | RTPIPv4Address addr(localip,9000); 36 | 37 | status = session.AddDestination(addr); 38 | if (status < 0) 39 | { 40 | std::cerr << RTPGetErrorString(status) << std::endl; 41 | exit(-1); 42 | } 43 | 44 | session.SetDefaultPayloadType(96); 45 | session.SetDefaultMark(false); 46 | session.SetDefaultTimestampIncrement(160); 47 | 48 | uint8_t silencebuffer[160]; 49 | for (int i = 0 ; i < 160 ; i++) 50 | silencebuffer[i] = 128; 51 | 52 | RTPTime delay(0.020); 53 | RTPTime starttime = RTPTime::CurrentTime(); 54 | 55 | bool done = false; 56 | while (!done) 57 | { 58 | status = session.SendPacket(silencebuffer,160); 59 | if (status < 0) 60 | { 61 | std::cerr << RTPGetErrorString(status) << std::endl; 62 | exit(-1); 63 | } 64 | 65 | session.BeginDataAccess(); 66 | if (session.GotoFirstSource()) 67 | { 68 | do 69 | { 70 | RTPPacket *packet; 71 | 72 | while ((packet = session.GetNextPacket()) != 0) 73 | { 74 | std::cout << "Got packet with " 75 | << "extended sequence number " 76 | << packet->GetExtendedSequenceNumber() 77 | << " from SSRC " << packet->GetSSRC() 78 | << std::endl; 79 | session.DeletePacket(packet); 80 | } 81 | } while (session.GotoNextSource()); 82 | } 83 | session.EndDataAccess(); 84 | 85 | RTPTime::Wait(delay); 86 | 87 | RTPTime t = RTPTime::CurrentTime(); 88 | t -= starttime; 89 | if (t > RTPTime(60.0)) 90 | done = true; 91 | } 92 | 93 | delay = RTPTime(10.0); 94 | session.BYEDestroy(delay,"Time's up",9); 95 | 96 | #ifdef RTP_SOCKETTYPE_WINSOCK 97 | WSACleanup(); 98 | #endif // RTP_SOCKETTYPE_WINSOCK 99 | return 0; 100 | } 101 | 102 | -------------------------------------------------------------------------------- /src/rtpmemoryobject.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpmemoryobject.h 35 | */ 36 | 37 | #ifndef RTPMEMORYOBJECT_H 38 | 39 | #define RTPMEMORYOBJECT_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtpmemorymanager.h" 43 | 44 | namespace jrtplib 45 | { 46 | 47 | class JRTPLIB_IMPORTEXPORT RTPMemoryObject 48 | { 49 | protected: 50 | #ifdef RTP_SUPPORT_MEMORYMANAGEMENT 51 | RTPMemoryObject(RTPMemoryManager *memmgr) : mgr(memmgr) { } 52 | #else 53 | RTPMemoryObject(RTPMemoryManager *memmgr) { JRTPLIB_UNUSED(memmgr); } 54 | #endif // RTP_SUPPORT_MEMORYMANAGEMENT 55 | virtual ~RTPMemoryObject() { } 56 | 57 | #ifdef RTP_SUPPORT_MEMORYMANAGEMENT 58 | RTPMemoryManager *GetMemoryManager() const { return mgr; } 59 | void SetMemoryManager(RTPMemoryManager *m) { mgr = m; } 60 | #else 61 | RTPMemoryManager *GetMemoryManager() const { return 0; } 62 | void SetMemoryManager(RTPMemoryManager *m) { JRTPLIB_UNUSED(m); } 63 | #endif // RTP_SUPPORT_MEMORYMANAGEMENT 64 | 65 | #ifdef RTP_SUPPORT_MEMORYMANAGEMENT 66 | private: 67 | RTPMemoryManager *mgr; 68 | #endif // RTP_SUPPORT_MEMORYMANAGEMENT 69 | }; 70 | 71 | } // end namespace 72 | 73 | #endif // RTPMEMORYOBJECT_H 74 | 75 | -------------------------------------------------------------------------------- /src/rtptcpaddress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtptcpaddress.h" 34 | #include "rtpmemorymanager.h" 35 | #ifdef RTPDEBUG 36 | #include "rtpinternalutils.h" 37 | #include 38 | #endif // RTPDEBUG 39 | 40 | #include "rtpdebug.h" 41 | 42 | namespace jrtplib 43 | { 44 | 45 | bool RTPTCPAddress::IsSameAddress(const RTPAddress *addr) const 46 | { 47 | if (addr == 0) 48 | return false; 49 | if (addr->GetAddressType() != TCPAddress) 50 | return false; 51 | 52 | const RTPTCPAddress *a = static_cast(addr); 53 | 54 | // We're using a socket to identify connections 55 | if (a->m_socket == m_socket) 56 | return true; 57 | 58 | return false; 59 | } 60 | 61 | bool RTPTCPAddress::IsFromSameHost(const RTPAddress *addr) const 62 | { 63 | return IsSameAddress(addr); 64 | } 65 | 66 | RTPAddress *RTPTCPAddress::CreateCopy(RTPMemoryManager *mgr) const 67 | { 68 | JRTPLIB_UNUSED(mgr); // possibly unused 69 | RTPTCPAddress *a = RTPNew(mgr,RTPMEM_TYPE_CLASS_RTPADDRESS) RTPTCPAddress(m_socket); 70 | return a; 71 | } 72 | 73 | #ifdef RTPDEBUG 74 | std::string RTPTCPAddress::GetAddressString() const 75 | { 76 | // TODO 77 | return "RTPTCPAddress::GetAddressString: TODO"; 78 | } 79 | #endif // RTPDEBUG 80 | 81 | } // end namespace 82 | 83 | -------------------------------------------------------------------------------- /src/rtplibraryversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtplibraryversion.h 35 | */ 36 | 37 | #ifndef RTPLIBRARYVERSION_H 38 | 39 | #define RTPLIBRARYVERSION_H 40 | 41 | #include "rtpconfig.h" 42 | #include 43 | #include 44 | 45 | namespace jrtplib 46 | { 47 | 48 | /** 49 | * Used to provide information about the version of the library. 50 | */ 51 | class JRTPLIB_IMPORTEXPORT RTPLibraryVersion 52 | { 53 | public: 54 | /** Returns an instance of RTPLibraryVersion describing the version of the library. */ 55 | static RTPLibraryVersion GetVersion(); 56 | private: 57 | RTPLibraryVersion(int major,int minor,int debug) { majornr = major; minornr = minor; debugnr = debug; } 58 | public: 59 | /** Returns the major version number. */ 60 | int GetMajorNumber() const { return majornr; } 61 | 62 | /** Returns the minor version number. */ 63 | int GetMinorNumber() const { return minornr; } 64 | 65 | /** Returns the debug version number. */ 66 | int GetDebugNumber() const { return debugnr; } 67 | 68 | /** Returns a string describing the library version. */ 69 | std::string GetVersionString() const; 70 | private: 71 | int debugnr,minornr,majornr; 72 | }; 73 | 74 | } // end namespace 75 | 76 | #endif // RTPLIBRARYVERSION_H 77 | 78 | -------------------------------------------------------------------------------- /src/rtprandom.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtprandom.h 35 | */ 36 | 37 | #ifndef RTPRANDOM_H 38 | 39 | #define RTPRANDOM_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtptypes.h" 43 | #include 44 | 45 | #define RTPRANDOM_2POWMIN63 1.08420217248550443400745280086994171142578125e-19 46 | 47 | namespace jrtplib 48 | { 49 | 50 | /** Interface for generating random numbers. */ 51 | class JRTPLIB_IMPORTEXPORT RTPRandom 52 | { 53 | public: 54 | RTPRandom() { } 55 | virtual ~RTPRandom() { } 56 | 57 | /** Returns a random eight bit value. */ 58 | virtual uint8_t GetRandom8() = 0; 59 | 60 | /** Returns a random sixteen bit value. */ 61 | virtual uint16_t GetRandom16() = 0; 62 | 63 | /** Returns a random thirty-two bit value. */ 64 | virtual uint32_t GetRandom32() = 0; 65 | 66 | /** Returns a random number between $0.0$ and $1.0$. */ 67 | virtual double GetRandomDouble() = 0; 68 | 69 | /** Can be used by subclasses to generate a seed for a random number generator. */ 70 | uint32_t PickSeed(); 71 | 72 | /** Allocate a default random number generator based on your platform. */ 73 | static RTPRandom *CreateDefaultRandomNumberGenerator(); 74 | }; 75 | 76 | } // end namespace 77 | 78 | #endif // RTPRANDOM_H 79 | 80 | -------------------------------------------------------------------------------- /src/rtpsocketutilinternal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpsocketutilinternal.h 35 | */ 36 | 37 | #ifndef RTPSOCKETUTILINTERNAL_H 38 | 39 | #define RTPSOCKETUTILINTERNAL_H 40 | 41 | #ifdef RTP_SOCKETTYPE_WINSOCK 42 | #define RTPSOCKERR INVALID_SOCKET 43 | #define RTPCLOSE(x) closesocket(x) 44 | #define RTPSOCKLENTYPE int 45 | #define RTPIOCTL ioctlsocket 46 | #else // not Win32 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | #ifdef RTP_HAVE_SYS_FILIO 57 | #include 58 | #endif // RTP_HAVE_SYS_FILIO 59 | #ifdef RTP_HAVE_SYS_SOCKIO 60 | #include 61 | #endif // RTP_HAVE_SYS_SOCKIO 62 | #ifdef RTP_SUPPORT_IFADDRS 63 | #include 64 | #endif // RTP_SUPPORT_IFADDRS 65 | 66 | #define RTPSOCKERR -1 67 | #define RTPCLOSE(x) close(x) 68 | 69 | #ifdef RTP_SOCKLENTYPE_UINT 70 | #define RTPSOCKLENTYPE unsigned int 71 | #else 72 | #define RTPSOCKLENTYPE int 73 | #endif // RTP_SOCKLENTYPE_UINT 74 | 75 | #define RTPIOCTL ioctl 76 | #endif // RTP_SOCKETTYPE_WINSOCK 77 | 78 | #endif // RTPSOCKETUTILINTERNAL_H 79 | 80 | -------------------------------------------------------------------------------- /visual_studio_jthread_jrtplib_compilation.txt: -------------------------------------------------------------------------------- 1 | To build JThread and JRTPLIB, you'll need to use 'cmake' to generate 2 | the project files. Below you can find the procedure you can follow. 3 | I've also created a screencast which illustrates the steps in making 4 | the library. You can try one of these files (it's the same file, in 5 | different video formats): 6 | 7 | http://research.edm.uhasselt.be/jori/jthread_jrtplib_example_mpeg1.mpg 8 | http://research.edm.uhasselt.be/jori/jthread_jrtplib_example_mpeg2.mpg 9 | http://research.edm.uhasselt.be/jori/jthread_jrtplib_example.avi 10 | 11 | In words you'll need to do the following. As an example, I'll assume 12 | that jrtplib is extracted into c:\projects\jrtplib-3.9.1 and jthread 13 | is in c:\projects\jthread-1.3.1 14 | 15 | First we'll build jthread. Start the CMake gui and enter 16 | c:\projects\jthread-1.3.1 as the source directory and 17 | c:\projects\jthread-1.3.1\build as the build directory. Then, 18 | before doing anything else, you'll need to specify where the library 19 | should be installed. I always use c:\local as the prefix, which will 20 | install the headers in c:\local\include and the libraries in 21 | c:\local\lib. To do this, add the cmake variable 22 | CMAKE_INSTALL_PREFIX and set it to c:\local 23 | 24 | Then, press 'configure'. When this first configure step is complete, 25 | press 'configure' again, and afterward press 'generate'. There you can 26 | specify to generate a visual studio project. When this is done, open 27 | the visual studio project (you can find it in 28 | c:\projects\jthread-1.3.1\build) and run the 'INSTALL' project. 29 | When this is done, select the 'release' build type, and run the 30 | 'INSTALL' project again. If all went well, you should find the 31 | jthread headers in c:\local\include\jthread, and the jthread library 32 | in c:\local\lib. 33 | 34 | Then, follow the exact same procedure for jrtplib. By using the same 35 | installation prefix (c:\local in my example), the cmake script will 36 | automatically detect jthread as well. After building and installing 37 | jrtplib, you should find that the examples are built as well, and 38 | that you can run them. 39 | 40 | To use jrtplib and jthread in another project, you must then do the 41 | following: 42 | - in the project settings, add the include directory 43 | c:\local\include to the list of include directories (for debug and 44 | release builds) 45 | - in the project settings, add c:\local\lib to the list of library 46 | directories. 47 | - for the release version, add jrtplib.lib, jthread.lib and 48 | ws2_32.lib to the list of libraries 49 | - for the debug version, add jrtplib_d.lib, jthread_d.lib and 50 | ws2_32.lib to the list of libraries. 51 | 52 | In your program files, include a jrtplib header like this: 53 | #include 54 | and a jthread header like this: 55 | #include 56 | 57 | -------------------------------------------------------------------------------- /src/rtcpapppacket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtcpapppacket.h" 34 | #ifdef RTPDEBUG 35 | #include 36 | #include 37 | #include 38 | #endif // RTPDEBUG 39 | 40 | #include "rtpdebug.h" 41 | 42 | namespace jrtplib 43 | { 44 | 45 | RTCPAPPPacket::RTCPAPPPacket(uint8_t *data,size_t datalength) 46 | : RTCPPacket(APP,data,datalength) 47 | { 48 | knownformat = false; 49 | 50 | RTCPCommonHeader *hdr; 51 | size_t len = datalength; 52 | 53 | hdr = (RTCPCommonHeader *)data; 54 | if (hdr->padding) 55 | { 56 | uint8_t padcount = data[datalength-1]; 57 | if ((padcount & 0x03) != 0) // not a multiple of four! (see rfc 3550 p 37) 58 | return; 59 | if (((size_t)padcount) >= len) 60 | return; 61 | len -= (size_t)padcount; 62 | } 63 | 64 | if (len < (sizeof(RTCPCommonHeader)+sizeof(uint32_t)*2)) 65 | return; 66 | len -= (sizeof(RTCPCommonHeader)+sizeof(uint32_t)*2); 67 | appdatalen = len; 68 | knownformat = true; 69 | } 70 | 71 | #ifdef RTPDEBUG 72 | void RTCPAPPPacket::Dump() 73 | { 74 | RTCPPacket::Dump(); 75 | if (!IsKnownFormat()) 76 | { 77 | std::cout << " Unknown format!" << std::endl; 78 | } 79 | else 80 | { 81 | std::cout << " SSRC: " << GetSSRC() << std::endl; 82 | 83 | char str[5]; 84 | memcpy(str,GetName(),4); 85 | str[4] = 0; 86 | std::cout << " Name: " << std::string(str).c_str() << std::endl; 87 | std::cout << " Length: " << GetAPPDataLength() << std::endl; 88 | } 89 | } 90 | #endif // RTPDEBUG 91 | 92 | } // end namespace 93 | 94 | -------------------------------------------------------------------------------- /src/rtcpunknownpacket.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtcpunknownpacket.h 35 | */ 36 | 37 | #ifndef RTCPUNKNOWNPACKET_H 38 | 39 | #define RTCPUNKNOWNPACKET_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtcppacket.h" 43 | 44 | namespace jrtplib 45 | { 46 | 47 | class RTCPCompoundPacket; 48 | 49 | /** Describes an RTCP packet of unknown type. 50 | * Describes an RTCP packet of unknown type. This class doesn't have any extra member functions besides 51 | * the ones it inherited. Note that since an unknown packet type doesn't have any format to check 52 | * against, the IsKnownFormat function will trivially return \c true. 53 | */ 54 | class JRTPLIB_IMPORTEXPORT RTCPUnknownPacket : public RTCPPacket 55 | { 56 | public: 57 | /** Creates an instance based on the data in \c data with length \c datalen. 58 | * Creates an instance based on the data in \c data with length \c datalen. Since the \c data pointer 59 | * is referenced inside the class (no copy of the data is made) one must make sure that the memory it 60 | * points to is valid as long as the class instance exists. 61 | */ 62 | RTCPUnknownPacket(uint8_t *data,size_t datalen) : RTCPPacket(Unknown,data,datalen) 63 | { 64 | // Since we don't expect a format, we'll trivially put knownformat = true 65 | knownformat = true; 66 | } 67 | ~RTCPUnknownPacket() { } 68 | }; 69 | 70 | } // end namespace 71 | 72 | #endif // RTCPUNKNOWNPACKET_H 73 | 74 | -------------------------------------------------------------------------------- /src/rtptcpaddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtptcpaddress.h 35 | */ 36 | 37 | #ifndef RTPTCPADDRESS_H 38 | 39 | #define RTPTCPADDRESS_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtpaddress.h" 43 | #include "rtptypes.h" 44 | #include "rtpsocketutil.h" 45 | 46 | namespace jrtplib 47 | { 48 | 49 | class RTPMemoryManager; 50 | 51 | /** Represents a TCP 'address' and port. 52 | * This class is used by the TCP transmission component, to specify which sockets 53 | * should be used to send/receive data, and to know on which socket incoming data 54 | * was received. 55 | */ 56 | class JRTPLIB_IMPORTEXPORT RTPTCPAddress : public RTPAddress 57 | { 58 | public: 59 | /** Creates an instance with which you can use a specific socket 60 | * in the TCP transmitter (must be connected). */ 61 | RTPTCPAddress(SocketType sock):RTPAddress(TCPAddress) 62 | { 63 | m_socket = sock; 64 | } 65 | 66 | ~RTPTCPAddress() { } 67 | 68 | /** Returns the socket that was specified in the constructor. */ 69 | SocketType GetSocket() const { return m_socket; } 70 | 71 | RTPAddress *CreateCopy(RTPMemoryManager *mgr) const; 72 | 73 | // Note that these functions are only used for received packets 74 | bool IsSameAddress(const RTPAddress *addr) const; 75 | bool IsFromSameHost(const RTPAddress *addr) const; 76 | #ifdef RTPDEBUG 77 | std::string GetAddressString() const; 78 | #endif // RTPDEBUG 79 | private: 80 | SocketType m_socket; 81 | }; 82 | 83 | } // end namespace 84 | 85 | #endif // RTPTCPADDRESS_H 86 | 87 | -------------------------------------------------------------------------------- /src/rtpdefines.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #ifndef RTPDEFINES_H 34 | 35 | #define RTPDEFINES_H 36 | 37 | #define RTP_VERSION 2 38 | #define RTP_MAXCSRCS 15 39 | #define RTP_MINPACKETSIZE 600 40 | #define RTP_DEFAULTPACKETSIZE 1400 41 | #define RTP_PROBATIONCOUNT 2 42 | #define RTP_MAXPRIVITEMS 256 43 | #define RTP_SENDERTIMEOUTMULTIPLIER 2 44 | #define RTP_BYETIMEOUTMULTIPLIER 1 45 | #define RTP_MEMBERTIMEOUTMULTIPLIER 5 46 | #define RTP_COLLISIONTIMEOUTMULTIPLIER 10 47 | #define RTP_NOTETTIMEOUTMULTIPLIER 25 48 | #define RTP_DEFAULTSESSIONBANDWIDTH 10000.0 49 | 50 | #define RTP_RTCPTYPE_SR 200 51 | #define RTP_RTCPTYPE_RR 201 52 | #define RTP_RTCPTYPE_SDES 202 53 | #define RTP_RTCPTYPE_BYE 203 54 | #define RTP_RTCPTYPE_APP 204 55 | 56 | #define RTCP_SDES_ID_CNAME 1 57 | #define RTCP_SDES_ID_NAME 2 58 | #define RTCP_SDES_ID_EMAIL 3 59 | #define RTCP_SDES_ID_PHONE 4 60 | #define RTCP_SDES_ID_LOCATION 5 61 | #define RTCP_SDES_ID_TOOL 6 62 | #define RTCP_SDES_ID_NOTE 7 63 | #define RTCP_SDES_ID_PRIVATE 8 64 | #define RTCP_SDES_NUMITEMS_NONPRIVATE 7 65 | #define RTCP_SDES_MAXITEMLENGTH 255 66 | 67 | #define RTCP_BYE_MAXREASONLENGTH 255 68 | #define RTCP_DEFAULTMININTERVAL 5.0 69 | #define RTCP_DEFAULTBANDWIDTHFRACTION 0.05 70 | #define RTCP_DEFAULTSENDERFRACTION 0.25 71 | #define RTCP_DEFAULTHALFATSTARTUP true 72 | #define RTCP_DEFAULTIMMEDIATEBYE true 73 | #define RTCP_DEFAULTSRBYE true 74 | 75 | #endif // RTPDEFINES_H 76 | 77 | -------------------------------------------------------------------------------- /src/rtpipv4address.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtpipv4address.h" 34 | #include "rtpmemorymanager.h" 35 | #ifdef RTPDEBUG 36 | #include "rtpinternalutils.h" 37 | #include 38 | #endif // RTPDEBUG 39 | 40 | #include "rtpdebug.h" 41 | 42 | namespace jrtplib 43 | { 44 | 45 | bool RTPIPv4Address::IsSameAddress(const RTPAddress *addr) const 46 | { 47 | if (addr == 0) 48 | return false; 49 | if (addr->GetAddressType() != IPv4Address) 50 | return false; 51 | 52 | const RTPIPv4Address *addr2 = (const RTPIPv4Address *)addr; 53 | if (addr2->GetIP() == ip && addr2->GetPort() == port) 54 | return true; 55 | return false; 56 | } 57 | 58 | bool RTPIPv4Address::IsFromSameHost(const RTPAddress *addr) const 59 | { 60 | if (addr == 0) 61 | return false; 62 | if (addr->GetAddressType() != IPv4Address) 63 | return false; 64 | 65 | const RTPIPv4Address *addr2 = (const RTPIPv4Address *)addr; 66 | if (addr2->GetIP() == ip) 67 | return true; 68 | return false; 69 | } 70 | 71 | RTPAddress *RTPIPv4Address::CreateCopy(RTPMemoryManager *mgr) const 72 | { 73 | JRTPLIB_UNUSED(mgr); // possibly unused 74 | RTPIPv4Address *a = RTPNew(mgr,RTPMEM_TYPE_CLASS_RTPADDRESS) RTPIPv4Address(ip,port); 75 | return a; 76 | } 77 | 78 | #ifdef RTPDEBUG 79 | std::string RTPIPv4Address::GetAddressString() const 80 | { 81 | char str[24]; 82 | 83 | RTP_SNPRINTF(str,24,"%d.%d.%d.%d:%d",(int)((ip>>24)&0xFF),(int)((ip>>16)&0xFF),(int)((ip>>8)&0xFF), 84 | (int)(ip&0xFF),(int)port); 85 | return std::string(str); 86 | } 87 | #endif // RTPDEBUG 88 | 89 | } // end namespace 90 | 91 | -------------------------------------------------------------------------------- /src/rtpconfig.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #ifndef RTPCONFIG_UNIX_H 34 | 35 | #define RTPCONFIG_UNIX_H 36 | 37 | #ifndef JRTPLIB_UNUSED 38 | /** 39 | * Provide a macro to use for marking method parameters as unused. 40 | */ 41 | #define JRTPLIB_UNUSED(x) (void)(x) 42 | #endif // JRTPLIB_UNUSED 43 | 44 | #define JRTPLIB_IMPORT ${JRTPLIB_IMPORT} 45 | #define JRTPLIB_EXPORT ${JRTPLIB_EXPORT} 46 | #ifdef JRTPLIB_COMPILING 47 | #define JRTPLIB_IMPORTEXPORT JRTPLIB_EXPORT 48 | #else 49 | #define JRTPLIB_IMPORTEXPORT JRTPLIB_IMPORT 50 | #endif // JRTPLIB_COMPILING 51 | 52 | ${RTP_HAVE_SYS_FILIO} 53 | 54 | ${RTP_HAVE_SYS_SOCKIO} 55 | 56 | ${RTP_ENDIAN} 57 | 58 | ${RTP_SOCKLENTYPE_UINT} 59 | 60 | ${RTP_HAVE_SOCKADDR_LEN} 61 | 62 | ${RTP_SUPPORT_IPV4MULTICAST} 63 | 64 | ${RTP_SUPPORT_THREAD} 65 | 66 | ${RTP_SUPPORT_SDESPRIV} 67 | 68 | ${RTP_SUPPORT_PROBATION} 69 | 70 | ${RTP_SUPPORT_GETLOGINR} 71 | 72 | ${RTP_SUPPORT_IPV6} 73 | 74 | ${RTP_SUPPORT_IPV6MULTICAST} 75 | 76 | ${RTP_SUPPORT_IFADDRS} 77 | 78 | ${RTP_SUPPORT_SENDAPP} 79 | 80 | ${RTP_SUPPORT_MEMORYMANAGEMENT} 81 | 82 | ${RTP_SUPPORT_RTCPUNKNOWN} 83 | 84 | ${RTP_SUPPORT_NETINET_IN} 85 | 86 | ${RTP_SOCKETTYPE_WINSOCK} 87 | 88 | ${RTP_HAVE_QUERYPERFORMANCECOUNTER} 89 | 90 | ${RTP_HAVE_VSUINT64SUFFIX} 91 | 92 | ${RTP_SNPRINTF_VERSION} 93 | 94 | ${RTP_HAVE_ARRAYALLOC} 95 | 96 | ${RTP_HAVE_RAND_S} 97 | 98 | ${RTP_HAVE_STRNCPY_S} 99 | 100 | ${RTP_SUPPORT_SRTP} 101 | 102 | ${RTP_HAVE_CLOCK_GETTIME} 103 | 104 | ${RTP_HAVE_POLL} 105 | 106 | ${RTP_HAVE_WSAPOLL} 107 | 108 | ${RTP_HAVE_MSG_NOSIGNAL} 109 | 110 | #endif // RTPCONFIG_UNIX_H 111 | 112 | -------------------------------------------------------------------------------- /tests/testautoportbase.cpp: -------------------------------------------------------------------------------- 1 | #include "rtpsession.h" 2 | #include "rtpsessionparams.h" 3 | #include "rtpudpv4transmitter.h" 4 | #include "rtperrors.h" 5 | #include "rtpsourcedata.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace jrtplib; 12 | 13 | void checkerror(int rtperr) 14 | { 15 | if (rtperr < 0) 16 | { 17 | std::cout << "ERROR: " << RTPGetErrorString(rtperr) << std::endl; 18 | exit(-1); 19 | } 20 | } 21 | 22 | class MyRTPSession : public RTPSession 23 | { 24 | protected: 25 | void OnValidatedRTPPacket(RTPSourceData *srcdat, RTPPacket *rtppack, bool isonprobation, bool *ispackethandled) 26 | { 27 | printf("Got packet in OnValidatedRTPPacket from source 0x%04x!\n", srcdat->GetSSRC()); 28 | DeletePacket(rtppack); 29 | *ispackethandled = true; 30 | } 31 | 32 | void OnRTCPSDESItem(RTPSourceData *srcdat, RTCPSDESPacket::ItemType t, const void *itemdata, size_t itemlength) 33 | { 34 | char msg[1024]; 35 | 36 | memset(msg, 0, sizeof(msg)); 37 | if (itemlength >= sizeof(msg)) 38 | itemlength = sizeof(msg)-1; 39 | 40 | memcpy(msg, itemdata, itemlength); 41 | printf("Received SDES item (%d): %s", (int)t, msg); 42 | } 43 | }; 44 | 45 | int main(void) 46 | { 47 | #ifdef RTP_SOCKETTYPE_WINSOCK 48 | WSADATA dat; 49 | WSAStartup(MAKEWORD(2,2),&dat); 50 | #endif // RTP_SOCKETTYPE_WINSOCK 51 | 52 | MyRTPSession sess; 53 | 54 | // Now, we'll create a RTP session, set the destination, send some 55 | // packets and poll for incoming data. 56 | 57 | RTPUDPv4TransmissionParams transparams; 58 | RTPSessionParams sessparams; 59 | 60 | sessparams.SetOwnTimestampUnit(1.0/10.0); 61 | sessparams.SetAcceptOwnPackets(true); 62 | transparams.SetPortbase(0); 63 | 64 | //transparams.SetRTCPMultiplexing(true); 65 | //transparams.SetAllowOddPortbase(true); 66 | 67 | int status = sess.Create(sessparams,&transparams); 68 | checkerror(status); 69 | 70 | RTPUDPv4TransmissionInfo *pInf = (RTPUDPv4TransmissionInfo *)sess.GetTransmissionInfo(); 71 | uint16_t rtpPort = pInf->GetRTPPort(); 72 | uint16_t rtcpPort = pInf->GetRTCPPort(); 73 | 74 | printf("Using RTP port %d and RTCP port %d\n", (int)rtpPort, (int)rtcpPort); 75 | 76 | uint32_t destip = ntohl(inet_addr("127.0.0.1")); 77 | 78 | // We're assuming that the destination is also using RTCP multiplexing 79 | // ('true' means that the same port will be used for RTCP) 80 | RTPIPv4Address addr(destip,rtpPort,rtcpPort); 81 | 82 | status = sess.AddDestination(addr); 83 | checkerror(status); 84 | 85 | const int num = 10; 86 | for (int i = 1 ; i <= num ; i++) 87 | { 88 | printf("\nSending packet %d/%d\n",i,num); 89 | 90 | // send the packet 91 | status = sess.SendPacket((void *)"1234567890",10,0,false,10); 92 | checkerror(status); 93 | 94 | #ifndef RTP_SUPPORT_THREAD 95 | status = sess.Poll(); 96 | checkerror(status); 97 | #endif // RTP_SUPPORT_THREAD 98 | 99 | RTPTime::Wait(RTPTime(1,0)); 100 | } 101 | 102 | sess.BYEDestroy(RTPTime(10,0),0,0); 103 | 104 | sess.Destroy(); 105 | 106 | #ifdef RTP_SOCKETTYPE_WINSOCK 107 | WSACleanup(); 108 | #endif // RTP_SOCKETTYPE_WINSOCK 109 | return 0; 110 | } 111 | 112 | -------------------------------------------------------------------------------- /src/rtpipv6destination.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpipv6destination.h 35 | */ 36 | 37 | #ifndef RTPIPV6DESTINATION_H 38 | 39 | #define RTPIPV6DESTINATION_H 40 | 41 | #include "rtpconfig.h" 42 | 43 | #ifdef RTP_SUPPORT_IPV6 44 | 45 | #include "rtptypes.h" 46 | #include 47 | #include 48 | #ifndef RTP_SOCKETTYPE_WINSOCK 49 | #include 50 | #include 51 | #include 52 | #endif // RTP_SOCKETTYPE_WINSOCK 53 | 54 | namespace jrtplib 55 | { 56 | 57 | class JRTPLIB_IMPORTEXPORT RTPIPv6Destination 58 | { 59 | public: 60 | RTPIPv6Destination(in6_addr ip,uint16_t portbase) 61 | { 62 | memset(&rtpaddr,0,sizeof(struct sockaddr_in6)); 63 | memset(&rtcpaddr,0,sizeof(struct sockaddr_in6)); 64 | rtpaddr.sin6_family = AF_INET6; 65 | rtpaddr.sin6_port = htons(portbase); 66 | rtpaddr.sin6_addr = ip; 67 | rtcpaddr.sin6_family = AF_INET6; 68 | rtcpaddr.sin6_port = htons(portbase+1); 69 | rtcpaddr.sin6_addr = ip; 70 | } 71 | in6_addr GetIP() const { return rtpaddr.sin6_addr; } 72 | bool operator==(const RTPIPv6Destination &src) const 73 | { 74 | if (rtpaddr.sin6_port == src.rtpaddr.sin6_port && (memcmp(&(src.rtpaddr.sin6_addr),&(rtpaddr.sin6_addr),sizeof(in6_addr)) == 0)) 75 | return true; 76 | return false; 77 | } 78 | const struct sockaddr_in6 *GetRTPSockAddr() const { return &rtpaddr; } 79 | const struct sockaddr_in6 *GetRTCPSockAddr() const { return &rtcpaddr; } 80 | std::string GetDestinationString() const; 81 | private: 82 | struct sockaddr_in6 rtpaddr; 83 | struct sockaddr_in6 rtcpaddr; 84 | }; 85 | 86 | } // end namespace 87 | 88 | #endif // RTP_SUPPORT_IPV6 89 | 90 | #endif // RTPIPV6DESTINATION_H 91 | 92 | -------------------------------------------------------------------------------- /src/rtcppacket.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtcppacket.h 35 | */ 36 | 37 | #ifndef RTCPPACKET_H 38 | 39 | #define RTCPPACKET_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtptypes.h" 43 | 44 | namespace jrtplib 45 | { 46 | 47 | class RTCPCompoundPacket; 48 | 49 | /** Base class for specific types of RTCP packets. */ 50 | class JRTPLIB_IMPORTEXPORT RTCPPacket 51 | { 52 | public: 53 | /** Identifies the specific kind of RTCP packet. */ 54 | enum PacketType 55 | { 56 | SR, /**< An RTCP sender report. */ 57 | RR, /**< An RTCP receiver report. */ 58 | SDES, /**< An RTCP source description packet. */ 59 | BYE, /**< An RTCP bye packet. */ 60 | APP, /**< An RTCP packet containing application specific data. */ 61 | Unknown /**< The type of RTCP packet was not recognized. */ 62 | }; 63 | protected: 64 | RTCPPacket(PacketType t,uint8_t *d,size_t dlen) : data(d),datalen(dlen),packettype(t) { knownformat = false; } 65 | public: 66 | virtual ~RTCPPacket() { } 67 | 68 | /** Returns \c true if the subclass was able to interpret the data and \c false otherwise. */ 69 | bool IsKnownFormat() const { return knownformat; } 70 | 71 | /** Returns the actual packet type which the subclass implements. */ 72 | PacketType GetPacketType() const { return packettype; } 73 | 74 | /** Returns a pointer to the data of this RTCP packet. */ 75 | uint8_t *GetPacketData() { return data; } 76 | 77 | /** Returns the length of this RTCP packet. */ 78 | size_t GetPacketLength() const { return datalen; } 79 | 80 | #ifdef RTPDEBUG 81 | virtual void Dump(); 82 | #endif // RTPDEBUG 83 | protected: 84 | uint8_t *data; 85 | size_t datalen; 86 | bool knownformat; 87 | private: 88 | const PacketType packettype; 89 | }; 90 | 91 | } // end namespace 92 | 93 | #endif // RTCPPACKET_H 94 | 95 | -------------------------------------------------------------------------------- /src/rtprandomurandom.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtprandomurandom.h" 34 | #include "rtperrors.h" 35 | 36 | #include "rtpdebug.h" 37 | 38 | namespace jrtplib 39 | { 40 | 41 | RTPRandomURandom::RTPRandomURandom() 42 | { 43 | device = 0; 44 | } 45 | 46 | RTPRandomURandom::~RTPRandomURandom() 47 | { 48 | if (device) 49 | fclose(device); 50 | } 51 | 52 | int RTPRandomURandom::Init() 53 | { 54 | if (device) 55 | return ERR_RTP_RTPRANDOMURANDOM_ALREADYOPEN; 56 | 57 | device = fopen("/dev/urandom","rb"); 58 | if (device == 0) 59 | return ERR_RTP_RTPRANDOMURANDOM_CANTOPEN; 60 | 61 | return 0; 62 | } 63 | 64 | uint8_t RTPRandomURandom::GetRandom8() 65 | { 66 | if (!device) 67 | return 0; 68 | 69 | uint8_t value; 70 | 71 | fread(&value, sizeof(uint8_t), 1, device); 72 | 73 | return value; 74 | } 75 | 76 | uint16_t RTPRandomURandom::GetRandom16() 77 | { 78 | if (!device) 79 | return 0; 80 | 81 | uint16_t value; 82 | 83 | fread(&value, sizeof(uint16_t), 1, device); 84 | 85 | return value; 86 | } 87 | 88 | uint32_t RTPRandomURandom::GetRandom32() 89 | { 90 | if (!device) 91 | return 0; 92 | 93 | uint32_t value; 94 | 95 | fread(&value, sizeof(uint32_t), 1, device); 96 | 97 | return value; 98 | } 99 | 100 | double RTPRandomURandom::GetRandomDouble() 101 | { 102 | if (!device) 103 | return 0; 104 | 105 | uint64_t value; 106 | 107 | fread(&value, sizeof(uint64_t), 1, device); 108 | 109 | #ifdef RTP_HAVE_VSUINT64SUFFIX 110 | value &= 0x7fffffffffffffffui64; 111 | #else 112 | value &= 0x7fffffffffffffffULL; 113 | #endif // RTP_HAVE_VSUINT64SUFFIX 114 | 115 | int64_t value2 = (int64_t)value; 116 | double x = RTPRANDOM_2POWMIN63*(double)value2; 117 | 118 | return x; 119 | 120 | } 121 | 122 | } // end namespace 123 | 124 | -------------------------------------------------------------------------------- /src/rtprandom.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #if defined(WIN32) && !defined(_WIN32_WCE) 34 | #define _CRT_RAND_S 35 | #endif // WIN32 || _WIN32_WCE 36 | 37 | #include "rtprandom.h" 38 | #include "rtprandomrands.h" 39 | #include "rtprandomurandom.h" 40 | #include "rtprandomrand48.h" 41 | #include 42 | #ifndef WIN32 43 | #include 44 | #else 45 | #ifndef _WIN32_WCE 46 | #include 47 | #else 48 | #include 49 | #include 50 | #endif // _WIN32_WINCE 51 | #include 52 | #endif // WIN32 53 | 54 | #include "rtpdebug.h" 55 | 56 | namespace jrtplib 57 | { 58 | 59 | uint32_t RTPRandom::PickSeed() 60 | { 61 | uint32_t x; 62 | #if defined(WIN32) || defined(_WIN32_WINCE) 63 | #ifndef _WIN32_WCE 64 | x = (uint32_t)_getpid(); 65 | x += (uint32_t)time(0); 66 | x += (uint32_t)clock(); 67 | #else 68 | x = (uint32_t)GetCurrentProcessId(); 69 | 70 | FILETIME ft; 71 | SYSTEMTIME st; 72 | 73 | GetSystemTime(&st); 74 | SystemTimeToFileTime(&st,&ft); 75 | 76 | x += ft.dwLowDateTime; 77 | #endif // _WIN32_WCE 78 | x ^= (uint32_t)((uint8_t *)this - (uint8_t *)0); 79 | #else 80 | x = (uint32_t)getpid(); 81 | x += (uint32_t)time(0); 82 | x += (uint32_t)clock(); 83 | x ^= (uint32_t)((uint8_t *)this - (uint8_t *)0); 84 | #endif 85 | return x; 86 | } 87 | 88 | RTPRandom *RTPRandom::CreateDefaultRandomNumberGenerator() 89 | { 90 | #ifdef RTP_HAVE_RAND_S 91 | RTPRandomRandS *r = new RTPRandomRandS(); 92 | #else 93 | RTPRandomURandom *r = new RTPRandomURandom(); 94 | #endif // RTP_HAVE_RAND_S 95 | RTPRandom *rRet = r; 96 | 97 | if (r->Init() < 0) // fall back to rand48 98 | { 99 | delete r; 100 | rRet = new RTPRandomRand48(); 101 | } 102 | 103 | return rRet; 104 | } 105 | 106 | } // end namespace 107 | 108 | -------------------------------------------------------------------------------- /src/rtcpbyepacket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtcpbyepacket.h" 34 | #ifdef RTPDEBUG 35 | #include 36 | #include 37 | #endif // RTPDEBUG 38 | 39 | #include "rtpdebug.h" 40 | 41 | namespace jrtplib 42 | { 43 | 44 | RTCPBYEPacket::RTCPBYEPacket(uint8_t *data,size_t datalength) 45 | : RTCPPacket(BYE,data,datalength) 46 | { 47 | knownformat = false; 48 | reasonoffset = 0; 49 | 50 | RTCPCommonHeader *hdr; 51 | size_t len = datalength; 52 | 53 | hdr = (RTCPCommonHeader *)data; 54 | if (hdr->padding) 55 | { 56 | uint8_t padcount = data[datalength-1]; 57 | if ((padcount & 0x03) != 0) // not a multiple of four! (see rfc 3550 p 37) 58 | return; 59 | if (((size_t)padcount) >= len) 60 | return; 61 | len -= (size_t)padcount; 62 | } 63 | 64 | size_t ssrclen = ((size_t)(hdr->count))*sizeof(uint32_t) + sizeof(RTCPCommonHeader); 65 | if (ssrclen > len) 66 | return; 67 | if (ssrclen < len) // there's probably a reason for leaving 68 | { 69 | uint8_t *reasonlength = (data+ssrclen); 70 | size_t reaslen = (size_t)(*reasonlength); 71 | if (reaslen > (len-ssrclen-1)) 72 | return; 73 | reasonoffset = ssrclen; 74 | } 75 | knownformat = true; 76 | } 77 | 78 | #ifdef RTPDEBUG 79 | void RTCPBYEPacket::Dump() 80 | { 81 | RTCPPacket::Dump(); 82 | if (!IsKnownFormat()) 83 | { 84 | std::cout << " Unknown format" << std::endl; 85 | return; 86 | } 87 | 88 | int num = GetSSRCCount(); 89 | int i; 90 | 91 | for (i = 0 ; i < num ; i++) 92 | std::cout << " SSRC: " << GetSSRC(i) << std::endl; 93 | if (HasReasonForLeaving()) 94 | { 95 | char str[1024]; 96 | memcpy(str,GetReasonData(),GetReasonLength()); 97 | str[GetReasonLength()] = 0; 98 | std::cout << " Reason: " << str << std::endl; 99 | } 100 | } 101 | #endif // RTPDEBUG 102 | 103 | } // end namespace 104 | 105 | -------------------------------------------------------------------------------- /src/rtpstructs.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpstructs.h 35 | */ 36 | 37 | #ifndef RTPSTRUCTS_H 38 | 39 | #define RTPSTRUCTS_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtptypes.h" 43 | 44 | namespace jrtplib 45 | { 46 | 47 | struct RTPHeader 48 | { 49 | #ifdef RTP_BIG_ENDIAN 50 | uint8_t version:2; 51 | uint8_t padding:1; 52 | uint8_t extension:1; 53 | uint8_t csrccount:4; 54 | 55 | uint8_t marker:1; 56 | uint8_t payloadtype:7; 57 | #else // little endian 58 | uint8_t csrccount:4; 59 | uint8_t extension:1; 60 | uint8_t padding:1; 61 | uint8_t version:2; 62 | 63 | uint8_t payloadtype:7; 64 | uint8_t marker:1; 65 | #endif // RTP_BIG_ENDIAN 66 | 67 | uint16_t sequencenumber; 68 | uint32_t timestamp; 69 | uint32_t ssrc; 70 | }; 71 | 72 | struct RTPExtensionHeader 73 | { 74 | uint16_t extid; 75 | uint16_t length; 76 | }; 77 | 78 | struct RTPSourceIdentifier 79 | { 80 | uint32_t ssrc; 81 | }; 82 | 83 | struct RTCPCommonHeader 84 | { 85 | #ifdef RTP_BIG_ENDIAN 86 | uint8_t version:2; 87 | uint8_t padding:1; 88 | uint8_t count:5; 89 | #else // little endian 90 | uint8_t count:5; 91 | uint8_t padding:1; 92 | uint8_t version:2; 93 | #endif // RTP_BIG_ENDIAN 94 | 95 | uint8_t packettype; 96 | uint16_t length; 97 | }; 98 | 99 | struct RTCPSenderReport 100 | { 101 | uint32_t ntptime_msw; 102 | uint32_t ntptime_lsw; 103 | uint32_t rtptimestamp; 104 | uint32_t packetcount; 105 | uint32_t octetcount; 106 | }; 107 | 108 | struct RTCPReceiverReport 109 | { 110 | uint32_t ssrc; // Identifies about which SSRC's data this report is... 111 | uint8_t fractionlost; 112 | uint8_t packetslost[3]; 113 | uint32_t exthighseqnr; 114 | uint32_t jitter; 115 | uint32_t lsr; 116 | uint32_t dlsr; 117 | }; 118 | 119 | struct RTCPSDESHeader 120 | { 121 | uint8_t sdesid; 122 | uint8_t length; 123 | }; 124 | 125 | } // end namespace 126 | 127 | #endif // RTPSTRUCTS 128 | 129 | -------------------------------------------------------------------------------- /src/rtpcollisionlist.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpcollisionlist.h 35 | */ 36 | 37 | #ifndef RTPCOLLISIONLIST_H 38 | 39 | #define RTPCOLLISIONLIST_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtpaddress.h" 43 | #include "rtptimeutilities.h" 44 | #include "rtpmemoryobject.h" 45 | #include 46 | 47 | namespace jrtplib 48 | { 49 | 50 | class RTPAddress; 51 | 52 | /** This class represents a list of addresses from which SSRC collisions were detected. */ 53 | class JRTPLIB_IMPORTEXPORT RTPCollisionList : public RTPMemoryObject 54 | { 55 | public: 56 | /** Constructs an instance, optionally installing a memory manager. */ 57 | RTPCollisionList(RTPMemoryManager *mgr = 0); 58 | ~RTPCollisionList() { Clear(); } 59 | 60 | /** Clears the list of addresses. */ 61 | void Clear(); 62 | 63 | /** Updates the entry for address \c addr to indicate that a collision was detected at time \c receivetime. 64 | * Updates the entry for address \c addr to indicate that a collision was detected at time \c receivetime. 65 | * If the entry did not exist yet, the flag \c created is set to \c true, otherwise it is set to \c false. 66 | */ 67 | int UpdateAddress(const RTPAddress *addr,const RTPTime &receivetime,bool *created); 68 | 69 | /** Returns \c true} if the address \c addr appears in the list. */ 70 | bool HasAddress(const RTPAddress *addr) const; 71 | 72 | /** Assuming that the current time is given by \c currenttime, this function times out entries which 73 | * haven't been updated in the previous time interval specified by \c timeoutdelay. 74 | */ 75 | void Timeout(const RTPTime ¤ttime,const RTPTime &timeoutdelay); 76 | #ifdef RTPDEBUG 77 | void Dump(); 78 | #endif // RTPDEBUG 79 | private: 80 | class AddressAndTime 81 | { 82 | public: 83 | AddressAndTime(RTPAddress *a,const RTPTime &t) : addr(a),recvtime(t) { } 84 | 85 | RTPAddress *addr; 86 | RTPTime recvtime; 87 | }; 88 | 89 | std::list addresslist; 90 | }; 91 | 92 | } // end namespace 93 | 94 | #endif // RTPCOLLISIONLIST_H 95 | 96 | -------------------------------------------------------------------------------- /src/rtpbyteaddress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtpbyteaddress.h" 34 | #include "rtpmemorymanager.h" 35 | #ifdef RTPDEBUG 36 | #include "rtpinternalutils.h" 37 | #include 38 | #endif // RTPDEBUG 39 | 40 | namespace jrtplib 41 | { 42 | 43 | bool RTPByteAddress::IsSameAddress(const RTPAddress *addr) const 44 | { 45 | if (addr == 0) 46 | return false; 47 | if (addr->GetAddressType() != ByteAddress) 48 | return false; 49 | 50 | const RTPByteAddress *addr2 = (const RTPByteAddress *)addr; 51 | 52 | if (addr2->addresslength != addresslength) 53 | return false; 54 | if (addresslength == 0 || (memcmp(hostaddress, addr2->hostaddress, addresslength) == 0)) 55 | { 56 | if (port == addr2->port) 57 | return true; 58 | } 59 | return false; 60 | } 61 | 62 | bool RTPByteAddress::IsFromSameHost(const RTPAddress *addr) const 63 | { 64 | if (addr == 0) 65 | return false; 66 | if (addr->GetAddressType() != ByteAddress) 67 | return false; 68 | 69 | const RTPByteAddress *addr2 = (const RTPByteAddress *)addr; 70 | 71 | if (addr2->addresslength != addresslength) 72 | return false; 73 | if (addresslength == 0 || (memcmp(hostaddress, addr2->hostaddress, addresslength) == 0)) 74 | return true; 75 | return false; 76 | } 77 | 78 | RTPAddress *RTPByteAddress::CreateCopy(RTPMemoryManager *mgr) const 79 | { 80 | JRTPLIB_UNUSED(mgr); // possibly unused 81 | RTPByteAddress *a = RTPNew(mgr, RTPMEM_TYPE_CLASS_RTPADDRESS) RTPByteAddress(hostaddress, addresslength, port); 82 | return a; 83 | } 84 | 85 | #ifdef RTPDEBUG 86 | std::string RTPByteAddress::GetAddressString() const 87 | { 88 | char str[16]; 89 | std::string s; 90 | 91 | for (int i = 0 ; i < addresslength ; i++) 92 | { 93 | RTP_SNPRINTF(str, 16, "%02X", (int)hostaddress[i]); 94 | s += std::string(str); 95 | } 96 | s += std::string(":"); 97 | 98 | RTP_SNPRINTF(str, 16, "%d",(int)port); 99 | s += std::string(str); 100 | 101 | return s; 102 | } 103 | 104 | #endif // RTPDEBUG 105 | 106 | } // end namespace 107 | -------------------------------------------------------------------------------- /examples/example4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This IPv4 example uses the background thread itself to process all packets. 3 | You can use example one to send data to the session that's created in this 4 | example. 5 | */ 6 | 7 | #include "rtpsession.h" 8 | #include "rtppacket.h" 9 | #include "rtpudpv4transmitter.h" 10 | #include "rtpipv4address.h" 11 | #include "rtpsessionparams.h" 12 | #include "rtperrors.h" 13 | #include "rtpsourcedata.h" 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | using namespace jrtplib; 20 | 21 | #ifdef RTP_SUPPORT_THREAD 22 | 23 | // 24 | // This function checks if there was a RTP error. If so, it displays an error 25 | // message and exists. 26 | // 27 | 28 | void checkerror(int rtperr) 29 | { 30 | if (rtperr < 0) 31 | { 32 | std::cout << "ERROR: " << RTPGetErrorString(rtperr) << std::endl; 33 | exit(-1); 34 | } 35 | } 36 | 37 | // 38 | // The new class routine 39 | // 40 | 41 | class MyRTPSession : public RTPSession 42 | { 43 | protected: 44 | void OnPollThreadStep(); 45 | void ProcessRTPPacket(const RTPSourceData &srcdat,const RTPPacket &rtppack); 46 | }; 47 | 48 | void MyRTPSession::OnPollThreadStep() 49 | { 50 | BeginDataAccess(); 51 | 52 | // check incoming packets 53 | if (GotoFirstSourceWithData()) 54 | { 55 | do 56 | { 57 | RTPPacket *pack; 58 | RTPSourceData *srcdat; 59 | 60 | srcdat = GetCurrentSourceInfo(); 61 | 62 | while ((pack = GetNextPacket()) != NULL) 63 | { 64 | ProcessRTPPacket(*srcdat,*pack); 65 | DeletePacket(pack); 66 | } 67 | } while (GotoNextSourceWithData()); 68 | } 69 | 70 | EndDataAccess(); 71 | } 72 | 73 | void MyRTPSession::ProcessRTPPacket(const RTPSourceData &srcdat,const RTPPacket &rtppack) 74 | { 75 | // You can inspect the packet and the source's info here 76 | std::cout << "Got packet " << rtppack.GetExtendedSequenceNumber() << " from SSRC " << srcdat.GetSSRC() << std::endl; 77 | } 78 | 79 | // 80 | // The main routine 81 | // 82 | 83 | int main(void) 84 | { 85 | #ifdef RTP_SOCKETTYPE_WINSOCK 86 | WSADATA dat; 87 | WSAStartup(MAKEWORD(2,2),&dat); 88 | #endif // RTP_SOCKETTYPE_WINSOCK 89 | 90 | MyRTPSession sess; 91 | uint16_t portbase; 92 | std::string ipstr; 93 | int status,num; 94 | 95 | // First, we'll ask for the necessary information 96 | 97 | std::cout << "Enter local portbase:" << std::endl; 98 | std::cin >> portbase; 99 | std::cout << std::endl; 100 | 101 | std::cout << std::endl; 102 | std::cout << "Number of seconds you wish to wait:" << std::endl; 103 | std::cin >> num; 104 | 105 | // Now, we'll create a RTP session, set the destination 106 | // and poll for incoming data. 107 | 108 | RTPUDPv4TransmissionParams transparams; 109 | RTPSessionParams sessparams; 110 | 111 | // IMPORTANT: The local timestamp unit MUST be set, otherwise 112 | // RTCP Sender Report info will be calculated wrong 113 | // In this case, we'll be just use 8000 samples per second. 114 | sessparams.SetOwnTimestampUnit(1.0/8000.0); 115 | 116 | transparams.SetPortbase(portbase); 117 | status = sess.Create(sessparams,&transparams); 118 | checkerror(status); 119 | 120 | // Wait a number of seconds 121 | RTPTime::Wait(RTPTime(num,0)); 122 | 123 | sess.BYEDestroy(RTPTime(10,0),0,0); 124 | 125 | #ifdef RTP_SOCKETTYPE_WINSOCK 126 | WSACleanup(); 127 | #endif // RTP_SOCKETTYPE_WINSOCK 128 | return 0; 129 | } 130 | 131 | #else 132 | 133 | int main(void) 134 | { 135 | std::cerr << "Thread support is required for this example" << std::endl; 136 | return 0; 137 | } 138 | 139 | #endif // RTP_SUPPORT_THREAD 140 | 141 | -------------------------------------------------------------------------------- /src/rtcprrpacket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtcprrpacket.h" 34 | #ifdef RTPDEBUG 35 | #include 36 | #endif // RTPDEBUG 37 | 38 | #include "rtpdebug.h" 39 | 40 | namespace jrtplib 41 | { 42 | 43 | RTCPRRPacket::RTCPRRPacket(uint8_t *data,size_t datalength) 44 | : RTCPPacket(RR,data,datalength) 45 | { 46 | knownformat = false; 47 | 48 | RTCPCommonHeader *hdr; 49 | size_t len = datalength; 50 | size_t expectedlength; 51 | 52 | hdr = (RTCPCommonHeader *)data; 53 | if (hdr->padding) 54 | { 55 | uint8_t padcount = data[datalength-1]; 56 | if ((padcount & 0x03) != 0) // not a multiple of four! (see rfc 3550 p 37) 57 | return; 58 | if (((size_t)padcount) >= len) 59 | return; 60 | len -= (size_t)padcount; 61 | } 62 | 63 | expectedlength = sizeof(RTCPCommonHeader)+sizeof(uint32_t); 64 | expectedlength += sizeof(RTCPReceiverReport)*((int)hdr->count); 65 | 66 | if (expectedlength != len) 67 | return; 68 | 69 | knownformat = true; 70 | } 71 | 72 | #ifdef RTPDEBUG 73 | void RTCPRRPacket::Dump() 74 | { 75 | RTCPPacket::Dump(); 76 | if (!IsKnownFormat()) 77 | std::cout << " Unknown format" << std::endl; 78 | else 79 | { 80 | int num = GetReceptionReportCount(); 81 | int i; 82 | 83 | std::cout << " SSRC of sender: " << GetSenderSSRC() << std::endl; 84 | for (i = 0 ; i < num ; i++) 85 | { 86 | std::cout << " Report block " << i << std::endl; 87 | std::cout << " SSRC: " << GetSSRC(i) << std::endl; 88 | std::cout << " Fraction lost: " << (uint32_t)GetFractionLost(i) << std::endl; 89 | std::cout << " Packets lost: " << GetLostPacketCount(i) << std::endl; 90 | std::cout << " Seq. nr.: " << GetExtendedHighestSequenceNumber(i) << std::endl; 91 | std::cout << " Jitter: " << GetJitter(i) << std::endl; 92 | std::cout << " LSR: " << GetLSR(i) << std::endl; 93 | std::cout << " DLSR: " << GetDLSR(i) << std::endl; 94 | } 95 | } 96 | } 97 | #endif // RTPDEBUG 98 | 99 | } // end namespace 100 | 101 | -------------------------------------------------------------------------------- /src/rtpsessionparams.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtpconfig.h" 34 | #include "rtpsessionparams.h" 35 | #include "rtpdefines.h" 36 | #include "rtperrors.h" 37 | 38 | #include "rtpdebug.h" 39 | 40 | namespace jrtplib 41 | { 42 | 43 | RTPSessionParams::RTPSessionParams() : mininterval(0,0) 44 | { 45 | #ifdef RTP_SUPPORT_THREAD 46 | usepollthread = true; 47 | m_needThreadSafety = true; 48 | #else 49 | usepollthread = false; 50 | m_needThreadSafety = false; 51 | #endif // RTP_SUPPORT_THREAD 52 | maxpacksize = RTP_DEFAULTPACKETSIZE; 53 | receivemode = RTPTransmitter::AcceptAll; 54 | acceptown = false; 55 | owntsunit = -1; // The user will have to set it to the correct value himself 56 | resolvehostname = false; 57 | #ifdef RTP_SUPPORT_PROBATION 58 | probationtype = RTPSources::ProbationStore; 59 | #endif // RTP_SUPPORT_PROBATION 60 | 61 | mininterval = RTPTime(RTCP_DEFAULTMININTERVAL); 62 | sessionbandwidth = RTP_DEFAULTSESSIONBANDWIDTH; 63 | controlfrac = RTCP_DEFAULTBANDWIDTHFRACTION; 64 | senderfrac = RTCP_DEFAULTSENDERFRACTION; 65 | usehalfatstartup = RTCP_DEFAULTHALFATSTARTUP; 66 | immediatebye = RTCP_DEFAULTIMMEDIATEBYE; 67 | SR_BYE = RTCP_DEFAULTSRBYE; 68 | 69 | sendermultiplier = RTP_SENDERTIMEOUTMULTIPLIER; 70 | generaltimeoutmultiplier = RTP_MEMBERTIMEOUTMULTIPLIER; 71 | byetimeoutmultiplier = RTP_BYETIMEOUTMULTIPLIER; 72 | collisionmultiplier = RTP_COLLISIONTIMEOUTMULTIPLIER; 73 | notemultiplier = RTP_NOTETTIMEOUTMULTIPLIER; 74 | 75 | usepredefinedssrc = false; 76 | predefinedssrc = 0; 77 | } 78 | 79 | int RTPSessionParams::SetUsePollThread(bool usethread) 80 | { 81 | #ifndef RTP_SUPPORT_THREAD 82 | JRTPLIB_UNUSED(usethread); 83 | return ERR_RTP_NOTHREADSUPPORT; 84 | #else 85 | usepollthread = usethread; 86 | return 0; 87 | #endif // RTP_SUPPORT_THREAD 88 | } 89 | 90 | int RTPSessionParams::SetNeedThreadSafety(bool s) 91 | { 92 | #ifndef RTP_SUPPORT_THREAD 93 | JRTPLIB_UNUSED(s); 94 | return ERR_RTP_NOTHREADSUPPORT; 95 | #else 96 | m_needThreadSafety = s; 97 | return 0; 98 | #endif // RTP_SUPPORT_THREAD 99 | } 100 | 101 | } // end namespace 102 | 103 | -------------------------------------------------------------------------------- /src/rtpipv6address.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtpipv6address.h" 34 | #include "rtpmemorymanager.h" 35 | 36 | #ifdef RTP_SUPPORT_IPV6 37 | 38 | #ifdef RTPDEBUG 39 | #include "rtpinternalutils.h" 40 | #include 41 | #endif // RTPDEBUG 42 | 43 | #include "rtpdebug.h" 44 | 45 | namespace jrtplib 46 | { 47 | 48 | RTPAddress *RTPIPv6Address::CreateCopy(RTPMemoryManager *mgr) const 49 | { 50 | JRTPLIB_UNUSED(mgr); // possibly unused 51 | RTPIPv6Address *newaddr = RTPNew(mgr,RTPMEM_TYPE_CLASS_RTPADDRESS) RTPIPv6Address(ip,port); 52 | return newaddr; 53 | } 54 | 55 | bool RTPIPv6Address::IsSameAddress(const RTPAddress *addr) const 56 | { 57 | if (addr == 0) 58 | return false; 59 | if (addr->GetAddressType() != RTPAddress::IPv6Address) 60 | return false; 61 | 62 | const RTPIPv6Address *addr2 = (const RTPIPv6Address *)addr; 63 | const uint8_t *ip2 = addr2->ip.s6_addr; 64 | 65 | if (port != addr2->port) 66 | return false; 67 | 68 | for (int i = 0 ; i < 16 ; i++) 69 | { 70 | if (ip.s6_addr[i] != ip2[i]) 71 | return false; 72 | } 73 | return true; 74 | } 75 | 76 | bool RTPIPv6Address::IsFromSameHost(const RTPAddress *addr) const 77 | { 78 | if (addr == 0) 79 | return false; 80 | if (addr->GetAddressType() != RTPAddress::IPv6Address) 81 | return false; 82 | 83 | const RTPIPv6Address *addr2 = (const RTPIPv6Address *)addr; 84 | const uint8_t *ip2 = addr2->ip.s6_addr; 85 | for (int i = 0 ; i < 16 ; i++) 86 | { 87 | if (ip.s6_addr[i] != ip2[i]) 88 | return false; 89 | } 90 | return true; 91 | } 92 | 93 | #ifdef RTPDEBUG 94 | std::string RTPIPv6Address::GetAddressString() const 95 | { 96 | char str[48]; 97 | uint16_t ip16[8]; 98 | int i,j; 99 | 100 | for (i = 0,j = 0 ; j < 8 ; j++,i += 2) 101 | { 102 | ip16[j] = (((uint16_t)ip.s6_addr[i])<<8); 103 | ip16[j] |= ((uint16_t)ip.s6_addr[i+1]); 104 | } 105 | 106 | RTP_SNPRINTF(str,48,"%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X/%d",(int)ip16[0],(int)ip16[1],(int)ip16[2],(int)ip16[3],(int)ip16[4],(int)ip16[5],(int)ip16[6],(int)ip16[7],(int)port); 107 | return std::string(str); 108 | } 109 | #endif // RTPDEBUG 110 | 111 | } // end namespace 112 | 113 | #endif // RTP_SUPPORT_IPV6 114 | 115 | -------------------------------------------------------------------------------- /src/rtprandomrand48.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtprandomrand48.h" 34 | 35 | namespace jrtplib 36 | { 37 | 38 | RTPRandomRand48::RTPRandomRand48() 39 | { 40 | SetSeed(PickSeed()); 41 | } 42 | 43 | RTPRandomRand48::RTPRandomRand48(uint32_t seed) 44 | { 45 | SetSeed(seed); 46 | } 47 | 48 | RTPRandomRand48::~RTPRandomRand48() 49 | { 50 | } 51 | 52 | void RTPRandomRand48::SetSeed(uint32_t seed) 53 | { 54 | #ifdef RTP_SUPPORT_THREAD 55 | mutex.Init(); // TODO: check error! 56 | #endif // RTP_SUPPORT_THREAD 57 | 58 | #ifdef RTP_HAVE_VSUINT64SUFFIX 59 | state = ((uint64_t)seed) << 16 | 0x330Eui64; 60 | #else 61 | state = ((uint64_t)seed) << 16 | 0x330EULL; 62 | #endif // RTP_HAVE_VSUINT64SUFFIX 63 | } 64 | 65 | uint8_t RTPRandomRand48::GetRandom8() 66 | { 67 | uint32_t x = ((GetRandom32() >> 24)&0xff); 68 | 69 | return (uint8_t)x; 70 | } 71 | 72 | uint16_t RTPRandomRand48::GetRandom16() 73 | { 74 | uint32_t x = ((GetRandom32() >> 16)&0xffff); 75 | 76 | return (uint16_t)x; 77 | } 78 | 79 | uint32_t RTPRandomRand48::GetRandom32() 80 | { 81 | #ifdef RTP_SUPPORT_THREAD 82 | mutex.Lock(); 83 | #endif // RTP_SUPPORT_THREAD 84 | 85 | #ifdef RTP_HAVE_VSUINT64SUFFIX 86 | state = ((0x5DEECE66Dui64*state) + 0xBui64)&0x0000ffffffffffffui64; 87 | 88 | uint32_t x = (uint32_t)((state>>16)&0xffffffffui64); 89 | #else 90 | state = ((0x5DEECE66DULL*state) + 0xBULL)&0x0000ffffffffffffULL; 91 | 92 | uint32_t x = (uint32_t)((state>>16)&0xffffffffULL); 93 | #endif // RTP_HAVE_VSUINT64SUFFIX 94 | 95 | #ifdef RTP_SUPPORT_THREAD 96 | mutex.Unlock(); 97 | #endif // RTP_SUPPORT_THREAD 98 | return x; 99 | } 100 | 101 | double RTPRandomRand48::GetRandomDouble() 102 | { 103 | #ifdef RTP_SUPPORT_THREAD 104 | mutex.Lock(); 105 | #endif // RTP_SUPPORT_THREAD 106 | 107 | #ifdef RTP_HAVE_VSUINT64SUFFIX 108 | state = ((0x5DEECE66Dui64*state) + 0xBui64)&0x0000ffffffffffffui64; 109 | 110 | int64_t x = (int64_t)state; 111 | #else 112 | state = ((0x5DEECE66DULL*state) + 0xBULL)&0x0000ffffffffffffULL; 113 | 114 | int64_t x = (int64_t)state; 115 | #endif // RTP_HAVE_VSUINT64SUFFIX 116 | 117 | #ifdef RTP_SUPPORT_THREAD 118 | mutex.Unlock(); 119 | #endif // RTP_SUPPORT_THREAD 120 | double y = 3.552713678800500929355621337890625e-15 * (double)x; 121 | return y; 122 | } 123 | 124 | } // end namespace 125 | 126 | -------------------------------------------------------------------------------- /tests/testmultiplex.cpp: -------------------------------------------------------------------------------- 1 | #include "rtpsession.h" 2 | #include "rtpudpv4transmitter.h" 3 | #include "rtpipv4address.h" 4 | #include "rtpsessionparams.h" 5 | #include "rtperrors.h" 6 | #include "rtplibraryversion.h" 7 | #include "rtpsourcedata.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace jrtplib; 14 | 15 | void checkerror(int rtperr) 16 | { 17 | if (rtperr < 0) 18 | { 19 | std::cout << "ERROR: " << RTPGetErrorString(rtperr) << std::endl; 20 | exit(-1); 21 | } 22 | } 23 | 24 | class MyRTPSession : public RTPSession 25 | { 26 | protected: 27 | void OnValidatedRTPPacket(RTPSourceData *srcdat, RTPPacket *rtppack, bool isonprobation, bool *ispackethandled) 28 | { 29 | printf("Got packet in OnValidatedRTPPacket from source 0x%04x!\n", srcdat->GetSSRC()); 30 | DeletePacket(rtppack); 31 | *ispackethandled = true; 32 | } 33 | 34 | void OnRTCPSDESItem(RTPSourceData *srcdat, RTCPSDESPacket::ItemType t, const void *itemdata, size_t itemlength) 35 | { 36 | char msg[1024]; 37 | 38 | memset(msg, 0, sizeof(msg)); 39 | if (itemlength >= sizeof(msg)) 40 | itemlength = sizeof(msg)-1; 41 | 42 | memcpy(msg, itemdata, itemlength); 43 | printf("Received SDES item (%d): %s", (int)t, msg); 44 | } 45 | }; 46 | 47 | int main(void) 48 | { 49 | #ifdef RTP_SOCKETTYPE_WINSOCK 50 | WSADATA dat; 51 | WSAStartup(MAKEWORD(2,2),&dat); 52 | #endif // RTP_SOCKETTYPE_WINSOCK 53 | 54 | MyRTPSession sess; 55 | uint16_t portbase,destport; 56 | uint32_t destip; 57 | std::string ipstr; 58 | int status,i,num; 59 | 60 | std::cout << "Using version " << RTPLibraryVersion::GetVersion().GetVersionString() << std::endl; 61 | 62 | // First, we'll ask for the necessary information 63 | 64 | portbase = 5000; 65 | ipstr = "127.0.0.1"; 66 | 67 | destip = inet_addr(ipstr.c_str()); 68 | if (destip == INADDR_NONE) 69 | { 70 | std::cerr << "Bad IP address specified" << std::endl; 71 | return -1; 72 | } 73 | 74 | // The inet_addr function returns a value in network byte order, but 75 | // we need the IP address in host byte order, so we use a call to 76 | // ntohl 77 | destip = ntohl(destip); 78 | destport = 5000; 79 | num = 10; 80 | 81 | // Now, we'll create a RTP session, set the destination, send some 82 | // packets and poll for incoming data. 83 | 84 | RTPUDPv4TransmissionParams transparams; 85 | RTPSessionParams sessparams; 86 | 87 | // IMPORTANT: The local timestamp unit MUST be set, otherwise 88 | // RTCP Sender Report info will be calculated wrong 89 | // In this case, we'll be sending 10 samples each second, so we'll 90 | // put the timestamp unit to (1.0/10.0) 91 | sessparams.SetOwnTimestampUnit(1.0/10.0); 92 | 93 | sessparams.SetAcceptOwnPackets(true); 94 | transparams.SetPortbase(portbase); 95 | 96 | // Let's also use RTCP multiplexing for this example 97 | transparams.SetRTCPMultiplexing(true); 98 | 99 | status = sess.Create(sessparams,&transparams); 100 | checkerror(status); 101 | 102 | // We're assuming that the destination is also using RTCP multiplexing 103 | // ('true' means that the same port will be used for RTCP) 104 | RTPIPv4Address addr(destip,destport,true); 105 | 106 | status = sess.AddDestination(addr); 107 | checkerror(status); 108 | 109 | for (i = 1 ; i <= num ; i++) 110 | { 111 | printf("\nSending packet %d/%d\n",i,num); 112 | 113 | // send the packet 114 | status = sess.SendPacket((void *)"1234567890",10,0,false,10); 115 | checkerror(status); 116 | 117 | #ifndef RTP_SUPPORT_THREAD 118 | status = sess.Poll(); 119 | checkerror(status); 120 | #endif // RTP_SUPPORT_THREAD 121 | 122 | RTPTime::Wait(RTPTime(1,0)); 123 | } 124 | 125 | sess.BYEDestroy(RTPTime(10,0),0,0); 126 | 127 | #ifdef RTP_SOCKETTYPE_WINSOCK 128 | WSACleanup(); 129 | #endif // RTP_SOCKETTYPE_WINSOCK 130 | return 0; 131 | } 132 | 133 | -------------------------------------------------------------------------------- /src/rtpaddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpaddress.h 35 | */ 36 | 37 | #ifndef RTPADDRESS_H 38 | 39 | #define RTPADDRESS_H 40 | 41 | #include "rtpconfig.h" 42 | #include 43 | 44 | namespace jrtplib 45 | { 46 | 47 | class RTPMemoryManager; 48 | 49 | /** This class is an abstract class which is used to specify destinations, multicast groups etc. */ 50 | class JRTPLIB_IMPORTEXPORT RTPAddress 51 | { 52 | public: 53 | /** Identifies the actual implementation being used. */ 54 | enum AddressType 55 | { 56 | IPv4Address, /**< Used by the UDP over IPv4 transmitter. */ 57 | IPv6Address, /**< Used by the UDP over IPv6 transmitter. */ 58 | ByteAddress, /**< A very general type of address, consisting of a port number and a number of bytes representing the host address. */ 59 | UserDefinedAddress, /**< Can be useful for a user-defined transmitter. */ 60 | TCPAddress /**< Used by the TCP transmitter. */ 61 | }; 62 | 63 | /** Returns the type of address the actual implementation represents. */ 64 | AddressType GetAddressType() const { return addresstype; } 65 | 66 | /** Creates a copy of the RTPAddress instance. 67 | * Creates a copy of the RTPAddress instance. If \c mgr is not NULL, the 68 | * corresponding memory manager will be used to allocate the memory for the address 69 | * copy. 70 | */ 71 | virtual RTPAddress *CreateCopy(RTPMemoryManager *mgr) const = 0; 72 | 73 | /** Checks if the address \c addr is the same address as the one this instance represents. 74 | * Checks if the address \c addr is the same address as the one this instance represents. 75 | * Implementations must be able to handle a NULL argument. 76 | */ 77 | virtual bool IsSameAddress(const RTPAddress *addr) const = 0; 78 | 79 | /** Checks if the address \c addr represents the same host as this instance. 80 | * Checks if the address \c addr represents the same host as this instance. Implementations 81 | * must be able to handle a NULL argument. 82 | */ 83 | virtual bool IsFromSameHost(const RTPAddress *addr) const = 0; 84 | 85 | #ifdef RTPDEBUG 86 | virtual std::string GetAddressString() const = 0; 87 | #endif // RTPDEBUG 88 | 89 | virtual ~RTPAddress() { } 90 | protected: 91 | // only allow subclasses to be created 92 | RTPAddress(const AddressType t) : addresstype(t) { } 93 | private: 94 | const AddressType addresstype; 95 | }; 96 | 97 | } // end namespace 98 | 99 | #endif // RTPADDRESS_H 100 | 101 | -------------------------------------------------------------------------------- /src/rtpbyteaddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpbyteaddress.h 35 | */ 36 | 37 | #ifndef RTPBYTEADDRESS_H 38 | 39 | #define RTPBYTEADDRESS_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtpaddress.h" 43 | #include "rtptypes.h" 44 | #include 45 | 46 | #define RTPBYTEADDRESS_MAXLENGTH 128 47 | 48 | namespace jrtplib 49 | { 50 | 51 | class RTPMemoryManager; 52 | 53 | /** A very general kind of address consisting of a port number and a number of bytes describing the host address. 54 | * A very general kind of address, consisting of a port number and a number of bytes describing the host address. 55 | */ 56 | class JRTPLIB_IMPORTEXPORT RTPByteAddress : public RTPAddress 57 | { 58 | public: 59 | /** Creates an instance of the class using \c addrlen bytes of \c hostaddress as host identification, 60 | * and using \c port as the port number. */ 61 | RTPByteAddress(const uint8_t hostaddress[RTPBYTEADDRESS_MAXLENGTH], size_t addrlen, uint16_t port = 0) : RTPAddress(ByteAddress) { if (addrlen > RTPBYTEADDRESS_MAXLENGTH) addrlen = RTPBYTEADDRESS_MAXLENGTH; memcpy(RTPByteAddress::hostaddress, hostaddress, addrlen); RTPByteAddress::addresslength = addrlen; RTPByteAddress::port = port; } 62 | 63 | /** Sets the host address to the first \c addrlen bytes of \c hostaddress. */ 64 | void SetHostAddress(const uint8_t hostaddress[RTPBYTEADDRESS_MAXLENGTH], size_t addrlen) { if (addrlen > RTPBYTEADDRESS_MAXLENGTH) addrlen = RTPBYTEADDRESS_MAXLENGTH; memcpy(RTPByteAddress::hostaddress, hostaddress, addrlen); RTPByteAddress::addresslength = addrlen; } 65 | 66 | /** Sets the port number to \c port. */ 67 | void SetPort(uint16_t port) { RTPByteAddress::port = port; } 68 | 69 | /** Returns a pointer to the stored host address. */ 70 | const uint8_t *GetHostAddress() const { return hostaddress; } 71 | 72 | /** Returns the length in bytes of the stored host address. */ 73 | size_t GetHostAddressLength() const { return addresslength; } 74 | 75 | /** Returns the port number stored in this instance. */ 76 | uint16_t GetPort() const { return port; } 77 | 78 | RTPAddress *CreateCopy(RTPMemoryManager *mgr) const; 79 | bool IsSameAddress(const RTPAddress *addr) const; 80 | bool IsFromSameHost(const RTPAddress *addr) const; 81 | #ifdef RTPDEBUG 82 | std::string GetAddressString() const; 83 | #endif // RTPDEBUG 84 | private: 85 | uint8_t hostaddress[RTPBYTEADDRESS_MAXLENGTH]; 86 | size_t addresslength; 87 | uint16_t port; 88 | }; 89 | 90 | } // end namespace 91 | 92 | #endif // RTPBYTEADDRESS_H 93 | 94 | -------------------------------------------------------------------------------- /examples/example1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Here's a small IPv4 example: it asks for a portbase and a destination and 3 | starts sending packets to that destination. 4 | */ 5 | 6 | #include "rtpsession.h" 7 | #include "rtpudpv4transmitter.h" 8 | #include "rtpipv4address.h" 9 | #include "rtpsessionparams.h" 10 | #include "rtperrors.h" 11 | #include "rtplibraryversion.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | using namespace jrtplib; 18 | 19 | // 20 | // This function checks if there was a RTP error. If so, it displays an error 21 | // message and exists. 22 | // 23 | 24 | void checkerror(int rtperr) 25 | { 26 | if (rtperr < 0) 27 | { 28 | std::cout << "ERROR: " << RTPGetErrorString(rtperr) << std::endl; 29 | exit(-1); 30 | } 31 | } 32 | 33 | // 34 | // The main routine 35 | // 36 | 37 | int main(void) 38 | { 39 | #ifdef RTP_SOCKETTYPE_WINSOCK 40 | WSADATA dat; 41 | WSAStartup(MAKEWORD(2,2),&dat); 42 | #endif // RTP_SOCKETTYPE_WINSOCK 43 | 44 | RTPSession sess; 45 | uint16_t portbase,destport; 46 | uint32_t destip; 47 | std::string ipstr; 48 | int status,i,num; 49 | 50 | std::cout << "Using version " << RTPLibraryVersion::GetVersion().GetVersionString() << std::endl; 51 | 52 | // First, we'll ask for the necessary information 53 | 54 | std::cout << "Enter local portbase:" << std::endl; 55 | std::cin >> portbase; 56 | std::cout << std::endl; 57 | 58 | std::cout << "Enter the destination IP address" << std::endl; 59 | std::cin >> ipstr; 60 | destip = inet_addr(ipstr.c_str()); 61 | if (destip == INADDR_NONE) 62 | { 63 | std::cerr << "Bad IP address specified" << std::endl; 64 | return -1; 65 | } 66 | 67 | // The inet_addr function returns a value in network byte order, but 68 | // we need the IP address in host byte order, so we use a call to 69 | // ntohl 70 | destip = ntohl(destip); 71 | 72 | std::cout << "Enter the destination port" << std::endl; 73 | std::cin >> destport; 74 | 75 | std::cout << std::endl; 76 | std::cout << "Number of packets you wish to be sent:" << std::endl; 77 | std::cin >> num; 78 | 79 | // Now, we'll create a RTP session, set the destination, send some 80 | // packets and poll for incoming data. 81 | 82 | RTPUDPv4TransmissionParams transparams; 83 | RTPSessionParams sessparams; 84 | 85 | // IMPORTANT: The local timestamp unit MUST be set, otherwise 86 | // RTCP Sender Report info will be calculated wrong 87 | // In this case, we'll be sending 10 samples each second, so we'll 88 | // put the timestamp unit to (1.0/10.0) 89 | sessparams.SetOwnTimestampUnit(1.0/10.0); 90 | 91 | sessparams.SetAcceptOwnPackets(true); 92 | transparams.SetPortbase(portbase); 93 | status = sess.Create(sessparams,&transparams); 94 | checkerror(status); 95 | 96 | RTPIPv4Address addr(destip,destport); 97 | 98 | status = sess.AddDestination(addr); 99 | checkerror(status); 100 | 101 | for (i = 1 ; i <= num ; i++) 102 | { 103 | printf("\nSending packet %d/%d\n",i,num); 104 | 105 | // send the packet 106 | status = sess.SendPacket((void *)"1234567890",10,0,false,10); 107 | checkerror(status); 108 | 109 | sess.BeginDataAccess(); 110 | 111 | // check incoming packets 112 | if (sess.GotoFirstSourceWithData()) 113 | { 114 | do 115 | { 116 | RTPPacket *pack; 117 | 118 | while ((pack = sess.GetNextPacket()) != NULL) 119 | { 120 | // You can examine the data here 121 | printf("Got packet !\n"); 122 | 123 | // we don't longer need the packet, so 124 | // we'll delete it 125 | sess.DeletePacket(pack); 126 | } 127 | } while (sess.GotoNextSourceWithData()); 128 | } 129 | 130 | sess.EndDataAccess(); 131 | 132 | #ifndef RTP_SUPPORT_THREAD 133 | status = sess.Poll(); 134 | checkerror(status); 135 | #endif // RTP_SUPPORT_THREAD 136 | 137 | RTPTime::Wait(RTPTime(1,0)); 138 | } 139 | 140 | sess.BYEDestroy(RTPTime(10,0),0,0); 141 | 142 | #ifdef RTP_SOCKETTYPE_WINSOCK 143 | WSACleanup(); 144 | #endif // RTP_SOCKETTYPE_WINSOCK 145 | return 0; 146 | } 147 | 148 | -------------------------------------------------------------------------------- /src/rtcpsrpacket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtcpsrpacket.h" 34 | #ifdef RTPDEBUG 35 | #include 36 | #endif // RTPDEBUG 37 | 38 | #include "rtpdebug.h" 39 | 40 | namespace jrtplib 41 | { 42 | 43 | RTCPSRPacket::RTCPSRPacket(uint8_t *data,size_t datalength) 44 | : RTCPPacket(SR,data,datalength) 45 | { 46 | knownformat = false; 47 | 48 | RTCPCommonHeader *hdr; 49 | size_t len = datalength; 50 | size_t expectedlength; 51 | 52 | hdr = (RTCPCommonHeader *)data; 53 | if (hdr->padding) 54 | { 55 | uint8_t padcount = data[datalength-1]; 56 | if ((padcount & 0x03) != 0) // not a multiple of four! (see rfc 3550 p 37) 57 | return; 58 | if (((size_t)padcount) >= len) 59 | return; 60 | len -= (size_t)padcount; 61 | } 62 | 63 | expectedlength = sizeof(RTCPCommonHeader)+sizeof(uint32_t)+sizeof(RTCPSenderReport); 64 | expectedlength += sizeof(RTCPReceiverReport)*((int)hdr->count); 65 | 66 | if (expectedlength != len) 67 | return; 68 | 69 | knownformat = true; 70 | } 71 | 72 | #ifdef RTPDEBUG 73 | void RTCPSRPacket::Dump() 74 | { 75 | RTCPPacket::Dump(); 76 | if (!IsKnownFormat()) 77 | std::cout << " Unknown format" << std::endl; 78 | else 79 | { 80 | int num = GetReceptionReportCount(); 81 | int i; 82 | RTPNTPTime t = GetNTPTimestamp(); 83 | 84 | std::cout << " SSRC of sender: " << GetSenderSSRC() << std::endl; 85 | std::cout << " Sender info:" << std::endl; 86 | std::cout << " NTP timestamp: " << t.GetMSW() << ":" << t.GetLSW() << std::endl; 87 | std::cout << " RTP timestamp: " << GetRTPTimestamp() << std::endl; 88 | std::cout << " Packet count: " << GetSenderPacketCount() << std::endl; 89 | std::cout << " Octet count: " << GetSenderOctetCount() << std::endl; 90 | for (i = 0 ; i < num ; i++) 91 | { 92 | std::cout << " Report block " << i << std::endl; 93 | std::cout << " SSRC: " << GetSSRC(i) << std::endl; 94 | std::cout << " Fraction lost: " << (uint32_t)GetFractionLost(i) << std::endl; 95 | std::cout << " Packets lost: " << GetLostPacketCount(i) << std::endl; 96 | std::cout << " Seq. nr.: " << GetExtendedHighestSequenceNumber(i) << std::endl; 97 | std::cout << " Jitter: " << GetJitter(i) << std::endl; 98 | std::cout << " LSR: " << GetLSR(i) << std::endl; 99 | std::cout << " DLSR: " << GetDLSR(i) << std::endl; 100 | } 101 | } 102 | } 103 | #endif // RTPDEBUG 104 | 105 | } // end namespace 106 | 107 | -------------------------------------------------------------------------------- /src/rtpcollisionlist.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtpcollisionlist.h" 34 | #include "rtperrors.h" 35 | #include "rtpmemorymanager.h" 36 | #ifdef RTPDEBUG 37 | #include 38 | #endif // RTPDEBUG 39 | 40 | #include "rtpdebug.h" 41 | 42 | namespace jrtplib 43 | { 44 | 45 | RTPCollisionList::RTPCollisionList(RTPMemoryManager *mgr) : RTPMemoryObject(mgr) 46 | { 47 | timeinit.Dummy(); 48 | } 49 | 50 | void RTPCollisionList::Clear() 51 | { 52 | std::list::iterator it; 53 | 54 | for (it = addresslist.begin() ; it != addresslist.end() ; it++) 55 | RTPDelete((*it).addr,GetMemoryManager()); 56 | addresslist.clear(); 57 | } 58 | 59 | int RTPCollisionList::UpdateAddress(const RTPAddress *addr,const RTPTime &receivetime,bool *created) 60 | { 61 | if (addr == 0) 62 | return ERR_RTP_COLLISIONLIST_BADADDRESS; 63 | 64 | std::list::iterator it; 65 | 66 | for (it = addresslist.begin() ; it != addresslist.end() ; it++) 67 | { 68 | if (((*it).addr)->IsSameAddress(addr)) 69 | { 70 | (*it).recvtime = receivetime; 71 | *created = false; 72 | return 0; 73 | } 74 | } 75 | 76 | RTPAddress *newaddr = addr->CreateCopy(GetMemoryManager()); 77 | if (newaddr == 0) 78 | return ERR_RTP_OUTOFMEM; 79 | 80 | addresslist.push_back(AddressAndTime(newaddr,receivetime)); 81 | *created = true; 82 | return 0; 83 | } 84 | 85 | bool RTPCollisionList::HasAddress(const RTPAddress *addr) const 86 | { 87 | std::list::const_iterator it; 88 | 89 | for (it = addresslist.begin() ; it != addresslist.end() ; it++) 90 | { 91 | if (((*it).addr)->IsSameAddress(addr)) 92 | return true; 93 | } 94 | 95 | return false; 96 | } 97 | 98 | void RTPCollisionList::Timeout(const RTPTime ¤ttime,const RTPTime &timeoutdelay) 99 | { 100 | std::list::iterator it; 101 | RTPTime checktime = currenttime; 102 | checktime -= timeoutdelay; 103 | 104 | it = addresslist.begin(); 105 | while(it != addresslist.end()) 106 | { 107 | if ((*it).recvtime < checktime) // timeout 108 | { 109 | RTPDelete((*it).addr,GetMemoryManager()); 110 | it = addresslist.erase(it); 111 | } 112 | else 113 | it++; 114 | } 115 | } 116 | 117 | #ifdef RTPDEBUG 118 | void RTPCollisionList::Dump() 119 | { 120 | std::list::const_iterator it; 121 | 122 | for (it = addresslist.begin() ; it != addresslist.end() ; it++) 123 | std::cout << "Address: " << ((*it).addr)->GetAddressString() << "\tTime: " << (*it).recvtime.GetSeconds() << std::endl; 124 | } 125 | #endif // RTPDEBUG 126 | 127 | } // end namespace 128 | 129 | -------------------------------------------------------------------------------- /src/rtpsessionsources.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpsessionsources.h 35 | */ 36 | 37 | #ifndef RTPSESSIONSOURCES_H 38 | 39 | #define RTPSESSIONSOURCES_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtpsources.h" 43 | 44 | namespace jrtplib 45 | { 46 | 47 | class RTPSession; 48 | 49 | class JRTPLIB_IMPORTEXPORT RTPSessionSources : public RTPSources 50 | { 51 | public: 52 | RTPSessionSources(RTPSession &sess,RTPMemoryManager *mgr) : RTPSources(RTPSources::ProbationStore,mgr),rtpsession(sess) 53 | { owncollision = false; } 54 | ~RTPSessionSources() { } 55 | void ClearOwnCollisionFlag() { owncollision = false; } 56 | bool DetectedOwnCollision() const { return owncollision; } 57 | private: 58 | void OnRTPPacket(RTPPacket *pack,const RTPTime &receivetime, 59 | const RTPAddress *senderaddress); 60 | void OnRTCPCompoundPacket(RTCPCompoundPacket *pack,const RTPTime &receivetime, 61 | const RTPAddress *senderaddress); 62 | void OnSSRCCollision(RTPSourceData *srcdat,const RTPAddress *senderaddress,bool isrtp); 63 | void OnCNAMECollision(RTPSourceData *srcdat,const RTPAddress *senderaddress, 64 | const uint8_t *cname,size_t cnamelength); 65 | void OnNewSource(RTPSourceData *srcdat); 66 | void OnRemoveSource(RTPSourceData *srcdat); 67 | void OnTimeout(RTPSourceData *srcdat); 68 | void OnBYETimeout(RTPSourceData *srcdat); 69 | void OnBYEPacket(RTPSourceData *srcdat); 70 | void OnAPPPacket(RTCPAPPPacket *apppacket,const RTPTime &receivetime, 71 | const RTPAddress *senderaddress); 72 | void OnUnknownPacketType(RTCPPacket *rtcppack,const RTPTime &receivetime, 73 | const RTPAddress *senderaddress); 74 | void OnUnknownPacketFormat(RTCPPacket *rtcppack,const RTPTime &receivetime, 75 | const RTPAddress *senderaddress); 76 | void OnNoteTimeout(RTPSourceData *srcdat); 77 | void OnValidatedRTPPacket(RTPSourceData *srcdat, RTPPacket *rtppack, bool isonprobation, bool *ispackethandled); 78 | void OnRTCPSenderReport(RTPSourceData *srcdat); 79 | void OnRTCPReceiverReport(RTPSourceData *srcdat); 80 | void OnRTCPSDESItem(RTPSourceData *srcdat, RTCPSDESPacket::ItemType t, 81 | const void *itemdata, size_t itemlength); 82 | #ifdef RTP_SUPPORT_SDESPRIV 83 | void OnRTCPSDESPrivateItem(RTPSourceData *srcdat, const void *prefixdata, size_t prefixlen, 84 | const void *valuedata, size_t valuelen); 85 | #endif // RTP_SUPPORT_SDESPRIV 86 | 87 | RTPSession &rtpsession; 88 | bool owncollision; 89 | }; 90 | 91 | } // end namespace 92 | 93 | #endif // RTPSESSIONSOURCES_H 94 | -------------------------------------------------------------------------------- /src/rtpipv4destination.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpipv4destination.h 35 | */ 36 | 37 | #ifndef RTPIPV4DESTINATION_H 38 | 39 | #define RTPIPV4DESTINATION_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtptypes.h" 43 | #include "rtpipv4address.h" 44 | #ifndef RTP_SOCKETTYPE_WINSOCK 45 | #include 46 | #include 47 | #include 48 | #endif // RTP_SOCKETTYPE_WINSOCK 49 | #include 50 | #include 51 | 52 | namespace jrtplib 53 | { 54 | 55 | class JRTPLIB_IMPORTEXPORT RTPIPv4Destination 56 | { 57 | public: 58 | RTPIPv4Destination() 59 | { 60 | ip = 0; 61 | memset(&rtpaddr,0,sizeof(struct sockaddr_in)); 62 | memset(&rtcpaddr,0,sizeof(struct sockaddr_in)); 63 | } 64 | 65 | RTPIPv4Destination(uint32_t ip,uint16_t rtpport,uint16_t rtcpport) 66 | { 67 | memset(&rtpaddr,0,sizeof(struct sockaddr_in)); 68 | memset(&rtcpaddr,0,sizeof(struct sockaddr_in)); 69 | 70 | rtpaddr.sin_family = AF_INET; 71 | rtpaddr.sin_port = htons(rtpport); 72 | rtpaddr.sin_addr.s_addr = htonl(ip); 73 | 74 | rtcpaddr.sin_family = AF_INET; 75 | rtcpaddr.sin_port = htons(rtcpport); 76 | rtcpaddr.sin_addr.s_addr = htonl(ip); 77 | 78 | RTPIPv4Destination::ip = ip; 79 | } 80 | 81 | bool operator==(const RTPIPv4Destination &src) const 82 | { 83 | if (rtpaddr.sin_addr.s_addr == src.rtpaddr.sin_addr.s_addr && rtpaddr.sin_port == src.rtpaddr.sin_port) 84 | return true; 85 | return false; 86 | } 87 | uint32_t GetIP() const { return ip; } 88 | // nbo = network byte order 89 | uint32_t GetIP_NBO() const { return rtpaddr.sin_addr.s_addr; } 90 | uint16_t GetRTPPort_NBO() const { return rtpaddr.sin_port; } 91 | uint16_t GetRTCPPort_NBO() const { return rtcpaddr.sin_port; } 92 | const struct sockaddr_in *GetRTPSockAddr() const { return &rtpaddr; } 93 | const struct sockaddr_in *GetRTCPSockAddr() const { return &rtcpaddr; } 94 | std::string GetDestinationString() const; 95 | 96 | static bool AddressToDestination(const RTPAddress &addr, RTPIPv4Destination &dest) 97 | { 98 | if (addr.GetAddressType() != RTPAddress::IPv4Address) 99 | return false; 100 | 101 | const RTPIPv4Address &address = (const RTPIPv4Address &)addr; 102 | uint16_t rtpport = address.GetPort(); 103 | uint16_t rtcpport = address.GetRTCPSendPort(); 104 | 105 | dest = RTPIPv4Destination(address.GetIP(),rtpport,rtcpport); 106 | return true; 107 | } 108 | 109 | private: 110 | uint32_t ip; 111 | struct sockaddr_in rtpaddr; 112 | struct sockaddr_in rtcpaddr; 113 | }; 114 | 115 | } // end namespace 116 | 117 | #endif // RTPIPV4DESTINATION_H 118 | 119 | -------------------------------------------------------------------------------- /src/rtpabortdescriptors.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpabortdescriptors.h 35 | */ 36 | 37 | #ifndef RTPABORTDESCRIPTORS_H 38 | 39 | #define RTPABORTDESCRIPTORS_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtpsocketutil.h" 43 | 44 | namespace jrtplib 45 | { 46 | 47 | /** 48 | * Helper class for several RTPTransmitter instances, to be able to cancel a 49 | * call to 'select', 'poll' or 'WSAPoll'. 50 | * 51 | * This is a helper class for several RTPTransmitter instances. Typically a 52 | * call to 'select' (or 'poll' or 'WSAPoll', depending on the platform) is used 53 | * to wait for incoming data for a certain time. To be able to cancel this wait 54 | * from another thread, this class provides a socket descriptor that's compatible 55 | * with e.g. the 'select' call, and to which data can be sent using 56 | * RTPAbortDescriptors::SendAbortSignal. If the descriptor is included in the 57 | * 'select' call, the function will detect incoming data and the function stops 58 | * waiting for incoming data. 59 | * 60 | * The class can be useful in case you'd like to create an implementation which 61 | * uses a single poll thread for several RTPSession and RTPTransmitter instances. 62 | * This idea is further illustrated in `example8.cpp`. 63 | */ 64 | class JRTPLIB_IMPORTEXPORT RTPAbortDescriptors 65 | { 66 | public: 67 | RTPAbortDescriptors(); 68 | ~RTPAbortDescriptors(); 69 | 70 | /** Initializes this instance. */ 71 | int Init(); 72 | 73 | /** Returns the socket descriptor that can be included in a call to 74 | * 'select' (for example).*/ 75 | SocketType GetAbortSocket() const { return m_descriptors[0]; } 76 | 77 | /** Returns a flag indicating if this instance was initialized. */ 78 | bool IsInitialized() const { return m_init; } 79 | 80 | /** De-initializes this instance. */ 81 | void Destroy(); 82 | 83 | /** Send a signal to the socket that's returned by RTPAbortDescriptors::GetAbortSocket, 84 | * causing the 'select' call to detect that data is available, making the call 85 | * end. */ 86 | int SendAbortSignal(); 87 | 88 | /** For each RTPAbortDescriptors::SendAbortSignal function that's called, a call 89 | * to this function can be made to clear the state again. */ 90 | int ReadSignallingByte(); 91 | 92 | /** Similar to ReadSignallingByte::ReadSignallingByte, this function clears the signalling 93 | * state, but this also works independently from the amount of times that 94 | * RTPAbortDescriptors::SendAbortSignal was called. */ 95 | int ClearAbortSignal(); 96 | private: 97 | SocketType m_descriptors[2]; 98 | bool m_init; 99 | }; 100 | 101 | } // end namespace 102 | 103 | #endif // RTPABORTDESCRIPTORS_H 104 | -------------------------------------------------------------------------------- /src/rtcpapppacket.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtcpapppacket.h 35 | */ 36 | 37 | #ifndef RTCPAPPPACKET_H 38 | 39 | #define RTCPAPPPACKET_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtcppacket.h" 43 | #include "rtpstructs.h" 44 | #ifdef RTP_SUPPORT_NETINET_IN 45 | #include 46 | #endif // RTP_SUPPORT_NETINET_IN 47 | 48 | namespace jrtplib 49 | { 50 | 51 | class RTCPCompoundPacket; 52 | 53 | /** Describes an RTCP APP packet. */ 54 | class JRTPLIB_IMPORTEXPORT RTCPAPPPacket : public RTCPPacket 55 | { 56 | public: 57 | /** Creates an instance based on the data in \c data with length \c datalen. 58 | * Creates an instance based on the data in \c data with length \c datalen. Since the \c data pointer 59 | * is referenced inside the class (no copy of the data is made) one must make sure that the memory it 60 | * points to is valid as long as the class instance exists. 61 | */ 62 | RTCPAPPPacket(uint8_t *data,size_t datalen); 63 | ~RTCPAPPPacket() { } 64 | 65 | /** Returns the subtype contained in the APP packet. */ 66 | uint8_t GetSubType() const; 67 | 68 | /** Returns the SSRC of the source which sent this packet. */ 69 | uint32_t GetSSRC() const; 70 | 71 | /** Returns the name contained in the APP packet. 72 | * Returns the name contained in the APP packet. This alway consists of four bytes and is not NULL-terminated. 73 | */ 74 | uint8_t *GetName(); 75 | 76 | /** Returns a pointer to the actual data. */ 77 | uint8_t *GetAPPData(); 78 | 79 | /** Returns the length of the actual data. */ 80 | size_t GetAPPDataLength() const; 81 | #ifdef RTPDEBUG 82 | void Dump(); 83 | #endif // RTPDEBUG 84 | private: 85 | size_t appdatalen; 86 | }; 87 | 88 | inline uint8_t RTCPAPPPacket::GetSubType() const 89 | { 90 | if (!knownformat) 91 | return 0; 92 | RTCPCommonHeader *hdr = (RTCPCommonHeader *)data; 93 | return hdr->count; 94 | } 95 | 96 | inline uint32_t RTCPAPPPacket::GetSSRC() const 97 | { 98 | if (!knownformat) 99 | return 0; 100 | 101 | uint32_t *ssrc = (uint32_t *)(data+sizeof(RTCPCommonHeader)); 102 | return ntohl(*ssrc); 103 | } 104 | 105 | inline uint8_t *RTCPAPPPacket::GetName() 106 | { 107 | if (!knownformat) 108 | return 0; 109 | 110 | return (data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)); 111 | } 112 | 113 | inline uint8_t *RTCPAPPPacket::GetAPPData() 114 | { 115 | if (!knownformat) 116 | return 0; 117 | if (appdatalen == 0) 118 | return 0; 119 | return (data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)*2); 120 | } 121 | 122 | inline size_t RTCPAPPPacket::GetAPPDataLength() const 123 | { 124 | if (!knownformat) 125 | return 0; 126 | return appdatalen; 127 | } 128 | 129 | } // end namespace 130 | 131 | #endif // RTCPAPPPACKET_H 132 | 133 | -------------------------------------------------------------------------------- /tests/abortdesctest.cpp: -------------------------------------------------------------------------------- 1 | #include "rtpconfig.h" 2 | #include "rtpabortdescriptors.h" 3 | #include "rtperrors.h" 4 | #include "rtpsocketutilinternal.h" 5 | #include "rtptimeutilities.h" 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | using namespace jrtplib; 11 | 12 | #ifdef RTP_SUPPORT_THREAD 13 | 14 | #include 15 | 16 | using namespace jthread; 17 | 18 | void checkError(int status) 19 | { 20 | if (status >= 0) 21 | return; 22 | 23 | cerr << "ERROR: " << RTPGetErrorString(status) << endl; 24 | exit(-1); 25 | } 26 | 27 | class SignalThread : public JThread 28 | { 29 | public: 30 | SignalThread(RTPAbortDescriptors &a, double delay, int sigCount) : m_ad(a), m_delay(delay), m_sigCount(sigCount) 31 | { 32 | } 33 | 34 | ~SignalThread() 35 | { 36 | while (IsRunning()) 37 | { 38 | cout << "Waiting for thread to finish" << endl; 39 | RTPTime::Wait(RTPTime(1.0)); 40 | } 41 | } 42 | private: 43 | void *Thread() 44 | { 45 | JThread::ThreadStarted(); 46 | 47 | cout << "Thread started, waiting " << m_delay << " seconds before sending abort signal" << endl; 48 | RTPTime::Wait(RTPTime(m_delay)); 49 | cout << "Sending " << m_sigCount << " abort signals" << endl; 50 | for (int i = 0 ; i < m_sigCount ; i++) 51 | m_ad.SendAbortSignal(); 52 | 53 | cout << "Thread finished" << endl; 54 | return 0; 55 | } 56 | 57 | RTPAbortDescriptors &m_ad; 58 | const double m_delay; 59 | const int m_sigCount; 60 | }; 61 | 62 | void test1() 63 | { 64 | RTPAbortDescriptors ad; 65 | SignalThread st(ad, 5, 1); 66 | 67 | st.Start(); 68 | checkError(ad.Init()); 69 | 70 | fd_set fdset; 71 | FD_ZERO(&fdset); 72 | FD_SET(ad.GetAbortSocket(), &fdset); 73 | 74 | if (select(FD_SETSIZE, &fdset, 0, 0, 0) < 0) 75 | { 76 | cerr << "Error in select" << endl; 77 | exit(-1); 78 | } 79 | 80 | cout << "Checking if select keeps triggering" << endl; 81 | int count = 0; 82 | RTPTime start = RTPTime::CurrentTime(); 83 | while (count < 5) 84 | { 85 | count++; 86 | struct timeval tv = { 1, 0 }; 87 | if (select(FD_SETSIZE, &fdset, 0, 0, &tv) < 0) 88 | { 89 | cerr << "Error in select" << endl; 90 | exit(-1); 91 | } 92 | } 93 | RTPTime delay = RTPTime::CurrentTime(); 94 | delay -= start; 95 | 96 | cout << "Elapsed time is " << delay.GetDouble(); 97 | if (delay.GetDouble() < 1.0) 98 | cout << ", seems OK" << endl; 99 | else 100 | cout << ", TAKES TOO LONG!" << endl; 101 | } 102 | 103 | void test2() 104 | { 105 | RTPAbortDescriptors ad; 106 | SignalThread st(ad, 5, 5); 107 | 108 | st.Start(); 109 | checkError(ad.Init()); 110 | 111 | fd_set fdset; 112 | FD_ZERO(&fdset); 113 | FD_SET(ad.GetAbortSocket(), &fdset); 114 | 115 | if (select(FD_SETSIZE, &fdset, 0, 0, 0) < 0) 116 | { 117 | cerr << "Error in select" << endl; 118 | exit(-1); 119 | } 120 | cout << "Reading one signalling byte, should continue immediately since we've sent multiple signals" << endl; 121 | ad.ReadSignallingByte(); 122 | if (select(FD_SETSIZE, &fdset, 0, 0, 0) < 0) 123 | { 124 | cerr << "Error in select" << endl; 125 | exit(-1); 126 | } 127 | 128 | cout << "Clearing abort signals" << endl; 129 | ad.ClearAbortSignal(); 130 | 131 | cout << "Waiting for signal, should timeout after one second since we've cleared the signal buffers" << endl; 132 | struct timeval tv = { 1, 0 }; 133 | RTPTime start = RTPTime::CurrentTime(); 134 | if (select(FD_SETSIZE, &fdset, 0, 0, &tv) < 0) 135 | { 136 | cerr << "Error in select" << endl; 137 | exit(-1); 138 | } 139 | RTPTime delay = RTPTime::CurrentTime(); 140 | delay -= start; 141 | 142 | cout << "Elapsed time is " << delay.GetDouble(); 143 | if (delay.GetDouble() < 1.0) 144 | cout << ", BUFFER NOT CLEARED?" << endl; 145 | else 146 | cout << ", seems OK" << endl; 147 | } 148 | 149 | int main(void) 150 | { 151 | #ifdef RTP_SOCKETTYPE_WINSOCK 152 | WSADATA dat; 153 | WSAStartup(MAKEWORD(2, 2), &dat); 154 | #endif // RTP_SOCKETTYPE_WINSOCK 155 | 156 | test1(); 157 | test2(); 158 | 159 | #ifdef RTP_SOCKETTYPE_WINSOCK 160 | WSACleanup(); 161 | #endif // RTP_SOCKETTYPE_WINSOCK 162 | return 0; 163 | } 164 | 165 | #else 166 | 167 | int main(void) 168 | { 169 | cerr << "Thread support is needed for this example" << endl; 170 | return 0; 171 | } 172 | 173 | #endif // RTP_SUPPORT_THREAD 174 | 175 | -------------------------------------------------------------------------------- /cmake/Macros.cmake: -------------------------------------------------------------------------------- 1 | macro(jrtplib_support_option DESCRIPTION OPTIONNAME DEFINENAME DEFAULTVALUE EMPTYVALUE) 2 | option(${OPTIONNAME} ${DESCRIPTION} ${DEFAULTVALUE}) 3 | if (${OPTIONNAME}) 4 | set(${DEFINENAME} "#define ${DEFINENAME}") 5 | else (${OPTIONNAME}) 6 | set(${DEFINENAME} "${EMPTYVALUE}") 7 | endif (${OPTIONNAME}) 8 | endmacro(jrtplib_support_option) 9 | 10 | macro(jrtplib_include_test INCFILE DEFINENAME EMPTYVALUE) 11 | check_include_file_cxx(${INCFILE} jrtplib_include_test_${DEFINENAME}) 12 | if (jrtplib_include_test_${DEFINENAME}) 13 | set(${DEFINENAME} "#define ${DEFINENAME}") 14 | else (jrtplib_include_test_${DEFINENAME}) 15 | set(${DEFINENAME} "${EMPTYVALUE}") 16 | endif (jrtplib_include_test_${DEFINENAME}) 17 | endmacro(jrtplib_include_test) 18 | 19 | macro (jrtplib_test_feature FILENAME DEFINENAME INVERT EMPTYVALUE EXTRADEFS) 20 | if (NOT DEFINED ${FILENAME}_RESULT) 21 | try_compile(${FILENAME}_RESULT "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tools/${FILENAME}.cpp" 22 | OUTPUT_VARIABLE OUTVAR 23 | COMPILE_DEFINITIONS "${EXTRADEFS}") 24 | message(STATUS "Compiling ${FILENAME}.cpp") 25 | set(BLA ${INVERT}) 26 | if (NOT BLA) 27 | if (${FILENAME}_RESULT) 28 | set(${DEFINENAME} "#define ${DEFINENAME}" CACHE INTERNAL "setting ${DEFINENAME} in rtpconfig.h") 29 | message(STATUS "Compiling ${FILENAME}.cpp worked - setting ${DEFINENAME} in rtpconfig.h") 30 | else (${FILENAME}_RESULT) 31 | set(${DEFINENAME} "${EMPTYVALUE}" CACHE INTERNAL "") 32 | message(STATUS "Compiling ${FILENAME}.cpp failed - no action necessary") 33 | endif (${FILENAME}_RESULT) 34 | else (NOT BLA) 35 | if (NOT ${FILENAME}_RESULT) 36 | set(${DEFINENAME} "#define ${DEFINENAME}" CACHE INTERNAL "setting ${DEFINENAME} in rtpconfig.h") 37 | message(STATUS "Compiling ${FILENAME}.cpp failed - setting ${DEFINENAME} in rtpconfig.h") 38 | else (NOT ${FILENAME}_RESULT) 39 | set(${DEFINENAME} "${EMPTYVALUE}" CACHE INTERNAL "") 40 | message(STATUS "Compiling ${FILENAME}.cpp worked - no action necessary") 41 | endif (NOT ${FILENAME}_RESULT) 42 | endif (NOT BLA) 43 | endif (NOT DEFINED ${FILENAME}_RESULT) 44 | endmacro (jrtplib_test_feature) 45 | 46 | macro(save_paths VARNAME) 47 | set (BLA "${ARGN}") 48 | foreach(i IN LISTS BLA) 49 | set (BLA2 "${i}") 50 | if (BLA2) 51 | list(APPEND ${VARNAME} "${i}") 52 | endif (BLA2) 53 | endforeach(i) 54 | list(LENGTH ${VARNAME} BLA) 55 | if (BLA GREATER 0) 56 | list(REMOVE_DUPLICATES ${VARNAME}) 57 | endif (BLA GREATER 0) 58 | endmacro(save_paths) 59 | 60 | macro(remove_empty VARNAME) 61 | set (remove_empty_NEWLIST "") 62 | foreach(i IN LISTS ${VARNAME}) 63 | set (BLA2 "${i}") 64 | if (BLA2) 65 | list(APPEND remove_empty_NEWLIST "${i}") 66 | endif (BLA2) 67 | endforeach(i) 68 | set(${VARNAME} "${remove_empty_NEWLIST}") 69 | endmacro(remove_empty) 70 | 71 | macro(apply_include_paths VARNAME) 72 | set (BLA "${VARNAME}") 73 | foreach(i IN LISTS BLA) 74 | set (BLA2 "${i}") 75 | if (BLA2) 76 | include_directories("${i}") 77 | endif (BLA2) 78 | endforeach(i) 79 | endmacro(apply_include_paths) 80 | 81 | macro(add_additional_stuff INCVAR LIBVAR) 82 | set(ADDITIONAL_INCLUDE_DIRS "" CACHE STRING "Additional include directories") 83 | if (UNIX AND NOT WIN32) 84 | set(ADDITIONAL_LIBRARIES "" CACHE STRING "Additional libraries to link against") 85 | else (UNIX AND NOT WIN32) 86 | set(ADDITIONAL_GENERAL_LIBRARIES "" CACHE STRING "Additional libraries to link against in both debug and release modes") 87 | set(ADDITIONAL_RELEASE_LIBRARIES "" CACHE STRING "Additional libraries to link against in release mode") 88 | set(ADDITIONAL_DEBUG_LIBRARIES "" CACHE STRING "Additional libraries to link against in debug mode") 89 | 90 | set(ADDITIONAL_LIBRARIES "${ADDITIONAL_GENERAL_LIBRARIES}") 91 | 92 | foreach(l IN LISTS ADDITIONAL_RELEASE_LIBRARIES) 93 | list(APPEND ADDITIONAL_LIBRARIES optimized) 94 | list(APPEND ADDITIONAL_LIBRARIES "${l}") 95 | endforeach(l) 96 | foreach(l IN LISTS ADDITIONAL_DEBUG_LIBRARIES) 97 | list(APPEND ADDITIONAL_LIBRARIES debug) 98 | list(APPEND ADDITIONAL_LIBRARIES "${l}") 99 | endforeach(l) 100 | endif (UNIX AND NOT WIN32) 101 | 102 | save_paths(${INCVAR} "${ADDITIONAL_INCLUDE_DIRS}") 103 | save_paths(${LIBVAR} "${ADDITIONAL_LIBRARIES}") 104 | endmacro(add_additional_stuff) 105 | 106 | -------------------------------------------------------------------------------- /tests/testexistingsockets.cpp: -------------------------------------------------------------------------------- 1 | #include "rtpsession.h" 2 | #include "rtpudpv4transmitter.h" 3 | #include "rtpipv4address.h" 4 | #include "rtpsessionparams.h" 5 | #include "rtperrors.h" 6 | #include "rtplibraryversion.h" 7 | #include "rtpsourcedata.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace jrtplib; 14 | 15 | void checkerror(int rtperr) 16 | { 17 | if (rtperr < 0) 18 | { 19 | std::cout << "ERROR: " << RTPGetErrorString(rtperr) << std::endl; 20 | exit(-1); 21 | } 22 | } 23 | 24 | class MyRTPSession : public RTPSession 25 | { 26 | protected: 27 | void OnValidatedRTPPacket(RTPSourceData *srcdat, RTPPacket *rtppack, bool isonprobation, bool *ispackethandled) 28 | { 29 | printf("Got packet in OnValidatedRTPPacket from source 0x%04x!\n", srcdat->GetSSRC()); 30 | DeletePacket(rtppack); 31 | *ispackethandled = true; 32 | } 33 | 34 | void OnRTCPSDESItem(RTPSourceData *srcdat, RTCPSDESPacket::ItemType t, const void *itemdata, size_t itemlength) 35 | { 36 | char msg[1024]; 37 | 38 | memset(msg, 0, sizeof(msg)); 39 | if (itemlength >= sizeof(msg)) 40 | itemlength = sizeof(msg)-1; 41 | 42 | memcpy(msg, itemdata, itemlength); 43 | printf("Received SDES item (%d): %s", (int)t, msg); 44 | } 45 | }; 46 | 47 | int GetASocket() 48 | { 49 | SocketType sock = socket(AF_INET, SOCK_DGRAM, 0); 50 | //int sock = socket(AF_INET, SOCK_STREAM, 0); // test with a TCP socket 51 | struct sockaddr_in addr; 52 | 53 | memset(&addr, 0, sizeof(addr)); 54 | addr.sin_family = AF_INET; 55 | bind(sock, (struct sockaddr*)&addr, sizeof(addr)); 56 | 57 | return sock; 58 | } 59 | 60 | 61 | int main(void) 62 | { 63 | #ifdef RTP_SOCKETTYPE_WINSOCK 64 | WSADATA dat; 65 | WSAStartup(MAKEWORD(2,2),&dat); 66 | #endif // RTP_SOCKETTYPE_WINSOCK 67 | 68 | MyRTPSession sess; 69 | uint32_t destip; 70 | std::string ipstr; 71 | int status,i,num; 72 | 73 | std::cout << "Using version " << RTPLibraryVersion::GetVersion().GetVersionString() << std::endl; 74 | 75 | // First, we'll ask for the necessary information 76 | 77 | ipstr = "127.0.0.1"; 78 | destip = inet_addr(ipstr.c_str()); 79 | if (destip == INADDR_NONE) 80 | { 81 | std::cerr << "Bad IP address specified" << std::endl; 82 | return -1; 83 | } 84 | 85 | // The inet_addr function returns a value in network byte order, but 86 | // we need the IP address in host byte order, so we use a call to 87 | // ntohl 88 | destip = ntohl(destip); 89 | num = 10; 90 | 91 | // Now, we'll create a RTP session, set the destination, send some 92 | // packets and poll for incoming data. 93 | 94 | RTPUDPv4TransmissionParams transparams; 95 | RTPSessionParams sessparams; 96 | 97 | // IMPORTANT: The local timestamp unit MUST be set, otherwise 98 | // RTCP Sender Report info will be calculated wrong 99 | // In this case, we'll be sending 10 samples each second, so we'll 100 | // put the timestamp unit to (1.0/10.0) 101 | sessparams.SetOwnTimestampUnit(1.0/10.0); 102 | sessparams.SetAcceptOwnPackets(true); 103 | 104 | int rtpsock = GetASocket(); 105 | //int rtcpsock = rtpsock; 106 | int rtcpsock = GetASocket(); 107 | transparams.SetUseExistingSockets(rtpsock, rtcpsock); 108 | 109 | status = sess.Create(sessparams,&transparams); 110 | checkerror(status); 111 | 112 | RTPUDPv4TransmissionInfo *pInf = (RTPUDPv4TransmissionInfo *)sess.GetTransmissionInfo(); 113 | uint16_t rtpPort = pInf->GetRTPPort(); 114 | uint16_t rtcpPort = pInf->GetRTCPPort(); 115 | 116 | printf("Using RTP port %d and RTCP port %d\n", (int)rtpPort, (int)rtcpPort); 117 | 118 | // We're assuming that the destination is also using RTCP multiplexing 119 | // ('true' means that the same port will be used for RTCP) 120 | RTPIPv4Address addr(destip,rtpPort,rtcpPort); 121 | 122 | status = sess.AddDestination(addr); 123 | checkerror(status); 124 | 125 | for (i = 1 ; i <= num ; i++) 126 | { 127 | printf("\nSending packet %d/%d\n",i,num); 128 | 129 | // send the packet 130 | status = sess.SendPacket((void *)"1234567890",10,0,false,10); 131 | checkerror(status); 132 | 133 | #ifndef RTP_SUPPORT_THREAD 134 | status = sess.Poll(); 135 | checkerror(status); 136 | #endif // RTP_SUPPORT_THREAD 137 | 138 | RTPTime::Wait(RTPTime(1,0)); 139 | } 140 | 141 | sess.BYEDestroy(RTPTime(10,0),0,0); 142 | 143 | #ifdef RTP_SOCKETTYPE_WINSOCK 144 | WSACleanup(); 145 | #endif // RTP_SOCKETTYPE_WINSOCK 146 | return 0; 147 | } 148 | 149 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_definitions(-DJRTPLIB_COMPILING) 2 | 3 | set (HEADERS 4 | rtcpapppacket.h 5 | rtcpbyepacket.h 6 | rtcpcompoundpacket.h 7 | rtcpcompoundpacketbuilder.h 8 | rtcppacket.h 9 | rtcppacketbuilder.h 10 | rtcprrpacket.h 11 | rtcpscheduler.h 12 | rtcpsdesinfo.h 13 | rtcpsdespacket.h 14 | rtcpsrpacket.h 15 | rtcpunknownpacket.h 16 | rtpaddress.h 17 | rtpcollisionlist.h 18 | ${PROJECT_BINARY_DIR}/src/rtpconfig.h 19 | rtpdebug.h 20 | rtpdefines.h 21 | rtperrors.h 22 | rtphashtable.h 23 | rtpinternalsourcedata.h 24 | rtpipv4address.h 25 | rtpipv4destination.h 26 | rtpipv6address.h 27 | rtpipv6destination.h 28 | rtpkeyhashtable.h 29 | rtplibraryversion.h 30 | rtpmemorymanager.h 31 | rtpmemoryobject.h 32 | rtppacket.h 33 | rtppacketbuilder.h 34 | rtppollthread.h 35 | rtprandom.h 36 | rtprandomrand48.h 37 | rtprandomrands.h 38 | rtprandomurandom.h 39 | rtprawpacket.h 40 | rtpsession.h 41 | rtpsessionparams.h 42 | rtpsessionsources.h 43 | rtpsourcedata.h 44 | rtpsources.h 45 | rtpstructs.h 46 | rtptimeutilities.h 47 | rtptransmitter.h 48 | rtptypes_win.h 49 | ${PROJECT_BINARY_DIR}/src/rtptypes.h 50 | rtpudpv4transmitter.h 51 | rtpudpv6transmitter.h 52 | rtpbyteaddress.h 53 | rtpexternaltransmitter.h 54 | rtpsecuresession.h 55 | rtpsocketutil.h 56 | rtpabortdescriptors.h 57 | rtpselect.h 58 | rtptcpaddress.h 59 | rtptcptransmitter.h 60 | ) 61 | 62 | set(SOURCES 63 | rtcpapppacket.cpp 64 | rtcpbyepacket.cpp 65 | rtcpcompoundpacket.cpp 66 | rtcpcompoundpacketbuilder.cpp 67 | rtcppacket.cpp 68 | rtcppacketbuilder.cpp 69 | rtcprrpacket.cpp 70 | rtcpscheduler.cpp 71 | rtcpsdesinfo.cpp 72 | rtcpsdespacket.cpp 73 | rtcpsrpacket.cpp 74 | rtpcollisionlist.cpp 75 | rtpdebug.cpp 76 | rtperrors.cpp 77 | rtpinternalsourcedata.cpp 78 | rtpipv4address.cpp 79 | rtpipv6address.cpp 80 | rtpipv4destination.cpp 81 | rtpipv6destination.cpp 82 | rtplibraryversion.cpp 83 | rtppacket.cpp 84 | rtppacketbuilder.cpp 85 | rtppollthread.cpp 86 | rtprandom.cpp 87 | rtprandomrand48.cpp 88 | rtprandomrands.cpp 89 | rtprandomurandom.cpp 90 | rtpsession.cpp 91 | rtpsessionparams.cpp 92 | rtpsessionsources.cpp 93 | rtpsourcedata.cpp 94 | rtpsources.cpp 95 | rtptimeutilities.cpp 96 | rtpudpv4transmitter.cpp 97 | rtpudpv6transmitter.cpp 98 | rtpbyteaddress.cpp 99 | rtpexternaltransmitter.cpp 100 | rtpsecuresession.cpp 101 | rtpabortdescriptors.cpp 102 | rtptcpaddress.cpp 103 | rtptcptransmitter.cpp 104 | ) 105 | 106 | if (NOT JRTPLIB_WINSOCK) 107 | set (SOURCES ${SOURCES} extratransmitters/rtpfaketransmitter.cpp ) 108 | set (HEADERS ${HEADERS} extratransmitters/rtpfaketransmitter.h ) 109 | endif () 110 | 111 | if (MSVC) 112 | set(CMAKE_DEBUG_POSTFIX _d) 113 | endif () 114 | 115 | # Enable extra compiler warnings and mark warnings as errors: -Wall -Wextra -Werror 116 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC) 117 | option(JRTPLIB_WARNINGSASERRORS "Enable -Wall -Wextra -Werror" ON) 118 | if (JRTPLIB_WARNINGSASERRORS) 119 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") 120 | endif () 121 | endif(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC) 122 | 123 | if (NOT MSVC OR JRTPLIB_COMPILE_STATIC) 124 | add_library(jrtplib-static STATIC ${SOURCES} ${HEADERS}) 125 | if (NOT MSVC) 126 | set_target_properties(jrtplib-static PROPERTIES OUTPUT_NAME jrtp) 127 | else () 128 | set_target_properties(jrtplib-static PROPERTIES OUTPUT_NAME jrtplib) 129 | endif() 130 | set_target_properties(jrtplib-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) 131 | set(JRTPLIB_INSTALLTARGETS jrtplib-static) 132 | target_link_libraries(jrtplib-static ${JRTPLIB_LINK_LIBS}) 133 | endif (NOT MSVC OR JRTPLIB_COMPILE_STATIC) 134 | 135 | if (NOT MSVC OR NOT JRTPLIB_COMPILE_STATIC) 136 | add_library(jrtplib-shared SHARED ${SOURCES} ${HEADERS}) 137 | if (NOT MSVC) 138 | set_target_properties(jrtplib-shared PROPERTIES OUTPUT_NAME jrtp) 139 | else () 140 | set_target_properties(jrtplib-shared PROPERTIES OUTPUT_NAME jrtplib) 141 | endif() 142 | set_target_properties(jrtplib-shared PROPERTIES VERSION ${VERSION}) 143 | set_target_properties(jrtplib-shared PROPERTIES CLEAN_DIRECT_OUTPUT 1) 144 | set(JRTPLIB_INSTALLTARGETS ${JRTPLIB_INSTALLTARGETS} jrtplib-shared) 145 | target_link_libraries(jrtplib-shared ${JRTPLIB_LINK_LIBS}) 146 | endif (NOT MSVC OR NOT JRTPLIB_COMPILE_STATIC) 147 | 148 | apply_include_paths("${JRTPLIB_INTERNAL_INCLUDES}") 149 | apply_include_paths("${JRTPLIB_EXTERNAL_INCLUDES}") 150 | 151 | install(FILES ${HEADERS} DESTINATION include/jrtplib3) 152 | install(TARGETS ${JRTPLIB_INSTALLTARGETS} DESTINATION ${LIBRARY_INSTALL_DIR}) 153 | 154 | -------------------------------------------------------------------------------- /src/rtcpcompoundpacket.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtcpcompoundpacket.h 35 | */ 36 | 37 | #ifndef RTCPCOMPOUNDPACKET_H 38 | 39 | #define RTCPCOMPOUNDPACKET_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtptypes.h" 43 | #include "rtpmemoryobject.h" 44 | #include 45 | 46 | namespace jrtplib 47 | { 48 | 49 | class RTPRawPacket; 50 | class RTCPPacket; 51 | 52 | /** Represents an RTCP compound packet. */ 53 | class JRTPLIB_IMPORTEXPORT RTCPCompoundPacket : public RTPMemoryObject 54 | { 55 | public: 56 | /** Creates an RTCPCompoundPacket instance from the data in \c rawpack, installing a memory manager if specified. */ 57 | RTCPCompoundPacket(RTPRawPacket &rawpack, RTPMemoryManager *memmgr = 0); 58 | 59 | /** Creates an RTCPCompoundPacket instance from the data in \c packet}, with size \c len. 60 | * Creates an RTCPCompoundPacket instance from the data in \c packet}, with size \c len. The \c deletedata 61 | * flag specifies if the data in \c packet should be deleted when the compound packet is destroyed. If 62 | * specified, a memory manager will be installed. 63 | */ 64 | RTCPCompoundPacket(uint8_t *packet, size_t len, bool deletedata = true, RTPMemoryManager *memmgr = 0); 65 | protected: 66 | RTCPCompoundPacket(RTPMemoryManager *memmgr); // this is for the compoundpacket builder 67 | public: 68 | virtual ~RTCPCompoundPacket(); 69 | 70 | /** Checks if the RTCP compound packet was created successfully. 71 | * If the raw packet data in the constructor could not be parsed, this function returns the error code of 72 | * what went wrong. If the packet had an invalid format, the return value is \c ERR_RTP_RTCPCOMPOUND_INVALIDPACKET. 73 | */ 74 | int GetCreationError() { return error; } 75 | 76 | /** Returns a pointer to the data of the entire RTCP compound packet. */ 77 | uint8_t *GetCompoundPacketData() { return compoundpacket; } 78 | 79 | /** Returns the size of the entire RTCP compound packet. */ 80 | size_t GetCompoundPacketLength() { return compoundpacketlength; } 81 | 82 | /** Starts the iteration over the individual RTCP packets in the RTCP compound packet. */ 83 | void GotoFirstPacket() { rtcppackit = rtcppacklist.begin(); } 84 | 85 | /** Returns a pointer to the next individual RTCP packet. 86 | * Returns a pointer to the next individual RTCP packet. Note that no \c delete call may be done 87 | * on the RTCPPacket instance which is returned. 88 | */ 89 | RTCPPacket *GetNextPacket() { if (rtcppackit == rtcppacklist.end()) return 0; RTCPPacket *p = *rtcppackit; rtcppackit++; return p; } 90 | 91 | #ifdef RTPDEBUG 92 | void Dump(); 93 | #endif // RTPDEBUG 94 | protected: 95 | void ClearPacketList(); 96 | int ParseData(uint8_t *packet, size_t len); 97 | 98 | int error; 99 | 100 | uint8_t *compoundpacket; 101 | size_t compoundpacketlength; 102 | bool deletepacket; 103 | 104 | std::list rtcppacklist; 105 | std::list::const_iterator rtcppackit; 106 | }; 107 | 108 | } // end namespace 109 | 110 | #endif // RTCPCOMPOUNDPACKET_H 111 | 112 | -------------------------------------------------------------------------------- /src/rtcpbyepacket.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtcpbyepacket.h 35 | */ 36 | 37 | #ifndef RTCPBYEPACKET_H 38 | 39 | #define RTCPBYEPACKET_H 40 | 41 | #include "rtpconfig.h" 42 | #include "rtcppacket.h" 43 | #include "rtpstructs.h" 44 | #ifdef RTP_SUPPORT_NETINET_IN 45 | #include 46 | #endif // RTP_SUPPORT_NETINET_IN 47 | 48 | namespace jrtplib 49 | { 50 | 51 | class RTCPCompoundPacket; 52 | 53 | /** Describes an RTCP BYE packet. */ 54 | class JRTPLIB_IMPORTEXPORT RTCPBYEPacket : public RTCPPacket 55 | { 56 | public: 57 | /** Creates an instance based on the data in \c data with length \c datalen. 58 | * Creates an instance based on the data in \c data with length \c datalen. Since the \c data pointer 59 | * is referenced inside the class (no copy of the data is made) one must make sure that the memory it 60 | * points to is valid as long as the class instance exists. 61 | */ 62 | RTCPBYEPacket(uint8_t *data,size_t datalen); 63 | ~RTCPBYEPacket() { } 64 | 65 | /** Returns the number of SSRC identifiers present in this BYE packet. */ 66 | int GetSSRCCount() const; 67 | 68 | /** Returns the SSRC described by \c index which may have a value from 0 to GetSSRCCount()-1 69 | * (note that no check is performed to see if \c index is valid). 70 | */ 71 | uint32_t GetSSRC(int index) const; // note: no check is performed to see if index is valid! 72 | 73 | /** Returns true if the BYE packet contains a reason for leaving. */ 74 | bool HasReasonForLeaving() const; 75 | 76 | /** Returns the length of the string which describes why the source(s) left. */ 77 | size_t GetReasonLength() const; 78 | 79 | /** Returns the actual reason for leaving data. */ 80 | uint8_t *GetReasonData(); 81 | 82 | #ifdef RTPDEBUG 83 | void Dump(); 84 | #endif // RTPDEBUG 85 | private: 86 | size_t reasonoffset; 87 | }; 88 | 89 | inline int RTCPBYEPacket::GetSSRCCount() const 90 | { 91 | if (!knownformat) 92 | return 0; 93 | 94 | RTCPCommonHeader *hdr = (RTCPCommonHeader *)data; 95 | return (int)(hdr->count); 96 | } 97 | 98 | inline uint32_t RTCPBYEPacket::GetSSRC(int index) const 99 | { 100 | if (!knownformat) 101 | return 0; 102 | uint32_t *ssrc = (uint32_t *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)*index); 103 | return ntohl(*ssrc); 104 | } 105 | 106 | inline bool RTCPBYEPacket::HasReasonForLeaving() const 107 | { 108 | if (!knownformat) 109 | return false; 110 | if (reasonoffset == 0) 111 | return false; 112 | return true; 113 | } 114 | 115 | inline size_t RTCPBYEPacket::GetReasonLength() const 116 | { 117 | if (!knownformat) 118 | return 0; 119 | if (reasonoffset == 0) 120 | return 0; 121 | uint8_t *reasonlen = (data+reasonoffset); 122 | return (size_t)(*reasonlen); 123 | } 124 | 125 | inline uint8_t *RTCPBYEPacket::GetReasonData() 126 | { 127 | if (!knownformat) 128 | return 0; 129 | if (reasonoffset == 0) 130 | return 0; 131 | uint8_t *reasonlen = (data+reasonoffset); 132 | if ((*reasonlen) == 0) 133 | return 0; 134 | return (data+reasonoffset+1); 135 | } 136 | 137 | } // end namespace 138 | 139 | #endif // RTCPBYEPACKET_H 140 | 141 | -------------------------------------------------------------------------------- /src/rtpipv6address.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | /** 34 | * \file rtpipv6address.h 35 | */ 36 | 37 | #ifndef RTPIPV6ADDRESS_H 38 | 39 | #define RTPIPV6ADDRESS_H 40 | 41 | #include "rtpconfig.h" 42 | 43 | #ifdef RTP_SUPPORT_IPV6 44 | 45 | #include "rtpaddress.h" 46 | #include "rtptypes.h" 47 | #ifdef RTP_SUPPORT_NETINET_IN 48 | #include 49 | #endif // RTP_SUPPORT_NETINET_IN 50 | 51 | namespace jrtplib 52 | { 53 | 54 | /** Represents an IPv6 IP address and port. 55 | * This class is used by the UDP over IPv4 transmission component. 56 | * When an RTPIPv6Address is used in one of the multicast functions of the 57 | * transmitter, the port number is ignored. When an instance is used in one of 58 | * the accept or ignore functions of the transmitter, a zero port number represents 59 | * all ports for the specified IP address. 60 | */ 61 | class JRTPLIB_IMPORTEXPORT RTPIPv6Address : public RTPAddress 62 | { 63 | public: 64 | /** Creates an instance with IP address and port number set to zero. */ 65 | RTPIPv6Address():RTPAddress(IPv6Address) { for (int i = 0 ; i < 16 ; i++) ip.s6_addr[i] = 0; port = 0; } 66 | 67 | /** Creates an instance with IP address \c ip and port number \c port (the port number is assumed to be in 68 | * host byte order). */ 69 | RTPIPv6Address(const uint8_t ip[16],uint16_t port = 0):RTPAddress(IPv6Address) { SetIP(ip); RTPIPv6Address::port = port; } 70 | 71 | /** Creates an instance with IP address \c ip and port number \c port (the port number is assumed to be in 72 | * host byte order). */ 73 | RTPIPv6Address(in6_addr ip,uint16_t port = 0):RTPAddress(IPv6Address) { RTPIPv6Address::ip = ip; RTPIPv6Address::port = port; } 74 | ~RTPIPv6Address() { } 75 | 76 | /** Sets the IP address for this instance to \c ip. */ 77 | void SetIP(in6_addr ip) { RTPIPv6Address::ip = ip; } 78 | 79 | /** Sets the IP address for this instance to \c ip. */ 80 | void SetIP(const uint8_t ip[16]) { for (int i = 0 ; i < 16 ; i++) RTPIPv6Address::ip.s6_addr[i] = ip[i]; } 81 | 82 | /** Sets the port number for this instance to \c port, which is interpreted in host byte order. */ 83 | void SetPort(uint16_t port) { RTPIPv6Address::port = port; } 84 | 85 | /** Copies the IP address of this instance in \c ip. */ 86 | void GetIP(uint8_t ip[16]) const { for (int i = 0 ; i < 16 ; i++) ip[i] = RTPIPv6Address::ip.s6_addr[i]; } 87 | 88 | /** Returns the IP address of this instance. */ 89 | in6_addr GetIP() const { return ip; } 90 | 91 | /** Returns the port number contained in this instance in host byte order. */ 92 | uint16_t GetPort() const { return port; } 93 | 94 | RTPAddress *CreateCopy(RTPMemoryManager *mgr) const; 95 | bool IsSameAddress(const RTPAddress *addr) const; 96 | bool IsFromSameHost(const RTPAddress *addr) const; 97 | #ifdef RTPDEBUG 98 | std::string GetAddressString() const; 99 | #endif // RTPDEBUG 100 | private: 101 | in6_addr ip; 102 | uint16_t port; 103 | }; 104 | 105 | } // end namespace 106 | 107 | #endif // RTP_SUPPORT_IPV6 108 | 109 | #endif // RTPIPV6ADDRESS_H 110 | 111 | -------------------------------------------------------------------------------- /src/rtppollthread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtppollthread.h" 34 | 35 | #ifdef RTP_SUPPORT_THREAD 36 | 37 | #include "rtpsession.h" 38 | #include "rtcpscheduler.h" 39 | #include "rtperrors.h" 40 | #include "rtprawpacket.h" 41 | #include 42 | #include 43 | 44 | #include "rtpdebug.h" 45 | 46 | namespace jrtplib 47 | { 48 | 49 | RTPPollThread::RTPPollThread(RTPSession &session,RTCPScheduler &sched):rtpsession(session),rtcpsched(sched) 50 | { 51 | stop = false; 52 | transmitter = 0; 53 | timeinit.Dummy(); 54 | } 55 | 56 | RTPPollThread::~RTPPollThread() 57 | { 58 | Stop(); 59 | } 60 | 61 | int RTPPollThread::Start(RTPTransmitter *trans) 62 | { 63 | if (JThread::IsRunning()) 64 | return ERR_RTP_POLLTHREAD_ALREADYRUNNING; 65 | 66 | transmitter = trans; 67 | if (!stopmutex.IsInitialized()) 68 | { 69 | if (stopmutex.Init() < 0) 70 | return ERR_RTP_POLLTHREAD_CANTINITMUTEX; 71 | } 72 | stop = false; 73 | if (JThread::Start() < 0) 74 | return ERR_RTP_POLLTHREAD_CANTSTARTTHREAD; 75 | return 0; 76 | } 77 | 78 | void RTPPollThread::Stop() 79 | { 80 | if (!IsRunning()) 81 | return; 82 | 83 | stopmutex.Lock(); 84 | stop = true; 85 | stopmutex.Unlock(); 86 | 87 | if (transmitter) 88 | transmitter->AbortWait(); 89 | 90 | RTPTime thetime = RTPTime::CurrentTime(); 91 | bool done = false; 92 | 93 | while (JThread::IsRunning() && !done) 94 | { 95 | // wait max 5 sec 96 | RTPTime curtime = RTPTime::CurrentTime(); 97 | if ((curtime.GetDouble()-thetime.GetDouble()) > 5.0) 98 | done = true; 99 | RTPTime::Wait(RTPTime(0,10000)); 100 | } 101 | 102 | if (JThread::IsRunning()) 103 | { 104 | std::cerr << "RTPPollThread: Warning! Having to kill thread!" << std::endl; 105 | JThread::Kill(); 106 | } 107 | stop = false; 108 | transmitter = 0; 109 | } 110 | 111 | void *RTPPollThread::Thread() 112 | { 113 | JThread::ThreadStarted(); 114 | 115 | bool stopthread; 116 | 117 | stopmutex.Lock(); 118 | stopthread = stop; 119 | stopmutex.Unlock(); 120 | 121 | rtpsession.OnPollThreadStart(stopthread); 122 | 123 | while (!stopthread) 124 | { 125 | int status; 126 | 127 | rtpsession.schedmutex.Lock(); 128 | rtpsession.sourcesmutex.Lock(); 129 | 130 | RTPTime rtcpdelay = rtcpsched.GetTransmissionDelay(); 131 | 132 | rtpsession.sourcesmutex.Unlock(); 133 | rtpsession.schedmutex.Unlock(); 134 | 135 | if ((status = transmitter->WaitForIncomingData(rtcpdelay)) < 0) 136 | { 137 | stopthread = true; 138 | rtpsession.OnPollThreadError(status); 139 | } 140 | else 141 | { 142 | if ((status = transmitter->Poll()) < 0) 143 | { 144 | stopthread = true; 145 | rtpsession.OnPollThreadError(status); 146 | } 147 | else 148 | { 149 | if ((status = rtpsession.ProcessPolledData()) < 0) 150 | { 151 | stopthread = true; 152 | rtpsession.OnPollThreadError(status); 153 | } 154 | else 155 | { 156 | rtpsession.OnPollThreadStep(); 157 | stopmutex.Lock(); 158 | stopthread = stop; 159 | stopmutex.Unlock(); 160 | } 161 | } 162 | } 163 | } 164 | 165 | rtpsession.OnPollThreadStop(); 166 | 167 | return 0; 168 | } 169 | 170 | } // end namespace 171 | 172 | #endif // RTP_SUPPORT_THREAD 173 | 174 | -------------------------------------------------------------------------------- /src/rtprandomrands.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file is a part of JRTPLIB 4 | Copyright (c) 1999-2017 Jori Liesenborgs 5 | 6 | Contact: jori.liesenborgs@gmail.com 7 | 8 | This library was developed at the Expertise Centre for Digital Media 9 | (http://www.edm.uhasselt.be), a research center of the Hasselt University 10 | (http://www.uhasselt.be). The library is based upon work done for 11 | my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a 14 | copy of this software and associated documentation files (the "Software"), 15 | to deal in the Software without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | */ 32 | 33 | #include "rtpconfig.h" 34 | #ifdef RTP_HAVE_RAND_S 35 | #define _CRT_RAND_S 36 | #endif // RTP_HAVE_RAND_S 37 | 38 | #include "rtprandomrands.h" 39 | #include "rtperrors.h" 40 | #include 41 | #include 42 | 43 | // If compiling on VC 8 or later for full Windows, we'll attempt to use rand_s, 44 | // which generates better random numbers. However, its only supported on Windows XP, 45 | // Windows Server 2003, and later, so we'll do a run-time check to see if we can 46 | // use it (it won't work on Windows 2000 SP4 for example). 47 | 48 | #include "rtpdebug.h" 49 | 50 | namespace jrtplib 51 | { 52 | 53 | #ifndef RTP_HAVE_RAND_S 54 | 55 | RTPRandomRandS::RTPRandomRandS() 56 | { 57 | initialized = false; 58 | } 59 | 60 | RTPRandomRandS::~RTPRandomRandS() 61 | { 62 | } 63 | 64 | int RTPRandomRandS::Init() 65 | { 66 | return ERR_RTP_RTPRANDOMRANDS_NOTSUPPORTED; 67 | } 68 | 69 | uint8_t RTPRandomRandS::GetRandom8() 70 | { 71 | return 0; 72 | } 73 | 74 | uint16_t RTPRandomRandS::GetRandom16() 75 | { 76 | return 0; 77 | } 78 | 79 | uint32_t RTPRandomRandS::GetRandom32() 80 | { 81 | return 0; 82 | } 83 | 84 | double RTPRandomRandS::GetRandomDouble() 85 | { 86 | return 0; 87 | } 88 | 89 | #else 90 | 91 | RTPRandomRandS::RTPRandomRandS() 92 | { 93 | initialized = false; 94 | } 95 | 96 | RTPRandomRandS::~RTPRandomRandS() 97 | { 98 | } 99 | 100 | int RTPRandomRandS::Init() 101 | { 102 | if (initialized) // doesn't matter then 103 | return 0; 104 | 105 | HMODULE hAdvApi32 = LoadLibrary(TEXT("ADVAPI32.DLL")); 106 | if(hAdvApi32 != NULL) 107 | { 108 | if(NULL != GetProcAddress( hAdvApi32, "SystemFunction036" )) // RtlGenRandom 109 | { 110 | initialized = true; 111 | } 112 | FreeLibrary(hAdvApi32); 113 | hAdvApi32 = NULL; 114 | } 115 | 116 | if (!initialized) 117 | return ERR_RTP_RTPRANDOMRANDS_NOTSUPPORTED; 118 | return 0; 119 | } 120 | 121 | // rand_s gives a number between 0 and UINT_MAX. We'll assume that UINT_MAX is at least 8 bits 122 | 123 | uint8_t RTPRandomRandS::GetRandom8() 124 | { 125 | if (!initialized) 126 | return 0; 127 | 128 | unsigned int r; 129 | 130 | rand_s(&r); 131 | 132 | return (uint8_t)(r&0xff); 133 | } 134 | 135 | uint16_t RTPRandomRandS::GetRandom16() 136 | { 137 | if (!initialized) 138 | return 0; 139 | 140 | unsigned int r; 141 | int shift = 0; 142 | uint16_t x = 0; 143 | 144 | for (int i = 0 ; i < 2 ; i++, shift += 8) 145 | { 146 | rand_s(&r); 147 | 148 | x ^= ((uint16_t)r << shift); 149 | } 150 | 151 | return x; 152 | } 153 | 154 | uint32_t RTPRandomRandS::GetRandom32() 155 | { 156 | if (!initialized) 157 | return 0; 158 | 159 | unsigned int r; 160 | int shift = 0; 161 | uint32_t x = 0; 162 | 163 | for (int i = 0 ; i < 4 ; i++, shift += 8) 164 | { 165 | rand_s(&r); 166 | 167 | x ^= ((uint32_t)r << shift); 168 | } 169 | 170 | return x; 171 | } 172 | 173 | double RTPRandomRandS::GetRandomDouble() 174 | { 175 | if (!initialized) 176 | return 0; 177 | 178 | unsigned int r; 179 | int shift = 0; 180 | uint64_t x = 0; 181 | 182 | for (int i = 0 ; i < 8 ; i++, shift += 8) 183 | { 184 | rand_s(&r); 185 | 186 | x ^= ((uint64_t)r << shift); 187 | } 188 | 189 | x &= 0x7fffffffffffffffULL; 190 | 191 | int64_t x2 = (int64_t)x; 192 | return RTPRANDOM_2POWMIN63*(double)x2; 193 | } 194 | 195 | #endif // RTP_HAVE_RAND_S 196 | 197 | } // end namespace 198 | 199 | --------------------------------------------------------------------------------