Skip to content

Commit

Permalink
Moved some globals into scopes, rewrote to constexpr
Browse files Browse the repository at this point in the history
Signed-off-by:doe300 <[email protected]>
  • Loading branch information
doe300 committed Feb 5, 2016
1 parent 1f7d308 commit 870c861
Show file tree
Hide file tree
Showing 24 changed files with 161 additions and 155 deletions.
10 changes: 5 additions & 5 deletions include/AudioProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
#include "ConfigurationMode.h"
#include "rtp/RTPHeader.h"

/*!
* This AudioProcessor supports any buffer-length
*/
const int BUFFER_SIZE_ANY = -1;

/*!
* Information about the stream to be passed to the process-methods of AudioProcessor.
* Details of the values are specified by the used AudioIO-implementation
Expand Down Expand Up @@ -54,6 +49,11 @@ struct StreamData
class AudioProcessor
{
public:
/*!
* This AudioProcessor supports any buffer-length
*/
static constexpr int BUFFER_SIZE_ANY{1};

AudioProcessor(const std::string name);

virtual ~AudioProcessor()
Expand Down
8 changes: 4 additions & 4 deletions include/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ enum class ParameterCategory : char
struct Parameter
{
//flag determining whether this parameter is required
const static unsigned short FLAG_REQUIRED = 0x1;
static constexpr unsigned short FLAG_REQUIRED = 0x1;
//flag determining whether this parameter has a value
const static unsigned short FLAG_HAS_VALUE = 0x2;
static constexpr unsigned short FLAG_HAS_VALUE = 0x2;
//flag determining whether this parameter calls another configuration-mode
const static unsigned short FLAG_CONFIGURATION_MODE = 0x4;
static constexpr unsigned short FLAG_CONFIGURATION_MODE = 0x4;

//The category of this parameter
const ParameterCategory category;
Expand Down Expand Up @@ -224,7 +224,7 @@ class Parameters
// A list of all available parameters
//we use list for easier sorting
static std::list<Parameter> availableParameters;
static const unsigned int tabSize{5};
static constexpr unsigned int tabSize{5};

//Prints a help-line for a single parameter
void printParameterHelp(const Parameter& param) const;
Expand Down
32 changes: 16 additions & 16 deletions include/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ class Statistics
{
//TODO RTCP-statistics # packages sent/received, # bytes sent/received
public:
static const int COUNTER_PACKAGES_SENT{0};
static const int COUNTER_PACKAGES_RECEIVED{1};
static const int COUNTER_PACKAGES_LOST{2};
static const int COUNTER_FRAMES_SENT{3};
static const int COUNTER_FRAMES_RECORDED{4};
static const int COUNTER_FRAMES_RECEIVED{5};
static const int COUNTER_FRAMES_OUTPUT{6};
static const int COUNTER_HEADER_BYTES_SENT{7};
static const int COUNTER_HEADER_BYTES_RECEIVED{8};
static const int COUNTER_PAYLOAD_BYTES_SENT{9};
static const int COUNTER_PAYLOAD_BYTES_RECORDED{10};
static const int COUNTER_PAYLOAD_BYTES_RECEIVED{11};
static const int COUNTER_PAYLOAD_BYTES_OUTPUT{12};
static const int TOTAL_ELAPSED_MILLISECONDS{13};
static const int RTP_BUFFER_MAXIMUM_USAGE{14};
static const int RTP_BUFFER_LIMIT{15};
static constexpr int COUNTER_PACKAGES_SENT{0};
static constexpr int COUNTER_PACKAGES_RECEIVED{1};
static constexpr int COUNTER_PACKAGES_LOST{2};
static constexpr int COUNTER_FRAMES_SENT{3};
static constexpr int COUNTER_FRAMES_RECORDED{4};
static constexpr int COUNTER_FRAMES_RECEIVED{5};
static constexpr int COUNTER_FRAMES_OUTPUT{6};
static constexpr int COUNTER_HEADER_BYTES_SENT{7};
static constexpr int COUNTER_HEADER_BYTES_RECEIVED{8};
static constexpr int COUNTER_PAYLOAD_BYTES_SENT{9};
static constexpr int COUNTER_PAYLOAD_BYTES_RECORDED{10};
static constexpr int COUNTER_PAYLOAD_BYTES_RECEIVED{11};
static constexpr int COUNTER_PAYLOAD_BYTES_OUTPUT{12};
static constexpr int TOTAL_ELAPSED_MILLISECONDS{13};
static constexpr int RTP_BUFFER_MAXIMUM_USAGE{14};
static constexpr int RTP_BUFFER_LIMIT{15};

/*!
* Increments the given counter by the value provided
Expand Down
3 changes: 2 additions & 1 deletion include/rtp/ProcessorRTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class ProcessorRTP : public AudioProcessor
bool cleanUp();
private:
//! Delay until treating input as silence
static const unsigned short SILENCE_DELAY;
//!Treat as silence after 500ms of no input
static constexpr unsigned short SILENCE_DELAY{500};
std::shared_ptr<NetworkWrapper> networkObject;
std::unique_ptr<RTPPackageHandler> rtpPackage;
std::shared_ptr<RTPBufferHandler> rtpBuffer;
Expand Down
3 changes: 2 additions & 1 deletion include/rtp/RTCPHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class RTCPHandler : public PlaybackListener
bool threadRunning = false;

//send SR every X seconds
static const std::chrono::seconds sendSRInterval;
//standard-conform minimum interval of 5 seconds (no need to be adaptive, as long as we only have one remote) (RFC3550 Section 6.2)
static constexpr std::chrono::seconds sendSRInterval{5};
std::chrono::system_clock::time_point lastSRReceived;
std::chrono::system_clock::time_point lastSRSent;
std::vector<SourceDescription> sourceDescriptions;
Expand Down
6 changes: 3 additions & 3 deletions include/rtp/RTCPPackageHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class RTCPPackageHandler
{
public:

static const uint8_t RTCP_HEADER_SIZE = sizeof(RTCPHeader);
static const uint8_t RTCP_SENDER_INFO_SIZE = sizeof(SenderInformation);
static const uint8_t RTCP_RECEPTION_REPORT_SIZE = sizeof(ReceptionReport);
static constexpr uint8_t RTCP_HEADER_SIZE = sizeof(RTCPHeader);
static constexpr uint8_t RTCP_SENDER_INFO_SIZE = sizeof(SenderInformation);
static constexpr uint8_t RTCP_RECEPTION_REPORT_SIZE = sizeof(ReceptionReport);

RTCPPackageHandler();

Expand Down
39 changes: 20 additions & 19 deletions include/rtp/RTPHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,6 @@
#include <netinet/in.h>
#endif

/*!
* Minimum size of a RTP-Header in bytes, without any CSRCs set
*/
static const unsigned int RTP_HEADER_MIN_SIZE = 12;
/*!
* Maximum size of a RTP-Header with all CSRCs set.
*/
static const unsigned int RTP_HEADER_MAX_SIZE = 72;

/*!
* Minimum size for RTP header-extensions, 4 Byte
*/
static const unsigned int RTP_HEADER_EXTENSION_MIN_SIZE = 4;

/*!
* A RTP header extension has the following format:
*
Expand Down Expand Up @@ -65,6 +51,11 @@ struct RTPHeaderExtension
uint32_t* extensions;

public:
/*!
* Minimum size for RTP header-extensions, 4 Byte
*/
static constexpr unsigned int MIN_EXTENSION_SIZE{4};

RTPHeaderExtension(uint16_t length) : profile_field(0), length(length)
{
if(length > 0)
Expand Down Expand Up @@ -290,17 +281,27 @@ struct RTPHeader
//also watch out for byte-order and order of fields
//uint32_t csrc_list[15];

static const unsigned int shiftVersion = 6;
static const unsigned int shiftPadding = 5;
static const unsigned int shiftExtension = 4;
static const unsigned int shiftMarker = 7;
static constexpr unsigned int shiftVersion = 6;
static constexpr unsigned int shiftPadding = 5;
static constexpr unsigned int shiftExtension = 4;
static constexpr unsigned int shiftMarker = 7;

public:

/*!
* Minimum size of a RTP-Header in bytes, without any CSRCs set
*/
static constexpr unsigned int MIN_HEADER_SIZE{12};

/*!
* Maximum size of a RTP-Header with all CSRCs set.
*/
static constexpr unsigned int MAX_HEADER_SIZE{72};

/*!
* The version-flag of a RTP package is always 2
*/
static const unsigned int VERSION = 2;
static constexpr unsigned int VERSION{2};

RTPHeader() : data{0}
{
Expand Down
42 changes: 21 additions & 21 deletions include/sip/SDPMessageHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,6 @@
#include "rtp/RTPHeader.h"
#include "sip/SupportedFormats.h"

/*!
* The MIME-type for SDP: application/sdp
*/
const std::string MIME_SDP="application/sdp";

const char SDP_VERSION='v';
const char SDP_ORIGIN='c';
const char SDP_SESSION_NAME='s';
const char SDP_CONNECTION='c';
const char SDP_TIMING='t';
const char SDP_MEDIA='m';
const char SDP_ATTRIBUTE='a';

const std::string SDP_ATTRIBUTE_RTPMAP("rtpmap");
const std::string SDP_ATTRIBUTE_FMTP("fmtp");
//specifies RTCP-port, if not consecutive to RTP-port, see RFC 3605
const std::string SDP_ATTRIBUTE_RTCP("rtcp");

const std::string SDP_MEDIA_RTP("RTP/AVP");
const std::string SDP_MEDIA_SRTP("RTP/SAVP");

struct SessionKey : public KeyValuePair<char>
{
SessionKey() : KeyValuePair<char>()
Expand Down Expand Up @@ -97,6 +76,22 @@ struct MediaDescription

struct SessionDescription : public KeyValuePairs<SessionKey>
{
static constexpr char SDP_VERSION='v';
static constexpr char SDP_ORIGIN='c';
static constexpr char SDP_SESSION_NAME='s';
static constexpr char SDP_CONNECTION='c';
static constexpr char SDP_TIMING='t';
static constexpr char SDP_MEDIA='m';
static constexpr char SDP_ATTRIBUTE='a';

static const std::string SDP_ATTRIBUTE_RTPMAP;
static const std::string SDP_ATTRIBUTE_FMTP;
//specifies RTCP-port, if not consecutive to RTP-port, see RFC 3605
static const std::string SDP_ATTRIBUTE_RTCP;

static const std::string SDP_MEDIA_RTP;
static const std::string SDP_MEDIA_SRTP;

/*!
* \param tag The attribute-tag to search for
* \param firstValue The (optional) first part of the attribute-value
Expand Down Expand Up @@ -140,6 +135,11 @@ struct SessionDescription : public KeyValuePairs<SessionKey>
class SDPMessageHandler
{
public:

/*!
* The MIME-type for SDP: application/sdp
*/
static const std::string MIME_SDP;
SDPMessageHandler();

/*!
Expand Down
2 changes: 1 addition & 1 deletion include/sip/SIPConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SIPConfiguration : public ConfigurationMode
void setConfig(const MediaDescription& media, const NetworkConfiguration& rtpConfig, const NetworkConfiguration& customRTCPConfig);

//Wait a maximum of 30 secs
static const int MAX_WAIT_TIME{30000};
static constexpr int MAX_WAIT_TIME{30000};
};

#endif /* SIPCONFIGURATION_H */
Expand Down
20 changes: 10 additions & 10 deletions include/sip/SIPHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
#include "SDPMessageHandler.h"
#include "SIPPackageHandler.h"

#define SIP_BUFFER_SIZE 2048

//A list of all allowed SIP-methods
const std::string SIP_ALLOW_METHODS = Utility::joinStrings({SIP_REQUEST_INVITE, SIP_REQUEST_ACK, SIP_REQUEST_BYE, SIP_REQUEST_CANCEL}, " ");

//A list of all accepted MIME-types
const std::string SIP_ACCEPT_TYPES = Utility::joinStrings({MIME_SDP, MIME_MULTIPART_MIXED, MIME_MULTIPART_ALTERNATIVE}, ", ");

const unsigned short SIP_DEFAULT_PORT =5060;

class SIPHandler
{
public:

//A list of all allowed SIP-methods
static const std::string SIP_ALLOW_METHODS;

//A list of all accepted MIME-types
static const std::string SIP_ACCEPT_TYPES;

//The default port for SIP, as of RFC 3261
static constexpr unsigned short SIP_DEFAULT_PORT{5060};

SIPHandler(const NetworkConfiguration& sipConfig, const std::string& remoteUser, const std::function<void(const MediaDescription, const NetworkConfiguration, const NetworkConfiguration)> configFunction);

SIPHandler(const NetworkConfiguration& sipConfig, const std::string& localUser, const std::string& localHostName, const std::string& remoteUser, const std::string& callID);
Expand All @@ -56,6 +55,7 @@ class SIPHandler
static std::string generateCallID(const std::string& host);

private:
static constexpr unsigned short SIP_BUFFER_SIZE{2048};
enum class SessionState
{
/*!
Expand Down
58 changes: 29 additions & 29 deletions include/sip/STUNClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,6 @@

#include "Utility.h"

typedef uint16_t STUNMessageType;

static const STUNMessageType STUN_BINDING_REQUEST = 0x0001;
static const STUNMessageType STUN_BINDING_RESPONSE = 0x0101;
static const STUNMessageType STUN_BINDING_ERROR_RESPONSE = 0x0111;
//list is not exhaustive (see: https://www.iana.org/assignments/stun-parameters/stun-parameters.txt)

typedef uint16_t STUNAttributeType;

static const STUNAttributeType STUN_INVALID_ATTRIBUTE = 0x0000;
static const STUNAttributeType STUN_MAPPED_ADDRESS = 0x0001;
static const STUNAttributeType STUN_CHANGE_REQUEST = 0x0003;
static const STUNAttributeType STUN_USERNAME = 0x0006;
static const STUNAttributeType STUN_MESSAGE_INTEGRITY = 0x0008;
static const STUNAttributeType STUN_ERROR_CODE = 0x0009;
static const STUNAttributeType STUN_UNKNOWN_ATTRIBUTES = 0x000A;
static const STUNAttributeType STUN_XOR_MAPPED_ADDRESS = 0x8020;
static const STUNAttributeType STUN_ALTERNATE_SERVER = 0x8023;
//list is not exhaustive (see: https://www.iana.org/assignments/stun-parameters/stun-parameters.txt)

static const uint16_t MAPPED_ADDRESS_IPv4 = 0x1;
static const uint16_t MAPPED_ADDRESS_IPv6 = 0x2;

/*!
* STUN client for RFC 5389
*
Expand All @@ -64,14 +41,37 @@ class STUNClient
const std::tuple<bool, std::string, unsigned short> retrieveSIPInfo();

private:
typedef uint16_t STUNMessageType;

static constexpr STUNMessageType STUN_BINDING_REQUEST = 0x0001;
static constexpr STUNMessageType STUN_BINDING_RESPONSE = 0x0101;
static constexpr STUNMessageType STUN_BINDING_ERROR_RESPONSE = 0x0111;
//list is not exhaustive (see: https://www.iana.org/assignments/stun-parameters/stun-parameters.txt)

typedef uint16_t STUNAttributeType;

static constexpr STUNAttributeType STUN_INVALID_ATTRIBUTE = 0x0000;
static constexpr STUNAttributeType STUN_MAPPED_ADDRESS = 0x0001;
static constexpr STUNAttributeType STUN_CHANGE_REQUEST = 0x0003;
static constexpr STUNAttributeType STUN_USERNAME = 0x0006;
static constexpr STUNAttributeType STUN_MESSAGE_INTEGRITY = 0x0008;
static constexpr STUNAttributeType STUN_ERROR_CODE = 0x0009;
static constexpr STUNAttributeType STUN_UNKNOWN_ATTRIBUTES = 0x000A;
static constexpr STUNAttributeType STUN_XOR_MAPPED_ADDRESS = 0x8020;
static constexpr STUNAttributeType STUN_ALTERNATE_SERVER = 0x8023;
//list is not exhaustive (see: https://www.iana.org/assignments/stun-parameters/stun-parameters.txt)

static constexpr uint16_t MAPPED_ADDRESS_IPv4 = 0x1;
static constexpr uint16_t MAPPED_ADDRESS_IPv6 = 0x2;

static const std::vector<std::string> STUN_SERVERS;
static const unsigned short DEFAULT_STUN_PORT;
static constexpr unsigned short DEFAULT_STUN_PORT{3478};
static const std::string DEFAULT_SOURCE_IP;
static const unsigned short LOCAL_PORT;
static const uint32_t MAGIC_COOKIE;
static const unsigned short BUFFER_SIZE;
static const uint8_t STUN_HEADER_SIZE;
static const uint8_t MAX_RETRIES;
static constexpr unsigned short LOCAL_PORT{54320};
static constexpr uint32_t MAGIC_COOKIE{0x2112A442};
static constexpr unsigned short BUFFER_SIZE{2048};
static constexpr uint8_t STUN_HEADER_SIZE{20};
static constexpr uint8_t MAX_RETRIES{8};
char buffer[2048];
std::string transactionID;

Expand Down
8 changes: 5 additions & 3 deletions include/sip/SupportedFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include <string>
#include <vector>

const std::string FORMAT_OPUS_DTX("usedtx");
const std::string FORMAT_OPUS_FEC("useinbandfec");

struct SupportedFormat
{
// media name for LPCM samples
Expand All @@ -23,6 +20,11 @@ struct SupportedFormat
//media name for G.711 mu-law samples
static const std::string MEDIA_PCMU;

//parameter name for opus DTX
static const std::string FORMAT_OPUS_DTX;
//parameter name for opus FEC
static const std::string FORMAT_OPUS_FEC;

const unsigned int payloadType;
const std::string encoding;
const unsigned int sampleRate;
Expand Down
Loading

1 comment on commit 870c861

@doe300
Copy link
Owner Author

@doe300 doe300 commented on 870c861 Feb 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could fix the clang error?
http://www.cplusplus.com/forum/beginner/130553/

Please sign in to comment.