AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
alexaClientSDK::avsCommon::utils Namespace Reference

Namespaces

 audioAnalyzer
 
 bluetooth
 
 configuration
 
 error
 
 file
 
 functional
 
 http
 
 http2
 
 id3Tags
 
 json
 
 libcurlUtils
 
 logger
 
 mediaPlayer
 
 memory
 
 metrics
 
 network
 
 observer
 
 playlistParser
 
 power
 
 sdkVersion
 
 sds
 
 stream
 
 string
 
 test
 
 threading
 
 timing
 
 uuidGeneration
 

Classes

struct  AudioFormat
 
class  DeviceInfo
 
struct  Dummy
 
class  EndianTest
 
class  GuardedValue
 
class  HTTPContent
 
class  MacAddressString
 
class  Metrics
 
class  Optional
 
class  PromiseFuturePair
 
class  PromiseFuturePair< void >
 
struct  ReferenceCounter
 
class  RequiresShutdown
 
class  RetryTimer
 
struct  StructWithoutDefaultConstructor
 
class  TestableAttachmentManager
 
class  TestableAttachmentWriter
 
class  TestableMessageObserver
 
class  TestMimeAttachmentPart
 
class  TestMimeJsonPart
 
class  TestMimePart
 
struct  TypeIndex
 
class  WaitEvent
 
struct  WavHeader
 

Typedefs

using ByteVector = std::vector< unsigned char >
 
using SDSType = avsCommon::utils::sds::InProcessSDS
 
using SDSBufferType = avsCommon::utils::sds::InProcessSDSTraits::Buffer
 

Enumerations

enum  MediaType { MediaType::MPEG, MediaType::WAV, MediaType::UNKNOWN }
 

Functions

std::ostream & operator<< (std::ostream &stream, const AudioFormat::Encoding &encoding)
 
std::ostream & operator<< (std::ostream &stream, const AudioFormat::Endianness &endianness)
 
static std::shared_ptr< std::mutex > getCoutMutex ()
 
bool littleEndianMachine ()
 Function used to check the machine endianness. More...
 
uint16_t swapEndian (uint16_t input)
 
uint32_t swapEndian (uint32_t input)
 
MediaType MimeTypeToMediaType (const std::string &mimetype)
 
std::ostream & operator<< (std::ostream &stream, const MediaType &mediatype)
 
template<typename Type >
TypeIndex getTypeIndex ()
 
template<typename Type >
void logTypeIndex (const std::string &name)
 
ByteVector generateWavHeader (unsigned int bytesPerSample, unsigned int channels, unsigned int rate, std::chrono::milliseconds totalDuration, bool isPCM=true)
 
bool readWAVFile (const std::string &absoluteFilePath, std::vector< uint16_t > *audioBuffer, WavHeader &wavHeader, bool isPCM=true)
 
std::string createRandomAlphabetString (int stringSize)
 
int generateRandomNumber (int min, int max)
 
std::string constructTestMimeString (const std::vector< std::shared_ptr< TestMimePart >> &mimeParts, const std::string &boundaryString, bool addPrependedNewline=true)
 
 TEST (OptionalTest, test_createEmptyOptional)
 
 TEST (OptionalTest, test_createOptionalWithValue)
 
 TEST (OptionalTest, test_getValueOfOptionalWithValue)
 
 TEST (OptionalTest, test_getValueOfEmptyOptional)
 
 TEST (OptionalTest, test_functionWithEmptyOptionalReturn)
 
 TEST (OptionalTest, test_functionWithNonEmptyOptionalReturn)
 
 TEST (OptionalTest, test_copyOptionalWithValue)
 
 TEST (OptionalTest, test_copyEmptyOptional)
 
 TEST (OptionalTest, test_setNewValueForEmptyOptional)
 
 TEST (OptionalTest, test_setNewValueForNonEmptyOptional)
 
 TEST (OptionalTest, test_resetEmptyOptional)
 
 TEST (OptionalTest, test_resetNonEmptyOptional)
 
 TEST (OptionalTest, test_optionalObjectWithoutDefaultConstructor)
 
 TEST (OptionalTest, test_constructorCallsMatchDestructorCalls)
 
 TEST (OptionalTest, test_equalityOperator)
 
 TEST (OptionalTest, test_inequalityOperator)
 
 TEST_F (EndianTest, test_SwapEndian16)
 
 TEST_F (EndianTest, test_SwapEndian32)
 

Variables

const std::string METRICS_TAG = ":METRICS:"
 
constexpr const char * ID_RIFF = "RIFF"
 
constexpr const char * ID_WAVE = "WAVE"
 
constexpr const char * ID_FMT = "fmt "
 
constexpr const char * ID_DATA = "data"
 
constexpr uint32_t PCM_SUBCHUNK_SZ = 16
 
constexpr uint16_t FORMAT_PCM = 1
 
constexpr uint16_t BITS_PER_BYTE = 8
 
constexpr uint16_t PLAY_BITS_PER_SAMPLE = 16
 
constexpr uint16_t FORMAT_IEEE_FLOAT = 3
 
constexpr uint32_t FLOAT_SUBCHUNK_SZ = 18
 
constexpr uint32_t FACT_CHUNK_SZ = 4
 
constexpr const char * ID_FACT = "fact"
 
constexpr unsigned int PCM_HEADER_SIZE = 44
 
constexpr unsigned int NON_PCM_HEADER_SIZE = 58
 
constexpr unsigned int RIFF_ID_OFFSET = 0
 
constexpr unsigned int RIFF_SZ_OFFSET = 4
 
constexpr unsigned int RIFF_FMT_OFFSET = 8
 
constexpr unsigned int FMT_ID_OFFSET = 12
 
constexpr unsigned int FMT_SZ_OFFSET = 16
 
constexpr unsigned int AUDIO_FORMAT_OFFSET = 20
 
constexpr unsigned int NUM_CHANNELS_OFFSET = 22
 
constexpr unsigned int SAMPLE_RATE_OFFSET = 24
 
constexpr unsigned int BYTE_RATE_OFFSET = 28
 
constexpr unsigned int BLOCK_ALIGN_OFFSET = 32
 
constexpr unsigned int BITS_PER_SAMPLE_OFFSET = 34
 
constexpr unsigned int DATA_ID_OFFSET = 36
 
constexpr unsigned int DATA_SZ_OFFSET = 40
 
constexpr unsigned int CB_SZ_OFFSET = 36
 
constexpr unsigned int FACT_ID_OFFSET = 38
 
constexpr unsigned int FACT_SZ_OFFSET = 42
 
constexpr unsigned int FACT_SAMPLE_LEN_OFFSET = 46
 
constexpr unsigned int NON_PCM_OFFSET = 14
 
static const std::string MIME_NEWLINE = "\r\n"
 The newline characters that MIME parsers expect. More...
 
static const std::string MIME_BOUNDARY_DASHES = "--"
 The double dashes which may occur before and after a boundary string. More...
 
static const std::string MIME_JSON_PREFIX_STRING = "Content-Type: application/json; charset=UTF-8"
 The MIME text expected before a JSON part. More...
 
static const std::string MIME_ATTACHMENT_PREFIX_STRING = "Content-Type: application/octet-stream"
 The MIME text expected before a binary data part. More...
 
static const std::string MIME_CONTENT_ID_PREFIX_STRING = "Content-ID: "
 The MIME prefix for a content id header. More...
 
static const std::chrono::seconds WAIT_FOR_DIRECTIVE_TIMEOUT_IN_SECONDS = std::chrono::seconds(1)
 Our default timeout when validating if a MIME part was received by another object. More...
 
static const int DUMMY_SDS_BUFFER_SIZE = 100
 A small value so we can create objects with a valid SDS (even if unused). More...
 

Typedef Documentation

◆ ByteVector

using alexaClientSDK::avsCommon::utils::ByteVector = typedef std::vector<unsigned char>

◆ SDSBufferType

◆ SDSType

Enumeration Type Documentation

◆ MediaType

An enum class used to represent the file type of audio data.

Enumerator
MPEG 

Mpeg type audio data.

WAV 

Wav type audio data.

UNKNOWN 

Audio data type not known.

Function Documentation

◆ constructTestMimeString()

std::string alexaClientSDK::avsCommon::utils::constructTestMimeString ( const std::vector< std::shared_ptr< TestMimePart >> &  mimeParts,
const std::string &  boundaryString,
bool  addPrependedNewline = true 
)

A utility function to generate a MIME string.

Parameters
mimePartsA vector of TestMimePart objects, which through polymorphism know how to generate their own substrings.
boundaryStringThe boundary string to be used when generating the MIME string.
addPrependedNewlinetrue if a trailing newline (CRLF) sequence is required, false otherwise.
Returns
The generated MIME string.

◆ createRandomAlphabetString()

std::string alexaClientSDK::avsCommon::utils::createRandomAlphabetString ( int  stringSize)

Utility function to generate a random string of characters between 'a' - 'z'.

Parameters
stringSizeThe length of the string we will create.
Returns
The generated string.

Convert the data into a std::string.

Convert the data into a std::string.

◆ generateRandomNumber()

int alexaClientSDK::avsCommon::utils::generateRandomNumber ( int  min,
int  max 
)

Utility function to generate a random number. This function does not require seeding before use.

Parameters
minThe minimum value in the desired distribution.
maxThe maximum value in the desired distribution.
Returns
The generated number.

Identifier to tell if the random number generated has been initialized

Identifier to tell if the random number generated has been initialized

◆ generateWavHeader()

ByteVector alexaClientSDK::avsCommon::utils::generateWavHeader ( unsigned int  bytesPerSample,
unsigned int  channels,
unsigned int  rate,
std::chrono::milliseconds  totalDuration,
bool  isPCM = true 
)

Generates a WAVE header.

Parameters
bytesPerSampleThe number of bytes per sample.
channelsThe number of channels in the audio data.
rateThe sample rate of the audio data, in blocks per second.
totalDurationThe total duration of the audio data.
isPCMBool indicating if header to generate is PCM format or Non-PCM.
Returns
The ByteVector of the generated WAVE header.

◆ getCoutMutex()

static std::shared_ptr<std::mutex> alexaClientSDK::avsCommon::utils::getCoutMutex ( )
inlinestatic

Get the mutex used to serialize writing to cout.

Returns
The mutex used to serialize writing to cout.

◆ getTypeIndex()

template<typename Type >
TypeIndex alexaClientSDK::avsCommon::utils::getTypeIndex ( )
inline

Get the TypeIndex value for Type.

Template Parameters
TypeThe type for which to create a TypeIndex value.

◆ littleEndianMachine()

bool alexaClientSDK::avsCommon::utils::littleEndianMachine ( )
inline

Function used to check the machine endianness.

◆ logTypeIndex()

template<typename Type >
void alexaClientSDK::avsCommon::utils::logTypeIndex ( const std::string &  name)
inline

Utility function to log a name for a given type. This can be useful when TypeIndex<Type>::getName() does not return a string that is easy to correlate with C++ type names.

Template Parameters
TypeThe type to log
Parameters
nameThe name ot log for the type.

◆ MimeTypeToMediaType()

MediaType alexaClientSDK::avsCommon::utils::MimeTypeToMediaType ( const std::string &  mimetype)
inline

Convert a string file type to MediaType value.

Parameters
mimetypeThe string representation of a file's mimetype.
Returns
MediaType value of file

◆ operator<<() [1/3]

std::ostream& alexaClientSDK::avsCommon::utils::operator<< ( std::ostream &  stream,
const MediaType mediatype 
)
inline

Write an MediaType value to an ostream as a string.

Parameters
streamThe stream to write the value to.
mediatypeThe MediaType value to write to the ostream as a string.
Returns
The ostream that was passed in and written to.

◆ operator<<() [2/3]

std::ostream& alexaClientSDK::avsCommon::utils::operator<< ( std::ostream &  stream,
const AudioFormat::Encoding encoding 
)
inline

Write an Encoding value to an ostream as a string.

Parameters
streamThe stream to write the value to.
encodingThe encoding value to write to the ostream as a string.
Returns
The ostream that was passed in and written to.

◆ operator<<() [3/3]

std::ostream& alexaClientSDK::avsCommon::utils::operator<< ( std::ostream &  stream,
const AudioFormat::Endianness endianness 
)
inline

Write an Endianness value to an ostream as a string.

Parameters
streamThe stream to write the value to.
endiannessThe endianness value to write to the ostream as a string.
Returns
The ostream that was passed in and written to.

◆ readWAVFile()

bool alexaClientSDK::avsCommon::utils::readWAVFile ( const std::string &  absoluteFilePath,
std::vector< uint16_t > *  audioBuffer,
WavHeader wavHeader,
bool  isPCM = true 
)

Reads a .wav file and seperates the audio data from the header data.

Parameters
absoluteFilePathThe path to a file to retrieve the WAVE header from.
audioBufferThe pointer to the audioBuffer vector.
wavHeaderThe WavHeader.
isPCMBool indicating if header to generate is PCM format or Non-PCM.
Returns
true if successful, else false.

◆ swapEndian() [1/2]

uint16_t alexaClientSDK::avsCommon::utils::swapEndian ( uint16_t  input)
inline

◆ swapEndian() [2/2]

uint32_t alexaClientSDK::avsCommon::utils::swapEndian ( uint32_t  input)
inline

◆ TEST() [1/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_createEmptyOptional   
)

◆ TEST() [2/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_createOptionalWithValue   
)

◆ TEST() [3/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_getValueOfOptionalWithValue   
)

◆ TEST() [4/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_getValueOfEmptyOptional   
)

◆ TEST() [5/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_functionWithEmptyOptionalReturn   
)

◆ TEST() [6/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_functionWithNonEmptyOptionalReturn   
)

◆ TEST() [7/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_copyOptionalWithValue   
)

◆ TEST() [8/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_copyEmptyOptional   
)

◆ TEST() [9/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_setNewValueForEmptyOptional   
)

◆ TEST() [10/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_setNewValueForNonEmptyOptional   
)

◆ TEST() [11/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_resetEmptyOptional   
)

◆ TEST() [12/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_resetNonEmptyOptional   
)

◆ TEST() [13/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_optionalObjectWithoutDefaultConstructor   
)

◆ TEST() [14/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_constructorCallsMatchDestructorCalls   
)

◆ TEST() [15/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_equalityOperator   
)

◆ TEST() [16/16]

alexaClientSDK::avsCommon::utils::TEST ( OptionalTest  ,
test_inequalityOperator   
)

◆ TEST_F() [1/2]

alexaClientSDK::avsCommon::utils::TEST_F ( EndianTest  ,
test_SwapEndian16   
)

◆ TEST_F() [2/2]

alexaClientSDK::avsCommon::utils::TEST_F ( EndianTest  ,
test_SwapEndian32   
)

Variable Documentation

◆ AUDIO_FORMAT_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::AUDIO_FORMAT_OFFSET = 20

◆ BITS_PER_BYTE

constexpr uint16_t alexaClientSDK::avsCommon::utils::BITS_PER_BYTE = 8

◆ BITS_PER_SAMPLE_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::BITS_PER_SAMPLE_OFFSET = 34

◆ BLOCK_ALIGN_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::BLOCK_ALIGN_OFFSET = 32

◆ BYTE_RATE_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::BYTE_RATE_OFFSET = 28

◆ CB_SZ_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::CB_SZ_OFFSET = 36

◆ DATA_ID_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::DATA_ID_OFFSET = 36

◆ DATA_SZ_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::DATA_SZ_OFFSET = 40

◆ DUMMY_SDS_BUFFER_SIZE

const int alexaClientSDK::avsCommon::utils::DUMMY_SDS_BUFFER_SIZE = 100
static

A small value so we can create objects with a valid SDS (even if unused).

◆ FACT_CHUNK_SZ

constexpr uint32_t alexaClientSDK::avsCommon::utils::FACT_CHUNK_SZ = 4

◆ FACT_ID_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::FACT_ID_OFFSET = 38

◆ FACT_SAMPLE_LEN_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::FACT_SAMPLE_LEN_OFFSET = 46

◆ FACT_SZ_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::FACT_SZ_OFFSET = 42

◆ FLOAT_SUBCHUNK_SZ

constexpr uint32_t alexaClientSDK::avsCommon::utils::FLOAT_SUBCHUNK_SZ = 18

◆ FMT_ID_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::FMT_ID_OFFSET = 12

◆ FMT_SZ_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::FMT_SZ_OFFSET = 16

◆ FORMAT_IEEE_FLOAT

constexpr uint16_t alexaClientSDK::avsCommon::utils::FORMAT_IEEE_FLOAT = 3

◆ FORMAT_PCM

constexpr uint16_t alexaClientSDK::avsCommon::utils::FORMAT_PCM = 1

◆ ID_DATA

constexpr const char* alexaClientSDK::avsCommon::utils::ID_DATA = "data"

◆ ID_FACT

constexpr const char* alexaClientSDK::avsCommon::utils::ID_FACT = "fact"

◆ ID_FMT

constexpr const char* alexaClientSDK::avsCommon::utils::ID_FMT = "fmt "

◆ ID_RIFF

constexpr const char* alexaClientSDK::avsCommon::utils::ID_RIFF = "RIFF"

◆ ID_WAVE

constexpr const char* alexaClientSDK::avsCommon::utils::ID_WAVE = "WAVE"

◆ METRICS_TAG

const std::string alexaClientSDK::avsCommon::utils::METRICS_TAG = ":METRICS:"

◆ MIME_ATTACHMENT_PREFIX_STRING

const std::string alexaClientSDK::avsCommon::utils::MIME_ATTACHMENT_PREFIX_STRING = "Content-Type: application/octet-stream"
static

The MIME text expected before a binary data part.

◆ MIME_BOUNDARY_DASHES

const std::string alexaClientSDK::avsCommon::utils::MIME_BOUNDARY_DASHES = "--"
static

The double dashes which may occur before and after a boundary string.

◆ MIME_CONTENT_ID_PREFIX_STRING

const std::string alexaClientSDK::avsCommon::utils::MIME_CONTENT_ID_PREFIX_STRING = "Content-ID: "
static

The MIME prefix for a content id header.

◆ MIME_JSON_PREFIX_STRING

const std::string alexaClientSDK::avsCommon::utils::MIME_JSON_PREFIX_STRING = "Content-Type: application/json; charset=UTF-8"
static

The MIME text expected before a JSON part.

◆ MIME_NEWLINE

const std::string alexaClientSDK::avsCommon::utils::MIME_NEWLINE = "\r\n"
static

The newline characters that MIME parsers expect.

◆ NON_PCM_HEADER_SIZE

constexpr unsigned int alexaClientSDK::avsCommon::utils::NON_PCM_HEADER_SIZE = 58

◆ NON_PCM_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::NON_PCM_OFFSET = 14

◆ NUM_CHANNELS_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::NUM_CHANNELS_OFFSET = 22

◆ PCM_HEADER_SIZE

constexpr unsigned int alexaClientSDK::avsCommon::utils::PCM_HEADER_SIZE = 44

◆ PCM_SUBCHUNK_SZ

constexpr uint32_t alexaClientSDK::avsCommon::utils::PCM_SUBCHUNK_SZ = 16

◆ PLAY_BITS_PER_SAMPLE

constexpr uint16_t alexaClientSDK::avsCommon::utils::PLAY_BITS_PER_SAMPLE = 16

◆ RIFF_FMT_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::RIFF_FMT_OFFSET = 8

◆ RIFF_ID_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::RIFF_ID_OFFSET = 0

◆ RIFF_SZ_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::RIFF_SZ_OFFSET = 4

◆ SAMPLE_RATE_OFFSET

constexpr unsigned int alexaClientSDK::avsCommon::utils::SAMPLE_RATE_OFFSET = 24

◆ WAIT_FOR_DIRECTIVE_TIMEOUT_IN_SECONDS

const std::chrono::seconds alexaClientSDK::avsCommon::utils::WAIT_FOR_DIRECTIVE_TIMEOUT_IN_SECONDS = std::chrono::seconds(1)
static

Our default timeout when validating if a MIME part was received by another object.

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0