Skip to content

Commit c018ba0

Browse files
Merge pull request #46 from sadhana-newrelic/NR-435627-actual-bitrate
fix: Addition of actual bitrate in attributes
2 parents fa986c4 + c04e993 commit c018ba0

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

NRExoPlayerTracker/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 16
99
targetSdkVersion 33
1010
versionCode 6
11-
versionName "3.0.2"
11+
versionName "3.0.3"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
consumerProguardFiles "consumer-rules.pro"
1414
}

NRExoPlayerTracker/src/main/java/com/newrelic/videoagent/exoplayer/tracker/NRTrackerExoPlayer.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Map;
2525

2626
import static com.newrelic.videoagent.core.NRDef.*;
27+
import androidx.media3.common.C;
2728

2829
/**
2930
* New Relic Video tracker for ExoPlayer.
@@ -38,6 +39,7 @@ public class NRTrackerExoPlayer extends NRVideoTracker implements Player.Listene
3839
protected List<Uri> playlist;
3940
protected int lastWindow;
4041
protected String renditionChangeShift;
42+
protected long actualBitrate;
4143

4244
/**
4345
* Init a new ExoPlayer tracker.
@@ -145,6 +147,10 @@ public Long getBitrate() {
145147
return bitrateEstimate;
146148
}
147149

150+
public Long getActualBitrate() {
151+
return actualBitrate;
152+
}
153+
148154
/**
149155
* Get rendition bitrate.
150156
*
@@ -324,6 +330,7 @@ private void resetState() {
324330
lastWindow = 0;
325331
lastWidth = 0;
326332
lastHeight = 0;
333+
actualBitrate = 0;
327334
}
328335

329336
/**
@@ -487,6 +494,16 @@ public void onLoadError(EventTime eventTime, LoadEventInfo loadEventInfo, MediaL
487494
sendError(error);
488495
}
489496

497+
@Override
498+
public void onLoadCompleted(EventTime eventTime, LoadEventInfo loadEventInfo, MediaLoadData mediaLoadData) {
499+
if (mediaLoadData.dataType == C.DATA_TYPE_MEDIA
500+
&& mediaLoadData.trackType == C.TRACK_TYPE_VIDEO
501+
&& loadEventInfo.loadDurationMs > 0) {
502+
// Calculate the bitrate for this specific chunk in bits per second
503+
this.actualBitrate = (loadEventInfo.bytesLoaded * 8 * 1000) / loadEventInfo.loadDurationMs;
504+
}
505+
}
506+
490507
@Override
491508
public void onBandwidthEstimate(AnalyticsListener.EventTime eventTime, int totalLoadTimeMs, long totalBytesLoaded, long bitrateEstimate) {
492509
NRLog.d("onBandwidthEstimate analytics");

NRIMATracker/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 16
99
targetSdkVersion 33
1010
versionCode 6
11-
versionName "3.0.2"
11+
versionName "3.0.3"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
consumerProguardFiles "consumer-rules.pro"
1414
}

NewRelicVideoCore/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 16
99
targetSdkVersion 33
1010
versionCode 9
11-
versionName "3.0.2"
11+
versionName "3.0.3"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
consumerProguardFiles "consumer-rules.pro"
1414
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ public boolean preSend(String action, Map<String, Object> attributes) {
139139
* @param attributes Event Type attributes for this action.
140140
*/
141141
public void sendEvent(String eventType, String action, Map<String, Object> attributes) {
142+
if (this instanceof NRVideoTracker) {
143+
((NRVideoTracker) this).updatePlaytime();
144+
}
145+
142146
if (attributes == null) {
143147
attributes = new HashMap<>();
144148
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ public Map<String, Object> getAttributes(String action, Map<String, Object> attr
226226
}
227227

228228
attr.put("contentTitle", getTitle());
229-
attr.put("contentBitrate", getBitrate());
229+
// attr.put("contentBitrate", getBitrate());
230+
attr.put("contentBitrate", getActualBitrate());
230231
attr.put("contentRenditionBitrate", getRenditionBitrate());
231232
attr.put("contentRenditionWidth", getRenditionWidth());
232233
attr.put("contentRenditionHeight", getRenditionHeight());
@@ -243,7 +244,7 @@ public Map<String, Object> getAttributes(String action, Map<String, Object> attr
243244
return attr;
244245
}
245246

246-
public void generatePlayElapsedTime() {
247+
public void updatePlaytime() {
247248
if (playtimeSinceLastEventTimestamp > 0) {
248249
playtimeSinceLastEvent = System.currentTimeMillis() - playtimeSinceLastEventTimestamp;
249250
totalPlaytime += playtimeSinceLastEvent;
@@ -598,6 +599,10 @@ public Long getBitrate() {
598599
return null;
599600
}
600601

602+
public Long getActualBitrate(){
603+
return null;
604+
}
605+
601606
/**
602607
* Get the video rendition bitrate.
603608
*

0 commit comments

Comments
 (0)