VPAAMP-261: AAMP_EVENT_TUNE_TIME_METRICS dispatched before PLAYING state event#1485
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes the tune-time metrics dispatch flow so AAMP_EVENT_TUNE_TIME_METRICS is emitted after the player transitions to PLAYING, by deferring event dispatch until MonitorProgress() observes eSTATE_PLAYING. It also refactors the tune-metrics event/profiler interfaces to pass/move the JSON payload more directly.
Changes:
- Queue tune-time metrics JSON in
PrivateInstanceAAMPand dispatch it fromMonitorProgress()once the state isPLAYING(with a TuneFail fallback path). - Update
TuneTimeMetricsEventto take the metrics JSON by value and move it into the event object. - Simplify
GetTuneTimeMetricAsJson()signature by removing the explicitlicenseAcqNWTimeparameter and deriving it from existing buckets.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
priv_aamp.cpp |
Defers tune metrics event dispatch to MonitorProgress() when state becomes PLAYING; updates TuneFail/LogTuneComplete behavior; adds additional state-transition logs. |
priv_aamp.h |
Updates SendTuneMetricsEvent() signature and adds mTuneTimeMetricData storage for deferred dispatch. |
AampEvent.h |
Changes TuneTimeMetricsEvent constructor to take JSON payload by value (movable). |
AampEvent.cpp |
Implements the updated TuneTimeMetricsEvent constructor using move semantics. |
AampProfiler.h |
Updates GetTuneTimeMetricAsJson() signature to remove licenseAcqNWTime. |
AampProfiler.cpp |
Computes lnw from PROFILE_BUCKET_LA_NETWORK directly and updates callers accordingly. |
test/utests/fakes/FakeAampEvent.cpp |
Updates fake TuneTimeMetricsEvent constructor to match the new signature and move behavior. |
test/utests/tests/PrivAampTests/PrivAampTests.cpp |
Adjusts the SendTuneMetricsEventTest call site to the new signature. |
test/utests/tests/AampProfilerTests/AampProfilerTests.cpp |
Updates the GetTuneTimeMetricAsJsonTest call site to the new signature. |
Comments suppressed due to low confidence (2)
priv_aamp.cpp:3388
- SendTuneMetricsEvent() relies on std::move(mTuneTimeMetricData) to "automatically" clear the member and uses empty() elsewhere to ensure the event is sent only once. A moved-from std::string is only guaranteed to be valid, not empty, so this can lead to duplicate sends or stale data. Use an explicit reset (e.g., exchange with an empty string and move the exchanged value into the event) so the member is deterministically cleared after dispatch.
// mTuneTimeMetricData is moved to constructor which automatically clears the mTuneTimeMetricData
// after sending the event, so that next tune will have fresh data and avoid any confusion.
TuneTimeMetricsEventPtr e = std::make_shared<TuneTimeMetricsEvent>(std::move(mTuneTimeMetricData), GetSessionId());
AAMPLOG_TRACE("PrivateInstanceAAMP: Sending TuneTimeMetric event: %s", e->getTuneMetricsData().c_str());
SendEvent(e,AAMP_EVENT_ASYNC_MODE);
priv_aamp.cpp:4129
- mTuneTimeMetricData is only populated via profiler.TuneEnd() when mManifestUrl != FAKE_TUNE_URL, but SendTuneMetricsEvent() is still called whenever eventAvailStatus is true. Because mTuneTimeMetricData persists across tunes, this can dispatch stale metrics from a previous tune (or an empty string) in the FAKE_TUNE_URL path. Clear mTuneTimeMetricData at the start of tune-end handling (TuneFail/LogTuneComplete and/or tune start), and consider only sending the event when the freshly-generated JSON string is non-empty.
if(mManifestUrl != FAKE_TUNE_URL)
{
profiler.TuneEnd(mTuneMetrics, mAppName,(mbPlayEnabled?STRFGPLAYER:STRBGPLAYER), mPlayerId, mPlayerPreBuffered, durationSeconds, activeInterfaceWifi, mFailureReason, eventAvailStatus ? &mTuneTimeMetricData : NULL);
}
if (eventAvailStatus)
{
// Send the tune time metrics event as the progress event might not fire here.
SendTuneMetricsEvent();
}
e621119 to
13c7e58
Compare
13c7e58 to
4d297db
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
priv_aamp.cpp:4134
- TuneFail sets mTuneMetricDataPending and immediately calls SendTuneMetricsEvent(), while MonitorProgress() can also call SendTuneMetricsEvent() when it sees the pending flag. With only load()/store() this can race and/or dispatch the tune-metrics event twice (and concurrently move from mTuneTimeMetricData). Use an atomic exchange-style check (e.g., if (mTuneMetricDataPending.exchange(false)) ...) around the send path, and synchronize access to mTuneTimeMetricData so only one thread consumes it.
bool eventAvailStatus = IsEventListenerAvailable(AAMP_EVENT_TUNE_TIME_METRICS);
profiler.TuneEnd(mTuneMetrics, mAppName,(mbPlayEnabled?STRFGPLAYER:STRBGPLAYER), mPlayerId, mPlayerPreBuffered, durationSeconds, activeInterfaceWifi, mFailureReason, eventAvailStatus ? &mTuneTimeMetricData : NULL);
if (eventAvailStatus)
{
mTuneMetricDataPending.store(true);
// Send the tune time metrics event as the progress event will not fire here.
SendTuneMetricsEvent();
}
4d297db to
cae50ff
Compare
…GED(PLAYING) Reason for change: Sent the tunetime metrics event from the progress callback to time it always after the player has moved to PLAYING state. In TuneFailure case, it will be sent during Stop call. PLAYING state event is used by VIPA and EPG to measure total tune time and hence should not be delayed. Test Procedure: Confirm from logs that tune time metrics event is sent after state=PLAYING event in tune success. Ensure the event is still sent in tune fail case Risks: Low Signed-off-by: Vinish100 <vinish.balan@gmail.com>
cae50ff to
f0b90ef
Compare
jfagunde
reviewed
May 29, 2026
- priv_aamp.cpp: move mTuneMetricDataPending.load() guard inside
SendTuneMetricsEvent() so the check lives in one place; remove
redundant outer guard at the progress-event call site
- priv_aamp.cpp: collapse if(eventAvailStatus){store(true)} patterns
at LogTuneFailure and LogTuneComplete sites to store(eventAvailStatus)
- priv_aamp.cpp: add centralised AAMPLOG_MIL state-transition log in
SetState(); remove per-site redundant log at first-frame call site
- AampEvent.h / AampEvent.cpp / FakeAampEvent.cpp: change
TuneTimeMetricsEvent tuneMetricData parameter to rvalue reference (&&)
- AampProfiler.h: expand GetTuneTimeMetricAsJson @return doc comment
to describe the JSON object and all its keys
jfagunde
approved these changes
May 29, 2026
…rameter std::move() the lvalue timeMetricData at the call site in AampEventTests SetUp() to match the updated TuneTimeMetricsEvent constructor signature which takes tuneMetricData as std::string &&.
…ange
After the constructor was changed to take tuneMetricData as std::string&&,
std::move(timeMetricData) in SetUp() left the member in a moved-from (empty)
state, causing both Constructor and GetTuneMetricsData assertions to compare
against "" instead of the expected value.
Pass std::string{timeMetricData} instead: constructs an rvalue temporary that
satisfies the && parameter while keeping the member intact for assertions.
anshephe
pushed a commit
that referenced
this pull request
Jun 9, 2026
…ate event (#1485) * VPAAMP-261: AAMP_EVENT_TUNE_TIME_METRICS dispatched before STATE_CHANGED(PLAYING) Reason for change: Sent the tunetime metrics event from the progress callback to time it always after the player has moved to PLAYING state. In TuneFailure case, it will be sent during Stop call. PLAYING state event is used by VIPA and EPG to measure total tune time and hence should not be delayed. Test Procedure: Confirm from logs that tune time metrics event is sent after state=PLAYING event in tune success. Ensure the event is still sent in tune fail case Risks: Low Signed-off-by: Vinish100 <vinish.balan@gmail.com> * VPAAMP-261: address code review comments - priv_aamp.cpp: move mTuneMetricDataPending.load() guard inside SendTuneMetricsEvent() so the check lives in one place; remove redundant outer guard at the progress-event call site - priv_aamp.cpp: collapse if(eventAvailStatus){store(true)} patterns at LogTuneFailure and LogTuneComplete sites to store(eventAvailStatus) - priv_aamp.cpp: add centralised AAMPLOG_MIL state-transition log in SetState(); remove per-site redundant log at first-frame call site - AampEvent.h / AampEvent.cpp / FakeAampEvent.cpp: change TuneTimeMetricsEvent tuneMetricData parameter to rvalue reference (&&) - AampProfiler.h: expand GetTuneTimeMetricAsJson @return doc comment to describe the JSON object and all its keys * VPAAMP-261: fix TuneTimeMetricsEvent test call site for rvalue ref parameter std::move() the lvalue timeMetricData at the call site in AampEventTests SetUp() to match the updated TuneTimeMetricsEvent constructor signature which takes tuneMetricData as std::string &&. * VPAAMP-261: fix TuneTimeMetricsEventTest failures after rvalue ref change After the constructor was changed to take tuneMetricData as std::string&&, std::move(timeMetricData) in SetUp() left the member in a moved-from (empty) state, causing both Constructor and GetTuneMetricsData assertions to compare against "" instead of the expected value. Pass std::string{timeMetricData} instead: constructs an rvalue temporary that satisfies the && parameter while keeping the member intact for assertions. --------- Signed-off-by: Vinish100 <vinish.balan@gmail.com> Co-authored-by: Philip Stroffolino <philip_stroffolino@cable.comcast.com>
shripadbpersonal
pushed a commit
that referenced
this pull request
Jun 10, 2026
…ate event (#1485) (#1570) * VPAAMP-261: AAMP_EVENT_TUNE_TIME_METRICS dispatched before STATE_CHANGED(PLAYING) Reason for change: Sent the tunetime metrics event from the progress callback to time it always after the player has moved to PLAYING state. In TuneFailure case, it will be sent during Stop call. PLAYING state event is used by VIPA and EPG to measure total tune time and hence should not be delayed. Test Procedure: Confirm from logs that tune time metrics event is sent after state=PLAYING event in tune success. Ensure the event is still sent in tune fail case Risks: Low * VPAAMP-261: address code review comments - priv_aamp.cpp: move mTuneMetricDataPending.load() guard inside SendTuneMetricsEvent() so the check lives in one place; remove redundant outer guard at the progress-event call site - priv_aamp.cpp: collapse if(eventAvailStatus){store(true)} patterns at LogTuneFailure and LogTuneComplete sites to store(eventAvailStatus) - priv_aamp.cpp: add centralised AAMPLOG_MIL state-transition log in SetState(); remove per-site redundant log at first-frame call site - AampEvent.h / AampEvent.cpp / FakeAampEvent.cpp: change TuneTimeMetricsEvent tuneMetricData parameter to rvalue reference (&&) - AampProfiler.h: expand GetTuneTimeMetricAsJson @return doc comment to describe the JSON object and all its keys * VPAAMP-261: fix TuneTimeMetricsEvent test call site for rvalue ref parameter std::move() the lvalue timeMetricData at the call site in AampEventTests SetUp() to match the updated TuneTimeMetricsEvent constructor signature which takes tuneMetricData as std::string &&. * VPAAMP-261: fix TuneTimeMetricsEventTest failures after rvalue ref change After the constructor was changed to take tuneMetricData as std::string&&, std::move(timeMetricData) in SetUp() left the member in a moved-from (empty) state, causing both Constructor and GetTuneMetricsData assertions to compare against "" instead of the expected value. Pass std::string{timeMetricData} instead: constructs an rvalue temporary that satisfies the && parameter while keeping the member intact for assertions. --------- Signed-off-by: Vinish100 <vinish.balan@gmail.com> Co-authored-by: Philip Stroffolino <philip_stroffolino@cable.comcast.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reason for change: Sent the tunetime metrics event from the progress callback to time it always after the player has moved to PLAYING state. In TuneFailure case, it will be sent during Stop call. PLAYING state event is used by VIPA and EPG to measure total tune time and hence should not be delayed.
Test Procedure: Confirm from logs that tune time metrics event is sent after state=PLAYING event in tune success. Ensure the event is still sent in tune fail case
Risks: Low