Skip to content

Commit

Permalink
v2.4.12 (#129)
Browse files Browse the repository at this point in the history
 - Add checkstyle task to gradle (#123)
 - Replaced FrameRendererListener with VideoListener. (#127)
 - Custom data update: deprecate MuxExoPlayer constructors that take a CustomerData arg separately, add custom-dimensions example to demo app (#128)

Co-authored-by: nbirkenshaw-mux <86244091+nbirkenshaw-mux@users.noreply.github.com>
Co-authored-by: Tomislav Kordic <32546640+tomkordic@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 29, 2021
1 parent 49805a2 commit 7cf30d5
Show file tree
Hide file tree
Showing 23 changed files with 688 additions and 97 deletions.
1 change: 1 addition & 0 deletions .buildkite/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ steps:
- "MuxExoPlayer/buildout/outputs/artifacts/*.aar"
- "MuxExoPlayer/buildout/outputs/artifacts/*.txt"
- "MuxExoPlayer/buildout/outputs/version-*"
- "MuxExoPlayer/buildout/reports/*/*.*"
- "automatedtests/buildout/outputs/apk/androidTest/**/*.apk"
- "automatedtests/buildout/outputs/apk/*/debug/automatedtests-*-debug.apk"
- wait
Expand Down
363 changes: 363 additions & 0 deletions .checkstyle/checkstyle.xml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
"https://checkstyle.org/dtds/suppressions_1_0.dtd">
<suppressions>
</suppressions>
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ gen-external-apklibs
.project
.classpath
.settings
.checkstyle
.cproject

# Gradle
Expand Down
26 changes: 24 additions & 2 deletions MuxExoPlayer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
apply plugin: 'com.android.library'
apply plugin: 'checkstyle'

checkstyle {
configFile = file("${rootDir}/.checkstyle/checkstyle.xml")
configDirectory = file("${rootDir}/.checkstyle")
toolVersion '8.42'
}

task checkstyle(type: Checkstyle) {
source 'src'
include '**/*.java'
exclude '**/gen/**'

// empty classpath
classpath = files()
showViolations = true
ignoreFailures = false
}

preBuild.dependsOn('checkstyle')
assemble.dependsOn('lint')
check.dependsOn('checkstyle')

android {
compileSdkVersion project.ext.compileSdkVersion
defaultConfig {
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.targetSdkVersion
versionCode 22
versionName "2.4.11"
versionCode 23
versionName "2.4.12"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
import com.google.android.exoplayer2.video.VideoListener;
import com.mux.stats.sdk.core.MuxSDKViewOrientation;
import com.mux.stats.sdk.core.events.EventBus;
import com.mux.stats.sdk.core.events.IEvent;
Expand All @@ -48,6 +49,7 @@
import com.mux.stats.sdk.core.events.playback.SeekingEvent;
import com.mux.stats.sdk.core.events.playback.TimeUpdateEvent;
import com.mux.stats.sdk.core.model.BandwidthMetricData;
import com.mux.stats.sdk.core.model.CustomerData;
import com.mux.stats.sdk.core.model.CustomerPlayerData;
import com.mux.stats.sdk.core.model.CustomerVideoData;
import com.mux.stats.sdk.core.model.CustomerViewData;
Expand All @@ -72,7 +74,7 @@ public class MuxBaseExoPlayer extends EventBus implements IPlayerListener {
protected static final int ERROR_DRM = -2;
protected static final int ERROR_IO = -3;

protected static final int NUMBER_OF_FRAMES_THAT_ARE_CONSIDERED_PLAYBACK = 2;
protected static final long TIME_TO_WAIT_AFTER_FIRST_FRAME_RENDERED = 50; // in ms

protected String mimeType;
protected Integer sourceWidth;
Expand All @@ -81,19 +83,21 @@ public class MuxBaseExoPlayer extends EventBus implements IPlayerListener {
protected Float sourceAdvertisedFramerate;
protected Long sourceDuration;
protected ExoPlayerHandler playerHandler;
protected FrameRenderedListener frameRenderedListener;
protected Timer updatePlayheadPositionTimer;
protected MuxVideoListener videoListener;

protected WeakReference<ExoPlayer> player;
protected WeakReference<View> playerView;
protected WeakReference<Context> contextRef;
protected AdsImaSDKListener adsImaSdkListener;

protected boolean detectMimeType;
protected boolean firstFrameReceived = false;
protected int numberOfEventsSent = 0;
protected int numberOfPlayEventsSent = 0;
protected int numberOfPauseEventsSent = 0;
protected int streamType = -1;
protected long firstFrameRenderedAt = -1;

public enum PlayerState {
BUFFERING, REBUFFERING, SEEKING, SEEKED, ERROR, PAUSED, PLAY, PLAYING, PLAYING_ADS,
Expand All @@ -103,26 +107,33 @@ public enum PlayerState {
protected PlayerState state;
protected MuxStats muxStats;
boolean seekingInProgress;
int numberOfFramesRenderedSinceSeekingStarted;
boolean playItemHaveVideoTrack;


@Deprecated
MuxBaseExoPlayer(Context ctx, ExoPlayer player, String playerName,
CustomerPlayerData customerPlayerData, CustomerVideoData customerVideoData,
CustomerViewData customerViewData, boolean sentryEnabled,
INetworkRequest networkRequest) {
this(ctx, player, playerName,
new CustomerData(customerPlayerData, customerVideoData, customerViewData),
sentryEnabled, networkRequest);
}

MuxBaseExoPlayer(Context ctx, ExoPlayer player, String playerName,
CustomerData data, boolean sentryEnabled,
INetworkRequest networkRequest) {
super();
detectMimeType = true;
this.player = new WeakReference<>(player);
this.contextRef = new WeakReference<>(ctx);
state = PlayerState.INIT;
MuxStats.setHostDevice(new MuxDevice(ctx));
MuxStats.setHostNetworkApi(networkRequest);
muxStats = new MuxStats(this, playerName, customerPlayerData, customerVideoData,
customerViewData, sentryEnabled);
muxStats = new MuxStats(this, playerName, data, sentryEnabled);
addListener(muxStats);
playerHandler = new ExoPlayerHandler(player.getApplicationLooper(), this);
frameRenderedListener = new FrameRenderedListener(playerHandler);
videoListener = new MuxVideoListener(this);
playItemHaveVideoTrack = false;
setPlaybackHeadUpdateInterval();
try {
Expand Down Expand Up @@ -217,29 +228,44 @@ public AdsImaSDKListener getAdEventListener() {
return adsImaSdkListener;
}

@SuppressWarnings("unused")
public void updateCustomerData(CustomerData data) {
muxStats.setCustomerData(data);
}

@SuppressWarnings("unused")
public CustomerData getCustomerData() {
return muxStats.getCustomerData();
}

@Deprecated
@SuppressWarnings("unused")
public void updateCustomerData(CustomerPlayerData customPlayerData,
CustomerVideoData customVideoData) {
muxStats.updateCustomerData(customPlayerData, customVideoData);
}

@Deprecated
@SuppressWarnings("unused")
public void updateCustomerData(CustomerPlayerData customerPlayerData,
CustomerVideoData customerVideoData,
CustomerViewData customerViewData) {
muxStats.updateCustomerData(customerPlayerData, customerVideoData, customerViewData);
}

@Deprecated
@SuppressWarnings("unused")
public CustomerVideoData getCustomerVideoData() {
return muxStats.getCustomerVideoData();
}

@Deprecated
@SuppressWarnings("unused")
public CustomerPlayerData getCustomerPlayerData() {
return muxStats.getCustomerPlayerData();
}

@Deprecated
@SuppressWarnings("unused")
public CustomerViewData getCustomerViewData() {
return muxStats.getCustomerViewData();
Expand Down Expand Up @@ -385,18 +411,17 @@ protected void setPlaybackHeadUpdateInterval() {
}
if (playItemHaveVideoTrack) {
Player.VideoComponent videoComponent = player.get().getVideoComponent();
videoComponent.setVideoFrameMetadataListener(frameRenderedListener);
} else {
// Schedule timer to execute, this is for audio only content.
updatePlayheadPositionTimer = new Timer();
updatePlayheadPositionTimer.schedule(new TimerTask() {
@Override
public void run() {
playerHandler.obtainMessage(ExoPlayerHandler.UPDATE_PLAYER_CURRENT_POSITION)
.sendToTarget();
}
}, 0, 15);
}
videoComponent.addVideoListener(videoListener);
}
// Schedule timer to execute, this is for audio only content.
updatePlayheadPositionTimer = new Timer();
updatePlayheadPositionTimer.schedule(new TimerTask() {
@Override
public void run() {
playerHandler.obtainMessage(ExoPlayerHandler.UPDATE_PLAYER_CURRENT_POSITION)
.sendToTarget();
}
}, 0, 15);
}

/*
Expand Down Expand Up @@ -519,26 +544,27 @@ protected void seeking() {
}
state = PlayerState.SEEKING;
seekingInProgress = true;
numberOfFramesRenderedSinceSeekingStarted = 0;
firstFrameRenderedAt = -1;
dispatch(new SeekingEvent(null));
firstFrameReceived = false;
}

protected void seeked(boolean newFrameRendered) {
protected void seeked(boolean timeUpdateEvent) {
/*
* Seeked event will be fired by the player immediately after seeking event
* This is not accurate, instead report the seeked event on first few frames rendered.
* This function is called each time a new frame is about to be rendered.
*/
if (seekingInProgress) {
if (newFrameRendered) {
if (numberOfFramesRenderedSinceSeekingStarted
> NUMBER_OF_FRAMES_THAT_ARE_CONSIDERED_PLAYBACK) {
if (timeUpdateEvent) {
if ((System.currentTimeMillis() - firstFrameRenderedAt
> TIME_TO_WAIT_AFTER_FIRST_FRAME_RENDERED) && firstFrameReceived) {
// This is a playback !!!
dispatch(new SeekedEvent(null));
seekingInProgress = false;
playing();
} else {
numberOfFramesRenderedSinceSeekingStarted++;
// No playback yet.
}
} else {
// the player was seeking while paused
Expand Down Expand Up @@ -583,26 +609,33 @@ private void resetInternalStats() {
numberOfPauseEventsSent = 0;
numberOfPlayEventsSent = 0;
numberOfEventsSent = 0;
firstFrameReceived = false;
firstFrameRenderedAt = -1;
}

static class FrameRenderedListener implements VideoFrameMetadataListener {
static class MuxVideoListener implements VideoListener {
MuxBaseExoPlayer muxStats;

ExoPlayerHandler handler;
public MuxVideoListener(MuxBaseExoPlayer muxStats) {
this.muxStats = muxStats;
}

public FrameRenderedListener(ExoPlayerHandler handler) {
this.handler = handler;
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
float pixelWidthHeightRatio) {
// Do nothing
}

// As of r2.11.x, the signature for this callback has changed. These are not annotated as @Overrides in
// order to support both before r2.11.x and after r2.11.x at the same time.
public void onVideoFrameAboutToBeRendered(long presentationTimeUs, long releaseTimeNs,
Format format) {
handler.obtainMessage(ExoPlayerHandler.UPDATE_PLAYER_CURRENT_POSITION).sendToTarget();
@Override
public void onSurfaceSizeChanged(int width, int height) {
// Do nothing
}

public void onVideoFrameAboutToBeRendered(long presentationTimeUs, long releaseTimeNs,
Format format, @Nullable MediaFormat mediaFormat) {
handler.obtainMessage(ExoPlayerHandler.UPDATE_PLAYER_CURRENT_POSITION).sendToTarget();
@Override
public void onRenderedFirstFrame() {
// TODO save this timestamp
muxStats.firstFrameRenderedAt = System.currentTimeMillis();
muxStats.firstFrameReceived = true;
}
}

Expand Down Expand Up @@ -631,7 +664,9 @@ public void handleMessage(Message msg) {
if (muxStats.player.get() != null) {
playerCurrentPosition.set(muxStats.player.get().getContentPosition());
}
muxStats.seeked(true);
if (muxStats.seekingInProgress) {
muxStats.seeked(true);
}
break;
default:
MuxLogger.d(TAG, "ExoPlayerHandler>> Unhandled message type: " + msg.what);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.mux.stats.sdk.core.model.CustomerData;
import com.mux.stats.sdk.core.model.CustomerPlayerData;
import com.mux.stats.sdk.core.model.CustomerVideoData;
import com.mux.stats.sdk.core.model.CustomerViewData;
Expand All @@ -28,41 +29,60 @@
public class MuxStatsExoPlayer extends MuxBaseExoPlayer implements AnalyticsListener,
Player.EventListener {

@Deprecated
public MuxStatsExoPlayer(Context ctx, ExoPlayer player, String playerName,
CustomerPlayerData customerPlayerData,
CustomerVideoData customerVideoData) {
this(ctx, player, playerName, customerPlayerData, customerVideoData, null, true);
this(ctx, player, playerName, customerPlayerData,
customerVideoData, null, true);
}

@Deprecated
public MuxStatsExoPlayer(Context ctx, ExoPlayer player, String playerName,
CustomerPlayerData customerPlayerData,
CustomerVideoData customerVideoData,
CustomerViewData customerViewData) {
this(ctx, player, playerName, customerPlayerData, customerVideoData, customerViewData, true);
this(ctx, player, playerName, customerPlayerData, customerVideoData,
customerViewData, true);
}

@Deprecated
public MuxStatsExoPlayer(Context ctx, ExoPlayer player, String playerName,
CustomerPlayerData customerPlayerData,
CustomerVideoData customerVideoData,
boolean sentryEnabled) {
this(ctx, player, playerName, customerPlayerData, customerVideoData, null, sentryEnabled);
this(ctx, player, playerName, customerPlayerData, customerVideoData,
null, sentryEnabled);
}

@Deprecated
public MuxStatsExoPlayer(Context ctx, ExoPlayer player, String playerName,
CustomerPlayerData customerPlayerData,
CustomerVideoData customerVideoData,
CustomerViewData customerViewData, boolean sentryEnabled) {
this(ctx, player, playerName, customerPlayerData, customerVideoData, customerViewData,
sentryEnabled, new MuxNetworkRequests());
this(ctx, player, playerName, new CustomerData(customerPlayerData, customerVideoData,
customerViewData), sentryEnabled, new MuxNetworkRequests());
}

@Deprecated
public MuxStatsExoPlayer(Context ctx, ExoPlayer player, String playerName,
CustomerPlayerData customerPlayerData,
CustomerVideoData customerVideoData,
CustomerViewData customerViewData, boolean sentryEnabled,
INetworkRequest networkRequest) {
super(ctx, player, playerName, customerPlayerData, customerVideoData, customerViewData,
sentryEnabled, networkRequest);
CustomerViewData customerViewData, boolean sentryEnabled, INetworkRequest networkRequests) {
this(ctx, player, playerName, new CustomerData(customerPlayerData, customerVideoData,
customerViewData), sentryEnabled, networkRequests);
}

public MuxStatsExoPlayer(Context ctx, ExoPlayer player, String playerName,
CustomerData data) {
this(ctx, player, playerName, data, true, new MuxNetworkRequests());
}

public MuxStatsExoPlayer(Context ctx, ExoPlayer player, String playerName,
CustomerData data,
boolean sentryEnabled,
INetworkRequest networkRequests) {
super(ctx, player, playerName, data, sentryEnabled, networkRequests);

if (player instanceof SimpleExoPlayer) {
((SimpleExoPlayer) player).addAnalyticsListener(this);
Expand Down
Loading

0 comments on commit 7cf30d5

Please sign in to comment.