Skip to content

Commit 98ecf34

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 98ecf34

29 files changed

+1655
-772
lines changed

AampConfig.cpp

Lines changed: 2 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 !!!!!!! /////////////
@@ -470,7 +471,7 @@ static const ConfigLookupEntryInt mConfigLookupTableInt[AAMPCONFIG_INT_COUNT+CON
470471
{DEFAULT_PROGRESS_LOGGING_DIVISOR,"progressLoggingDivisor",eAAMPConfig_ProgressLoggingDivisor,false},
471472
{DEFAULT_MONITOR_AV_REPORTING_INTERVAL, "monitorAVReportingInterval", eAAMPConfig_MonitorAVReportingInterval, false},
472473
{DEFAULT_UTC_SYNC_MIN_INTERVAL_SEC,"utcSyncMinIntervalSec",eAAMPConfig_UTCSyncMinIntervalSec,true },
473-
474+
{DEFAULT_ABR_BANDWIDTH_ESTIMATOR_TYPE, "abrBandwidthEstimator", eAAMPConfig_ABRBandwidthEstimator, false, eCONFIG_RANGE_ANY},
474475
// Add new integer config entries above this line, before the aliases section.
475476
//
476477
// 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#define DEFAULT_BUFFER_HEALTH_MONITOR_INTERVAL 5
6161
#define DEFAULT_ABR_CACHE_LENGTH 3 /**< Default ABR cache length */
6262
#define DEFAULT_ABR_BUFFER_COUNTER 4 /**< Default ABR Buffer Counter */
63+
#define DEFAULT_ABR_BANDWIDTH_ESTIMATOR_TYPE 0 /**< Default ABR Bandwidth Estimator Type */
6364
#define DEFAULT_REPORT_PROGRESS_INTERVAL 1 /**< Progress event reporting interval: 1sec */
6465
#define DEFAULT_PROGRESS_LOGGING_DIVISOR 4 /**< Divisor of progress logging frequency to print logging */
6566
#define DEFAULT_LICENSE_REQ_RETRY_WAIT_TIME 500 /**< Wait time in milliseconds before retrying for DRM license */

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: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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 Optional configuration for bandwidth estimators.
49+
*
50+
* Not all estimators use every field. Estimators that do not support
51+
* configuration should ignore it.
52+
*/
53+
struct BandwidthEstimatorConfig
54+
{
55+
int mAbrCacheLife;
56+
int mAbrCacheLength;
57+
int mAbrCacheOutlier;
58+
std::size_t mLowLatencyCacheLength;
59+
60+
BandwidthEstimatorConfig()
61+
: mAbrCacheLife(0),
62+
mAbrCacheLength(0),
63+
mAbrCacheOutlier(0),
64+
mLowLatencyCacheLength(0)
65+
{
66+
}
67+
68+
BandwidthEstimatorConfig(
69+
int abrCacheLife,
70+
int abrCacheLength,
71+
int abrCacheOutlier,
72+
std::size_t lowLatencyCacheLength)
73+
: mAbrCacheLife(abrCacheLife),
74+
mAbrCacheLength(abrCacheLength),
75+
mAbrCacheOutlier(abrCacheOutlier),
76+
mLowLatencyCacheLength(lowLatencyCacheLength)
77+
{
78+
}
79+
};
80+
81+
/**
82+
* @brief Base interface for bandwidth estimation algorithms.
83+
*/
84+
class BandwidthEstimatorBase
85+
{
86+
public:
87+
virtual ~BandwidthEstimatorBase() {}
88+
89+
/**
90+
* @brief Human-readable algorithm name.
91+
*/
92+
virtual const char* GetNetworkEstimatorName() const = 0;
93+
94+
/**
95+
* @brief Reset all internal state.
96+
*/
97+
virtual void Reset() = 0;
98+
99+
/**
100+
* @brief Add a bandwidth sample (bits per second).
101+
*/
102+
virtual void AddBandwidthSample(BitsPerSecond downloadbps, bool lowLatencyMode) = 0;
103+
104+
/**
105+
* @brief Add download metrics derived from curl (optional).
106+
*/
107+
virtual void UpdateDownloadMetrics(const DownloadMetrics &metrics ) = 0;
108+
109+
/**
110+
* @brief Provide in-flight download progress updates (optional).
111+
*/
112+
virtual void UpdateDownloadProgress(const DownloadProgressInfo &progressInfo)
113+
{
114+
}
115+
116+
/**
117+
* @brief Update estimator configuration (optional).
118+
*
119+
* Default implementation is a no-op.
120+
*/
121+
virtual void SetConfig(const BandwidthEstimatorConfig &config)
122+
{
123+
}
124+
125+
/**
126+
* @brief Return current bandwidth estimate (bits per second).
127+
*
128+
* @return Estimated bandwidth in bits per second, or -1 if unavailable.
129+
*/
130+
virtual BitsPerSecond GetBandwidthBitsPerSecond() = 0;
131+
132+
/**
133+
* @brief Return current robust throughput estimate (bytes/s).
134+
*/
135+
virtual double GetThroughputBytesPerSecond() = 0;
136+
137+
/**
138+
* @brief Return current overhead (TTFB) estimate (seconds).
139+
*/
140+
virtual double GetTimeToFirstByteSeconds() = 0;
141+
142+
/**
143+
* @brief Predict completion time for a new segment.
144+
*/
145+
virtual double GetPredictedDownloadTimeSeconds(std::size_t segment_size_bytes) = 0;
146+
147+
/**
148+
* @brief Reset only the currently available bandwidth estimate.
149+
*/
150+
virtual void ResetCurrentlyAvailableBandwidth()
151+
{
152+
}
153+
};
154+
155+
#endif

0 commit comments

Comments
 (0)