Skip to content

Commit a93313d

Browse files
committed
VPLAY-12213: ABR Refactoring part 3 - encapsulate remaining abr logic inside abr.cpp
Reason for change: To encapsulate all ABR related logic inside abr.cpp and abr.h. This will help in future to add/remove different bandwidth estimation algorithms without affecting other parts of the code. Risks: Low Test Procedure: Test with Linear and VOD Priority: P1 Signed-off-by: Nandakishor U M <[email protected]>
1 parent 4797f77 commit a93313d

29 files changed

+1292
-727
lines changed

AampConfig.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "PlayerRfc.h"
3232
#include "PlayerExternalsInterface.h"
3333
#include "PlayerSecInterface.h"
34+
#include "abr.h"
3435
#include <time.h>
3536
#include <map>
3637
//////////////// CAUTION !!!! STOP !!! Read this before you proceed !!!!!!! /////////////
@@ -84,6 +85,7 @@ typedef enum
8485
eCONFIG_RANGE_MONITOR_AVSYNC_THRESHOLD_POSITIVE, //1ms to 10000ms
8586
eCONFIG_RANGE_MONITOR_AVSYNC_THRESHOLD_NEGATIVE, //-1 to -10000ms
8687
eCONFIG_RANGE_MONITOR_AVSYNC_JUMP_THRESHOLD,//1ms to 10000
88+
eCONFIG_RANGE_ABR_BANDWIDTH_ESTIMATOR, // BandwidthEstimatorType enum range
8789
eCONFIG_RANGE_MAX_VALUE,
8890
} ConfigValidRange;
8991
#define CONFIG_RANGE_ENUM_COUNT (eCONFIG_RANGE_MAX_VALUE)
@@ -127,6 +129,7 @@ static const struct
127129
{ MIN_MONITOR_AVSYNC_POSITIVE_DELTA_MS, MAX_MONITOR_AVSYNC_POSITIVE_DELTA_MS, eCONFIG_RANGE_MONITOR_AVSYNC_THRESHOLD_POSITIVE},
128130
{ MIN_MONITOR_AVSYNC_NEGATIVE_DELTA_MS, MAX_MONITOR_AVSYNC_NEGATIVE_DELTA_MS, eCONFIG_RANGE_MONITOR_AVSYNC_THRESHOLD_NEGATIVE},
129131
{ MIN_MONITOR_AV_JUMP_THRESHOLD_MS, MAX_MONITOR_AV_JUMP_THRESHOLD_MS, eCONFIG_RANGE_MONITOR_AVSYNC_JUMP_THRESHOLD},
132+
{ BANDWIDTH_ESTIMATOR_TYPE_ROLLING_MEDIAN_OUTLIER, BANDWIDTH_ESTIMATOR_TYPE_MAX, eCONFIG_RANGE_ABR_BANDWIDTH_ESTIMATOR},
130133
};
131134

132135
static ConfigPriority customOwner;
@@ -470,7 +473,7 @@ static const ConfigLookupEntryInt mConfigLookupTableInt[AAMPCONFIG_INT_COUNT+CON
470473
{DEFAULT_PROGRESS_LOGGING_DIVISOR,"progressLoggingDivisor",eAAMPConfig_ProgressLoggingDivisor,false},
471474
{DEFAULT_MONITOR_AV_REPORTING_INTERVAL, "monitorAVReportingInterval", eAAMPConfig_MonitorAVReportingInterval, false},
472475
{DEFAULT_UTC_SYNC_MIN_INTERVAL_SEC,"utcSyncMinIntervalSec",eAAMPConfig_UTCSyncMinIntervalSec,true },
473-
476+
{BANDWIDTH_ESTIMATOR_TYPE_ROLLING_MEDIAN_OUTLIER, "abrBandwidthEstimator", eAAMPConfig_ABRBandwidthEstimator, false, eCONFIG_RANGE_ABR_BANDWIDTH_ESTIMATOR},
474477
// Add new integer config entries above this line, before the aliases section.
475478
//
476479
// Aliases, kept for backwards compatibility

AampConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ typedef enum
313313
eAAMPConfig_ProgressLoggingDivisor, /**< Divisor to avoid printing the progress report too frequently in the log */
314314
eAAMPConfig_MonitorAVReportingInterval, /**< Timeout in milliseconds for reporting MonitorAV events */
315315
eAAMPConfig_UTCSyncMinIntervalSec, /**< Minimum interval between sync attempts */
316+
eAAMPConfig_ABRBandwidthEstimator, /**< Select ABR bandwidth estimator */
316317
eAAMPConfig_IntMaxValue /**< Max value of int config always last element*/
317318
} AAMPConfigSettingInt;
318319
#define AAMPCONFIG_INT_COUNT (eAAMPConfig_IntMaxValue)

AampDefine.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,5 +361,12 @@ enum EOSInjectionModeCode
361361
EOS_INJECTION_MODE_STOP_ONLY,
362362
};
363363

364+
enum BandwidthEstimatorType
365+
{
366+
BANDWIDTH_ESTIMATOR_TYPE_ROLLING_MEDIAN_OUTLIER,
367+
BANDWIDTH_ESTIMATOR_TYPE_HARMONIC_EWMA,
368+
BANDWIDTH_ESTIMATOR_TYPE_MAX
369+
};
370+
364371
#endif
365372

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ set(LIBAAMP_SOURCES
389389
AampCMCDCollector.cpp AampCMCDCollector.h
390390
downloader/AampCurlDownloader.cpp downloader/AampCurlDownloader.h
391391
ID3Metadata.cpp ID3Metadata.hpp
392-
abr/abr.cpp abr/abr.h abr/NetworkBandwidthEstimator.cpp abr/NetworkBandwidthEstimator.h
392+
abr/abr.cpp abr/abr.h
393+
abr/RMOBandwidthEstimator.cpp abr/RMOBandwidthEstimator.h
394+
abr/HarmonicEWMAEstimator.cpp abr/HarmonicEWMAEstimator.h
393395
dash/xml/DomDocument.cpp
394396
dash/xml/DomElement.cpp
395397
dash/xml/DomNode.cpp
@@ -586,6 +588,9 @@ install(FILES
586588
LangCodePreference.h StreamOutputFormat.h VideoZoomMode.h StreamSink.h TimedMetadata.h
587589
AampDemuxDataTypes.h
588590
abr/abr.h
591+
abr/RMOBandwidthEstimator.h
592+
abr/HarmonicEWMAEstimator.h
593+
abr/BandwidthEstimatorBase.h
589594
DESTINATION include
590595
)
591596

abr/BandwidthEstimatorBase.h

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* If not stated otherwise in this file or this component's license file the
3+
* following copyright and licenses apply:
4+
*
5+
* Copyright 2026 RDK Management
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
#ifndef AAMP_ABR_BANDWIDTH_ESTIMATOR_BASE_H
20+
#define AAMP_ABR_BANDWIDTH_ESTIMATOR_BASE_H
21+
22+
#include <cstddef>
23+
24+
#include "AampMediaType.h"
25+
26+
/**
27+
* @brief Plain Old Data (POD) structure for profiling information from a
28+
* given CURL instance.
29+
*/
30+
struct DownloadMetrics
31+
{
32+
std::size_t m_size_download_bytes; // CURLINFO_SIZE_DOWNLOAD
33+
double m_total_time_seconds; // CURLINFO_TOTAL_TIME
34+
double m_time_to_first_byte_seconds; // CURLINFO_STARTTRANSFER_TIME
35+
};
36+
37+
/**
38+
* @brief POD structure for in-flight progress updates (xferinfo-style).
39+
*/
40+
struct DownloadProgressInfo
41+
{
42+
double m_now_seconds;
43+
std::size_t m_total_bytes;
44+
std::size_t m_now_bytes;
45+
};
46+
47+
/**
48+
* @brief Base interface for bandwidth estimation algorithms.
49+
*/
50+
class BandwidthEstimatorBase
51+
{
52+
public:
53+
virtual ~BandwidthEstimatorBase() {}
54+
55+
/**
56+
* @brief Human-readable algorithm name.
57+
*/
58+
virtual const char* GetNetworkEstimatorName() const = 0;
59+
60+
/**
61+
* @brief Reset all internal state.
62+
*/
63+
virtual void Reset() = 0;
64+
65+
/**
66+
* @brief Add a bandwidth sample (bits per second).
67+
*/
68+
virtual void AddBandwidthSample(
69+
BitsPerSecond downloadbps, bool lowLatencyMode) = 0;
70+
71+
/**
72+
* @brief Add download metrics derived from curl (optional).
73+
*/
74+
virtual void UpdateDownloadMetrics( const DownloadMetrics &metrics ) = 0;
75+
76+
/**
77+
* @brief Provide in-flight download progress updates (optional).
78+
*/
79+
virtual void UpdateDownloadProgress(
80+
const DownloadProgressInfo &progressInfo)
81+
{
82+
(void)progressInfo;
83+
}
84+
85+
/**
86+
* @brief Return current bandwidth estimate (bits per second).
87+
*
88+
* @return Estimated bandwidth in bits per second, or -1 if unavailable.
89+
*/
90+
virtual BitsPerSecond GetBandwidthBitsPerSecond() = 0;
91+
92+
/**
93+
* @brief Return current robust throughput estimate (bytes/s).
94+
*/
95+
virtual double GetThroughputBytesPerSecond() = 0;
96+
97+
/**
98+
* @brief Return current overhead (TTFB) estimate (seconds).
99+
*/
100+
virtual double GetTimeToFirstByteSeconds() = 0;
101+
102+
/**
103+
* @brief Predict completion time for a new segment.
104+
*/
105+
virtual double GetPredictedDownloadTimeSeconds(
106+
std::size_t segment_size_bytes) = 0;
107+
};
108+
109+
#endif

0 commit comments

Comments
 (0)