RDK Documentation (Open Sourced RDK Components)
AampUtils.cpp File Reference

Common utility functions. More...

#include "AampUtils.h"
#include "_base64.h"
#include "AampConfig.h"
#include "AampConstants.h"
#include <sys/time.h>
#include <string.h>
#include <assert.h>
#include <ctime>
#include <curl/curl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fstream>
#include <dirent.h>
#include <algorithm>
Include dependency graph for AampUtils.cpp:

Go to the source code of this file.

Macros

#define DEFER_DRM_LIC_OFFSET_FROM_START   5
 
#define DEFER_DRM_LIC_OFFSET_TO_UPPER_BOUND   5
 
#define MAC_STRING_LEN   12
 
#define URAND_STRING_LEN   16
 
#define RAND_STRING_LEN   (MAC_STRING_LEN + 2*URAND_STRING_LEN)
 
#define MAX_BUFF_LENGTH   4096
 
#define AAMP_AUDIO_FORMAT_MAP_LEN   ARRAY_SIZE(mAudioFormatMap)
 
#define AAMP_VIDEO_FORMAT_MAP_LEN   ARRAY_SIZE(mVideoFormatMap)
 

Enumerations

enum  HarvestConfigType
 Harvest Configuration type. More...
 

Functions

long long aamp_GetCurrentTimeMS (void)
 Get current time from epoch is milliseconds. More...
 
void getDefaultHarvestPath (std::string &value)
 Get harvest path to dump the files.
 
static const char * ParseUriProtocol (const char *uri)
 parse leading protcocol from uri if present More...
 
void aamp_ResolveURL (std::string &dst, std::string base, const char *uri, bool bPropagateUriParams)
 Resolve file URL from the base and file path.
 
bool aamp_IsAbsoluteURL (const std::string &url)
 distinguish between absolute and relative urls More...
 
std::string aamp_getHostFromURL (std::string url)
 Extract host string from url. More...
 
bool aamp_IsLocalHost (std::string Hostname)
 check is local or not from given hostname More...
 
bool aamp_StartsWith (const char *inputStr, const char *prefix)
 Check if string start with a prefix. More...
 
char * aamp_Base64_URL_Encode (const unsigned char *src, size_t len)
 convert blob of binary data to ascii base64-URL-encoded equivalent More...
 
unsigned char * aamp_Base64_URL_Decode (const char *src, size_t *len, size_t srcLen)
 decode base64 URL encoded data to binary equivalent More...
 
void aamp_DecodeUrlParameter (std::string &uriParam)
 unescape uri-encoded uri parameter More...
 
double ISO8601DateTimeToUTCSeconds (const char *ptr)
 Parse date time from ISO8601 string and return value in seconds. More...
 
static size_t MyRpcWriteFunction (void *buffer, size_t size, size_t nmemb, void *context)
 
std::string aamp_PostJsonRPC (std::string id, std::string method, std::string params)
 aamp_PostJsonRPC posts JSONRPC data
 
int aamp_GetDeferTimeMs (long maxTimeSeconds)
 Get time to defer DRM acquisition. More...
 
DRMSystems GetDrmSystem (std::string drmSystemID)
 Get DRM system from ID. More...
 
const char * GetDrmSystemName (DRMSystems drmSystem)
 Get name of DRM system. More...
 
const char * GetDrmSystemID (DRMSystems drmSystem)
 Get ID of DRM system. More...
 
void UrlEncode (std::string inStr, std::string &outStr)
 Encode URL. More...
 
void trim (std::string &src)
 Trim a string.
 
std::string Getiso639map_NormalizeLanguageCode (std::string lang, LangCodePreference preferLangFormat)
 To get the preferred iso639mapped language code. More...
 
struct timespec aamp_GetTimespec (int timeInMs)
 To get the timespec. More...
 
static void createdir (const char *dirpath)
 Inline function to create directory. More...
 
int getHarvestConfigForMedia (MediaType fileType)
 Get harvest config corresponds to Media type. More...
 
bool aamp_WriteFile (std::string fileName, const char *data, size_t len, MediaType &fileType, unsigned int count, const char *prefix)
 Write - file to storage.
 
float getWorkingTrickplayRate (float rate)
 Get compatible trickplay for 6s cadense of iframe track from the given rates.
 
float getPseudoTrickplayRate (float rate)
 Get reverse map the working rates to the rates given by platform player.
 
void stream2hex (const std::string str, std::string &hexstr, bool capital)
 Convert string of chars to its representative string of hex numbers.
 
void mssleep (int milliseconds)
 Sleep for given milliseconds.
 
const char * GetAudioFormatStringForCodec (StreamOutputFormat input)
 
const FormatMapGetAudioFormatForCodec (const char *codecs)
 
const FormatMapGetVideoFormatForCodec (const char *codecs)
 

Variables

const FormatMap mAudioFormatMap []
 
const FormatMap mVideoFormatMap []
 

yes

Common utility functions.

Definition in file AampUtils.cpp.

Enumeration Type Documentation

◆ HarvestConfigType

Harvest Configuration type.

Enumerator
eHARVEST_DISABLE_DEFAULT 

Desable harversting for unknown type

eHARVEST_ENAABLE_VIDEO 

Enable Harvest Video fragments - set 1st bit

eHARVEST_ENAABLE_AUDIO 

Enable Harvest audio - set 2nd bit

eHARVEST_ENAABLE_SUBTITLE 

Enable Harvest subtitle - set 3rd bit

eHARVEST_ENAABLE_AUX_AUDIO 

Enable Harvest auxiliary audio - set 4th bit

eHARVEST_ENAABLE_MANIFEST 

Enable Harvest manifest - set 5th bit

eHARVEST_ENAABLE_LICENCE 

Enable Harvest license - set 6th bit

eHARVEST_ENAABLE_IFRAME 

Enable Harvest iframe - set 7th bit

eHARVEST_ENAABLE_INIT_VIDEO 

Enable Harvest video init fragment - set 8th bit

eHARVEST_ENAABLE_INIT_AUDIO 

Enable Harvest audio init fragment - set 9th bit

eHARVEST_ENAABLE_INIT_SUBTITLE 

Enable Harvest subtitle init fragment - set 10th bit

eHARVEST_ENAABLE_INIT_AUX_AUDIO 

Enable Harvest auxiliary audio init fragment - set 11th bit

eHARVEST_ENAABLE_PLAYLIST_VIDEO 

Enable Harvest video playlist - set 12th bit

eHARVEST_ENAABLE_PLAYLIST_AUDIO 

Enable Harvest audio playlist - set 13th bit

eHARVEST_ENAABLE_PLAYLIST_SUBTITLE 

Enable Harvest subtitle playlist - set 14th bit

eHARVEST_ENAABLE_PLAYLIST_AUX_AUDIO 

Enable Harvest auxiliary audio playlist - set 15th bit

eHARVEST_ENAABLE_PLAYLIST_IFRAME 

Enable Harvest Iframe playlist - set 16th bit

eHARVEST_ENAABLE_INIT_IFRAME 

Enable Harvest IFRAME init fragment - set 17th bit

eHARVEST_ENAABLE_DSM_CC 

Enable Harvest digital storage media command and control (DSM-CC)- set 18th bit

eHARVEST_ENAABLE_DEFAULT 

Harvest unknown - Enable all by default

Definition at line 758 of file AampUtils.cpp.

Function Documentation

◆ aamp_GetCurrentTimeMS()

aamp_GetCurrentTimeMS ( void  )

Get current time from epoch is milliseconds.

Return values
-current time in milliseconds

Definition at line 92 of file AampUtils.cpp.

◆ ParseUriProtocol()

static const char* ParseUriProtocol ( const char *  uri)
static

parse leading protcocol from uri if present

Parameters
[in]urimanifest/ fragment uri
Return values
returnpointer just past protocol (i.e. http://) if present (or) return NULL uri doesn't start with protcol

Definition at line 127 of file AampUtils.cpp.

◆ aamp_IsAbsoluteURL()

bool aamp_IsAbsoluteURL ( const std::string &  url)

distinguish between absolute and relative urls

Returns
true iff url starts with http:// or https://

Definition at line 221 of file AampUtils.cpp.

◆ aamp_getHostFromURL()

std::string aamp_getHostFromURL ( std::string  url)

Extract host string from url.

Return values
hostof input url

Definition at line 232 of file AampUtils.cpp.

◆ aamp_IsLocalHost()

bool aamp_IsLocalHost ( std::string  Hostname)

check is local or not from given hostname

Return values
trueif localhost, false otherwise.

Definition at line 267 of file AampUtils.cpp.

◆ aamp_StartsWith()

bool aamp_StartsWith ( const char *  inputStr,
const char *  prefix 
)

Check if string start with a prefix.

Return values
TRUEif substring is found in bigstring

Definition at line 284 of file AampUtils.cpp.

◆ aamp_Base64_URL_Encode()

char* aamp_Base64_URL_Encode ( const unsigned char *  src,
size_t  len 
)

convert blob of binary data to ascii base64-URL-encoded equivalent

Return values
pointerto malloc'd cstring containing base64 URL encoded version of string
NULLif insufficient memory to allocate base64-URL-encoded copy
Note
caller responsible for freeing returned cstring

Definition at line 304 of file AampUtils.cpp.

◆ aamp_Base64_URL_Decode()

unsigned char* aamp_Base64_URL_Decode ( const char *  src,
size_t *  len,
size_t  srcLen 
)

decode base64 URL encoded data to binary equivalent

Return values
pointerto malloc'd memory containing decoded binary data
NULLif insufficient memory to allocate decoded data
Note
caller responsible for freeing returned data

Definition at line 340 of file AampUtils.cpp.

◆ aamp_DecodeUrlParameter()

void aamp_DecodeUrlParameter ( std::string &  uriParam)

unescape uri-encoded uri parameter

Parameters
uriParamstring to un-escape

Definition at line 366 of file AampUtils.cpp.

◆ ISO8601DateTimeToUTCSeconds()

double ISO8601DateTimeToUTCSeconds ( const char *  ptr)

Parse date time from ISO8601 string and return value in seconds.

Return values
durationMsduration in milliseconds

Definition at line 387 of file AampUtils.cpp.

◆ aamp_GetDeferTimeMs()

int aamp_GetDeferTimeMs ( long  maxTimeSeconds)

Get time to defer DRM acquisition.

Returns
Time in MS to defer DRM acquisition

Definition at line 539 of file AampUtils.cpp.

◆ GetDrmSystem()

DRMSystems GetDrmSystem ( std::string  drmSystemID)

Get DRM system from ID.

Return values
drmSystemdrm system

Definition at line 601 of file AampUtils.cpp.

◆ GetDrmSystemName()

const char* GetDrmSystemName ( DRMSystems  drmSystem)

Get name of DRM system.

Return values
Nameof the DRM system, empty string if not supported

Definition at line 625 of file AampUtils.cpp.

◆ GetDrmSystemID()

const char* GetDrmSystemID ( DRMSystems  drmSystem)

Get ID of DRM system.

Return values
IDof the DRM system, empty string if not supported

Definition at line 649 of file AampUtils.cpp.

◆ UrlEncode()

void UrlEncode ( std::string  inStr,
std::string &  outStr 
)

Encode URL.

Returns
Encoding status

Definition at line 678 of file AampUtils.cpp.

◆ Getiso639map_NormalizeLanguageCode()

std::string Getiso639map_NormalizeLanguageCode ( std::string  lang,
LangCodePreference  preferLangFormat 
)

To get the preferred iso639mapped language code.

Return values
[out]preferred iso639 mapped language.

Definition at line 725 of file AampUtils.cpp.

◆ aamp_GetTimespec()

struct timespec aamp_GetTimespec ( int  timeInMs)

To get the timespec.

Return values
[out]timespec.

Definition at line 741 of file AampUtils.cpp.

◆ createdir()

static void createdir ( const char *  dirpath)
inlinestatic

Inline function to create directory.

Parameters
dirpath- path name

Definition at line 786 of file AampUtils.cpp.

◆ getHarvestConfigForMedia()

int getHarvestConfigForMedia ( MediaType  fileType)

Get harvest config corresponds to Media type.

Returns
harvestType

Definition at line 807 of file AampUtils.cpp.

Variable Documentation

◆ mAudioFormatMap

const FormatMap mAudioFormatMap[]
Initial value:
=
{
{ "mp4a.40.2", FORMAT_AUDIO_ES_AAC },
{ "mp4a.40.5", FORMAT_AUDIO_ES_AAC },
{ "ac-3", FORMAT_AUDIO_ES_AC3 },
{ "mp4a.a5", FORMAT_AUDIO_ES_AC3 },
{ "ac-4.02.01.01", FORMAT_AUDIO_ES_AC4 },
{ "ac-4.02.01.02", FORMAT_AUDIO_ES_AC4 },
{ "ec-3", FORMAT_AUDIO_ES_EC3 },
{ "ec+3", FORMAT_AUDIO_ES_ATMOS },
{ "eac3", FORMAT_AUDIO_ES_EC3 }
}

Definition at line 61 of file AampUtils.cpp.

◆ mVideoFormatMap

const FormatMap mVideoFormatMap[]
Initial value:
=
{
{ "avc1.", FORMAT_VIDEO_ES_H264 },
{ "hvc1.", FORMAT_VIDEO_ES_HEVC },
{ "hev1.", FORMAT_VIDEO_ES_HEVC },
{ "mpeg2v", FORMAT_VIDEO_ES_MPEG2 }
}

Definition at line 78 of file AampUtils.cpp.

FORMAT_VIDEO_ES_HEVC
@ FORMAT_VIDEO_ES_HEVC
Definition: main_aamp.h:117
FORMAT_AUDIO_ES_AAC
@ FORMAT_AUDIO_ES_AAC
Definition: main_aamp.h:111
FORMAT_AUDIO_ES_AC3
@ FORMAT_AUDIO_ES_AC3
Definition: main_aamp.h:112
FORMAT_AUDIO_ES_AC4
@ FORMAT_AUDIO_ES_AC4
Definition: main_aamp.h:115
FORMAT_AUDIO_ES_EC3
@ FORMAT_AUDIO_ES_EC3
Definition: main_aamp.h:113
FORMAT_VIDEO_ES_H264
@ FORMAT_VIDEO_ES_H264
Definition: main_aamp.h:116
FORMAT_AUDIO_ES_ATMOS
@ FORMAT_AUDIO_ES_ATMOS
Definition: main_aamp.h:114
FORMAT_VIDEO_ES_MPEG2
@ FORMAT_VIDEO_ES_MPEG2
Definition: main_aamp.h:118