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

Advanced Adaptive Media Player (AAMP) PrivateInstanceAAMP impl. More...

#include "isobmffprocessor.h"
#include "priv_aamp.h"
#include "AampJsonObject.h"
#include "isobmffbuffer.h"
#include "AampFnLogger.h"
#include "AampConstants.h"
#include "AampCacheHandler.h"
#include "AampUtils.h"
#include "iso639map.h"
#include "fragmentcollector_mpd.h"
#include "admanager_mpd.h"
#include "fragmentcollector_hls.h"
#include "fragmentcollector_progressive.h"
#include "MediaStreamContext.h"
#include "hdmiin_shim.h"
#include "compositein_shim.h"
#include "ota_shim.h"
#include "_base64.h"
#include "base16.h"
#include "aampgstplayer.h"
#include "AampDRMSessionManager.h"
#include "SubtecFactory.hpp"
#include "AampCurlStore.h"
#include <sys/time.h>
#include <cmath>
#include <regex>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <uuid/uuid.h>
#include <string.h>
Include dependency graph for priv_aamp.cpp:

Go to the source code of this file.

Data Structures

struct  gActivePrivAAMP_t
 Used for storing active PrivateInstanceAAMPs. More...
 
struct  CurlCbContextSyncTime
 context during curl callbacks More...
 
struct  _IARM_BUS_NetSrvMgr_Iface_EventData_t
 IARM Bus struct contains active streaming interface, origional definition present in homenetworkingservice.h. More...
 
union  _IARM_BUS_NetSrvMgr_Iface_EventData_t.__unnamed__
 

Macros

#define LOCAL_HOST_IP   "127.0.0.1"
 
#define AAMP_MAX_TIME_BW_UNDERFLOWS_TO_TRIGGER_RETUNE_MS   (20*1000LL)
 
#define AAMP_MAX_TIME_LL_BW_UNDERFLOWS_TO_TRIGGER_RETUNE_MS   (AAMP_MAX_TIME_BW_UNDERFLOWS_TO_TRIGGER_RETUNE_MS/10)
 
#define MAX_DESCRIPTION_SIZE   128
 
#define MACRO_TO_STRING(s)   X_STR(s)
 
#define X_STR(s)   #s
 
#define TRUST_LOCATOR_EXTENSION_IF_PRESENT
 
#define VALIDATE_INT(param_name, param_value, default_value)
 
#define VALIDATE_LONG(param_name, param_value, default_value)
 
#define VALIDATE_DOUBLE(param_name, param_value, default_value)
 
#define CURL_EASY_SETOPT(curl, CURLoption, option)
 
#define FOG_REASON_STRING   "Fog-Reason:"
 
#define CURLHEADER_X_REASON   "X-Reason:"
 
#define BITRATE_HEADER_STRING   "X-Bitrate:"
 
#define CONTENTLENGTH_STRING   "Content-Length:"
 
#define SET_COOKIE_HEADER_STRING   "Set-Cookie:"
 
#define LOCATION_HEADER_STRING   "Location:"
 
#define CONTENT_ENCODING_STRING   "Content-Encoding:"
 
#define FOG_RECORDING_ID_STRING   "Fog-Recording-Id:"
 
#define CAPPED_PROFILE_STRING   "Profile-Capped:"
 
#define TRANSFER_ENCODING_STRING   "Transfer-Encoding:"
 
#define MAX_DOWNLOAD_DELAY_LIMIT_MS   30000
 
#define BITRATEREASON2STRING(id)   BITRATECHANGE_STR[id]
 
#define ADEVENT2STRING(id)   ADEVENT_STR[id - AAMP_EVENT_AD_RESERVATION_START]
 
#define ONE_KILO   1024
 
#define ONE_MEGA   ((1024) * ONE_KILO)
 
#define WV_KID_WORKAROUND   "SkyStoreDE="
 

Typedefs

typedef enum _NetworkManager_EventId_t IARM_Bus_NetworkManager_EventId_t
 Enumeration for net_srv_mgr active interface event callback.
 
typedef struct _IARM_BUS_NetSrvMgr_Iface_EventData_t IARM_BUS_NetSrvMgr_Iface_EventData_t
 

Enumerations

enum  _NetworkManager_EventId_t
 Enumeration for net_srv_mgr active interface event callback.
 

Functions

static guint aamp_GetSourceID ()
 Get the idle task's source ID. More...
 
static gboolean PrivateInstanceAAMP_Resume (gpointer ptr)
 Idle task to resume aamp. More...
 
static gboolean PrivateInstanceAAMP_ProcessDiscontinuity (gpointer ptr)
 Idle task to process discontinuity. More...
 
static gboolean PrivateInstanceAAMP_Retune (gpointer ptr)
 Tune again to currently viewing asset. Used for internal error handling. More...
 
static void SimulateLinearWindow (struct GrowableBuffer *buffer, const char *ptr, size_t len)
 Simulate VOD asset as a "virtual linear" stream.
 
static MediaTypeTelemetry aamp_GetMediaTypeForTelemetry (MediaType type)
 Get the telemetry type for a media type. More...
 
static void DeFog (std::string &url)
 de-fog playback URL to play directly from CDN instead of fog More...
 
static bool replace (std::string &str, const char *existingSubStringToReplace, const char *replacementString)
 replace all occurrences of existingSubStringToReplace in str with replacementString More...
 
void ForceHttpCoversionforFog (std::string &url, const std::string &from, const std::string &to)
 convert https to https in recordedUrl part of manifestUrl More...
 
static bool IsActiveStreamingInterfaceWifi (void)
 Active streaming interface is wifi. More...
 
static int ReadConfigStringHelper (std::string buf, const char *prefixPtr, const char **valueCopyPtr)
 helper function to avoid dependency on unsafe sscanf while reading strings More...
 
template<typename T >
static int ReadConfigNumericHelper (std::string buf, const char *prefixPtr, T &value)
 helper function to extract numeric value from given buf after removing prefix More...
 
static std::string getTimeStamp (time_t epochTime, const char *format="%Y-%m-%dT%H:%M:%S.%f%Z")
 
static time_t convertTimeToEpoch (const char *theTime, const char *format="%Y-%m-%dT%H:%M:%S.%f%Z")
 
static size_t SyncTime_write_callback (char *ptr, size_t size, size_t nmemb, void *userdata)
 write callback to be used by CURL More...
 
static size_t write_callback (char *ptr, size_t size, size_t nmemb, void *userdata)
 write callback to be used by CURL More...
 
static void print_headerResponse (std::vector< std::string > &allResponseHeadersForErrorLogging, MediaType fileType)
 function to print header response during download failure and latency. More...
 
char * ConvertSpeedToStr (long bps, char *str)
 Convert to string and add suffix k, M, G. More...
 
long getCurrentContentDownloadSpeed (PrivateInstanceAAMP *aamp, MediaType fileType, bool bDownloadStart, long start, double dlnow)
 Get Current Content Download Speed. More...
 
static int progress_callback (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
 
static gboolean PrivateInstanceAAMP_PausePosition (gpointer ptr)
 perform pause of the pipeline and notifications for PauseAt functionality
 
static void * PausePositionMonitor (void *arg)
 call the PausePositionMonitoring thread loop
 
static std::string TrackTypeString (const int track)
 track description string from TrackType enum
 
static char * createJsonData (TextTrackInfo &track)
 Create json data from track Info.
 

Variables

static long long simulation_start
 
static char * full_playlist_video_ptr = NULL
 
static size_t full_playlist_video_len = 0
 
static char * full_playlist_audio_ptr = NULL
 
static size_t full_playlist_audio_len = 0
 
static std::list< gActivePrivAAMP_tgActivePrivAAMPs = std::list<gActivePrivAAMP_t>()
 
static pthread_mutex_t gMutex = PTHREAD_MUTEX_INITIALIZER
 
static pthread_cond_t gCond = PTHREAD_COND_INITIALIZER
 
static int PLAYERID_CNTR = 0
 
static const char * strAAMPPipeName = "/tmp/ipc_aamp"
 
static bool activeInterfaceWifi = false
 
static char previousInterface [20] = {'\0'}
 
static unsigned int ui32CurlTrace = 0
 
static TuneFailureMap tuneFailureMap []
 
static constexpr const char * BITRATECHANGE_STR []
 
static constexpr const char * ADEVENT_STR []
 
static constexpr const char * mMediaFormatName []
 

yes

Advanced Adaptive Media Player (AAMP) PrivateInstanceAAMP impl.

Definition in file priv_aamp.cpp.


Data Structure Documentation

◆ gActivePrivAAMP_t

struct gActivePrivAAMP_t

Used for storing active PrivateInstanceAAMPs.

Definition at line 142 of file priv_aamp.cpp.

Collaboration diagram for gActivePrivAAMP_t:
Collaboration graph
Data Fields
PrivateInstanceAAMP * pAAMP
bool reTune
int numPtsErrors

Macro Definition Documentation

◆ VALIDATE_INT

#define VALIDATE_INT (   param_name,
  param_value,
  default_value 
)
Value:
if ((param_value <= 0) || (param_value > INT_MAX)) { \
AAMPLOG_WARN("Parameter '%s' not within INTEGER limit. Using default value instead.", param_name); \
param_value = default_value; \
}

Definition at line 91 of file priv_aamp.cpp.

◆ VALIDATE_LONG

#define VALIDATE_LONG (   param_name,
  param_value,
  default_value 
)
Value:
if ((param_value <= 0) || (param_value > LONG_MAX)) { \
AAMPLOG_WARN("Parameter '%s' not within LONG INTEGER limit. Using default value instead.", param_name); \
param_value = default_value; \
}

Definition at line 97 of file priv_aamp.cpp.

◆ VALIDATE_DOUBLE

#define VALIDATE_DOUBLE (   param_name,
  param_value,
  default_value 
)
Value:
if ((param_value <= 0) || (param_value > DBL_MAX)) { \
AAMPLOG_WARN("Parameter '%s' not within DOUBLE limit. Using default value instead.", param_name); \
param_value = default_value; \
}

Definition at line 103 of file priv_aamp.cpp.

◆ CURL_EASY_SETOPT

#define CURL_EASY_SETOPT (   curl,
  CURLoption,
  option 
)
Value:
if (curl_easy_setopt(curl, CURLoption, option) != 0) {\
logprintf("Failed at curl_easy_setopt ");\
}

Definition at line 109 of file priv_aamp.cpp.

Function Documentation

◆ aamp_GetSourceID()

static guint aamp_GetSourceID ( )
static

Get the idle task's source ID.

Return values
sourceID

Definition at line 284 of file priv_aamp.cpp.

◆ PrivateInstanceAAMP_Resume()

static gboolean PrivateInstanceAAMP_Resume ( gpointer  ptr)
static

Idle task to resume aamp.

Parameters
ptrpointer to PrivateInstanceAAMP object
Return values
True/False

Definition at line 300 of file priv_aamp.cpp.

◆ PrivateInstanceAAMP_ProcessDiscontinuity()

static gboolean PrivateInstanceAAMP_ProcessDiscontinuity ( gpointer  ptr)
static

Idle task to process discontinuity.

Parameters
ptrpointer to PrivateInstanceAAMP object
Return values
G_SOURCE_REMOVE

Definition at line 341 of file priv_aamp.cpp.

◆ PrivateInstanceAAMP_Retune()

static gboolean PrivateInstanceAAMP_Retune ( gpointer  ptr)
static

Tune again to currently viewing asset. Used for internal error handling.

Parameters
ptrpointer to PrivateInstanceAAMP object
Return values
G_SOURCE_REMOVE

Definition at line 367 of file priv_aamp.cpp.

◆ aamp_GetMediaTypeForTelemetry()

static MediaTypeTelemetry aamp_GetMediaTypeForTelemetry ( MediaType  type)
static

Get the telemetry type for a media type.

Parameters
typemedia type
Return values
telemetrytype

Definition at line 491 of file priv_aamp.cpp.

◆ DeFog()

static void DeFog ( std::string &  url)
static

de-fog playback URL to play directly from CDN instead of fog

Parameters
[in]

Definition at line 532 of file priv_aamp.cpp.

◆ replace()

static bool replace ( std::string &  str,
const char *  existingSubStringToReplace,
const char *  replacementString 
)
static

replace all occurrences of existingSubStringToReplace in str with replacementString

Parameters
strstring to be scanned/modified
existingSubStringToReplacesubstring to be replaced
replacementStringstring to be substituted
Return values
trueiff str was modified

Definition at line 556 of file priv_aamp.cpp.

◆ ForceHttpCoversionforFog()

void ForceHttpCoversionforFog ( std::string &  url,
const std::string &  from,
const std::string &  to 
)

convert https to https in recordedUrl part of manifestUrl

Parameters
[in]

Definition at line 621 of file priv_aamp.cpp.

◆ IsActiveStreamingInterfaceWifi()

static bool IsActiveStreamingInterfaceWifi ( void  )
static

Active streaming interface is wifi.

Returns
bool - true if wifi interface connected

Definition at line 636 of file priv_aamp.cpp.

◆ ReadConfigStringHelper()

static int ReadConfigStringHelper ( std::string  buf,
const char *  prefixPtr,
const char **  valueCopyPtr 
)
static

helper function to avoid dependency on unsafe sscanf while reading strings

Parameters
bufpointer to CString buffer to scan
prefixPtr- prefix string to match in bufPtr
valueCopyPtrreceives allocated copy of string following prefix (skipping delimiting whitesace) if prefix found
Return values
0if prefix not present or error
1if string extracted/copied to valueCopyPtr

Definition at line 667 of file priv_aamp.cpp.

◆ ReadConfigNumericHelper()

template<typename T >
static int ReadConfigNumericHelper ( std::string  buf,
const char *  prefixPtr,
T &  value 
)
static

helper function to extract numeric value from given buf after removing prefix

Parameters
bufString buffer to scan
prefixPtr- prefix string to match in bufPtr
value- receives numeric value after extraction
Return values
0if prefix not present or error
1if string converted to numeric value

Definition at line 696 of file priv_aamp.cpp.

◆ SyncTime_write_callback()

static size_t SyncTime_write_callback ( char *  ptr,
size_t  size,
size_t  nmemb,
void *  userdata 
)
static

write callback to be used by CURL

Parameters
ptrpointer to buffer containing the data
sizesize of the buffer
nmembnumber of bytes
userdataCurlCallbackContext pointer
Return values
sizeconsumed or 0 if interrupted

Definition at line 755 of file priv_aamp.cpp.

◆ write_callback()

static size_t write_callback ( char *  ptr,
size_t  size,
size_t  nmemb,
void *  userdata 
)
static

write callback to be used by CURL

Parameters
ptrpointer to buffer containing the data
sizesize of the buffer
nmembnumber of bytes
userdataCurlCallbackContext pointer
Return values
sizeconsumed or 0 if interrupted

Definition at line 830 of file priv_aamp.cpp.

◆ print_headerResponse()

static void print_headerResponse ( std::vector< std::string > &  allResponseHeadersForErrorLogging,
MediaType  fileType 
)
static

function to print header response during download failure and latency.

Parameters
fileTypecurrent media type

Definition at line 844 of file priv_aamp.cpp.

◆ ConvertSpeedToStr()

char* ConvertSpeedToStr ( long  bps,
char *  str 
)

Convert to string and add suffix k, M, G.

Parameters
bpsbytes Speed
strptr String buffer
Return values
ptrConverted String buffer

Definition at line 1020 of file priv_aamp.cpp.

◆ getCurrentContentDownloadSpeed()

long getCurrentContentDownloadSpeed ( PrivateInstanceAAMP aamp,
MediaType  fileType,
bool  bDownloadStart,
long  start,
double  dlnow 
)

Get Current Content Download Speed.

Parameters
aampptr aamp context
fileTypeFile Type
bDownloadStartDownload start flag
startDownload start time
dlnowcurrent downloaded bytes
Return values
bpsbits per second

Definition at line 1050 of file priv_aamp.cpp.

◆ progress_callback()

static int progress_callback ( void *  clientp,
double  dltotal,
double  dlnow,
double  ultotal,
double  ulnow 
)
static
Parameters
clientpapp-specific as optionally set with CURLOPT_PROGRESSDATA
dltotaltotal bytes expected to download
dlnowdownloaded bytes so far
ultotaltotal bytes expected to upload
ulnowuploaded bytes so far
Return values

Definition at line 1260 of file priv_aamp.cpp.

Variable Documentation

◆ simulation_start

long long simulation_start
static

New state for treating a VOD asset as a "virtual linear" stream

Definition at line 131 of file priv_aamp.cpp.

◆ BITRATECHANGE_STR

constexpr const char* BITRATECHANGE_STR[]
staticconstexpr
Initial value:
=
{
(const char *)"BitrateChanged - Network adaptation",
(const char *)"BitrateChanged - Rampdown due to network failure",
(const char *)"BitrateChanged - Reset to default bitrate due to tune",
(const char *)"BitrateChanged - Reset to default bitrate due to seek",
(const char *)"BitrateChanged - Reset to default bitrate due to trickplay",
(const char *)"BitrateChanged - Rampup since buffers are full",
(const char *)"BitrateChanged - Rampdown since buffers are empty",
(const char *)"BitrateChanged - Network adaptation by FOG",
(const char *)"BitrateChanged - Information from OTA",
(const char *)"BitrateChanged - Video stream information from HDMIIN",
(const char *)"BitrateChanged - Unknown reason"
}

Definition at line 245 of file priv_aamp.cpp.

◆ ADEVENT_STR

constexpr const char* ADEVENT_STR[]
staticconstexpr
Initial value:
=
{
(const char *)"AAMP_EVENT_AD_RESERVATION_START",
(const char *)"AAMP_EVENT_AD_RESERVATION_END",
(const char *)"AAMP_EVENT_AD_PLACEMENT_START",
(const char *)"AAMP_EVENT_AD_PLACEMENT_END",
(const char *)"AAMP_EVENT_AD_PLACEMENT_ERROR",
(const char *)"AAMP_EVENT_AD_PLACEMENT_PROGRESS"
}

Definition at line 262 of file priv_aamp.cpp.

◆ mMediaFormatName

constexpr const char* mMediaFormatName[]
staticconstexpr
Initial value:
=
{
"HLS","DASH","PROGRESSIVE","HLS_MP4","OTA","HDMI_IN","COMPOSITE_IN","SMOOTH_STREAMING", "RMF", "UNKNOWN"
}

Definition at line 274 of file priv_aamp.cpp.