Skip to content

Commit ebb1f5b

Browse files
authored
Merge pull request #103 from newrelic/QOE-beta-release-android
feat : qoe event with attributes
2 parents 94475c6 + 3748ccb commit ebb1f5b

File tree

4 files changed

+565
-13
lines changed

4 files changed

+565
-13
lines changed

NewRelicVideoCore/src/main/java/com/newrelic/videoagent/core/NRDef.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ private NRDef() {
3030
public static final String CONTENT_HEARTBEAT = "CONTENT_HEARTBEAT";
3131
public static final String CONTENT_RENDITION_CHANGE = "CONTENT_RENDITION_CHANGE";
3232
public static final String CONTENT_ERROR = "CONTENT_ERROR";
33+
public static final String QOE_AGGREGATE = "QOE_AGGREGATE";
3334

3435
public static final String AD_REQUEST = "AD_REQUEST";
3536
public static final String AD_START = "AD_START";
@@ -47,4 +48,4 @@ private NRDef() {
4748
public static final String AD_BREAK_END = "AD_BREAK_END";
4849
public static final String AD_QUARTILE = "AD_QUARTILE";
4950
public static final String AD_CLICK = "AD_CLICK";
50-
}
51+
}

NewRelicVideoCore/src/main/java/com/newrelic/videoagent/core/NRVideo.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public static boolean isInitialized() {
4242
return instance != null;
4343
}
4444

45+
/**
46+
* Get configured harvest cycle in seconds
47+
* @return harvest cycle seconds, or default 60 if not initialized
48+
*/
49+
public static int getHarvestCycleSeconds() {
50+
if (instance != null && instance.harvestManager != null) {
51+
return instance.harvestManager.getFactory().getConfiguration().getHarvestCycleSeconds();
52+
}
53+
return 60; // Default harvest cycle
54+
}
55+
4556
public static Integer addPlayer(NRVideoPlayerConfiguration config) {
4657
if (!isInitialized()) {
4758
NRLog.w("NRVideo not initialized - cannot add player");
@@ -152,7 +163,7 @@ public static void recordCustomEvent(Map<String, Object> attributes, Integer tra
152163
NRTracker contentTracker = NewRelicVideoAgent.getInstance().getContentTracker(trackerId);
153164
if (contentTracker != null) {
154165
contentTracker.sendEvent(action, attributes);
155-
}
166+
}
156167
} else {
157168
// Global event - send to all trackers
158169
NRVideo videoInstance = getInstance();
@@ -224,7 +235,7 @@ private NRVideo initialize(Context context, NRVideoConfiguration config) {
224235
if (applicationContext instanceof Application) {
225236
Application app = (Application) applicationContext;
226237
NRVideoLifecycleObserver lifecycleObserver =
227-
new NRVideoLifecycleObserver(harvestManager.getFactory());
238+
new NRVideoLifecycleObserver(harvestManager.getFactory());
228239

229240
// Register with application
230241
app.registerActivityLifecycleCallbacks(lifecycleObserver);
@@ -342,4 +353,4 @@ public static void setAdAttribute(Integer trackerId, String key, Object value) {
342353
public static void setGlobalAttribute(String key, Object value) {
343354
NewRelicVideoAgent.getInstance().setGlobalAttribute(key, value);
344355
}
345-
}
356+
}

NewRelicVideoCore/src/main/java/com/newrelic/videoagent/core/tracker/NRTracker.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public Map<String, Object> getAttributes(String action, Map<String, Object> attr
7373
attributes = eventAttributes.generateAttributes(action, attributes);
7474
return attributes;
7575
}
76-
7776
/**
7877
* Add an entry to the timeSince table.
7978
*
@@ -142,6 +141,9 @@ public void sendEvent(String eventType, String action, Map<String, Object> attri
142141
attributes = getAttributes(action, attributes);
143142
timeSinceTable.applyAttributes(action, attributes);
144143

144+
// Process QoE events that require timing attributes
145+
processQoeEvents(action, attributes);
146+
145147
attributes.put("agentSession", getAgentSession());
146148
attributes.put("instrumentation.provider", "newrelic");
147149
attributes.put("instrumentation.name", getInstrumentationName());
@@ -247,5 +249,28 @@ public String getInstrumentationName() {
247249
public String getAgentSession() {
248250
return NewRelicVideoAgent.getInstance().getSessionId();
249251
}
252+
/**
253+
* Process QoE events that require timing attributes to be already applied.
254+
* This method handles QOE_AGGREGATE and CONTENT_BUFFER_END events for various QoE calculations.
255+
*
256+
* @param action The event action name
257+
* @param attributes The event attributes map (timing attributes already applied)
258+
*/
259+
private void processQoeEvents(String action, Map<String, Object> attributes) {
260+
if (this instanceof NRVideoTracker) {
261+
NRVideoTracker videoTracker = (NRVideoTracker) this;
250262

251-
}
263+
if (QOE_AGGREGATE.equals(action)) {
264+
// Process QOE_AGGREGATE events for startup time calculation
265+
Long timeSinceRequested = (Long) attributes.get("timeSinceRequested");
266+
Long timeSinceStarted = (Long) attributes.get("timeSinceStarted");
267+
Long timeSinceLastError = (Long) attributes.get("timeSinceLastError");
268+
videoTracker.calculateAndAddStartupTime(attributes, timeSinceRequested, timeSinceStarted, timeSinceLastError);
269+
}
270+
else if (CONTENT_BUFFER_END.equals(action)) {
271+
// Process CONTENT_BUFFER_END events for rebuffering time calculation
272+
videoTracker.calculateRebufferingTime(attributes);
273+
}
274+
}
275+
}
276+
}

0 commit comments

Comments
 (0)