- changes from pvqa-server project

This commit is contained in:
Dmytro Bogovych 2018-07-15 11:46:50 +03:00
parent a6535bdb97
commit 20ee81666b
11 changed files with 118 additions and 37 deletions

View File

@ -7,7 +7,8 @@
#ifndef __AUDIO_WAVFILE_H #ifndef __AUDIO_WAVFILE_H
#define __AUDIO_WAVFILE_H #define __AUDIO_WAVFILE_H
//#include "helper/HL_Types.h" #include "helper/HL_Sync.h"
#include "helper/HL_Types.h"
#include "Audio_Resampler.h" #include "Audio_Resampler.h"
#include <stdio.h> #include <stdio.h>
@ -15,7 +16,6 @@
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include "helper/HL_Types.h"
namespace Audio namespace Audio
{ {

View File

@ -38,7 +38,7 @@ protected:
std::string mPeer; std::string mPeer;
}; };
typedef SharedPtr<ClientObserver> PClientObserver; typedef std::shared_ptr<ClientObserver> PClientObserver;
class ServerObserver class ServerObserver
{ {
@ -68,6 +68,6 @@ protected:
int mSessionId; int mSessionId;
}; };
typedef SharedPtr<ServerObserver> PServerObserver; typedef std::shared_ptr<ServerObserver> PServerObserver;
#endif // EP_OBSERVER_H #endif // EP_OBSERVER_H

View File

@ -167,12 +167,12 @@ int ResipSession::sessionId()
return mSessionId; return mSessionId;
} }
void ResipSession::setUASProfile(SharedPtr<resip::UserProfile> profile) void ResipSession::setUASProfile(std::shared_ptr<resip::UserProfile> profile)
{ {
mUASProfile = profile; mUASProfile = profile;
} }
SharedPtr<resip::UserProfile> ResipSession::selectUASUserProfile(const resip::SipMessage& msg) resip::SharedPtr<resip::UserProfile> ResipSession::selectUASUserProfile(const resip::SipMessage& msg)
{ {
assert(mUserAgent != nullptr); assert(mUserAgent != nullptr);
@ -184,7 +184,7 @@ SharedPtr<resip::UserProfile> ResipSession::selectUASUserProfile(const resip::Si
else else
return mUserAgent->mProfile; return mUserAgent->mProfile;
} }
return SharedPtr<resip::UserProfile>(); return resip::SharedPtr<resip::UserProfile>();
} }
#pragma endregion #pragma endregion

View File

@ -321,7 +321,7 @@ public:
static resip::AtomicCounter InstanceCounter; static resip::AtomicCounter InstanceCounter;
}; };
typedef SharedPtr<Session> PSession; typedef std::shared_ptr<Session> PSession;
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// //
@ -383,7 +383,7 @@ public:
void runTerminatedEvent(Type type, int code = 0, int reason = 0); void runTerminatedEvent(Type type, int code = 0, int reason = 0);
void setUASProfile(SharedPtr<resip::UserProfile> profile); void setUASProfile(std::shared_ptr<resip::UserProfile> profile);
protected: protected:
bool mTerminated; bool mTerminated;
@ -394,7 +394,7 @@ protected:
std::string mRemoteAddress; std::string mRemoteAddress;
void* mTag; void* mTag;
bool mOnWatchingStartSent; bool mOnWatchingStartSent;
SharedPtr<resip::UserProfile> mUASProfile; std::shared_ptr<resip::UserProfile> mUASProfile;
}; };

View File

@ -3,6 +3,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <assert.h>
#include "helper/HL_VariantMap.h" #include "helper/HL_VariantMap.h"
#include "helper/HL_String.h" #include "helper/HL_String.h"

View File

@ -1,8 +1,12 @@
#include <iostream>
#include "HL_NetworkFrame.h" #include "HL_NetworkFrame.h"
#include "HL_InternetAddress.h" #include "HL_InternetAddress.h"
#define ETHERTYPE_MPLS_UC (0x8847) #define ETHERTYPE_MPLS_UC (0x8847)
#define ETHERTYPE_MPLS_MC (0x8848) #define ETHERTYPE_MPLS_MC (0x8848)
#define ETHERTYPE_IPV6 (0x86dd)
#define ETHERTYPE_IP (0x0800)
#define MPLS_STACK_MASK (0x00000100) #define MPLS_STACK_MASK (0x00000100)
#define MPLS_STACK_SHIFT (8) #define MPLS_STACK_SHIFT (8)
@ -28,9 +32,10 @@ NetworkFrame::PacketData NetworkFrame::GetUdpPayloadForEthernet(NetworkFrame::Pa
} }
// Skip MPLS headers // Skip MPLS headers
switch (proto)
if (proto == ETHERTYPE_MPLS_UC || proto == ETHERTYPE_MPLS_MC)
{ {
case ETHERTYPE_MPLS_UC:
case ETHERTYPE_MPLS_MC:
// Parse MPLS here until marker "bottom of mpls stack" // Parse MPLS here until marker "bottom of mpls stack"
for(bool bottomOfStack = false; !bottomOfStack; for(bool bottomOfStack = false; !bottomOfStack;
bottomOfStack = ((ntohl(*(uint32_t*)(packet.mData - 4)) & MPLS_STACK_MASK) >> MPLS_STACK_SHIFT) != 0) bottomOfStack = ((ntohl(*(uint32_t*)(packet.mData - 4)) & MPLS_STACK_MASK) >> MPLS_STACK_SHIFT) != 0)
@ -38,11 +43,20 @@ NetworkFrame::PacketData NetworkFrame::GetUdpPayloadForEthernet(NetworkFrame::Pa
packet.mData += 4; packet.mData += 4;
packet.mLength -=4; packet.mLength -=4;
} }
break;
case ETHERTYPE_IP:
// Next IPv4 packet
break;
case ETHERTYPE_IPV6:
// Next IPv6 packet
break;
} }
const Ip4Header* ip4 = reinterpret_cast<const Ip4Header*>(packet.mData); const Ip4Header* ip4 = reinterpret_cast<const Ip4Header*>(packet.mData);
if (ip4->mProtocol != IPPROTO_UDP) if (ip4->mProtocol != IPPROTO_UDP && ip4->mProtocol != 0)
return PacketData(); return PacketData();
@ -89,7 +103,7 @@ NetworkFrame::PacketData NetworkFrame::GetUdpPayloadForIp4(NetworkFrame::PacketD
{ {
PacketData result(packet); PacketData result(packet);
const Ip4Header* ip4 = reinterpret_cast<const Ip4Header*>(packet.mData); const Ip4Header* ip4 = reinterpret_cast<const Ip4Header*>(packet.mData);
if (ip4->mProtocol != IPPROTO_UDP) if (ip4->mProtocol != IPPROTO_UDP && ip4->mProtocol != 0)
return PacketData(nullptr, 0); return PacketData(nullptr, 0);
result.mData += ip4->headerLength(); result.mData += ip4->headerLength();
@ -113,17 +127,45 @@ NetworkFrame::PacketData NetworkFrame::GetUdpPayloadForIp4(NetworkFrame::PacketD
return result; return result;
} }
struct Ip6Header
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
uint8_t traffic_class_hi:4,
version:4;
uint8_t flow_label_hi:4,
traffic_class_lo:4;
uint16_t flow_label_lo;
#elif __BYTE_ORDER == __BIG_ENDIAN
uint8_t version:4,
traffic_class_hi:4;
uint8_t traffic_class_lo:4,
flow_label_hi:4;
uint16_t flow_label_lo;
#else
# error "Please fix endianness defines"
#endif
uint16_t payload_len;
uint8_t next_header;
uint8_t hop_limit;
struct in6_addr src_ip;
struct in6_addr dst_ip;
};
NetworkFrame::PacketData NetworkFrame::GetUdpPayloadForIp6(NetworkFrame::PacketData& packet, InternetAddress& source, InternetAddress& destination) NetworkFrame::PacketData NetworkFrame::GetUdpPayloadForIp6(NetworkFrame::PacketData& packet, InternetAddress& source, InternetAddress& destination)
{ {
PacketData result(packet); PacketData result(packet);
const Ip4Header* ip4 = reinterpret_cast<const Ip4Header*>(packet.mData); const Ip6Header* ip6 = reinterpret_cast<const Ip6Header*>(packet.mData);
if (ip4->mProtocol != IPPROTO_UDP) /*if (ip6->mProtocol != IPPROTO_UDP && ip4->mProtocol != 0)
return PacketData(nullptr, 0); return PacketData(nullptr, 0);
*/
result.mData += sizeof(Ip6Header);
result.mLength -= sizeof(Ip6Header);
//std::cout << sizeof(Ip6Header) << std::endl;
result.mData += ip4->headerLength(); const UdpHeader* udp = reinterpret_cast<const UdpHeader*>(result.mData);
result.mLength -= ip4->headerLength();
const UdpHeader* udp = reinterpret_cast<const UdpHeader*>(packet.mData);
result.mData += sizeof(UdpHeader); result.mData += sizeof(UdpHeader);
result.mLength -= sizeof(UdpHeader); result.mLength -= sizeof(UdpHeader);
@ -131,11 +173,14 @@ NetworkFrame::PacketData NetworkFrame::GetUdpPayloadForIp6(NetworkFrame::PacketD
if (result.mLength != ntohs(udp->mDatagramLength)) if (result.mLength != ntohs(udp->mDatagramLength))
return PacketData(nullptr, 0); return PacketData(nullptr, 0);
*/ */
source.setIp(ip4->mSource);
source.setPort(ntohs(udp->mSourcePort));
destination.setIp(ip4->mDestination); source.setIp(ip6->src_ip);
source.setPort(ntohs(udp->mSourcePort));
//std::cout << source.toStdString() << " - ";
destination.setIp(ip6->dst_ip);
destination.setPort(ntohs(udp->mDestinationPort)); destination.setPort(ntohs(udp->mDestinationPort));
//std::cout << destination.toStdString() << std::endl;
return result; return result;
} }

View File

@ -80,6 +80,11 @@ public:
{ {
return mVhl >> 4; return mVhl >> 4;
} }
const in_addr& source4() const { return mSource; }
const in_addr& dest4() const { return mDestination; }
const in6_addr& source6() const { return (const in6_addr&)mSource; }
const in6_addr& dest6() const { return (const in6_addr&)mDestination; }
}; };
struct UdpHeader struct UdpHeader

View File

@ -7,11 +7,8 @@
#define __SMART_POINTER_H #define __SMART_POINTER_H
#include <memory> #include <memory>
#define SharedPtr std::shared_ptr
#include "HL_Sync.h"
#include <map> #include <map>
#include "HL_Sync.h"
class UsageCounter class UsageCounter
{ {

View File

@ -6,6 +6,7 @@
#include "HL_Sync.h" #include "HL_Sync.h"
#include <assert.h> #include <assert.h>
#include <atomic> #include <atomic>
#include <memory.h>
#ifdef TARGET_OSX #ifdef TARGET_OSX
# include <libkern/OSAtomic.h> # include <libkern/OSAtomic.h>
@ -85,6 +86,16 @@ uint32_t TimeHelper::getDelta(uint32_t later, uint32_t earlier)
return 0; return 0;
} }
TimeHelper::ExecutionTime::ExecutionTime()
{
mStart = TimeHelper::getTimestamp();
}
uint64_t TimeHelper::ExecutionTime::getSpentTime() const
{
return TimeHelper::getTimestamp() - mStart;
}
// --------------- BufferQueue ----------------- // --------------- BufferQueue -----------------
BufferQueue::BufferQueue() BufferQueue::BufferQueue()
{ {

View File

@ -76,8 +76,18 @@ public:
// Finds time delta between 'later' and 'earlier' time points. // Finds time delta between 'later' and 'earlier' time points.
// Handles cases when clock is wrapped. // Handles cases when clock is wrapped.
static uint32_t getDelta(uint32_t later, uint32_t earlier); static uint32_t getDelta(uint32_t later, uint32_t earlier);
class ExecutionTime
{
public:
ExecutionTime();
uint64_t getSpentTime() const;
protected:
uint64_t mStart;
};
}; };
class BufferQueue class BufferQueue
{ {
public: public:

View File

@ -150,6 +150,18 @@ extern Logger GLogger;
#define ICELogDebug(args_) ICELog(LL_DEBUG, LOG_SUBSYSTEM, args_) #define ICELogDebug(args_) ICELog(LL_DEBUG, LOG_SUBSYSTEM, args_)
#define ICELogMedia(args_) ICELog(LL_MEDIA, LOG_SUBSYSTEM, args_) #define ICELogMedia(args_) ICELog(LL_MEDIA, LOG_SUBSYSTEM, args_)
#define ICELogCritical2(args_) ICELog(LogLevel_Critical, LogSubsystem.c_str(), args_)
#define ICELogInfo2(args_) ICELog(LogLevel_Info, LogSubsystem.c_str(), args_)
#define ICELogDebug2(args_) ICELog(LogLevel_Debug, LogSubsystem.c_str(), args_)
#define ICELogMedia2(args_) ICELog(LogLevel_Media, LogSubsystem.c_str(), args_)
#define DEFINE_LOGGING(subsystem) \
static std::string LogSubsystem = subsystem; \
static ice::LogLevel LogLevel_Critical = LL_CRITICAL; \
static ice::LogLevel LogLevel_Info = LL_INFO; \
static ice::LogLevel LogLevel_Debug = LL_DEBUG; \
static ice::LogLevel LogLevel_Media = LL_MEDIA
/* /*
#define ICELogCritical(args_) #define ICELogCritical(args_)