Skip to content

VPAAMP-261: AAMP_EVENT_TUNE_TIME_METRICS dispatched before PLAYING state event#1485

Merged
pstroffolino merged 5 commits into
dev_sprint_25_2from
feature/VPAAMP-261
May 29, 2026
Merged

VPAAMP-261: AAMP_EVENT_TUNE_TIME_METRICS dispatched before PLAYING state event#1485
pstroffolino merged 5 commits into
dev_sprint_25_2from
feature/VPAAMP-261

Conversation

@Vinish100

@Vinish100 Vinish100 commented May 20, 2026

Copy link
Copy Markdown
Contributor

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

@Vinish100 Vinish100 requested a review from a team as a code owner May 20, 2026 14:40
@Vinish100 Vinish100 requested a review from Copilot May 20, 2026 14:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PrivateInstanceAAMP and dispatch it from MonitorProgress() once the state is PLAYING (with a TuneFail fallback path).
  • Update TuneTimeMetricsEvent to take the metrics JSON by value and move it into the event object.
  • Simplify GetTuneTimeMetricAsJson() signature by removing the explicit licenseAcqNWTime parameter 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();
	}

Comment thread priv_aamp.cpp Outdated
Comment thread test/utests/tests/PrivAampTests/PrivAampTests.cpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread test/utests/tests/PrivAampTests/PrivAampTests.cpp
Comment thread priv_aamp.cpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
		}

Comment thread priv_aamp.cpp Outdated
@Vinish100 Vinish100 force-pushed the feature/VPAAMP-261 branch from 4d297db to cae50ff Compare May 21, 2026 07:43
…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>
@Vinish100 Vinish100 force-pushed the feature/VPAAMP-261 branch from cae50ff to f0b90ef Compare May 27, 2026 06:03
Comment thread priv_aamp.cpp Outdated
Comment thread priv_aamp.cpp Outdated
Comment thread priv_aamp.cpp Outdated
Comment thread priv_aamp.cpp
Comment thread AampProfiler.h Outdated
Comment thread AampEvent.h Outdated
- 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
pstroffolino and others added 3 commits May 29, 2026 10:43
…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.
@pstroffolino pstroffolino merged commit 0b75f5a into dev_sprint_25_2 May 29, 2026
11 checks passed
@pstroffolino pstroffolino deleted the feature/VPAAMP-261 branch May 29, 2026 15:29
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants